core/stdarch/crates/core_arch/src/x86/
tbm.rs1#[cfg(test)]
14use stdarch_test::assert_instr;
15
16unsafe extern "C" {
17 #[link_name = "llvm.x86.tbm.bextri.u32"]
18 fn bextri_u32(a: u32, control: u32) -> u32;
19}
20
21#[inline]
29#[target_feature(enable = "tbm")]
30#[cfg_attr(test, assert_instr(bextr, CONTROL = 0x0404))]
31#[rustc_legacy_const_generics(1)]
32#[stable(feature = "simd_x86_updates", since = "1.82.0")]
33pub fn _bextri_u32<const CONTROL: u32>(a: u32) -> u32 {
34 static_assert_uimm_bits!(CONTROL, 16);
35 unsafe { bextri_u32(a, CONTROL) }
36}
37
38#[inline]
42#[target_feature(enable = "tbm")]
43#[cfg_attr(test, assert_instr(blcfill))]
44#[stable(feature = "simd_x86", since = "1.27.0")]
45#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
46pub const fn _blcfill_u32(x: u32) -> u32 {
47 x & (x.wrapping_add(1))
48}
49
50#[inline]
54#[target_feature(enable = "tbm")]
55#[cfg_attr(test, assert_instr(blci))]
56#[stable(feature = "simd_x86", since = "1.27.0")]
57#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
58pub const fn _blci_u32(x: u32) -> u32 {
59 x | !x.wrapping_add(1)
60}
61
62#[inline]
66#[target_feature(enable = "tbm")]
67#[cfg_attr(test, assert_instr(blcic))]
68#[stable(feature = "simd_x86", since = "1.27.0")]
69#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
70pub const fn _blcic_u32(x: u32) -> u32 {
71 !x & x.wrapping_add(1)
72}
73
74#[inline]
79#[target_feature(enable = "tbm")]
80#[cfg_attr(test, assert_instr(blcmsk))]
81#[stable(feature = "simd_x86", since = "1.27.0")]
82#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
83pub const fn _blcmsk_u32(x: u32) -> u32 {
84 x ^ x.wrapping_add(1)
85}
86
87#[inline]
91#[target_feature(enable = "tbm")]
92#[cfg_attr(test, assert_instr(blcs))]
93#[stable(feature = "simd_x86", since = "1.27.0")]
94#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
95pub const fn _blcs_u32(x: u32) -> u32 {
96 x | x.wrapping_add(1)
97}
98
99#[inline]
103#[target_feature(enable = "tbm")]
104#[cfg_attr(test, assert_instr(blsfill))]
105#[stable(feature = "simd_x86", since = "1.27.0")]
106#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
107pub const fn _blsfill_u32(x: u32) -> u32 {
108 x | x.wrapping_sub(1)
109}
110
111#[inline]
115#[target_feature(enable = "tbm")]
116#[cfg_attr(test, assert_instr(blsic))]
117#[stable(feature = "simd_x86", since = "1.27.0")]
118#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
119pub const fn _blsic_u32(x: u32) -> u32 {
120 !x | x.wrapping_sub(1)
121}
122
123#[inline]
128#[target_feature(enable = "tbm")]
129#[cfg_attr(test, assert_instr(t1mskc))]
130#[stable(feature = "simd_x86", since = "1.27.0")]
131#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
132pub const fn _t1mskc_u32(x: u32) -> u32 {
133 !x | x.wrapping_add(1)
134}
135
136#[inline]
141#[target_feature(enable = "tbm")]
142#[cfg_attr(test, assert_instr(tzmsk))]
143#[stable(feature = "simd_x86", since = "1.27.0")]
144#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
145pub const fn _tzmsk_u32(x: u32) -> u32 {
146 !x & x.wrapping_sub(1)
147}
148
149#[cfg(test)]
150mod tests {
151 use crate::core_arch::assert_eq_const as assert_eq;
152 use stdarch_test::simd_test;
153
154 use crate::core_arch::x86::*;
155
156 #[simd_test(enable = "tbm")]
157 fn test_bextri_u32() {
158 assert_eq!(_bextri_u32::<0x0404>(0b0101_0000u32), 0b0000_0101u32);
159 }
160
161 #[simd_test(enable = "tbm")]
162 const fn test_blcfill_u32() {
163 assert_eq!(_blcfill_u32(0b0101_0111u32), 0b0101_0000u32);
164 assert_eq!(_blcfill_u32(0b1111_1111u32), 0u32);
165 }
166
167 #[simd_test(enable = "tbm")]
168 const fn test_blci_u32() {
169 assert_eq!(
170 _blci_u32(0b0101_0000u32),
171 0b1111_1111_1111_1111_1111_1111_1111_1110u32
172 );
173 assert_eq!(
174 _blci_u32(0b1111_1111u32),
175 0b1111_1111_1111_1111_1111_1110_1111_1111u32
176 );
177 }
178
179 #[simd_test(enable = "tbm")]
180 const fn test_blcic_u32() {
181 assert_eq!(_blcic_u32(0b0101_0001u32), 0b0000_0010u32);
182 assert_eq!(_blcic_u32(0b1111_1111u32), 0b1_0000_0000u32);
183 }
184
185 #[simd_test(enable = "tbm")]
186 const fn test_blcmsk_u32() {
187 assert_eq!(_blcmsk_u32(0b0101_0001u32), 0b0000_0011u32);
188 assert_eq!(_blcmsk_u32(0b1111_1111u32), 0b1_1111_1111u32);
189 }
190
191 #[simd_test(enable = "tbm")]
192 const fn test_blcs_u32() {
193 assert_eq!(_blcs_u32(0b0101_0001u32), 0b0101_0011u32);
194 assert_eq!(_blcs_u32(0b1111_1111u32), 0b1_1111_1111u32);
195 }
196
197 #[simd_test(enable = "tbm")]
198 const fn test_blsfill_u32() {
199 assert_eq!(_blsfill_u32(0b0101_0100u32), 0b0101_0111u32);
200 assert_eq!(
201 _blsfill_u32(0u32),
202 0b1111_1111_1111_1111_1111_1111_1111_1111u32
203 );
204 }
205
206 #[simd_test(enable = "tbm")]
207 const fn test_blsic_u32() {
208 assert_eq!(
209 _blsic_u32(0b0101_0100u32),
210 0b1111_1111_1111_1111_1111_1111_1111_1011u32
211 );
212 assert_eq!(
213 _blsic_u32(0u32),
214 0b1111_1111_1111_1111_1111_1111_1111_1111u32
215 );
216 }
217
218 #[simd_test(enable = "tbm")]
219 const fn test_t1mskc_u32() {
220 assert_eq!(
221 _t1mskc_u32(0b0101_0111u32),
222 0b1111_1111_1111_1111_1111_1111_1111_1000u32
223 );
224 assert_eq!(
225 _t1mskc_u32(0u32),
226 0b1111_1111_1111_1111_1111_1111_1111_1111u32
227 );
228 }
229
230 #[simd_test(enable = "tbm")]
231 const fn test_tzmsk_u32() {
232 assert_eq!(_tzmsk_u32(0b0101_1000u32), 0b0000_0111u32);
233 assert_eq!(_tzmsk_u32(0b0101_1001u32), 0b0000_0000u32);
234 }
235}