vector Cross/Dot using core.simd?
F i L
witte2008 at gmail.com
Sat Aug 11 18:23:45 PDT 2012
I'm trying to write a Cross and Dot function using
core.simd.float4 and DMD
The C++ code looks like:
from:
http://fastcpp.blogspot.com/2011/04/vector-cross-product-using-sse-code.html
inline __m128 CrossProduct(__m128 a, __m128 b)
{
return _mm_sub_ps (
_mm_mul_ps (
_mm_shuffle_ps(a, a, _MM_SHUFFLE(3, 0, 2, 1)),
_mm_shuffle_ps(b, b, _MM_SHUFFLE(3, 1, 0, 2))
),
_mm_mul_ps (
_mm_shuffle_ps(a, a, _MM_SHUFFLE(3, 1, 0, 2)),
_mm_shuffle_ps(b, b, _MM_SHUFFLE(3, 0, 2, 1))
)
);
}
I can see that core.simd.XMM supports a XMM.PSHUFB command I can
use with __simd(), but I'm not sure how to go about translate the
_MM_SHUFFLE() macro above.
For Dot product, I have a C# Mono.Simd function:
public static Vector4f Dot(Vector4f a, Vector4f b)
{
var result = a * b;
result = HorizontalAdd(result, result);
result = HorizontalAdd(result, result);
return result.X;
}
And I have no idea what XMM command HorizontalAdd would translate
to. But the Mono.Simd documentation says it performs:
Vector4f HorizontalAdd(Vector4f a, Vector4f b)
{
return new Vector4f (
(a.X + a.Y), (a.Z + a.W),
(b.X + b.Y), (b.Z + b.W)
);
}
Does anyone know anything about SIMD operations that may be able
to help me translate these functions into a D equivalent? I would
very much appreciate your help.
More information about the Digitalmars-d-learn
mailing list