예제 #1
0
파일: sbyte8.cs 프로젝트: csritter/MaxMath
        public sbyte8(sbyte3 x012, sbyte2 x34, sbyte3 x567)
        {
            if (Sse2.IsSse2Supported)
            {
                v128 hi = Sse2.bslli_si128(x567, 2 * sizeof(sbyte));
                if (Sse4_1.IsSse41Supported)
                {
                    hi = Sse4_1.blend_epi16(x34, hi, 0b0110);
                }
                else
                {
                    hi = Mask.BlendEpi16_SSE2(x34, hi, 0b0110);
                }
                hi = Sse2.bslli_si128(hi, 3 * sizeof(sbyte));

                this = Mask.BlendV(x012, hi, new byte8(0, 0, 0, 255, 255, 255, 255, 255));
            }
            else
            {
                this.x0 = x012.x;
                this.x1 = x012.y;
                this.x2 = x012.z;
                this.x3 = x34.x;
                this.x4 = x34.y;
                this.x5 = x567.x;
                this.x6 = x567.y;
                this.x7 = x567.z;
            }
        }
예제 #2
0
파일: sbyte8.cs 프로젝트: csritter/MaxMath
        public sbyte8(sbyte3 x012, sbyte3 x345, sbyte2 x67)
        {
            if (Sse2.IsSse2Supported)
            {
                v128 mid = Sse2.bslli_si128(x345, 3 * sizeof(sbyte));
                v128 hi  = Sse2.bslli_si128(x67, 6 * sizeof(sbyte));

                mid = Mask.BlendV(x012, mid, new byte8(0, 0, 0, 255, 255, 255, 0, 0));

                if (Sse4_1.IsSse41Supported)
                {
                    this = Sse4_1.blend_epi16(mid, hi, 0b1000);
                }
                else
                {
                    this = Mask.BlendEpi16_SSE2(mid, hi, 0b1000);
                }
            }
            else
            {
                this.x0 = x012.x;
                this.x1 = x012.y;
                this.x2 = x012.z;
                this.x3 = x345.x;
                this.x4 = x345.y;
                this.x5 = x345.z;
                this.x6 = x67.x;
                this.x7 = x67.y;
            }
        }
예제 #3
0
 public sbyte2x3(sbyte m00, sbyte m01, sbyte m02,
                 sbyte m10, sbyte m11, sbyte m12)
 {
     this.c0 = new sbyte2(m00, m10);
     this.c1 = new sbyte2(m01, m11);
     this.c2 = new sbyte2(m02, m12);
 }
예제 #4
0
파일: sbyte8.cs 프로젝트: csritter/MaxMath
        public sbyte8(sbyte2 x01, sbyte3 x234, sbyte3 x567)
        {
            if (Sse2.IsSse2Supported)
            {
                v128 mid = Sse2.bslli_si128(x234, 2 * sizeof(sbyte));
                v128 hi  = Sse2.bslli_si128(x567, 5 * sizeof(sbyte));

                hi = Mask.BlendV(mid, hi, new byte8(0, 0, 0, 0, 0, 255, 255, 255));

                if (Sse4_1.IsSse41Supported)
                {
                    this = Sse4_1.blend_epi16(x01, hi, 0b1110);
                }
                else
                {
                    this = Mask.BlendEpi16_SSE2(x01, hi, 0b1110);
                }
            }
            else
            {
                this.x0 = x01.x;
                this.x1 = x01.y;
                this.x2 = x234.x;
                this.x3 = x234.y;
                this.x4 = x234.z;
                this.x5 = x567.x;
                this.x6 = x567.y;
                this.x7 = x567.z;
            }
        }
예제 #5
0
        public static byte2 lcm(sbyte2 x, sbyte2 y)
        {
            byte2 absX = (byte2)abs(x);
            byte2 absY = (byte2)abs(y);

            return((absX / gcd(absX, absY)) * absY);
        }
