1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! The portable kernel of Montgomery's reduction, for Miri and for the targets without assembly
//! kernels: a row of limb products added into the limbs, a product of two limbs taken as a `u128`,
//! which compilers lower to the target's widening multiplication.
/// Adds the `n` limbs at `x` times `y` to the `n` limbs at `r`, and returns the limb that carries
/// out of them.
///
/// # Safety
///
/// `n >= 1`; the `n` limbs at `x` must be valid for reads and those at `r` for reads and writes,
/// and apart from them.
pub unsafe
/// The row of [`addmul_1`], for the low halves of products.
pub use addmul_1 as row;
/// REDC a limb at a time, after GMP's `mpn_redc_1`: sets the `n` limbs at `r` to `u / B^n mod m`
/// less `m` when it returns `true`, for the `2n` limbs at `u`, below `B^n m`, which it clobbers,
/// with `minv[0] = -1/m mod B`.
///
/// Limb `j`'s quotient `q = u_j (-1/m) mod B` makes `u + q m B^j` zero at limb `j`; the row's carry
/// out, which belongs at limb `j + n`, is kept in limb `j`, now free, and the carries are added to
/// the high half at the end, in one pass, whose carry out it returns.
///
/// # Safety
///
/// `n >= 1`; the limbs must be valid, `r` apart from `u`, `m` apart from both, and `minv` must be
/// `-1/m mod B^2`.
pub unsafe