Skip to content

Commit 37152ea

Browse files
committed
type usage fixes.
1 parent 489703f commit 37152ea

File tree

5 files changed

+65
-63
lines changed

5 files changed

+65
-63
lines changed

include/fast_float/ascii_number.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
561561
auto const *const start_digits = p;
562562

563563
FASTFLOAT_IF_CONSTEXPR17((std::is_same<T, std::uint8_t>::value)) {
564-
const auto len = static_cast<am_digits>(pend - p);
564+
const auto len = static_cast<am_bits_t>(pend - p);
565565
if (len == 0) {
566566
if (has_leading_zeros) {
567567
value = 0;
@@ -605,7 +605,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
605605
const uint32_t magic =
606606
((digits + 0x46464646u) | (digits - 0x30303030u)) & 0x80808080u;
607607
const auto tz = countr_zero_32(magic); // 7, 15, 23, 31, or 32
608-
am_digits nd = (tz == 32) ? 4 : (tz >> 3);
608+
am_bits_t nd = (tz == 32) ? 4 : (tz >> 3);
609609
nd = std::min(nd, len);
610610
if (nd == 0) {
611611
if (has_leading_zeros) {
@@ -620,7 +620,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
620620
}
621621
if (nd > 3) {
622622
const UC *q = p + nd;
623-
am_digits rem = len - nd;
623+
am_bits_t rem = len - nd;
624624
while (rem) {
625625
if (*q < UC('0') || *q > UC('9'))
626626
break;

include/fast_float/bigint.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,18 @@ empty_hi64(bool &truncated) noexcept {
169169
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint64_t
170170
uint64_hi64(uint64_t r0, bool &truncated) noexcept {
171171
truncated = false;
172-
int shl = leading_zeroes(r0);
172+
auto shl = leading_zeroes(r0);
173173
return r0 << shl;
174174
}
175175

176176
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint64_t
177177
uint64_hi64(uint64_t r0, uint64_t r1, bool &truncated) noexcept {
178-
int shl = leading_zeroes(r0);
178+
auto shl = leading_zeroes(r0);
179179
if (shl == 0) {
180180
truncated = r1 != 0;
181181
return r0;
182182
} else {
183-
int shr = 64 - shl;
183+
limb_t shr = 64 - shl;
184184
truncated = (r1 << shl) != 0;
185185
return (r0 << shl) | (r1 >> shr);
186186
}

include/fast_float/decimal_to_binary.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace fast_float {
2020
template <limb_t bit_precision>
2121
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 value128
2222
compute_product_approximation(am_pow_t q, am_mant_t w) noexcept {
23-
am_pow_t const index = 2 * am_pow_t(q - powers::smallest_power_of_five);
23+
am_pow_t const index = 2 * (q - powers::smallest_power_of_five);
2424
// For small values of q, e.g., q in [0,27], the answer is always exact
2525
// because The line value128 firstproduct = full_multiplication(w,
2626
// power_of_five_128[index]); gives the exact answer.
@@ -71,7 +71,7 @@ constexpr fastfloat_really_inline am_pow_t power(am_pow_t q) noexcept {
7171
// for significant digits already multiplied by 10 ** q.
7272
template <typename binary>
7373
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 adjusted_mantissa
74-
compute_error_scaled(am_pow_t q, am_mant_t w, am_digits lz) noexcept {
74+
compute_error_scaled(am_pow_t q, am_mant_t w, am_bits_t lz) noexcept {
7575
auto const hilz = static_cast<am_pow_t>((w >> 63) ^ 1);
7676
adjusted_mantissa answer;
7777
answer.mantissa = w << hilz;
@@ -86,7 +86,7 @@ compute_error_scaled(am_pow_t q, am_mant_t w, am_digits lz) noexcept {
8686
template <typename binary>
8787
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
8888
compute_error(am_pow_t q, am_mant_t w) noexcept {
89-
am_digits const lz = leading_zeroes(w);
89+
auto const lz = leading_zeroes(w);
9090
w <<= lz;
9191
value128 product =
9292
compute_product_approximation<binary::mantissa_explicit_bits() + 3>(q, w);
@@ -118,7 +118,7 @@ compute_float(am_pow_t q, am_mant_t w) noexcept {
118118
// powers::largest_power_of_five].
119119

120120
// We want the most significant bit of i to be 1. Shift if needed.
121-
am_digits const lz = leading_zeroes(w);
121+
auto const lz = leading_zeroes(w);
122122
w <<= lz;
123123

124124
// The required precision is binary::mantissa_explicit_bits() + 3 because
@@ -138,7 +138,7 @@ compute_float(am_pow_t q, am_mant_t w) noexcept {
138138
// branchless approach: value128 product = compute_product(q, w); but in
139139
// practice, we can win big with the compute_product_approximation if its
140140
// additional branch is easily predicted. Which is best is data specific.
141-
limb_t const upperbit = static_cast<limb_t>(product.high >> 63);
141+
auto const upperbit = static_cast<limb_t>(product.high >> 63);
142142
limb_t const shift = upperbit + 64 - binary::mantissa_explicit_bits() - 3;
143143

144144
answer.mantissa = product.high >> shift;

include/fast_float/fast_table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ template <class unused = void> struct powers_template {
3333
binary_format<double>::smallest_power_of_ten();
3434
constexpr static am_pow_t largest_power_of_five =
3535
binary_format<double>::largest_power_of_ten();
36-
constexpr static am_digits number_of_entries =
36+
constexpr static am_pow_t number_of_entries =
3737
2 * (largest_power_of_five - smallest_power_of_five + 1);
3838
// Powers of five from 5^-342 all the way to 5^308 rounded toward one.
3939
constexpr static am_mant_t power_of_five_128[number_of_entries] = {

include/fast_float/float_common.h

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,31 @@
3333

3434
namespace fast_float {
3535

36+
// 64 bit integer is used because mantissa can be up to 53 bits for double.
37+
// Value of the int mantissa in the API.
38+
typedef int_fast64_t am_sign_mant_t;
39+
// An unsigned int avoids signed overflows (which are bad)
40+
typedef uint_fast64_t am_mant_t;
41+
3642
// The number of digits in the mantissa.
3743
typedef uint_fast16_t am_digits;
3844

3945
// The number of bits in the limb.
4046
typedef uint_fast8_t limb_t;
4147

48+
// Size of bits in the mantissa and path and rounding shifts
49+
typedef int_fast8_t am_bits_t;
50+
51+
// 16 bit signed integer is used for power to cover all double exponents.
52+
typedef int16_t am_pow_t;
53+
// Power bias is signed for handling a denormal float
54+
// or an invalid mantissa.
55+
// Bias so we can get the real exponent with an invalid adjusted_mantissa.
56+
constexpr static am_pow_t invalid_am_bias =
57+
std::numeric_limits<am_pow_t>::min() + 1;
58+
constexpr static am_pow_t am_bias_limit =
59+
(std::numeric_limits<am_pow_t>::max() / 8) - 1;
60+
4261
// Type for enum chars_format.
4362
typedef uint_fast8_t chars_format_t;
4463

@@ -355,8 +374,11 @@ struct alignas(16) value128 {
355374
};
356375

357376
/* Helper C++14 constexpr generic implementation of leading_zeroes for 64-bit */
358-
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 am_digits
359-
leading_zeroes_generic(uint64_t input_num, uint32_t last_bit = 0) noexcept {
377+
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 limb_t
378+
leading_zeroes_generic(uint64_t input_num) noexcept {
379+
assert(input_num > 0);
380+
FASTFLOAT_ASSUME(input_num > 0);
381+
uint_fast32_t last_bit = 0;
360382
if (input_num & uint64_t(0xffffffff00000000)) {
361383
input_num >>= 32;
362384
last_bit |= 32;
@@ -380,11 +402,11 @@ leading_zeroes_generic(uint64_t input_num, uint32_t last_bit = 0) noexcept {
380402
if (input_num & uint64_t(0x2)) { /* input_num >>= 1; */
381403
last_bit |= 1;
382404
}
383-
return 63 - static_cast<am_digits>(last_bit);
405+
return 63 - static_cast<limb_t>(last_bit);
384406
}
385407

386408
/* result might be undefined when input_num is zero */
387-
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 am_digits
409+
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 limb_t
388410
leading_zeroes(uint64_t input_num) noexcept {
389411
assert(input_num > 0);
390412
FASTFLOAT_ASSUME(input_num > 0);
@@ -397,21 +419,20 @@ leading_zeroes(uint64_t input_num) noexcept {
397419
// Search the mask data from most significant bit (MSB)
398420
// to least significant bit (LSB) for a set bit (1).
399421
_BitScanReverse64(&leading_zero, input_num);
400-
return static_cast<am_digits>(63 - leading_zero);
422+
return static_cast<limb_t>(63 - leading_zero);
401423
#else
402-
return static_cast<am_digits>(leading_zeroes_generic(input_num));
424+
return static_cast<limb_t>(leading_zeroes_generic(input_num));
403425
#endif
404426
#else
405-
return static_cast<am_digits>(__builtin_clzll(input_num));
427+
return static_cast<limb_t>(__builtin_clzll(input_num));
406428
#endif
407429
}
408430

409431
/* Helper C++14 constexpr generic implementation of countr_zero for 32-bit */
410-
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 am_digits
432+
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 limb_t
411433
countr_zero_generic_32(uint32_t input_num) {
412-
if (input_num == 0) {
413-
return 32;
414-
}
434+
assert(input_num > 0);
435+
FASTFLOAT_ASSUME(input_num > 0);
415436
uint_fast16_t last_bit = 0;
416437
if (!(input_num & 0x0000FFFF)) {
417438
input_num >>= 16;
@@ -432,23 +453,23 @@ countr_zero_generic_32(uint32_t input_num) {
432453
if (!(input_num & 0x1)) {
433454
last_bit |= 1;
434455
}
435-
return static_cast<am_digits>(last_bit);
456+
return static_cast<limb_t>(last_bit);
436457
}
437458

438459
/* count trailing zeroes for 32-bit integers */
439-
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 am_digits
460+
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 limb_t
440461
countr_zero_32(uint32_t input_num) {
441462
if (cpp20_and_in_constexpr()) {
442463
return countr_zero_generic_32(input_num);
443464
}
444465
#ifdef FASTFLOAT_VISUAL_STUDIO
445466
unsigned long trailing_zero = 0;
446467
if (_BitScanForward(&trailing_zero, input_num)) {
447-
return static_cast<am_digits>(trailing_zero);
468+
return static_cast<limb_t>(trailing_zero);
448469
}
449470
return 32;
450471
#else
451-
return input_num == 0 ? 32 : static_cast<am_digits>(__builtin_ctz(input_num));
472+
return input_num == 0 ? 32 : static_cast<limb_t>(__builtin_ctz(input_num));
452473
#endif
453474
}
454475

@@ -509,25 +530,6 @@ full_multiplication(uint64_t a, uint64_t b) noexcept {
509530
return answer;
510531
}
511532

512-
// 64 bit integer is used because mantissa can be up to 53 bits for double.
513-
// Value of the int mantissa in the API.
514-
typedef int_fast64_t am_sign_mant_t;
515-
// An unsigned int avoids signed overflows (which are bad)
516-
typedef uint_fast64_t am_mant_t;
517-
518-
// Size of bits in the mantissa and path and rounding shifts
519-
typedef int_fast8_t am_bits_t;
520-
521-
// 16 bit signed integer is used for power to cover all double exponents.
522-
// Power bias is signed for handling a denormal float
523-
// or an invalid mantissa.
524-
typedef int_fast16_t am_pow_t;
525-
// Bias so we can get the real exponent with an invalid adjusted_mantissa.
526-
constexpr static am_pow_t invalid_am_bias =
527-
std::numeric_limits<int16_t>::min() + 1;
528-
constexpr static am_pow_t am_bias_limit =
529-
(std::numeric_limits<int16_t>::max() + 1) / 8;
530-
531533
struct alignas(16) adjusted_mantissa {
532534
am_mant_t mantissa;
533535
am_pow_t power2;
@@ -550,21 +552,21 @@ template <typename T, typename U = void> struct binary_format_lookup_tables;
550552
template <typename T> struct binary_format : binary_format_lookup_tables<T> {
551553
using equiv_uint = equiv_uint_t<T>;
552554

553-
static constexpr limb_t mantissa_explicit_bits();
555+
static constexpr am_bits_t mantissa_explicit_bits();
554556
static constexpr am_pow_t minimum_exponent();
555557
static constexpr am_pow_t infinite_power();
556558
static constexpr am_bits_t sign_index();
557559
static constexpr am_bits_t
558560
min_exponent_fast_path(); // used when fegetround() == FE_TONEAREST
559561
static constexpr am_bits_t max_exponent_fast_path();
560-
static constexpr am_bits_t max_exponent_round_to_even();
561-
static constexpr am_bits_t min_exponent_round_to_even();
562-
static constexpr equiv_uint max_mantissa_fast_path(am_pow_t power);
562+
static constexpr am_pow_t max_exponent_round_to_even();
563+
static constexpr am_pow_t min_exponent_round_to_even();
564+
static constexpr equiv_uint max_mantissa_fast_path(am_pow_t const power);
563565
static constexpr equiv_uint
564566
max_mantissa_fast_path(); // used when fegetround() == FE_TONEAREST
565567
static constexpr am_pow_t largest_power_of_ten();
566568
static constexpr am_pow_t smallest_power_of_ten();
567-
static constexpr T exact_power_of_ten(am_pow_t power);
569+
static constexpr T exact_power_of_ten(am_pow_t const power);
568570
static constexpr am_digits max_digits();
569571
static constexpr equiv_uint exponent_mask();
570572
static constexpr equiv_uint mantissa_mask();
@@ -673,32 +675,32 @@ inline constexpr am_bits_t binary_format<float>::min_exponent_fast_path() {
673675
}
674676

675677
template <>
676-
inline constexpr limb_t binary_format<double>::mantissa_explicit_bits() {
678+
inline constexpr am_bits_t binary_format<double>::mantissa_explicit_bits() {
677679
return 52;
678680
}
679681

680682
template <>
681-
inline constexpr limb_t binary_format<float>::mantissa_explicit_bits() {
683+
inline constexpr am_bits_t binary_format<float>::mantissa_explicit_bits() {
682684
return 23;
683685
}
684686

685687
template <>
686-
inline constexpr am_bits_t binary_format<double>::max_exponent_round_to_even() {
688+
inline constexpr am_pow_t binary_format<double>::max_exponent_round_to_even() {
687689
return 23;
688690
}
689691

690692
template <>
691-
inline constexpr am_bits_t binary_format<float>::max_exponent_round_to_even() {
693+
inline constexpr am_pow_t binary_format<float>::max_exponent_round_to_even() {
692694
return 10;
693695
}
694696

695697
template <>
696-
inline constexpr am_bits_t binary_format<double>::min_exponent_round_to_even() {
698+
inline constexpr am_pow_t binary_format<double>::min_exponent_round_to_even() {
697699
return -4;
698700
}
699701

700702
template <>
701-
inline constexpr am_bits_t binary_format<float>::min_exponent_round_to_even() {
703+
inline constexpr am_pow_t binary_format<float>::min_exponent_round_to_even() {
702704
return -17;
703705
}
704706

@@ -807,7 +809,7 @@ binary_format<std::float16_t>::max_exponent_fast_path() {
807809
}
808810

809811
template <>
810-
inline constexpr limb_t
812+
inline constexpr am_bits_t
811813
binary_format<std::float16_t>::mantissa_explicit_bits() {
812814
return 10;
813815
}
@@ -829,13 +831,13 @@ binary_format<std::float16_t>::min_exponent_fast_path() {
829831
}
830832

831833
template <>
832-
inline constexpr am_bits_t
834+
inline constexpr am_pow_t
833835
binary_format<std::float16_t>::max_exponent_round_to_even() {
834836
return 5;
835837
}
836838

837839
template <>
838-
inline constexpr am_bits_t
840+
inline constexpr am_pow_t
839841
binary_format<std::float16_t>::min_exponent_round_to_even() {
840842
return -22;
841843
}
@@ -934,7 +936,7 @@ binary_format<std::bfloat16_t>::hidden_bit_mask() {
934936
}
935937

936938
template <>
937-
inline constexpr limb_t
939+
inline constexpr am_bits_t
938940
binary_format<std::bfloat16_t>::mantissa_explicit_bits() {
939941
return 7;
940942
}
@@ -956,13 +958,13 @@ binary_format<std::bfloat16_t>::min_exponent_fast_path() {
956958
}
957959

958960
template <>
959-
inline constexpr am_bits_t
961+
inline constexpr am_pow_t
960962
binary_format<std::bfloat16_t>::max_exponent_round_to_even() {
961963
return 3;
962964
}
963965

964966
template <>
965-
inline constexpr am_bits_t
967+
inline constexpr am_pow_t
966968
binary_format<std::bfloat16_t>::min_exponent_round_to_even() {
967969
return -24;
968970
}

0 commit comments

Comments
 (0)