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)); }
/// <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); }
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); }
/// <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); }
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); }
public static BitVector64 flip(BitVector64 x) => math.flip(x.data);
public static ref BitVector64 flip(ref BitVector64 x) { math.flip(ref x.data); return(ref x); }
public static ref BitVector64 negate(BitVector64 x, ref BitVector64 z) { math.negate(x.data, ref z.data); return(ref z); }
public static BitVector64 negate(BitVector64 x) => math.negate(x.data);
public static ref BitVector64 negate(ref BitVector64 x) { math.negate(ref x.data); return(ref x); }
public static ref BitVector64 srl(ref BitVector64 x, int offset) { math.srl(ref x.data, offset); return(ref x); }
public static FixedBits <BitVector64, ulong> ToFixedBits(this BitVector64 src) => src;
public static ref BitVector64 sll(BitVector64 x, int offset, ref BitVector64 z) { z.assign(Bits.sll(x.Scalar, offset)); return(ref z); }
public static BitVector64 sll(BitVector64 x, int offset) => Bits.sll(x.Scalar, offset);
public static ref BitVector64 sll(ref BitVector64 x, int offset) { x.assign(Bits.sll(x.Scalar, offset)); return(ref x); }
public static ref BitVector64 srl(BitVector64 x, int offset, ref BitVector64 z) { z.assign(math.srl(x.data, offset)); return(ref z); }
public static BitVector64 srl(BitVector64 x, int offset) => math.srl(x.data, offset);
public static ref BitVector64 flip(BitVector64 x, ref BitVector64 z) { z.data = math.flip(x.data); return(ref z); }
public static BitVector64 xor(BitVector64 x, BitVector64 y) => math.xor(x.data, y.data);
public static BitVector64 ToBitVector(this BitString src, N64 n) => BitVector64.FromBitString(src);
public static ref BitVector64 mask(Perm spec, out BitVector64 mask) { mask = BitVector64.Mask(spec); return(ref mask); }
public static BitVector64 and(BitVector64 x, BitVector64 y) => math.and(x.data, y.data);
public static ref BitVector64 xor(BitVector64 x, BitVector64 y, ref BitVector64 z) { math.xor(x.data, y.data, ref z.data); return(ref z); }
public static BitVector <N64, ulong> ToGeneric(this BitVector64 src) => src;