@@ -5,6 +5,12 @@ use core::iter::repeat;
5
5
use core:: mem;
6
6
use num_traits:: { One , PrimInt , Zero } ;
7
7
8
+ #[ cfg( all( use_addcarry, target_arch = "x86_64" ) ) ]
9
+ use core:: arch:: x86_64 as arch;
10
+
11
+ #[ cfg( all( use_addcarry, target_arch = "x86" ) ) ]
12
+ use core:: arch:: x86 as arch;
13
+
8
14
use crate :: biguint:: biguint_from_vec;
9
15
use crate :: biguint:: BigUint ;
10
16
@@ -15,31 +21,35 @@ use crate::bigint::Sign::{Minus, NoSign, Plus};
15
21
use crate :: big_digit:: { self , BigDigit , DoubleBigDigit } ;
16
22
17
23
// only needed for the fallback implementation of `sbb`
18
- #[ cfg( not( any ( use_addcarry_u64 , use_addcarry_u32 ) ) ) ]
24
+ #[ cfg( not( use_addcarry ) ) ]
19
25
use crate :: big_digit:: SignedDoubleBigDigit ;
20
26
21
- // Generic functions for add/subtract/multiply with carry/borrow. These are specialized for some platforms to take advantage of intrinsics etc
27
+ // Generic functions for add/subtract/multiply with carry/borrow. These are specialized
28
+ // for some platforms to take advantage of intrinsics, etc.
22
29
23
30
// Add with carry:
24
- #[ cfg( use_addcarry_u64 ) ]
31
+ #[ cfg( all ( use_addcarry , u64_digit ) ) ]
25
32
#[ inline]
26
33
fn adc ( a : BigDigit , b : BigDigit , acc : & mut u8 ) -> BigDigit {
27
34
let mut out = 0 ;
28
- // Safety: There are absolutely no safety concerns with calling _addcarry_u64, it's just unsafe for API consistency with other intrinsics
29
- * acc = unsafe { core:: arch:: x86_64:: _addcarry_u64 ( * acc, a, b, & mut out) } ;
35
+ // Safety: There are absolutely no safety concerns with calling `_addcarry_u64`.
36
+ // It's just unsafe for API consistency with other intrinsics.
37
+ * acc = unsafe { arch:: _addcarry_u64 ( * acc, a, b, & mut out) } ;
30
38
out
31
39
}
32
40
33
- #[ cfg( use_addcarry_u32 ) ]
41
+ #[ cfg( all ( use_addcarry , not ( u64_digit ) ) ) ]
34
42
#[ inline]
35
43
fn adc ( a : BigDigit , b : BigDigit , acc : & mut u8 ) -> BigDigit {
36
44
let mut out = 0 ;
37
- // Safety: There are absolutely no safety concerns with calling _addcarry_u32, it's just unsafe for API consistency with other intrinsics
38
- * acc = unsafe { core:: arch:: x86_64:: _addcarry_u32 ( * acc, a, b, & mut out) } ;
45
+ // Safety: There are absolutely no safety concerns with calling `_addcarry_u32`.
46
+ // It's just unsafe for API consistency with other intrinsics.
47
+ * acc = unsafe { arch:: _addcarry_u32 ( * acc, a, b, & mut out) } ;
39
48
out
40
49
}
41
50
42
- #[ cfg( not( any( use_addcarry_u64, use_addcarry_u32) ) ) ] // fallback for environments where we don't have an addcarry intrinsic
51
+ // fallback for environments where we don't have an addcarry intrinsic
52
+ #[ cfg( not( use_addcarry) ) ]
43
53
#[ inline]
44
54
fn adc ( a : BigDigit , b : BigDigit , acc : & mut DoubleBigDigit ) -> BigDigit {
45
55
* acc += DoubleBigDigit :: from ( a) ;
@@ -50,24 +60,28 @@ fn adc(a: BigDigit, b: BigDigit, acc: &mut DoubleBigDigit) -> BigDigit {
50
60
}
51
61
52
62
// Subtract with borrow:
53
- #[ cfg( use_addcarry_u64 ) ]
63
+ #[ cfg( all ( use_addcarry , u64_digit ) ) ]
54
64
#[ inline]
55
65
fn sbb ( a : BigDigit , b : BigDigit , acc : & mut u8 ) -> BigDigit {
56
66
let mut out = 0 ;
57
- // Safety: There are absolutely no safety concerns with calling _subborrow_u64, it's just unsafe for API consistency with other intrinsics
58
- * acc = unsafe { core:: arch:: x86_64:: _subborrow_u64 ( * acc, a, b, & mut out) } ;
67
+ // Safety: There are absolutely no safety concerns with calling `_subborrow_u64`.
68
+ // It's just unsafe for API consistency with other intrinsics.
69
+ * acc = unsafe { arch:: _subborrow_u64 ( * acc, a, b, & mut out) } ;
59
70
out
60
71
}
61
- #[ cfg( use_addcarry_u32) ]
72
+
73
+ #[ cfg( all( use_addcarry, not( u64_digit) ) ) ]
62
74
#[ inline]
63
75
fn sbb ( a : BigDigit , b : BigDigit , acc : & mut u8 ) -> BigDigit {
64
76
let mut out = 0 ;
65
- // Safety: There are absolutely no safety concerns with calling _subborrow_u32, it's just unsafe for API consistency with other intrinsics
66
- * acc = unsafe { core:: arch:: x86_64:: _subborrow_u32 ( * acc, a, b, & mut out) } ;
77
+ // Safety: There are absolutely no safety concerns with calling `_subborrow_u32`.
78
+ // It's just unsafe for API consistency with other intrinsics.
79
+ * acc = unsafe { arch:: _subborrow_u32 ( * acc, a, b, & mut out) } ;
67
80
out
68
81
}
69
82
70
- #[ cfg( not( any( use_addcarry_u64, use_addcarry_u32) ) ) ] // fallback for environments where we don't have an addcarry intrinsic
83
+ // fallback for environments where we don't have an addcarry intrinsic
84
+ #[ cfg( not( use_addcarry) ) ]
71
85
#[ inline]
72
86
fn sbb ( a : BigDigit , b : BigDigit , acc : & mut SignedDoubleBigDigit ) -> BigDigit {
73
87
* acc += SignedDoubleBigDigit :: from ( a) ;
0 commit comments