예제 #1
0
        public static long2 divrem(long2 dividend, long2 divisor, out long2 remainder)
        {
            remainder = default(v128);

            return(new long2(divrem(dividend.x, divisor.x, out remainder.x),
                             divrem(dividend.y, divisor.y, out remainder.y)));
        }
예제 #2
0
        internal static long2 shra_long(long2 x, int n)
        {
            v128 shiftLo;
            v128 shiftHi;

            if (n <= 32)
            {
                shiftHi = shra_int(x, n);
                shiftLo = shrl_long(x, n);
            }
            else
            {
                shiftHi = shra_int(x, 31);
                shiftLo = shra_int(x, n - 32);
                shiftLo = shrl_long(shiftLo, 32);
            }


            if (Sse4_1.IsSse41Supported)
            {
                return(Sse4_1.blend_epi16(shiftLo, shiftHi, 0b1100_1100));
            }
            else if (Sse2.IsSse2Supported)
            {
                return(Mask.BlendEpi16_SSE2(shiftLo, shiftHi, 0b1100_1100));
            }
            else
            {
                throw new CPUFeatureCheckException();
            }
        }
예제 #3
0
파일: long2x3.cs 프로젝트: csritter/MaxMath
 public long2x3(long m00, long m01, long m02,
                long m10, long m11, long m12)
 {
     this.c0 = new long2(m00, m10);
     this.c1 = new long2(m01, m11);
     this.c2 = new long2(m02, m12);
 }
예제 #4
0
파일: long2x4.cs 프로젝트: csritter/MaxMath
 public long2x4(long2 c0, long2 c1, long2 c2, long2 c3)
 {
     this.c0 = c0;
     this.c1 = c1;
     this.c2 = c2;
     this.c3 = c3;
 }
예제 #5
0
파일: long2x4.cs 프로젝트: csritter/MaxMath
 public long2x4(long v)
 {
     this.c0 = v;
     this.c1 = v;
     this.c2 = v;
     this.c3 = v;
 }
예제 #6
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);
        }
예제 #7
0
        public static bool2 isdivisible(long2 dividend, long2 divisor)
        {
            Assert.AreNotEqual(0, divisor.x);
            Assert.AreNotEqual(0, divisor.y);

            return(dividend % divisor == 0);
        }
예제 #8
0
파일: long2x4.cs 프로젝트: csritter/MaxMath
 public long2x4(long m00, long m01, long m02, long m03,
                long m10, long m11, long m12, long m13)
 {
     this.c0 = new long2(m00, m10);
     this.c1 = new long2(m01, m11);
     this.c2 = new long2(m02, m12);
     this.c3 = new long2(m03, m13);
 }
예제 #9
0
 public static long csum(long2 x)
 {
     if (Sse2.IsSse2Supported)
     {
         return(Sse2.add_epi64(x, Sse2.shuffle_epi32(x, Sse.SHUFFLE(0, 0, 3, 2))).SLong0);
     }
     else
     {
         return(x.x + x.y);
     }
 }
예제 #10
0
파일: All.cs 프로젝트: csritter/MaxMath
 public static bool all(long2 x)
 {
     if (Sse2.IsSse2Supported)
     {
         return(0 == Sse2.movemask_epi8(Operator.equals_mask_long(x, default(v128))));
     }
     else
     {
         return(math.all(x != 0));
     }
 }
예제 #11
0
 public static long cmin(long2 x)
 {
     if (Sse4_2.IsSse42Supported)
     {
         return(min(x, x.yy).x);
     }
     else
     {
         return(math.min(x.x, x.y));
     }
 }
예제 #12
0
파일: Max.cs 프로젝트: csritter/MaxMath
 public static long2 max(long2 a, long2 b)
 {
     if (Sse2.IsSse2Supported)
     {
         return(Mask.BlendV(a, b, Operator.greater_mask_long(b, a)));
     }
     else
     {
         return(new long2(math.max(a.x, b.x), math.max(a.y, b.y)));
     }
 }
예제 #13
0
파일: Any.cs 프로젝트: csritter/MaxMath
 public static bool any(long2 x)
 {
     if (Sse2.IsSse2Supported)
     {
         return(bitmask32(2 * sizeof(long)) != Sse2.movemask_epi8(Operator.equals_mask_long(x, default(v128))));
     }
     else
     {
         return(math.any(x != 0));
     }
 }
예제 #14
0
 public static long2 nabs(long2 x)
 {
     if (Sse2.IsSse2Supported)
     {
         return(Mask.BlendV(-x, x, Operator.greater_mask_long(default(v128), x)));
     }
     else
     {
         return(new long2(nabs(x.x), nabs(x.y)));
     }
 }
