Skip to content

Commit

Permalink
x86_64: Move CpuInfo to common file
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jan 23, 2023
1 parent 1b52b61 commit c5e30b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
22 changes: 22 additions & 0 deletions src/imp/atomic128/detect/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#[derive(Clone, Copy)]
pub(crate) struct CpuInfo(u32);

impl CpuInfo {
#[inline]
fn set(&mut self, bit: u32) {
self.0 = set(self.0, bit);
}
#[inline]
fn test(self, bit: u32) -> bool {
test(self.0, bit)
}
}

#[inline]
fn set(x: u32, bit: u32) -> u32 {
x | 1 << bit
}
#[inline]
fn test(x: u32, bit: u32) -> bool {
x & (1 << bit) != 0
}
23 changes: 2 additions & 21 deletions src/imp/atomic128/detect/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,20 @@
allow(dead_code)
)]

include!("common.rs");

#[cfg(not(portable_atomic_no_asm))]
use core::arch::asm;
use core::{
arch::x86_64::CpuidResult,
sync::atomic::{AtomicU32, Ordering},
};

#[derive(Clone, Copy)]
pub(crate) struct CpuInfo(u32);

impl CpuInfo {
const INIT: u32 = 0;
const HAS_CMPXCHG16B: u32 = 1;
const HAS_VMOVDQA_ATOMIC: u32 = 2;

#[inline]
fn set(&mut self, bit: u32) {
self.0 = set(self.0, bit);
}
#[inline]
fn test(self, bit: u32) -> bool {
test(self.0, bit)
}

#[allow(clippy::unused_self)]
#[inline]
pub(crate) fn has_cmpxchg16b(self) -> bool {
Expand All @@ -56,15 +46,6 @@ impl CpuInfo {
}
}

#[inline]
fn set(x: u32, bit: u32) -> u32 {
x | 1 << bit
}
#[inline]
fn test(x: u32, bit: u32) -> bool {
x & (1 << bit) != 0
}

// Workaround for https://github.com/rust-lang/rust/issues/101346
// It is not clear if our use cases are affected, but we implement this just in case.
//
Expand Down

0 comments on commit c5e30b6

Please sign in to comment.