From 3a2a73439562177389872c444b799e25e7a7429e Mon Sep 17 00:00:00 2001 From: killcerr Date: Thu, 1 May 2025 23:22:57 +0800 Subject: [PATCH] replace __has_builtin to FAST_IO_HAS_BUILTIN and replace __builtin_unreachable to ::fast_io::unreachable --- .../fast_io_core_impl/allocation/c_malloc.h | 44 ++------- include/fast_io_core_impl/codecvt/utf.h | 4 +- .../freestanding/algorithm.h | 36 ++------ .../freestanding/allocator.h | 8 +- .../fast_io_core_impl/freestanding/bytes.h | 40 +++------ .../fast_io_core_impl/freestanding/cstr_len.h | 12 +-- include/fast_io_core_impl/intrinsics.h | 90 +++++++------------ include/fast_io_core_impl/intrinsics/carry.h | 8 +- include/fast_io_core_impl/intrinsics/umul.h | 8 +- include/fast_io_core_impl/iso/iso8601.h | 44 ++------- .../fast_io_core_impl/secure_clear_guard.h | 12 +-- include/fast_io_core_impl/simd/gcc_clang.h | 60 ++++++------- include/fast_io_core_impl/simd/generic.h | 12 +-- include/fast_io_core_impl/socket/addrscn.h | 18 +--- include/fast_io_core_impl/terminate.h | 8 +- include/fast_io_core_impl/timestamp_counter.h | 6 +- include/fast_io_core_impl/utils.h | 8 +- include/fast_io_crypto/hash/crc32.h | 12 +-- .../hash/md5_sha_hash_context.h | 18 +--- include/fast_io_crypto/hash/sha256.h | 6 +- include/fast_io_crypto/hash/sha512.h | 4 +- include/fast_io_crypto/hash/sha512_simd16.h | 4 +- include/fast_io_crypto/hash/sha512_simd32.h | 2 +- .../hash/sha512_simd32_shuffle.h | 2 +- .../fast_io_crypto/streamcipher/chacha/impl.h | 2 +- include/fast_io_driver/tsc_timer.h | 2 +- include/fast_io_dsal/impl/freestanding.h | 6 +- include/fast_io_dsal/impl/misc/pop_macros.h | 1 + include/fast_io_dsal/impl/misc/push_macros.h | 10 ++- .../serializations/lebe.h | 12 +-- .../file_loaders/allocation_file_loader.h | 18 +--- .../fast_io_hosted/file_loaders/file_size.h | 6 +- .../fast_io_hosted/platforms/linux/amd64.h | 1 - .../timeutil/environ_timezone.h | 6 +- include/fast_io_i18n/locale/posix.h | 6 +- include/fast_io_legacy_impl/c/done.h | 55 +++--------- include/fast_io_legacy_impl/c/impl.h | 30 ++----- include/fast_io_legacy_impl/c/wincrt.h | 4 +- .../filebuf/rtti_hack/impl.h | 6 +- include/fast_io_unit/floating/punning.h | 6 +- share/fast_io/fast_io_inc/core.inc | 22 +++++ share/fast_io/fast_io_inc/freestanding.inc | 1 + share/fast_io/fast_io_inc/host/nt.inc | 6 +- share/fast_io/fast_io_inc/host/win32.inc | 5 ++ share/fast_io/fast_io_inc/hosted.inc | 6 ++ 45 files changed, 217 insertions(+), 460 deletions(-) diff --git a/include/fast_io_core_impl/allocation/c_malloc.h b/include/fast_io_core_impl/allocation/c_malloc.h index a1316de92..c77b868d5 100644 --- a/include/fast_io_core_impl/allocation/c_malloc.h +++ b/include/fast_io_core_impl/allocation/c_malloc.h @@ -39,12 +39,8 @@ class c_malloc_allocator n = 1; } void *p = -#if defined(__has_builtin) -#if __has_builtin(__builtin_malloc) +#if FAST_IO_HAS_BUILTIN(__builtin_malloc) __builtin_malloc(n) -#else - ::std::malloc(n) -#endif #else ::std::malloc(n) #endif @@ -66,12 +62,8 @@ class c_malloc_allocator } ::std::size_t const to_allocate{n}; p = -#if defined(__has_builtin) -#if __has_builtin(__builtin_realloc) +#if FAST_IO_HAS_BUILTIN(__builtin_realloc) __builtin_realloc -#else - ::std::realloc -#endif #else ::std::realloc #endif @@ -93,12 +85,8 @@ class c_malloc_allocator n = 1; } void *p = -#if defined(__has_builtin) -#if __has_builtin(__builtin_calloc) +#if FAST_IO_HAS_BUILTIN(__builtin_calloc) __builtin_calloc -#else - ::std::calloc -#endif #else ::std::calloc #endif @@ -142,12 +130,8 @@ class c_malloc_allocator if (alignment <= __STDCPP_DEFAULT_NEW_ALIGNMENT__) { p = -#if defined(__has_builtin) -#if __has_builtin(__builtin_malloc) +#if FAST_IO_HAS_BUILTIN(__builtin_malloc) __builtin_malloc -#else - ::std::malloc -#endif #else ::std::malloc #endif @@ -175,12 +159,8 @@ class c_malloc_allocator if (alignment <= __STDCPP_DEFAULT_NEW_ALIGNMENT__) { p = -#if defined(__has_builtin) -#if __has_builtin(__builtin_realloc) +#if FAST_IO_HAS_BUILTIN(__builtin_realloc) __builtin_realloc -#else - ::std::realloc -#endif #else ::std::realloc #endif @@ -205,12 +185,8 @@ class c_malloc_allocator } if (alignment <= __STDCPP_DEFAULT_NEW_ALIGNMENT__) { -#if defined(__has_builtin) -#if __has_builtin(__builtin_free) +#if FAST_IO_HAS_BUILTIN(__builtin_free) __builtin_free -#else - ::std::free -#endif #else ::std::free #endif @@ -228,12 +204,8 @@ class c_malloc_allocator { return; } -#if defined(__has_builtin) -#if __has_builtin(__builtin_free) - __builtin_free -#else - ::std::free -#endif +#if FAST_IO_HAS_BUILTIN(__builtin_free) + __builtin_free #else ::std::free #endif diff --git a/include/fast_io_core_impl/codecvt/utf.h b/include/fast_io_core_impl/codecvt/utf.h index f4e9fe83f..53bacdf79 100644 --- a/include/fast_io_core_impl/codecvt/utf.h +++ b/include/fast_io_core_impl/codecvt/utf.h @@ -520,7 +520,7 @@ inline code_cvt_result convert_ascii_with_sse(T const *__restrict pSrc, U x86_64_v16qi chunk; __builtin_memcpy(__builtin_addressof(chunk), pSrc, m128i_size); mask = static_cast<::std::uint_least32_t>(__builtin_ia32_pmovmskb128(chunk)); -#if __has_builtin(__builtin_shufflevector) +#if FAST_IO_HAS_BUILTIN(__builtin_shufflevector) x86_64_v16qi half{__builtin_shufflevector(chunk, zero, 0, 16 + 0, 1, 16 + 1, 2, 16 + 2, 3, 16 + 3, 4, 16 + 4, 5, 16 + 5, 6, 16 + 6, 7, 16 + 7)}; __builtin_memcpy(pDst, __builtin_addressof(half), m128i_size); @@ -539,7 +539,7 @@ inline code_cvt_result convert_ascii_with_sse(T const *__restrict pSrc, U x86_64_v16qi chunk; __builtin_memcpy(__builtin_addressof(chunk), pSrc, m128i_size); mask = static_cast<::std::uint_least32_t>(__builtin_ia32_pmovmskb128(chunk)); -#if __has_builtin(__builtin_shufflevector) +#if FAST_IO_HAS_BUILTIN(__builtin_shufflevector) x86_64_v16qi half_result{__builtin_shufflevector(chunk, zero, 0, 16 + 0, 1, 16 + 1, 2, 16 + 2, 3, 16 + 3, 4, 16 + 4, 5, 16 + 5, 6, 16 + 6, 7, 16 + 7)}; x86_64_v8hi half; diff --git a/include/fast_io_core_impl/freestanding/algorithm.h b/include/fast_io_core_impl/freestanding/algorithm.h index a460f26e4..e235170bf 100644 --- a/include/fast_io_core_impl/freestanding/algorithm.h +++ b/include/fast_io_core_impl/freestanding/algorithm.h @@ -243,21 +243,15 @@ namespace fast_io::freestanding { inline -#if defined(__has_builtin) -#if __has_builtin(__builtin_memcpy) +#if FAST_IO_HAS_BUILTIN(__builtin_memcpy) constexpr -#endif #endif void * my_memcpy(void *dest, void const *src, ::std::size_t count) noexcept { return -#if defined(__has_builtin) -#if __has_builtin(__builtin_memcpy) +#if FAST_IO_HAS_BUILTIN(__builtin_memcpy) __builtin_memcpy -#else - ::std::memcpy -#endif #else ::std::memcpy #endif @@ -265,21 +259,15 @@ inline } inline -#if defined(__has_builtin) -#if __has_builtin(__builtin_memmove) +#if FAST_IO_HAS_BUILTIN(__builtin_memmove) constexpr -#endif #endif void * my_memmove(void *dest, void const *src, ::std::size_t count) noexcept { return -#if defined(__has_builtin) -#if __has_builtin(__builtin_memmove) +#if FAST_IO_HAS_BUILTIN(__builtin_memmove) __builtin_memmove -#else - ::std::memmove -#endif #else ::std::memmove #endif @@ -289,12 +277,8 @@ inline inline void *my_memset(void *dest, int ch, ::std::size_t count) noexcept { return -#if defined(__has_builtin) -#if __has_builtin(__builtin_memset) +#if FAST_IO_HAS_BUILTIN(__builtin_memset) __builtin_memset -#else - ::std::memset -#endif #else ::std::memset #endif @@ -302,21 +286,15 @@ inline void *my_memset(void *dest, int ch, ::std::size_t count) noexcept } inline -#if defined(__has_builtin) -#if __has_builtin(__builtin_memcmp) +#if FAST_IO_HAS_BUILTIN(__builtin_memcmp) constexpr -#endif #endif int my_memcmp(void const *dest, void const *src, ::std::size_t count) noexcept { return -#if defined(__has_builtin) -#if __has_builtin(__builtin_memcmp) +#if FAST_IO_HAS_BUILTIN(__builtin_memcmp) __builtin_memcmp -#else - ::std::memcmp -#endif #else ::std::memcmp #endif diff --git a/include/fast_io_core_impl/freestanding/allocator.h b/include/fast_io_core_impl/freestanding/allocator.h index 96145f62a..97210edd4 100644 --- a/include/fast_io_core_impl/freestanding/allocator.h +++ b/include/fast_io_core_impl/freestanding/allocator.h @@ -13,8 +13,8 @@ struct allocator { __builtin_trap(); } -#if __has_builtin(__builtin_operator_new) - return static_cast(__builtin_operator_new(n * sizeof(T))); +#if FAST_IO_HAS_BUILTIN(__builtin_operator_new) + return static_cast(__builtin_operator_new(n * sizeof(T))); #else __builtin_trap(); return nullptr; @@ -22,8 +22,8 @@ struct allocator } inline constexpr void deallocate([[maybe_unused]] T *ptr, [[maybe_unused]] ::std::size_t n) noexcept { -#if __has_builtin(__builtin_operator_delete) - __builtin_operator_delete(ptr, sizeof(T) * n); +#if FAST_IO_HAS_BUILTIN(__builtin_operator_delete) + __builtin_operator_delete(ptr, sizeof(T) * n); #endif } }; diff --git a/include/fast_io_core_impl/freestanding/bytes.h b/include/fast_io_core_impl/freestanding/bytes.h index da215e319..a80c86a83 100644 --- a/include/fast_io_core_impl/freestanding/bytes.h +++ b/include/fast_io_core_impl/freestanding/bytes.h @@ -88,10 +88,8 @@ inline constexpr ::std::byte *bytes_copy_n(::std::byte const *first, ::std::size [[likely]] #endif { -#if !defined(__has_builtin) - ::std::memmove(dest, first, n); -#elif __has_builtin(__builtin_memmove) - __builtin_memmove(dest, first, n); +#if FAST_IO_HAS_BUILTIN(__builtin_memmove) + __builtin_memmove(dest, first, n); #else ::std::memmove(dest, first, n); #endif @@ -122,10 +120,8 @@ inline constexpr ::std::byte *nonoverlapped_bytes_copy_n(::std::byte const *firs [[likely]] #endif { -#if !defined(__has_builtin) - ::std::memcpy(dest, first, n); -#elif __has_builtin(__builtin_memcpy) - __builtin_memcpy(dest, first, n); +#if FAST_IO_HAS_BUILTIN(__builtin_memcpy) + __builtin_memcpy(dest, first, n); #else ::std::memcpy(dest, first, n); #endif @@ -157,10 +153,8 @@ inline constexpr ::std::byte const *type_punning_from_bytes(::std::byte const *_ else #endif { -#if !defined(__has_builtin) - ::std::memcpy(__builtin_addressof(t), first, n); -#elif __has_builtin(__builtin_memcpy) - __builtin_memcpy(__builtin_addressof(t), first, n); +#if FAST_IO_HAS_BUILTIN(__builtin_memcpy) + __builtin_memcpy(__builtin_addressof(t), first, n); #else ::std::memcpy(__builtin_addressof(t), first, n); #endif @@ -184,10 +178,8 @@ inline constexpr ::std::byte *type_punning_to_bytes_n(T const &__restrict first, else #endif { -#if !defined(__has_builtin) - ::std::memcpy(dest, __builtin_addressof(first), n); -#elif __has_builtin(__builtin_memcpy) - __builtin_memcpy(dest, __builtin_addressof(first), n); +#if FAST_IO_HAS_BUILTIN(__builtin_memcpy) + __builtin_memcpy(dest, __builtin_addressof(first), n); #else ::std::memcpy(dest, __builtin_addressof(first), n); #endif @@ -214,12 +206,8 @@ inline constexpr ::std::byte *bytes_clear_n(::std::byte *data, ::std::size_t siz } else { -#if defined(__has_builtin) -#if __has_builtin(__builtin_memset) - __builtin_memset(data, 0, size); -#else - ::std::memset(data, 0, size); -#endif +#if FAST_IO_HAS_BUILTIN(__builtin_memset) + __builtin_memset(data, 0, size); #else ::std::memset(data, 0, size); #endif @@ -243,12 +231,8 @@ inline constexpr ::std::byte *bytes_fill_n(::std::byte *data, ::std::size_t size } else { -#if defined(__has_builtin) -#if __has_builtin(__builtin_memset) - __builtin_memset(data, static_cast(val), size); -#else - ::std::memset(data, static_cast(val), size); -#endif +#if FAST_IO_HAS_BUILTIN(__builtin_memset) + __builtin_memset(data, static_cast(val), size); #else ::std::memset(data, static_cast(val), size); #endif diff --git a/include/fast_io_core_impl/freestanding/cstr_len.h b/include/fast_io_core_impl/freestanding/cstr_len.h index a7fda553a..388e5d807 100644 --- a/include/fast_io_core_impl/freestanding/cstr_len.h +++ b/include/fast_io_core_impl/freestanding/cstr_len.h @@ -39,12 +39,8 @@ inline constexpr ::std::size_t cstr_len(char_type const *cstr) noexcept { if constexpr (::std::same_as) { -#if defined(__has_builtin) -#if __has_builtin(__builtin_strlen) +#if FAST_IO_HAS_BUILTIN(__builtin_strlen) return __builtin_strlen(cstr); -#else - return ::std::strlen(cstr); -#endif #else return ::std::strlen(cstr); #endif @@ -67,12 +63,8 @@ inline constexpr ::std::size_t cstr_nlen(char_type const *cstr, ::std::size_t n) { if constexpr (::std::same_as) { -#if defined(__has_builtin) -#if __has_builtin(__builtin_strnlen) +#if FAST_IO_HAS_BUILTIN(__builtin_strnlen) return __builtin_strnlen(cstr, n); -#else - return details::dummy_cstr_nlen(cstr, n); -#endif #else return details::dummy_cstr_nlen(cstr, n); #endif diff --git a/include/fast_io_core_impl/intrinsics.h b/include/fast_io_core_impl/intrinsics.h index e6c327fc7..64dbe733a 100644 --- a/include/fast_io_core_impl/intrinsics.h +++ b/include/fast_io_core_impl/intrinsics.h @@ -24,14 +24,10 @@ inline { if (dest == nullptr || src == nullptr || sizeof(T1) != sizeof(T2) || bytes % sizeof(T1) != 0) { -#if defined(__has_builtin) -#if __has_builtin(__builtin_trap) +#if FAST_IO_HAS_BUILTIN(__builtin_trap) __builtin_trap(); -#elif __has_builtin(__builtin_abort) +#elif FAST_IO_HAS_BUILTIN(__builtin_abort) __builtin_abort(); -#else - ::std::abort(); -#endif #else ::std::abort(); #endif @@ -45,12 +41,8 @@ inline else #endif { -#if defined(__has_builtin) -#if __has_builtin(__builtin_memcpy) +#if FAST_IO_HAS_BUILTIN(__builtin_memcpy) __builtin_memcpy(dest, src, bytes); -#else - memcpy(dest, src, bytes); -#endif #else memcpy(dest, src, bytes); #endif @@ -90,8 +82,7 @@ using ul32x2 = ul_generic_x2<::std::uint_least32_t>; inline constexpr ::std::uint_least32_t umul_least_32(::std::uint_least32_t a, ::std::uint_least32_t b, ::std::uint_least32_t &high) noexcept { -#if defined(__has_builtin) && defined(__GNUC__) && !defined(__clang__) -#if __has_builtin(__builtin_bit_cast) +#if defined(__GNUC__) && !defined(__clang__) && FAST_IO_HAS_BUILTIN(__builtin_bit_cast) if constexpr (::std::endian::native == ::std::endian::little || ::std::endian::native == ::std::endian::big) { auto ret{__builtin_bit_cast(ul32x2, static_cast<::std::uint_least64_t>(a) * b)}; @@ -99,7 +90,6 @@ inline constexpr ::std::uint_least32_t umul_least_32(::std::uint_least32_t a, :: return ret.low; } else -#endif #endif { ::std::uint_least64_t v{static_cast<::std::uint_least64_t>(a) * b}; @@ -110,15 +100,13 @@ inline constexpr ::std::uint_least32_t umul_least_32(::std::uint_least32_t a, :: inline constexpr ::std::uint_least32_t umulh_least_32(::std::uint_least32_t a, ::std::uint_least32_t b) noexcept { -#if defined(__has_builtin) && defined(__GNUC__) && !defined(__clang__) -#if __has_builtin(__builtin_bit_cast) +#if defined(__GNUC__) && !defined(__clang__) && FAST_IO_HAS_BUILTIN(__builtin_bit_cast) if constexpr (::std::endian::native == ::std::endian::little || ::std::endian::native == ::std::endian::big) { auto ret{__builtin_bit_cast(ul32x2, static_cast<::std::uint_least64_t>(a) * b)}; return ret.high; } else -#endif #endif { ::std::uint_least64_t v{static_cast<::std::uint_least64_t>(a) * b}; @@ -128,8 +116,7 @@ inline constexpr ::std::uint_least32_t umulh_least_32(::std::uint_least32_t a, : inline constexpr ::std::uint_least32_t unpack_ul64(::std::uint_least64_t a, ::std::uint_least32_t &high) noexcept { -#if defined(__has_builtin) && defined(__GNUC__) && !defined(__clang__) -#if __has_builtin(__builtin_bit_cast) +#if defined(__GNUC__) && !defined(__clang__) && FAST_IO_HAS_BUILTIN(__builtin_bit_cast) if constexpr (::std::endian::native == ::std::endian::little) { auto [a0, a1] = __builtin_bit_cast(ul32x2_little_endian, a); // get around gcc bug @@ -143,7 +130,6 @@ inline constexpr ::std::uint_least32_t unpack_ul64(::std::uint_least64_t a, ::st return a0; } else -#endif #endif { high = static_cast<::std::uint_least32_t>(a >> ::std::numeric_limits<::std::uint_least32_t>::digits); @@ -155,8 +141,7 @@ template requires(sizeof(T) == sizeof(U) * 2) inline constexpr U unpack_generic(T a, U &high) noexcept { -#if defined(__has_builtin) && defined(__GNUC__) && !defined(__clang__) -#if __has_builtin(__builtin_bit_cast) +#if defined(__GNUC__) && !defined(__clang__) && FAST_IO_HAS_BUILTIN(__builtin_bit_cast) if constexpr (::std::endian::native == ::std::endian::little) { auto [a0, a1] = __builtin_bit_cast(ul_generic_x2_little_endian, a); // get around gcc bug @@ -170,7 +155,6 @@ inline constexpr U unpack_generic(T a, U &high) noexcept return a0; } else -#endif #endif { high = static_cast(a >> ::std::numeric_limits::digits); @@ -239,9 +223,8 @@ inline constexpr bool add_carry(bool carry, T a, T b, T &out) noexcept #else return add_carry_naive(carry, a, b, out); #endif -#elif defined(__has_builtin) && \ - (__has_builtin(__builtin_addcb) && __has_builtin(__builtin_addcs) && __has_builtin(__builtin_addc) && \ - __has_builtin(__builtin_addcl) && __has_builtin(__builtin_addcll)) +#elif (FAST_IO_HAS_BUILTIN(__builtin_addcb) && FAST_IO_HAS_BUILTIN(__builtin_addcs) && FAST_IO_HAS_BUILTIN(__builtin_addc) && \ + FAST_IO_HAS_BUILTIN(__builtin_addcl) && FAST_IO_HAS_BUILTIN(__builtin_addcll)) if constexpr (sizeof(T) == sizeof(long long unsigned)) { long long unsigned carryout; @@ -276,12 +259,11 @@ inline constexpr bool add_carry(bool carry, T a, T b, T &out) noexcept { return add_carry_naive(carry, a, b, out); } -#elif defined(__has_builtin) && \ - (__has_builtin(__builtin_ia32_addcarryx_u32) || __has_builtin(__builtin_ia32_addcarry_u32) || \ - __has_builtin(__builtin_ia32_addcarryx_u64)) +#elif (FAST_IO_HAS_BUILTIN(__builtin_ia32_addcarryx_u32) || FAST_IO_HAS_BUILTIN(__builtin_ia32_addcarry_u32) || \ + FAST_IO_HAS_BUILTIN(__builtin_ia32_addcarryx_u64)) if constexpr (sizeof(T) == 8) { -#if __has_builtin(__builtin_ia32_addcarryx_u64) +#if FAST_IO_HAS_BUILTIN(__builtin_ia32_addcarryx_u64) using may_alias_ptr_type #if __has_cpp_attribute(__gnu__::__may_alias__) [[__gnu__::__may_alias__]] @@ -289,7 +271,7 @@ inline constexpr bool add_carry(bool carry, T a, T b, T &out) noexcept = unsigned long long *; return __builtin_ia32_addcarryx_u64(carry, a, b, reinterpret_cast(__builtin_addressof(out))); -#elif __has_builtin(__builtin_ia32_addcarry_u64) +#elif FAST_IO_HAS_BUILTIN(__builtin_ia32_addcarry_u64) using may_alias_ptr_type #if __has_cpp_attribute(__gnu__::__may_alias__) [[__gnu__::__may_alias__]] @@ -313,12 +295,12 @@ inline constexpr bool add_carry(bool carry, T a, T b, T &out) noexcept [[__gnu__::__may_alias__]] #endif = unsigned *; -#if __has_builtin(__builtin_ia32_addcarryx_u32) +#if FAST_IO_HAS_BUILTIN(__builtin_ia32_addcarryx_u32) return __builtin_ia32_addcarryx_u32( __builtin_ia32_addcarryx_u32(carry, a_low, b_low, reinterpret_cast(__builtin_addressof(out))), a_high, b_high, reinterpret_cast(__builtin_addressof(out)) + 1); -#elif __has_builtin(__builtin_ia32_addcarry_u32) +#elif FAST_IO_HAS_BUILTIN(__builtin_ia32_addcarry_u32) return __builtin_ia32_addcarry_u32( __builtin_ia32_addcarry_u32(carry, a_low, b_low, reinterpret_cast(__builtin_addressof(out))), @@ -335,10 +317,10 @@ inline constexpr bool add_carry(bool carry, T a, T b, T &out) noexcept [[__gnu__::__may_alias__]] #endif = unsigned *; -#if __has_builtin(__builtin_ia32_addcarryx_u32) +#if FAST_IO_HAS_BUILTIN(__builtin_ia32_addcarryx_u32) return __builtin_ia32_addcarryx_u32(carry, a, b, reinterpret_cast(__builtin_addressof(out))); -#elif __has_builtin(__builtin_ia32_addcarry_u32) +#elif FAST_IO_HAS_BUILTIN(__builtin_ia32_addcarry_u32) return __builtin_ia32_addcarry_u32(carry, a, b, reinterpret_cast(__builtin_addressof(out))); #else @@ -427,9 +409,8 @@ inline constexpr bool sub_borrow(bool borrow, T a, T b, T &out) noexcept #else return sub_borrow_naive(borrow, a, b, out); #endif -#elif defined(__has_builtin) && \ - (__has_builtin(__builtin_subcb) && __has_builtin(__builtin_subcs) && __has_builtin(__builtin_subc) && \ - __has_builtin(__builtin_subcl) && __has_builtin(__builtin_subcll)) +#elif (FAST_IO_HAS_BUILTIN(__builtin_subcb) && FAST_IO_HAS_BUILTIN(__builtin_subcs) && FAST_IO_HAS_BUILTIN(__builtin_subc) && \ + FAST_IO_HAS_BUILTIN(__builtin_subcl) && FAST_IO_HAS_BUILTIN(__builtin_subcll)) if constexpr (sizeof(T) == sizeof(long long unsigned)) { long long unsigned borrowout; @@ -464,12 +445,11 @@ inline constexpr bool sub_borrow(bool borrow, T a, T b, T &out) noexcept { return sub_borrow_naive(borrow, a, b, out); } -#elif defined(__has_builtin) && \ - (__has_builtin(__builtin_ia32_sbb_u32) || __has_builtin(__builtin_ia32_sbb_u64) || \ - __has_builtin(__builtin_ia32_subborrow_u64) || __has_builtin(__builtin_ia32_subborrow_u32)) +#elif (FAST_IO_HAS_BUILTIN(__builtin_ia32_sbb_u32) || FAST_IO_HAS_BUILTIN(__builtin_ia32_sbb_u64) || \ + FAST_IO_HAS_BUILTIN(__builtin_ia32_subborrow_u64) || FAST_IO_HAS_BUILTIN(__builtin_ia32_subborrow_u32)) if constexpr (sizeof(T) == 8) { -#if __has_builtin(__builtin_ia32_sbb_u64) +#if FAST_IO_HAS_BUILTIN(__builtin_ia32_sbb_u64) using may_alias_ptr_type #if __has_cpp_attribute(__gnu__::__may_alias__) [[__gnu__::__may_alias__]] @@ -477,7 +457,7 @@ inline constexpr bool sub_borrow(bool borrow, T a, T b, T &out) noexcept = unsigned long long *; return __builtin_ia32_sbb_u64(borrow, a, b, reinterpret_cast(__builtin_addressof(out))); -#elif __has_builtin(__builtin_ia32_subborrow_u64) +#elif FAST_IO_HAS_BUILTIN(__builtin_ia32_subborrow_u64) using may_alias_ptr_type #if __has_cpp_attribute(__gnu__::__may_alias__) [[__gnu__::__may_alias__]] @@ -485,7 +465,7 @@ inline constexpr bool sub_borrow(bool borrow, T a, T b, T &out) noexcept = unsigned long long *; return __builtin_ia32_subborrow_u64(borrow, a, b, reinterpret_cast(__builtin_addressof(out))); -#elif __has_builtin(__builtin_ia32_sbb_u32) || __has_builtin(__builtin_ia32_subborrow_u32) +#elif FAST_IO_HAS_BUILTIN(__builtin_ia32_sbb_u32) || FAST_IO_HAS_BUILTIN(__builtin_ia32_subborrow_u32) ::std::uint_least32_t a_low; ::std::uint_least32_t a_high; __builtin_memcpy(__builtin_addressof(a_low), __builtin_addressof(a), 4); @@ -501,7 +481,7 @@ inline constexpr bool sub_borrow(bool borrow, T a, T b, T &out) noexcept [[__gnu__::__may_alias__]] #endif = unsigned *; -#if __has_builtin(__builtin_ia32_sbb_u32) +#if FAST_IO_HAS_BUILTIN(__builtin_ia32_sbb_u32) return __builtin_ia32_sbb_u32( __builtin_ia32_sbb_u32(borrow, a_low, b_low, reinterpret_cast(__builtin_addressof(out))), @@ -518,7 +498,7 @@ inline constexpr bool sub_borrow(bool borrow, T a, T b, T &out) noexcept } else if constexpr (sizeof(T) == 4) { -#if __has_builtin(__builtin_ia32_sbb_u32) +#if FAST_IO_HAS_BUILTIN(__builtin_ia32_sbb_u32) using may_alias_ptr_type #if __has_cpp_attribute(__gnu__::__may_alias__) [[__gnu__::__may_alias__]] @@ -526,7 +506,7 @@ inline constexpr bool sub_borrow(bool borrow, T a, T b, T &out) noexcept = unsigned *; return __builtin_ia32_sbb_u32(borrow, a, b, reinterpret_cast(__builtin_addressof(out))); -#elif __has_builtin(__builtin_ia32_subborrow_u32) +#elif FAST_IO_HAS_BUILTIN(__builtin_ia32_subborrow_u32) using may_alias_ptr_type #if __has_cpp_attribute(__gnu__::__may_alias__) [[__gnu__::__may_alias__]] @@ -551,8 +531,7 @@ inline constexpr bool sub_borrow(bool borrow, T a, T b, T &out) noexcept inline constexpr ::std::uint_least64_t pack_ul64(::std::uint_least32_t low, ::std::uint_least32_t high) noexcept { -#if defined(__has_builtin) && defined(__GNUC__) && !defined(__clang__) -#if __has_builtin(__builtin_bit_cast) +#if defined(__GNUC__) && !defined(__clang__) && FAST_IO_HAS_BUILTIN(__builtin_bit_cast) if constexpr (::std::endian::native == ::std::endian::little) { return __builtin_bit_cast(::std::uint_least64_t, ul32x2_little_endian{low, high}); // get around gcc bug @@ -562,7 +541,6 @@ inline constexpr ::std::uint_least64_t pack_ul64(::std::uint_least32_t low, ::st return __builtin_bit_cast(::std::uint_least64_t, ul32x2_big_endian{high, low}); // get around gcc bug } else -#endif #endif { return (static_cast<::std::uint_least64_t>(high) << 32u) | low; @@ -625,14 +603,14 @@ inline using u64x2_t = ::std::conditional_t<::std::endian::native == ::std::endian::little, u64x2_little_endian_t, u64x2_big_endian_t>; static_assert(sizeof(__uint128_t) == sizeof(u64x2_t)); -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) auto u{__builtin_bit_cast(u64x2_t, static_cast<__uint128_t>(a) * b)}; high = u.high; return u.low; #else __uint128_t res{static_cast<__uint128_t>(a) * b}; u64x2_t u; -#if __has_builtin(__builtin_memcpy) +#if FAST_IO_HAS_BUILTIN(__builtin_memcpy) __builtin_memcpy(__builtin_addressof(u), __builtin_addressof(res), sizeof(u64x2_t)); #else ::std::memcpy(__builtin_addressof(u), __builtin_addressof(res), sizeof(u64x2_t)); @@ -765,7 +743,7 @@ inline constexpr ::std::size_t add_or_overflow_die(::std::size_t a, ::std::size_ } return size; } -#elif __has_builtin(__builtin_add_overflow) && __has_builtin(__builtin_trap) +#elif FAST_IO_HAS_BUILTIN(__builtin_add_overflow) && FAST_IO_HAS_BUILTIN(__builtin_trap) ::std::size_t size; if (__builtin_add_overflow(a, b, __builtin_addressof(size))) [[unlikely]] { @@ -805,7 +783,7 @@ inline constexpr ::std::size_t mul_or_overflow_die(::std::size_t a, ::std::size_ __debugbreak(); } return a * b; -#elif __has_builtin(__builtin_mul_overflow) && __has_builtin(__builtin_trap) +#elif FAST_IO_HAS_BUILTIN(__builtin_mul_overflow) && FAST_IO_HAS_BUILTIN(__builtin_trap) ::std::size_t size; if (__builtin_mul_overflow(a, b, __builtin_addressof(size))) [[unlikely]] { @@ -853,7 +831,7 @@ inline constexpr bool sub_underflow(int_type a, int_type b, int_type &c) noexcep { #if defined(_MSC_VER) && !defined(__clang__) return sub_underflow_naive(a, b, c); -#elif __has_builtin(__builtin_sub_underflow) +#elif FAST_IO_HAS_BUILTIN(__builtin_sub_underflow) return __builtin_sub_underflow(a, b, __builtin_addressof(c)); #else return sub_underflow_naive(a, b, c); @@ -884,7 +862,7 @@ inline constexpr ::std::size_t cal_allocation_size_or_die(::std::size_t size) no __debugbreak(); } return size * sizeof(T); -#elif __has_builtin(__builtin_mul_overflow) && __has_builtin(__builtin_trap) +#elif FAST_IO_HAS_BUILTIN(__builtin_mul_overflow) && FAST_IO_HAS_BUILTIN(__builtin_trap) if (__builtin_mul_overflow(size, sizeof(T), __builtin_addressof(size))) [[unlikely]] { __builtin_trap(); diff --git a/include/fast_io_core_impl/intrinsics/carry.h b/include/fast_io_core_impl/intrinsics/carry.h index 918ea80a0..5a5da23ac 100644 --- a/include/fast_io_core_impl/intrinsics/carry.h +++ b/include/fast_io_core_impl/intrinsics/carry.h @@ -74,14 +74,12 @@ inline constexpr T addc(T a, T b, bool carryin, bool &carryout) noexcept return (static_cast(reshigh) << 32u) | reslow; } } -#elif defined(__has_builtin) -#if __has_builtin(__builtin_add_overflow) +#elif FAST_IO_HAS_BUILTIN(__builtin_add_overflow) T s; auto c1 = __builtin_add_overflow(a, b, __builtin_addressof(s)); auto c2 = __builtin_add_overflow(s, carryin, __builtin_addressof(s)); carryout = c1 | c2; return s; -#endif #endif } a += b; @@ -152,14 +150,12 @@ inline constexpr T subc(T a, T b, bool carryin, bool &carryout) noexcept return (static_cast(reshigh) << 32u) | reslow; } } -#elif defined(__has_builtin) -#if __has_builtin(__builtin_sub_overflow) +#elif FAST_IO_HAS_BUILTIN(__builtin_sub_overflow) T s; auto c1 = __builtin_sub_overflow(a, b, __builtin_addressof(s)); auto c2 = __builtin_sub_overflow(s, carryin, __builtin_addressof(s)); carryout = c1 | c2; return s; -#endif #endif } b = a - b; diff --git a/include/fast_io_core_impl/intrinsics/umul.h b/include/fast_io_core_impl/intrinsics/umul.h index a11b5ced7..29147a75b 100644 --- a/include/fast_io_core_impl/intrinsics/umul.h +++ b/include/fast_io_core_impl/intrinsics/umul.h @@ -100,8 +100,7 @@ template requires(sizeof(U) * 2 <= sizeof(T)) inline constexpr U umul_least_generic(U a, U b, U &high) noexcept { -#if defined(__has_builtin) && defined(__GNUC__) && !defined(__clang__) -#if __has_builtin(__builtin_bit_cast) +#if defined(__GNUC__) && !defined(__clang__) && FAST_IO_HAS_BUILTIN(__builtin_bit_cast) if constexpr (::std::endian::native == ::std::endian::little || ::std::endian::native == ::std::endian::big) { auto ret{__builtin_bit_cast(::fast_io::intrinsics::ul_generic_x2, static_cast(a) * b)}; @@ -109,7 +108,6 @@ inline constexpr U umul_least_generic(U a, U b, U &high) noexcept return ret.low; } else -#endif #endif { T v{static_cast(a) * b}; @@ -174,15 +172,13 @@ template requires(sizeof(U) * 2 <= sizeof(T)) inline constexpr U umulh_least_generic(U a, U b) noexcept { -#if defined(__has_builtin) && defined(__GNUC__) && !defined(__clang__) -#if __has_builtin(__builtin_bit_cast) +#if defined(__GNUC__) && !defined(__clang__) && FAST_IO_HAS_BUILTIN(__builtin_bit_cast) if constexpr (::std::endian::native == ::std::endian::little || ::std::endian::native == ::std::endian::big) { auto ret{__builtin_bit_cast(::fast_io::intrinsics::ul_generic_x2, static_cast(a) * b)}; return ret.high; } else -#endif #endif { T v{static_cast(a) * b}; diff --git a/include/fast_io_core_impl/iso/iso8601.h b/include/fast_io_core_impl/iso/iso8601.h index 90ec82aaa..fc2a656e4 100644 --- a/include/fast_io_core_impl/iso/iso8601.h +++ b/include/fast_io_core_impl/iso/iso8601.h @@ -443,8 +443,7 @@ inline constexpr ::std::uint_least32_t days_per_4_year{365LL * 4LL + 1LL}; template <::std::signed_integral T> inline constexpr T sub_overflow(T a, T b) noexcept { -#if defined(__has_builtin) -#if __has_builtin(__builtin_sub_overflow) +#if FAST_IO_HAS_BUILTIN(__builtin_sub_overflow) T c; if (__builtin_sub_overflow(a, b, __builtin_addressof(c))) [[unlikely]] { @@ -469,23 +468,6 @@ inline constexpr T sub_overflow(T a, T b) noexcept } return a - b; #endif -#else - if (b <= 0) [[unlikely]] - { - if (a > ::std::numeric_limits::max() + b) [[unlikely]] - { - fast_terminate(); - } - } - else - { - if (a < ::std::numeric_limits::min() + b) [[unlikely]] - { - fast_terminate(); - } - } - return a - b; -#endif } #if __has_cpp_attribute(__gnu__::__pure__) @@ -637,14 +619,10 @@ inline constexpr ::std::uint_least8_t c_weekday_tb[]{0, 3, 2, 5, 0, 3, 5, 1, 4, inline constexpr ::std::uint_least8_t c_weekday_impl(::std::int_least64_t year, ::std::uint_least8_t month_minus1, ::std::uint_least8_t day) noexcept { -#if defined(__has_builtin) -#if __has_builtin(__builtin_unreachable) if (12u <= month_minus1) { - __builtin_unreachable(); + ::fast_io::unreachable(); } -#endif -#endif return static_cast<::std::uint_least8_t>( static_cast<::std::uint_least64_t>( static_cast<::std::uint_least64_t>(year) + static_cast<::std::uint_least64_t>(year / 4) - @@ -656,14 +634,10 @@ inline constexpr ::std::uint_least8_t c_weekday_impl(::std::int_least64_t year, inline constexpr ::std::uint_least8_t weekday_impl(::std::int_least64_t year, ::std::uint_least8_t month_minus1, ::std::uint_least8_t day) noexcept { -#if defined(__has_builtin) -#if __has_builtin(__builtin_unreachable) if (12u <= month_minus1) { - __builtin_unreachable(); + ::fast_io::unreachable(); } -#endif -#endif return static_cast<::std::uint_least8_t>( static_cast<::std::uint_least64_t>( static_cast<::std::uint_least64_t>(year) + static_cast<::std::uint_least64_t>(year / 4) - @@ -1576,11 +1550,7 @@ scan_iso8601_context_2_digits_phase(timestamp_scan_state_t &state, ch break; } default:; -#ifdef __has_builtin -#if __has_builtin(__builtin_unreachable) - __builtin_unreachable(); -#endif -#endif + ::fast_io::unreachable(); } return {begin, parse_code::ok}; } @@ -1842,11 +1812,7 @@ scn_ctx_define_iso8601_impl(timestamp_scan_state_t &state, char_type case scan_timestamp_context_phase::ok: return {begin, parse_code::ok}; } -#ifdef __has_builtin -#if __has_builtin(__builtin_unreachable) - __builtin_unreachable(); -#endif -#endif + ::fast_io::unreachable(); #undef FAST_IO_SCAN_ISO8601_CONTEXT_TOKEN_PHASE } diff --git a/include/fast_io_core_impl/secure_clear_guard.h b/include/fast_io_core_impl/secure_clear_guard.h index 0fcbfbc51..b4618df95 100644 --- a/include/fast_io_core_impl/secure_clear_guard.h +++ b/include/fast_io_core_impl/secure_clear_guard.h @@ -52,12 +52,8 @@ inline } else { -#if defined(__has_builtin) -#if __has_builtin(__builtin_memset) +#if FAST_IO_HAS_BUILTIN(__builtin_memset) __builtin_memset(data, 0, size); -#else - ::std::memset(data, 0, size); -#endif #else ::std::memset(data, 0, size); #endif @@ -138,12 +134,8 @@ inline constexpr ::std::byte *bytes_secure_clear_n(::std::byte *data, ::std::siz https://github.com/bminor/glibc/blob/master/string/explicit_bzero.c Referenced from glibc */ -#if defined(__has_builtin) -#if __has_builtin(__builtin_memset) +#if FAST_IO_HAS_BUILTIN(__builtin_memset) __builtin_memset(data, 0, size); -#else - ::std::memset(data, 0, size); -#endif #else ::std::memset(data, 0, size); #endif diff --git a/include/fast_io_core_impl/simd/gcc_clang.h b/include/fast_io_core_impl/simd/gcc_clang.h index b988164b8..934e49de8 100644 --- a/include/fast_io_core_impl/simd/gcc_clang.h +++ b/include/fast_io_core_impl/simd/gcc_clang.h @@ -14,7 +14,7 @@ inline constexpr bool simd_shuffle_size_is_supported(::std::size_t n) noexcept { if (n == 16) { -#if __has_builtin(__builtin_ia32_pshufb128) +#if FAST_IO_HAS_BUILTIN(__builtin_ia32_pshufb128) return true; #else return false; @@ -22,7 +22,7 @@ inline constexpr bool simd_shuffle_size_is_supported(::std::size_t n) noexcept } else if (n == 32) { -#if __has_builtin(__builtin_ia32_pshufb256) +#if FAST_IO_HAS_BUILTIN(__builtin_ia32_pshufb256) return true; #else return false; @@ -115,7 +115,7 @@ struct simd_vector template requires((sizeof(T2) == sizeof(T) * N) && ::std::is_trivially_copyable_v) inline -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) constexpr #endif void @@ -130,7 +130,7 @@ struct simd_vector { using unsigned_type = ::std::make_unsigned_t; using unsigned_vec_type = typename simd_vector::vec_type; -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) this->value = __builtin_bit_cast(vec_type, __builtin_bit_cast(unsigned_vec_type, this->value) + __builtin_bit_cast(unsigned_vec_type, b)); #else @@ -147,7 +147,7 @@ struct simd_vector template requires((sizeof(T2) == sizeof(T) * N) && ::std::is_trivially_copyable_v) inline -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) constexpr #endif void @@ -162,7 +162,7 @@ struct simd_vector { using unsigned_type = ::std::make_unsigned_t; using unsigned_vec_type = typename simd_vector::vec_type; -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) this->value = __builtin_bit_cast(vec_type, __builtin_bit_cast(unsigned_vec_type, this->value) - __builtin_bit_cast(unsigned_vec_type, b)); #else @@ -220,12 +220,12 @@ struct simd_vector template requires(sizeof(T1) * N1 == sizeof(T) * N && !::std::same_as) inline explicit -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) constexpr #endif operator simd_vector() const noexcept { -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) return __builtin_bit_cast(simd_vector, *this); #else simd_vector v; @@ -244,7 +244,7 @@ struct simd_vector return *this; } inline -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) constexpr #endif void @@ -259,14 +259,14 @@ struct simd_vector else if constexpr (N * sizeof(T) == 64) { using temp_vec_type [[__gnu__::__vector_size__(64)]] = char; -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) auto temp_vec{__builtin_bit_cast(temp_vec_type, this->value)}; #else temp_vec_type temp_vec; __builtin_memcpy(__builtin_addressof(temp_vec), __builtin_addressof(this->value), sizeof(vec_type)); #endif -#if __has_builtin(__builtin_shufflevector) +#if FAST_IO_HAS_BUILTIN(__builtin_shufflevector) if constexpr (sizeof(T) == 8) { // clang-format off @@ -294,7 +294,7 @@ struct simd_vector 48, 51, 50, 53, 52, 55, 54, 57, 56, 59, 58, 61, 60, 63, 62); // clang-format on } -#elif __has_builtin(__builtin_ia32_pshufb512) +#elif FAST_IO_HAS_BUILTIN(__builtin_ia32_pshufb512) if constexpr (sizeof(T) == 8) { // clang-format off @@ -326,7 +326,7 @@ struct simd_vector // clang-format on } #endif -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) this->value = __builtin_bit_cast(vec_type, temp_vec); #else __builtin_memcpy(__builtin_addressof(this->value), __builtin_addressof(temp_vec), sizeof(vec_type)); @@ -335,13 +335,13 @@ struct simd_vector else if constexpr (N * sizeof(T) == 32) { using temp_vec_type [[__gnu__::__vector_size__(32)]] = char; -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) auto temp_vec{__builtin_bit_cast(temp_vec_type, this->value)}; #else temp_vec_type temp_vec; __builtin_memcpy(__builtin_addressof(temp_vec), __builtin_addressof(this->value), sizeof(vec_type)); #endif -#if __has_builtin(__builtin_shufflevector) +#if FAST_IO_HAS_BUILTIN(__builtin_shufflevector) if constexpr (sizeof(T) == 8) { // clang-format off @@ -364,7 +364,7 @@ struct simd_vector 14, 17, 16, 19, 18, 21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30); // clang-format on } -#elif __has_builtin(__builtin_ia32_pshufb256) +#elif FAST_IO_HAS_BUILTIN(__builtin_ia32_pshufb256) if constexpr (sizeof(T) == 8) { // clang-format off @@ -390,7 +390,7 @@ struct simd_vector // clang-format on } #endif -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) this->value = __builtin_bit_cast(vec_type, temp_vec); #else __builtin_memcpy(__builtin_addressof(this->value), __builtin_addressof(temp_vec), sizeof(vec_type)); @@ -399,13 +399,13 @@ struct simd_vector else { using temp_vec_type [[__gnu__::__vector_size__(16)]] = char; -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) auto temp_vec{__builtin_bit_cast(temp_vec_type, this->value)}; #else temp_vec_type temp_vec; __builtin_memcpy(__builtin_addressof(temp_vec), __builtin_addressof(this->value), sizeof(vec_type)); #endif -#if __has_builtin(__builtin_shufflevector) && ((!defined(__x86_64__) && !defined(__i386__)) || \ +#if FAST_IO_HAS_BUILTIN(__builtin_shufflevector) && ((!defined(__x86_64__) && !defined(__i386__)) || \ (!defined(__GNUC__) || defined(__clang__)) || defined(__SSE4_2__)) if constexpr (sizeof(T) == 8) { @@ -428,7 +428,7 @@ struct simd_vector __builtin_shufflevector(temp_vec, temp_vec, 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14); // clang-format on } -#elif __has_builtin(__builtin_ia32_pshufb128) && defined(__SSE3__) +#elif FAST_IO_HAS_BUILTIN(__builtin_ia32_pshufb128) && defined(__SSE3__) if constexpr (sizeof(T) == 8) { // clang-format off @@ -450,7 +450,7 @@ struct simd_vector temp_vec = __builtin_ia32_pshufb128(temp_vec, mask); // clang-format on } -#elif defined(__SSE2__) && __has_builtin(__builtin_ia32_punpcklbw128) && __has_builtin(__builtin_ia32_punpckhbw128) +#elif defined(__SSE2__) && FAST_IO_HAS_BUILTIN(__builtin_ia32_punpcklbw128) && FAST_IO_HAS_BUILTIN(__builtin_ia32_punpckhbw128) using x86_64_v4si [[__gnu__::__vector_size__(16)]] = int; using x86_64_v16qi [[__gnu__::__vector_size__(16)]] = char; using x86_64_v8hi [[__gnu__::__vector_size__(16)]] = short; @@ -484,7 +484,7 @@ struct simd_vector temp_vec = (x86_64_v16qi)((res0 >> 8) | (res0 << 8)); } #endif -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) this->value = __builtin_bit_cast(vec_type, temp_vec); #else __builtin_memcpy(__builtin_addressof(this->value), __builtin_addressof(temp_vec), sizeof(vec_type)); @@ -498,9 +498,9 @@ struct simd_vector { if constexpr (sizeof(mask) == 16) { -#if __has_builtin(__builtin_ia32_pshufb128) +#if FAST_IO_HAS_BUILTIN(__builtin_ia32_pshufb128) using value_type2 [[__gnu__::__vector_size__(16)]] = char; -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) value = __builtin_bit_cast(vec_type, __builtin_ia32_pshufb128(__builtin_bit_cast(value_type2, value), mask.value)); #else @@ -513,9 +513,9 @@ struct simd_vector } else if constexpr (sizeof(mask) == 32) { -#if __has_builtin(__builtin_ia32_pshufb256) +#if FAST_IO_HAS_BUILTIN(__builtin_ia32_pshufb256) using value_type2 [[__gnu__::__vector_size__(32)]] = char; -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) value = __builtin_bit_cast(vec_type, __builtin_ia32_pshufb256(__builtin_bit_cast(value_type2, value), mask.value)); #else @@ -633,7 +633,7 @@ inline constexpr simd_vector operator!=(simd_vector const &a, simd_v template <::std::integral T, ::std::size_t N> inline -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) constexpr #endif simd_vector @@ -643,7 +643,7 @@ inline { using unsigned_type = ::std::make_unsigned_t; using vec_type = typename simd_vector::vec_type; -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) return __builtin_bit_cast(simd_vector, __builtin_bit_cast(vec_type, a) + __builtin_bit_cast(vec_type, b)); #else vec_type asv; @@ -664,7 +664,7 @@ inline template <::std::integral T, ::std::size_t N> inline -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) constexpr #endif simd_vector @@ -674,7 +674,7 @@ inline { using unsigned_type = ::std::make_unsigned_t; using vec_type = typename simd_vector::vec_type; -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) return __builtin_bit_cast(simd_vector, __builtin_bit_cast(vec_type, a) - __builtin_bit_cast(vec_type, b)); #else vec_type asv; diff --git a/include/fast_io_core_impl/simd/generic.h b/include/fast_io_core_impl/simd/generic.h index c656413e0..c2931e025 100644 --- a/include/fast_io_core_impl/simd/generic.h +++ b/include/fast_io_core_impl/simd/generic.h @@ -36,12 +36,8 @@ struct #endif inline void load(void const *address) noexcept { -#if defined(__has_builtin) -#if __has_builtin(__builtin_memcpy) +#if FAST_IO_HAS_BUILTIN(__builtin_memcpy) __builtin_memcpy(__builtin_addressof(value), address, sizeof(value)); -#else - ::std::memcpy(__builtin_addressof(value), address, sizeof(value)); -#endif #else ::std::memcpy(__builtin_addressof(value), address, sizeof(value)); #endif @@ -55,12 +51,8 @@ struct #endif inline void store(void *address) noexcept { -#if defined(__has_builtin) -#if __has_builtin(__builtin_memcpy) +#if FAST_IO_HAS_BUILTIN(__builtin_memcpy) __builtin_memcpy(address, __builtin_addressof(value), sizeof(value)); -#else - ::std::memcpy(address, __builtin_addressof(value), sizeof(value)); -#endif #else ::std::memcpy(address, __builtin_addressof(value), sizeof(value)); #endif diff --git a/include/fast_io_core_impl/socket/addrscn.h b/include/fast_io_core_impl/socket/addrscn.h index e1126c909..9858cc996 100644 --- a/include/fast_io_core_impl/socket/addrscn.h +++ b/include/fast_io_core_impl/socket/addrscn.h @@ -268,11 +268,7 @@ scn_ctx_define_inaddr_impl(ipv4_scan_state_t &state, char_type const return {begin, parse_code::ok}; } } -#ifdef __has_builtin -#if __has_builtin(__builtin_unreachable) - __builtin_unreachable(); -#endif -#endif + ::fast_io::unreachable(); } template <::std::integral char_type> @@ -317,11 +313,7 @@ inline constexpr parse_result scn_ctx_define_port_impl(ip_por } return scan_context_define_parse_impl<10, true, false, false>(state, begin, end, t); default:; -#ifdef __has_builtin -#if __has_builtin(__builtin_unreachable) - __builtin_unreachable(); -#endif -#endif + ::fast_io::unreachable(); } } @@ -844,11 +836,7 @@ scan_context_define(::fast_io::io_reserve_type_tport)}; } #endif -#ifdef __has_builtin -#if __has_builtin(__builtin_unreachable) - __builtin_unreachable(); -#endif -#endif + ::fast_io::unreachable(); } } diff --git a/include/fast_io_core_impl/terminate.h b/include/fast_io_core_impl/terminate.h index c0c87839f..6df2e6855 100644 --- a/include/fast_io_core_impl/terminate.h +++ b/include/fast_io_core_impl/terminate.h @@ -15,17 +15,13 @@ namespace fast_io fast_terminate() noexcept { // https://llvm.org/doxygen/Compiler_8h_source.html -#if defined(__has_builtin) -#if __has_builtin(__builtin_trap) +#if FAST_IO_HAS_BUILTIN(__builtin_trap) __builtin_trap(); -#elif __has_builtin(__builtin_abort) +#elif FAST_IO_HAS_BUILTIN(__builtin_abort) __builtin_abort(); #else ::std::abort(); #endif -#else - ::std::abort(); -#endif } #if __has_cpp_attribute(__gnu__::__always_inline__) diff --git a/include/fast_io_core_impl/timestamp_counter.h b/include/fast_io_core_impl/timestamp_counter.h index bd96b63ee..eb0e15ae7 100644 --- a/include/fast_io_core_impl/timestamp_counter.h +++ b/include/fast_io_core_impl/timestamp_counter.h @@ -5,12 +5,8 @@ namespace fast_io inline auto current_processor_timestamp_counter() noexcept { -#if defined(__has_builtin) -#if __has_builtin(__builtin_ia32_rdtsc) +#if FAST_IO_HAS_BUILTIN(__builtin_ia32_rdtsc) return __builtin_ia32_rdtsc(); -#else - return static_cast<::std::uint_least64_t>(0); -#endif #elif defined(_MSC_VER) && defined(_M_IX86) return __rdtsc(); #else diff --git a/include/fast_io_core_impl/utils.h b/include/fast_io_core_impl/utils.h index c26461af5..49db8400c 100644 --- a/include/fast_io_core_impl/utils.h +++ b/include/fast_io_core_impl/utils.h @@ -21,12 +21,8 @@ inline return ::std::bit_cast(src); #else To dst; -#if defined(__has_builtin) -#if __has_builtin(__builtin_memcpy) +#if FAST_IO_HAS_BUILTIN(__builtin_memcpy) __builtin_memcpy -#else - ::std::memcpy -#endif #else ::std::memcpy #endif @@ -247,7 +243,7 @@ inline constexpr U byte_swap(U a) noexcept #if (defined(__GNUC__) || defined(__clang__)) #ifdef __SIZEOF_INT128__ if constexpr (sizeof(U) == 16) -#if __has_builtin(__builtin_bswap128) +#if FAST_IO_HAS_BUILTIN(__builtin_bswap128) return __builtin_bswap128(a); #else { diff --git a/include/fast_io_crypto/hash/crc32.h b/include/fast_io_crypto/hash/crc32.h index 3cf22fc3e..656805074 100644 --- a/include/fast_io_crypto/hash/crc32.h +++ b/include/fast_io_crypto/hash/crc32.h @@ -109,7 +109,7 @@ inline constexpr ::std::uint_least32_t crc32c_tb[256]{ // clang-format on inline constexpr bool support_hardware_crc32{ -#if defined(__ARM_FEATURE_CRC32) && __has_builtin(__builtin_arm_crc32b) +#if defined(__ARM_FEATURE_CRC32) && FAST_IO_HAS_BUILTIN(__builtin_arm_crc32b) true #endif }; @@ -119,7 +119,7 @@ inline constexpr ::std::uint_least32_t calculate_crc32_hardware(::std::uint_leas { for (; i != ed; ++i) { -#if defined(__ARM_FEATURE_CRC32) && __has_builtin(__builtin_arm_crc32b) +#if defined(__ARM_FEATURE_CRC32) && FAST_IO_HAS_BUILTIN(__builtin_arm_crc32b) crc = __builtin_arm_crc32b(crc, static_cast<::std::uint_least8_t>(*i)); #else crc = crc32_tb[(static_cast<::std::uint_least32_t>(*i) ^ crc) & 0xff] ^ (crc >> 8); @@ -129,8 +129,8 @@ inline constexpr ::std::uint_least32_t calculate_crc32_hardware(::std::uint_leas } inline constexpr bool support_hardware_crc32c{ -#if defined(__CRC32__) && __has_builtin(__builtin_ia32_crc32qi) || \ - defined(__ARM_FEATURE_CRC32) && __has_builtin(__builtin_arm_crc32cb) || \ +#if defined(__CRC32__) && FAST_IO_HAS_BUILTIN(__builtin_ia32_crc32qi) || \ + defined(__ARM_FEATURE_CRC32) && FAST_IO_HAS_BUILTIN(__builtin_arm_crc32cb) || \ ((defined(_MSC_VER) && !defined(__clang__)) && !(!defined(_M_IX86) && !defined(_M_X64) && !(defined(_M_ARM64) && defined(USE_SOFT_INTRINSICS)))) true #endif @@ -141,9 +141,9 @@ inline constexpr ::std::uint_least32_t calculate_crc32c_hardware(::std::uint_lea { for (; i != ed; ++i) { -#if defined(__CRC32__) && __has_builtin(__builtin_ia32_crc32qi) +#if defined(__CRC32__) && FAST_IO_HAS_BUILTIN(__builtin_ia32_crc32qi) crc = __builtin_ia32_crc32qi(crc, static_cast<::std::uint_least8_t>(*i)); -#elif defined(__ARM_FEATURE_CRC32) && __has_builtin(__builtin_arm_crc32cb) +#elif defined(__ARM_FEATURE_CRC32) && FAST_IO_HAS_BUILTIN(__builtin_arm_crc32cb) crc = __builtin_arm_crc32cb(crc, static_cast<::std::uint_least8_t>(*i)); #elif (defined(_MSC_VER) && !defined(__clang__)) && !(!defined(_M_IX86) && !defined(_M_X64) && !(defined(_M_ARM64) && defined(USE_SOFT_INTRINSICS))) crc = ::_mm_crc32_u8(crc, static_cast<::std::uint_least8_t>(*i)); diff --git a/include/fast_io_crypto/hash/md5_sha_hash_context.h b/include/fast_io_crypto/hash/md5_sha_hash_context.h index a08f4d86a..7c6ebe0ad 100644 --- a/include/fast_io_crypto/hash/md5_sha_hash_context.h +++ b/include/fast_io_crypto/hash/md5_sha_hash_context.h @@ -114,14 +114,10 @@ struct md5_sha_common_impl ::std::size_t const buffer_remain_space{static_cast<::std::size_t>(block_size - buffer_offset)}; if (diff < buffer_remain_space) [[likely]] { -#if defined(__has_builtin) -#if __has_builtin(__builtin_unreachable) if (diff >= block_size) { - __builtin_unreachable(); + ::fast_io::unreachable(); } -#endif -#endif ::fast_io::details::non_overlapped_copy_n(block_first, diff, buffer + buffer_offset); buffer_offset += diff; } @@ -147,27 +143,19 @@ struct md5_sha_common_impl if (buffer_off <= sz) { ::std::size_t const to_fill{static_cast<::std::size_t>(sz - buffer_off)}; -#if defined(__has_builtin) -#if __has_builtin(__builtin_unreachable) if (to_fill > sz) { - __builtin_unreachable(); + ::fast_io::unreachable(); } -#endif -#endif ::fast_io::none_secure_clear(this->buffer + buffer_off, to_fill); this->append_sentinal(buffer_offs); return; } ::std::size_t const to_fill{static_cast<::std::size_t>(block_size - buffer_off)}; -#if defined(__has_builtin) -#if __has_builtin(__builtin_unreachable) if (to_fill > counter_type_size) { - __builtin_unreachable(); + ::fast_io::unreachable(); } -#endif -#endif ::fast_io::none_secure_clear(this->buffer + buffer_off, to_fill); this->hasher.update_blocks(this->buffer, this->buffer + block_size); ::fast_io::none_secure_clear(this->buffer, sz); diff --git a/include/fast_io_crypto/hash/sha256.h b/include/fast_io_crypto/hash/sha256.h index 118017223..7acb4569e 100644 --- a/include/fast_io_crypto/hash/sha256.h +++ b/include/fast_io_crypto/hash/sha256.h @@ -152,9 +152,9 @@ inline !defined(__clang__) && defined(__ELF__) && defined(FAST_IO_RUNTIME_DISPATCH) #include "sha256_x86_sha_extensions.h" #include "sha256_simd16.h" -#elif __has_builtin(__builtin_ia32_sha256rnds2) && __has_builtin(__builtin_ia32_pshufd) && \ - __has_builtin(__builtin_ia32_palignr128) && __has_builtin(__builtin_ia32_sha256msg1) && \ - __has_builtin(__builtin_ia32_sha256msg2) && __has_builtin(__builtin_ia32_pshufb128) && \ +#elif FAST_IO_HAS_BUILTIN(__builtin_ia32_sha256rnds2) && FAST_IO_HAS_BUILTIN(__builtin_ia32_pshufd) && \ + FAST_IO_HAS_BUILTIN(__builtin_ia32_palignr128) && FAST_IO_HAS_BUILTIN(__builtin_ia32_sha256msg1) && \ + FAST_IO_HAS_BUILTIN(__builtin_ia32_sha256msg2) && FAST_IO_HAS_BUILTIN(__builtin_ia32_pshufb128) && \ (!defined(__clang__) || (defined(__SSE4_2__) && defined(__SHA__))) #include "sha256_x86_sha_extensions.h" #elif defined(__SSE2__) || defined(__wasm_simd128__) diff --git a/include/fast_io_crypto/hash/sha512.h b/include/fast_io_crypto/hash/sha512.h index 21209a49b..041d38af1 100644 --- a/include/fast_io_crypto/hash/sha512.h +++ b/include/fast_io_crypto/hash/sha512.h @@ -168,11 +168,11 @@ inline constexpr void sha512_do_constexpr_function(::std::uint_least64_t *__rest #include "sha512_scalar.h" #else #if !(defined(_MSC_VER) && !defined(__clang__)) -#if defined(__SSE2__) && !defined(__AVX2__) && __has_builtin(__builtin_shufflevector) && \ +#if defined(__SSE2__) && !defined(__AVX2__) && FAST_IO_HAS_BUILTIN(__builtin_shufflevector) && \ __has_cpp_attribute(__gnu__::__target__) && defined(__ELF__) && defined(FAST_IO_RUNTIME_DISPATCH) #include "sha512_simd32_shuffle.h" #include "sha512_simd16.h" -#elif defined(__AVX2__) && __has_builtin(__builtin_shufflevector) +#elif defined(__AVX2__) && FAST_IO_HAS_BUILTIN(__builtin_shufflevector) #include "sha512_simd32_shuffle.h" #elif defined(__SSE2__) #include "sha512_simd16.h" diff --git a/include/fast_io_crypto/hash/sha512_simd16.h b/include/fast_io_crypto/hash/sha512_simd16.h index e05f2aeaa..446bf75c8 100644 --- a/include/fast_io_crypto/hash/sha512_simd16.h +++ b/include/fast_io_crypto/hash/sha512_simd16.h @@ -62,13 +62,11 @@ sha512_simd16_compute_message_2rounds(::fast_io::intrinsics::simd_vector<::std:: s0.store(wt); } -#if defined(__has_builtin) -#if __has_cpp_attribute(__gnu__::__target__) && __has_builtin(__builtin_shufflevector) && defined(__SSE2__) && \ +#if __has_cpp_attribute(__gnu__::__target__) && FAST_IO_HAS_BUILTIN(__builtin_shufflevector) && defined(__SSE2__) && \ !defined(__AVX2__) && defined(__ELF__) && defined(FAST_IO_RUNTIME_DISPATCH) [[__gnu__::__target__("default")]] #elif __has_cpp_attribute(__gnu__::__flatten__) [[__gnu__::__flatten__]] -#endif #elif __has_cpp_attribute(msvc::flatten) [[msvc::flatten]] #endif diff --git a/include/fast_io_crypto/hash/sha512_simd32.h b/include/fast_io_crypto/hash/sha512_simd32.h index d7af3e708..546fb9f27 100644 --- a/include/fast_io_crypto/hash/sha512_simd32.h +++ b/include/fast_io_crypto/hash/sha512_simd32.h @@ -73,7 +73,7 @@ sha512_simd32_compute_message_4rounds(::fast_io::intrinsics::simd_vector<::std:: s0.store(wt); } -#if __has_cpp_attribute(__gnu__::__target__) && __has_builtin(__builtin_shufflevector) && defined(__SSE2__) && \ +#if __has_cpp_attribute(__gnu__::__target__) && FAST_IO_HAS_BUILTIN(__builtin_shufflevector) && defined(__SSE2__) && \ !defined(__AVX2__) && defined(__ELF__) [[__gnu__::__target__("avx2")]] #elif __has_cpp_attribute(__gnu__::__flatten__) diff --git a/include/fast_io_crypto/hash/sha512_simd32_shuffle.h b/include/fast_io_crypto/hash/sha512_simd32_shuffle.h index 691d6fe67..b2f7c3152 100644 --- a/include/fast_io_crypto/hash/sha512_simd32_shuffle.h +++ b/include/fast_io_crypto/hash/sha512_simd32_shuffle.h @@ -337,7 +337,7 @@ inline void sha512_simd32_compute_message_4rounds( } } -#if __has_cpp_attribute(__gnu__::__target__) && __has_builtin(__builtin_shufflevector) && defined(__SSE2__) && \ +#if __has_cpp_attribute(__gnu__::__target__) && FAST_IO_HAS_BUILTIN(__builtin_shufflevector) && defined(__SSE2__) && \ !defined(__AVX2__) && defined(__ELF__) && defined(FAST_IO_RUNTIME_DISPATCH) [[__gnu__::__target__("avx2")]] #elif __has_cpp_attribute(__gnu__::__flatten__) diff --git a/include/fast_io_crypto/streamcipher/chacha/impl.h b/include/fast_io_crypto/streamcipher/chacha/impl.h index 9bdd75f63..7bccaec90 100644 --- a/include/fast_io_crypto/streamcipher/chacha/impl.h +++ b/include/fast_io_crypto/streamcipher/chacha/impl.h @@ -2,7 +2,7 @@ #include "scalar.h" #if (defined(__GNUC__) || defined(__clang__)) && (defined(__SSE__) || defined(__wasm_simd128__)) -#if __has_builtin(__builtin_shufflevector) +#if FAST_IO_HAS_BUILTIN(__builtin_shufflevector) #include "simd16.h" #else #include "runtime.h" diff --git a/include/fast_io_driver/tsc_timer.h b/include/fast_io_driver/tsc_timer.h index cad2da265..233adbb08 100644 --- a/include/fast_io_driver/tsc_timer.h +++ b/include/fast_io_driver/tsc_timer.h @@ -7,7 +7,7 @@ inline ::std::uint_least64_t current_tsc() noexcept { #if defined(_MSC_VER) && !defined(__clang__) return __rdtsc(); -#elif __has_builtin(__builtin_ia32_rdtsc) +#elif FAST_IO_HAS_BUILTIN(__builtin_ia32_rdtsc) return __builtin_ia32_rdtsc(); #else return 0; diff --git a/include/fast_io_dsal/impl/freestanding.h b/include/fast_io_dsal/impl/freestanding.h index 88982ef12..68c7dbedb 100644 --- a/include/fast_io_dsal/impl/freestanding.h +++ b/include/fast_io_dsal/impl/freestanding.h @@ -287,12 +287,8 @@ inline constexpr Iter uninitialized_fill(Iter first, Iter last, T const &ele) if (!__builtin_is_constant_evaluated()) #endif { -#ifdef __has_builtin -#if __has_builtin(__builtin_memset) +#if FAST_IO_HAS_BUILTIN(__builtin_memset) __builtin_memset -#else - ::std::memset -#endif #else ::std::memset #endif diff --git a/include/fast_io_dsal/impl/misc/pop_macros.h b/include/fast_io_dsal/impl/misc/pop_macros.h index d44ba4729..6f8008b82 100644 --- a/include/fast_io_dsal/impl/misc/pop_macros.h +++ b/include/fast_io_dsal/impl/misc/pop_macros.h @@ -1,5 +1,6 @@ // Please keep it in reverse order with the macros in push_macros.h +#pragma pop_macro("FAST_IO_HAS_BUILTIN") #pragma pop_macro("FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE") #pragma pop_macro("FAST_IO_ASSERT") #pragma pop_macro("FAST_IO_GNU_RETURNS_NONNULL") diff --git a/include/fast_io_dsal/impl/misc/push_macros.h b/include/fast_io_dsal/impl/misc/push_macros.h index f9a229f50..b555a5792 100644 --- a/include/fast_io_dsal/impl/misc/push_macros.h +++ b/include/fast_io_dsal/impl/misc/push_macros.h @@ -215,4 +215,12 @@ Internal assert macros for fuzzing fast_io. #define FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE trivially_relocatable_if_eligible #else #define FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE -#endif \ No newline at end of file +#endif + +#pragma push_macro("FAST_IO_HAS_BUILTIN") +#undef FAST_IO_HAS_BUILTIN +#ifdef __has_builtin +# define FAST_IO_HAS_BUILTIN(...) __has_builtin(__VA_ARGS__) +#else +# define FAST_IO_HAS_BUILTIN(...) 0 +#endif diff --git a/include/fast_io_freestanding_impl/serializations/lebe.h b/include/fast_io_freestanding_impl/serializations/lebe.h index 521e22d51..8c0e0a3f6 100644 --- a/include/fast_io_freestanding_impl/serializations/lebe.h +++ b/include/fast_io_freestanding_impl/serializations/lebe.h @@ -328,9 +328,7 @@ inline } #if __cpp_lib_bit_cast >= 201806L t = ::std::bit_cast(buffer); -#elif !defined(__has_builtin) - ::std::memcpy(__builtin_addressof(t), buffer, n); -#elif __has_builtin(__builtin_memcpy) +#elif FAST_IO_HAS_BUILTIN(__builtin_memcpy) __builtin_memcpy(__builtin_addressof(t), buffer, n); #else ::std::memcpy(__builtin_addressof(t), buffer, n); @@ -375,9 +373,7 @@ inline else #endif { -#if !defined(__has_builtin) - ::std::memcpy(__builtin_addressof(t), iter, sizeof(int_type)); -#elif __has_builtin(__builtin_memcpy) +#if FAST_IO_HAS_BUILTIN(__builtin_memcpy) __builtin_memcpy(__builtin_addressof(t), iter, sizeof(int_type)); #else ::std::memcpy(__builtin_addressof(t), iter, sizeof(int_type)); @@ -566,9 +562,7 @@ inline } else { -#if !defined(__has_builtin) - ::std::memcpy(iter, __builtin_addressof(u), n); -#elif __has_builtin(__builtin_memcpy) +#if FAST_IO_HAS_BUILTIN(__builtin_memcpy) __builtin_memcpy(iter, __builtin_addressof(u), n); #else ::std::memcpy(iter, __builtin_addressof(u), n); diff --git a/include/fast_io_hosted/file_loaders/allocation_file_loader.h b/include/fast_io_hosted/file_loaders/allocation_file_loader.h index b96a94772..253224245 100644 --- a/include/fast_io_hosted/file_loaders/allocation_file_loader.h +++ b/include/fast_io_hosted/file_loaders/allocation_file_loader.h @@ -26,12 +26,8 @@ struct allocation_file_loader_closer_impl ::fast_io::noexcept_call(::close, fd); #endif } -#if defined(__has_builtin) -#if __has_builtin(__builtin_free) +#if FAST_IO_HAS_BUILTIN(__builtin_free) __builtin_free(address_begin); -#else - ::std::free(address_begin); -#endif #else ::std::free(address_begin); #endif @@ -105,12 +101,8 @@ struct load_file_allocation_guard inline explicit constexpr load_file_allocation_guard() noexcept = default; inline explicit load_file_allocation_guard(::std::size_t file_size) : address( -#if defined(__has_builtin) -#if __has_builtin(__builtin_malloc) +#if FAST_IO_HAS_BUILTIN(__builtin_malloc) __builtin_malloc -#else - ::std::malloc -#endif #else ::std::malloc #endif @@ -125,12 +117,8 @@ struct load_file_allocation_guard inline load_file_allocation_guard &operator=(load_file_allocation_guard const &) = delete; inline ~load_file_allocation_guard() { -#if defined(__has_builtin) -#if __has_builtin(__builtin_free) +#if FAST_IO_HAS_BUILTIN(__builtin_free) __builtin_free(address); -#else - ::std::free(address); -#endif #else ::std::free(address); #endif diff --git a/include/fast_io_hosted/file_loaders/file_size.h b/include/fast_io_hosted/file_loaders/file_size.h index 080c3ec62..f997264db 100644 --- a/include/fast_io_hosted/file_loaders/file_size.h +++ b/include/fast_io_hosted/file_loaders/file_size.h @@ -1,10 +1,6 @@ #pragma once -#if defined(__has_builtin) -#if !__has_builtin(__builtin_malloc) || !__has_builtin(__builtin_free) -#include -#endif -#elif !defined(_MSC_VER) +#if !FAST_IO_HAS_BUILTIN(__builtin_malloc) || !FAST_IO_HAS_BUILTIN(__builtin_free) || !defined(_MSC_VER) #include #endif namespace fast_io diff --git a/include/fast_io_hosted/platforms/linux/amd64.h b/include/fast_io_hosted/platforms/linux/amd64.h index 469d04c06..c20773390 100644 --- a/include/fast_io_hosted/platforms/linux/amd64.h +++ b/include/fast_io_hosted/platforms/linux/amd64.h @@ -117,6 +117,5 @@ template <::std::integral I> inline void fast_exit(I ret) noexcept { system_call_no_return<__NR_exit>(ret); - __builtin_unreachable(); } } // namespace fast_io diff --git a/include/fast_io_hosted/timeutil/environ_timezone.h b/include/fast_io_hosted/timeutil/environ_timezone.h index e7a600667..f848d82f4 100644 --- a/include/fast_io_hosted/timeutil/environ_timezone.h +++ b/include/fast_io_hosted/timeutil/environ_timezone.h @@ -20,12 +20,8 @@ namespace details inline environ_timezone_name environ_localtimezone_impl() noexcept { auto ptr{reinterpret_cast<::fast_io::environ_timezone_name::char8_const_may_alias_ptr>( -#if !defined(__has_builtin) -#if __has_builtin(__builtin_getenv) +#if FAST_IO_HAS_BUILTIN(__builtin_getenv) __builtin_getenv -#else - ::std::getenv -#endif #else ::std::getenv #endif diff --git a/include/fast_io_i18n/locale/posix.h b/include/fast_io_i18n/locale/posix.h index 79ebcc5a0..1ad364c64 100644 --- a/include/fast_io_i18n/locale/posix.h +++ b/include/fast_io_i18n/locale/posix.h @@ -52,12 +52,8 @@ inline void *posix_load_l10n_common_impl(char8_t const *cstr, ::std::size_t n, l } cstr = reinterpret_cast(lc_all_env); n = -#if defined(__has_builtin) -#if __has_builtin(__builtin_strlen) +#if FAST_IO_HAS_BUILTIN(__builtin_strlen) __builtin_strlen(lc_all_env); -#else - ::std::strlen(lc_all_env); -#endif #else ::std::strlen(lc_all_env); #endif diff --git a/include/fast_io_legacy_impl/c/done.h b/include/fast_io_legacy_impl/c/done.h index f4b823995..3e01c9fc9 100644 --- a/include/fast_io_legacy_impl/c/done.h +++ b/include/fast_io_legacy_impl/c/done.h @@ -59,21 +59,13 @@ inline ::std::size_t c_fwrite_unlocked_impl(void const *__restrict begin, ::std: #if defined(__CYGWIN__) my_cygwin_fwrite_unlocked(begin, type_size, count, fp) #elif (defined(__USE_MISC) || defined(__BSD_VISIBLE)) && (!defined(__BIONIC__) || (defined(__USE_BSD))) -#if !defined(fwrite_unlocked) && defined(__has_builtin) -#if __has_builtin(__builtin_fwrite_unlocked) +#if !defined(fwrite_unlocked) && FAST_IO_HAS_BUILTIN(__builtin_fwrite_unlocked) __builtin_fwrite_unlocked(begin, type_size, count, fp) #else fwrite_unlocked(begin, type_size, count, fp) #endif -#else - fwrite_unlocked(begin, type_size, count, fp) -#endif -#elif !defined(fwrite) && defined(__has_builtin) -#if __has_builtin(__builtin_fwrite) +#elif !defined(fwrite) && FAST_IO_HAS_BUILTIN(__builtin_fwrite) __builtin_fwrite(begin, type_size, count, fp) -#else - fwrite(begin, type_size, count, fp) -#endif #else fwrite(begin, type_size, count, fp) #endif @@ -114,21 +106,14 @@ inline ::std::size_t c_fread_unlocked_impl(void *__restrict begin, ::std::size_t #if defined(__CYGWIN__) my_cygwin_fread_unlocked(begin, type_size, count, fp) #elif (defined(__USE_MISC) || defined(__BSD_VISIBLE)) && (!defined(__BIONIC__) || (defined(__USE_BSD))) -#if !defined(fread_unlocked) && defined(__has_builtin) -#if __has_builtin(__builtin_fread_unlocked) +#if !defined(fread_unlocked) && FAST_IO_HAS_BUILTIN(__builtin_fread_unlocked) __builtin_fread_unlocked(begin, type_size, count, fp) #else fread_unlocked(begin, type_size, count, fp) #endif -#else - fread_unlocked(begin, type_size, count, fp) -#endif -#elif !defined(fread) && defined(__has_builtin) -#if __has_builtin(__builtin_fread) + +#elif !defined(fread) && FAST_IO_HAS_BUILTIN(__builtin_fread) __builtin_fread(begin, type_size, count, fp) -#else - fread(begin, type_size, count, fp) -#endif #else fread(begin, type_size, count, fp) #endif @@ -139,21 +124,13 @@ inline ::std::size_t c_fread_unlocked_impl(void *__restrict begin, ::std::size_t #if defined(__CYGWIN__) __sferror(fp) #elif defined(__USE_MISC) || defined(__BSD_VISIBLE) || defined(__DARWIN_C_LEVEL) -#if defined(__has_builtin) -#if __has_builtin(__builtin_ferror_unlocked) +#if FAST_IO_HAS_BUILTIN(__builtin_ferror_unlocked) __builtin_ferror_unlocked(fp) #else ferror_unlocked(fp) #endif -#else - ferror_unlocked(fp) -#endif -#elif !defined(ferror) && defined(__has_builtin) -#if __has_builtin(__builtin_ferror) +#elif !defined(ferror) && FAST_IO_HAS_BUILTIN(__builtin_ferror) __builtin_ferror(fp) -#else - ferror(fp) -#endif #else ferror(fp) #endif @@ -181,12 +158,8 @@ inline ::std::size_t c_fwrite_impl(void const *__restrict begin, ::std::size_t t #else ::std::size_t written_count{ -#if !defined(fwrite) && defined(__has_builtin) -#if __has_builtin(__builtin_fwrite) +#if !defined(fwrite) && FAST_IO_HAS_BUILTIN(__builtin_fwrite) __builtin_fwrite(begin, type_size, count, fp) -#else - fwrite(begin, type_size, count, fp) -#endif #else fwrite(begin, type_size, count, fp) #endif @@ -218,12 +191,8 @@ inline ::std::size_t c_fread_impl(void *__restrict begin, ::std::size_t type_siz } #else ::std::size_t read_count{ -#if !defined(fread) && defined(__has_builtin) -#if __has_builtin(__builtin_fread) +#if !defined(fread) && FAST_IO_HAS_BUILTIN(__builtin_fread) __builtin_fread(begin, type_size, count, fp) -#else - fread(begin, type_size, count, fp) -#endif #else fread(begin, type_size, count, fp) #endif @@ -231,12 +200,8 @@ inline ::std::size_t c_fread_impl(void *__restrict begin, ::std::size_t type_siz if (read_count == 0) [[unlikely]] { if ( -#if !defined(ferror) && defined(__has_builtin) -#if __has_builtin(__builtin_ferror) +#if !defined(ferror) && FAST_IO_HAS_BUILTIN(__builtin_ferror) __builtin_ferror(fp) -#else - ferror(fp) -#endif #else ferror(fp) #endif diff --git a/include/fast_io_legacy_impl/c/impl.h b/include/fast_io_legacy_impl/c/impl.h index 346688d67..0c6a1f63b 100644 --- a/include/fast_io_legacy_impl/c/impl.h +++ b/include/fast_io_legacy_impl/c/impl.h @@ -324,12 +324,8 @@ inline int my_fclose_impl(FILE *fp) noexcept { if constexpr (family == c_family::standard || family == c_family::emulated) { -#ifdef __has_builtin -#if __has_builtin(__builtin_fclose) +#if FAST_IO_HAS_BUILTIN(__builtin_fclose) return __builtin_fclose(fp); -#else - return fclose(fp); -#endif #else return fclose(fp); #endif @@ -339,15 +335,11 @@ inline int my_fclose_impl(FILE *fp) noexcept #if defined(_MSC_VER) || defined(_UCRT) return noexcept_call(_fclose_nolock, fp); #else -#ifdef __has_builtin -#if __has_builtin(__builtin_fclose) +#if FAST_IO_HAS_BUILTIN(__builtin_fclose) return __builtin_fclose(fp); #else return fclose(fp); #endif -#else - return fclose(fp); -#endif #endif } } @@ -439,12 +431,8 @@ inline void my_c_io_flush_impl(FILE *fp) #else if constexpr (family == c_family::standard) { -#if defined(__has_builtin) -#if __has_builtin(__builtin_fflush) +#if FAST_IO_HAS_BUILTIN(__builtin_fflush) if (__builtin_fflush(fp)) -#else - if (fflush(fp)) -#endif #else if (fflush(fp)) #endif @@ -574,12 +562,8 @@ inline ::fast_io::intfpos_t my_c_io_seek_impl(FILE *fp, ::fast_io::intfpos_t off _fseeki64(fp, offset, static_cast(s)) #elif defined(__USE_LARGEFILE64) noexcept_call(fseeko64, fp, offset, static_cast(s)) -#elif defined(__has_builtin) -#if __has_builtin(__builtin_fseeko) +#elif FAST_IO_HAS_BUILTIN(__builtin_fseeko) __builtin_fseeko(fp, offset, static_cast(s)) -#else - fseeko(fp, offset, static_cast(s)) -#endif #else fseeko(fp, offset, static_cast(s)) #endif @@ -590,12 +574,8 @@ inline ::fast_io::intfpos_t my_c_io_seek_impl(FILE *fp, ::fast_io::intfpos_t off noexcept_call(_ftelli64, fp) #elif defined(__USE_LARGEFILE64) noexcept_call(ftello64, fp) -#elif defined(__has_builtin) -#if __has_builtin(__builtin_ftello) +#elif FAST_IO_HAS_BUILTIN(__builtin_ftello) __builtin_ftello(fp) -#else - ftello(fp) -#endif #else ftello(fp) #endif diff --git a/include/fast_io_legacy_impl/c/wincrt.h b/include/fast_io_legacy_impl/c/wincrt.h index 066e64740..fe992673c 100644 --- a/include/fast_io_legacy_impl/c/wincrt.h +++ b/include/fast_io_legacy_impl/c/wincrt.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once namespace fast_io { @@ -569,4 +569,4 @@ inline u32c_io_observer u32c_stderr() noexcept return {::fast_io::win32::wincrt_acrt_iob_func(2)}; } -} // namespace fast_io +} // namespace fast_io \ No newline at end of file diff --git a/include/fast_io_legacy_impl/filebuf/rtti_hack/impl.h b/include/fast_io_legacy_impl/filebuf/rtti_hack/impl.h index 2fd9ac227..87af3c259 100644 --- a/include/fast_io_legacy_impl/filebuf/rtti_hack/impl.h +++ b/include/fast_io_legacy_impl/filebuf/rtti_hack/impl.h @@ -86,12 +86,8 @@ inline constexpr bool symbol_cmp_equal_commom(char8_t const *sym, char const *st } else { -#ifdef __has_builtin -#if __has_builtin(__builtin_memcmp) +#if FAST_IO_HAS_BUILTIN(__builtin_memcmp) return __builtin_memcmp(sym, strp, N) == 0; -#else - return ::std::memcmp(sym, strp, N) == 0; -#endif #else return ::std::memcmp(sym, strp, N) == 0; #endif diff --git a/include/fast_io_unit/floating/punning.h b/include/fast_io_unit/floating/punning.h index 929faadfc..a25d54e57 100644 --- a/include/fast_io_unit/floating/punning.h +++ b/include/fast_io_unit/floating/punning.h @@ -589,12 +589,8 @@ inline constexpr punning_result get_punned_result(flt f) noexcept constexpr mantissa_type exponent_mask{(static_cast(1) << ebits) - 1}; auto unwrap = -#if defined(__has_builtin) -#if __has_builtin(__builtin_bit_cast) +#if FAST_IO_HAS_BUILTIN(__builtin_bit_cast) __builtin_bit_cast(mantissa_type, f) -#else - bit_cast(f) -#endif #elif defined(_MSC_VER) && __cpp_lib_bit_cast >= 201806L __builtin_bit_cast(mantissa_type, f) #else diff --git a/share/fast_io/fast_io_inc/core.inc b/share/fast_io/fast_io_inc/core.inc index 18b193b36..ae0792aa8 100644 --- a/share/fast_io/fast_io_inc/core.inc +++ b/share/fast_io/fast_io_inc/core.inc @@ -5,6 +5,8 @@ using ::fast_io::char_literal_v; using ::fast_io::pr_rsv_size; using ::fast_io::pr_rsv_to_iterator_unchecked; +using ::fast_io::io_alias_type_t; + using ::fast_io::io_reserve_type_t; using ::fast_io::io_reserve_type; using ::fast_io::print_alias_define; @@ -22,13 +24,28 @@ using ::fast_io::scan_context_eof_define; using ::fast_io::unreachable; using ::fast_io::noexcept_call; +using ::fast_io::little_endian; +using ::fast_io::big_endian; +using ::fast_io::byte_swap; + using ::fast_io::error; +using ::fast_io::error_type_t; +using ::fast_io::error_type; +using ::fast_io::error_domain; +using ::fast_io::is_domain; +using ::fast_io::to_code; +using ::fast_io::throw_parse_code; +using ::fast_io::parse_domain_value; + using ::fast_io::cstr_len; using ::fast_io::cstr_nlen; using ::fast_io::parse_by_scan; using ::fast_io::parse_code; +using ::fast_io::io_dup; +using ::fast_io::open_mode; + #if !defined(__clang__) // The gcc and msvc module does not support non-exported functions adl matching using ::fast_io::input_stream_ref_define; using ::fast_io::output_stream_ref_define; @@ -131,6 +148,9 @@ using ::fast_io::manipulators::scalar_manip_t; using ::fast_io::manipulators::member_function_pointer_holder_t; using ::fast_io::manipulators::whole_get_t; +using ::fast_io::manipulators::leb128_get; +using ::fast_io::manipulators::leb128_put; + using ::fast_io::manipulators::boolalpha; using ::fast_io::manipulators::pointervw; @@ -144,6 +164,8 @@ using ::fast_io::manipulators::os_c_str_carr; using ::fast_io::manipulators::rgvw; +using ::fast_io::manipulators::cond; + using ::fast_io::manipulators::code_cvt; using ::fast_io::manipulators::code_cvt_os_c_str; using ::fast_io::manipulators::os_c_str_null_terminated; diff --git a/share/fast_io/fast_io_inc/freestanding.inc b/share/fast_io/fast_io_inc/freestanding.inc index a30a0916e..7b23a95b5 100644 --- a/share/fast_io/fast_io_inc/freestanding.inc +++ b/share/fast_io/fast_io_inc/freestanding.inc @@ -44,5 +44,6 @@ using ::fast_io::freestanding::find_first_not_of; using ::fast_io::freestanding::find_last_of; using ::fast_io::freestanding::find_last_not_of; +using ::fast_io::freestanding::errc; } // namespace freestanding } // namespace fast_io \ No newline at end of file diff --git a/share/fast_io/fast_io_inc/host/nt.inc b/share/fast_io/fast_io_inc/host/nt.inc index fa03d6a6b..9b890699c 100644 --- a/share/fast_io/fast_io_inc/host/nt.inc +++ b/share/fast_io/fast_io_inc/host/nt.inc @@ -5,6 +5,10 @@ export namespace fast_io { using ::fast_io::win32::nt::nt_get_current_peb; using ::fast_io::win32::nt::CsrClientCallServer; - + using ::fast_io::win32::nt::RtlQueryEnvironmentVariable_U; + using ::fast_io::win32::nt::unicode_string; + using ::fast_io::win32::nt::nt_set_information_virtual_memory; + using ::fast_io::win32::nt::memory_range_entry; + using ::fast_io::win32::nt::virtual_memory_information_class; } // namespace win32::nt } \ No newline at end of file diff --git a/share/fast_io/fast_io_inc/host/win32.inc b/share/fast_io/fast_io_inc/host/win32.inc index aba29f29a..20ce4a6df 100644 --- a/share/fast_io/fast_io_inc/host/win32.inc +++ b/share/fast_io/fast_io_inc/host/win32.inc @@ -16,5 +16,10 @@ export namespace fast_io using ::fast_io::win32::SetConsoleOutputCP; using ::fast_io::win32::CommandLineToArgvW; using ::fast_io::win32::LocalFree; + using ::fast_io::win32::GetEnvironmentVariableW; + using ::fast_io::win32::GetEnvironmentVariableA; + using ::fast_io::win32::PrefetchVirtualMemory; + using ::fast_io::win32::win32_memory_range_entry; + using ::fast_io::win32::SetConsoleTextAttribute; } // namespace win32 } \ No newline at end of file diff --git a/share/fast_io/fast_io_inc/hosted.inc b/share/fast_io/fast_io_inc/hosted.inc index 05d65e514..f6797ef53 100644 --- a/share/fast_io/fast_io_inc/hosted.inc +++ b/share/fast_io/fast_io_inc/hosted.inc @@ -10,6 +10,9 @@ using ::fast_io::nt_family; using ::fast_io::basic_nt_family_io_observer; using ::fast_io::basic_nt_family_file; +using ::fast_io::basic_nt_io_observer; +using ::fast_io::basic_nt_file; + using ::fast_io::nt_io_observer; using ::fast_io::nt_file; using ::fast_io::wnt_io_observer; @@ -28,6 +31,9 @@ using ::fast_io::nt_stderr; using ::fast_io::basic_win32_family_io_observer; using ::fast_io::basic_win32_family_file; +using ::fast_io::basic_win32_io_observer; +using ::fast_io::basic_win32_file; + using ::fast_io::win32_io_observer; using ::fast_io::win32_file; using ::fast_io::wwin32_io_observer;