Attempt to use intrinsics!

This commit is contained in:
Lokathor 2019-01-04 19:17:02 -07:00
parent 2e8b85439f
commit 9a68e74ebd

View File

@ -301,64 +301,67 @@ macro_rules! impl_wide_int {
impl_wide_int!(u32, u64, 32);
impl_wide_int!(u64, u128, 64);
#[no_mangle]
#[cfg(any(
target_pointer_width = "16",
target_pointer_width = "32",
target_pointer_width = "64"
))]
pub extern "C" fn __clzsi2(mut x: usize) -> usize {
// TODO: const this? Would require const-if
let mut y: usize;
let mut n: usize = {
intrinsics! {
#[cfg(any(
target_pointer_width = "16",
target_pointer_width = "32",
target_pointer_width = "64"
))]
pub extern "C" fn __clzsi2(x: usize) -> usize {
// TODO: const this? Would require const-if
// Note(Lokathor): the `intrinsics!` macro can't process mut inputs
let mut x = x;
let mut y: usize;
let mut n: usize = {
#[cfg(target_pointer_width = "64")]
{
64
}
#[cfg(target_pointer_width = "32")]
{
32
}
#[cfg(target_pointer_width = "16")]
{
16
}
};
#[cfg(target_pointer_width = "64")]
{
64
y = x >> 32;
if y != 0 {
n -= 32;
x = y;
}
}
#[cfg(target_pointer_width = "32")]
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
{
32
y = x >> 16;
if y != 0 {
n -= 16;
x = y;
}
}
#[cfg(target_pointer_width = "16")]
{
16
}
};
#[cfg(target_pointer_width = "64")]
{
y = x >> 32;
y = x >> 8;
if y != 0 {
n -= 32;
n -= 8;
x = y;
}
}
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
{
y = x >> 16;
y = x >> 4;
if y != 0 {
n -= 16;
n -= 4;
x = y;
}
}
y = x >> 8;
if y != 0 {
n -= 8;
x = y;
}
y = x >> 4;
if y != 0 {
n -= 4;
x = y;
}
y = x >> 2;
if y != 0 {
n -= 2;
x = y;
}
y = x >> 1;
if y != 0 {
n - 2
} else {
n - x
y = x >> 2;
if y != 0 {
n -= 2;
x = y;
}
y = x >> 1;
if y != 0 {
n - 2
} else {
n - x
}
}
}