示例#1
0
文件: clmul.cs 项目: 0xCM/arrows
        static BitVector128 clmul(BitVector64 lhs, BitVector64 rhs)
        {
            var a = Vec128.LoadScalar(lhs.Scalar);
            var b = Vec128.LoadScalar(rhs.Scalar);

            return(dinx.clmul(a, b, ClMulMask.X00));
        }
示例#2
0
文件: clmul.cs 项目: 0xCM/arrows
        /// <summary>
        /// Defines a reference implementation of caryless multiplication that follows
        /// Intel's published algirithm
        /// </summary>
        /// <param name="x">The left vector</param>
        /// <param name="y">The right vector</param>
        /// <returns></returns>
        public static BitVector128 clmul_ref(BitVector64 x, BitVector64 y)
        {
            var temp1 = x;
            var temp2 = y;

            var dst = BitVector128.Zero;
            var tmp = BitVector128.Zero;

            for (var i = 0; i < 64; i++)
            {
                tmp[i] = temp1[0] & temp2[i];
                for (var j = 1; j <= i; j++)
                {
                    tmp[i] = tmp[i] ^ (temp1[j] & temp2[i - j]);
                }
                dst[i] = tmp[i];
            }

            for (var i = 64; i < 128; i++)
            {
                tmp[i] = 0;
                for (var j = (i - 63); j < 64; j++)
                {
                    tmp[i] = tmp[i] ^ (temp1[j] & temp2[i - j]);
                }
                dst[i] = tmp[i];
            }
            dst[127] = 0;

            return(dst);
        }
示例#3
0
文件: clmul.cs 项目: 0xCM/arrows
        public static BitVector64 clmulr(BitVector64 a, BitVector64 b, BitVector128 poly)
        {
            var prod = clmul(a, b);

            prod = Bits.xor(prod, dinx.clmul(srl(prod, 64), poly, ClMulMask.X00));
            prod = Bits.xor(prod, dinx.clmul(srl(prod, 64), poly, ClMulMask.X00));
            return((BitVector64)prod);
        }
示例#4
0
文件: ModProd.cs 项目: 0xCM/arrows
        /// <summary>
        /// Compultes the scalar product between two bitvectors using modular arithmetic
        /// </summary>
        /// <param name="lhs">The first vector</param>
        /// <param name="rhs">The second vector</param>
        /// <returns></returns>
        public static int ModProd(BitVector64 lhs, BitVector64 rhs)
        {
            var result = 0;

            for (var i = 0; i < lhs.Length; i++)
            {
                var x = lhs[i] ? 1 : 0;
                var y = rhs[i] ? 1 : 0;
                result += x * y;
            }
            return(result % 2);
        }
示例#5
0
        public void bitmap_8x64()
        {
            var         dst       = 0ul;
            byte        srclen    = 8;
            byte        srcOffset = 0;
            BitVector64 src       = 0b11110000110011001010101011111111ul;

            Bits.bitmap(src.Byte(0), srcOffset, srclen, 0, ref dst);
            Bits.bitmap(src.Byte(1), srcOffset, srclen, 8, ref dst);
            Bits.bitmap(src.Byte(2), srcOffset, srclen, 8, ref dst);
            Bits.bitmap(src.Byte(3), srcOffset, srclen, 8, ref dst);

            BitVector64 expect = 0b11111111101010101100110011110000ul;
            BitVector64 actual = dst;

            Claim.eq(expect, actual);
        }
示例#6
0
文件: flip.cs 项目: 0xCM/arrows
 public static BitVector64 flip(BitVector64 x)
 => math.flip(x.data);
示例#7
0
文件: flip.cs 项目: 0xCM/arrows
 public static ref BitVector64 flip(ref BitVector64 x)
 {
     math.flip(ref x.data);
     return(ref x);
 }
示例#8
0
文件: negate.cs 项目: 0xCM/arrows
 public static ref BitVector64 negate(BitVector64 x, ref BitVector64 z)
 {
     math.negate(x.data, ref z.data);
     return(ref z);
 }
示例#9
0
文件: negate.cs 项目: 0xCM/arrows
 public static BitVector64 negate(BitVector64 x)
 => math.negate(x.data);
示例#10
0
文件: negate.cs 项目: 0xCM/arrows
 public static ref BitVector64 negate(ref BitVector64 x)
 {
     math.negate(ref x.data);
     return(ref x);
 }
示例#11
0
 public static ref BitVector64 srl(ref BitVector64 x, int offset)
 {
     math.srl(ref x.data, offset);
     return(ref x);
 }
示例#12
0
 public static FixedBits <BitVector64, ulong> ToFixedBits(this BitVector64 src)
 => src;
示例#13
0
 public static ref BitVector64 sll(BitVector64 x, int offset, ref BitVector64 z)
 {
     z.assign(Bits.sll(x.Scalar, offset));
     return(ref z);
 }
示例#14
0
 public static BitVector64 sll(BitVector64 x, int offset)
 => Bits.sll(x.Scalar, offset);
示例#15
0
 public static ref BitVector64 sll(ref BitVector64 x, int offset)
 {
     x.assign(Bits.sll(x.Scalar, offset));
     return(ref x);
 }
示例#16
0
 public static ref BitVector64 srl(BitVector64 x, int offset, ref BitVector64 z)
 {
     z.assign(math.srl(x.data, offset));
     return(ref z);
 }
示例#17
0
 public static BitVector64 srl(BitVector64 x, int offset)
 => math.srl(x.data, offset);
示例#18
0
文件: flip.cs 项目: 0xCM/arrows
 public static ref BitVector64 flip(BitVector64 x, ref BitVector64 z)
 {
     z.data = math.flip(x.data);
     return(ref z);
 }
示例#19
0
文件: xor.cs 项目: 0xCM/arrows
 public static BitVector64 xor(BitVector64 x, BitVector64 y)
 => math.xor(x.data, y.data);
示例#20
0
 public static BitVector64 ToBitVector(this BitString src, N64 n)
 => BitVector64.FromBitString(src);
示例#21
0
文件: mask.cs 项目: 0xCM/arrows
 public static ref BitVector64 mask(Perm spec, out BitVector64 mask)
 {
     mask = BitVector64.Mask(spec);
     return(ref mask);
 }
示例#22
0
文件: and.cs 项目: 0xCM/arrows
 public static BitVector64 and(BitVector64 x, BitVector64 y)
 => math.and(x.data, y.data);
示例#23
0
文件: xor.cs 项目: 0xCM/arrows
 public static ref BitVector64 xor(BitVector64 x, BitVector64 y, ref BitVector64 z)
 {
     math.xor(x.data, y.data, ref z.data);
     return(ref z);
 }
示例#24
0
 public static BitVector <N64, ulong> ToGeneric(this BitVector64 src)
 => src;