Debian Codegraph @

src/mul.rs

raw symbols SCIP
1 //! Fast multiplication routines.
2
3 use craterust-analyzer cargo lexical-util 1.0.7 crate/::numrust-analyzer cargo lexical-util 1.0.7 num/::{as_castrust-analyzer cargo lexical-util 1.0.7 num/as_cast()., UnsignedIntegerrust-analyzer cargo lexical-util 1.0.7 num/UnsignedInteger#};
4
5 /// Multiply two unsigned, integral values, and return the high and low product.
6 ///
7 /// The high product is the upper half of the product and the low product is the
8 /// lower half. The `full` type is the full type size, while the `half` type is
9 /// the type with exactly half the bits.
10 #[inline(always)]
11 pub fn mulrust-analyzer cargo lexical-util 1.0.7 mul/mul().<Full, Half>(x: Full, y: Full) -> (Full, Full)
12 where
13 Full: UnsignedIntegerrust-analyzer cargo lexical-util 1.0.7 num/UnsignedInteger#,
14 Half: UnsignedIntegerrust-analyzer cargo lexical-util 1.0.7 num/UnsignedInteger#,
15 {
16 // Extract high-and-low masks.
17 let x1 = x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().Half::BITSrust-analyzer cargo lexical-util 1.0.7 num/Integer#BITS. as i32;
18 let x0 = x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand().as_castrust-analyzer cargo lexical-util 1.0.7 num/as_cast().(Half::MAXrust-analyzer cargo lexical-util 1.0.7 num/Integer#MAX.);
19 let y1 = y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().Half::BITSrust-analyzer cargo lexical-util 1.0.7 num/Integer#BITS. as i32;
20 let y0 = y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand().as_castrust-analyzer cargo lexical-util 1.0.7 num/as_cast().(Half::MAXrust-analyzer cargo lexical-util 1.0.7 num/Integer#MAX.);
21
22 let w0 = x0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().y0;
23 let tmp = (x1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().y0) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().(w0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().Half::BITSrust-analyzer cargo lexical-util 1.0.7 num/Integer#BITS. as i32);
24 let w1 = tmp rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand().as_castrust-analyzer cargo lexical-util 1.0.7 num/as_cast().(Half::MAXrust-analyzer cargo lexical-util 1.0.7 num/Integer#MAX.);
25 let w2 = tmp rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().Half::BITSrust-analyzer cargo lexical-util 1.0.7 num/Integer#BITS. as i32;
26 let w1 = w1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().x0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().y1;
27 let hi = (x1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().y1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().w2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().(w1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().Half::BITSrust-analyzer cargo lexical-util 1.0.7 num/Integer#BITS. as i32);
28 let lo = x.wrapping_mulrust-analyzer cargo lexical-util 1.0.7 num/Integer#wrapping_mul().(y);
29
30 (hi, lo)
31 }
32
33 /// Multiply two unsigned, integral values, and return the high product.
34 ///
35 /// The high product is the upper half of the product. The `full` type is the
36 /// full type size, while the `half` type is the type with exactly half the
37 /// bits.
38 #[inline(always)]
39 pub fn mulhirust-analyzer cargo lexical-util 1.0.7 mul/mulhi().<Full, Half>(x: Full, y: Full) -> Full
40 where
41 Full: UnsignedIntegerrust-analyzer cargo lexical-util 1.0.7 num/UnsignedInteger#,
42 Half: UnsignedIntegerrust-analyzer cargo lexical-util 1.0.7 num/UnsignedInteger#,
43 {
44 // Extract high-and-low masks.
45 let x1 = x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().Half::BITSrust-analyzer cargo lexical-util 1.0.7 num/Integer#BITS. as i32;
46 let x0 = x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand().as_castrust-analyzer cargo lexical-util 1.0.7 num/as_cast().(Half::MAXrust-analyzer cargo lexical-util 1.0.7 num/Integer#MAX.);
47 let y1 = y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().Half::BITSrust-analyzer cargo lexical-util 1.0.7 num/Integer#BITS. as i32;
48 let y0 = y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand().as_castrust-analyzer cargo lexical-util 1.0.7 num/as_cast().(Half::MAXrust-analyzer cargo lexical-util 1.0.7 num/Integer#MAX.);
49
50 let w0 = x0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().y0;
51 let m = (x0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().y1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().(w0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().Half::BITSrust-analyzer cargo lexical-util 1.0.7 num/Integer#BITS. as i32);
52 let w1 = m rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand().as_castrust-analyzer cargo lexical-util 1.0.7 num/as_cast().(Half::MAXrust-analyzer cargo lexical-util 1.0.7 num/Integer#MAX.);
53 let w2 = m rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().Half::BITSrust-analyzer cargo lexical-util 1.0.7 num/Integer#BITS. as i32;
54
55 let w3 = (x1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().y0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().w1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Shr#shr().Half::BITSrust-analyzer cargo lexical-util 1.0.7 num/Integer#BITS. as i32;
56
57 x1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().y1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().w2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().w3
58 }