From: Eric Fiselier Date: Tue, 3 May 2016 02:04:26 +0000 (+0000) Subject: Don't use std::__clz in 'test/support/hexfloat.h'. X-Git-Tag: llvmorg-3.9.0-rc1~7160 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=43a10eb637b2da24cc8d5ee1c52a7ff3a485cf9c;p=platform%2Fupstream%2Fllvm.git Don't use std::__clz in 'test/support/hexfloat.h'. std::__clz is a libc++ specific function so it can't be used in the test suite. This patch implements a dumb "count leading zeros" implementation within hexfloat itself. This patch also fixes UB since the output of `__builtin_clz(0)` is undefined according to the GCC docs. llvm-svn: 268354 --- diff --git a/libcxx/test/support/hexfloat.h b/libcxx/test/support/hexfloat.h index 7ef0937..19008d1 100644 --- a/libcxx/test/support/hexfloat.h +++ b/libcxx/test/support/hexfloat.h @@ -15,7 +15,6 @@ #ifndef HEXFLOAT_H #define HEXFLOAT_H -#include #include #include @@ -23,13 +22,26 @@ template class hexfloat { T value_; + + static int CountLeadingZeros(unsigned long long n) { + const std::size_t Digits = sizeof(unsigned long long) * CHAR_BIT; + const unsigned long long TopBit = 1ull << (Digits - 1); + if (n == 0) return Digits; + int LeadingZeros = 0; + while ((n & TopBit) == 0) { + ++LeadingZeros; + n <<= 1; + } + return LeadingZeros; + } + public: hexfloat(long long m1, unsigned long long m0, int exp) { - const std::size_t n = sizeof(unsigned long long) * CHAR_BIT; + const std::size_t Digits = sizeof(unsigned long long) * CHAR_BIT; int s = m1 < 0 ? -1 : 1; - value_ = std::ldexp(m1 + s * std::ldexp(T(m0), -static_cast(n - - std::__clz(m0)/4*4)), exp); + int exp2 = -static_cast(Digits - CountLeadingZeros(m0)/4*4); + value_ = std::ldexp(m1 + s * std::ldexp(T(m0), exp2), exp); } operator T() const {return value_;}