1
1
//! Reciprocal, shared across Uint and BoxedUint
2
- use crate :: { ConstChoice , Limb , NonZero , Word , primitives } ;
2
+ use crate :: { primitives , ConstChoice , Limb , NonZero , Word } ;
3
3
use subtle:: { Choice , ConditionallySelectable } ;
4
4
5
5
/// Calculates the reciprocal of the given 32-bit divisor with the highmost bit set.
@@ -12,14 +12,14 @@ pub const fn reciprocal(d: Word) -> Word {
12
12
let d21 = ( d >> 11 ) + 1 ;
13
13
let d31 = ( d >> 1 ) + d0;
14
14
let v0 = short_div ( ( 1 << 24 ) - ( 1 << 14 ) + ( 1 << 9 ) , 24 , d10, 10 ) ;
15
- let ( hi, _lo) = mulhilo ( v0 * v0, d21) ;
15
+ let ( hi, _lo) = primitives :: mulhilo ( v0 * v0, d21) ;
16
16
let v1 = ( v0 << 4 ) - hi - 1 ;
17
17
18
18
// Checks that the expression for `e` can be simplified in the way we did below.
19
- debug_assert ! ( mulhilo( v1, d31) . 0 == ( 1 << 16 ) - 1 ) ;
19
+ debug_assert ! ( primitives :: mulhilo( v1, d31) . 0 == ( 1 << 16 ) - 1 ) ;
20
20
let e = Word :: MAX - v1. wrapping_mul ( d31) + 1 + ( v1 >> 1 ) * d0;
21
21
22
- let ( hi, _lo) = mulhilo ( v1, e) ;
22
+ let ( hi, _lo) = primitives :: mulhilo ( v1, e) ;
23
23
// Note: the paper does not mention a wrapping add here,
24
24
// but the 64-bit version has it at this stage, and the function panics without it
25
25
// when calculating a reciprocal for `Word::MAX`.
@@ -29,7 +29,7 @@ pub const fn reciprocal(d: Word) -> Word {
29
29
// If `v2 == 2^32-1` this should give `d`, but we can't achieve this in our wrapping arithmetic.
30
30
// Hence the `ct_select()`.
31
31
let x = v2. wrapping_add ( 1 ) ;
32
- let ( hi, _lo) = mulhilo ( x, d) ;
32
+ let ( hi, _lo) = primitives :: mulhilo ( x, d) ;
33
33
let hi = ConstChoice :: from_u32_nonzero ( x) . select_word ( d, hi) ;
34
34
35
35
v2. wrapping_sub ( hi) . wrapping_sub ( d)
0 commit comments