Esempio n. 1
0
 public void Byte3_ParseFromString_ArbitarySpace(byte v0, byte v1, byte v2)
 {
     foreach (string fmt in ArbitaryWhiteSpaceFormat)
     {
         string s  = fmt.F(v0, v1, v2);
         byte3  n  = new byte3(v0, v1, v2);
         byte3  ns = byte3.Parse(s);
         Assert.That(ns, Is.EqualTo(n));
     }
 }
Esempio n. 2
0
        internal static byte3 vdiv_byte(byte3 dividend, byte3 divisor)
        {
            Assert.AreNotEqual(divisor.x, 0);
            Assert.AreNotEqual(divisor.y, 0);
            Assert.AreNotEqual(divisor.z, 0);

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

            return((byte3)(*(float3 *)&floatResult));
        }
Esempio n. 3
0
        public void Byte3_SetIndices(byte v0, byte v1, byte v2)
        {
            byte3 n = new byte3();

            n[0] = v0;
            n[1] = v1;
            n[2] = v2;
            Assert.That(n[0], Is.EqualTo(v0));
            Assert.That(n[1], Is.EqualTo(v1));
            Assert.That(n[2], Is.EqualTo(v2));
        }
Esempio n. 4
0
 public static bool all_eq(byte3 c)
 {
     if (Ssse3.IsSsse3Supported)
     {
         return(c.xxx.Equals(c));
     }
     else
     {
         return(c.x == c.y & c.x == c.z);
     }
 }
Esempio n. 5
0
 public static quarter3 asquarter(byte3 x)
 {
     if (Sse.IsSseSupported)
     {
         return((v128)x);
     }
     else
     {
         return(*(quarter3 *)&x);
     }
 }
Esempio n. 6
0
 public static byte3 avg(byte3 x, byte3 y)
 {
     if (Sse2.IsSse2Supported)
     {
         return(Sse2.avg_epu8(x, y));
     }
     else
     {
         return(new byte3((byte)((x.x + y.x + 1) >> 1), (byte)((x.y + y.y + 1) >> 1), (byte)((x.z + y.z + 1) >> 1)));
     }
 }
Esempio n. 7
0
 public static byte3 max(byte3 a, byte3 b)
 {
     if (Sse2.IsSse2Supported)
     {
         return(Sse2.max_epu8(a, b));
     }
     else
     {
         return(new byte3((byte)math.max((uint)a.x, (uint)b.x), (byte)math.max((uint)a.y, (uint)b.y), (byte)math.max((uint)a.z, (uint)b.z)));
     }
 }
Esempio n. 8
0
 public static bool any(byte3 x)
 {
     if (Sse2.IsSse2Supported)
     {
         return(0 != (bitmask32(24) & ((v128)x).UInt0));
     }
     else
     {
         return(math.any(x != 0));
     }
 }
Esempio n. 9
0
 public static bool all(byte3 x)
 {
     if (Sse2.IsSse2Supported)
     {
         return(0 == (bitmask32(24) & Sse2.cmpeq_epi8(x, default(v128)).UInt0));
     }
     else
     {
         return(math.all(x != 0));
     }
 }
Esempio n. 10
0
        public static void byte3()
        {
            Random8 rng = new Random8(135);

            for (int i = 0; i < 64; i++)
            {
                byte3 x = rng.NextByte3();

                Assert.AreEqual(new byte3((byte)_intsqrt(x.x), (byte)_intsqrt(x.y), (byte)_intsqrt(x.z)), maxmath.intsqrt(x));
            }
        }
Esempio n. 11
0
 public static byte3 andnot(byte3 left, byte3 right)
 {
     if (Sse2.IsSse2Supported)
     {
         return(Sse2.andnot_si128(right, left));
     }
     else
     {
         return(left & ~right);
     }
 }
Esempio n. 12
0
 public static byte3 subadd(byte3 a, byte3 b)
 {
     if (Ssse3.IsSsse3Supported)
     {
         return(a + Ssse3.sign_epi8(b, new byte4(255, 1, 255, 1)));
     }
     else
     {
         return(a - select(b, (byte3)(-(sbyte3)b), new bool3(false, true, false)));
     }
 }
Esempio n. 13
0
 public static uint csum(byte3 x)
 {
     if (Sse2.IsSse2Supported)
     {
         return(sad(x, byte3.zero));
     }
     else
     {
         return((uint)(x.x + x.y + x.z));
     }
 }
