Ejemplo n.º 1
0
        public static int first(bool32 x)
        {
            Assert.IsSafeBoolean(x.x0);

            Assert.IsSafeBoolean(x.x1);
            Assert.IsSafeBoolean(x.x2);
            Assert.IsSafeBoolean(x.x3);
            Assert.IsSafeBoolean(x.x4);
            Assert.IsSafeBoolean(x.x5);
            Assert.IsSafeBoolean(x.x6);
            Assert.IsSafeBoolean(x.x7);
            Assert.IsSafeBoolean(x.x8);
            Assert.IsSafeBoolean(x.x9);
            Assert.IsSafeBoolean(x.x10);
            Assert.IsSafeBoolean(x.x11);
            Assert.IsSafeBoolean(x.x12);
            Assert.IsSafeBoolean(x.x13);
            Assert.IsSafeBoolean(x.x14);
            Assert.IsSafeBoolean(x.x15);
            Assert.IsSafeBoolean(x.x16);
            Assert.IsSafeBoolean(x.x17);
            Assert.IsSafeBoolean(x.x18);
            Assert.IsSafeBoolean(x.x19);
            Assert.IsSafeBoolean(x.x20);
            Assert.IsSafeBoolean(x.x21);
            Assert.IsSafeBoolean(x.x22);
            Assert.IsSafeBoolean(x.x23);
            Assert.IsSafeBoolean(x.x24);
            Assert.IsSafeBoolean(x.x25);
            Assert.IsSafeBoolean(x.x26);
            Assert.IsSafeBoolean(x.x27);
            Assert.IsSafeBoolean(x.x28);
            Assert.IsSafeBoolean(x.x29);
            Assert.IsSafeBoolean(x.x30);
            Assert.IsSafeBoolean(x.x31);

            if (Avx2.IsAvx2Supported)
            {
                return(math.tzcnt(Avx2.mm256_movemask_epi8(Avx2.mm256_slli_epi16(x, 7))));
            }
            else if (Sse2.IsSse2Supported)
            {
                return(math.tzcnt(Sse2.movemask_epi8(Sse2.slli_epi16(x._v16_0, 7)) | (Sse2.movemask_epi8(Sse2.slli_epi16(x._v16_16, 7)) << 16)));
            }
            else
            {
                int first16 = first(x.v16_0);

                if (first16 == 32)
                {
                    int last16 = first(x.v16_16);

                    return(last16 == 32 ? 32 : 16 + last16);
                }
                else
                {
                    return(first16);
                }
            }
        }
Ejemplo n.º 2
0
        public static void Bool32()
        {
            bool result = true;

            Random64 rng = new Random64(RNG_SEED);

            for (int i = 0; i < NUM_TESTS; i++)
            {
                bool32 x = new bool32(rng.NextBool8(), rng.NextBool8(), rng.NextBool8(), rng.NextBool8());

                int test = 0;

                for (int j = 0; j < 32; j++)
                {
                    if (x[j])
                    {
                        test++;
                    }
                }

                result &= test == maxmath.count(x);
            }

            Assert.AreEqual(true, result);
        }
Ejemplo n.º 3
0
        public bool32 NextBool32()
        {
            bool32 result = ((Random64)this).NextBool32();

            NextState();

            return(result);
        }
Ejemplo n.º 4
0
 public static bool all(bool32 x)
 {
     if (Avx2.IsAvx2Supported)
     {
         return(uint.MaxValue == (uint)Avx2.mm256_movemask_epi8(Avx2.mm256_slli_epi16(x, 7)));
     }
     else
     {
         return(all(x.v16_0) & all(x.v16_16));
     }
 }
Ejemplo n.º 5
0
 public static bool any(bool32 x)
 {
     if (Avx2.IsAvx2Supported)
     {
         return(Avx2.mm256_movemask_epi8(Avx2.mm256_slli_epi16(x, 7)) != 0);
     }
     else
     {
         return(any(x.v16_0) | any(x.v16_16));
     }
 }
Ejemplo n.º 6
0
        public static void SByte32()
        {
            bool     result = true;
            Random64 x      = new Random64(47);

            for (int i = 0; i < Tests.SByte32.NUM_TESTS; i++)
            {
                bool32  b = x.NextBool32();
                sbyte32 a = maxmath.negate(Tests.SByte32.TestData_LHS[i], b);

                result &= maxmath.all(a == maxmath.select(Tests.SByte32.TestData_LHS[i], -Tests.SByte32.TestData_LHS[i], b));
            }

            Assert.AreEqual(true, result);
        }
