Ejemplo n.º 1
0
        public static ulong4 lcm(long4 x, long4 y)
        {
            ulong4 absX = (ulong4)abs(x);
            ulong4 absY = (ulong4)abs(y);

            return((absX / gcd(absX, absY)) * absY);
        }
Ejemplo n.º 2
0
        public static long4x2 transpose(long2x4 v)
        {
            if (Avx2.IsAvx2Supported)
            {
                long4 lo = new long4(v.c0, v.c2);
                long4 hi = new long4(v.c1, v.c3);

                return(new long4x2(Avx2.mm256_unpacklo_epi64(lo, hi),
                                   Avx2.mm256_unpackhi_epi64(lo, hi)));
            }
            else if (Sse2.IsSse2Supported)
            {
                return(new long4x2(new long4(Sse2.unpacklo_epi64(v.c0, v.c1),
                                             Sse2.unpacklo_epi64(v.c2, v.c3)),
                                   new long4(Sse2.unpackhi_epi64(v.c0, v.c1),
                                             Sse2.unpackhi_epi64(v.c2, v.c3))));
            }
            else
            {
                return(new long4x2(v.c0.x, v.c0.y,
                                   v.c1.x, v.c1.y,
                                   v.c2.x, v.c2.y,
                                   v.c3.x, v.c3.y));
            }
        }
Ejemplo n.º 3
0
        public static long4x4 transpose(long4x4 v)
        {
            if (Avx2.IsAvx2Supported)
            {
                long4 lo_lo = Avx2.mm256_unpacklo_epi64(v.c0, v.c1);
                long4 lo_hi = Avx2.mm256_unpacklo_epi64(v.c2, v.c3);

                long4 hi_lo = Avx2.mm256_unpackhi_epi64(v.c0, v.c1);
                long4 hi_hi = Avx2.mm256_unpackhi_epi64(v.c2, v.c3);

                return(new long4x4(Avx2.mm256_inserti128_si256(lo_lo, Avx.mm256_castsi256_si128(lo_hi), 1),
                                   Avx2.mm256_inserti128_si256(hi_lo, Avx.mm256_castsi256_si128(hi_hi), 1),
                                   Avx2.mm256_inserti128_si256(Avx.mm256_castsi128_si256(Avx2.mm256_extracti128_si256(lo_lo, 1)), Avx2.mm256_extracti128_si256(lo_hi, 1), 1),
                                   Avx2.mm256_inserti128_si256(Avx.mm256_castsi128_si256(Avx2.mm256_extracti128_si256(hi_lo, 1)), Avx2.mm256_extracti128_si256(hi_hi, 1), 1)));
            }
            else if (Sse2.IsSse2Supported)
            {
                return(new long4x4(new long4(Sse2.unpacklo_epi64(v.c0._xy, v.c1._xy), Sse2.unpacklo_epi64(v.c2._xy, v.c3._xy)),
                                   new long4(Sse2.unpackhi_epi64(v.c0._xy, v.c1._xy), Sse2.unpackhi_epi64(v.c2._xy, v.c3._xy)),
                                   new long4(Sse2.unpacklo_epi64(v.c0._zw, v.c1._zw), Sse2.unpacklo_epi64(v.c2._zw, v.c3._zw)),
                                   new long4(Sse2.unpackhi_epi64(v.c0._zw, v.c1._zw), Sse2.unpackhi_epi64(v.c2._zw, v.c3._zw))));
            }
            else
            {
                return(new long4x4(v.c0.x, v.c0.y, v.c0.z, v.c0.w,
                                   v.c1.x, v.c1.y, v.c1.z, v.c1.w,
                                   v.c2.x, v.c2.y, v.c2.z, v.c2.w,
                                   v.c3.x, v.c3.y, v.c3.z, v.c3.w));
            }
        }
Ejemplo n.º 4
0
 public long4x4(long v)
 {
     this.c0 = v;
     this.c1 = v;
     this.c2 = v;
     this.c3 = v;
 }
Ejemplo n.º 5
0
 public long4x4(long4 c0, long4 c1, long4 c2, long4 c3)
 {
     this.c0 = c0;
     this.c1 = c1;
     this.c2 = c2;
     this.c3 = c3;
 }