Esempio n. 14
0
 public static byte3 countbits(byte3 x)
 {
     if (Ssse3.IsSsse3Supported)
     {
         return((v128)countbits((byte16)(v128)x));
     }
     else
     {
         return(new byte3((byte)math.countbits((uint)x.x), (byte)math.countbits((uint)x.y), (byte)math.countbits((uint)x.z)));
     }
 }
Esempio n. 15
0
        public static void byte3()
        {
            Random8 rng = new Random8(135);

            for (int i = 0; i < 64; i++)
            {
                byte3 x = rng.NextByte3();
                byte3 y = rng.NextByte3();

                Assert.AreEqual(new byte3((byte)_gcd(x.x, y.x), (byte)_gcd(x.y, y.y), (byte)_gcd(x.z, y.z)), maxmath.gcd(x, y));
            }
        }
Esempio n. 16
0
        internal static byte3 vrem_byte(byte3 dividend, byte3 divisor)
        {
            Assert.AreNotEqual(divisor.x, 0);
            Assert.AreNotEqual(divisor.y, 0);
            Assert.AreNotEqual(divisor.z, 0);

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

            return((byte3)(castDividend - ((int3)(*(float3 *)&floatResult) * castDivisor)));
        }
Esempio n. 17
0
        public static void sbyte3()
        {
            Random8 rng = new Random8(135);

            for (int i = 0; i < 64; i++)
            {
                sbyte3 x = rng.NextSByte3();
                byte3  n = rng.NextByte3();

                Assert.AreEqual(new sbyte3((sbyte)_intpow(x.x, n.x), (sbyte)_intpow(x.y, n.y), (sbyte)_intpow(x.z, n.z)), maxmath.intpow(x, n));
            }
        }
Esempio n. 18
0
 public static byte3 divrem(byte3 dividend, byte3 divisor, out byte3 remainder)
 {
     if (Sse2.IsSse2Supported)
     {
         return(Operator.vdivrem_byte(dividend, divisor, out remainder));
     }
     else
     {
         remainder = dividend % divisor;
         return(dividend / divisor);
     }
 }
Esempio n. 19
0
 public static byte3 divrem(byte3 dividend, byte divisor, out byte3 remainder)
 {
     if (Constant.IsConstantExpression(divisor))
     {
         remainder = dividend % divisor;
         return(dividend / divisor);
     }
     else
     {
         return(divrem(dividend, (byte3)divisor, out remainder));
     }
 }
Esempio n. 20
0
        public static bool3 tobool3(int mask)
        {
            if (Avx2.IsAvx2Supported)
            {
                byte3 temp = (byte3)(1 & shrl(mask, new int3(0, 1, 2)));

                return(*(bool3 *)&temp);
            }
            else
            {
                return(tobool(1 & new byte3((byte)mask, (byte)(mask >> 1), (byte)(mask >> 2))));
            }
        }
Esempio n. 21
0
 public static bool3 ispow2(long3 x)
 {
     if (Avx2.IsAvx2Supported)
     {
         v128 result = new byte3(1) & ((byte3)(ulong3)Avx2.mm256_and_si256(Avx2.mm256_cmpgt_epi64(x, default(v256)),
                                                                           Avx2.mm256_cmpeq_epi64(default(v256), x & (x - 1))));
         return(*(bool3 *)&result);
     }
     else
     {
         return(new bool3(ispow2(x.xy), ispow2(x.z)));
     }
 }
Esempio n. 22
0
        public byte3 NextByte3(byte3 max)
        {
            if (Ssse3.IsSsse3Supported)
            {
                short3 temp = (short3)max * new short3(NextState(), NextState(), NextState());

                return(Ssse3.shuffle_epi8(temp, new byte4(1, 3, 5, 0)));
            }
            else
            {
                return((byte3)(((short3)max * new short3(NextState(), NextState(), NextState())) >> 8));
            }
        }
Esempio n. 23
0
        public static byte cmin(byte3 x)
        {
            if (Ssse3.IsSsse3Supported)
            {
                x = min(x, x.zyz);

                return(min(x, x.yyy).x);
            }
            else
            {
                return((byte)math.min((uint)x.x, math.min((uint)x.y, (uint)x.z)));
            }
        }
