Skip to content
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

Fix #19 - Remove broken Rust nightly support. #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ readme = "readme.md"
keywords = ["portable", "bit", "manipulation", "intrinsics"]
license = "MIT"
categories = ["algorithms", "hardware-support", "no-std"]
build = "build.rs"
edition = "2018"

[badges]
Expand Down
23 changes: 0 additions & 23 deletions build.rs

This file was deleted.

2 changes: 1 addition & 1 deletion check_asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def compile_file(file):
if verbose:
print "Checking: " + str(file) + "..."

cargo_args = 'cargo rustc --verbose --release -- -C panic=abort -C codegen-units=1 -C lto=fat --cfg=\'bitintr_nightly\' '
cargo_args = 'cargo rustc --verbose --release -- -C panic=abort -C codegen-units=1 -C lto=fat '
if file.feature:
cargo_args = cargo_args + '-C target-feature=+{}'.format(file.feature)
if file.arch == 'armv7' or file.arch == 'armv8':
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//! in the target. You might manually enable features via `-C
//! target-feature=+...` and/or `-C target-cpu=...`.
#![no_std]
#![cfg_attr(bitintr_nightly, feature(stdsimd))]

use core::{marker, mem};

Expand Down
149 changes: 66 additions & 83 deletions src/rbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,96 +26,79 @@ pub trait Rbit {
fn rbit(self) -> Self;
}

cfg_if! {
// The reverse_bits methods have been stabilized and should land
// in Rust 1.37.0 .
if #[cfg(bitintr_nightly)] {
macro_rules! impl_rbit {
($id:ident) => {
impl Rbit for $id {
#[inline]
fn rbit(self) -> Self {
self.reverse_bits()
}
macro_rules! impl_rbit {
($id:ident) => {
impl Rbit for $id {
#[inline]
fn rbit(self) -> Self {
if crate::mem::size_of::<Self>() == 1 {
return (((self as u8 as u64).wrapping_mul(0x80200802_u64)
& 0x0884422110_u64)
.wrapping_mul(0x0101010101_u64)
.wrapping_shr(32)) as Self;
}
};
}
} else {
macro_rules! impl_rbit {
($id:ident) => {
impl Rbit for $id {
#[inline]
fn rbit(self) -> Self {
if crate::mem::size_of::<Self>() == 1 {
return (((self as u8 as u64).wrapping_mul(0x80200802_u64)
& 0x0884422110_u64)
.wrapping_mul(0x0101010101_u64)
.wrapping_shr(32)) as Self;
}
let mut x = self;
let byte_width = crate::mem::size_of::<Self>() as u32;
let bit_width = byte_width * 8;
let k = bit_width - 1;
let mut x = self;
let byte_width = crate::mem::size_of::<Self>() as u32;
let bit_width = byte_width * 8;
let k = bit_width - 1;

{
let mut up0 = |i: u32, l: u64, r: u64| {
if k & i > 0 {
x = (((x as u64 & l).wrapping_shl(i))
| ((x as u64 & r).wrapping_shr(i)))
as Self;
}
};

up0(
1,
0x5555555555555555_u64,
0xAAAAAAAAAAAAAAAA_u64,
);
up0(
2,
0x3333333333333333_u64,
0xCCCCCCCCCCCCCCCC_u64,
);
up0(
4,
0x0F0F0F0F0F0F0F0F_u64,
0xF0F0F0F0F0F0F0F0_u64,
);
}
{
let mut up1 = |i: u32, s: u32, l: u64, r: u64| {
if byte_width > i && (k & s > 0) {
x = (((x as u64 & l).wrapping_shl(s))
| ((x as u64 & r).wrapping_shr(s)))
{
let mut up0 = |i: u32, l: u64, r: u64| {
if k & i > 0 {
x = (((x as u64 & l).wrapping_shl(i))
| ((x as u64 & r).wrapping_shr(i)))
as Self;
}
};
}
};

up1(
1,
8,
0x00FF00FF00FF00FF_u64,
0xFF00FF00FF00FF00_u64,
);
up1(
2,
16,
0x0000FFFF0000FFFF_u64,
0xFFFF0000FFFF0000_u64,
);
up1(
4,
32,
0x00000000FFFFFFFF_u64,
0xFFFFFFFF00000000_u64,
);
up0(
1,
0x5555555555555555_u64,
0xAAAAAAAAAAAAAAAA_u64,
);
up0(
2,
0x3333333333333333_u64,
0xCCCCCCCCCCCCCCCC_u64,
);
up0(
4,
0x0F0F0F0F0F0F0F0F_u64,
0xF0F0F0F0F0F0F0F0_u64,
);
}
{
let mut up1 = |i: u32, s: u32, l: u64, r: u64| {
if byte_width > i && (k & s > 0) {
x = (((x as u64 & l).wrapping_shl(s))
| ((x as u64 & r).wrapping_shr(s)))
as Self;
}
x
}
};

up1(
1,
8,
0x00FF00FF00FF00FF_u64,
0xFF00FF00FF00FF00_u64,
);
up1(
2,
16,
0x0000FFFF0000FFFF_u64,
0xFFFF0000FFFF0000_u64,
);
up1(
4,
32,
0x00000000FFFFFFFF_u64,
0xFFFFFFFF00000000_u64,
);
}
};
x
}
}
}
};
}

impl_all!(impl_rbit: u8, u16, u32, u64, i8, i16, i32, i64);
Expand Down