[GHC] #9035: ghci sometimes displays Word32 as Word64

GHC ghc-devs at haskell.org
Mon May 19 03:42:14 UTC 2014


#9035: ghci sometimes displays Word32 as Word64
------------------------------------------------+--------------------------
        Reporter:  MikeIzbicki                  |            Owner:
            Type:  bug                          |           Status:  closed
        Priority:  normal                       |        Milestone:
       Component:  GHCi                         |          Version:  7.8.2
      Resolution:  invalid                      |         Keywords:
Operating System:  Linux                        |     Architecture:  x86_64
 Type of failure:  Incorrect result at runtime  |  (amd64)
       Test Case:                               |       Difficulty:
        Blocking:                               |  Unknown
                                                |       Blocked By:
                                                |  Related Tickets:
------------------------------------------------+--------------------------

Comment (by carter):

 you can't do an unsafe coerce  between Words and Floats in ghc currently
 and have it be well defined . Its got nothing to do with boxing, it has to
 do with Floats and Words actually living is completely distinct groups of
 registers in the CPU. eg on x86, ghc currently only manipulates words in
 the general purpose registers, and floats are in SSE registers.

 (yes, there ARE word manipulation sse instructions, but ghc currently
 doesn't use them.. yet)

 NH2 wrote a cute wee lib to cast between float and words
 https://github.com/nh2/float-cast, which works by writing the input to
 memory as one type, and reading the memory location back as the other
 type. I think the only reason some of your code works at all is your
 unsafe coerce actually will by accident do that "casted memory read" off
 the heap.


 The other issue is your Word32 is actually going to be 64bit (1 whoel
 register) value on 64 bit systems, but Floats are always 32b bits, and
 your unsafe coerce doesn't actually have any well defined way of mapping
 between the two. Again, anything resembling that working in current GHC is
 actually a complete "this is undefined" accident :)

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9035#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list