[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: NaN trick
- From: David Kastrup <dak@...>
- Date: Wed, 06 Jul 2011 18:45:16 +0200
David Given <dg@cowlark.com> writes:
> Peter Cawley wrote:
> [...]
>> Though you then need to get slightly more creative about encoding the
>> type. A double has 52 bits of mantissa; with 48 taken for a
>> pointer-sized value, and 1 taken to ensure a quiet NaN, you only have
>> 3 bits left to encode the type. If you borrow the sign bit as well,
>> then you have 4 bits. For reference, the current implementation in 5.2
>> beta uses 6 bits for encoding type.
>
> If the thing you're pointing at is 4-aligned, then you get two free bits
> at the bottom of the pointer. If the thing you're pointing at has been
> allocated with malloc(), then you get more --- the result of malloc() is
> guaranteed to be correctly aligned for any kind of variable, which in
> practice usually gives you four bits.
Since an 80x86 as far as I know will accept any variable at _byte_
boundaries, the result of malloc is not guaranteed to be of any
granularity coarser than a byte. Actual implementations will likely
offer smaller granularity. But since the native floating point format
of the x86 is _10_ bytes, a granularity coarser than 2 bytes will waste
storage in full precision floating point arrays.
--
David Kastrup