Skip to content

Commit 122ccd5

Browse files
KanRobertmemfrob
authored andcommitted
[X86] Support intrinsics _bextr2*
Reviewers: LuoYuanke, craig.topper, RKSimon, pengfei Reviewed By: craig.topper Subscribers: cfe-commits, llvm-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D75894
1 parent 4b0f167 commit 122ccd5

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

clang/lib/Headers/bmiintrin.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,28 @@ _bextr_u32(unsigned int __X, unsigned int __Y, unsigned int __Z)
192192
return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));
193193
}
194194

195+
/* Intel-specified, single-leading-underscore version of BEXTR2 */
196+
/// Extracts the specified bits from the first operand and returns them
197+
/// in the least significant bits of the result.
198+
///
199+
/// \headerfile <x86intrin.h>
200+
///
201+
/// This intrinsic corresponds to the <c> BEXTR </c> instruction.
202+
///
203+
/// \param __X
204+
/// An unsigned integer whose bits are to be extracted.
205+
/// \param __Y
206+
/// An unsigned integer used to specify which bits are extracted. Bits [7:0]
207+
/// specify the index of the least significant bit. Bits [15:8] specify the
208+
/// number of bits to be extracted.
209+
/// \returns An unsigned integer whose least significant bits contain the
210+
/// extracted bits.
211+
/// \see __bextr_u32
212+
static __inline__ unsigned int __DEFAULT_FN_ATTRS
213+
_bextr2_u32(unsigned int __X, unsigned int __Y) {
214+
return __builtin_ia32_bextr_u32(__X, __Y);
215+
}
216+
195217
/// Clears all bits in the source except for the least significant bit
196218
/// containing a value of 1 and returns the result.
197219
///
@@ -321,6 +343,28 @@ _bextr_u64(unsigned long long __X, unsigned int __Y, unsigned int __Z)
321343
return __builtin_ia32_bextr_u64 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));
322344
}
323345

346+
/* Intel-specified, single-leading-underscore version of BEXTR2 */
347+
/// Extracts the specified bits from the first operand and returns them
348+
/// in the least significant bits of the result.
349+
///
350+
/// \headerfile <x86intrin.h>
351+
///
352+
/// This intrinsic corresponds to the <c> BEXTR </c> instruction.
353+
///
354+
/// \param __X
355+
/// An unsigned 64-bit integer whose bits are to be extracted.
356+
/// \param __Y
357+
/// An unsigned 64-bit integer used to specify which bits are extracted. Bits
358+
/// [7:0] specify the index of the least significant bit. Bits [15:8] specify
359+
/// the number of bits to be extracted.
360+
/// \returns An unsigned 64-bit integer whose least significant bits contain the
361+
/// extracted bits.
362+
/// \see __bextr_u64
363+
static __inline__ unsigned long long __DEFAULT_FN_ATTRS
364+
_bextr2_u64(unsigned long long __X, unsigned long long __Y) {
365+
return __builtin_ia32_bextr_u64(__X, __Y);
366+
}
367+
324368
/// Clears all bits in the source except for the least significant bit
325369
/// containing a value of 1 and returns the result.
326370
///

clang/test/CodeGen/bmi-builtins.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ unsigned int test_bextr_u32(unsigned int __X, unsigned int __Y,
155155
return _bextr_u32(__X, __Y, __Z);
156156
}
157157

158+
unsigned int test_bextr2_u32(unsigned int __X, unsigned int __Y) {
159+
// CHECK-LABEL: test_bextr2_u32
160+
// CHECK: i32 @llvm.x86.bmi.bextr.32(i32 %{{.*}}, i32 %{{.*}})
161+
return _bextr2_u32(__X, __Y);
162+
}
163+
158164
unsigned int test_blsi_u32(unsigned int __X) {
159165
// CHECK-LABEL: test_blsi_u32
160166
// CHECK: sub i32 0, %{{.*}}
@@ -196,6 +202,13 @@ unsigned long long test_bextr_u64(unsigned long __X, unsigned int __Y,
196202
return _bextr_u64(__X, __Y, __Z);
197203
}
198204

205+
unsigned long long test_bextr2_u64(unsigned long long __X,
206+
unsigned long long __Y) {
207+
// CHECK-LABEL: test_bextr2_u64
208+
// CHECK: i64 @llvm.x86.bmi.bextr.64(i64 %{{.*}}, i64 %{{.*}})
209+
return _bextr2_u64(__X, __Y);
210+
}
211+
199212
unsigned long long test_blsi_u64(unsigned long long __X) {
200213
// CHECK-LABEL: test_blsi_u64
201214
// CHECK: sub i64 0, %{{.*}}

0 commit comments

Comments
 (0)