예제 #1
0
 public ulong2x3(ulong m00, ulong m01, ulong m02,
                 ulong m10, ulong m11, ulong m12)
 {
     this.c0 = new ulong2(m00, m10);
     this.c1 = new ulong2(m01, m11);
     this.c2 = new ulong2(m02, m12);
 }
예제 #2
0
 public ulong2x4(ulong v)
 {
     this.c0 = v;
     this.c1 = v;
     this.c2 = v;
     this.c3 = v;
 }
예제 #3
0
 public ulong2x4(ulong2 c0, ulong2 c1, ulong2 c2, ulong2 c3)
 {
     this.c0 = c0;
     this.c1 = c1;
     this.c2 = c2;
     this.c3 = c3;
 }
예제 #4
0
        internal static v128 greater_mask_ulong(ulong2 left, ulong2 right)
        {
            if (Sse4_1.IsSse41Supported)
            {
                ulong2 mask = 1ul << 63;

                return(Operator.greater_mask_long(Sse2.xor_si128(left, mask),
                                                  Sse2.xor_si128(right, mask)));
            }
            else if (Sse2.IsSse2Supported)
            {
                v128 mask32 = new v128(1u << 31);

                v128 equal32  = Sse2.cmpeq_epi32(left, right);
                v128 larger32 = Sse2.cmpgt_epi32(Sse2.xor_si128(left, mask32),
                                                 Sse2.xor_si128(right, mask32));

                v128 equal64  = Sse2.and_si128(equal32, Sse2.shuffle_epi32(larger32, Sse.SHUFFLE(2, 2, 0, 0)));
                v128 larger64 = Sse2.or_si128(larger32, equal64);

                return(Sse2.shuffle_epi32(larger64, Sse.SHUFFLE(3, 3, 1, 1)));
            }
            else
            {
                throw new CPUFeatureCheckException();
            }
        }
예제 #5
0
        public static ulong2 lcm(long2 x, long2 y)
        {
            ulong2 absX = (ulong2)abs(x);
            ulong2 absY = (ulong2)abs(y);

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

            return(dividend % divisor == 0);
        }
예제 #7
0
 public ulong2x4(ulong m00, ulong m01, ulong m02, ulong m03,
                 ulong m10, ulong m11, ulong m12, ulong m13)
 {
     this.c0 = new ulong2(m00, m10);
     this.c1 = new ulong2(m01, m11);
     this.c2 = new ulong2(m02, m12);
     this.c3 = new ulong2(m03, m13);
 }
예제 #8
0
        public ulong2 NextULong2(ulong2 max)
        {
            ulong2 result = ulong2.zero;

            Common.umul128(NextState(), max.x, out result.x);
            Common.umul128(NextState(), max.y, out result.y);

            return(result);
        }
예제 #9
0
        public static ulong2 reversebits(ulong2 x)
        {
            x = ((x >> 1) & 0x5555_5555_5555_5555ul) | ((x & 0x5555_5555_5555_5555ul) << 1);
            x = ((x >> 2) & 0x3333_3333_3333_3333ul) | ((x & 0x3333_3333_3333_3333ul) << 2);
            x = ((x >> 4) & 0x0F0F_0F0F_0F0F_0F0Ful) | ((x & 0x0F0F_0F0F_0F0F_0F0Ful) << 4);
            x = ((x >> 8) & 0x00FF_00FF_00FF_00FFul) | ((x & 0x00FF_00FF_00FF_00FFul) << 8);
            x = ((x >> 16) & 0x0000_FFFF_0000_FFFFul) | ((x & 0x0000_FFFF_0000_FFFFul) << 16);

            return((x >> 32) | (x << 32));
        }
예제 #10
0
 public static ulong cmin(ulong2 x)
 {
     if (Sse4_2.IsSse42Supported)
     {
         return(min(x, x.yy).x);
     }
     else
     {
         return(math.min(x.x, x.y));
     }
 }
예제 #11
0
파일: Max.cs 프로젝트: csritter/MaxMath
 public static ulong2 max(ulong2 a, ulong2 b)
 {
     if (Sse2.IsSse2Supported)
     {
         return(Mask.BlendV(a, b, Operator.greater_mask_ulong(b, a)));
     }
     else
     {
         return(new ulong2(math.max(a.x, b.x), math.max(a.y, b.y)));
     }
 }
예제 #12
0
        public static ulong cmax(ulong3 x)
        {
            if (Sse4_2.IsSse42Supported)
            {
                ulong2 temp = max(x.xy, x.yz);

                return(max(temp, temp.yy).x);
            }
            else
            {
                return(math.max(x.x, math.max(x.y, x.z)));
            }
        }
