Exemplo n.º 1
0
        public static unsafe Mat4x4 TransposeReadOnlySpan(Mat4x4 source)
        {
            Mat4x4 result = new Mat4x4();

            Mat4x4 *srcP = &source;
            Mat4x4 *resP = &result;

            float *src = (float *)srcP;
            float *res = (float *)resP;

            var avx1 = Avx.LoadVector256(src);
            var avx2 = Avx.LoadVector256(&src[8]);

            Vector256 <int> permuter;

            fixed(int *p = &pmuter.GetPinnableReference())
            {
                permuter = Avx.LoadVector256(p);
            }

            var tmp1 = Avx2.PermuteVar8x32(avx1, permuter);
            var tmp2 = Avx2.PermuteVar8x32(avx2, permuter);

            var res1 = Avx.Shuffle(tmp1, tmp2, 0b10_00_10_00);
            var res2 = Avx.Shuffle(tmp1, tmp2, 0b11_01_11_01);

            Avx.Store(&res[0], res1);
            Avx.Store(&res[8], res2);

            return(result);
        }
Exemplo n.º 2
0
        public static unsafe Mat4x4 TransposeLoadArray(Mat4x4 source)
        {
            Mat4x4 result = new Mat4x4();

            Mat4x4 *srcP = &source;
            Mat4x4 *resP = &result;

            float *src = (float *)srcP;
            float *res = (float *)resP;

            var avx1 = Avx.LoadVector256(src);
            var avx2 = Avx.LoadVector256(&src[8]);

            Vector256 <int> permuter = Avx.LoadVector256(tranpose_permuter);

            var tmp1 = Avx2.PermuteVar8x32(avx1, permuter);
            var tmp2 = Avx2.PermuteVar8x32(avx2, permuter);

            var res1 = Avx.Shuffle(tmp1, tmp2, 0b10_00_10_00);
            var res2 = Avx.Shuffle(tmp1, tmp2, 0b11_01_11_01);

            Avx.Store(&res[0], res1);
            Avx.Store(&res[8], res2);

            return(result);
        }