[PATCH] D67212: [x86] Adding support for some missing intrinsics: _castf32_u32, _castf64_u64, _castu32_f32, _castu64_f64

Bing Yu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 5 00:11:21 PDT 2019


yubing created this revision.
yubing added reviewers: craig.topper, LuoYuanke, RKSimon, pengfei.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Adding support for some missing intrinsics:
_castf32_u32, _castf64_u64, _castu32_f32, _castu64_f64


Repository:
  rL LLVM

https://reviews.llvm.org/D67212

Files:
  clang/lib/Headers/ia32intrin.h
  clang/test/CodeGen/miscellaneous-builtins.c


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 <x86intrin.h>
+
+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
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.
  *


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67212.218845.patch
Type: text/x-patch
Size: 2612 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190905/5ee103a2/attachment-0001.bin>


More information about the llvm-commits mailing list