Skip to content

Commit b8fb0b1

Browse files
authored
Merge pull request #371 from maxaudron/master
add 32 bit shift instructions
2 parents 2635ae9 + 5238652 commit b8fb0b1

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/int/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ macro_rules! int_impl {
188188
};
189189
}
190190

191+
int_impl!(i16, u16, 16);
191192
int_impl!(i32, u32, 32);
192193
int_impl!(i64, u64, 64);
193194
int_impl!(i128, u128, 128);
@@ -229,6 +230,8 @@ macro_rules! large_int {
229230
};
230231
}
231232

233+
large_int!(u32, u16, u16, 16);
234+
large_int!(i32, u16, i16, 16);
232235
large_int!(u64, u32, u32, 32);
233236
large_int!(i64, u32, i32, 32);
234237
large_int!(u128, u64, u64, 64);

src/int/shift.rs

+18
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ trait Ashl: Int + LargeInt {
2020
}
2121
}
2222

23+
impl Ashl for u32 {}
2324
impl Ashl for u64 {}
2425
impl Ashl for u128 {}
2526

@@ -47,6 +48,7 @@ trait Ashr: Int + LargeInt {
4748
}
4849
}
4950

51+
impl Ashr for i32 {}
5052
impl Ashr for i64 {}
5153
impl Ashr for i128 {}
5254

@@ -70,10 +72,16 @@ trait Lshr: Int + LargeInt {
7072
}
7173
}
7274

75+
impl Lshr for u32 {}
7376
impl Lshr for u64 {}
7477
impl Lshr for u128 {}
7578

7679
intrinsics! {
80+
#[maybe_use_optimized_c_shim]
81+
pub extern "C" fn __ashlsi3(a: u32, b: u32) -> u32 {
82+
a.ashl(b)
83+
}
84+
7785
#[maybe_use_optimized_c_shim]
7886
#[arm_aeabi_alias = __aeabi_llsl]
7987
pub extern "C" fn __ashldi3(a: u64, b: u32) -> u64 {
@@ -84,6 +92,11 @@ intrinsics! {
8492
a.ashl(b)
8593
}
8694

95+
#[maybe_use_optimized_c_shim]
96+
pub extern "C" fn __ashrsi3(a: i32, b: u32) -> i32 {
97+
a.ashr(b)
98+
}
99+
87100
#[maybe_use_optimized_c_shim]
88101
#[arm_aeabi_alias = __aeabi_lasr]
89102
pub extern "C" fn __ashrdi3(a: i64, b: u32) -> i64 {
@@ -94,6 +107,11 @@ intrinsics! {
94107
a.ashr(b)
95108
}
96109

110+
#[maybe_use_optimized_c_shim]
111+
pub extern "C" fn __lshrsi3(a: u32, b: u32) -> u32 {
112+
a.lshr(b)
113+
}
114+
97115
#[maybe_use_optimized_c_shim]
98116
#[arm_aeabi_alias = __aeabi_llsr]
99117
pub extern "C" fn __lshrdi3(a: u64, b: u32) -> u64 {

testcrate/build.rs

+13
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,10 @@ fn main() {
857857
);
858858

859859
// int/shift.rs
860+
gen(
861+
|(a, b): (MyU32, MyU32)| Some(a.0 << (b.0 % 32)),
862+
"builtins::int::shift::__ashlsi3(a, b % 32)",
863+
);
860864
gen(
861865
|(a, b): (MyU64, MyU32)| Some(a.0 << (b.0 % 64)),
862866
"builtins::int::shift::__ashldi3(a, b % 64)",
@@ -865,6 +869,10 @@ fn main() {
865869
|(a, b): (MyU128, MyU32)| Some(a.0 << (b.0 % 128)),
866870
"builtins::int::shift::__ashlti3(a, b % 128)",
867871
);
872+
gen(
873+
|(a, b): (MyI32, MyU32)| Some(a.0 >> (b.0 % 32)),
874+
"builtins::int::shift::__ashrsi3(a, b % 32)",
875+
);
868876
gen(
869877
|(a, b): (MyI64, MyU32)| Some(a.0 >> (b.0 % 64)),
870878
"builtins::int::shift::__ashrdi3(a, b % 64)",
@@ -873,6 +881,10 @@ fn main() {
873881
|(a, b): (MyI128, MyU32)| Some(a.0 >> (b.0 % 128)),
874882
"builtins::int::shift::__ashrti3(a, b % 128)",
875883
);
884+
gen(
885+
|(a, b): (MyU32, MyU32)| Some(a.0 >> (b.0 % 32)),
886+
"builtins::int::shift::__lshrsi3(a, b % 32)",
887+
);
876888
gen(
877889
|(a, b): (MyU64, MyU32)| Some(a.0 >> (b.0 % 64)),
878890
"builtins::int::shift::__lshrdi3(a, b % 64)",
@@ -1285,6 +1297,7 @@ my_integer! {
12851297
struct MyI32(i32);
12861298
struct MyI64(i64);
12871299
struct MyI128(i128);
1300+
struct MyU16(u16);
12881301
struct MyU32(u32);
12891302
struct MyU64(u64);
12901303
struct MyU128(u128);

0 commit comments

Comments
 (0)