[compiler-rt] r234148 - Add hard float versions of FP to LL conversions
Sergey Dmitrouk
sdmitrouk at accesssoftek.com
Mon Apr 6 04:54:51 PDT 2015
Author: sdmitrouk
Date: Mon Apr 6 06:54:51 2015
New Revision: 234148
URL: http://llvm.org/viewvc/llvm-project?rev=234148&view=rev
Log:
Add hard float versions of FP to LL conversions
This adds hard-float implementation for the following builtins:
* __fixdfdi()
* __fixsfdi()
* __fixunsdfdi()
* __fixunssfdi()
The soft-float implementation does never raise floating point
exceptions, which doesn't allow clients to detect floating point
conversion errors.
I must mention that I had to refer to libgcc's implementation to
write these functions.
Related unit-tests of compiler-rt passed with these changes.
Patch was somewhat out-dated, so was updated locally without any
functional changes.
Differential Revision: http://reviews.llvm.org/D5376
Modified:
compiler-rt/trunk/lib/builtins/fixdfdi.c
compiler-rt/trunk/lib/builtins/fixsfdi.c
compiler-rt/trunk/lib/builtins/fixunsdfdi.c
compiler-rt/trunk/lib/builtins/fixunssfdi.c
Modified: compiler-rt/trunk/lib/builtins/fixdfdi.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/fixdfdi.c?rev=234148&r1=234147&r2=234148&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/fixdfdi.c (original)
+++ compiler-rt/trunk/lib/builtins/fixdfdi.c Mon Apr 6 06:54:51 2015
@@ -12,6 +12,28 @@
#include "fp_lib.h"
ARM_EABI_FNALIAS(d2lz, fixdfdi)
+#ifndef __SOFT_FP__
+/* Support for systems that have hardware floating-point; can set the invalid
+ * flag as a side-effect of computation.
+ */
+
+COMPILER_RT_ABI du_int __fixunsdfdi(double a);
+
+COMPILER_RT_ABI di_int
+__fixdfdi(double a)
+{
+ if (a < 0.0) {
+ return -__fixunsdfdi(-a);
+ }
+ return __fixunsdfdi(a);
+}
+
+#else
+/* Support for systems that don't have hardware floating-point; there are no
+ * flags to set, and we don't want to code-gen to an unknown soft-float
+ * implementation.
+ */
+
typedef di_int fixint_t;
typedef du_int fixuint_t;
#include "fp_fixint_impl.inc"
@@ -20,3 +42,5 @@ COMPILER_RT_ABI di_int
__fixdfdi(fp_t a) {
return __fixint(a);
}
+
+#endif
Modified: compiler-rt/trunk/lib/builtins/fixsfdi.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/fixsfdi.c?rev=234148&r1=234147&r2=234148&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/fixsfdi.c (original)
+++ compiler-rt/trunk/lib/builtins/fixsfdi.c Mon Apr 6 06:54:51 2015
@@ -13,6 +13,28 @@
ARM_EABI_FNALIAS(f2lz, fixsfdi)
+#ifndef __SOFT_FP__
+/* Support for systems that have hardware floating-point; can set the invalid
+ * flag as a side-effect of computation.
+ */
+
+COMPILER_RT_ABI du_int __fixunssfdi(float a);
+
+COMPILER_RT_ABI di_int
+__fixsfdi(float a)
+{
+ if (a < 0.0f) {
+ return -__fixunssfdi(-a);
+ }
+ return __fixunssfdi(a);
+}
+
+#else
+/* Support for systems that don't have hardware floating-point; there are no
+ * flags to set, and we don't want to code-gen to an unknown soft-float
+ * implementation.
+ */
+
typedef di_int fixint_t;
typedef du_int fixuint_t;
#include "fp_fixint_impl.inc"
@@ -21,3 +43,5 @@ COMPILER_RT_ABI di_int
__fixsfdi(fp_t a) {
return __fixint(a);
}
+
+#endif
Modified: compiler-rt/trunk/lib/builtins/fixunsdfdi.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/fixunsdfdi.c?rev=234148&r1=234147&r2=234148&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/fixunsdfdi.c (original)
+++ compiler-rt/trunk/lib/builtins/fixunsdfdi.c Mon Apr 6 06:54:51 2015
@@ -10,12 +10,34 @@
#define DOUBLE_PRECISION
#include "fp_lib.h"
-typedef du_int fixuint_t;
-#include "fp_fixuint_impl.inc"
ARM_EABI_FNALIAS(d2ulz, fixunsdfdi)
+#ifndef __SOFT_FP__
+/* Support for systems that have hardware floating-point; can set the invalid
+ * flag as a side-effect of computation.
+ */
+
+COMPILER_RT_ABI du_int
+__fixunsdfdi(double a)
+{
+ su_int high = a/0x1p32f;
+ su_int low = a - (double)high*0x1p32f;
+ return ((du_int)high << 32) | low;
+}
+
+#else
+/* Support for systems that don't have hardware floating-point; there are no
+ * flags to set, and we don't want to code-gen to an unknown soft-float
+ * implementation.
+ */
+
+typedef du_int fixuint_t;
+#include "fp_fixuint_impl.inc"
+
COMPILER_RT_ABI du_int
__fixunsdfdi(fp_t a) {
return __fixuint(a);
}
+
+#endif
Modified: compiler-rt/trunk/lib/builtins/fixunssfdi.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/fixunssfdi.c?rev=234148&r1=234147&r2=234148&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/fixunssfdi.c (original)
+++ compiler-rt/trunk/lib/builtins/fixunssfdi.c Mon Apr 6 06:54:51 2015
@@ -10,12 +10,35 @@
#define SINGLE_PRECISION
#include "fp_lib.h"
-typedef du_int fixuint_t;
-#include "fp_fixuint_impl.inc"
ARM_EABI_FNALIAS(f2ulz, fixunssfdi)
+#ifndef __SOFT_FP__
+/* Support for systems that have hardware floating-point; can set the invalid
+ * flag as a side-effect of computation.
+ */
+
+COMPILER_RT_ABI du_int
+__fixunssfdi(float a)
+{
+ double da = a;
+ su_int high = da/0x1p32f;
+ su_int low = da - (double)high*0x1p32f;
+ return ((du_int)high << 32) | low;
+}
+
+#else
+/* Support for systems that don't have hardware floating-point; there are no
+ * flags to set, and we don't want to code-gen to an unknown soft-float
+ * implementation.
+ */
+
+typedef du_int fixuint_t;
+#include "fp_fixuint_impl.inc"
+
COMPILER_RT_ABI du_int
__fixunssfdi(fp_t a) {
return __fixuint(a);
}
+
+#endif
More information about the llvm-commits
mailing list