On Wed, Nov 19, 2008 at 4:23 PM, crashfourit <[EMAIL PROTECTED]> 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?
_______________________________________________ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list