File tree Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ macro_rules! sdivmod {
99 $( $attr: tt) ,* // attributes
1010 ) => {
1111 intrinsics! {
12+ #[ avr_skip]
1213 $(
1314 #[ $attr]
1415 ) *
@@ -50,6 +51,7 @@ macro_rules! sdiv {
5051 $( $attr: tt) ,* // attributes
5152 ) => {
5253 intrinsics! {
54+ #[ avr_skip]
5355 $(
5456 #[ $attr]
5557 ) *
@@ -85,6 +87,7 @@ macro_rules! smod {
8587 $( $attr: tt) ,* // attributes
8688 ) => {
8789 intrinsics! {
90+ #[ avr_skip]
8891 $(
8992 #[ $attr]
9093 ) *
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ intrinsics! {
1818 u32_div_rem( n, d) . 1
1919 }
2020
21+ #[ avr_skip]
2122 #[ maybe_use_optimized_c_shim]
2223 /// Returns `n / d` and sets `*rem = n % d`
2324 pub extern "C" fn __udivmodsi4( n: u32 , d: u32 , rem: Option <& mut u32 >) -> u32 {
@@ -28,18 +29,21 @@ intrinsics! {
2829 quo_rem. 0
2930 }
3031
32+ #[ avr_skip]
3133 #[ maybe_use_optimized_c_shim]
3234 /// Returns `n / d`
3335 pub extern "C" fn __udivdi3( n: u64 , d: u64 ) -> u64 {
3436 u64_div_rem( n, d) . 0
3537 }
3638
39+ #[ avr_skip]
3740 #[ maybe_use_optimized_c_shim]
3841 /// Returns `n % d`
3942 pub extern "C" fn __umoddi3( n: u64 , d: u64 ) -> u64 {
4043 u64_div_rem( n, d) . 1
4144 }
4245
46+ #[ avr_skip]
4347 #[ maybe_use_optimized_c_shim]
4448 /// Returns `n / d` and sets `*rem = n % d`
4549 pub extern "C" fn __udivmoddi4( n: u64 , d: u64 , rem: Option <& mut u64 >) -> u64 {
@@ -77,6 +81,7 @@ intrinsics! {
7781 }
7882 }
7983
84+ #[ avr_skip]
8085 #[ win64_128bit_abi_hack]
8186 /// Returns `n / d` and sets `*rem = n % d`
8287 pub extern "C" fn __udivmodti4( n: u128 , d: u128 , rem: Option <& mut u128 >) -> u128 {
Original file line number Diff line number Diff line change @@ -111,7 +111,6 @@ macro_rules! intrinsics {
111111
112112 $( $rest: tt) *
113113 ) => (
114-
115114 #[ cfg( $name = "optimized-c" ) ]
116115 pub extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
117116 extern $abi {
@@ -333,6 +332,36 @@ macro_rules! intrinsics {
333332 intrinsics!( $( $rest) * ) ;
334333 ) ;
335334
335+ // For division and modulo, AVR uses a custom calling convention¹ that does
336+ // not match our definitions here. Ideally we would just use hand-written
337+ // naked functions, but that's quite a lot of code to port² - so for the
338+ // time being we are just ignoring the problematic functions, letting
339+ // avr-gcc (which is required to compile to AVR anyway) link them from
340+ // libgcc.
341+ //
342+ // ¹ https://gcc.gnu.org/wiki/avr-gcc (see "Exceptions to the Calling
343+ // Convention")
344+ // ² https://github.com/gcc-mirror/gcc/blob/31048012db98f5ec9c2ba537bfd850374bdd771f/libgcc/config/avr/lib1funcs.S
345+ (
346+ #[ avr_skip]
347+ $( #[ $( $attr: tt) * ] ) *
348+ pub extern $abi: tt fn $name: ident( $( $argname: ident: $ty: ty) ,* ) $( -> $ret: ty) ? {
349+ $( $body: tt) *
350+ }
351+
352+ $( $rest: tt) *
353+ ) => (
354+ #[ cfg( not( target_arch = "avr" ) ) ]
355+ intrinsics! {
356+ $( #[ $( $attr) * ] ) *
357+ pub extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
358+ $( $body) *
359+ }
360+ }
361+
362+ intrinsics!( $( $rest) * ) ;
363+ ) ;
364+
336365 // This is the final catch-all rule. At this point we generate an
337366 // intrinsic with a conditional `#[no_mangle]` directive to avoid
338367 // interfering with duplicate symbols and whatnot during testing.
You can’t perform that action at this time.
0 commit comments