Skip to content

Commit c9f5280

Browse files
committed
fix: Add #[avr_skip] for bit shifts
This commit follows the same logic as: - rust-lang#462 - rust-lang#466 I've tested the changes by preparing a simple program: ```rust fn calc() -> ... { let x = hint::black_box(4u...); // 4u8, 4u16, 4u32, 4u64, 4u128 + signed let y = hint::black_box(1u32); // x >> y // x << y } fn main() -> ! { let dp = arduino_hal::Peripherals::take().unwrap(); let pins = arduino_hal::pins!(dp); let mut serial = arduino_hal::default_serial!(dp, pins, 57600); for b in calc().to_le_bytes() { _ = ufmt::uwrite!(&mut serial, "{} ", b); } _ = ufmt::uwriteln!(&mut serial, ""); loop { // } } ``` ... switching types & operators in `calc()`, and observing the results; what I ended up with was: ``` u32 << u32 - ok u64 << u32 - ok u128 << u32 - error (undefined reference to `__ashlti3') i32 >> u32 - ok i64 >> u32 - ok i128 >> u32 - error (undefined reference to `__ashrti3') u32 >> u32 - ok u64 >> u32 - ok u128 >> u32 - error (undefined reference to `__lshrti3') (where "ok" = compiles and returns correct results) ``` As with multiplication and division, so do in here 128-bit operations not work, because avr-gcc's standard library doesn't provide them (at the same time, requiring that specific calling convention, making it pretty difficult for compiler-builtins to jump in). I think 128-bit operations non-working on an 8-bit controller is an acceptable trade-off - :innocent: - and so the entire fix in here is just about skipping those functions.
1 parent 23a74de commit c9f5280

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/int/shift.rs

+9
Original file line numberDiff line numberDiff line change
@@ -69,47 +69,56 @@ impl Lshr for u64 {}
6969
impl Lshr for u128 {}
7070

7171
intrinsics! {
72+
#[avr_skip]
7273
#[maybe_use_optimized_c_shim]
7374
pub extern "C" fn __ashlsi3(a: u32, b: u32) -> u32 {
7475
a.ashl(b)
7576
}
7677

78+
#[avr_skip]
7779
#[maybe_use_optimized_c_shim]
7880
#[arm_aeabi_alias = __aeabi_llsl]
7981
pub extern "C" fn __ashldi3(a: u64, b: u32) -> u64 {
8082
a.ashl(b)
8183
}
8284

85+
#[avr_skip]
8386
pub extern "C" fn __ashlti3(a: u128, b: u32) -> u128 {
8487
a.ashl(b)
8588
}
8689

90+
#[avr_skip]
8791
#[maybe_use_optimized_c_shim]
8892
pub extern "C" fn __ashrsi3(a: i32, b: u32) -> i32 {
8993
a.ashr(b)
9094
}
9195

96+
#[avr_skip]
9297
#[maybe_use_optimized_c_shim]
9398
#[arm_aeabi_alias = __aeabi_lasr]
9499
pub extern "C" fn __ashrdi3(a: i64, b: u32) -> i64 {
95100
a.ashr(b)
96101
}
97102

103+
#[avr_skip]
98104
pub extern "C" fn __ashrti3(a: i128, b: u32) -> i128 {
99105
a.ashr(b)
100106
}
101107

108+
#[avr_skip]
102109
#[maybe_use_optimized_c_shim]
103110
pub extern "C" fn __lshrsi3(a: u32, b: u32) -> u32 {
104111
a.lshr(b)
105112
}
106113

114+
#[avr_skip]
107115
#[maybe_use_optimized_c_shim]
108116
#[arm_aeabi_alias = __aeabi_llsr]
109117
pub extern "C" fn __lshrdi3(a: u64, b: u32) -> u64 {
110118
a.lshr(b)
111119
}
112120

121+
#[avr_skip]
113122
pub extern "C" fn __lshrti3(a: u128, b: u32) -> u128 {
114123
a.lshr(b)
115124
}

0 commit comments

Comments
 (0)