Skip to content

Commit 35025db

Browse files
gnzlbgBurntSushi
authored andcommitted
[abm] use lzcnt and popcnt features
1 parent e7702fb commit 35025db

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/x86/abm.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
//! Advanced Bit Manipulation (ABM) instructions
22
//!
3-
//! That is, POPCNT and LZCNT. These instructions have their own CPUID bits to
4-
//! indicate support.
5-
//!
6-
//! TODO: it is unclear which target feature to use here. SSE4.2 should be good
7-
//! enough but we might need to use BMI for LZCNT if there are any problems.
3+
//! The POPCNT and LZCNT have their own CPUID bits to indicate support.
84
//!
95
//! The references are:
106
//!
@@ -19,50 +15,50 @@
1915
///
2016
/// When the operand is zero, it returns its size in bits.
2117
#[inline(always)]
22-
#[target_feature = "+sse4.2"]
18+
#[target_feature = "+lzcnt"]
2319
pub fn _lzcnt_u32(x: u32) -> u32 { x.leading_zeros() }
2420

2521
/// Counts the leading most significant zero bits.
2622
///
2723
/// When the operand is zero, it returns its size in bits.
2824
#[inline(always)]
29-
#[target_feature = "+sse4.2"]
25+
#[target_feature = "+lzcnt"]
3026
pub fn _lzcnt_u64(x: u64) -> u64 { x.leading_zeros() as u64 }
3127

3228
/// Counts the bits that are set.
3329
#[inline(always)]
34-
#[target_feature = "+sse4.2"]
30+
#[target_feature = "+popcnt"]
3531
pub fn _popcnt32(x: u32) -> u32 { x.count_ones() }
3632

3733
/// Counts the bits that are set.
3834
#[inline(always)]
39-
#[target_feature = "+sse4.2"]
35+
#[target_feature = "+popcnt"]
4036
pub fn _popcnt64(x: u64) -> u64 { x.count_ones() as u64 }
4137

42-
#[cfg(all(test, target_feature = "sse4.2", any(target_arch = "x86", target_arch = "x86_64")))]
38+
#[cfg(all(test, target_feature = "bmi", any(target_arch = "x86", target_arch = "x86_64")))]
4339
mod tests {
4440
use x86::abm;
4541

4642
#[test]
47-
#[target_feature = "+sse4.2"]
43+
#[target_feature = "+lzcnt"]
4844
fn _lzcnt_u32() {
4945
assert_eq!(abm::_lzcnt_u32(0b0101_1010u32), 25u32);
5046
}
5147

5248
#[test]
53-
#[target_feature = "+sse4.2"]
49+
#[target_feature = "+lzcnt"]
5450
fn _lzcnt_u64() {
5551
assert_eq!(abm::_lzcnt_u64(0b0101_1010u64), 57u64);
5652
}
5753

5854
#[test]
59-
#[target_feature = "+sse4.2"]
55+
#[target_feature = "+popcnt"]
6056
fn _popcnt32() {
6157
assert_eq!(abm::_popcnt32(0b0101_1010u32), 4);
6258
}
6359

6460
#[test]
65-
#[target_feature = "+sse4.2"]
61+
#[target_feature = "+popcnt"]
6662
fn _popcnt64() {
6763
assert_eq!(abm::_popcnt64(0b0101_1010u64), 4);
6864
}

0 commit comments

Comments
 (0)