예제 #13
0
 public static bool2 ispow2(ulong2 x)
 {
     if (Sse4_2.IsSse42Supported)
     {
         v128 result = (byte2)(new ulong2(1) & Sse2.and_si128(Operator.greater_mask_ulong(x, default(v128)),
                                                              Operator.equals_mask_long(default(v128), x & (x - 1))));
         return(*(bool2 *)&result);
     }
     else
     {
         return(new bool2(ispow2(x.x), ispow2(x.y)));
     }
 }
예제 #14
0
        public static ulong cmin(ulong4 x)
        {
            if (Sse4_2.IsSse42Supported)
            {
                ulong2 temp = min(x.xy, x.zw);

                return(min(temp, temp.yy).x);
            }
            else
            {
                return(math.min(x.x, math.min(x.y, math.min(x.z, x.w))));
            }
        }
예제 #15
0
        public ulong2 NextULong2(ulong2 min, ulong2 max)
        {
            Assert.IsNotSmaller(max.x, min.x);
            Assert.IsNotSmaller(max.y, min.y);

            max -= min;
            ulong2 result = ulong2.zero;

            Common.umul128(NextState(), max.x, out result.x);
            Common.umul128(NextState(), max.y, out result.y);

            return(min + result);
        }
예제 #16
0
        public long2 NextLong2(long2 min, long2 max)
        {
            Assert.IsNotSmaller(max.x, min.x);
            Assert.IsNotSmaller(max.y, min.y);

            ulong2 result = ulong2.zero;

            max -= min;

            Common.umul128(NextState(), (ulong)(max.x), out result.x);
            Common.umul128(NextState(), (ulong)(max.y), out result.y);

            return(min + (long2)result);
        }
예제 #17
0
        public static ulong2 gcd(ulong2 x, ulong2 y)
        {
            if (Sse2.IsSse2Supported)
            {
                v128 ZERO = default(v128);

                v128 result             = ZERO;
                v128 result_if_zero_any = ZERO;

                v128 x_is_zero = Operator.equals_mask_long(x, ZERO);
                v128 y_is_zero = Operator.equals_mask_long(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;

                ulong2 shift = tzcnt(x | y);

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

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

                    v128 tempX       = x;
                    v128 x_greater_y = Operator.greater_mask_ulong(x, y);

                    x = Mask.BlendV(x, y, x_greater_y);
                    y = Mask.BlendV(y, tempX, x_greater_y);

                    y -= x;

                    v128 loopCheck = Sse2.andnot_si128(doneMask, Operator.equals_mask_long(y, ZERO));
                    result   = Mask.BlendV(result, x, loopCheck);
                    doneMask = Sse2.or_si128(doneMask, loopCheck);
                } while (bitmask32(2 * sizeof(ulong)) != Sse2.movemask_epi8(doneMask));

                result = shl(result, shift);

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

                return(result);
            }
            else
            {
                return(new ulong2(gcd(x.x, y.x), gcd(x.y, y.y)));
            }
        }
예제 #18
0
        public static long2 compareto(ulong2 x, ulong2 y)
        {
            if (Sse4_2.IsSse42Supported)
            {
                long2 xGreatery = Operator.greater_mask_ulong(x, y);
                long2 yGreaterx = Operator.greater_mask_ulong(y, x);

                return((0 - xGreatery) + yGreaterx);
            }
            else
            {
                return(new long2(compareto(x.x, y.x),
                                 compareto(x.y, y.y)));
            }
        }
예제 #19
0
        public static bool2 isdivisible(uint2 dividend, uint2 divisor)
        {
            Assert.AreNotEqual(0u, divisor.x);
            Assert.AreNotEqual(0u, divisor.y);

            if (Constant.IsConstantExpression(divisor))
            {
                ulong2 compile = (new ulong2(ulong.MaxValue) / divisor) + 1;

                return(dividend * compile <= compile - 1);
            }
            else
            {
                return(dividend % divisor == 0);
            }
        }
예제 #20
0
 public static ulong2 subadd(ulong2 a, ulong2 b)
 {
     if (Sse2.IsSse2Supported)
     {
         if (Sse4_1.IsSse41Supported)
         {
             return(a + Sse4_1.blend_epi16(b, default(v128) - b, 0b0000_1111));
         }
         else
         {
             return(a + Mask.BlendEpi16_SSE2(b, default(v128) - b, 0b0000_1111));
         }
     }
     else
     {
         return(new ulong2(a.x - b.x, a.y + b.y));
     }
 }
