Skip to content

Commit

Permalink
Merge pull request #1004 from trcrsired/master
Browse files Browse the repository at this point in the history
Remove more braindeath by macromodel
  • Loading branch information
trcrsired authored Dec 3, 2024
2 parents 6a15e4a + 3f6d5ba commit ba3f7dd
Showing 1 changed file with 18 additions and 70 deletions.
88 changes: 18 additions & 70 deletions include/fast_io_core_impl/integers/sto/sto_contiguous.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace fast_io
namespace details
{

inline constexpr bool sto_use_table{true};

template <char8_t base, ::std::integral char_type>
requires(2 <= base && base <= 36)
inline constexpr bool char_digit_to_literal(my_make_unsigned_t<char_type> &ch) noexcept
Expand All @@ -34,32 +32,8 @@ inline constexpr bool char_digit_to_literal(my_make_unsigned_t<char_type> &ch) n
}
else
{
if constexpr (sto_use_table)
{
constexpr char8_t mx{::std::numeric_limits<char8_t>::max()};
constexpr bool use_partial{mx < (::std::numeric_limits<unsigned_char_type>::max()) ||
::std::numeric_limits<char8_t>::digits != 8};
if constexpr (use_partial)
{
constexpr ::std::size_t n{sto_base_tb<ebcdic, use_partial, base>.size()};
static_assert(n <= mx);
constexpr char8_t v{static_cast<char8_t>(n)};
if (v < ch)
{
return true;
}
}
char8_t ret{sto_base_tb<ebcdic, use_partial, base>[static_cast<unsigned_char_type>(ch)]};
if (ret == mx)
{
return true;
}
ch = static_cast<unsigned_char_type>(ret);
return false;
}
else if constexpr (ebcdic)
if constexpr (ebcdic)
{

if constexpr (base <= 19)
{
constexpr unsigned_char_type mns{base - 10};
Expand Down Expand Up @@ -213,29 +187,7 @@ inline constexpr bool char_is_digit(my_make_unsigned_t<char_type> ch) noexcept
}
else
{
if constexpr (sto_use_table)
{
constexpr char8_t mx{::std::numeric_limits<char8_t>::max()};
constexpr bool use_partial{mx < (::std::numeric_limits<unsigned_char_type>::max()) ||
::std::numeric_limits<char8_t>::digits != 8};
if constexpr (use_partial)
{
constexpr ::std::size_t n{sto_base_tb<ebcdic, use_partial, base>.size()};
static_assert(n <= mx);
constexpr char8_t v{static_cast<char8_t>(n)};
if (v < ch)
{
return false;
}
}
auto ret{sto_base_tb<ebcdic, use_partial, base>[static_cast<unsigned_char_type>(ch)]};
if (ret == mx)
{
return false;
}
return true;
}
else if constexpr (ebcdic)
if constexpr (ebcdic)
{
if constexpr (base <= 19)
{
Expand Down Expand Up @@ -680,15 +632,19 @@ scan_int_contiguous_none_simd_space_part_define_impl(char_type const *first, cha

if constexpr (max_size >= sizeof(::std::uint_least32_t))
{

constexpr ::std::uint_least32_t pow_base_sizeof_u32{::fast_io::details::compile_time_pow<::std::uint_least32_t>(static_cast<::std::uint_least32_t>(base_char_type), sizeof(::std::uint_least32_t))};
constexpr ::std::uint_least32_t first_bound{0x46464646 + 0x01010101 * (10 - base_char_type)};

if (static_cast<::std::size_t>(first_phase_last - first) >= sizeof(::std::uint_least32_t))
{
::std::uint_least32_t val;
::fast_io::freestanding::my_memcpy(__builtin_addressof(val), first, sizeof(::std::uint_least32_t));

val = ::fast_io::little_endian(val);

constexpr ::std::uint_least32_t pow_base_sizeof_u32{::fast_io::details::compile_time_pow<::std::uint_least32_t>(static_cast<::std::uint_least32_t>(base_char_type), sizeof(::std::uint_least32_t))};
constexpr ::std::uint_least32_t first_bound{0x46464646 + 0x01010101 * (10 - base_char_type)};
if constexpr (::std::endian::little != ::std::endian::native)
{
val = ::fast_io::little_endian(val);
}

if (::std::uint_least32_t const cval{((val + first_bound) | (val - 0x30303030)) & 0x80808080}; cval)
{
Expand Down Expand Up @@ -716,7 +672,7 @@ scan_int_contiguous_none_simd_space_part_define_impl(char_type const *first, cha
val = (val * base_char_type) + (val >> 8);
val = (((val & mask) * pow_base_sizeof_base_2) + ((val >> 16) & mask));

ctrz_cval >= shifter;
ctrz_cval >>= shifter;
res = static_cast<T>(res * ::fast_io::details::pow_table_n<base_char_type, ::std::uint_least32_t, 4>.index_unchecked(ctrz_cval) + val);

first += ctrz_cval;
Expand Down Expand Up @@ -807,6 +763,13 @@ scan_int_contiguous_none_simd_space_part_define_impl(char_type const *first, cha
{
if constexpr (max_size >= sizeof(::std::uint_least64_t))
{
constexpr ::std::uint_least64_t pow_base_sizeof_base_2{::fast_io::details::compile_time_pow<::std::uint_least64_t>(static_cast<::std::uint_least64_t>(base_char_type), 2)};
constexpr ::std::uint_least64_t pow_base_sizeof_base_4{::fast_io::details::compile_time_pow<::std::uint_least64_t>(static_cast<::std::uint_least64_t>(base_char_type), 4)};
constexpr ::std::uint_least64_t pow_base_sizeof_base_6{::fast_io::details::compile_time_pow<::std::uint_least64_t>(static_cast<::std::uint_least64_t>(base_char_type), 6)};

constexpr ::std::uint_least64_t mask{0x000000FF000000FF};
constexpr ::std::uint_least64_t mul1{pow_base_sizeof_base_2 + (pow_base_sizeof_base_6 << 32)};
constexpr ::std::uint_least64_t mul2{1 + (pow_base_sizeof_base_4 << 32)};
while (static_cast<::std::size_t>(first_phase_last - first) >= sizeof(::std::uint_least64_t))
{
::std::uint_least64_t val;
Expand Down Expand Up @@ -841,13 +804,6 @@ scan_int_contiguous_none_simd_space_part_define_impl(char_type const *first, cha
all_zero >>= valid_bits;

val |= all_zero;
constexpr ::std::uint_least64_t pow_base_sizeof_base_2{::fast_io::details::compile_time_pow<::std::uint_least64_t>(static_cast<::std::uint_least64_t>(base_char_type), 2)};
constexpr ::std::uint_least64_t pow_base_sizeof_base_4{::fast_io::details::compile_time_pow<::std::uint_least64_t>(static_cast<::std::uint_least64_t>(base_char_type), 4)};
constexpr ::std::uint_least64_t pow_base_sizeof_base_6{::fast_io::details::compile_time_pow<::std::uint_least64_t>(static_cast<::std::uint_least64_t>(base_char_type), 6)};

constexpr ::std::uint_least64_t mask{0x000000FF000000FF};
constexpr ::std::uint_least64_t mul1{pow_base_sizeof_base_2 + (pow_base_sizeof_base_6 << 32)};
constexpr ::std::uint_least64_t mul2{1 + (pow_base_sizeof_base_4 << 32)};

val -= 0x3030303030303030;
val = (val & 0x0f0f0f0f0f0f0f0f) + ((val & 0x1010101010101010) >> 4) * 9;
Expand All @@ -862,14 +818,6 @@ scan_int_contiguous_none_simd_space_part_define_impl(char_type const *first, cha
return scan_int_contiguous_none_simd_space_part_check_overflow_impl<base, char_type, T>(first, last, res);
}

constexpr ::std::uint_least64_t pow_base_sizeof_base_2{::fast_io::details::compile_time_pow<::std::uint_least64_t>(static_cast<::std::uint_least64_t>(base_char_type), 2)};
constexpr ::std::uint_least64_t pow_base_sizeof_base_4{::fast_io::details::compile_time_pow<::std::uint_least64_t>(static_cast<::std::uint_least64_t>(base_char_type), 4)};
constexpr ::std::uint_least64_t pow_base_sizeof_base_6{::fast_io::details::compile_time_pow<::std::uint_least64_t>(static_cast<::std::uint_least64_t>(base_char_type), 6)};

constexpr ::std::uint_least64_t mask{0x000000FF000000FF};
constexpr ::std::uint_least64_t mul1{pow_base_sizeof_base_2 + (pow_base_sizeof_base_6 << 32)};
constexpr ::std::uint_least64_t mul2{1 + (pow_base_sizeof_base_4 << 32)};

val -= 0x3030303030303030;
val = (val & 0x0f0f0f0f0f0f0f0f) + ((val & 0x1010101010101010) >> 4) * 9;
val = (val * base_char_type) + (val >> 8);
Expand Down

0 comments on commit ba3f7dd

Please sign in to comment.