scAdd static method

void scAdd(
  1. List<int> s,
  2. List<int> a,
  3. List<int> b
)

Implementation

static void scAdd(List<int> s, List<int> a, List<int> b) {
  s.asMin32("scAdd");
  a.asMin32("scAdd");
  b.asMin32("scAdd");
  final BigInt a0 = _b2097151 & _load3(a, 0);
  final BigInt a1 = _b2097151 & (_load4(a, 2) >> 5);
  final BigInt a2 = _b2097151 & (_load3(a, 5) >> 2);
  final BigInt a3 = _b2097151 & (_load4(a, 7) >> 7);
  final BigInt a4 = _b2097151 & (_load4(a, 10) >> 4);
  final BigInt a5 = _b2097151 & (_load3(a, 13) >> 1);
  final BigInt a6 = _b2097151 & (_load4(a, 15) >> 6);
  final BigInt a7 = _b2097151 & (_load3(a, 18) >> 3);
  final BigInt a8 = _b2097151 & _load3(a, 21);
  final BigInt a9 = _b2097151 & (_load4(a, 23) >> 5);
  final BigInt a10 = _b2097151 & (_load3(a, 26) >> 2);
  final BigInt a11 = (_load4(a, 28) >> 7);
  final BigInt b0 = _b2097151 & _load3(b, 0);
  final BigInt b1 = _b2097151 & (_load4(b, 2) >> 5);
  final BigInt b2 = _b2097151 & (_load3(b, 5) >> 2);
  final BigInt b3 = _b2097151 & (_load4(b, 7) >> 7);
  final BigInt b4 = _b2097151 & (_load4(b, 10) >> 4);
  final BigInt b5 = _b2097151 & (_load3(b, 13) >> 1);
  final BigInt b6 = _b2097151 & (_load4(b, 15) >> 6);
  final BigInt b7 = _b2097151 & (_load3(b, 18) >> 3);
  final BigInt b8 = _b2097151 & _load3(b, 21);
  final BigInt b9 = _b2097151 & (_load4(b, 23) >> 5);
  final BigInt b10 = _b2097151 & (_load3(b, 26) >> 2);
  final BigInt b11 = (_load4(b, 28) >> 7);
  BigInt s0 = a0 + b0;
  BigInt s1 = a1 + b1;
  BigInt s2 = a2 + b2;
  BigInt s3 = a3 + b3;
  BigInt s4 = a4 + b4;
  BigInt s5 = a5 + b5;
  BigInt s6 = a6 + b6;
  BigInt s7 = a7 + b7;
  BigInt s8 = a8 + b8;
  BigInt s9 = a9 + b9;
  BigInt s10 = a10 + b10;
  BigInt s11 = a11 + b11;
  BigInt s12 = BigInt.zero;
  BigInt carry0;
  BigInt carry1;
  BigInt carry2;
  BigInt carry3;
  BigInt carry4;
  BigInt carry5;
  BigInt carry6;
  BigInt carry7;
  BigInt carry8;
  BigInt carry9;
  BigInt carry10;
  BigInt carry11;

  carry0 = (s0 + _bitMaskFor20) >> 21;
  s1 += carry0;
  s0 -= carry0 << 21;
  carry2 = (s2 + _bitMaskFor20) >> 21;
  s3 += carry2;
  s2 -= carry2 << 21;
  carry4 = (s4 + _bitMaskFor20) >> 21;
  s5 += carry4;
  s4 -= carry4 << 21;
  carry6 = (s6 + _bitMaskFor20) >> 21;
  s7 += carry6;
  s6 -= carry6 << 21;
  carry8 = (s8 + _bitMaskFor20) >> 21;
  s9 += carry8;
  s8 -= carry8 << 21;
  carry10 = (s10 + _bitMaskFor20) >> 21;
  s11 += carry10;
  s10 -= carry10 << 21;

  carry1 = (s1 + _bitMaskFor20) >> 21;
  s2 += carry1;
  s1 -= carry1 << 21;
  carry3 = (s3 + _bitMaskFor20) >> 21;
  s4 += carry3;
  s3 -= carry3 << 21;
  carry5 = (s5 + _bitMaskFor20) >> 21;
  s6 += carry5;
  s5 -= carry5 << 21;
  carry7 = (s7 + _bitMaskFor20) >> 21;
  s8 += carry7;
  s7 -= carry7 << 21;
  carry9 = (s9 + _bitMaskFor20) >> 21;
  s10 += carry9;
  s9 -= carry9 << 21;
  carry11 = (s11 + _bitMaskFor20) >> 21;
  s12 += carry11;
  s11 -= carry11 << 21;

  s0 += s12 * 666643.toBig;
  s1 += s12 * 470296.toBig;
  s2 += s12 * 654183.toBig;
  s3 -= s12 * 997805.toBig;
  s4 += s12 * 136657.toBig;
  s5 -= s12 * 683901.toBig;
  s12 = BigInt.zero;

  carry0 = s0 >> 21;
  s1 += carry0;
  s0 -= carry0 << 21;
  carry1 = s1 >> 21;
  s2 += carry1;
  s1 -= carry1 << 21;
  carry2 = s2 >> 21;
  s3 += carry2;
  s2 -= carry2 << 21;
  carry3 = s3 >> 21;
  s4 += carry3;
  s3 -= carry3 << 21;
  carry4 = s4 >> 21;
  s5 += carry4;
  s4 -= carry4 << 21;
  carry5 = s5 >> 21;
  s6 += carry5;
  s5 -= carry5 << 21;
  carry6 = s6 >> 21;
  s7 += carry6;
  s6 -= carry6 << 21;
  carry7 = s7 >> 21;
  s8 += carry7;
  s7 -= carry7 << 21;
  carry8 = s8 >> 21;
  s9 += carry8;
  s8 -= carry8 << 21;
  carry9 = s9 >> 21;
  s10 += carry9;
  s9 -= carry9 << 21;
  carry10 = s10 >> 21;
  s11 += carry10;
  s10 -= carry10 << 21;
  carry11 = s11 >> 21;
  s12 += carry11;
  s11 -= carry11 << 21;

  s0 += s12 * 666643.toBig;
  s1 += s12 * 470296.toBig;
  s2 += s12 * 654183.toBig;
  s3 -= s12 * 997805.toBig;
  s4 += s12 * 136657.toBig;
  s5 -= s12 * 683901.toBig;

  carry0 = s0 >> 21;
  s1 += carry0;
  s0 -= carry0 << 21;
  carry1 = s1 >> 21;
  s2 += carry1;
  s1 -= carry1 << 21;
  carry2 = s2 >> 21;
  s3 += carry2;
  s2 -= carry2 << 21;
  carry3 = s3 >> 21;
  s4 += carry3;
  s3 -= carry3 << 21;
  carry4 = s4 >> 21;
  s5 += carry4;
  s4 -= carry4 << 21;
  carry5 = s5 >> 21;
  s6 += carry5;
  s5 -= carry5 << 21;
  carry6 = s6 >> 21;
  s7 += carry6;
  s6 -= carry6 << 21;
  carry7 = s7 >> 21;
  s8 += carry7;
  s7 -= carry7 << 21;
  carry8 = s8 >> 21;
  s9 += carry8;
  s8 -= carry8 << 21;
  carry9 = s9 >> 21;
  s10 += carry9;
  s9 -= carry9 << 21;
  carry10 = s10 >> 21;
  s11 += carry10;
  s10 -= carry10 << 21;
  final List<BigInt> sBig = List<BigInt>.filled(32, BigInt.zero);
  sBig[0] = s0 >> 0;
  sBig[1] = s0 >> 8;
  sBig[2] = (s0 >> 16) | (s1 << 5);
  sBig[3] = s1 >> 3;
  sBig[4] = s1 >> 11;
  sBig[5] = (s1 >> 19) | (s2 << 2);
  sBig[6] = s2 >> 6;
  sBig[7] = (s2 >> 14) | (s3 << 7);
  sBig[8] = s3 >> 1;
  sBig[9] = s3 >> 9;
  sBig[10] = (s3 >> 17) | (s4 << 4);
  sBig[11] = s4 >> 4;
  sBig[12] = s4 >> 12;
  sBig[13] = (s4 >> 20) | (s5 << 1);
  sBig[14] = s5 >> 7;
  sBig[15] = (s5 >> 15) | (s6 << 6);
  sBig[16] = s6 >> 2;
  sBig[17] = s6 >> 10;
  sBig[18] = (s6 >> 18) | (s7 << 3);
  sBig[19] = s7 >> 5;
  sBig[20] = s7 >> 13;
  sBig[21] = s8 >> 0;
  sBig[22] = s8 >> 8;
  sBig[23] = (s8 >> 16) | (s9 << 5);
  sBig[24] = s9 >> 3;
  sBig[25] = s9 >> 11;
  sBig[26] = (s9 >> 19) | (s10 << 2);
  sBig[27] = s10 >> 6;
  sBig[28] = (s10 >> 14) | (s11 << 7);
  sBig[29] = s11 >> 1;
  sBig[30] = s11 >> 9;
  sBig[31] = s11 >> 17;
  for (int i = 0; i < sBig.length; i++) {
    s[i] = sBig[i].toUnsigned8;
  }
}