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

refac(hal-x86_64): use mycelium-bitfield for segment descrs #295

Merged
merged 3 commits into from
Aug 10, 2022
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions bitfield/src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ macro_rules! make_packers {
///
/// The two ranges must be the same size. This can be asserted
/// by the `assert_valid` method on the returned pair type.
pub const fn pair_with(&self, dst: Self) -> $Pair<T> {
pub const fn pair_with<F2>(&self, dst: $Pack<T, F2>) -> $Pair<T> {
// TODO(eliza): validate that `dst.shift + self.bits() < N_BITS` in
// const fn somehow lol
let (dst_shl, dst_shr) = if dst.shift > self.shift {
Expand Down Expand Up @@ -830,36 +830,36 @@ macro_rules! make_packers {
/// # Panics
///
/// If `value` contains bits outside the range specified by `packer`.
pub fn pack<T: FromBits<$Bits>>(self, value: T, packer: &$Pack<T>) -> Self {
pub fn pack<T: FromBits<$Bits>, F>(self, value: T, packer: &$Pack<T, F>) -> Self {
Self(packer.pack(value, self.0))
}

/// Set _all_ bits in the range specified by `packer` to 1 in `self`.
#[inline]
pub const fn set_all(self, packer: &$Pack) -> Self {
pub const fn set_all<T, F>(self, packer: &$Pack<T, F>) -> Self {
Self(packer.set_all(self.0))
}

/// Set _all_ bits in the range specified by `packer` to 0 in
/// `self`.
#[inline]
pub const fn unset_all(self, packer: &$Pack) -> Self {
pub const fn unset_all<T, F>(self, packer: &$Pack<T, F>) -> Self {
Self(packer.unset_all(self.0))
}


/// Returns `true` if **any** bits specified by `packer` are set
/// in `self`.
#[inline]
pub const fn contains_any(self, packer: &$Pack) -> bool {
pub const fn contains_any<T, F>(self, packer: &$Pack<T, F>) -> bool {
packer.contained_in_any(self.0)
}


/// Returns `true` if **any** bits specified by `packer` are set
/// in `self`.
#[inline]
pub const fn contains_all(self, packer: &$Pack) -> bool {
pub const fn contains_all<T, F>(self, packer: &$Pack<T, F>) -> bool {
packer.contained_in_all(self.0)
}

Expand Down
1 change: 0 additions & 1 deletion hal-x86_64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ log = ["tracing/log"]
hal-core = { path = "../hal-core" }
mycelium-util = { path = "../util" }
mycelium-trace = { path = "../trace" }
bitflags = "1.2"
mycotest = { path = "../mycotest"}
tracing = { git = "https://github.com/tokio-rs/tracing", default_features = false, features = ["attributes"] }
volatile = { version = "0.4.5", features = ["unstable"] }
Expand Down
13 changes: 13 additions & 0 deletions hal-x86_64/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ impl Ring {
}
}

impl bits::FromBits<u64> for Ring {
const BITS: u32 = 2;
type Error = core::convert::Infallible;

fn try_from_bits(u: u64) -> Result<Self, Self::Error> {
Ok(Self::from_u8(u as u8))
}

fn into_bits(self) -> u64 {
self as u8 as u64
}
}

impl bits::FromBits<u16> for Ring {
const BITS: u32 = 2;
type Error = core::convert::Infallible;
Expand Down
Loading