[clang] 560aa53 - [X86] Support intrinsics _bextr2*

Shengchen Kan via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 11 18:27:16 PDT 2020


Author: Shengchen Kan
Date: 2020-03-12T09:26:51+08:00
New Revision: 560aa53f8fe58abcbc4bb441b631e8a401ee78fe

URL: https://github.com/llvm/llvm-project/commit/560aa53f8fe58abcbc4bb441b631e8a401ee78fe
DIFF: https://github.com/llvm/llvm-project/commit/560aa53f8fe58abcbc4bb441b631e8a401ee78fe.diff

LOG: [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

Added: 
    

Modified: 
    clang/lib/Headers/bmiintrin.h
    clang/test/CodeGen/bmi-builtins.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Headers/bmiintrin.h b/clang/lib/Headers/bmiintrin.h
index 841bd84070e8..937f1683b544 100644
--- a/clang/lib/Headers/bmiintrin.h
+++ b/clang/lib/Headers/bmiintrin.h
@@ -192,6 +192,28 @@ _bextr_u32(unsigned int __X, unsigned int __Y, unsigned int __Z)
   return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));
 }
 
+/* Intel-specified, single-leading-underscore version of BEXTR2 */
+/// Extracts the specified bits from the first operand and returns them
+///    in the least significant bits of the result.
+///
+/// \headerfile <x86intrin.h>
+///
+/// This intrinsic corresponds to the <c> BEXTR </c> instruction.
+///
+/// \param __X
+///    An unsigned integer whose bits are to be extracted.
+/// \param __Y
+///    An unsigned integer used to specify which bits are extracted. Bits [7:0]
+///    specify the index of the least significant bit. Bits [15:8] specify the
+///    number of bits to be extracted.
+/// \returns An unsigned integer whose least significant bits contain the
+///    extracted bits.
+/// \see __bextr_u32
+static __inline__ unsigned int __DEFAULT_FN_ATTRS
+_bextr2_u32(unsigned int __X, unsigned int __Y) {
+  return __builtin_ia32_bextr_u32(__X, __Y);
+}
+
 /// Clears all bits in the source except for the least significant bit
 ///    containing a value of 1 and returns the result.
 ///
@@ -321,6 +343,28 @@ _bextr_u64(unsigned long long __X, unsigned int __Y, unsigned int __Z)
   return __builtin_ia32_bextr_u64 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));
 }
 
+/* Intel-specified, single-leading-underscore version of BEXTR2 */
+/// Extracts the specified bits from the first operand and returns them
+///    in the least significant bits of the result.
+///
+/// \headerfile <x86intrin.h>
+///
+/// This intrinsic corresponds to the <c> BEXTR </c> instruction.
+///
+/// \param __X
+///    An unsigned 64-bit integer whose bits are to be extracted.
+/// \param __Y
+///    An unsigned 64-bit integer used to specify which bits are extracted. Bits
+///    [7:0] specify the index of the least significant bit. Bits [15:8] specify
+///    the number of bits to be extracted.
+/// \returns An unsigned 64-bit integer whose least significant bits contain the
+///    extracted bits.
+/// \see __bextr_u64
+static __inline__ unsigned long long __DEFAULT_FN_ATTRS
+_bextr2_u64(unsigned long long __X, unsigned long long __Y) {
+  return __builtin_ia32_bextr_u64(__X, __Y);
+}
+
 /// Clears all bits in the source except for the least significant bit
 ///    containing a value of 1 and returns the result.
 ///

diff  --git a/clang/test/CodeGen/bmi-builtins.c b/clang/test/CodeGen/bmi-builtins.c
index 9f2d776299f8..409dd40c4a33 100644
--- a/clang/test/CodeGen/bmi-builtins.c
+++ b/clang/test/CodeGen/bmi-builtins.c
@@ -155,6 +155,12 @@ unsigned int test_bextr_u32(unsigned int __X, unsigned int __Y,
   return _bextr_u32(__X, __Y, __Z);
 }
 
+unsigned int test_bextr2_u32(unsigned int __X, unsigned int __Y) {
+  // CHECK-LABEL: test_bextr2_u32
+  // CHECK: i32 @llvm.x86.bmi.bextr.32(i32 %{{.*}}, i32 %{{.*}})
+  return _bextr2_u32(__X, __Y);
+}
+
 unsigned int test_blsi_u32(unsigned int __X) {
   // CHECK-LABEL: test_blsi_u32
   // CHECK: sub i32 0, %{{.*}}
@@ -196,6 +202,13 @@ unsigned long long test_bextr_u64(unsigned long __X, unsigned int __Y,
   return _bextr_u64(__X, __Y, __Z);
 }
 
+unsigned long long test_bextr2_u64(unsigned long long __X,
+                                   unsigned long long __Y) {
+  // CHECK-LABEL: test_bextr2_u64
+  // CHECK: i64 @llvm.x86.bmi.bextr.64(i64 %{{.*}}, i64 %{{.*}})
+  return _bextr2_u64(__X, __Y);
+}
+
 unsigned long long test_blsi_u64(unsigned long long __X) {
   // CHECK-LABEL: test_blsi_u64
   // CHECK: sub i64 0, %{{.*}}


        


More information about the cfe-commits mailing list