ldc-developers/druntime — pull request #3 by jerro (2012-11-16 18:27:19+00:00)
Title: Added ldc.simd

This pull request adds a new module named ldc.simd. This module contains some SIMD templates that can't be implemented using x86 builtins. These functions are needed to implement libraries such as std.simd.

The functions in this module are:

* shufflevector: This function provides access to [LLVM's shufflevector instruction](http://llvm.org/docs/LangRef.html#i_shufflevector). Usage:
```d
int4 a, b;
int4 c = shufflevector!(int4, 0, 2, 4, 6)(a, b);
```

* insertelement: This function provides access to [LLVM's insertelement instruction](http://llvm.org/docs/LangRef.html#i_insertelement). Usage:
```d
int4 a;
int k;
int4 b = insertelement!(int4, 2)(a, k);
```

* extractelement: This function provides access to [LLVM's extractelement instruction](http://llvm.org/docs/LangRef.html#i_extractelement). Usage:
```d
int4 a;
int k = extractelement!(int4, 2)(a);
```

* loadUnaligned: Loads a vector from an unaligned pointer. Usage:
```d
int* p;
int4 a = loadUnaligned!int4(p);
```

* equalMask, notEqualMask, greaterMask, greaterOrEqualMask. These functions perform an element-wise comparison between two vectors and return a vector with signed integral elements. The number of elements in the returned vector and their size is the same as in parameter vectors. If the condition in the name of the function holds for elements of the parameter vectors at a given index, all bits of the element of the result at that index are set to 1, otherwise the element of the result is zero. Usage:
```d
float4 a, b;
// equivalent to doing c.array[i] = a.array[i] > b.array[i] ? 0xffff_ffff : 0 for all elements
int4 c = greaterMask!int4(a, b);
```

I have a fork of TurkeyMan's std.simd that is implemented using this module and the intrinsics in ldc.gccbuiltins_x86 (and no other language extensions) [here](https://github.com/jerro/phobos/blob/use-ldc.simd/std/simd.d). I'm testing it with [this file](https://github.com/jerro/std.simd-tests/blob/master/test.d). The tests for all the functions that use ldc.simd pass.