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. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@268354 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -15,7 +15,6 @@
|
|||||||
#ifndef HEXFLOAT_H
|
#ifndef HEXFLOAT_H
|
||||||
#define HEXFLOAT_H
|
#define HEXFLOAT_H
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
|
||||||
@@ -23,13 +22,26 @@ template <class T>
|
|||||||
class hexfloat
|
class hexfloat
|
||||||
{
|
{
|
||||||
T value_;
|
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:
|
public:
|
||||||
hexfloat(long long m1, unsigned long long m0, int exp)
|
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;
|
int s = m1 < 0 ? -1 : 1;
|
||||||
value_ = std::ldexp(m1 + s * std::ldexp(T(m0), -static_cast<int>(n -
|
int exp2 = -static_cast<int>(Digits - CountLeadingZeros(m0)/4*4);
|
||||||
std::__clz(m0)/4*4)), exp);
|
value_ = std::ldexp(m1 + s * std::ldexp(T(m0), exp2), exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
operator T() const {return value_;}
|
operator T() const {return value_;}
|
||||||
|
|||||||
Reference in New Issue
Block a user