@@ -2,7 +2,7 @@ use super::addition::{__add2, add2};
2
2
use super :: subtraction:: sub2;
3
3
#[ cfg( not( u64_digit) ) ]
4
4
use super :: u32_from_u128;
5
- use super :: { biguint_from_vec, cmp_slice, BigUint } ;
5
+ use super :: { biguint_from_vec, cmp_slice, BigUint , IntDigits } ;
6
6
7
7
use crate :: big_digit:: { self , BigDigit , DoubleBigDigit } ;
8
8
use crate :: Sign :: { self , Minus , NoSign , Plus } ;
@@ -322,14 +322,24 @@ fn mac3(mut acc: &mut [BigDigit], mut b: &[BigDigit], mut c: &[BigDigit]) {
322
322
// Recomposition. The coefficients of the polynomial are now known.
323
323
//
324
324
// Evaluate at w(t) where t is our given base to get the result.
325
- let bits = u64:: from ( big_digit:: BITS ) * i as u64 ;
326
- let result = r0
327
- + ( comp1 << bits)
328
- + ( comp2 << ( 2 * bits) )
329
- + ( comp3 << ( 3 * bits) )
330
- + ( r4 << ( 4 * bits) ) ;
331
- let result_pos = result. to_biguint ( ) . unwrap ( ) ;
332
- add2 ( & mut acc[ ..] , & result_pos. data ) ;
325
+ //
326
+ // let bits = u64::from(big_digit::BITS) * i as u64;
327
+ // let result = r0
328
+ // + (comp1 << bits)
329
+ // + (comp2 << (2 * bits))
330
+ // + (comp3 << (3 * bits))
331
+ // + (r4 << (4 * bits));
332
+ // let result_pos = result.to_biguint().unwrap();
333
+ // add2(&mut acc[..], &result_pos.data);
334
+ //
335
+ // But with less intermediate copying:
336
+ for ( j, result) in [ & r0, & comp1, & comp2, & comp3, & r4] . iter ( ) . enumerate ( ) . rev ( ) {
337
+ match result. sign ( ) {
338
+ Plus => add2 ( & mut acc[ i * j..] , result. digits ( ) ) ,
339
+ Minus => sub2 ( & mut acc[ i * j..] , result. digits ( ) ) ,
340
+ NoSign => { }
341
+ }
342
+ }
333
343
}
334
344
}
335
345
0 commit comments