Return the index of a non-zero bit Uses the BSF instruction: Assumes that at least one bit is not zero
(bitmap: u32)
| 19 | /// |
| 20 | /// Assumes that at least one bit is not zero |
| 21 | fn nonzero_bit_index(bitmap: u32) -> u32 { |
| 22 | let index: u32; |
| 23 | unsafe { |
| 24 | asm!("bsf eax, ecx", |
| 25 | in("ecx") bitmap, |
| 26 | lateout("eax") index, |
| 27 | options(pure, nomem, nostack)); |
| 28 | } |
| 29 | index |
| 30 | } |
| 31 | |
| 32 | #[test_case] |
| 33 | fn test_nonzero_bit_index() { |