summaryrefslogtreecommitdiff
path: root/lib/builtins/floatsitf.c
diff options
context:
space:
mode:
authorJoerg Sonnenberger <joerg@bec.de>2014-09-16 20:34:41 +0000
committerJoerg Sonnenberger <joerg@bec.de>2014-09-16 20:34:41 +0000
commit086f46a9b87b17d36de8cc7e7f4b5a7469161cca (patch)
tree056ad3a0cb3ff7b3670b81ef8270426e9a9e33c8 /lib/builtins/floatsitf.c
parent48d5c81378502ac2f26565f76caec9601e702e6a (diff)
Implement floatsitf, floatunstfsi, which perform
(signed/unsigned)integer to quad-precision conversion. Submitted by GuanHong Liu. Differential Revision: http://reviews.llvm.org/D2805 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@217901 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/builtins/floatsitf.c')
-rw-r--r--lib/builtins/floatsitf.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/builtins/floatsitf.c b/lib/builtins/floatsitf.c
new file mode 100644
index 000000000..85346933f
--- /dev/null
+++ b/lib/builtins/floatsitf.c
@@ -0,0 +1,52 @@
+//===-- lib/floatsitf.c - integer -> quad-precision conversion ----*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements integer to quad-precision conversion for the
+// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
+// mode.
+//
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+COMPILER_RT_ABI fp_t __floatsitf(int a) {
+
+ const int aWidth = sizeof a * CHAR_BIT;
+
+ // Handle zero as a special case to protect clz
+ if (a == 0)
+ return fromRep(0);
+
+ // All other cases begin by extracting the sign and absolute value of a
+ rep_t sign = 0;
+ unsigned aAbs = (unsigned)a;
+ if (a < 0) {
+ sign = signBit;
+ aAbs += 0x80000000;
+ }
+
+ // Exponent of (fp_t)a is the width of abs(a).
+ const int exponent = (aWidth - 1) - __builtin_clz(a);
+ rep_t result;
+
+ // Shift a into the significand field and clear the implicit bit. Extra
+ // cast to unsigned int is necessary to get the correct behavior for
+ // the input INT_MIN.
+ const int shift = significandBits - exponent;
+ result = (rep_t)aAbs << shift ^ implicitBit;
+
+ // Insert the exponent
+ result += (rep_t)(exponent + exponentBias) << significandBits;
+ // Insert the sign bit and return
+ return fromRep(result | sign);
+}
+
+#endif