| 1 |
// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s |
| 2 |
// RUN: %clang_cc1 -x c -ffreestanding %s -triple=i386-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s --check-prefix=B32 |
| 3 |
// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s |
| 4 |
// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=i386-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s --check-prefix=B32 |
| 5 |
|
| 6 |
// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi2 -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s |
| 7 |
// RUN: %clang_cc1 -x c -ffreestanding %s -triple=i386-apple-darwin -target-feature +bmi2 -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s --check-prefix=B32 |
| 8 |
// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi2 -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s |
| 9 |
// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=i386-apple-darwin -target-feature +bmi2 -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s --check-prefix=B32 |
| 10 |
|
| 11 |
|
| 12 |
#include <immintrin.h> |
| 13 |
|
| 14 |
unsigned int test_bzhi_u32(unsigned int __X, unsigned int __Y) { |
| 15 |
// CHECK: @llvm.x86.bmi.bzhi.32 |
| 16 |
return _bzhi_u32(__X, __Y); |
| 17 |
} |
| 18 |
|
| 19 |
unsigned int test_pdep_u32(unsigned int __X, unsigned int __Y) { |
| 20 |
// CHECK: @llvm.x86.bmi.pdep.32 |
| 21 |
return _pdep_u32(__X, __Y); |
| 22 |
} |
| 23 |
|
| 24 |
unsigned int test_pext_u32(unsigned int __X, unsigned int __Y) { |
| 25 |
// CHECK: @llvm.x86.bmi.pext.32 |
| 26 |
return _pext_u32(__X, __Y); |
| 27 |
} |
| 28 |
|
| 29 |
#ifdef __i386__ |
| 30 |
unsigned int test_mulx_u32(unsigned int __X, unsigned int __Y, |
| 31 |
unsigned int *__P) { |
| 32 |
// B32: mul i64 |
| 33 |
return _mulx_u32(__X, __Y, __P); |
| 34 |
} |
| 35 |
#endif |
| 36 |
|
| 37 |
#ifdef __x86_64__ |
| 38 |
unsigned long long test_bzhi_u64(unsigned long long __X, unsigned long long __Y) { |
| 39 |
// CHECK: @llvm.x86.bmi.bzhi.64 |
| 40 |
return _bzhi_u64(__X, __Y); |
| 41 |
} |
| 42 |
|
| 43 |
unsigned long long test_pdep_u64(unsigned long long __X, unsigned long long __Y) { |
| 44 |
// CHECK: @llvm.x86.bmi.pdep.64 |
| 45 |
return _pdep_u64(__X, __Y); |
| 46 |
} |
| 47 |
|
| 48 |
unsigned long long test_pext_u64(unsigned long long __X, unsigned long long __Y) { |
| 49 |
// CHECK: @llvm.x86.bmi.pext.64 |
| 50 |
return _pext_u64(__X, __Y); |
| 51 |
} |
| 52 |
|
| 53 |
unsigned long long test_mulx_u64(unsigned long long __X, unsigned long long __Y, |
| 54 |
unsigned long long *__P) { |
| 55 |
// CHECK: mul i128 |
| 56 |
return _mulx_u64(__X, __Y, __P); |
| 57 |
} |
| 58 |
#endif |
| 59 |
|
| 60 |
// Test constexpr handling. |
| 61 |
#if defined(__cplusplus) && (__cplusplus >= 201103L) |
| 62 |
char bzhi32_0[_bzhi_u32(0x89ABCDEF, 0) == 0x00000000 ? 1 : -1]; |
| 63 |
char bzhi32_1[_bzhi_u32(0x89ABCDEF, 16) == 0x0000CDEF ? 1 : -1]; |
| 64 |
char bzhi32_2[_bzhi_u32(0x89ABCDEF, 31) == 0x09ABCDEF ? 1 : -1]; |
| 65 |
char bzhi32_3[_bzhi_u32(0x89ABCDEF, 32) == 0x89ABCDEF ? 1 : -1]; |
| 66 |
char bzhi32_4[_bzhi_u32(0x89ABCDEF, 99) == 0x89ABCDEF ? 1 : -1]; |
| 67 |
char bzhi32_5[_bzhi_u32(0x89ABCDEF, 260) == 0x0000000F ? 1 : -1]; |
| 68 |
|
| 69 |
char pdep32_0[_pdep_u32(0x89ABCDEF, 0x00000000) == 0x00000000 ? 1 : -1]; |
| 70 |
char pdep32_1[_pdep_u32(0x89ABCDEF, 0x000000F0) == 0x000000F0 ? 1 : -1]; |
| 71 |
char pdep32_2[_pdep_u32(0x89ABCDEF, 0xF00000F0) == 0xE00000F0 ? 1 : -1]; |
| 72 |
char pdep32_3[_pdep_u32(0x89ABCDEF, 0xFFFFFFFF) == 0x89ABCDEF ? 1 : -1]; |
| 73 |
|
| 74 |
char pext32_0[_pext_u32(0x89ABCDEF, 0x00000000) == 0x00000000 ? 1 : -1]; |
| 75 |
char pext32_1[_pext_u32(0x89ABCDEF, 0x000000F0) == 0x0000000E ? 1 : -1]; |
| 76 |
char pext32_2[_pext_u32(0x89ABCDEF, 0xF00000F0) == 0x0000008E ? 1 : -1]; |
| 77 |
char pext32_3[_pext_u32(0x89ABCDEF, 0xFFFFFFFF) == 0x89ABCDEF ? 1 : -1]; |
| 78 |
|
| 79 |
constexpr unsigned long long |
| 80 |
test_mulx_u32(unsigned int X, unsigned int Y) |
| 81 |
{ |
| 82 |
unsigned int H{}; |
| 83 |
return _mulx_u32(X, Y, &H) | ((unsigned long long) H << 32); |
| 84 |
} |
| 85 |
|
| 86 |
void mulxu32() { |
| 87 |
constexpr unsigned X = 0x89ABCDEF, Y = 0x01234567; |
| 88 |
static_assert(test_mulx_u32(X,Y) == ((unsigned long long)X * Y)); |
| 89 |
} |
| 90 |
|
| 91 |
#ifdef __x86_64__ |
| 92 |
char bzhi64_0[_bzhi_u64(0x0123456789ABCDEFULL, 0) == 0x0000000000000000ULL ? 1 : -1]; |
| 93 |
char bzhi64_1[_bzhi_u64(0x0123456789ABCDEFULL, 32) == 0x0000000089ABCDEFULL ? 1 : -1]; |
| 94 |
char bzhi64_2[_bzhi_u64(0x0123456789ABCDEFULL, 99) == 0x0123456789ABCDEFULL ? 1 : -1]; |
| 95 |
char bzhi64_3[_bzhi_u64(0x0123456789ABCDEFULL, 520) == 0x00000000000000EFULL ? 1 : -1]; |
| 96 |
|
| 97 |
char pdep64_0[_pdep_u64(0x0123456789ABCDEFULL, 0x0000000000000000ULL) == 0x0000000000000000ULL ? 1 : -1]; |
| 98 |
char pdep64_1[_pdep_u64(0x0123456789ABCDEFULL, 0x00000000000000F0ULL) == 0x00000000000000F0ULL ? 1 : -1]; |
| 99 |
char pdep64_2[_pdep_u64(0x0123456789ABCDEFULL, 0xF00000F0F00000F0ULL) == 0xC00000D0E00000F0ULL ? 1 : -1]; |
| 100 |
char pdep64_3[_pdep_u64(0x0123456789ABCDEFULL, 0xFFFFFFFFFFFFFFFFULL) == 0x0123456789ABCDEFULL ? 1 : -1]; |
| 101 |
|
| 102 |
char pext64_0[_pext_u64(0x0123456789ABCDEFULL, 0x0000000000000000ULL) == 0x0000000000000000ULL ? 1 : -1]; |
| 103 |
char pext64_1[_pext_u64(0x0123456789ABCDEFULL, 0x00000000000000F0ULL) == 0x000000000000000EULL ? 1 : -1]; |
| 104 |
char pext64_2[_pext_u64(0x0123456789ABCDEFULL, 0xF00000F0F00000F0ULL) == 0x000000000000068EULL ? 1 : -1]; |
| 105 |
char pext64_3[_pext_u64(0x0123456789ABCDEFULL, 0xFFFFFFFFFFFFFFFFULL) == 0x0123456789ABCDEFULL ? 1 : -1]; |
| 106 |
|
| 107 |
constexpr unsigned __int128 |
| 108 |
test_mulx_u64(unsigned long long X, unsigned long long Y) |
| 109 |
{ |
| 110 |
unsigned long long H{}; |
| 111 |
return _mulx_u64(X, Y, &H) | ((unsigned __int128) H << 64); |
| 112 |
} |
| 113 |
|
| 114 |
void mulxu64() { |
| 115 |
constexpr unsigned long long X = 0x0123456789ABCDEFULL, Y = 0xFEDCBA9876543210ULL; |
| 116 |
static_assert(test_mulx_u64(X,Y) == ((unsigned __int128)X * Y)); |
| 117 |
} |
| 118 |
#endif |
| 119 |
#endif |