xref: /DragonOS/kernel/src/arch/x86_64/asm/bitops.rs (revision 7ae679ddd6481897a86523a52fad3b060254fa5b)
1 #![allow(dead_code)]
2 use core::arch::x86_64::_popcnt64;
3 
4 /// @brief ffz - 寻找u64中的第一个0所在的位(从第0位开始寻找)
5 /// 请注意,如果x中没有0,那么结果将是未定义的。请确保传入的x至少存在1个0
6 ///
7 /// @param x 目标u64
8 /// @return i32 bit-number(0..63) of the first (least significant) zero bit.
9 #[inline]
10 pub fn ffz(x: u64) -> i32 {
11     return unsafe { _popcnt64((x & ((!x) - 1)).try_into().unwrap()) };
12 }
13