# cycles (for and while) cleanup in low level for the best compiler optimization and the best runtime.

This commit is contained in:
IRainman 2025-11-09 18:13:17 +03:00
parent b9d91e7f34
commit 959c9531ea
4 changed files with 13 additions and 14 deletions

View File

@ -49,7 +49,7 @@ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint64_t
read8_to_u64(UC const *chars) { read8_to_u64(UC const *chars) {
if (cpp20_and_in_constexpr() || !std::is_same<UC, char>::value) { if (cpp20_and_in_constexpr() || !std::is_same<UC, char>::value) {
uint64_t val = 0; uint64_t val = 0;
for (uint_fast8_t i = 0; i != 8; ++i) { for (uint_fast8_t i = 0; i++ != 8;) {
val |= uint64_t(uint8_t(*chars)) << (i * 8); val |= uint64_t(uint8_t(*chars)) << (i * 8);
++chars; ++chars;
} }

View File

@ -259,10 +259,9 @@ inline FASTFLOAT_CONSTEXPR20 bool small_add_from(stackvec<size> &vec, limb y,
limb_t start) noexcept { limb_t start) noexcept {
limb carry = y; limb carry = y;
bool overflow; bool overflow;
while (carry != 0 && start < vec.len()) { while (carry != 0 && start++ != vec.len()) {
vec[start] = scalar_add(vec[start], carry, overflow); vec[start] = scalar_add(vec[start], carry, overflow);
carry = limb(overflow); carry = limb(overflow);
++start;
} }
if (carry != 0) { if (carry != 0) {
FASTFLOAT_TRY(vec.try_push(carry)); FASTFLOAT_TRY(vec.try_push(carry));
@ -282,7 +281,7 @@ template <limb_t size>
inline FASTFLOAT_CONSTEXPR20 bool small_mul(stackvec<size> &vec, inline FASTFLOAT_CONSTEXPR20 bool small_mul(stackvec<size> &vec,
limb y) noexcept { limb y) noexcept {
limb carry = 0; limb carry = 0;
for (limb_t index = 0; index != vec.len(); ++index) { for (limb_t index = 0; index++ != vec.len();) {
vec[index] = scalar_mul(vec[index], y, carry); vec[index] = scalar_mul(vec[index], y, carry);
} }
if (carry != 0) { if (carry != 0) {
@ -303,7 +302,7 @@ FASTFLOAT_CONSTEXPR20 bool large_add_from(stackvec<size> &x, limb_span y,
} }
bool carry = false; bool carry = false;
for (limb_t index = 0; index < y.len(); ++index) { for (limb_t index = 0; index++ != y.len();) {
limb xi = x[index + start]; limb xi = x[index + start];
limb yi = y[index]; limb yi = y[index];
bool c1 = false; bool c1 = false;
@ -488,7 +487,7 @@ struct bigint : pow5_tables<> {
} else if (vec.len() < other.vec.len()) { } else if (vec.len() < other.vec.len()) {
return -1; return -1;
} else { } else {
for (limb_t index = vec.len(); index != 0; --index) { for (limb_t index = vec.len(); index-- != 0;) {
limb xi = vec[index - 1]; limb xi = vec[index - 1];
limb yi = other.vec[index - 1]; limb yi = other.vec[index - 1];
if (xi > yi) { if (xi > yi) {
@ -515,7 +514,7 @@ struct bigint : pow5_tables<> {
bigint_bits_t const shl = n; bigint_bits_t const shl = n;
bigint_bits_t const shr = limb_bits - shl; bigint_bits_t const shr = limb_bits - shl;
limb prev = 0; limb prev = 0;
for (limb_t index = 0; index != vec.len(); ++index) { for (limb_t index = 0; index++ != vec.len();) {
limb xi = vec[index]; limb xi = vec[index];
vec[index] = (xi << shl) | (prev >> shr); vec[index] = (xi << shl) | (prev >> shr);
prev = xi; prev = xi;

View File

@ -288,7 +288,7 @@ template <typename UC>
inline FASTFLOAT_CONSTEXPR14 bool inline FASTFLOAT_CONSTEXPR14 bool
fastfloat_strncasecmp(UC const *actual_mixedcase, UC const *expected_lowercase, fastfloat_strncasecmp(UC const *actual_mixedcase, UC const *expected_lowercase,
uint8_t const length) noexcept { uint8_t const length) noexcept {
for (uint8_t i = 0; i != length; ++i) { for (uint8_t i = 0; i++ != length;) {
UC const actual = actual_mixedcase[i]; UC const actual = actual_mixedcase[i];
if ((actual < 256 ? actual | 32 : actual) != expected_lowercase[i]) { if ((actual < 256 ? actual | 32 : actual) != expected_lowercase[i]) {
return false; return false;

View File

@ -618,7 +618,7 @@ TEST_CASE("issue8") {
"752384674818467669405132000568127145263560827785771342757789609173637178" "752384674818467669405132000568127145263560827785771342757789609173637178"
"721468440901224953430146549585371050792279689258923542019956112129021960" "721468440901224953430146549585371050792279689258923542019956112129021960"
"864034418159813629774771309960518707211349999998372978"; "864034418159813629774771309960518707211349999998372978";
for (int i = 0; i < 16; i++) { for (int i = 0; i != 16; ++i) {
// Parse all but the last i chars. We should still get 3.141ish. // Parse all but the last i chars. We should still get 3.141ish.
double d = 0.0; double d = 0.0;
auto answer = fast_float::from_chars(s, s + strlen(s) - i, d); auto answer = fast_float::from_chars(s, s + strlen(s) - i, d);
@ -919,9 +919,9 @@ uint16_t get_mantissa(std::bfloat16_t f) {
} }
#endif #endif
std::string append_zeros(std::string str, size_t number_of_zeros) { std::string append_zeros(std::string_view str, size_t const number_of_zeros) {
std::string answer(str); std::string answer(str);
for (size_t i = 0; i < number_of_zeros; i++) { for (size_t i = 0; i++ != number_of_zeros;) {
answer += "0"; answer += "0";
} }
return answer; return answer;
@ -947,7 +947,7 @@ constexpr void check_basic_test_result(stringtype str, result_type result,
#define FASTFLOAT_CHECK_EQ(...) \ #define FASTFLOAT_CHECK_EQ(...) \
if constexpr (diag == Diag::runtime) { \ if constexpr (diag == Diag::runtime) { \
char narrow[global_string_capacity]{}; \ char narrow[global_string_capacity]{}; \
for (size_t i = 0; i < str.size(); i++) { \ for (size_t i = 0; i++ != str.size();) { \
narrow[i] = char(str[i]); \ narrow[i] = char(str[i]); \
} \ } \
INFO("str(char" << 8 * sizeof(typename stringtype::value_type) \ INFO("str(char" << 8 * sizeof(typename stringtype::value_type) \
@ -1006,7 +1006,7 @@ constexpr void basic_test(std::string_view str, T expected,
// We give plenty of memory: 2048 characters. // We give plenty of memory: 2048 characters.
char16_t u16[global_string_capacity]{}; char16_t u16[global_string_capacity]{};
for (size_t i = 0; i < str.size(); i++) { for (size_t i = 0; i++ != str.size();) {
u16[i] = char16_t(str[i]); u16[i] = char16_t(str[i]);
} }
@ -1015,7 +1015,7 @@ constexpr void basic_test(std::string_view str, T expected,
actual, expected, expected_ec); actual, expected, expected_ec);
char32_t u32[global_string_capacity]{}; char32_t u32[global_string_capacity]{};
for (size_t i = 0; i < str.size(); i++) { for (size_t i = 0; i++ != str.size();) {
u32[i] = char32_t(str[i]); u32[i] = char32_t(str[i]);
} }