1#[cfg(not(feature = "public-test-deps"))]
2pub(crate) use crate::int::specialized_div_rem::*;
3
4#[cfg(feature = "public-test-deps")]
5pub use crate::int::specialized_div_rem::*;
6
7intrinsics! {
8 #[maybe_use_optimized_c_shim]
9 #[arm_aeabi_alias = __aeabi_uidiv]
10 /// Returns `n / d`
11 pub extern "C" fn __udivsi3(n: u32, d: u32) -> u32 {
12 u32_div_rem(n, d).0
13 }
14
15 #[maybe_use_optimized_c_shim]
16 /// Returns `n % d`
17 pub extern "C" fn __umodsi3(n: u32, d: u32) -> u32 {
18 u32_div_rem(n, d).1
19 }
20
21 #[avr_skip]
22 #[maybe_use_optimized_c_shim]
23 /// Returns `n / d` and sets `*rem = n % d`
24 pub extern "C" fn __udivmodsi4(n: u32, d: u32, rem: Option<&mut u32>) -> u32 {
25 let quo_rem = u32_div_rem(n, d);
26 if let Some(rem) = rem {
27 *rem = quo_rem.1;
28 }
29 quo_rem.0
30 }
31
32 #[avr_skip]
33 #[maybe_use_optimized_c_shim]
34 /// Returns `n / d`
35 pub extern "C" fn __udivdi3(n: u64, d: u64) -> u64 {
36 u64_div_rem(n, d).0
37 }
38
39 #[avr_skip]
40 #[maybe_use_optimized_c_shim]
41 /// Returns `n % d`
42 pub extern "C" fn __umoddi3(n: u64, d: u64) -> u64 {
43 u64_div_rem(n, d).1
44 }
45
46 #[avr_skip]
47 #[maybe_use_optimized_c_shim]
48 /// Returns `n / d` and sets `*rem = n % d`
49 pub extern "C" fn __udivmoddi4(n: u64, d: u64, rem: Option<&mut u64>) -> u64 {
50 let quo_rem = u64_div_rem(n, d);
51 if let Some(rem) = rem {
52 *rem = quo_rem.1;
53 }
54 quo_rem.0
55 }
56
57 // Note: we use block configuration and not `if cfg!(...)`, because we need to entirely disable
58 // the existence of `u128_div_rem` to get 32-bit SPARC to compile, see `u128_divide_sparc` docs.
59
60 #[avr_skip]
61 #[win64_128bit_abi_hack]
62 /// Returns `n / d`
63 pub extern "C" fn __udivti3(n: u128, d: u128) -> u128 {
64 #[cfg(not(any(target_arch = "sparc", target_arch = "sparc64")))] {
65 u128_div_rem(n, d).0
66 }
67 #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] {
68 u128_divide_sparc(n, d, &mut 0)
69 }
70 }
71
72 #[avr_skip]
73 #[win64_128bit_abi_hack]
74 /// Returns `n % d`
75 pub extern "C" fn __umodti3(n: u128, d: u128) -> u128 {
76 #[cfg(not(any(target_arch = "sparc", target_arch = "sparc64")))] {
77 u128_div_rem(n, d).1
78 }
79 #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] {
80 let mut rem = 0;
81 u128_divide_sparc(n, d, &mut rem);
82 rem
83 }
84 }
85
86 #[avr_skip]
87 #[win64_128bit_abi_hack]
88 /// Returns `n / d` and sets `*rem = n % d`
89 pub extern "C" fn __udivmodti4(n: u128, d: u128, rem: Option<&mut u128>) -> u128 {
90 #[cfg(not(any(target_arch = "sparc", target_arch = "sparc64")))] {
91 let quo_rem = u128_div_rem(n, d);
92 if let Some(rem) = rem {
93 *rem = quo_rem.1;
94 }
95 quo_rem.0
96 }
97 #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] {
98 let mut tmp = 0;
99 let quo = u128_divide_sparc(n, d, &mut tmp);
100 if let Some(rem) = rem {
101 *rem = tmp;
102 }
103 quo
104 }
105 }
106}
107