SIMD support...

Walter Bright newshound2 at digitalmars.com
Fri Jan 6 16:00:51 PST 2012


On 1/6/2012 12:45 PM, Manu wrote:
> Here are some examples of tight interacting between int/float, and interacting
> ON floats with int operations...
> Naturally the examples I present will be wrapped as useful functions in
> libraries, but the primitive type shouldn't try and make this more annoying by
> trying to enforce pointless type safety errors like you seem to be suggesting.

I am suggesting it, no doubt about it!

> In computer graphics it's common to work with float16's, a type not supported by
> simd units. Pack/Unpack code involved detailed float/int interaction.
> You might take a register of floats, then mask the exponent and then perform
> integer arithmetic on the exponent to shift it into the float16 exponent
> range... then you will mask the bottom of the mantissa and shift them into place.
> Unpacking is same process in reverse.
>
> Other tricks with the float sign bits, making everything negative, by or-ing in
> 1's into the top bits. or you can gather the signs using various techniques..
> useful for identifying the cell in a quad-tree for instance.
> Integer manipulation of floats is surprisingly common.

I'm aware of such tricks, and actually do them with the floating point code 
generation in the compiler back end. I don't think that renders the idea that 
floats and ints should be different types a bad one.

I'd also argue that such tricks are tricks, and using a reinterpret cast on them 
makes it clear in the code that you know what you're doing, rather than doing 
something bizarre like a left shift on a float type.

I've worked a lot with large assembler programs. As you know, EAX has no type. 
The assembler code would constantly shift the type of things that were in EAX, 
sometimes a pointer, sometimes an int, sometimes a ushort, sometimes treating a 
pointer as an int, etc. I can unequivocably state that this typeless approach is 
confusing, buggy, hard to untangle, and ultimately a freedom that is not 
justifiable.

Static typing is a big improvement, and having to insert a few reinterpret casts 
is a good thing, not a detriment.


More information about the Digitalmars-d mailing list