primitive vector types

Denis Koroskin 2korden at gmail.com
Thu Feb 19 16:01:08 PST 2009


On Thu, 19 Feb 2009 23:05:34 +0300, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:

> Denis Koroskin wrote:
>> On Thu, 19 Feb 2009 22:25:04 +0300, Mattias Holm  
>> <hannibal.holm at gmail.com> wrote:
>>
>>> Since (SIMD) vectors are so common and every reasonabe system support  
>>> them in one way or the other (and scalar emulation of this is rather  
>>> simple), why not have support for this in D directly?
>>>
>>> Yes, the array operations are nice (and one of the main reasons for  
>>> why I like D :) ), but have the problem that an array of floats must  
>>> be aligned on float boundaries and not vector boundaries. In my mind  
>>> vectors are a primitive data type that should be exposed by the  
>>> programming language.
>>>
>>> Something OpenCL-like:
>>>
>>>     float4 vec;
>>>     vec.xyzw = {1.0,1.0, 1.0, 1.0}; // assignment
>>>     vec.xyzw = vec.wyxz; // permutation
>>>     vec[i] = 1.0; // indexing
>>>
>>> And then we can easily immagine some extra nice features to have with  
>>> respect to operators:
>>>
>>>     vec ^ vec2; // 3d cross product for float vectors, for int vectors  
>>> xor
>>>
>>> Has this been discussed before?
>>>
>>> / Mattias
>>>
>>  I don't see any reason why float4 can't be made a library type.
>
> Yah, I was thinking the same:
>
> struct float4
> {
>      __align(16) float[4] data; // right syntax and value?
>      alias data this;
> }
>
> This looks like something that should go into std.matrix pronto. It even  
> has value semantics even though fixed arrays don't :o/.
>
>
> Andrei

That would be great. If float4 gets its way into D, I'll share our blazing fast math code with community (most common operations on vectors, matrices, quaternions etc). It is written entirely in SSE (intrinsics, not asm; there is a problem with inlining asm in D, IIRC. Can anyone elaborate on this?) and *very* fast. According to our benchmarks, that's the best we get squeeze out of hardware.

I know LLVM have support for *very* wide range of intrinsics:
http://www.cs.ucla.edu/classes/spring08/cs259/llvm-2.2/include/llvm/Intrinsics.gen

Hopefully they will get into LDC (and DMD *hint* Walter *hint*) very soon.




More information about the Digitalmars-d mailing list