r[n - 1] = un[n - 1] >> s;
}
+void biglsh(unsigned s, unsigned vn[], unsigned const v[], int n)
+{
+ for (int i = n - 1; i > 0; i--)
+ vn[i] = (v[i] << s) | ((unsigned long long)v[i - 1] >> (32 - s));
+ vn[0] = v[0] << s;
+}
+
bool bigmul(unsigned long long qhat, unsigned product[], unsigned vn[], int m,
int n)
{
s = nlz(v[n - 1]); // 0 <= s <= 31.
vn = (unsigned *)alloca(4 * n);
- for (i = n - 1; i > 0; i--)
- vn[i] = (v[i] << s) | ((unsigned long long)v[i - 1] >> (32 - s));
- vn[0] = v[0] << s;
+ biglsh(s, vn, v, n);
un = (unsigned *)alloca(4 * (m + 1));
un[m] = (unsigned long long)u[m - 1] >> (32 - s);
- for (i = m - 1; i > 0; i--)
- un[i] = (u[i] << s) | ((unsigned long long)u[i - 1] >> (32 - s));
- un[0] = u[0] << s;
+ biglsh(s, un, u, m);
for (j = m - n; j >= 0; j--)
{ // Main loop.