brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.3 KiB · 1b2cb90 Raw
119 lines · c
1// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s2// RUN: %clang_cc1 -x c -ffreestanding %s -triple=i386-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s --check-prefix=B323// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s4// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=i386-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s --check-prefix=B325 6// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi2 -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s7// 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=B328// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi2 -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s9// 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=B3210 11 12#include <immintrin.h>13 14unsigned int test_bzhi_u32(unsigned int __X, unsigned int __Y) {15  // CHECK: @llvm.x86.bmi.bzhi.3216  return _bzhi_u32(__X, __Y);17}18 19unsigned int test_pdep_u32(unsigned int __X, unsigned int __Y) {20  // CHECK: @llvm.x86.bmi.pdep.3221  return _pdep_u32(__X, __Y);22}23 24unsigned int test_pext_u32(unsigned int __X, unsigned int __Y) {25  // CHECK: @llvm.x86.bmi.pext.3226  return _pext_u32(__X, __Y);27}28 29#ifdef __i386__30unsigned int test_mulx_u32(unsigned int __X, unsigned int __Y,31                                 unsigned int *__P) {32  // B32: mul i6433  return _mulx_u32(__X, __Y, __P);34}35#endif36 37#ifdef __x86_64__38unsigned long long test_bzhi_u64(unsigned long long __X, unsigned long long __Y) {39  // CHECK: @llvm.x86.bmi.bzhi.6440  return _bzhi_u64(__X, __Y);41}42 43unsigned long long test_pdep_u64(unsigned long long __X, unsigned long long __Y) {44  // CHECK: @llvm.x86.bmi.pdep.6445  return _pdep_u64(__X, __Y);46}47 48unsigned long long test_pext_u64(unsigned long long __X, unsigned long long __Y) {49  // CHECK: @llvm.x86.bmi.pext.6450  return _pext_u64(__X, __Y);51}52 53unsigned long long test_mulx_u64(unsigned long long __X, unsigned long long __Y,54                                 unsigned long long *__P) {55  // CHECK: mul i12856  return _mulx_u64(__X, __Y, __P);57}58#endif59 60// Test constexpr handling.61#if defined(__cplusplus) && (__cplusplus >= 201103L)62char bzhi32_0[_bzhi_u32(0x89ABCDEF,   0) == 0x00000000 ? 1 : -1];63char bzhi32_1[_bzhi_u32(0x89ABCDEF,  16) == 0x0000CDEF ? 1 : -1];64char bzhi32_2[_bzhi_u32(0x89ABCDEF,  31) == 0x09ABCDEF ? 1 : -1];65char bzhi32_3[_bzhi_u32(0x89ABCDEF,  32) == 0x89ABCDEF ? 1 : -1];66char bzhi32_4[_bzhi_u32(0x89ABCDEF,  99) == 0x89ABCDEF ? 1 : -1];67char bzhi32_5[_bzhi_u32(0x89ABCDEF, 260) == 0x0000000F ? 1 : -1];68 69char pdep32_0[_pdep_u32(0x89ABCDEF,  0x00000000) == 0x00000000 ? 1 : -1];70char pdep32_1[_pdep_u32(0x89ABCDEF,  0x000000F0) == 0x000000F0 ? 1 : -1];71char pdep32_2[_pdep_u32(0x89ABCDEF,  0xF00000F0) == 0xE00000F0 ? 1 : -1];72char pdep32_3[_pdep_u32(0x89ABCDEF,  0xFFFFFFFF) == 0x89ABCDEF ? 1 : -1];73 74char pext32_0[_pext_u32(0x89ABCDEF,  0x00000000) == 0x00000000 ? 1 : -1];75char pext32_1[_pext_u32(0x89ABCDEF,  0x000000F0) == 0x0000000E ? 1 : -1];76char pext32_2[_pext_u32(0x89ABCDEF,  0xF00000F0) == 0x0000008E ? 1 : -1];77char pext32_3[_pext_u32(0x89ABCDEF,  0xFFFFFFFF) == 0x89ABCDEF ? 1 : -1];78 79constexpr unsigned long long80test_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 86void 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__92char bzhi64_0[_bzhi_u64(0x0123456789ABCDEFULL,   0) == 0x0000000000000000ULL ? 1 : -1];93char bzhi64_1[_bzhi_u64(0x0123456789ABCDEFULL,  32) == 0x0000000089ABCDEFULL ? 1 : -1];94char bzhi64_2[_bzhi_u64(0x0123456789ABCDEFULL,  99) == 0x0123456789ABCDEFULL ? 1 : -1];95char bzhi64_3[_bzhi_u64(0x0123456789ABCDEFULL, 520) == 0x00000000000000EFULL ? 1 : -1];96 97char pdep64_0[_pdep_u64(0x0123456789ABCDEFULL, 0x0000000000000000ULL) == 0x0000000000000000ULL ? 1 : -1];98char pdep64_1[_pdep_u64(0x0123456789ABCDEFULL, 0x00000000000000F0ULL) == 0x00000000000000F0ULL ? 1 : -1];99char pdep64_2[_pdep_u64(0x0123456789ABCDEFULL, 0xF00000F0F00000F0ULL) == 0xC00000D0E00000F0ULL ? 1 : -1];100char pdep64_3[_pdep_u64(0x0123456789ABCDEFULL, 0xFFFFFFFFFFFFFFFFULL) == 0x0123456789ABCDEFULL ? 1 : -1];101 102char pext64_0[_pext_u64(0x0123456789ABCDEFULL, 0x0000000000000000ULL) == 0x0000000000000000ULL ? 1 : -1];103char pext64_1[_pext_u64(0x0123456789ABCDEFULL, 0x00000000000000F0ULL) == 0x000000000000000EULL ? 1 : -1];104char pext64_2[_pext_u64(0x0123456789ABCDEFULL, 0xF00000F0F00000F0ULL) == 0x000000000000068EULL ? 1 : -1];105char pext64_3[_pext_u64(0x0123456789ABCDEFULL, 0xFFFFFFFFFFFFFFFFULL) == 0x0123456789ABCDEFULL ? 1 : -1];106 107constexpr unsigned __int128108test_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 114void mulxu64() {115  constexpr unsigned long long X = 0x0123456789ABCDEFULL, Y = 0xFEDCBA9876543210ULL;116  static_assert(test_mulx_u64(X,Y) == ((unsigned __int128)X * Y));117}118#endif119#endif