21 using char_type = char32_t;
23 [[nodiscard]] std::endian guess_endian(
void const *ptr,
size_t size, std::endian endian)
const noexcept
26 auto *ptr_ =
reinterpret_cast<uint8_t
const *
>(ptr);
29 return std::endian::native;
32 if (ptr_[0] == 0x00 and ptr_[1] == 0x00 and ptr_[2] == 0xfe and ptr_[3] == 0xff) {
33 return std::endian::big;
34 }
else if (ptr_[0] == 0xff and ptr_[1] == 0xfe and ptr_[2] == 0x00 and ptr_[3] == 0x00) {
35 return std::endian::little;
40 for (
auto i = 0; i != size; ++i) {
41 count[i % 4] = ptr_[i] == 0 ? count[i % 4] + 1 : 0;
43 if (i % 4 == 0 and count[0] >= 8) {
44 return std::endian::big;
45 }
else if (i % 4 == 3 and count[3] >= 8) {
46 return std::endian::little;
54 template<
typename It,
typename EndIt>
59 if (
auto cu = *it++; cu < 0xd800) {
62 }
else if (cu < 0xe000) {
64 return {0xfffd,
false};
66 }
else if (cu < 0x11'0000) {
71 return {0xfffd,
false};
78 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
79 return {uint8_t{1},
true};
83 constexpr void write(
char32_t code_point, It& dst)
const noexcept
86 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
91#if defined(HI_HAS_SSE2)
93 hi_force_inline __m128i read_ascii_chunk16(It it)
const noexcept
104 hilet lo = _mm_packs_epi32(c0, c1);
105 hilet hi = _mm_packs_epi32(c2, c3);
113 hilet sign_lo = _mm_srai_epi16(lo, 15);
114 hilet sign_hi = _mm_srai_epi16(
hi, 15);
115 hilet sign = _mm_packs_epi16(sign_lo, sign_hi);
120 hilet chunk = _mm_packus_epi16(lo,
hi);
125 return _mm_or_si128(chunk, sign);
128 template<
typename It>
129 hi_force_inline
void write_ascii_chunk16(__m128i chunk, It dst)
const noexcept
131 hilet zero = _mm_setzero_si128();
132 hilet lo = _mm_unpacklo_epi8(chunk, zero);
133 hilet hi = _mm_unpackhi_epi8(chunk, zero);
135 hilet c0 = _mm_unpacklo_epi8(lo, zero);
136 hilet c1 = _mm_unpackhi_epi8(lo, zero);
137 hilet c2 = _mm_unpacklo_epi8(
hi, zero);
138 hilet c3 = _mm_unpackhi_epi8(
hi, zero);
140 _mm_storeu_si128(
reinterpret_cast<__m128i *
>(
std::addressof(*dst)), c0);
142 _mm_storeu_si128(
reinterpret_cast<__m128i *
>(
std::addressof(*dst)), c1);
144 _mm_storeu_si128(
reinterpret_cast<__m128i *
>(
std::addressof(*dst)), c2);
146 _mm_storeu_si128(
reinterpret_cast<__m128i *
>(
std::addressof(*dst)), c3);
#define hi_axiom(expression)
Specify an axiom; an expression that is true.
Definition assert.hpp:133