[Mono-dev] mono.simd sugestions
Rodrigo Kumpera
kumpera at gmail.com
Wed Nov 19 20:12:00 EST 2008
On Wed, Nov 19, 2008 at 4:23 PM, crashfourit <crashfourit at gmail.com> wrote:
>
>
> It would be nice to have the vector* have a constructor that takes in only
> one argument and fills all spots in the vector* with the same value.
> Like...
> Vector4f vector = new Vector4f(1);
>
> Second... I can really see someone doing this to use mono.simd in already
> established code base.
>
> [StructLayout( LayoutKind.Sequential, Pack = 0, Size = 16 )]
> class Vector4 {
>
> /*
> some user defined vector methods.
> ..........
> */
>
> private static explicit operator Vector4f(Vector4 v){
> unsafe {
> Vector4f* p = (Vector4f*) &v;
> return *p;
> }
> }
>
> private static explicit operator Vector4(Vector4f v){
> unsafe {
> Vector4* p = (Vector4*) &v;
> return *p;
> }
> }
> }
>
> Is it possible to accelerate these user defined operator overloads? Or do I
> have to resort to C# style unions?
> --
>
>
This code will be inlined and work like a charm. But I recommend coding it
in the following way to
squeeze the maximum performance out of it:
public static unsafe Vector4f AsVector(ref Vector4 v){
fixed (Vector4 *f = &v) {
return *(Vector4f*)f;
}
}
This will avoid the extra copy of passing the valuetype by value on stack
and will inline straight to a load from the
load/array element to a simd machine register. Pretty cool, isn't it?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20081119/445c4c8c/attachment.html
More information about the Mono-devel-list
mailing list