예제 #6
0
        public static bool2 isdivisible(sbyte2 dividend, sbyte2 divisor)
        {
            Assert.AreNotEqual(0, divisor.x);
            Assert.AreNotEqual(0, divisor.y);

            return(dividend % divisor == 0);
        }
예제 #7
0
 public sbyte2x4(sbyte2 c0, sbyte2 c1, sbyte2 c2, sbyte2 c3)
 {
     this.c0 = c0;
     this.c1 = c1;
     this.c2 = c2;
     this.c3 = c3;
 }
예제 #8
0
 public sbyte2x4(sbyte v)
 {
     this.c0 = v;
     this.c1 = v;
     this.c2 = v;
     this.c3 = v;
 }
예제 #9
0
 public sbyte2x4(sbyte m00, sbyte m01, sbyte m02, sbyte m03,
                 sbyte m10, sbyte m11, sbyte m12, sbyte m13)
 {
     this.c0 = new sbyte2(m00, m10);
     this.c1 = new sbyte2(m01, m11);
     this.c2 = new sbyte2(m02, m12);
     this.c3 = new sbyte2(m03, m13);
 }
예제 #10
0
        internal static sbyte2 vdiv_sbyte(sbyte2 dividend, sbyte2 divisor)
        {
            Assert.AreNotEqual(divisor.x, 0);
            Assert.AreNotEqual(divisor.y, 0);

            v128 floatResult = vdiv_byte_quotient((int2)dividend, (int2)divisor);

            return((sbyte2)(*(float2 *)&floatResult));
        }
예제 #11
0
 public static quarter2 asquarter(sbyte2 x)
 {
     if (Sse.IsSseSupported)
     {
         return((v128)x);
     }
     else
     {
         return(*(quarter2 *)&x);
     }
 }
예제 #12
0
 public static sbyte2 subadd(sbyte2 a, sbyte2 b)
 {
     if (Ssse3.IsSsse3Supported)
     {
         return(a + Ssse3.sign_epi8(b, new byte2(255, 1)));
     }
     else
     {
         return(a - select(b, -b, new bool2(false, true)));
     }
 }
예제 #13
0
        internal static sbyte2 vrem_sbyte(sbyte2 dividend, sbyte2 divisor)
        {
            Assert.AreNotEqual(divisor.x, 0);
            Assert.AreNotEqual(divisor.y, 0);

            int2 castDividend = dividend;
            int2 castDivisor  = divisor;
            v128 floatResult  = vdiv_byte_quotient(castDividend, castDivisor);

            return((sbyte2)(castDividend - ((int2)(*(float2 *)&floatResult) * castDivisor)));
        }
예제 #14
0
 public static sbyte cmin(sbyte2 x)
 {
     if (Ssse3.IsSsse3Supported)
     {
         return(min(x, x.yy).x);
     }
     else
     {
         return((sbyte)math.min((int)x.x, (int)x.y));
     }
 }
예제 #15
0
 public static sbyte2 divrem(sbyte2 dividend, sbyte2 divisor, out sbyte2 remainder)
 {
     if (Sse2.IsSse2Supported)
     {
         return(Operator.vdivrem_sbyte(dividend, divisor, out remainder));
     }
     else
     {
         remainder = dividend % divisor;
         return(dividend / divisor);
     }
 }
예제 #16
0
 public static sbyte2 divrem(sbyte2 dividend, sbyte divisor, out sbyte2 remainder)
 {
     if (Constant.IsConstantExpression(divisor))
     {
         remainder = dividend % divisor;
         return(dividend / divisor);
     }
     else
     {
         return(divrem(dividend, (sbyte2)divisor, out remainder));
     }
 }
