Index: include/clang/Basic/BuiltinsX86.def =================================================================== --- include/clang/Basic/BuiltinsX86.def +++ include/clang/Basic/BuiltinsX86.def @@ -35,6 +35,10 @@ BUILTIN(__builtin_ms_va_end, "vc*&", "n") BUILTIN(__builtin_ms_va_copy, "vc*&c*&", "n") +// Bit scan +BUILTIN(__builtin_bit_scan_forward, "ii", "") +BUILTIN(__builtin_bit_scan_reverse, "ii", "") + // Undefined Values // TARGET_BUILTIN(__builtin_ia32_undef128, "V2d", "nc", "") Index: lib/Headers/avxintrin.h =================================================================== --- lib/Headers/avxintrin.h +++ lib/Headers/avxintrin.h @@ -537,6 +537,25 @@ return (__m256i)__builtin_ia32_cvttps2dq256((__v8sf) __a); } +static __inline double __DEFAULT_FN_ATTRS +_mm256_cvtsd_f64(__m256d __a) +{ + return __a[0]; +} + +static __inline int __DEFAULT_FN_ATTRS +_mm256_cvtsi256_si32(__m256i __a) +{ + __v8si __b = (__v8si)__a; + return __b[0]; +} + +static __inline float __DEFAULT_FN_ATTRS +_mm256_cvtss_f32(__m256 __a) +{ + return __a[0]; +} + /* Vector replicate */ static __inline __m256 __DEFAULT_FN_ATTRS _mm256_movehdup_ps(__m256 __a) Index: lib/Headers/ia32intrin.h =================================================================== --- lib/Headers/ia32intrin.h +++ lib/Headers/ia32intrin.h @@ -74,4 +74,6 @@ #define _rdtsc() __rdtsc() +#define _rdpmc(A) __rdpmc(A) + #endif /* __IA32INTRIN_H */ Index: lib/Headers/immintrin.h =================================================================== --- lib/Headers/immintrin.h +++ lib/Headers/immintrin.h @@ -157,6 +157,19 @@ { return __builtin_ia32_wrgsbase64(__V); } + +/* __bit_scan_forward */ +static __inline__ int __attribute__((__always_inline__, __nodebug__)) +_bit_scan_forward(int __A) { + return __builtin_bit_scan_forward(__A); +} + +/* __bit_scan_reverse */ +static __inline__ int __attribute__((__always_inline__, __nodebug__)) +_bit_scan_reverse(int __A) { + return __builtin_bit_scan_reverse(__A); +} + #endif #include Index: test/CodeGen/avx-builtins.c =================================================================== --- test/CodeGen/avx-builtins.c +++ test/CodeGen/avx-builtins.c @@ -168,3 +168,24 @@ // CHECK: ret <4 x i64> undef return _mm256_undefined_si256(); } + +double test_mm256_cvtsd_f64(__m256d __a) +{ + // CHECK-LABEL: @test_mm256_cvtsd_f64 + // CHECK: extractelement <4 x double> %{{.*}}, i32 0 + return _mm256_cvtsd_f64(__a); +} + +int test_mm256_cvtsi256_si32(__m256i __a) +{ + // CHECK-LABEL: @test_mm256_cvtsi256_si32 + // CHECK: extractelement <8 x i32> %{{.*}}, i32 0 + return _mm256_cvtsi256_si32(__a); +} + +float test_mm256_cvtss_f32(__m256 __a) +{ + // CHECK-LABEL: @test_mm256_cvtss_f32 + // CHECK: extractelement <8 x float> %{{.*}}, i32 0 + return _mm256_cvtss_f32(__a); +} \ No newline at end of file Index: test/CodeGen/bitscan-builtins.c =================================================================== --- test/CodeGen/bitscan-builtins.c +++ test/CodeGen/bitscan-builtins.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -target-feature +rdrnd -target-feature +rdseed -emit-llvm -o - %s | FileCheck %s + +// Don't include mm_malloc.h, it's system specific. +#define __MM_MALLOC_H +#include + +int test_bit_scan_forward(int a) { + return _bit_scan_forward(a); +// CHECK: @test_bit_scan_forward +// CHECK: call i32 @llvm.x86.bit.scan.forward +} + +int test_bit_scan_reverse(int a) { + return _bit_scan_reverse(a); +// CHECK: @test_bit_scan_reverse +// CHECK: call i32 @llvm.x86.bit.scan.reverse +} \ No newline at end of file Index: test/CodeGen/rd-builtins.c =================================================================== --- test/CodeGen/rd-builtins.c +++ test/CodeGen/rd-builtins.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -target-feature +rdrnd -target-feature +rdseed -emit-llvm -o - %s | FileCheck %s + +// Don't include mm_malloc.h, it's system specific. +#define __MM_MALLOC_H + +#include + +unsigned long long test_rdpmc(int a) { + return _rdpmc(a); +// CHECK: @test_rdpmc +// CHECK: call i64 @llvm.x86.rdpmc +} + +int test_rdtsc() { + return _rdtsc(); +// CHECK: @test_rdtsc +// CHECK: call i64 @llvm.x86.rdtsc +} \ No newline at end of file