Ejemplo n.º 7
0
 public static byte32 touint8safe(bool32 x)
 {
     if (Avx2.IsAvx2Supported)
     {
         return(clamp((byte32)(v256)x, 0, 1));
     }
     else if (Sse2.IsSse2Supported)
     {
         return(clamp(new byte32((v128)x.v16_0, (v128)x.v16_16), 0, 1));
     }
     else
     {
         return(clamp(*(byte32 *)&x, 0, 1));
     }
 }
Ejemplo n.º 8
0
        public static sbyte32 negate(sbyte32 x, bool32 p)
        {
            Assert.IsSafeBoolean(p.x0);
            Assert.IsSafeBoolean(p.x1);
            Assert.IsSafeBoolean(p.x2);
            Assert.IsSafeBoolean(p.x3);
            Assert.IsSafeBoolean(p.x4);
            Assert.IsSafeBoolean(p.x5);
            Assert.IsSafeBoolean(p.x6);
            Assert.IsSafeBoolean(p.x7);
            Assert.IsSafeBoolean(p.x8);
            Assert.IsSafeBoolean(p.x9);
            Assert.IsSafeBoolean(p.x10);
            Assert.IsSafeBoolean(p.x11);
            Assert.IsSafeBoolean(p.x12);
            Assert.IsSafeBoolean(p.x13);
            Assert.IsSafeBoolean(p.x14);
            Assert.IsSafeBoolean(p.x15);
            Assert.IsSafeBoolean(p.x16);
            Assert.IsSafeBoolean(p.x17);
            Assert.IsSafeBoolean(p.x18);
            Assert.IsSafeBoolean(p.x19);
            Assert.IsSafeBoolean(p.x20);
            Assert.IsSafeBoolean(p.x21);
            Assert.IsSafeBoolean(p.x22);
            Assert.IsSafeBoolean(p.x23);
            Assert.IsSafeBoolean(p.x24);
            Assert.IsSafeBoolean(p.x25);
            Assert.IsSafeBoolean(p.x26);
            Assert.IsSafeBoolean(p.x27);
            Assert.IsSafeBoolean(p.x28);
            Assert.IsSafeBoolean(p.x29);
            Assert.IsSafeBoolean(p.x30);
            Assert.IsSafeBoolean(p.x31);

            if (Avx2.IsAvx2Supported)
            {
                sbyte32 mask = Avx2.mm256_cmpgt_epi8(p, default(v256));

                return((x ^ mask) - mask);
            }
            else
            {
                return(new sbyte32(negate(x.v16_0, p.v16_0), negate(x.v16_16, p.v16_16)));;
            }
        }
Ejemplo n.º 9
0
        public static uint count(bool32 x)
        {
            Assert.IsSafeBoolean(x.x0);

            Assert.IsSafeBoolean(x.x1);
            Assert.IsSafeBoolean(x.x2);
            Assert.IsSafeBoolean(x.x3);
            Assert.IsSafeBoolean(x.x4);
            Assert.IsSafeBoolean(x.x5);
            Assert.IsSafeBoolean(x.x6);
            Assert.IsSafeBoolean(x.x7);
            Assert.IsSafeBoolean(x.x8);
            Assert.IsSafeBoolean(x.x9);
            Assert.IsSafeBoolean(x.x10);
            Assert.IsSafeBoolean(x.x11);
            Assert.IsSafeBoolean(x.x12);
            Assert.IsSafeBoolean(x.x13);
            Assert.IsSafeBoolean(x.x14);
            Assert.IsSafeBoolean(x.x15);
            Assert.IsSafeBoolean(x.x16);
            Assert.IsSafeBoolean(x.x17);
            Assert.IsSafeBoolean(x.x18);
            Assert.IsSafeBoolean(x.x19);
            Assert.IsSafeBoolean(x.x20);
            Assert.IsSafeBoolean(x.x21);
            Assert.IsSafeBoolean(x.x22);
            Assert.IsSafeBoolean(x.x23);
            Assert.IsSafeBoolean(x.x24);
            Assert.IsSafeBoolean(x.x25);
            Assert.IsSafeBoolean(x.x26);
            Assert.IsSafeBoolean(x.x27);
            Assert.IsSafeBoolean(x.x28);
            Assert.IsSafeBoolean(x.x29);
            Assert.IsSafeBoolean(x.x30);
            Assert.IsSafeBoolean(x.x31);

            if (Avx2.IsAvx2Supported)
            {
                return((uint)math.countbits(Avx2.mm256_movemask_epi8(Avx2.mm256_slli_epi16(x, 7))));
            }
            else
            {
                return(count(x.v16_0) + count(x.v16_16));
            }
        }
