Index: clang/lib/Headers/ia32intrin.h =================================================================== --- clang/lib/Headers/ia32intrin.h +++ clang/lib/Headers/ia32intrin.h @@ -195,6 +195,34 @@ } #endif /* !__x86_64__ */ +static __inline__ unsigned int __attribute__((__always_inline__)) +_castf32_u32(float __Bits) { + unsigned int D; + __builtin_memcpy(&D, &__Bits, sizeof(__Bits)); + return D; +} + +static __inline__ unsigned long long __attribute__((__always_inline__)) +_castf64_u64(double __Bits) { + unsigned long long D; + __builtin_memcpy(&D, &__Bits, sizeof(__Bits)); + return D; +} + +static __inline__ float __attribute__((__always_inline__)) +_castu32_f32(unsigned int __Bits) { + float D; + __builtin_memcpy(&D, &__Bits, sizeof(__Bits)); + return D; +} + +static __inline__ double __attribute__((__always_inline__)) +_castu64_f64(unsigned long long __Bits) { + double D; + __builtin_memcpy(&D, &__Bits, sizeof(__Bits)); + return D; +} + /** Adds the unsigned integer operand to the CRC-32C checksum of the * unsigned char operand. * Index: clang/test/CodeGen/miscellaneous-builtins.c =================================================================== --- /dev/null +++ clang/test/CodeGen/miscellaneous-builtins.c @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-unknown -emit-llvm -o - -Wall -Werror | FileCheck %s + +#include + +unsigned int test_castf32_u32 (float __A){ + // CHECK-LABEL: @test_castf32_u32 + // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %{{.*}}, i8* align 4 %{{.*}}, i64 4, i1 false) + // CHECK: %{{.*}} = load i32, i32* %{{.*}}, align 4 + return _castf32_u32(__A); +} + +unsigned long long test_castf64_u64 (double __A){ + // CHECK-LABEL: @test_castf64_u64 + // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i64 8, i1 false) + // CHECK: %{{.*}} = load i64, i64* %{{.*}}, align 8 + return _castf64_u64(__A); +} + +float test_castu32_f32 (unsigned int __A){ + // CHECK-LABEL: @test_castu32_f32 + // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %{{.*}}, i8* align 4 %{{.*}}, i64 4, i1 false) + // CHECK: %{{.*}} = load float, float* %{{.*}}, align 4 + return _castu32_f32(__A); +} + +double test_castu64_f64 (unsigned long long __A){ + // CHECK-LABEL: @test_castu64_f64 + // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 %{{.*}}, i64 8, i1 false) + // CHECK: %{{.*}} = load double, double* %{{.*}}, align 8 + return _castu64_f64(__A); +} \ No newline at end of file