[compiler-rt] a4e8f7f - [builtins] Improve compatibility with 16 bit targets
Anton Korobeynikov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 26 05:31:35 PDT 2020
Author: Anatoly Trosinenko
Date: 2020-06-26T15:31:11+03:00
New Revision: a4e8f7fe3f38085c0fdd6e34e870f8e9c6c72861
URL: https://github.com/llvm/llvm-project/commit/a4e8f7fe3f38085c0fdd6e34e870f8e9c6c72861
DIFF: https://github.com/llvm/llvm-project/commit/a4e8f7fe3f38085c0fdd6e34e870f8e9c6c72861.diff
LOG: [builtins] Improve compatibility with 16 bit targets
Some parts of existing codebase assume the default `int` type to be (at least) 32 bit wide. On 16 bit targets such as MSP430 this may cause Undefined Behavior or results being defined but incorrect.
Differential Revision: https://reviews.llvm.org/D81408
Added:
Modified:
compiler-rt/lib/builtins/floatdidf.c
compiler-rt/lib/builtins/floatundidf.c
compiler-rt/lib/builtins/fp_lib.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/builtins/floatdidf.c b/compiler-rt/lib/builtins/floatdidf.c
index 8f887314b9e1..b2d8f2b44b6d 100644
--- a/compiler-rt/lib/builtins/floatdidf.c
+++ b/compiler-rt/lib/builtins/floatdidf.c
@@ -87,7 +87,7 @@ COMPILER_RT_ABI double __floatdidf(di_int a) {
}
double_bits fb;
fb.u.s.high = ((su_int)s & 0x80000000) | // sign
- ((e + 1023) << 20) | // exponent
+ ((su_int)(e + 1023) << 20) | // exponent
((su_int)(a >> 32) & 0x000FFFFF); // mantissa-high
fb.u.s.low = (su_int)a; // mantissa-low
return fb.f;
diff --git a/compiler-rt/lib/builtins/floatundidf.c b/compiler-rt/lib/builtins/floatundidf.c
index e7c6aae5ce38..4c445b118080 100644
--- a/compiler-rt/lib/builtins/floatundidf.c
+++ b/compiler-rt/lib/builtins/floatundidf.c
@@ -90,7 +90,7 @@ COMPILER_RT_ABI double __floatundidf(du_int a) {
// a is now rounded to DBL_MANT_DIG bits
}
double_bits fb;
- fb.u.s.high = ((e + 1023) << 20) | // exponent
+ fb.u.s.high = ((su_int)(e + 1023) << 20) | // exponent
((su_int)(a >> 32) & 0x000FFFFF); // mantissa-high
fb.u.s.low = (su_int)a; // mantissa-low
return fb.f;
diff --git a/compiler-rt/lib/builtins/fp_lib.h b/compiler-rt/lib/builtins/fp_lib.h
index e6ba077d2313..bd1f180f499e 100644
--- a/compiler-rt/lib/builtins/fp_lib.h
+++ b/compiler-rt/lib/builtins/fp_lib.h
@@ -46,7 +46,7 @@ typedef float fp_t;
#define REP_C UINT32_C
#define significandBits 23
-static __inline int rep_clz(rep_t a) { return __builtin_clz(a); }
+static __inline int rep_clz(rep_t a) { return clzsi(a); }
// 32x32 --> 64 bit multiply
static __inline void wideMultiply(rep_t a, rep_t b, rep_t *hi, rep_t *lo) {
More information about the llvm-commits
mailing list