예제 #17
0
        internal static sbyte2 vdivrem_sbyte(sbyte2 dividend, sbyte2 divisor, out sbyte2 remainder)
        {
            Assert.AreNotEqual(divisor.x, 0);
            Assert.AreNotEqual(divisor.y, 0);

            int2 castDividend = dividend;
            int2 castDivisor  = divisor;
            v128 floatResult  = vdiv_byte_quotient(castDividend, castDivisor);
            int2 quotientCast = (int2)(*(float2 *)&floatResult);

            remainder = (sbyte2)(castDividend - quotientCast * castDivisor);
            return((sbyte2)quotientCast);
        }
예제 #18
0
        public static sbyte2 rol(sbyte2 x, sbyte2 n)
        {
            if (Sse2.IsSse2Supported)
            {
                n &= 7;

                return((sbyte2)(shl((byte2)x, (byte2)n) | shrl((byte2)x, (byte2)(-n & 7))));
            }
            else
            {
                return(new sbyte2(rol(x.x, n.x), rol(x.y, n.y)));
            }
        }
예제 #19
0
 public static bool2 ispow2(sbyte2 x)
 {
     if (Sse2.IsSse2Supported)
     {
         v128 result = Sse2.and_si128(Sse2.and_si128(Sse2.cmpgt_epi8(x, default(v128)),
                                                     Sse2.cmpeq_epi8(default(v128), x & (x - 1))),
                                      new sbyte16(1));
         return(*(bool2 *)&result);
     }
     else
     {
         return(new bool2(math.ispow2(x.x), math.ispow2(x.y)));
     }
 }
예제 #20
0
        public static sbyte2 compareto(byte2 x, byte2 y)
        {
            if (Sse2.IsSse2Supported)
            {
                sbyte2 xGreatery = Operator.greater_mask_byte(x, y);
                sbyte2 yGreaterx = Operator.greater_mask_byte(y, x);

                return((0 - xGreatery) + yGreaterx);
            }
            else
            {
                return(new sbyte2((sbyte)compareto(x.x, y.x),
                                  (sbyte)compareto(x.y, y.y)));
            }
        }
예제 #21
0
파일: Sign.cs 프로젝트: csritter/MaxMath
 public static sbyte2 sign(sbyte2 x)
 {
     if (Ssse3.IsSsse3Supported)
     {
         return(Ssse3.sign_epi8(new sbyte2(1), x));
     }
     else if (Sse2.IsSse2Supported)
     {
         return(((sbyte2)Sse2.cmpgt_epi8(x, default(v128)) & 1) + Sse2.cmpgt_epi8(default(v128), x));
     }
     else
     {
         return((x >> 7) | (sbyte2)((byte2)(-x) >> 7));
     }
 }
예제 #22
0
파일: Max.cs 프로젝트: csritter/MaxMath
 public static sbyte2 max(sbyte2 a, sbyte2 b)
 {
     if (Sse4_1.IsSse41Supported)
     {
         return(Sse4_1.max_epi8(a, b));
     }
     else if (Sse2.IsSse2Supported)
     {
         return(Mask.BlendV(a, b, Sse2.cmpgt_epi8(b, a)));
     }
     else
     {
         return(new sbyte2((sbyte)math.max(a.x, b.x), (sbyte)math.max(a.y, b.y)));
     }
 }
예제 #23
0
        public static sbyte2 compareto(sbyte2 x, sbyte2 y)
        {
            if (Sse2.IsSse2Supported)
            {
                sbyte2 xGreatery = Sse2.cmpgt_epi8(x, y);
                sbyte2 yGreaterx = Sse2.cmpgt_epi8(y, x);

                return((0 - xGreatery) + yGreaterx);
            }
            else
            {
                return(new sbyte2((sbyte)compareto(x.x, y.x),
                                  (sbyte)compareto(x.y, y.y)));
            }
        }