Ejemplo n.º 6
0
        public void Indexer()
        {
            var v = new long4(-1L, -4L, -2L, 6L);

            Assert.AreEqual(-1L, v[0]);
            Assert.AreEqual(-4L, v[1]);
            Assert.AreEqual(-2L, v[2]);
            Assert.AreEqual(6L, v[3]);

            Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[-2147483648]; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { v[-2147483648] = 0; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[-1]; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { v[-1] = 0; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[4]; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { v[4] = 0; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[2147483647]; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { v[2147483647] = 0; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[5]; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { v[5] = 0; });

            v[2] = 0;
            Assert.AreEqual(0, v[2]);
            v[1] = 1;
            Assert.AreEqual(1, v[1]);
            v[2] = 2L;
            Assert.AreEqual(2L, v[2]);
            v[2] = 3L;
            Assert.AreEqual(3L, v[2]);
            v[0] = 4L;
            Assert.AreEqual(4L, v[0]);
            v[3] = 5L;
            Assert.AreEqual(5L, v[3]);
            v[0] = 6L;
            Assert.AreEqual(6L, v[0]);
            v[1] = 7L;
            Assert.AreEqual(7L, v[1]);
            v[0] = 8L;
            Assert.AreEqual(8L, v[0]);
            v[2] = 9L;
            Assert.AreEqual(9L, v[2]);
            v[3] = -1L;
            Assert.AreEqual(-1L, v[3]);
            v[0] = -2L;
            Assert.AreEqual(-2L, v[0]);
            v[2] = -3L;
            Assert.AreEqual(-3L, v[2]);
            v[1] = -4L;
            Assert.AreEqual(-4L, v[1]);
            v[3] = -5L;
            Assert.AreEqual(-5L, v[3]);
            v[2] = -6L;
            Assert.AreEqual(-6L, v[2]);
            v[2] = -7L;
            Assert.AreEqual(-7L, v[2]);
            v[1] = -8L;
            Assert.AreEqual(-8L, v[1]);
            v[0] = -9L;
            Assert.AreEqual(-9L, v[0]);
        }
Ejemplo n.º 7
0
 public long4x2(long m00, long m01,
                long m10, long m11,
                long m20, long m21,
                long m30, long m31)
 {
     this.c0 = new long4(m00, m10, m20, m30);
     this.c1 = new long4(m01, m11, m21, m31);
 }
Ejemplo n.º 8
0
        public static long4 divrem(long4 dividend, long4 divisor, out long4 remainder)
        {
            remainder = default(v256);

            return(new long4(divrem(dividend.x, divisor.x, out remainder.x),
                             divrem(dividend.y, divisor.y, out remainder.y),
                             divrem(dividend.z, divisor.z, out remainder.z),
                             divrem(dividend.w, divisor.w, out remainder.w)));
        }
Ejemplo n.º 9
0
        public static bool4 isdivisible(long4 dividend, long4 divisor)
        {
            Assert.AreNotEqual(0, divisor.x);
            Assert.AreNotEqual(0, divisor.y);
            Assert.AreNotEqual(0, divisor.z);
            Assert.AreNotEqual(0, divisor.w);

            return(dividend % divisor == 0);
        }
Ejemplo n.º 10
0
 public long4x3(long m00, long m01, long m02,
                long m10, long m11, long m12,
                long m20, long m21, long m22,
                long m30, long m31, long m32)
 {
     this.c0 = new long4(m00, m10, m20, m30);
     this.c1 = new long4(m01, m11, m21, m31);
     this.c2 = new long4(m02, m12, m22, m32);
 }
Ejemplo n.º 11
0
 public long4x4(long m00, long m01, long m02, long m03,
                long m10, long m11, long m12, long m13,
                long m20, long m21, long m22, long m23,
                long m30, long m31, long m32, long m33)
 {
     this.c0 = new long4(m00, m10, m20, m30);
     this.c1 = new long4(m01, m11, m21, m31);
     this.c2 = new long4(m02, m12, m22, m32);
     this.c3 = new long4(m03, m13, m23, m33);
 }
Ejemplo n.º 12
0
 public static bool any(long4 x)
 {
     if (Avx2.IsAvx2Supported)
     {
         return(bitmask32(4 * sizeof(long)) != Avx2.mm256_movemask_epi8(Avx2.mm256_cmpeq_epi64(x, default(v256))));
     }
     else
     {
         return(any(x.xy) | any(x.zw));
     }
 }
Ejemplo n.º 13
0
        public void PropertyValues()
        {
            var v    = new long4(-7L, -2L, 2L, 8L);
            var vals = v.Values;

            Assert.AreEqual(-7L, vals[0]);
            Assert.AreEqual(-2L, vals[1]);
            Assert.AreEqual(2L, vals[2]);
            Assert.AreEqual(8L, vals[3]);
            Assert.That(vals.SequenceEqual(v.ToArray()));
        }
Ejemplo n.º 14
0
        public static void long4()
        {
            Random64 rng = new Random64(135);

            for (long i = 0; i < 64; i++)
            {
                long4 x = rng.NextLong4();

                Assert.AreEqual(new long4((long)math.lzcnt(x.x), (long)math.lzcnt(x.y), (long)math.lzcnt(x.z), (long)math.lzcnt(x.w)), maxmath.lzcnt(x));
            }
        }
Ejemplo n.º 15
0
 public static long4 addsub(long4 a, long4 b)
 {
     if (Avx2.IsAvx2Supported)
     {
         return(a + Avx2.mm256_blend_epi16(b, -b, 0b1111_0000));
     }
     else
     {
         return(new long4(addsub(a.xy, b.xy), addsub(a.zw, b.zw)));
     }
 }
Ejemplo n.º 16
0
 public static long4 andnot(long4 left, long4 right)
 {
     if (Avx2.IsAvx2Supported)
     {
         return(Avx2.mm256_andnot_si256(right, left));
     }
     else
     {
         return(new long4(andnot(left.xy, right.xy), andnot(left.zw, right.zw)));
     }
 }
Ejemplo n.º 17
0
 public static long csum(long4 x)
 {
     if (Sse2.IsSse2Supported)
     {
         return(csum(x.xy + x.zw));
     }
     else
     {
         return((x.x + x.y) + (x.z + x.w));
     }
 }
Ejemplo n.º 18
0
        public void SerializationJson()
        {
            var v0 = new long4(8L, -7L, 1, -7L);
            var s0 = JsonConvert.SerializeObject(v0);

            var v1 = JsonConvert.DeserializeObject <long4>(s0);
            var s1 = JsonConvert.SerializeObject(v1);

            Assert.AreEqual(v0, v1);
            Assert.AreEqual(s0, s1);
        }
Ejemplo n.º 19
0
 public static long4 max(long4 a, long4 b)
 {
     if (Avx2.IsAvx2Supported)
     {
         return(Avx2.mm256_blendv_epi8(a, b, Avx2.mm256_cmpgt_epi64(b, a)));
     }
     else
     {
         return(new long4(max(a.xy, b.xy), max(a.zw, b.zw)));
     }
 }
Ejemplo n.º 20
0
 public static bool all_eq(long4 c)
 {
     if (Avx2.IsAvx2Supported)
     {
         return(c.xxxx.Equals(c));
     }
     else
     {
         return(c.x == c.y & c.x == c.z & c.x == c.w);
     }
 }
Ejemplo n.º 21
0
 public static long4 nabs(long4 x)
 {
     if (Avx2.IsAvx2Supported)
     {
         return(Avx2.mm256_blendv_epi8(-x, x, Avx2.mm256_cmpgt_epi64(default(v256), x)));
     }
     else
     {
         return(new long4(abs(x.xy), nabs(x.zw)));
     }
 }
Ejemplo n.º 22
0
 public static long4 subadd(long4 a, long4 b)
 {
     if (Avx2.IsAvx2Supported)
     {
         return(a + Avx2.mm256_blend_epi16(b, -b, 0b0000_1111));
     }
     else
     {
         return(new long4(subadd(a.xy, b.xy), subadd(a.zw, b.zw)));
     }
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix.
 /// </summary>
 public long2x4(long4 c0, long4 c1)
 {
     this.m00 = c0.x;
     this.m01 = c0.y;
     this.m02 = c0.z;
     this.m03 = c0.w;
     this.m10 = c1.x;
     this.m11 = c1.y;
     this.m12 = c1.z;
     this.m13 = c1.w;
 }
Ejemplo n.º 24
0
 public static bool all(long4 x)
 {
     if (Avx2.IsAvx2Supported)
     {
         return(0 == Avx2.mm256_movemask_epi8(Avx2.mm256_cmpeq_epi64(x, default(v256))));
     }
     else
     {
         return(all(x.xy) & all(x.zw));
     }
 }
Ejemplo n.º 25
0
 public void InvariantCommutative()
 {
     {
         var v0 = new long4(1, -9L, 9L, -8L);
         var v1 = new long4(-3L, 3L, 7L, 8L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long4(-9L, 2L, -9L, -2L);
         var v1 = new long4(-5L, 7L, 5L, -8L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long4(-3L, 0, -9L, -2L);
         var v1 = new long4(2L, -4L, 5L, -8L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long4(9L, 9L, 2L, 4L);
         var v1 = new long4(-5L, -1L, 5L, 2L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long4(-5L, -7L, -5L, 4L);
         var v1 = new long4(8L, 1, 3L, -5L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long4(-2L, 3L, 8L, -5L);
         var v1 = new long4(-8L, -7L, 7L, -9L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long4(3L, -5L, 2L, 8L);
         var v1 = new long4(-2L, -4L, -3L, 7L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long4(-3L, -2L, 8L, 3L);
         var v1 = new long4(0, 2L, -3L, 7L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long4(-7L, -7L, -7L, -7L);
         var v1 = new long4(-3L, 0, 9L, -1L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long4(-7L, 3L, 0, -8L);
         var v1 = new long4(4L, 9L, -9L, -2L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
 }
Ejemplo n.º 26
0
 public void InvariantCommutativeNeg()
 {
     {
         var v0 = new long4(4L, -8L, 6L, -8L);
         var v1 = new long4(-5L, -9L, -2L, 3L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long4(5L, 0, -5L, 5L);
         var v1 = new long4(-5L, -2L, -7L, 7L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long4(-9L, -4L, -3L, 0);
         var v1 = new long4(2L, -5L, -7L, -5L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long4(-2L, 3L, -7L, -1L);
         var v1 = new long4(-7L, 4L, -4L, 2L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long4(9L, -9L, 3L, 2L);
         var v1 = new long4(-6L, 0, -3L, 9L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long4(9L, 6L, 2L, -3L);
         var v1 = new long4(4L, -5L, 3L, -9L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long4(1, -2L, 7L, 9L);
         var v1 = new long4(5L, -5L, 8L, 8L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long4(1, -1L, 5L, -1L);
         var v1 = new long4(2L, 1, 5L, 0);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long4(6L, -3L, -5L, -6L);
         var v1 = new long4(7L, -4L, -2L, -8L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long4(0, 2L, -1L, -5L);
         var v1 = new long4(-3L, 4L, -1L, -6L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
 }
Ejemplo n.º 27
0
 public void TriangleInequality()
 {
     {
         var v0 = new long4(-8L, 0, 4L, -8L);
         var v1 = new long4(8L, -8L, -5L, -4L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long4(-4L, 0, 0, 5L);
         var v1 = new long4(5L, -3L, 4L, 4L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long4(-6L, 9L, -9L, -2L);
         var v1 = new long4(-3L, -1L, -2L, 6L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long4(-7L, 2L, -8L, -6L);
         var v1 = new long4(3L, -4L, -5L, 2L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long4(9L, 8L, -2L, -4L);
         var v1 = new long4(-4L, -1L, -9L, -2L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long4(-9L, -4L, -6L, -1L);
         var v1 = new long4(2L, 6L, 4L, 3L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long4(6L, -9L, 7L, 7L);
         var v1 = new long4(-9L, 2L, -5L, 6L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long4(8L, -8L, 1, 5L);
         var v1 = new long4(-9L, -8L, -1L, 0);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long4(5L, -8L, -6L, -6L);
         var v1 = new long4(1, 9L, 9L, 5L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long4(-1L, 7L, -2L, -9L);
         var v1 = new long4(-5L, 0, 3L, -1L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
 }
Ejemplo n.º 28
0
        public static void long4()
        {
            Random64 rng = new Random64(135);

            for (long i = 0; i < 64; i++)
            {
                long4 x = rng.NextLong4();
                long4 y = rng.NextLong4();

                Assert.AreEqual(new ulong4((ulong)_gcd(x.x, y.x), (ulong)_gcd(x.y, y.y), (ulong)_gcd(x.z, y.z), (ulong)_gcd(x.w, y.w)), maxmath.gcd(x, y));
            }
        }
Ejemplo n.º 29
0
        public static void long4()
        {
            Random64 rng = new Random64(135);

            for (long i = 0; i < 64; i++)
            {
                long4  x = rng.NextLong4();
                ulong4 n = rng.NextULong4();

                Assert.AreEqual(new long4((long)_intpow(x.x, n.x), (long)_intpow(x.y, n.y), (long)_intpow(x.z, n.z), (long)_intpow(x.w, n.w)), maxmath.intpow(x, n));
            }
        }
Ejemplo n.º 30
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))));
            }
        }
Ejemplo n.º 31
0
 public static extern CUResult cuMemcpyDtoH_v2(ref long4 dstHost, CUdeviceptr srcDevice, SizeT ByteCount);