예제 #15
0
파일: AndNot.cs 프로젝트: csritter/MaxMath
 public static long2 andnot(long2 left, long2 right)
 {
     if (Sse2.IsSse2Supported)
     {
         return(Sse2.andnot_si128(right, left));
     }
     else
     {
         return(left & ~right);
     }
 }
예제 #16
0
        public static long cmax(long3 x)
        {
            if (Sse4_2.IsSse42Supported)
            {
                long2 temp = max(x.xy, x.yz);

                return(max(temp, temp.yy).x);
            }
            else
            {
                return(math.max(x.x, math.max(x.y, x.z)));
            }
        }
예제 #17
0
        public static long2 abs(long2 x)
        {
            if (Sse2.IsSse2Supported)
            {
                long2 mask = Operator.greater_mask_long(default(v128), x);

                return((x + mask) ^ mask);
            }
            else
            {
                return(new long2(math.abs(x.x), math.abs(x.y)));
            }
        }
예제 #18
0
        public static long2 rol(long2 x, long2 n)
        {
            if (Sse2.IsSse2Supported)
            {
                n &= 63;

                return(shl(x, n) | shrl(x, -n & 63));
            }
            else
            {
                return(new long2(math.rol(x.x, (int)n.x), math.rol(x.y, (int)n.y)));
            }
        }
예제 #19
0
 public static bool2 ispow2(long2 x)
 {
     if (Sse4_2.IsSse42Supported)
     {
         v128 result = (byte2)(new long2(1) & Sse2.and_si128(Operator.greater_mask_long(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)));
     }
 }
예제 #20
0
        public static long cmin(long4 x)
        {
            if (Sse4_2.IsSse42Supported)
            {
                long2 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))));
            }
        }
예제 #21
0
        public static long csum(long3 x)
        {
            if (Avx2.IsAvx2Supported)
            {
                long2 result = Sse2.add_epi64(Avx.mm256_castsi256_si128(x), Avx2.mm256_extracti128_si256(x, 1));

                return(Sse2.add_epi64(result, Sse2.shuffle_epi32(result, Sse.SHUFFLE(0, 0, 3, 2))).SLong0);
            }
            else
            {
                return(x.x + x.y + x.z);
            }
        }
예제 #22
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);
        }
예제 #23
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)));
            }
        }
예제 #24
0
        public static long2 compareto(double2 x, double2 y)
        {
            if (Sse2.IsSse2Supported)
            {
                long2 xGreatery = Sse2.cmpgt_pd(*(v128 *)&x, *(v128 *)&y);
                long2 yGreaterx = Sse2.cmpgt_pd(*(v128 *)&y, *(v128 *)&x);

                return((0 - xGreatery) + yGreaterx);
            }
            else
            {
                return(new long2(compareto(x.x, y.x),
                                 compareto(x.y, y.y)));
            }
        }
예제 #25
0
파일: Average.cs 프로젝트: csritter/MaxMath
        public static long2 avg(long2 x, long2 y)
        {
            long2 result = x + y;

            // if the intermediate sum is positive add 1
            if (Sse2.IsSse2Supported)
            {
                result -= Operator.greater_mask_long(result, default(v128));
            }
            else
            {
                result.x += touint8(result.x > 0);
                result.y += touint8(result.y > 0);
            }

            return(result >> 1);
        }
예제 #26
0
        public static long2 negate(long2 x, bool2 p)
        {
            Assert.IsSafeBoolean(p.x);
            Assert.IsSafeBoolean(p.y);

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

                return((x ^ mask) - mask);
            }
            else
            {
                long2 mask = touint8(p);

                return((x ^ -mask) + mask);
            }
        }
예제 #27
0
 public static long2 subadd(long2 a, long2 b)
 {
     if (Sse2.IsSse2Supported)
     {
         if (Sse4_1.IsSse41Supported)
         {
             return(a + Sse4_1.blend_epi16(b, -b, 0b0000_1111));
         }
         else
         {
             return(a + Mask.BlendEpi16_SSE2(b, -b, 0b0000_1111));
         }
     }
     else
     {
         return(new long2(a.x - b.x, a.y + b.y));
     }
 }
예제 #28
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)));
            }
        }
예제 #29
0
파일: Bitmask.cs 프로젝트: csritter/MaxMath
 public static long2 bitmask64(long2 numBits, long2 index = default(long2)) => (long2)bitmask64((ulong2)numBits, (ulong2)index);
예제 #30
0
파일: long2.cs 프로젝트: csritter/MaxMath
 public DebuggerProxy(long2 v)
 {
     x = v.x;
     y = v.y;
 }