public static Int128 Rol(Int128 a, int amt) { int nn; Int128 aa = a.Clone(); for (; amt > 0; amt--) { for (nn = 0; nn < 4; nn++) { aa.digits[nn] <<= 1; } for (nn = 0; nn < 3; nn++) { if (aa.digits[nn] > 0xffffffffL) { aa.digits[nn] &= 0xffffffffL; aa.digits[nn + 1]++; } } if (aa.digits[nn] > 0xffffffffL) { aa.digits[0] |= 1; } aa.digits[nn] &= 0xffffffffL; } aa.mask(); return(aa); }
public static Int128 Com(Int128 a) { int nn; Int128 aa = a.Clone(); for (nn = 0; nn < 4; nn++) { aa.digits[nn] = ~aa.digits[nn]; } return(aa); }
public static Int128 Mul(Int128 a, Int128 b) { Int128 aa = a.Clone(); Int128 p = new Int128(); int nn; for (nn = 0; nn < 128; nn++) { if (((aa.digits[3] >> 31) & 1) != 0) { p = Add(p, b); } p = Shl(p, 1); aa = Shl(aa, 1); } return(p); }
public Int128 ShrPair(Int128 hi, Int128 lo, int amt) { int nn; UInt64[] digits; Int128 aa = new Int128(); digits = new ulong[8]; Int128 reslo = lo.Clone(); Int128 reshi = hi.Clone(); digits[0] = lo.digits[0]; digits[1] = lo.digits[1]; digits[2] = lo.digits[2]; digits[3] = lo.digits[3]; digits[4] = hi.digits[0]; digits[5] = hi.digits[1]; digits[6] = hi.digits[2]; digits[7] = hi.digits[3]; for (; amt > 0; amt--) { for (nn = 7; nn > 0; nn--) { if ((digits[nn] & 1L) != 0) { digits[nn - 1] |= 0x100000000L; } } for (nn = 0; nn < 8; nn++) { digits[nn] >>= 1; } } aa.digits[0] = digits[0]; aa.digits[1] = digits[1]; aa.digits[2] = digits[2]; aa.digits[3] = digits[3]; aa.mask(); return(aa); }
public static Int128 Asr(Int128 a, int amt) { int nn; Int128 aa = a.Clone(); for (; amt > 0; amt--) { for (nn = 3; nn > 0; nn--) { if ((aa.digits[nn] & 1L) != 0) { aa.digits[nn - 1] |= 0x100000000L; } } for (nn = 0; nn < 4; nn++) { aa.digits[nn] >>= 1; } aa.digits[nn - 1] |= (ulong)((aa.digits[nn - 1] >> 30) & 1) << 31; } aa.mask(); return(aa); }
public static void ShlPair(Int128 a, ref Int128 aa, ref Int128 bb, int amt, int lsb = 0) { int nn; aa = a.Clone(); // bb = Int128.Convert(lsb!=0 ? -1 : 0); for (; amt > 0; amt--) { for (nn = 0; nn < 4; nn++) { aa.digits[nn] <<= 1; bb.digits[nn] <<= 1; } for (nn = 0; nn < 3; nn++) { if (aa.digits[nn] > 0xffffffffL) { aa.digits[nn] &= 0xffffffffL; aa.digits[nn + 1]++; } if (bb.digits[nn] > 0xffffffffL) { bb.digits[nn] &= 0xffffffffL; bb.digits[nn + 1]++; } } if (aa.digits[nn] > 0xffffffffL) { bb.digits[0]++; } aa.digits[0] |= (ulong)lsb; aa.mask(); bb.mask(); } }