[MLton] Experimental 64-bit binary package (& SVN sources)
Matthew Fluet
fluet at tti-c.org
Fri Mar 2 13:56:56 PST 2007
Daniel C. Wang wrote:
> Matthew Fluet wrote:
> {stuff deleted}
>> Word64. Unfortunately, we don't have a *bitcast* from Real32 to
>> Word32; naively emitting
>> Real32 r = ...;
>> Word32 w = (Word32)r;
>> results in coercion that attempts to preserve the numeric meaning
>> of r, rather than the bits of r. Simply more evidence that we need
>> real/word bitcast primitives.
>
> Need them in the MLton IR or the C-code?
Both. We've suggested having such primitives for better Basis Library
implementation (e.g., implementing PackReal<N> in terms of PackWord<N>,
and for floating-point predicates (isnan, etc.)); for export through
MLton.* structures (in particular, for providing efficient hash
functions on Real<N>.real); and now for supporting packing of
Real<N>.real values in datatype representations.
Of course, once you have a primitive, you need codegen support for
implementing it; for the C-codegen, that means C-code.
> This I think does the "right"
> thing in ANSIC.
> typedef union {
> Word32 asWord32;
> Reald32 asReal32;
> /* ... */
> } univ_t;
> inline Real32bitstoWord32bits(Word32 w) {
> univ_t v;
> v.asWord32 = w;
> return v.asReal32;
> }
Technically, this is undefined in C. (It is only defined to read the
most recently written union member.) However, it is a widely supported
idiom. We use this idiom to handle mis-aligned reads and writes of
Real64.real on HPPA and Sparc. (One only gets the mis-aligned accesses
if compiled with -align 4.)
More information about the MLton
mailing list