Esempio n. 24
0
 public static bool3 ispow2(byte3 x)
 {
     if (Sse2.IsSse2Supported)
     {
         v128 result = Sse2.and_si128(Sse2.and_si128(Operator.greater_mask_byte(x, default(v128)),
                                                     Sse2.cmpeq_epi8(default(v128), x & (x - 1))),
                                      new byte16(1));
         return(*(bool3 *)&result);
     }
     else
     {
         return(new bool3(math.ispow2((uint)x.x), math.ispow2((uint)x.y), math.ispow2((uint)x.z)));
     }
 }
        public static uint sad(byte3 a, byte3 b)
        {
            if (Sse2.IsSse2Supported)
            {
                v128 maskedA = Sse2.and_si128(a, new v128(maxmath.bitmask32(24), 0, 0, 0));
                v128 maskedB = Sse2.and_si128(b, new v128(maxmath.bitmask32(24), 0, 0, 0));

                return(Sse2.sad_epu8(maskedA, maskedB).UShort0);
            }
            else
            {
                return((uint)(math.abs(a.x - b.x) + math.abs(a.y - b.y) + math.abs(a.z - b.z)));
            }
        }
Esempio n. 26
0
        internal static byte3 vdivrem_byte(byte3 dividend, byte3 divisor, out byte3 remainder)
        {
            Assert.AreNotEqual(divisor.x, 0);
            Assert.AreNotEqual(divisor.y, 0);
            Assert.AreNotEqual(divisor.z, 0);

            int3 castDividend = dividend;
            int3 castDivisor  = divisor;
            v128 floatResult  = vdiv_byte_quotient(castDividend, castDivisor);
            int3 quotientCast = (int3)(*(float3 *)&floatResult);

            remainder = (byte3)(castDividend - quotientCast * castDivisor);
            return((byte3)quotientCast);
        }
Esempio n. 27
0
        public static byte3 gcd(byte3 x, byte3 y)
        {
            if (Sse2.IsSse2Supported)
            {
                v128 ZERO = default(v128);

                v128 result             = ZERO;
                v128 result_if_zero_any = ZERO;

                v128 x_is_zero = Sse2.cmpeq_epi8(x, ZERO);
                v128 y_is_zero = Sse2.cmpeq_epi8(y, ZERO);
                v128 any_zero  = Sse2.or_si128(x_is_zero, y_is_zero);

                result_if_zero_any = Mask.BlendV(result_if_zero_any, y, x_is_zero);
                result_if_zero_any = Mask.BlendV(result_if_zero_any, x, y_is_zero);

                v128 doneMask = any_zero;

                byte3 shift = tzcnt(x | y);

                x = shrl(x, tzcnt(x));

                do
                {
                    y = shrl(y, tzcnt(y));

                    v128 tempX = x;

                    x = Sse2.min_epu8(x, y);
                    y = Sse2.max_epu8(y, tempX);

                    y -= x;

                    v128 loopCheck = Sse2.andnot_si128(doneMask, Sse2.cmpeq_epi8(y, ZERO));
                    result   = Mask.BlendV(result, x, loopCheck);
                    doneMask = Sse2.or_si128(doneMask, loopCheck);
                } while (bitmask32(3 * sizeof(byte)) != (bitmask32(3 * sizeof(byte)) & Sse2.movemask_epi8(doneMask)));

                result = shl(result, shift);

                result = Mask.BlendV(result, result_if_zero_any, any_zero);

                return(result);
            }
            else
            {
                return(new byte3((byte)gcd((uint)x.x, (uint)y.x), (byte)gcd((uint)x.y, (uint)y.y), (byte)gcd((uint)x.z, (uint)y.z)));
            }
        }
Esempio n. 28
0
        public static void Remainder()
        {
            bool result = true;

            for (int i = 0; i < NUM_TESTS; i++)
            {
                byte3 x = TestData_LHS[i] % TestData_RHS[i];

                result &= x.x == (byte)(TestData_LHS[i].x % TestData_RHS[i].x) &
                          x.y == (byte)(TestData_LHS[i].y % TestData_RHS[i].y) &
                          x.z == (byte)(TestData_LHS[i].z % TestData_RHS[i].z);
            }

            Assert.AreEqual(true, result);
        }
Esempio n. 29
0
        public static void Cast_ToByte()
        {
            bool result = true;

            for (int i = 0; i < NUM_TESTS; i++)
            {
                byte3 x = (byte3)TestData_LHS[i];

                result &= x.x == (byte)TestData_LHS[i].x &
                          x.y == (byte)TestData_LHS[i].y &
                          x.z == (byte)TestData_LHS[i].z;
            }

            Assert.AreEqual(true, result);
        }
Esempio n. 30
0
        public static void NOT()
        {
            bool result = true;

            for (int i = 0; i < NUM_TESTS; i++)
            {
                byte3 x = ~TestData_LHS[i];

                result &= x.x == (byte)(~TestData_LHS[i].x) &
                          x.y == (byte)(~TestData_LHS[i].y) &
                          x.z == (byte)(~TestData_LHS[i].z);
            }

            Assert.AreEqual(true, result);
        }