예제 #21
0
        public static ulong2 floorpow2(ulong2 x)
        {
            if (Avx2.IsAvx2Supported)
            {
                return(shrl(0x8000_0000_0000_0000, lzcnt(x)));
            }
            else
            {
                x |= x >> 1;
                x |= x >> 2;
                x |= x >> 4;
                x |= x >> 8;
                x |= x >> 16;
                x |= x >> 32;

                return(x - (x >> 1));
            }
        }
예제 #22
0
        public static ulong2 ceilpow2(ulong2 x)
        {
            if (Avx2.IsAvx2Supported)
            {
                return(shrl(0x8000_0000_0000_0000, lzcnt(x - 1) - 1));
            }
            else
            {
                x -= 1;
                x |= x >> 1;
                x |= x >> 2;
                x |= x >> 4;
                x |= x >> 8;
                x |= x >> 16;
                x |= x >> 32;

                return(x + 1);
            }
        }
예제 #23
0
        public static long2 intpow(long2 x, ulong2 n)
        {
            if (Sse2.IsSse2Supported)
            {
                v128 ZERO = long2.zero;
                v128 ONE  = new long2(1);

                v128 doneMask = ZERO;
                v128 result   = ZERO;

                v128 p = x;
                v128 y = ONE;


Loop:
                v128 y_times_p = Operator.mul_long(y, p);
                y = Mask.BlendV(y, y_times_p, Operator.equals_mask_long(ONE, ONE & n));

                n >>= 1;

                v128 n_is_zero = Sse4_1.cmpeq_epi64(ZERO, n);
                result   = Mask.BlendV(result, y, Sse2.andnot_si128(doneMask, n_is_zero));
                doneMask = n_is_zero;


                if (bitmask32(2 * sizeof(long)) != Sse2.movemask_epi8(doneMask))
                {
                    p = Operator.mul_long(p, p);

                    goto Loop;
                }
                else
                {
                    return(result);
                }
            }
            else
            {
                return(new long2(intpow(x.x, n.x), intpow(x.y, n.y)));
            }
        }
예제 #24
0
파일: Bitmask.cs 프로젝트: csritter/MaxMath
        public static ulong2 bitmask64(ulong2 numBits, ulong2 index = default(ulong2))
        {
            Assert.IsBetween(index.x, 0ul, 64ul);
            Assert.IsBetween(index.y, 0ul, 64ul);
            Assert.IsBetween(numBits.x, 0ul, 64ul - index.x);
            Assert.IsBetween(numBits.y, 0ul, 64ul - index.y);

            // mask
            index = shl(ulong.MaxValue, index);

            if (Sse2.IsSse2Supported)
            {
                v128 isMaxBitsMask = Operator.equals_mask_long(numBits, new v128(64ul));

                return(isMaxBitsMask | andnot(index, shl(index, numBits)));
            }
            else
            {
                return((ulong2)(-toint64(numBits == 64)) | andnot(index, shl(index, numBits)));
            }
        }
예제 #25
0
        public static long indexof(ulong2 v, ulong x)
        {
            if (Sse2.IsSse2Supported)
            {
                return(math.tzcnt(Sse2.movemask_pd(Operator.equals_mask_long(v, new v128(x)))));
            }
            else
            {
                for (int i = 0; i < 2; i++)
                {
                    if (v[i] == x)
                    {
                        return(i);
                    }
                    else
                    {
                        continue;
                    }
                }

                return(32);
            }
        }
예제 #26
0
 public static ulong2 clamp(ulong2 x, ulong2 a, ulong2 b)
 {
     return(max(a, min(x, b)));
 }
예제 #27
0
 public static ulong2 countbits(ulong2 x)
 {
     return(new ulong2((uint)math.countbits(x.x), (uint)math.countbits(x.y)));
 }
예제 #28
0
파일: AndNot.cs 프로젝트: csritter/MaxMath
 public static ulong2 andnot(ulong2 left, ulong2 right)
 {
     return((ulong2)andnot((long2)left, (long2)right));
 }
예제 #29
0
파일: All.cs 프로젝트: csritter/MaxMath
 public static bool all(ulong2 x)
 {
     return(all((long2)x));
 }
예제 #30
0
 public static bool2 isinrange(ulong2 x, ulong2 min, ulong2 max)
 {
     return(maxmath.min(maxmath.max(x, min), max) == x);
 }