Ejemplo n.º 10
0
        public static void SByte32()
        {
            bool result = true;

            for (int i = 0; i < Tests.SByte32.NUM_TESTS; i++)
            {
                bool32 t = maxmath.ispow2(Tests.SByte32.TestData_LHS[i]);

                result &= t.x0 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x0);
                result &= t.x1 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x1);
                result &= t.x2 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x2);
                result &= t.x3 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x3);
                result &= t.x4 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x4);
                result &= t.x5 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x5);
                result &= t.x6 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x6);
                result &= t.x7 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x7);
                result &= t.x8 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x8);
                result &= t.x9 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x9);
                result &= t.x10 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x10);
                result &= t.x11 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x11);
                result &= t.x12 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x12);
                result &= t.x13 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x13);
                result &= t.x14 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x14);
                result &= t.x15 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x15);
                result &= t.x16 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x16);
                result &= t.x17 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x17);
                result &= t.x18 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x18);
                result &= t.x19 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x19);
                result &= t.x20 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x20);
                result &= t.x21 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x21);
                result &= t.x22 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x22);
                result &= t.x23 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x23);
                result &= t.x24 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x24);
                result &= t.x25 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x25);
                result &= t.x26 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x26);
                result &= t.x27 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x27);
                result &= t.x28 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x28);
                result &= t.x29 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x29);
                result &= t.x30 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x30);
                result &= t.x31 == math.ispow2((int)Tests.SByte32.TestData_LHS[i].x31);
            }

            Assert.AreEqual(true, result);
        }
Ejemplo n.º 11
0
        public static int bitmask(bool32 x)
        {
            if (Avx2.IsAvx2Supported)
            {
                Assert.IsSafeBoolean(x.x0);
                Assert.IsSafeBoolean(x.x1);
                Assert.IsSafeBoolean(x.x2);
                Assert.IsSafeBoolean(x.x3);
                Assert.IsSafeBoolean(x.x4);
                Assert.IsSafeBoolean(x.x5);
                Assert.IsSafeBoolean(x.x6);
                Assert.IsSafeBoolean(x.x7);
                Assert.IsSafeBoolean(x.x8);
                Assert.IsSafeBoolean(x.x9);
                Assert.IsSafeBoolean(x.x10);
                Assert.IsSafeBoolean(x.x11);
                Assert.IsSafeBoolean(x.x12);
                Assert.IsSafeBoolean(x.x13);
                Assert.IsSafeBoolean(x.x14);
                Assert.IsSafeBoolean(x.x15);
                Assert.IsSafeBoolean(x.x16);
                Assert.IsSafeBoolean(x.x17);
                Assert.IsSafeBoolean(x.x18);
                Assert.IsSafeBoolean(x.x19);
                Assert.IsSafeBoolean(x.x20);
                Assert.IsSafeBoolean(x.x21);
                Assert.IsSafeBoolean(x.x22);
                Assert.IsSafeBoolean(x.x23);
                Assert.IsSafeBoolean(x.x24);
                Assert.IsSafeBoolean(x.x25);
                Assert.IsSafeBoolean(x.x26);
                Assert.IsSafeBoolean(x.x27);
                Assert.IsSafeBoolean(x.x28);
                Assert.IsSafeBoolean(x.x29);
                Assert.IsSafeBoolean(x.x31);
                Assert.IsSafeBoolean(x.x30);

                return(Avx2.mm256_movemask_epi8(Avx2.mm256_slli_epi16(x, 7)));
            }
            else
            {
                return(bitmask(x.v16_0) | (bitmask(x.v16_16) << 16));
            }
        }
Ejemplo n.º 12
0
        public static void Bool32()
        {
            Random32 rng = new Random32(RNG_SEED);

            bool result = true;

            for (int i = 0; i < NUM_TESTS; i++)
            {
                int    r = rng.NextInt();
                bool32 x = maxmath.tobool32(r);

                for (int j = 0; j < 32; j++)
                {
                    result &= x[j] == System.Convert.ToBoolean((r >> j) & 1);
                }
            }

            Assert.AreEqual(true, result);
        }
Ejemplo n.º 13
0
        public static void Bool32()
        {
            bool result = true;

            Random64 rng = new Random64(RNG_SEED);

            for (int i = 0; i < NUM_TESTS; i++)
            {
                bool32 x = new bool32(rng.NextBool8(), rng.NextBool8(), rng.NextBool8(), rng.NextBool8());

                int test = maxmath.first(x);

                int j = 0;
                while (j < 32 && !x[j])
                {
                    j++;
                }

                result &= test == j;
            }

            Assert.AreEqual(result && maxmath.first(default(bool32)) == 32, true);
        }