[Mono-dev] mono.simd sugestions

crashfourit crashfourit at gmail.com
Thu Nov 20 18:15:13 EST 2008




Rodrigo Kumpera wrote:
> 
> 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?
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 
> 
How will the jit engine handle this?
    public static unsafe Vector4 AsVector4(ref Vector4f v){
        fixed (Vector4f *f = &v) {
            return *(Vector4*)f;
        }
    }
-- 
View this message in context: http://www.nabble.com/mono.simd-sugestions-tp20586082p20612136.html
Sent from the Mono - Dev mailing list archive at Nabble.com.



More information about the Mono-devel-list mailing list