re #33: win32 is working

This commit is contained in:
Joao Paulo Magalhaes 2020-11-16 11:58:03 +00:00
parent 829ac72f87
commit c4693cc86f
2 changed files with 36 additions and 6 deletions

View File

@ -90,6 +90,7 @@ struct value128 {
/* result might be undefined when input_num is zero */
fastfloat_really_inline int leading_zeroes(uint64_t input_num) {
#ifdef FASTFLOAT_VISUAL_STUDIO
#if defined(_M_X64) || defined(_M_ARM64)
unsigned long leading_zero = 0;
// Search the mask data from most significant bit (MSB)
// to least significant bit (LSB) for a set bit (1).
@ -97,6 +98,17 @@ fastfloat_really_inline int leading_zeroes(uint64_t input_num) {
return (int)(63 - leading_zero);
else
return 64;
#else
if(!input_num) return 64;
int n = 0;
if(input_num & uint64_t(0xffffffff00000000)) input_num >>= 32, n |= 32;
if(input_num & uint64_t( 0xffff0000)) input_num >>= 16, n |= 16;
if(input_num & uint64_t( 0xff00)) input_num >>= 8, n |= 8;
if(input_num & uint64_t( 0xf0)) input_num >>= 4, n |= 4;
if(input_num & uint64_t( 0xc)) input_num >>= 2, n |= 2;
if(input_num & uint64_t( 0x2)) input_num >>= 1, n |= 1;
return 63 - n;
#endif
#else
return __builtin_clzll(input_num);
#endif
@ -109,9 +121,9 @@ fastfloat_really_inline int leading_zeroes(uint64_t input_num) {
#if !defined(_M_X64) && !defined(_M_ARM64) // _umul128 for x86, arm
// this is a slow emulation routine for 32-bit Windows
//
fastfloat_really_inline uint64_t __emulu(uint32_t x, uint32_t y) {
return x * (uint64_t)y;
}
//fastfloat_really_inline uint64_t __emulu(uint32_t x, uint32_t y) {
// return x * (uint64_t)y;
//}
fastfloat_really_inline uint64_t _umul128(uint64_t ab, uint64_t cd,
uint64_t *hi) {
uint64_t ad = __emulu((uint32_t)(ab >> 32), (uint32_t)cd);

View File

@ -1,9 +1,14 @@
#include "fast_float/fast_float.h"
#include <iomanip>
inline void Assert(bool Assertion) {
if (!Assertion)
throw std::runtime_error("bug");
#define Q(x) #x
#define QUOTE(x) Q(x)
#define Assert(assertion) \
if (!(assertion)) {\
AssertionFailed(__FILE__ ":" QUOTE(__LINE__) ": assertion failed: " #assertion);\
}
inline void AssertionFailed(const char *msg) {
throw std::runtime_error(msg);
}
template <typename T> std::string to_string(T d) {
@ -327,7 +332,20 @@ bool test_fixed_only() {
return true;
}
void test_leading_zeroes()
{
constexpr const uint64_t bit = 1;
Assert(fast_float::leading_zeroes(0) == 64);
Assert(fast_float::leading_zeroes(bit << 0) == 63);
Assert(fast_float::leading_zeroes(bit << 1) == 62);
Assert(fast_float::leading_zeroes(bit << 2) == 61);
Assert(fast_float::leading_zeroes(bit << 61) == 2);
Assert(fast_float::leading_zeroes(bit << 62) == 1);
Assert(fast_float::leading_zeroes(bit << 63) == 0);
}
int main() {
test_leading_zeroes();
Assert(test_fixed_only());
Assert(test_scientific_only());
Assert(issue8());