Пример #1
0
        public static short16 negate(short16 x, bool16 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);

            if (Avx2.IsAvx2Supported)
            {
                short16 mask = (sbyte16)Sse2.cmpgt_epi8(p, default(v128));

                return((x ^ mask) - mask);
            }
            else
            {
                return(new short16(negate(x.v8_0, p.v8_0), negate(x.v8_8, p.v8_8)));
            }
        }
Пример #2
0
        public static uint count(bool16 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);

            if (Sse2.IsSse2Supported)
            {
                return((uint)math.countbits(Sse2.movemask_epi8(Sse2.slli_epi16(x, 7))));
            }
            else
            {
                return(count(x.v8_0) + count(x.v8_8));
            }
        }
Пример #3
0
        public static sbyte16 negate(sbyte16 x, bool16 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);

            if (Sse2.IsSse2Supported)
            {
                sbyte16 mask = Sse2.cmpgt_epi8(p, default(v128));

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

                return((x ^ -mask) + mask);
            }
        }
Пример #4
0
        public static int bitmask(bool16 x)
        {
            if (Sse2.IsSse2Supported)
            {
                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);

                return(Sse2.movemask_epi8(Sse2.slli_epi16(x, 7)));
            }
            else
            {
                return((((toint32(x.x0) | (toint8(x.x1) << 1)) + ((toint8(x.x2) << 2) | (toint8(x.x3) << 3))) + (((toint8(x.x4) << 4) | (toint8(x.x5) << 5)) + ((toint8(x.x6) << 6) | (toint8(x.x7) << 7)))) + ((((toint8(x.x8) << 8) | (toint8(x.x9) << 9)) + ((toint8(x.x10) << 10) | (toint8(x.x11) << 11))) + (((toint8(x.x12) << 12) | (toint8(x.x13) << 13)) + ((toint8(x.x14) << 14) | (toint8(x.x15) << 15)))));
            }
        }
Пример #5
0
        public bool16 NextBool16()
        {
            bool16 result = ((Random64)this).NextBool16();

            NextState();

            return(result);
        }
Пример #6
0
 public static bool all(bool16 x)
 {
     if (Sse2.IsSse2Supported)
     {
         return(maxmath.bitmask32(16) == Sse2.movemask_epi8(Sse2.slli_epi16(x, 7)));
     }
     else
     {
         return(all(x.v8_0) & all(x.v8_8));
     }
 }
Пример #7
0
 public static bool any(bool16 x)
 {
     if (Sse2.IsSse2Supported)
     {
         return(Sse2.movemask_epi8(Sse2.slli_epi16(x, 7)) != 0);
     }
     else
     {
         return(any(x.v8_0) | any(x.v8_8));
     }
 }
Пример #8
0
 public static byte16 touint8safe(bool16 x)
 {
     if (Sse2.IsSse2Supported)
     {
         return(clamp((byte16)(v128)x, 0, 1));
     }
     else
     {
         return(clamp(*(byte16 *)&x, 0, 1));
     }
 }
Пример #9
0
 public static short16 toint16safe(bool16 x)
 {
     if (Avx2.IsAvx2Supported)
     {
         return((short16)clamp((byte16)(v128)x, 0, 1));
     }
     else if (Sse2.IsSse2Supported)
     {
         return(new short16((short8)clamp((byte8)(v128)x.v8_0, 0, 1), (short8)clamp((byte8)(v128)x.v8_8, 0, 1)));
     }
     else
     {
         return((short16)clamp(*(byte16 *)&x, 0, 1));
     }
 }
Пример #10
0
        public static int first(bool16 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);

            if (Sse2.IsSse2Supported)
            {
                return(math.tzcnt(Sse2.movemask_epi8(Sse2.slli_epi16(x, 7))));
            }
            else
            {
                int first8 = first(x.v8_0);

                if (first8 == 8)
                {
                    int last8 = first(x.v8_8);

                    return(last8 == 8 ? 32 : 8 + last8);
                }
                else
                {
                    return(first8);
                }
            }
        }
Пример #11
0
        public static int last(bool16 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);

            if (Sse2.IsSse2Supported)
            {
                return(31 - math.lzcnt(Sse2.movemask_epi8(Sse2.slli_epi16(x, 7))));
            }
            else
            {
                int last8 = last(x.v8_8);

                if (last8 != -1)
                {
                    return(8 + last8);
                }
                else
                {
                    return(last(x.v8_0));
                }
            }
        }