]>
git.proxmox.com Git - rustc.git/blob - library/stdarch/crates/core_arch/src/x86/bt.rs
2 use stdarch_test
::assert_instr
;
4 // x32 wants to use a 32-bit address size, but asm! defaults to using the full
5 // register name (e.g. rax). We have to explicitly override the placeholder to
6 // use the 32-bit register name in that case.
7 #[cfg(target_pointer_width = "32")]
10 concat
!($inst
, " {b:e}, ({p:e})")
13 #[cfg(target_pointer_width = "64")]
16 concat
!($inst
, " {b:e}, ({p})")
20 /// Returns the bit in position `b` of the memory addressed by `p`.
22 #[cfg_attr(test, assert_instr(bt))]
23 #[stable(feature = "simd_x86_bittest", since = "1.55.0")]
24 pub unsafe fn _bittest(p
: *const i32, b
: i32) -> u8 {
32 options(readonly
, nostack
, pure, att_syntax
)
37 /// Returns the bit in position `b` of the memory addressed by `p`, then sets the bit to `1`.
39 #[cfg_attr(test, assert_instr(bts))]
40 #[stable(feature = "simd_x86_bittest", since = "1.55.0")]
41 pub unsafe fn _bittestandset(p
: *mut i32, b
: i32) -> u8 {
49 options(nostack
, att_syntax
)
54 /// Returns the bit in position `b` of the memory addressed by `p`, then resets that bit to `0`.
56 #[cfg_attr(test, assert_instr(btr))]
57 #[stable(feature = "simd_x86_bittest", since = "1.55.0")]
58 pub unsafe fn _bittestandreset(p
: *mut i32, b
: i32) -> u8 {
66 options(nostack
, att_syntax
)
71 /// Returns the bit in position `b` of the memory addressed by `p`, then inverts that bit.
73 #[cfg_attr(test, assert_instr(btc))]
74 #[stable(feature = "simd_x86_bittest", since = "1.55.0")]
75 pub unsafe fn _bittestandcomplement(p
: *mut i32, b
: i32) -> u8 {
83 options(nostack
, att_syntax
)
90 use crate::core_arch
::x86
::*;
95 let a
= 0b0101_0000i32;
96 assert_eq
!(_bittest(&a
as _
, 4), 1);
97 assert_eq
!(_bittest(&a
as _
, 5), 0);
102 fn test_bittestandset() {
104 let mut a
= 0b0101_0000i32;
105 assert_eq
!(_bittestandset(&mut a
as _
, 4), 1);
106 assert_eq
!(_bittestandset(&mut a
as _
, 4), 1);
107 assert_eq
!(_bittestandset(&mut a
as _
, 5), 0);
108 assert_eq
!(_bittestandset(&mut a
as _
, 5), 1);
113 fn test_bittestandreset() {
115 let mut a
= 0b0101_0000i32;
116 assert_eq
!(_bittestandreset(&mut a
as _
, 4), 1);
117 assert_eq
!(_bittestandreset(&mut a
as _
, 4), 0);
118 assert_eq
!(_bittestandreset(&mut a
as _
, 5), 0);
119 assert_eq
!(_bittestandreset(&mut a
as _
, 5), 0);
124 fn test_bittestandcomplement() {
126 let mut a
= 0b0101_0000i32;
127 assert_eq
!(_bittestandcomplement(&mut a
as _
, 4), 1);
128 assert_eq
!(_bittestandcomplement(&mut a
as _
, 4), 0);
129 assert_eq
!(_bittestandcomplement(&mut a
as _
, 4), 1);
130 assert_eq
!(_bittestandcomplement(&mut a
as _
, 5), 0);
131 assert_eq
!(_bittestandcomplement(&mut a
as _
, 5), 1);