Skip to content

add 32 bit shift instructions #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/int/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ macro_rules! int_impl {
};
}

int_impl!(i16, u16, 16);
int_impl!(i32, u32, 32);
int_impl!(i64, u64, 64);
int_impl!(i128, u128, 128);
Expand Down Expand Up @@ -229,6 +230,8 @@ macro_rules! large_int {
};
}

large_int!(u32, u16, u16, 16);
large_int!(i32, u16, i16, 16);
large_int!(u64, u32, u32, 32);
large_int!(i64, u32, i32, 32);
large_int!(u128, u64, u64, 64);
Expand Down
18 changes: 18 additions & 0 deletions src/int/shift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ trait Ashl: Int + LargeInt {
}
}

impl Ashl for u32 {}
impl Ashl for u64 {}
impl Ashl for u128 {}

Expand Down Expand Up @@ -47,6 +48,7 @@ trait Ashr: Int + LargeInt {
}
}

impl Ashr for i32 {}
impl Ashr for i64 {}
impl Ashr for i128 {}

Expand All @@ -70,10 +72,16 @@ trait Lshr: Int + LargeInt {
}
}

impl Lshr for u32 {}
impl Lshr for u64 {}
impl Lshr for u128 {}

intrinsics! {
#[maybe_use_optimized_c_shim]
pub extern "C" fn __ashlsi3(a: u32, b: u32) -> u32 {
a.ashl(b)
}

#[maybe_use_optimized_c_shim]
#[arm_aeabi_alias = __aeabi_llsl]
pub extern "C" fn __ashldi3(a: u64, b: u32) -> u64 {
Expand All @@ -84,6 +92,11 @@ intrinsics! {
a.ashl(b)
}

#[maybe_use_optimized_c_shim]
pub extern "C" fn __ashrsi3(a: i32, b: u32) -> i32 {
a.ashr(b)
}

#[maybe_use_optimized_c_shim]
#[arm_aeabi_alias = __aeabi_lasr]
pub extern "C" fn __ashrdi3(a: i64, b: u32) -> i64 {
Expand All @@ -94,6 +107,11 @@ intrinsics! {
a.ashr(b)
}

#[maybe_use_optimized_c_shim]
pub extern "C" fn __lshrsi3(a: u32, b: u32) -> u32 {
a.lshr(b)
}

#[maybe_use_optimized_c_shim]
#[arm_aeabi_alias = __aeabi_llsr]
pub extern "C" fn __lshrdi3(a: u64, b: u32) -> u64 {
Expand Down
13 changes: 13 additions & 0 deletions testcrate/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,10 @@ fn main() {
);

// int/shift.rs
gen(
|(a, b): (MyU32, MyU32)| Some(a.0 << (b.0 % 32)),
"builtins::int::shift::__ashlsi3(a, b % 32)",
);
gen(
|(a, b): (MyU64, MyU32)| Some(a.0 << (b.0 % 64)),
"builtins::int::shift::__ashldi3(a, b % 64)",
Expand All @@ -865,6 +869,10 @@ fn main() {
|(a, b): (MyU128, MyU32)| Some(a.0 << (b.0 % 128)),
"builtins::int::shift::__ashlti3(a, b % 128)",
);
gen(
|(a, b): (MyI32, MyU32)| Some(a.0 >> (b.0 % 32)),
"builtins::int::shift::__ashrsi3(a, b % 32)",
);
gen(
|(a, b): (MyI64, MyU32)| Some(a.0 >> (b.0 % 64)),
"builtins::int::shift::__ashrdi3(a, b % 64)",
Expand All @@ -873,6 +881,10 @@ fn main() {
|(a, b): (MyI128, MyU32)| Some(a.0 >> (b.0 % 128)),
"builtins::int::shift::__ashrti3(a, b % 128)",
);
gen(
|(a, b): (MyU32, MyU32)| Some(a.0 >> (b.0 % 32)),
"builtins::int::shift::__lshrsi3(a, b % 32)",
);
gen(
|(a, b): (MyU64, MyU32)| Some(a.0 >> (b.0 % 64)),
"builtins::int::shift::__lshrdi3(a, b % 64)",
Expand Down Expand Up @@ -1285,6 +1297,7 @@ my_integer! {
struct MyI32(i32);
struct MyI64(i64);
struct MyI128(i128);
struct MyU16(u16);
struct MyU32(u32);
struct MyU64(u64);
struct MyU128(u128);
Expand Down