* floor() broken on Multia
@ 2000-03-02 5:00 telford
2000-03-03 5:00 ` Ryan C. Price
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: telford @ 2000-03-02 5:00 UTC (permalink / raw)
I'm using kernel 2.2.12 and GNU libc-2.1.3.so on a Multia and the floor()
function never completes, it just hangs the process until you force it
to die with a signal. Seems like in /usr/include/bits/mathinline.h is
some assembler code:
__MATH_INLINE double
__floor (double __x)
{
if (__x != 0 && fabs (__x) < 9007199254740992.0) /* 1 << DBL_MANT_DIG */
{
double __tmp1;
__asm (
#ifdef _IEEE_FP_INEXACT
"cvttq/svim %2,%1\n\t"
#else
"cvttq/svm %2,%1\n\t"
#endif
"cvtqt/m %1,%0\n\t"
: "=f"(__x), "=&f"(__tmp1)
: "f"(__x));
}
return __x;
}
And those instructions don't seem to execute on the old Multia processor:
cpu : Alpha
cpu model : LCA4
cpu variation : 7
cpu revision : 0
cpu serial number :
system type : Noname
So does anyone have a floor() function that does work?
Is it the kernel's responsibility to support these instructions or
should the libc be adjusted to support a given processor
(this is an off-the-shelf Debian libc, if I have to compile my own that's OK)?
- Tel
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: floor() broken on Multia
2000-03-02 5:00 floor() broken on Multia telford
@ 2000-03-03 5:00 ` Ryan C. Price
2000-03-03 5:00 ` Michal Jaegermann
2000-03-03 5:00 ` Tony Hammitt
2000-03-03 5:00 ` telford
2 siblings, 1 reply; 9+ messages in thread
From: Ryan C. Price @ 2000-03-03 5:00 UTC (permalink / raw)
Hasn't the Multia's CPU (21066) got reduced FP functionality ? This may have
something to do with the problem.
I had a similar problem with some app (squid I think), I just replaced the
floor with a couple of type casts as suggested already. Works fine. May not
be the most efficient, but it works.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: floor() broken on Multia
2000-03-03 5:00 ` Ryan C. Price
@ 2000-03-03 5:00 ` Michal Jaegermann
2000-03-06 5:00 ` telford
0 siblings, 1 reply; 9+ messages in thread
From: Michal Jaegermann @ 2000-03-03 5:00 UTC (permalink / raw)
Ryan C. Price (pricerc@ihug.co.nz) wrote:
: Hasn't the Multia's CPU (21066) got reduced FP functionality ? This may have
: something to do with the problem.
All of this sounds exactly like the problem which was described
recently. Here is the original message:
From: Carsten Jacobi <carsten@jakes.kawo1.rwth-aachen.de>
Date: Sun, 20 Feb 2000 23:19:40 +0100 (CET)
Subject: [PATCH] Trapping for Alpha EV4 machines
I have found a bug. I just don't know whether to blame the kernel or
my processor, but now it works.
The problem is, that EV4 machines seam to behave differently than
EV5/6 during an illegal opcode or FP forced software handling trap. At
least the code in arch/alpha/kernel/traps.c assumes that the PC is
incremented when the exception handler is executed. This is not the case
on my EV4-machine, and programs that used trapping math instructions (I
got him on "cvttq/svm") just stuck:
1. The exception handler tried to handle the instruction that preceeded
the instruction which caused the exception.
2. After the handling the PC was still pointing to the same insn so that
the exception was caused over and over again.
Thus the process using such an insn ate up the whole CPU power and didn't
process!
Unfortunately this instruction was located in the libgtk so that every
program using gtk didn't work on my machine (Thanks tux now they do run
8-) ).
Ok, anybody with an EV4-Alpha (for example Jensen) who shares the same
experience with me? Or do I have a very exclusive/unique 21064 in my
chassis ... ;-)
Carsten
PS.: I definitely know that the second call in the patchfile to
"alpha_fp_emul" is corrected by the patch. I hope my change to the first
call in the patch file is correct too, but I am not sure ...
--------------------------------------
Carsten Jacobi
Kastanienweg 6, App.1317
52074 Aachen
Tel.: +49 241 878117
Fax : +49 241 878189
ISDN: +49 241 878190
E-Mail: carsten@jakes.kawo1.rwth-aachen.de
--- linux/arch/alpha/kernel/traps.c.old Tue Jan 4 19:12:11 2000
+++ linux/arch/alpha/kernel/traps.c Sun Feb 20 19:45:06 2000
@@ -336,9 +336,14 @@
/* Software-completion summary bit is set, so try to
emulate the instruction. */
if (!amask(AMASK_PRECISE_TRAP)) {
+#ifdef CONFIG_ALPHA_EV4
+ if (alpha_fp_emul(regs.pc))
+ return;
+#else
/* 21264 (except pass 1) has precise exceptions. */
if (alpha_fp_emul(regs.pc - 4))
return;
+#endif
} else {
if (alpha_fp_emul_imprecise(®s, write_mask))
return;
@@ -417,8 +422,13 @@
/* EV4 does not implement anything except normal
rounding. Everything else will come here as
an illegal instruction. Emulate them. */
- if (alpha_fp_emul(regs.pc - 4))
+ if (alpha_fp_emul(regs.pc))
+ {
+ /* Increment the PC so that the program in
+ user space continues */
+ regs.pc += 4;
return;
+ }
}
send_sig(SIGILL, current, 1);
break;
Try the patch above and see if this will change anything. It sounds
like it might.
Reports of a failure or success are very welcome.
Michal
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: floor() broken on Multia
2000-03-03 5:00 ` Michal Jaegermann
@ 2000-03-06 5:00 ` telford
0 siblings, 0 replies; 9+ messages in thread
From: telford @ 2000-03-06 5:00 UTC (permalink / raw)
> 1. The exception handler tried to handle the instruction that preceeded
> the instruction which caused the exception.
> 2. After the handling the PC was still pointing to the same insn so that
> the exception was caused over and over again.
> Thus the process using such an insn ate up the whole CPU power and didn't
> process!
This sounds exactly like the symptoms I was getting.
> Unfortunately this instruction was located in the libgtk so that every
> program using gtk didn't work on my machine (Thanks tux now they do run
> 8-) ).
That would probably be because the libgtk used floor() somewhere and the
inline assembly code ended up compiled into libgtk.
> Ok, anybody with an EV4-Alpha (for example Jensen) who shares the same
> experience with me? Or do I have a very exclusive/unique 21064 in my
> chassis ... ;-)
Looks like the EV4 in the Multia behaves the same way.
[snip the patch]
> Try the patch above and see if this will change anything. It sounds
> like it might.
> Reports of a failure or success are very welcome.
I upgraded from 2.2.12 to 2.2.14 and I also put the patch into the
kernel (see previous message for patch details). That does fix the problem,
I can compile with floor() and get correct behaviour (no hang).
I haven't tested all the extreme cases to see that floor() is exactly right
but for all the obvious cases it does the expected thing.
So just to repeat, the patch does work.
I tried a few apps that I had previously compiled and which were hanging
on me and they worked too. Interestingly, the other kludge solution that
involved replacing floor() with round-off is probably FASTER on an EV4
chip than the inline assembly. The reason being that even though the kludge
solution is longer, it doesn't evoke a kernel trap (which is vastly slower).
Then again, the EV4 is pretty slow to begin with, I can understand why libc
would be optimised to work best with the newest machines. Just maybe some
conditional code in the bits/mathinline.h file would be a nice touch so that
it gets the best results all round... maybe something like:
#ifdef __alpha_ev4__
__MATH_INLINE double __floor( double x )
{
return(( double )( int )(( x < 0 ) ? d1 - nextafter( 1, 0 ) : d1 ));
}
/* correct use of nextafter() ?? */
#else /* __alpha_ev4__ */
/* normal definition here */
#endif /* __alpha_ev4__ */
Anyhow, the difference is probably not worth worrying about (though these
little things add up after a while).
- Tel
PS: I heard that 2.2.15pre10 works abd 2.2.15pre13 is broken again
so someone is playing with this code
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: floor() broken on Multia
2000-03-02 5:00 floor() broken on Multia telford
2000-03-03 5:00 ` Ryan C. Price
@ 2000-03-03 5:00 ` Tony Hammitt
2000-03-03 5:00 ` telford
2000-03-03 5:00 ` telford
2 siblings, 1 reply; 9+ messages in thread
From: Tony Hammitt @ 2000-03-03 5:00 UTC (permalink / raw)
This isn't pretty, but it works:
y=floor(x); is equivalent to y=(double)(int)((x<0)?x-1:x);
It shouldn't require too much time to run on an Alpha, but
avoid this on an Intel box, they have problems with
converting doubles to and from ints and it takes 5 times
as long.
Regards,
Tony Hammitt
telford@xenon.triode.net.au wrote:
>
> I'm using kernel 2.2.12 and GNU libc-2.1.3.so on a Multia and the floor()
> function never completes, it just hangs the process until you force it
> to die with a signal. Seems like in /usr/include/bits/mathinline.h is
> some assembler code:
>
> __MATH_INLINE double
> __floor (double __x)
> {
> if (__x != 0 && fabs (__x) < 9007199254740992.0) /* 1 << DBL_MANT_DIG */
> {
> double __tmp1;
> __asm (
> #ifdef _IEEE_FP_INEXACT
> "cvttq/svim %2,%1\n\t"
> #else
> "cvttq/svm %2,%1\n\t"
> #endif
> "cvtqt/m %1,%0\n\t"
> : "=f"(__x), "=&f"(__tmp1)
> : "f"(__x));
> }
> return __x;
> }
>
> And those instructions don't seem to execute on the old Multia processor:
>
> cpu : Alpha
> cpu model : LCA4
> cpu variation : 7
> cpu revision : 0
> cpu serial number :
> system type : Noname
>
> So does anyone have a floor() function that does work?
> Is it the kernel's responsibility to support these instructions or
> should the libc be adjusted to support a given processor
> (this is an off-the-shelf Debian libc, if I have to compile my own that's OK)?
>
> - Tel
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: floor() broken on Multia
2000-03-03 5:00 ` Tony Hammitt
@ 2000-03-03 5:00 ` telford
2000-03-03 5:00 ` Tony Hammitt
0 siblings, 1 reply; 9+ messages in thread
From: telford @ 2000-03-03 5:00 UTC (permalink / raw)
Tony Hammitt <thammitt@kc.rr.com> wrote:
> This isn't pretty, but it works:
> y=floor(x); is equivalent to y=(double)(int)((x<0)?x-1:x);
OK, thanks for that it seems to work without hanging since
it doesn't use the troublesome instruction. Worst case I can patch
the libc source and recompile everything (yuck). This is especially
annoying since I found that the X11 server contains the same bad
instructions and recompiling that is a big undertaking on a Multia.
I'm trying a newer kernel...
- Tel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: floor() broken on Multia
2000-03-03 5:00 ` telford
@ 2000-03-03 5:00 ` Tony Hammitt
2000-03-06 5:00 ` Ryan C. Price
0 siblings, 1 reply; 9+ messages in thread
From: Tony Hammitt @ 2000-03-03 5:00 UTC (permalink / raw)
Someone emailed me and said that the given kludge has problems
with accuracy and overflow, which is kinda obvious once I think
about it.
You obviously have to limit the input range to +/-2^31 and it
would be better to subtract something less than one for the
negative case, so make it:
y = (double)(int)((x<0)?x-0.999999999999:x);
Sorry about the mixup, it was 1am after all...
Tony
telford@xenon.triode.net.au wrote:
>
> Tony Hammitt <thammitt@kc.rr.com> wrote:
> > This isn't pretty, but it works:
>
> > y=floor(x); is equivalent to y=(double)(int)((x<0)?x-1:x);
>
> OK, thanks for that it seems to work without hanging since
> it doesn't use the troublesome instruction. Worst case I can patch
> the libc source and recompile everything (yuck). This is especially
> annoying since I found that the X11 server contains the same bad
> instructions and recompiling that is a big undertaking on a Multia.
>
> I'm trying a newer kernel...
>
> - Tel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: floor() broken on Multia
2000-03-02 5:00 floor() broken on Multia telford
2000-03-03 5:00 ` Ryan C. Price
2000-03-03 5:00 ` Tony Hammitt
@ 2000-03-03 5:00 ` telford
2 siblings, 0 replies; 9+ messages in thread
From: telford @ 2000-03-03 5:00 UTC (permalink / raw)
following up myself:
> __MATH_INLINE double
> __floor (double __x)
> {
> if (__x != 0 && fabs (__x) < 9007199254740992.0) /* 1 << DBL_MANT_DIG */
> {
> double __tmp1;
> __asm (
> #ifdef _IEEE_FP_INEXACT
> "cvttq/svim %2,%1\n\t"
> #else
> "cvttq/svm %2,%1\n\t"
> #endif
> "cvtqt/m %1,%0\n\t"
> : "=f"(__x), "=&f"(__tmp1)
> : "f"(__x));
> }
> return __x;
> }
XF86_TGA also hangs from time to time, when it happens the CPU usage goes up
a lot (so there is an infinite loop somewhere) and when I come in there with
gdb, then do a disassemble around the program counter, hmm what do I see there:
cvttq/svm <floating point regs>
cvtqt/m <floating point regs>
So it seems that the same hanging thing is happening to XF86_TGA (and I'll
guess it is calling floor() somewhere) and now my Multia doesn't give me
stable X11 anymore. I'm pretty sure this used to work, so something fairly
recent has introduced this.
- Tel
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2000-03-06 5:00 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-03-02 5:00 floor() broken on Multia telford
2000-03-03 5:00 ` Ryan C. Price
2000-03-03 5:00 ` Michal Jaegermann
2000-03-06 5:00 ` telford
2000-03-03 5:00 ` Tony Hammitt
2000-03-03 5:00 ` telford
2000-03-03 5:00 ` Tony Hammitt
2000-03-06 5:00 ` Ryan C. Price
2000-03-03 5:00 ` telford
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox