ldc-developers/ldc — pull request #151 by jerro (2012-08-05 17:40:53+00:00)
Title: Add pragma shufflevector

This adds pragma shufflevector to support shuffling elements in SIMD vectors. It is used like that:

pragma(shufflevector)
float4 shufflevector(float4, float4, int, int, int, int);

// This will compile to shufps instruction when using SSE
static auto shufps(int m0, int m1, int m2, int m3)(float4 a, float4 b)
{
return shufflevector(a, b, m3, m2, m1 + 4, m0 + 4);
}

Without support for LLVM shufflevector instruction there is no clean way to support some SIMD instructions in LDC. AFAIK LLVM only defines intrinsics for operations that can't be achieved through other means such as shufflevector or vector addition, subtraction etc. Shufflevector is also what Clang uses to implement SIMD intrinsics, as you can see [here](http://llvm.org/svn/llvm-project/cfe/trunk/lib/Headers/xmmintrin.h), for example.

I am new to LDC, the DMD frontend and LLVM, so it would probably be a good idea to carefully review this code before merging. I have, however, tried it on my code [here](https://github.com/jerro/pfft/tree/ldc-shufflevector) (files pfft/sse_float.d and pfft/sse_double.d use shufflevector) and it seems to work fine.