[vorbis-dev] optimizing float to int conversions

Segher Boessenkool segher at kernel.crashing.org
Wed May 5 21:12:04 PDT 2004



>>>   uint32_t u1 = **(uint32_t **)a;
>>>   uint32_t u2 = **(uint32_t **)b;
>>
>> This isn't valid C (it's violating aliasing rules).
>
> heh... as if that's the least valid C of the code i sent... i'd think 
> the
> assumptions about IEEE single precision format and endianness are a bit
> more problematic than a few casts :)

Those assumptions *can* be valid (for a given target machine).
The aliasing problem makes it invalid C *always*.

> but at any rate, those are void *a, void *b ... how am i violating
> aliasing rules?  i see i dropped the const qualifier -- that's true of 
> the
> existing apsort() code as well though.

The types of the intermediate pointers don't matter at all.
It just isn't allowed to access an object of one type as
an object of another type (unless one of those types is a
character type).

> fwiw it's not possible for that routine to be inlined, it's called via
> indirect function call from qsort().

That doesn't matter a bit.  And, FYI, some compilers *are* smart
enough to inline stuff like that.

<p>Segher

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis-dev mailing list