예제 #24
0
 public static sbyte2 nabs(sbyte2 x)
 {
     if (Ssse3.IsSsse3Supported)
     {
         return(Sse2.sub_epi8(default(v128), Ssse3.abs_epi8(x)));
     }
     else if (Sse2.IsSse2Supported)
     {
         return(Mask.BlendV(-x, x, Sse2.cmpgt_epi8(default(v128), x)));
     }
     else
     {
         return(new sbyte2((sbyte)nabs((int)x.x), (sbyte)nabs((int)x.y)));
     }
 }
예제 #25
0
파일: Average.cs 프로젝트: csritter/MaxMath
        public static sbyte2 avg(sbyte2 x, sbyte2 y)
        {
            short2 result = ((short2)x + (short2)y);

            // if the intermediate sum is positive add 1
            if (Sse2.IsSse2Supported)
            {
                result -= Sse2.cmpgt_epi16(result, default(v128));
            }
            else
            {
                result += toint8(result > 0);
            }

            return((sbyte2)(result >> 1));
        }
예제 #26
0
        public sbyte2 NextSByte2(sbyte2 min, sbyte2 max)
        {
            Assert.IsNotSmaller(max.x, min.x);
            Assert.IsNotSmaller(max.y, min.y);

            if (Ssse3.IsSsse3Supported)
            {
                ushort2 temp = (ushort2)(max - min) * new ushort2(NextState(), NextState());

                return(min + Ssse3.shuffle_epi8(temp, new byte4(1, 3, 0, 0)));
            }
            else
            {
                return(min + (sbyte2)(((ushort2)(max - min) * new ushort2(NextState(), NextState())) >> 8));
            }
        }
예제 #27
0
        public static sbyte2 abs(sbyte2 x)
        {
            if (Ssse3.IsSsse3Supported)
            {
                return(Ssse3.abs_epi8(x));
            }
            else if (Sse2.IsSse2Supported)
            {
                v128 mask = Sse2.cmpgt_epi8(default(v128), x);

                return((x + mask) ^ mask);
            }
            else
            {
                return(new sbyte2((sbyte)math.abs(x.x), (sbyte)math.abs(x.y)));
            }
        }
예제 #28
0
        public static sbyte2 negate(sbyte2 x, bool2 p)
        {
            Assert.IsSafeBoolean(p.x);
            Assert.IsSafeBoolean(p.y);

            if (Sse2.IsSse2Supported)
            {
                sbyte2 mask = Sse2.cmpgt_epi8(*(v128 *)&p, default(v128));

                return((x ^ mask) - mask);
            }
            else
            {
                sbyte2 mask = toint8(p);

                return((x ^ -mask) + mask);
            }
        }
예제 #29
0
파일: sbyte8.cs 프로젝트: csritter/MaxMath
 public sbyte8(sbyte2 x01, sbyte2 x23, sbyte2 x45, sbyte2 x67)
 {
     if (Sse2.IsSse2Supported)
     {
         this = new sbyte8(new sbyte4(x01, x23), new sbyte4(x45, x67));
     }
     else
     {
         this.x0 = x01.x;
         this.x1 = x01.y;
         this.x2 = x23.x;
         this.x3 = x23.y;
         this.x4 = x45.x;
         this.x5 = x45.y;
         this.x6 = x67.x;
         this.x7 = x67.y;
     }
 }
예제 #30
0
파일: sbyte8.cs 프로젝트: csritter/MaxMath
 public sbyte8(sbyte2 x01, sbyte4 x2345, sbyte2 x67)
 {
     if (Sse2.IsSse2Supported)
     {
         this = new sbyte8((sbyte4)Sse2.unpacklo_epi16(x01, x2345),
                           (sbyte4)Sse2.unpacklo_epi16(Sse2.bsrli_si128(x2345, 2 * sizeof(sbyte)), x67));
     }
     else
     {
         this.x0 = x01.x;
         this.x1 = x01.y;
         this.x2 = x2345.x;
         this.x3 = x2345.y;
         this.x4 = x2345.z;
         this.x5 = x2345.w;
         this.x6 = x67.x;
         this.x7 = x67.y;
     }
 }