diff --git a/compiler-rt/lib/builtins/floatsisf.c b/compiler-rt/lib/builtins/floatsisf.c --- a/compiler-rt/lib/builtins/floatsisf.c +++ b/compiler-rt/lib/builtins/floatsisf.c @@ -17,7 +17,7 @@ #include "int_lib.h" -COMPILER_RT_ABI fp_t __floatsisf(int a) { +COMPILER_RT_ABI fp_t __floatsisf(si_int a) { const int aWidth = sizeof a * CHAR_BIT; @@ -33,7 +33,7 @@ } // Exponent of (fp_t)a is the width of abs(a). - const int exponent = (aWidth - 1) - __builtin_clz(a); + const int exponent = (aWidth - 1) - clzsi(a); rep_t result; // Shift a into the significand field, rounding if it is a right-shift diff --git a/compiler-rt/lib/builtins/floatsitf.c b/compiler-rt/lib/builtins/floatsitf.c --- a/compiler-rt/lib/builtins/floatsitf.c +++ b/compiler-rt/lib/builtins/floatsitf.c @@ -16,7 +16,7 @@ #include "fp_lib.h" #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) -COMPILER_RT_ABI fp_t __floatsitf(int a) { +COMPILER_RT_ABI fp_t __floatsitf(si_int a) { const int aWidth = sizeof a * CHAR_BIT; @@ -26,14 +26,14 @@ // All other cases begin by extracting the sign and absolute value of a rep_t sign = 0; - unsigned aAbs = (unsigned)a; + su_int aAbs = (su_int)a; if (a < 0) { sign = signBit; - aAbs = ~(unsigned)a + 1U; + aAbs = ~(su_int)a + 1U; } // Exponent of (fp_t)a is the width of abs(a). - const int exponent = (aWidth - 1) - __builtin_clz(aAbs); + const int exponent = (aWidth - 1) - clzsi(aAbs); rep_t result; // Shift a into the significand field and clear the implicit bit. diff --git a/compiler-rt/lib/builtins/floatunsisf.c b/compiler-rt/lib/builtins/floatunsisf.c --- a/compiler-rt/lib/builtins/floatunsisf.c +++ b/compiler-rt/lib/builtins/floatunsisf.c @@ -17,7 +17,7 @@ #include "int_lib.h" -COMPILER_RT_ABI fp_t __floatunsisf(unsigned int a) { +COMPILER_RT_ABI fp_t __floatunsisf(su_int a) { const int aWidth = sizeof a * CHAR_BIT; @@ -26,7 +26,7 @@ return fromRep(0); // Exponent of (fp_t)a is the width of abs(a). - const int exponent = (aWidth - 1) - __builtin_clz(a); + const int exponent = (aWidth - 1) - clzsi(a); rep_t result; // Shift a into the significand field, rounding if it is a right-shift diff --git a/compiler-rt/lib/builtins/floatunsitf.c b/compiler-rt/lib/builtins/floatunsitf.c --- a/compiler-rt/lib/builtins/floatunsitf.c +++ b/compiler-rt/lib/builtins/floatunsitf.c @@ -16,7 +16,7 @@ #include "fp_lib.h" #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) -COMPILER_RT_ABI fp_t __floatunsitf(unsigned int a) { +COMPILER_RT_ABI fp_t __floatunsitf(su_int a) { const int aWidth = sizeof a * CHAR_BIT; @@ -25,7 +25,7 @@ return fromRep(0); // Exponent of (fp_t)a is the width of abs(a). - const int exponent = (aWidth - 1) - __builtin_clz(a); + const int exponent = (aWidth - 1) - clzsi(a); rep_t result; // Shift a into the significand field and clear the implicit bit. diff --git a/compiler-rt/lib/builtins/fp_extend.h b/compiler-rt/lib/builtins/fp_extend.h --- a/compiler-rt/lib/builtins/fp_extend.h +++ b/compiler-rt/lib/builtins/fp_extend.h @@ -28,16 +28,7 @@ typedef uint64_t src_rep_t; #define SRC_REP_C UINT64_C static const int srcSigBits = 52; -static __inline int src_rep_t_clz(src_rep_t a) { -#if defined __LP64__ - return __builtin_clzl(a); -#else - if (a & REP_C(0xffffffff00000000)) - return __builtin_clz(a >> 32); - else - return 32 + __builtin_clz(a & REP_C(0xffffffff)); -#endif -} +static __inline int src_rep_t_clz(src_rep_t a) { return clzdi(a); } #elif defined SRC_HALF typedef uint16_t src_t; diff --git a/compiler-rt/lib/builtins/fp_lib.h b/compiler-rt/lib/builtins/fp_lib.h --- a/compiler-rt/lib/builtins/fp_lib.h +++ b/compiler-rt/lib/builtins/fp_lib.h @@ -64,16 +64,7 @@ #define REP_C UINT64_C #define significandBits 52 -static __inline int rep_clz(rep_t a) { -#if defined __LP64__ - return __builtin_clzl(a); -#else - if (a & REP_C(0xffffffff00000000)) - return clzsi(a >> 32); - else - return 32 + clzsi(a & REP_C(0xffffffff)); -#endif -} +static __inline int rep_clz(rep_t a) { return clzdi(a); } #define loWord(a) (a & 0xffffffffU) #define hiWord(a) (a >> 32) diff --git a/compiler-rt/lib/builtins/int_lib.h b/compiler-rt/lib/builtins/int_lib.h --- a/compiler-rt/lib/builtins/int_lib.h +++ b/compiler-rt/lib/builtins/int_lib.h @@ -146,4 +146,15 @@ #define __builtin_clzl __builtin_clzll #endif // defined(_MSC_VER) && !defined(__clang__) +static int __inline clzdi(di_int a) { +#if defined __LP64__ + return __builtin_clzl(a); +#else + if (a & UINT64_C(0xffffffff00000000)) + return clzsi(a >> 32); + else + return 32 + clzsi(a & UINT64_C(0xffffffff)); +#endif +} + #endif // INT_LIB_H diff --git a/compiler-rt/lib/builtins/udivmoddi4.c b/compiler-rt/lib/builtins/udivmoddi4.c --- a/compiler-rt/lib/builtins/udivmoddi4.c +++ b/compiler-rt/lib/builtins/udivmoddi4.c @@ -82,7 +82,7 @@ r.s.high = n.s.high & (d.s.high - 1); *rem = r.all; } - return n.s.high >> __builtin_ctz(d.s.high); + return n.s.high >> ctzsi(d.s.high); } // K K // --- @@ -112,7 +112,7 @@ *rem = n.s.low & (d.s.low - 1); if (d.s.low == 1) return n.all; - sr = __builtin_ctz(d.s.low); + sr = ctzsi(d.s.low); q.s.high = n.s.high >> sr; q.s.low = (n.s.high << (n_uword_bits - sr)) | (n.s.low >> sr); return q.all; diff --git a/compiler-rt/test/builtins/Unit/floatditf_test.c b/compiler-rt/test/builtins/Unit/floatditf_test.c --- a/compiler-rt/test/builtins/Unit/floatditf_test.c +++ b/compiler-rt/test/builtins/Unit/floatditf_test.c @@ -12,9 +12,9 @@ // Returns: long integer converted to long double -COMPILER_RT_ABI long double __floatditf(long long a); +COMPILER_RT_ABI long double __floatditf(di_int a); -int test__floatditf(long long a, uint64_t expectedHi, uint64_t expectedLo) +int test__floatditf(di_int a, uint64_t expectedHi, uint64_t expectedLo) { long double x = __floatditf(a); int ret = compareResultLD(x, expectedHi, expectedLo); diff --git a/compiler-rt/test/builtins/Unit/floatsitf_test.c b/compiler-rt/test/builtins/Unit/floatsitf_test.c --- a/compiler-rt/test/builtins/Unit/floatsitf_test.c +++ b/compiler-rt/test/builtins/Unit/floatsitf_test.c @@ -8,9 +8,9 @@ #include "fp_test.h" -long COMPILER_RT_ABI double __floatsitf(int a); +COMPILER_RT_ABI long double __floatsitf(si_int a); -int test__floatsitf(int a, uint64_t expectedHi, uint64_t expectedLo) +int test__floatsitf(si_int a, uint64_t expectedHi, uint64_t expectedLo) { long double x = __floatsitf(a); int ret = compareResultLD(x, expectedHi, expectedLo); diff --git a/compiler-rt/test/builtins/Unit/floatunditf_test.c b/compiler-rt/test/builtins/Unit/floatunditf_test.c --- a/compiler-rt/test/builtins/Unit/floatunditf_test.c +++ b/compiler-rt/test/builtins/Unit/floatunditf_test.c @@ -12,9 +12,9 @@ // Returns: long integer converted to long double -COMPILER_RT_ABI long double __floatunditf(unsigned long long a); +COMPILER_RT_ABI long double __floatunditf(du_int a); -int test__floatunditf(unsigned long long a, uint64_t expectedHi, uint64_t expectedLo) +int test__floatunditf(du_int a, uint64_t expectedHi, uint64_t expectedLo) { long double x = __floatunditf(a); int ret = compareResultLD(x, expectedHi, expectedLo); diff --git a/compiler-rt/test/builtins/Unit/floatunsitf_test.c b/compiler-rt/test/builtins/Unit/floatunsitf_test.c --- a/compiler-rt/test/builtins/Unit/floatunsitf_test.c +++ b/compiler-rt/test/builtins/Unit/floatunsitf_test.c @@ -8,9 +8,9 @@ #include "fp_test.h" -COMPILER_RT_ABI long double __floatunsitf(unsigned int a); +COMPILER_RT_ABI long double __floatunsitf(su_int a); -int test__floatunsitf(unsigned int a, uint64_t expectedHi, uint64_t expectedLo) +int test__floatunsitf(su_int a, uint64_t expectedHi, uint64_t expectedLo) { long double x = __floatunsitf(a); int ret = compareResultLD(x, expectedHi, expectedLo);