#4867: ghci displays negative floats incorrectly (was: Incorrect result from
trig
functions)
-------------------------------+--------------------------------------------
Reporter: gwright | Owner: gwright
Type: bug | Status: new
Priority: high | Milestone: 7.0.2
Component: GHCi | Version: 7.0.1
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: MacOS X | Blocking:
Architecture: x86_64 (amd64) | Failure: Incorrect result at runtime
-------------------------------+--------------------------------------------
Comment(by gwright):
Some progress -- I've seen the error occur in `gdb`. I start up gdb,
source the gdbinit macros and my gdb_ghc script. I still set a breakpoint
on the `tanh` function, as that makes it easier to get close to the bug.
After entering
{{{
Prelude> tanh(-1.0)
}}}
and hitting the breakpoint, I set a watchpoint on `$xmm0` and stepped 4000
machine instructions. Then I single stepped displaying each instruction.
Eventually I found:
{{{
0x000000010524a8e2 in ?? ()
1: x/i $rip 0x10524a8e2: movsd 0x281b7c(%rip),%xmm7 #
0x1054cc466
(gdb)
0x000000010524a8ea in ?? ()
1: x/i $rip 0x10524a8ea: xorpd %xmm7,%xmm0
(gdb)
Watchpoint 2: $xmm0
Old value = {
v4_float = {0, 0, -1.81539845, -5.54887492e-07},
v2_double = {0, -0.76159415595576485},
v16_int8 = {0, 0, 0, 0, 0, 0, 0, 0, -65, -24, 94, -6, -75, 20, -13,
-108},
v8_int16 = {0, 0, 0, 0, -16408, 24314, -19180, -3180},
v4_int32 = {0, 0, -1075290374, -1256918124},
v2_int64 = {0, -4618336986995559532},
uint128 = 10732945108776183999
}
New value = {
v4_float = {0, 0, 2.22554744e-27, -3.5318561e+37},
v2_double = {0, 2.9599490498307242e-216},
v16_int8 = {0, 0, 0, 0, 0, 0, 0, 0, 19, 48, 83, 119, -3, -44, -112,
-36},
v8_int16 = {0, 0, 0, 0, 4912, 21367, -556, -28452},
v4_int32 = {0, 0, 321934199, -36400932},
v2_int64 = {0, 1382696860427522268},
uint128 = 15893437270084235283
}
}}}
This ghci trying to negate the value in `$xmm0`. (IEEE 754 uses a sign &
magnitude representation; the canonical way to negate a floating value is
to `XOR` it with the sign bit mask.) After the xor, `$xmm0` contains the
incorrect value I see output from `ghci`.
What can be concluded is that the sign mask loaded into `$xmm7` is wrong.
It is:
{{{
(gdb) p $xmm7
$1 = {
v4_float = {0, 0, -6.14059368e-12, 394010.25},
v2_double = {0, -1.1531066037009445e-92},
v16_int8 = {0, 0, 0, 0, 0, 0, 0, 0, -84, -40, 13, -115, 72, -64, 99,
72},
v8_int16 = {0, 0, 0, 0, -21288, 3469, 18624, 25416},
v4_int32 = {0, 0, -1395126899, 1220567880},
v2_int64 = {0, -5992024403754327224},
uint128 = 5216224211261839532
}
(gdb) p/x $xmm7
$2 = {
v4_float = {0x0.000000p+0, 0x0.000000p+0, -0x1.b01b1ap-38,
0x1.80c690p+18},
v2_double = {0x0.0000000000000p+0, -0x1.80d8d48c06348p-306},
v16_int8 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xac, 0xd8, 0xd,
0x8d, 0x48, 0xc0, 0x63, 0x48},
v8_int16 = {0x0, 0x0, 0x0, 0x0, 0xacd8, 0xd8d, 0x48c0, 0x6348},
v4_int32 = {0x0, 0x0, 0xacd80d8d, 0x48c06348},
v2_int64 = {0x0, 0xacd80d8d48c06348},
uint128 = 0x4863c0488d0dd8ac0000000000000000
}
(gdb) p/u $xmm7
$3 = {
v4_float = {0, 0, 0, 394010},
v2_double = {0, 0},
v16_int8 = {0, 0, 0, 0, 0, 0, 0, 0, 172, 216, 13, 141, 72, 192, 99, 72},
v8_int16 = {0, 0, 0, 0, 44248, 3469, 18624, 25416},
v4_int32 = {0, 0, 2899840397, 1220567880},
v2_int64 = {0, 12454719669955224392},
uint128 = 96222353056234618556517257475063283712
}
}}}
It's not obvious what's being loaded into `$xmm7`. There are 16 files
containing the "load xmm7 relative to the instruction pointer, xor with
xmm0", 113 places total. Could be a static data alignment error or the
linker could be wee-hawed.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4867#comment:17>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs