private void Reduce(MutableInteger z) { // var qhat = (z >> (bLength * (k - 1))) * mu >> (bLength * (k + 1)); var reg1 = store.Allocate().Set(z); reg1.RightShift(bToTheKMinusOneLength); #if false var reg2.store.Allocate().SetProductShifted(reg1, muRep, bToTheKPlusOneLength); #else var reg2 = store.Allocate().SetProduct(reg1, muRep); reg2.RightShift(bToTheKPlusOneLength); #endif // var r = z % bToTheKPlusOne - qhat * p % bToTheKPlusOne; z.Mask(bToTheKPlusOneLength); #if true reg1.SetProductMasked(reg2, pRep, bToTheKPlusOneLength); #else reg1.SetProduct(reg2, pRep); reg1.Mask(bToTheKPlusOneLength); #endif // if (r.Sign == -1) r += bToTheKPlusOne; if (z < reg1) { z.SetBit(bToTheKPlusOneLength, true); } z.Subtract(reg1); // while (r >= p) r -= p; while (z >= pRep) { z.Subtract(pRep); } store.Release(reg1); store.Release(reg2); }