[Haskell-cafe] ANNOUNCE: storable-endian

Henning Thielemann lemming at henning-thielemann.de
Fri Dec 24 12:54:24 CET 2010

On Fri, 24 Dec 2010, Eugene Kirpichov wrote:

> I don't think I'd like to allocate memory in these functions - I
> expect them to have very predictable and very high performance.

I'm afraid on ix86 it is not possible to move a Double that is stored in 
(two 32 bit) general purpose registers over to the FPU or to an XMM 
register. That is, what happens if you read a bit pattern from memory 
while reversing the order and then converting to double is actually on 
machine level that it is written back to memory and then loaded into FPU 
or SSE unit. I'm not entirely sure, you better check the assembly code 
that your Haskell code generates.

> I'm using unsafeCoerce because it allows me to treat all these types
> in the same fashion (which is good for correctness and readability),
> and unsafeCoerce's semantics is identical to what is expected of this
> code - interpret a memory area as a value of a different type.

That's also the purpose of castPtr. It is certainly also unsafe, but not 
as unsafe, since you only convert between "dead bit patterns" and not 
between "life Haskell values". :-)

More information about the Haskell-Cafe mailing list