_Z29get_supported_implementationsv:
   26|  2.77k|get_supported_implementations() {
   27|  2.77k|  static const auto impl = []() -> auto {
   28|  2.77k|    std::vector<const simdutf::implementation*> ret;
   29|  2.77k|    for (auto e : simdutf::get_available_implementations()) {
   30|  2.77k|      std::cerr << "implementation " << e->name() << " is available? "
   31|  2.77k|                << e->supported_by_runtime_system() << '\n';
   32|  2.77k|      if (e->supported_by_runtime_system()) {
   33|  2.77k|        ret.push_back(e);
   34|  2.77k|      }
   35|  2.77k|    }
   36|  2.77k|    return ret;
   37|  2.77k|  }();
   38|  2.77k|  return {impl.data(), impl.size()};
   39|  2.77k|}
_ZZ29get_supported_implementationsvENKUlvE_clEv:
   27|      1|  static const auto impl = []() -> auto {
   28|      1|    std::vector<const simdutf::implementation*> ret;
   29|      4|    for (auto e : simdutf::get_available_implementations()) {
  ------------------
  |  Branch (29:17): [True: 4, False: 1]
  ------------------
   30|      4|      std::cerr << "implementation " << e->name() << " is available? "
   31|      4|                << e->supported_by_runtime_system() << '\n';
   32|      4|      if (e->supported_by_runtime_system()) {
  ------------------
  |  Branch (32:11): [True: 3, False: 1]
  ------------------
   33|      3|        ret.push_back(e);
   34|      3|      }
   35|      4|    }
   36|      1|    return ret;
   37|      1|  }();
_ZneRKN7simdutf6resultES2_:
   42|  5.55k|inline bool operator!=(const simdutf::result& a, const simdutf::result& b) {
   43|  5.55k|  return a.count != b.count || a.error != b.error;
  ------------------
  |  Branch (43:10): [True: 0, False: 5.55k]
  |  Branch (43:32): [True: 0, False: 5.55k]
  ------------------
   44|  5.55k|}

LLVMFuzzerTestOneInput:
  211|  2.77k|extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  212|       |  // First 4 bytes: action selector + alignment padding.
  213|  2.77k|  if (size < 4) {
  ------------------
  |  Branch (213:7): [True: 2, False: 2.77k]
  ------------------
  214|      2|    return 0;
  215|      2|  }
  216|  2.77k|  constexpr auto Ncases = 2u;
  217|  2.77k|  constexpr auto actionmask = std::bit_ceil(Ncases) - 1;
  218|  2.77k|  const auto action = data[0] & actionmask;
  219|       |
  220|       |  // Advance by 4 so the remaining data is aligned to char16_t.
  221|  2.77k|  data += 4;
  222|  2.77k|  size -= 4;
  223|       |
  224|  2.77k|  const std::span<const char16_t> u16data{
  225|  2.77k|      reinterpret_cast<const char16_t*>(data), size / sizeof(char16_t)};
  226|       |
  227|  2.77k|  switch (action) {
  ------------------
  |  Branch (227:11): [True: 2.77k, False: 0]
  ------------------
  228|  1.42k|  case 0:
  ------------------
  |  Branch (228:3): [True: 1.42k, False: 1.35k]
  ------------------
  229|  1.42k|    test_utf16le_with_replacement(u16data);
  230|  1.42k|    break;
  231|  1.35k|  case 1:
  ------------------
  |  Branch (231:3): [True: 1.35k, False: 1.42k]
  ------------------
  232|  1.35k|    test_utf16be_with_replacement(u16data);
  233|  1.35k|    break;
  234|  2.77k|  }
  235|       |
  236|  2.77k|  return 0;
  237|  2.77k|}
with_replacement.cpp:_ZL29test_utf16le_with_replacementNSt3__14spanIKDsLm18446744073709551615EEE:
   27|  1.42k|static void test_utf16le_with_replacement(std::span<const char16_t> input) {
   28|  1.42k|  const auto implementations = get_supported_implementations();
   29|  1.42k|  if (implementations.empty()) {
  ------------------
  |  Branch (29:7): [True: 0, False: 1.42k]
  ------------------
   30|      0|    return;
   31|      0|  }
   32|       |
   33|       |  // Step 1: Collect length predictions from all implementations and check
   34|       |  // agreement.
   35|  1.42k|  std::vector<simdutf::result> len_results;
   36|  1.42k|  len_results.reserve(implementations.size());
   37|  4.27k|  for (auto impl : implementations) {
  ------------------
  |  Branch (37:18): [True: 4.27k, False: 1.42k]
  ------------------
   38|  4.27k|    len_results.push_back(impl->utf8_length_from_utf16le_with_replacement(
   39|  4.27k|        input.data(), input.size()));
   40|  4.27k|  }
   41|  1.42k|  {
   42|  1.42k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
   43|  1.42k|    if (std::ranges::adjacent_find(len_results, neq) != len_results.end()) {
  ------------------
  |  Branch (43:9): [True: 0, False: 1.42k]
  ------------------
   44|      0|      std::cerr << "utf8_length_from_utf16le_with_replacement: implementations "
   45|      0|                   "disagree\n";
   46|      0|      for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (46:31): [True: 0, False: 0]
  ------------------
   47|      0|        std::cerr << "  " << implementations[i]->name()
   48|      0|                  << ": count=" << len_results[i].count
   49|      0|                  << " error=" << len_results[i].error << "\n";
   50|      0|      }
   51|      0|      std::abort();
   52|      0|    }
   53|  1.42k|  }
   54|       |
   55|  1.42k|  const std::size_t expected_len = len_results[0].count;
   56|       |  // error == SUCCESS means no surrogates encountered; SURROGATE means at least
   57|       |  // one.
   58|  1.42k|  const bool has_surrogates = (len_results[0].error != simdutf::SUCCESS);
   59|       |
   60|       |  // Step 2: Run conversion across all implementations and verify written ==
   61|       |  // expected_len.
   62|  1.42k|  std::vector<std::vector<char>> outputs;
   63|  1.42k|  outputs.reserve(implementations.size());
   64|  4.27k|  for (auto impl : implementations) {
  ------------------
  |  Branch (64:18): [True: 4.27k, False: 1.42k]
  ------------------
   65|  4.27k|    std::vector<char> out(expected_len);
   66|  4.27k|    const auto written = impl->convert_utf16le_to_utf8_with_replacement(
   67|  4.27k|        input.data(), input.size(), out.data());
   68|  4.27k|    if (written != expected_len) {
  ------------------
  |  Branch (68:9): [True: 0, False: 4.27k]
  ------------------
   69|      0|      std::cerr << "convert_utf16le_to_utf8_with_replacement:" << " written="
   70|      0|                << written << " but length predicted=" << expected_len
   71|      0|                << " impl=" << impl->name() << "\n";
   72|      0|      std::abort();
   73|      0|    }
   74|  4.27k|    outputs.push_back(std::move(out));
   75|  4.27k|  }
   76|       |
   77|       |  // Step 3: All implementations must agree on the output bytes.
   78|  1.42k|  {
   79|  1.42k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
   80|  1.42k|    if (std::ranges::adjacent_find(outputs, neq) != outputs.end()) {
  ------------------
  |  Branch (80:9): [True: 0, False: 1.42k]
  ------------------
   81|      0|      std::cerr << "convert_utf16le_to_utf8_with_replacement: outputs differ "
   82|      0|                   "between implementations\n";
   83|      0|      for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (83:31): [True: 0, False: 0]
  ------------------
   84|      0|        std::cerr << "  " << implementations[i]->name()
   85|      0|                  << ": hash=" << FNV1A_hash::as_str(outputs[i]) << "\n";
   86|      0|      }
   87|      0|      std::abort();
   88|      0|    }
   89|  1.42k|  }
   90|       |
   91|       |  // Step 4: Output must always be valid UTF-8.
   92|  5.70k|  for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (92:27): [True: 4.27k, False: 1.42k]
  ------------------
   93|  4.27k|    if (!implementations[i]->validate_utf8(outputs[i].data(),
  ------------------
  |  Branch (93:9): [True: 0, False: 4.27k]
  ------------------
   94|  4.27k|                                           outputs[i].size())) {
   95|      0|      std::cerr << "convert_utf16le_to_utf8_with_replacement: output is not "
   96|      0|                   "valid UTF-8"
   97|      0|                << " impl=" << implementations[i]->name() << "\n";
   98|      0|      std::abort();
   99|      0|    }
  100|  4.27k|  }
  101|       |
  102|       |  // Step 5: When no surrogates were found, match the regular (non-replacement)
  103|       |  // length.
  104|  1.42k|  if (!has_surrogates) {
  ------------------
  |  Branch (104:7): [True: 497, False: 928]
  ------------------
  105|  1.98k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (105:29): [True: 1.49k, False: 497]
  ------------------
  106|  1.49k|      auto impl = implementations[i];
  107|  1.49k|      const auto regular_len =
  108|  1.49k|          impl->utf8_length_from_utf16le(input.data(), input.size());
  109|  1.49k|      if (regular_len != expected_len) {
  ------------------
  |  Branch (109:11): [True: 0, False: 1.49k]
  ------------------
  110|      0|        std::cerr
  111|      0|            << "utf16le_with_replacement: no surrogates but length mismatch:"
  112|      0|            << " with_replacement=" << expected_len
  113|      0|            << " regular=" << regular_len << " impl=" << impl->name() << "\n";
  114|      0|        std::abort();
  115|      0|      }
  116|  1.49k|    }
  117|    497|  }
  118|  1.42k|}
with_replacement.cpp:_ZZL29test_utf16le_with_replacementNSt3__14spanIKDsLm18446744073709551615EEEENK3$_0clIN7simdutf6resultES6_EEDaRKT_RKT0_:
   42|  2.85k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
with_replacement.cpp:_ZZL29test_utf16le_with_replacementNSt3__14spanIKDsLm18446744073709551615EEEENK3$_1clINS_6vectorIcNS_9allocatorIcEEEES8_EEDaRKT_RKT0_:
   79|  2.85k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
with_replacement.cpp:_ZL29test_utf16be_with_replacementNSt3__14spanIKDsLm18446744073709551615EEE:
  120|  1.35k|static void test_utf16be_with_replacement(std::span<const char16_t> input) {
  121|  1.35k|  const auto implementations = get_supported_implementations();
  122|  1.35k|  if (implementations.empty()) {
  ------------------
  |  Branch (122:7): [True: 0, False: 1.35k]
  ------------------
  123|      0|    return;
  124|      0|  }
  125|       |
  126|       |  // Step 1: Collect length predictions from all implementations and check
  127|       |  // agreement.
  128|  1.35k|  std::vector<simdutf::result> len_results;
  129|  1.35k|  len_results.reserve(implementations.size());
  130|  4.05k|  for (auto impl : implementations) {
  ------------------
  |  Branch (130:18): [True: 4.05k, False: 1.35k]
  ------------------
  131|  4.05k|    len_results.push_back(impl->utf8_length_from_utf16be_with_replacement(
  132|  4.05k|        input.data(), input.size()));
  133|  4.05k|  }
  134|  1.35k|  {
  135|  1.35k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  136|  1.35k|    if (std::ranges::adjacent_find(len_results, neq) != len_results.end()) {
  ------------------
  |  Branch (136:9): [True: 0, False: 1.35k]
  ------------------
  137|      0|      std::cerr << "utf8_length_from_utf16be_with_replacement: implementations "
  138|      0|                   "disagree\n";
  139|      0|      for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (139:31): [True: 0, False: 0]
  ------------------
  140|      0|        std::cerr << "  " << implementations[i]->name()
  141|      0|                  << ": count=" << len_results[i].count
  142|      0|                  << " error=" << len_results[i].error << "\n";
  143|      0|      }
  144|      0|      std::abort();
  145|      0|    }
  146|  1.35k|  }
  147|       |
  148|  1.35k|  const std::size_t expected_len = len_results[0].count;
  149|  1.35k|  const bool has_surrogates = (len_results[0].error != simdutf::SUCCESS);
  150|       |
  151|       |  // Step 2: Run conversion across all implementations and verify written ==
  152|       |  // expected_len.
  153|  1.35k|  std::vector<std::vector<char>> outputs;
  154|  1.35k|  outputs.reserve(implementations.size());
  155|  4.05k|  for (auto impl : implementations) {
  ------------------
  |  Branch (155:18): [True: 4.05k, False: 1.35k]
  ------------------
  156|  4.05k|    std::vector<char> out(expected_len);
  157|  4.05k|    const auto written = impl->convert_utf16be_to_utf8_with_replacement(
  158|  4.05k|        input.data(), input.size(), out.data());
  159|  4.05k|    if (written != expected_len) {
  ------------------
  |  Branch (159:9): [True: 0, False: 4.05k]
  ------------------
  160|      0|      std::cerr << "convert_utf16be_to_utf8_with_replacement:" << " written="
  161|      0|                << written << " but length predicted=" << expected_len
  162|      0|                << " impl=" << impl->name() << "\n";
  163|      0|      std::abort();
  164|      0|    }
  165|  4.05k|    outputs.push_back(std::move(out));
  166|  4.05k|  }
  167|       |
  168|       |  // Step 3: All implementations must agree on the output bytes.
  169|  1.35k|  {
  170|  1.35k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  171|  1.35k|    if (std::ranges::adjacent_find(outputs, neq) != outputs.end()) {
  ------------------
  |  Branch (171:9): [True: 0, False: 1.35k]
  ------------------
  172|      0|      std::cerr << "convert_utf16be_to_utf8_with_replacement: outputs differ "
  173|      0|                   "between implementations\n";
  174|      0|      for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (174:31): [True: 0, False: 0]
  ------------------
  175|      0|        std::cerr << "  " << implementations[i]->name()
  176|      0|                  << ": hash=" << FNV1A_hash::as_str(outputs[i]) << "\n";
  177|      0|      }
  178|      0|      std::abort();
  179|      0|    }
  180|  1.35k|  }
  181|       |
  182|       |  // Step 4: Output must always be valid UTF-8.
  183|  5.40k|  for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (183:27): [True: 4.05k, False: 1.35k]
  ------------------
  184|  4.05k|    if (!implementations[i]->validate_utf8(outputs[i].data(),
  ------------------
  |  Branch (184:9): [True: 0, False: 4.05k]
  ------------------
  185|  4.05k|                                           outputs[i].size())) {
  186|      0|      std::cerr << "convert_utf16be_to_utf8_with_replacement: output is not "
  187|      0|                   "valid UTF-8"
  188|      0|                << " impl=" << implementations[i]->name() << "\n";
  189|      0|      std::abort();
  190|      0|    }
  191|  4.05k|  }
  192|       |
  193|       |  // Step 5: When no surrogates were found, match the regular (non-replacement)
  194|       |  // length.
  195|  1.35k|  if (!has_surrogates) {
  ------------------
  |  Branch (195:7): [True: 455, False: 897]
  ------------------
  196|  1.82k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (196:29): [True: 1.36k, False: 455]
  ------------------
  197|  1.36k|      auto impl = implementations[i];
  198|  1.36k|      const auto regular_len =
  199|  1.36k|          impl->utf8_length_from_utf16be(input.data(), input.size());
  200|  1.36k|      if (regular_len != expected_len) {
  ------------------
  |  Branch (200:11): [True: 0, False: 1.36k]
  ------------------
  201|      0|        std::cerr
  202|      0|            << "utf16be_with_replacement: no surrogates but length mismatch:"
  203|      0|            << " with_replacement=" << expected_len
  204|      0|            << " regular=" << regular_len << " impl=" << impl->name() << "\n";
  205|      0|        std::abort();
  206|      0|      }
  207|  1.36k|    }
  208|    455|  }
  209|  1.35k|}
with_replacement.cpp:_ZZL29test_utf16be_with_replacementNSt3__14spanIKDsLm18446744073709551615EEEENK3$_0clIN7simdutf6resultES6_EEDaRKT_RKT0_:
  135|  2.70k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
with_replacement.cpp:_ZZL29test_utf16be_with_replacementNSt3__14spanIKDsLm18446744073709551615EEEENK3$_1clINS_6vectorIcNS_9allocatorIcEEEES8_EEDaRKT_RKT0_:
  170|  2.70k|    auto neq = [](const auto& a, const auto& b) { return a != b; };

_ZN7simdutf6resultC2ENS_10error_codeEm:
   87|  10.1M|      : error{err}, count{pos} {}
_ZN7simdutf11full_resultC2ENS_10error_codeEmm:
  111|  10.1M|      : error{err}, input_count{pos_in}, output_count{pos_out} {}

_ZNK7simdutf14implementation4nameEv:
 5654|      4|  virtual std::string_view name() const noexcept { return _name; }
_ZNK7simdutf14implementation25required_instruction_setsEv:
 5705|      8|  virtual uint32_t required_instruction_sets() const {
 5706|      8|    return _required_instruction_sets;
 5707|      8|  }
_ZN7simdutf14implementationC2EPKcS2_j:
 7619|      4|      : _name(name), _description(description),
 7620|      4|        _required_instruction_sets(required_instruction_sets) {}
_ZN7simdutf8internal29available_implementation_listC2Ev:
 7651|      1|  simdutf_really_inline available_implementation_list() {}

simdutf.cpp:_ZN7simdutf8internalL30detect_supported_architecturesEv:
  301|      8|static inline uint32_t detect_supported_architectures() {
  302|      8|  uint32_t eax;
  303|      8|  uint32_t ebx = 0;
  304|      8|  uint32_t ecx = 0;
  305|      8|  uint32_t edx = 0;
  306|      8|  uint32_t host_isa = 0x0;
  307|       |
  308|       |  // EBX for EAX=0x1
  309|      8|  eax = 0x1;
  310|      8|  cpuid(&eax, &ebx, &ecx, &edx);
  311|       |
  312|      8|  if (ecx & cpuid_bit::sse42) {
  ------------------
  |  Branch (312:7): [True: 8, False: 0]
  ------------------
  313|      8|    host_isa |= instruction_set::SSE42;
  314|      8|  }
  315|       |
  316|      8|  if (ecx & cpuid_bit::pclmulqdq) {
  ------------------
  |  Branch (316:7): [True: 8, False: 0]
  ------------------
  317|      8|    host_isa |= instruction_set::PCLMULQDQ;
  318|      8|  }
  319|       |
  320|      8|  if ((ecx & cpuid_bit::osxsave) != cpuid_bit::osxsave) {
  ------------------
  |  Branch (320:7): [True: 0, False: 8]
  ------------------
  321|      0|    return host_isa;
  322|      0|  }
  323|       |
  324|       |  // xgetbv for checking if the OS saves registers
  325|      8|  uint64_t xcr0 = xgetbv();
  326|       |
  327|      8|  if ((xcr0 & cpuid_bit::xcr0_bit::avx256_saved) == 0) {
  ------------------
  |  Branch (327:7): [True: 0, False: 8]
  ------------------
  328|      0|    return host_isa;
  329|      0|  }
  330|       |  // ECX for EAX=0x7
  331|      8|  eax = 0x7;
  332|      8|  ecx = 0x0; // Sub-leaf = 0
  333|      8|  cpuid(&eax, &ebx, &ecx, &edx);
  334|      8|  if (ebx & cpuid_bit::ebx::avx2) {
  ------------------
  |  Branch (334:7): [True: 8, False: 0]
  ------------------
  335|      8|    host_isa |= instruction_set::AVX2;
  336|      8|  }
  337|      8|  if (ebx & cpuid_bit::ebx::bmi1) {
  ------------------
  |  Branch (337:7): [True: 8, False: 0]
  ------------------
  338|      8|    host_isa |= instruction_set::BMI1;
  339|      8|  }
  340|      8|  if (ebx & cpuid_bit::ebx::bmi2) {
  ------------------
  |  Branch (340:7): [True: 8, False: 0]
  ------------------
  341|      8|    host_isa |= instruction_set::BMI2;
  342|      8|  }
  343|      8|  if (!((xcr0 & cpuid_bit::xcr0_bit::avx512_saved) ==
  ------------------
  |  Branch (343:7): [True: 8, False: 0]
  ------------------
  344|      8|        cpuid_bit::xcr0_bit::avx512_saved)) {
  345|      8|    return host_isa;
  346|      8|  }
  347|      0|  if (ebx & cpuid_bit::ebx::avx512f) {
  ------------------
  |  Branch (347:7): [True: 0, False: 0]
  ------------------
  348|      0|    host_isa |= instruction_set::AVX512F;
  349|      0|  }
  350|      0|  if (ebx & cpuid_bit::ebx::avx512bw) {
  ------------------
  |  Branch (350:7): [True: 0, False: 0]
  ------------------
  351|      0|    host_isa |= instruction_set::AVX512BW;
  352|      0|  }
  353|      0|  if (ebx & cpuid_bit::ebx::avx512cd) {
  ------------------
  |  Branch (353:7): [True: 0, False: 0]
  ------------------
  354|      0|    host_isa |= instruction_set::AVX512CD;
  355|      0|  }
  356|      0|  if (ebx & cpuid_bit::ebx::avx512dq) {
  ------------------
  |  Branch (356:7): [True: 0, False: 0]
  ------------------
  357|      0|    host_isa |= instruction_set::AVX512DQ;
  358|      0|  }
  359|      0|  if (ebx & cpuid_bit::ebx::avx512vl) {
  ------------------
  |  Branch (359:7): [True: 0, False: 0]
  ------------------
  360|      0|    host_isa |= instruction_set::AVX512VL;
  361|      0|  }
  362|      0|  if (ecx & cpuid_bit::ecx::avx512vbmi2) {
  ------------------
  |  Branch (362:7): [True: 0, False: 0]
  ------------------
  363|      0|    host_isa |= instruction_set::AVX512VBMI2;
  364|      0|  }
  365|      0|  if (ecx & cpuid_bit::ecx::avx512vpopcnt) {
  ------------------
  |  Branch (365:7): [True: 0, False: 0]
  ------------------
  366|      0|    host_isa |= instruction_set::AVX512VPOPCNTDQ;
  367|      0|  }
  368|      0|  return host_isa;
  369|      8|}
simdutf.cpp:_ZN7simdutf8internalL5cpuidEPjS1_S1_S1_:
  267|     16|                         uint32_t *edx) {
  268|       |  #if defined(_MSC_VER)
  269|       |  int cpu_info[4];
  270|       |  __cpuidex(cpu_info, *eax, *ecx);
  271|       |  *eax = cpu_info[0];
  272|       |  *ebx = cpu_info[1];
  273|       |  *ecx = cpu_info[2];
  274|       |  *edx = cpu_info[3];
  275|       |  #elif (defined(HAVE_GCC_GET_CPUID) && defined(USE_GCC_GET_CPUID)) ||         \
  276|       |      defined(__FILC__)
  277|       |  uint32_t level = *eax;
  278|       |  __get_cpuid(level, eax, ebx, ecx, edx);
  279|       |  #else
  280|     16|  uint32_t a = *eax, b, c = *ecx, d;
  281|     16|  asm volatile("cpuid\n\t" : "+a"(a), "=b"(b), "+c"(c), "=d"(d));
  282|     16|  *eax = a;
  283|     16|  *ebx = b;
  284|     16|  *ecx = c;
  285|     16|  *edx = d;
  286|     16|  #endif
  287|     16|}
simdutf.cpp:_ZN7simdutf8internalL6xgetbvEv:
  289|      8|static inline uint64_t xgetbv() {
  290|       |  #if defined(_MSC_VER)
  291|       |  return _xgetbv(0);
  292|       |  #elif defined(__FILC__)
  293|       |  return zxgetbv();
  294|       |  #else
  295|      8|  uint32_t xcr0_lo, xcr0_hi;
  296|      8|  asm volatile("xgetbv\n\t" : "=a"(xcr0_lo), "=d"(xcr0_hi) : "c"(0));
  297|      8|  return xcr0_lo | ((uint64_t)xcr0_hi << 32);
  298|      8|  #endif
  299|      8|}

_ZN7simdutf6scalar14u16_swap_bytesEt:
    8|   145M|u16_swap_bytes(const uint16_t word) {
    9|   145M|  return uint16_t((word >> 8) | (word << 8));
   10|   145M|}
_ZN7simdutf6scalar5utf1614swap_if_neededILNS_10endiannessE0EEEtt:
   27|   104M|template <endianness big_endian> constexpr uint16_t swap_if_needed(uint16_t c) {
   28|   104M|  return !match_system(big_endian) ? scalar::u16_swap_bytes(c) : c;
  ------------------
  |  Branch (28:10): [Folded, False: 104M]
  ------------------
   29|   104M|}
_ZN7simdutf6scalar5utf1614swap_if_neededILNS_10endiannessE1EEEtt:
   27|  86.8M|template <endianness big_endian> constexpr uint16_t swap_if_needed(uint16_t c) {
   28|  86.8M|  return !match_system(big_endian) ? scalar::u16_swap_bytes(c) : c;
  ------------------
  |  Branch (28:10): [True: 86.8M, Folded]
  ------------------
   29|  86.8M|}

_ZN7simdutf6scalar5utf1617is_high_surrogateILNS_10endiannessE0EEEbDs:
  137|  34.5M|template <endianness big_endian> constexpr bool is_high_surrogate(char16_t c) {
  138|  34.5M|  c = scalar::utf16::swap_if_needed<big_endian>(c);
  139|  34.5M|  return (0xd800 <= c && c <= 0xdbff);
  ------------------
  |  Branch (139:11): [True: 3.26M, False: 31.2M]
  |  Branch (139:26): [True: 2.47M, False: 785k]
  ------------------
  140|  34.5M|}
_ZN7simdutf6scalar5utf1616is_low_surrogateILNS_10endiannessE0EEEbDs:
  142|  40.3M|template <endianness big_endian> constexpr bool is_low_surrogate(char16_t c) {
  143|  40.3M|  c = scalar::utf16::swap_if_needed<big_endian>(c);
  144|  40.3M|  return (0xdc00 <= c && c <= 0xdfff);
  ------------------
  |  Branch (144:11): [True: 889k, False: 39.4M]
  |  Branch (144:26): [True: 365k, False: 524k]
  ------------------
  145|  40.3M|}
_ZN7simdutf6scalar5utf1617is_high_surrogateILNS_10endiannessE1EEEbDs:
  137|  29.7M|template <endianness big_endian> constexpr bool is_high_surrogate(char16_t c) {
  138|  29.7M|  c = scalar::utf16::swap_if_needed<big_endian>(c);
  139|  29.7M|  return (0xd800 <= c && c <= 0xdbff);
  ------------------
  |  Branch (139:11): [True: 3.19M, False: 26.5M]
  |  Branch (139:26): [True: 1.98M, False: 1.20M]
  ------------------
  140|  29.7M|}
_ZN7simdutf6scalar5utf1616is_low_surrogateILNS_10endiannessE1EEEbDs:
  142|  34.6M|template <endianness big_endian> constexpr bool is_low_surrogate(char16_t c) {
  143|  34.6M|  c = scalar::utf16::swap_if_needed<big_endian>(c);
  144|  34.6M|  return (0xdc00 <= c && c <= 0xdfff);
  ------------------
  |  Branch (144:11): [True: 1.40M, False: 33.2M]
  |  Branch (144:26): [True: 382k, False: 1.02M]
  ------------------
  145|  34.6M|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE0EEEmPKDsm:
   91|  1.56k|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|  1.56k|  size_t counter{0};
   94|  17.5M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 17.5M, False: 1.56k]
  ------------------
   95|  17.5M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|  17.5M|    counter++; // ASCII
   97|  17.5M|    counter += static_cast<size_t>(
   98|  17.5M|        word >
   99|  17.5M|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|  17.5M|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 9.52M, False: 7.98M]
  |  Branch (100:53): [True: 9.44M, False: 83.2k]
  ------------------
  101|  8.06M|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 83.2k, False: 7.98M]
  ------------------
  102|  17.5M|  }
  103|  1.56k|  return counter;
  104|  1.56k|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE1EEEmPKDsm:
   91|  1.41k|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|  1.41k|  size_t counter{0};
   94|  11.8M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 11.8M, False: 1.41k]
  ------------------
   95|  11.8M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|  11.8M|    counter++; // ASCII
   97|  11.8M|    counter += static_cast<size_t>(
   98|  11.8M|        word >
   99|  11.8M|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|  11.8M|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 7.08M, False: 4.72M]
  |  Branch (100:53): [True: 7.05M, False: 32.8k]
  ------------------
  101|  4.76M|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 32.8k, False: 4.72M]
  ------------------
  102|  11.8M|  }
  103|  1.41k|  return counter;
  104|  1.41k|}
_ZN7simdutf6scalar5utf1639utf8_length_from_utf16_with_replacementILNS_10endiannessE0EEENS_6resultEPKDsm:
  153|  4.27k|utf8_length_from_utf16_with_replacement(const char16_t *p, size_t len) {
  154|  4.27k|  bool any_surrogates = false;
  155|       |  // We are not BOM aware.
  156|  4.27k|  size_t counter{0};
  157|  34.5M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (157:22): [True: 34.4M, False: 4.27k]
  ------------------
  158|  34.4M|    if (is_high_surrogate<big_endian>(p[i])) {
  ------------------
  |  Branch (158:9): [True: 2.47M, False: 32.0M]
  ------------------
  159|  2.47M|      any_surrogates = true;
  160|       |      // surrogate pair
  161|  2.47M|      if (i + 1 < len && is_low_surrogate<big_endian>(p[i + 1])) {
  ------------------
  |  Branch (161:11): [True: 2.47M, False: 549]
  |  Branch (161:26): [True: 22.2k, False: 2.45M]
  ------------------
  162|  22.2k|        counter += 4;
  163|  22.2k|        i++; // skip low surrogate
  164|  2.45M|      } else {
  165|  2.45M|        counter += 3; // unpaired high surrogate replaced by U+FFFD
  166|  2.45M|      }
  167|  2.47M|      continue;
  168|  32.0M|    } else if (is_low_surrogate<big_endian>(p[i])) {
  ------------------
  |  Branch (168:16): [True: 337k, False: 31.6M]
  ------------------
  169|   337k|      any_surrogates = true;
  170|   337k|      counter += 3; // unpaired low surrogate replaced by U+FFFD
  171|   337k|      continue;
  172|   337k|    }
  173|  31.6M|    char16_t word = !match_system(big_endian) ? u16_swap_bytes(p[i]) : p[i];
  ------------------
  |  Branch (173:21): [Folded, False: 31.6M]
  ------------------
  174|  31.6M|    counter++; // at least 1 byte
  175|  31.6M|    counter +=
  176|  31.6M|        static_cast<size_t>(word > 0x7F); // non-ASCII is at least 2 bytes
  177|  31.6M|    counter += static_cast<size_t>(word > 0x7FF); // three-byte
  178|  31.6M|  }
  179|  4.27k|  return {any_surrogates ? error_code::SURROGATE : error_code::SUCCESS,
  ------------------
  |  Branch (179:11): [True: 2.08k, False: 2.18k]
  ------------------
  180|  4.27k|          counter};
  181|  4.27k|}
_ZN7simdutf6scalar5utf1639utf8_length_from_utf16_with_replacementILNS_10endiannessE1EEENS_6resultEPKDsm:
  153|  4.05k|utf8_length_from_utf16_with_replacement(const char16_t *p, size_t len) {
  154|  4.05k|  bool any_surrogates = false;
  155|       |  // We are not BOM aware.
  156|  4.05k|  size_t counter{0};
  157|  29.7M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (157:22): [True: 29.7M, False: 4.05k]
  ------------------
  158|  29.7M|    if (is_high_surrogate<big_endian>(p[i])) {
  ------------------
  |  Branch (158:9): [True: 1.98M, False: 27.7M]
  ------------------
  159|  1.98M|      any_surrogates = true;
  160|       |      // surrogate pair
  161|  1.98M|      if (i + 1 < len && is_low_surrogate<big_endian>(p[i + 1])) {
  ------------------
  |  Branch (161:11): [True: 1.98M, False: 498]
  |  Branch (161:26): [True: 31.6k, False: 1.95M]
  ------------------
  162|  31.6k|        counter += 4;
  163|  31.6k|        i++; // skip low surrogate
  164|  1.95M|      } else {
  165|  1.95M|        counter += 3; // unpaired high surrogate replaced by U+FFFD
  166|  1.95M|      }
  167|  1.98M|      continue;
  168|  27.7M|    } else if (is_low_surrogate<big_endian>(p[i])) {
  ------------------
  |  Branch (168:16): [True: 342k, False: 27.3M]
  ------------------
  169|   342k|      any_surrogates = true;
  170|   342k|      counter += 3; // unpaired low surrogate replaced by U+FFFD
  171|   342k|      continue;
  172|   342k|    }
  173|  27.3M|    char16_t word = !match_system(big_endian) ? u16_swap_bytes(p[i]) : p[i];
  ------------------
  |  Branch (173:21): [True: 27.3M, Folded]
  ------------------
  174|  27.3M|    counter++; // at least 1 byte
  175|  27.3M|    counter +=
  176|  27.3M|        static_cast<size_t>(word > 0x7F); // non-ASCII is at least 2 bytes
  177|  27.3M|    counter += static_cast<size_t>(word > 0x7FF); // three-byte
  178|  27.3M|  }
  179|  4.05k|  return {any_surrogates ? error_code::SURROGATE : error_code::SUCCESS,
  ------------------
  |  Branch (179:11): [True: 2.01k, False: 2.03k]
  ------------------
  180|  4.05k|          counter};
  181|  4.05k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf819convert_with_errorsILNS_10endiannessE0ELb0EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT1_Esr7simdutf6detailE26index_assignable_from_charIT2_EEENS_11full_resultES8_mS9_m:
  101|  9.73k|                                                    size_t utf8_len = 0) {
  102|  9.73k|  if (check_output && utf8_len == 0) {
  ------------------
  |  Branch (102:7): [Folded, False: 9.73k]
  |  Branch (102:23): [True: 0, False: 0]
  ------------------
  103|      0|    return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, 0, 0);
  104|      0|  }
  105|       |
  106|  9.73k|  size_t pos = 0;
  107|  9.73k|  auto start = utf8_output;
  108|  9.73k|  auto end = utf8_output + utf8_len;
  109|       |
  110|  39.5k|  while (pos < len) {
  ------------------
  |  Branch (110:10): [True: 37.4k, False: 2.10k]
  ------------------
  111|       |#if SIMDUTF_CPLUSPLUS23
  112|       |    if !consteval
  113|       |#endif
  114|  37.4k|    {
  115|       |      // try to convert the next block of 8 bytes
  116|  37.4k|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (116:11): [True: 30.2k, False: 7.20k]
  ------------------
  117|       |                            // they are ascii
  118|  30.2k|        uint64_t v;
  119|  30.2k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
  120|       |        if constexpr (!match_system(big_endian))
  121|       |          v = (v >> 8) | (v << (64 - 8));
  122|  30.2k|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (122:13): [True: 1.67k, False: 28.5k]
  ------------------
  123|  1.67k|          size_t final_pos = pos + 4;
  124|  8.38k|          while (pos < final_pos) {
  ------------------
  |  Branch (124:18): [True: 6.70k, False: 1.67k]
  ------------------
  125|  6.70k|            if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (125:17): [Folded, False: 6.70k]
  |  Branch (125:33): [True: 0, False: 0]
  ------------------
  126|      0|              return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  127|      0|                                 utf8_output - start);
  128|      0|            }
  129|  6.70k|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (129:30): [Folded, False: 6.70k]
  ------------------
  130|  6.70k|                                 ? char(u16_swap_bytes(data[pos]))
  131|  6.70k|                                 : char(data[pos]);
  132|  6.70k|            pos++;
  133|  6.70k|          }
  134|  1.67k|          continue;
  135|  1.67k|        }
  136|  30.2k|      }
  137|  37.4k|    }
  138|       |
  139|  35.7k|    uint16_t word =
  140|  35.7k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (140:9): [Folded, False: 35.7k]
  ------------------
  141|  35.7k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (141:9): [True: 4.22k, False: 31.5k]
  ------------------
  142|       |      // will generate one UTF-8 bytes
  143|  4.22k|      if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (143:11): [Folded, False: 4.22k]
  |  Branch (143:27): [True: 0, False: 0]
  ------------------
  144|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  145|      0|                           utf8_output - start);
  146|      0|      }
  147|  4.22k|      *utf8_output++ = char(word);
  148|  4.22k|      pos++;
  149|  31.5k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (149:16): [True: 2.52k, False: 28.9k]
  ------------------
  150|       |      // will generate two UTF-8 bytes
  151|       |      // we have 0b110XXXXX 0b10XXXXXX
  152|  2.52k|      if (check_output && size_t(end - utf8_output) < 2) {
  ------------------
  |  Branch (152:11): [Folded, False: 2.52k]
  |  Branch (152:27): [True: 0, False: 0]
  ------------------
  153|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  154|      0|                           utf8_output - start);
  155|      0|      }
  156|  2.52k|      *utf8_output++ = char((word >> 6) | 0b11000000);
  157|  2.52k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  158|  2.52k|      pos++;
  159|       |
  160|  28.9k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (160:16): [True: 20.6k, False: 8.34k]
  ------------------
  161|       |      // will generate three UTF-8 bytes
  162|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
  163|  20.6k|      if (check_output && size_t(end - utf8_output) < 3) {
  ------------------
  |  Branch (163:11): [Folded, False: 20.6k]
  |  Branch (163:27): [True: 0, False: 0]
  ------------------
  164|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  165|      0|                           utf8_output - start);
  166|      0|      }
  167|  20.6k|      *utf8_output++ = char((word >> 12) | 0b11100000);
  168|  20.6k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  169|  20.6k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  170|  20.6k|      pos++;
  171|  20.6k|    } else {
  172|       |
  173|  8.34k|      if (check_output && size_t(end - utf8_output) < 4) {
  ------------------
  |  Branch (173:11): [Folded, False: 8.34k]
  |  Branch (173:27): [True: 0, False: 0]
  ------------------
  174|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  175|      0|                           utf8_output - start);
  176|      0|      }
  177|       |      // must be a surrogate pair
  178|  8.34k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (178:11): [True: 742, False: 7.60k]
  ------------------
  179|    742|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  180|    742|      }
  181|  7.60k|      uint16_t diff = uint16_t(word - 0xD800);
  182|  7.60k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (182:11): [True: 2.51k, False: 5.09k]
  ------------------
  183|  2.51k|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  184|  2.51k|      }
  185|  5.09k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (185:28): [Folded, False: 5.09k]
  ------------------
  186|  5.09k|                               ? u16_swap_bytes(data[pos + 1])
  187|  5.09k|                               : data[pos + 1];
  188|  5.09k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
  189|  5.09k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (189:11): [True: 4.37k, False: 720]
  ------------------
  190|  4.37k|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  191|  4.37k|      }
  192|    720|      uint32_t value = (diff << 10) + diff2 + 0x10000;
  193|       |      // will generate four UTF-8 bytes
  194|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
  195|    720|      *utf8_output++ = char((value >> 18) | 0b11110000);
  196|    720|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  197|    720|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  198|    720|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
  199|    720|      pos += 2;
  200|    720|    }
  201|  35.7k|  }
  202|  2.10k|  return full_result(error_code::SUCCESS, pos, utf8_output - start);
  203|  9.73k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf819convert_with_errorsILNS_10endiannessE1ELb0EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT1_Esr7simdutf6detailE26index_assignable_from_charIT2_EEENS_11full_resultES8_mS9_m:
  101|  9.35k|                                                    size_t utf8_len = 0) {
  102|  9.35k|  if (check_output && utf8_len == 0) {
  ------------------
  |  Branch (102:7): [Folded, False: 9.35k]
  |  Branch (102:23): [True: 0, False: 0]
  ------------------
  103|      0|    return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, 0, 0);
  104|      0|  }
  105|       |
  106|  9.35k|  size_t pos = 0;
  107|  9.35k|  auto start = utf8_output;
  108|  9.35k|  auto end = utf8_output + utf8_len;
  109|       |
  110|  36.7k|  while (pos < len) {
  ------------------
  |  Branch (110:10): [True: 34.7k, False: 2.03k]
  ------------------
  111|       |#if SIMDUTF_CPLUSPLUS23
  112|       |    if !consteval
  113|       |#endif
  114|  34.7k|    {
  115|       |      // try to convert the next block of 8 bytes
  116|  34.7k|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (116:11): [True: 28.0k, False: 6.74k]
  ------------------
  117|       |                            // they are ascii
  118|  28.0k|        uint64_t v;
  119|  28.0k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
  120|       |        if constexpr (!match_system(big_endian))
  121|  28.0k|          v = (v >> 8) | (v << (64 - 8));
  122|  28.0k|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (122:13): [True: 1.56k, False: 26.4k]
  ------------------
  123|  1.56k|          size_t final_pos = pos + 4;
  124|  7.80k|          while (pos < final_pos) {
  ------------------
  |  Branch (124:18): [True: 6.24k, False: 1.56k]
  ------------------
  125|  6.24k|            if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (125:17): [Folded, False: 6.24k]
  |  Branch (125:33): [True: 0, False: 0]
  ------------------
  126|      0|              return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  127|      0|                                 utf8_output - start);
  128|      0|            }
  129|  6.24k|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (129:30): [True: 6.24k, Folded]
  ------------------
  130|  6.24k|                                 ? char(u16_swap_bytes(data[pos]))
  131|  6.24k|                                 : char(data[pos]);
  132|  6.24k|            pos++;
  133|  6.24k|          }
  134|  1.56k|          continue;
  135|  1.56k|        }
  136|  28.0k|      }
  137|  34.7k|    }
  138|       |
  139|  33.1k|    uint16_t word =
  140|  33.1k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (140:9): [True: 33.1k, Folded]
  ------------------
  141|  33.1k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (141:9): [True: 3.74k, False: 29.4k]
  ------------------
  142|       |      // will generate one UTF-8 bytes
  143|  3.74k|      if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (143:11): [Folded, False: 3.74k]
  |  Branch (143:27): [True: 0, False: 0]
  ------------------
  144|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  145|      0|                           utf8_output - start);
  146|      0|      }
  147|  3.74k|      *utf8_output++ = char(word);
  148|  3.74k|      pos++;
  149|  29.4k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (149:16): [True: 2.75k, False: 26.6k]
  ------------------
  150|       |      // will generate two UTF-8 bytes
  151|       |      // we have 0b110XXXXX 0b10XXXXXX
  152|  2.75k|      if (check_output && size_t(end - utf8_output) < 2) {
  ------------------
  |  Branch (152:11): [Folded, False: 2.75k]
  |  Branch (152:27): [True: 0, False: 0]
  ------------------
  153|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  154|      0|                           utf8_output - start);
  155|      0|      }
  156|  2.75k|      *utf8_output++ = char((word >> 6) | 0b11000000);
  157|  2.75k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  158|  2.75k|      pos++;
  159|       |
  160|  26.6k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (160:16): [True: 18.6k, False: 8.08k]
  ------------------
  161|       |      // will generate three UTF-8 bytes
  162|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
  163|  18.6k|      if (check_output && size_t(end - utf8_output) < 3) {
  ------------------
  |  Branch (163:11): [Folded, False: 18.6k]
  |  Branch (163:27): [True: 0, False: 0]
  ------------------
  164|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  165|      0|                           utf8_output - start);
  166|      0|      }
  167|  18.6k|      *utf8_output++ = char((word >> 12) | 0b11100000);
  168|  18.6k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  169|  18.6k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  170|  18.6k|      pos++;
  171|  18.6k|    } else {
  172|       |
  173|  8.08k|      if (check_output && size_t(end - utf8_output) < 4) {
  ------------------
  |  Branch (173:11): [Folded, False: 8.08k]
  |  Branch (173:27): [True: 0, False: 0]
  ------------------
  174|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  175|      0|                           utf8_output - start);
  176|      0|      }
  177|       |      // must be a surrogate pair
  178|  8.08k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (178:11): [True: 660, False: 7.42k]
  ------------------
  179|    660|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  180|    660|      }
  181|  7.42k|      uint16_t diff = uint16_t(word - 0xD800);
  182|  7.42k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (182:11): [True: 2.34k, False: 5.08k]
  ------------------
  183|  2.34k|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  184|  2.34k|      }
  185|  5.08k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (185:28): [True: 5.08k, Folded]
  ------------------
  186|  5.08k|                               ? u16_swap_bytes(data[pos + 1])
  187|  5.08k|                               : data[pos + 1];
  188|  5.08k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
  189|  5.08k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (189:11): [True: 4.30k, False: 773]
  ------------------
  190|  4.30k|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  191|  4.30k|      }
  192|    773|      uint32_t value = (diff << 10) + diff2 + 0x10000;
  193|       |      // will generate four UTF-8 bytes
  194|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
  195|    773|      *utf8_output++ = char((value >> 18) | 0b11110000);
  196|    773|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  197|    773|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  198|    773|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
  199|    773|      pos += 2;
  200|    773|    }
  201|  33.1k|  }
  202|  2.03k|  return full_result(error_code::SUCCESS, pos, utf8_output - start);
  203|  9.35k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf824convert_with_replacementILNS_10endiannessE0EEEmPKDsmPc:
  214|  1.42k|                                                    char *utf8_output) {
  215|  1.42k|  size_t pos = 0;
  216|  1.42k|  char *start = utf8_output;
  217|  25.3M|  while (pos < len) {
  ------------------
  |  Branch (217:10): [True: 25.3M, False: 1.42k]
  ------------------
  218|       |#if SIMDUTF_CPLUSPLUS23
  219|       |    if !consteval
  220|       |#endif
  221|  25.3M|    {
  222|       |      // try to convert the next block of 8 bytes
  223|  25.3M|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (223:11): [True: 25.3M, False: 3.59k]
  ------------------
  224|       |                            // they are ascii
  225|  25.3M|        uint64_t v;
  226|  25.3M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
  227|       |        if constexpr (!match_system(big_endian)) {
  228|       |          v = (v >> 8) | (v << (64 - 8));
  229|       |        }
  230|  25.3M|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (230:13): [True: 3.04M, False: 22.2M]
  ------------------
  231|  3.04M|          size_t final_pos = pos + 4;
  232|  15.2M|          while (pos < final_pos) {
  ------------------
  |  Branch (232:18): [True: 12.1M, False: 3.04M]
  ------------------
  233|  12.1M|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (233:30): [Folded, False: 12.1M]
  ------------------
  234|  12.1M|                                 ? char(u16_swap_bytes(data[pos]))
  235|  12.1M|                                 : char(data[pos]);
  236|  12.1M|            pos++;
  237|  12.1M|          }
  238|  3.04M|          continue;
  239|  3.04M|        }
  240|  25.3M|      }
  241|  25.3M|    }
  242|  22.2M|    uint16_t word =
  243|  22.2M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (243:9): [Folded, False: 22.2M]
  ------------------
  244|  22.2M|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (244:9): [True: 309k, False: 21.9M]
  ------------------
  245|       |      // will generate one UTF-8 bytes
  246|   309k|      *utf8_output++ = char(word);
  247|   309k|      pos++;
  248|  21.9M|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (248:16): [True: 267k, False: 21.7M]
  ------------------
  249|       |      // will generate two UTF-8 bytes
  250|       |      // we have 0b110XXXXX 0b10XXXXXX
  251|   267k|      *utf8_output++ = char((word >> 6) | 0b11000000);
  252|   267k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  253|   267k|      pos++;
  254|  21.7M|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (254:16): [True: 18.9M, False: 2.80M]
  ------------------
  255|       |      // will generate three UTF-8 bytes
  256|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
  257|  18.9M|      *utf8_output++ = char((word >> 12) | 0b11100000);
  258|  18.9M|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  259|  18.9M|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  260|  18.9M|      pos++;
  261|  18.9M|    } else {
  262|       |      // surrogate range
  263|  2.80M|      uint16_t diff = uint16_t(word - 0xD800);
  264|  2.80M|      if (diff <= 0x3FF && pos + 1 < len) {
  ------------------
  |  Branch (264:11): [True: 2.47M, False: 337k]
  |  Branch (264:28): [True: 2.47M, False: 183]
  ------------------
  265|       |        // high surrogate, check for valid pair
  266|  2.47M|        uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (266:30): [Folded, False: 2.47M]
  ------------------
  267|  2.47M|                                 ? u16_swap_bytes(data[pos + 1])
  268|  2.47M|                                 : data[pos + 1];
  269|  2.47M|        uint16_t diff2 = uint16_t(next_word - 0xDC00);
  270|  2.47M|        if (diff2 <= 0x3FF) {
  ------------------
  |  Branch (270:13): [True: 21.9k, False: 2.45M]
  ------------------
  271|       |          // valid surrogate pair
  272|  21.9k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  273|       |          // will generate four UTF-8 bytes
  274|  21.9k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  275|  21.9k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  276|  21.9k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  277|  21.9k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  278|  21.9k|          pos += 2;
  279|  21.9k|          continue;
  280|  21.9k|        }
  281|  2.47M|      }
  282|       |      // unpaired surrogate: replace with U+FFFD (0xEF 0xBF 0xBD)
  283|  2.78M|      *utf8_output++ = char(0xef);
  284|  2.78M|      *utf8_output++ = char(0xbf);
  285|  2.78M|      *utf8_output++ = char(0xbd);
  286|  2.78M|      pos++;
  287|  2.78M|    }
  288|  22.2M|  }
  289|  1.42k|  return utf8_output - start;
  290|  1.42k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf824convert_with_replacementILNS_10endiannessE1EEEmPKDsmPc:
  214|  1.35k|                                                    char *utf8_output) {
  215|  1.35k|  size_t pos = 0;
  216|  1.35k|  char *start = utf8_output;
  217|  20.0M|  while (pos < len) {
  ------------------
  |  Branch (217:10): [True: 20.0M, False: 1.35k]
  ------------------
  218|       |#if SIMDUTF_CPLUSPLUS23
  219|       |    if !consteval
  220|       |#endif
  221|  20.0M|    {
  222|       |      // try to convert the next block of 8 bytes
  223|  20.0M|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (223:11): [True: 20.0M, False: 3.38k]
  ------------------
  224|       |                            // they are ascii
  225|  20.0M|        uint64_t v;
  226|  20.0M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
  227|  20.0M|        if constexpr (!match_system(big_endian)) {
  228|  20.0M|          v = (v >> 8) | (v << (64 - 8));
  229|  20.0M|        }
  230|  20.0M|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (230:13): [True: 3.23M, False: 16.7M]
  ------------------
  231|  3.23M|          size_t final_pos = pos + 4;
  232|  16.1M|          while (pos < final_pos) {
  ------------------
  |  Branch (232:18): [True: 12.9M, False: 3.23M]
  ------------------
  233|  12.9M|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (233:30): [True: 12.9M, Folded]
  ------------------
  234|  12.9M|                                 ? char(u16_swap_bytes(data[pos]))
  235|  12.9M|                                 : char(data[pos]);
  236|  12.9M|            pos++;
  237|  12.9M|          }
  238|  3.23M|          continue;
  239|  3.23M|        }
  240|  20.0M|      }
  241|  20.0M|    }
  242|  16.7M|    uint16_t word =
  243|  16.7M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (243:9): [True: 16.7M, Folded]
  ------------------
  244|  16.7M|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (244:9): [True: 201k, False: 16.5M]
  ------------------
  245|       |      // will generate one UTF-8 bytes
  246|   201k|      *utf8_output++ = char(word);
  247|   201k|      pos++;
  248|  16.5M|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (248:16): [True: 177k, False: 16.3M]
  ------------------
  249|       |      // will generate two UTF-8 bytes
  250|       |      // we have 0b110XXXXX 0b10XXXXXX
  251|   177k|      *utf8_output++ = char((word >> 6) | 0b11000000);
  252|   177k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  253|   177k|      pos++;
  254|  16.3M|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (254:16): [True: 14.0M, False: 2.32M]
  ------------------
  255|       |      // will generate three UTF-8 bytes
  256|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
  257|  14.0M|      *utf8_output++ = char((word >> 12) | 0b11100000);
  258|  14.0M|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  259|  14.0M|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  260|  14.0M|      pos++;
  261|  14.0M|    } else {
  262|       |      // surrogate range
  263|  2.32M|      uint16_t diff = uint16_t(word - 0xD800);
  264|  2.32M|      if (diff <= 0x3FF && pos + 1 < len) {
  ------------------
  |  Branch (264:11): [True: 1.98M, False: 341k]
  |  Branch (264:28): [True: 1.98M, False: 166]
  ------------------
  265|       |        // high surrogate, check for valid pair
  266|  1.98M|        uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (266:30): [True: 1.98M, Folded]
  ------------------
  267|  1.98M|                                 ? u16_swap_bytes(data[pos + 1])
  268|  1.98M|                                 : data[pos + 1];
  269|  1.98M|        uint16_t diff2 = uint16_t(next_word - 0xDC00);
  270|  1.98M|        if (diff2 <= 0x3FF) {
  ------------------
  |  Branch (270:13): [True: 31.2k, False: 1.95M]
  ------------------
  271|       |          // valid surrogate pair
  272|  31.2k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  273|       |          // will generate four UTF-8 bytes
  274|  31.2k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  275|  31.2k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  276|  31.2k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  277|  31.2k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  278|  31.2k|          pos += 2;
  279|  31.2k|          continue;
  280|  31.2k|        }
  281|  1.98M|      }
  282|       |      // unpaired surrogate: replace with U+FFFD (0xEF 0xBF 0xBD)
  283|  2.29M|      *utf8_output++ = char(0xef);
  284|  2.29M|      *utf8_output++ = char(0xbf);
  285|  2.29M|      *utf8_output++ = char(0xbd);
  286|  2.29M|      pos++;
  287|  2.29M|    }
  288|  16.7M|  }
  289|  1.35k|  return utf8_output - start;
  290|  1.35k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf88validateEPKcm:
  113|  2.77k|                                                        size_t len) noexcept {
  114|  2.77k|  return validate(reinterpret_cast<const uint8_t *>(buf), len);
  115|  2.77k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf88validateIPKhEEbT_m:
   14|  2.77k|                                                      size_t len) noexcept {
   15|  2.77k|  static_assert(
   16|  2.77k|      std::is_same<typename std::decay<decltype(*data)>::type, uint8_t>::value,
   17|  2.77k|      "dereferencing the data pointer must result in a uint8_t");
   18|  2.77k|  uint64_t pos = 0;
   19|  2.77k|  uint32_t code_point = 0;
   20|  40.1M|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 40.0M, False: 2.35k]
  ------------------
   21|  40.0M|    uint64_t next_pos;
   22|       |#if SIMDUTF_CPLUSPLUS23
   23|       |    if !consteval
   24|       |#endif
   25|  40.0M|    { // check if the next 16 bytes are ascii.
   26|  40.0M|      next_pos = pos + 16;
   27|  40.0M|      if (next_pos <= len) { // if it is safe to read 16 more bytes, check
  ------------------
  |  Branch (27:11): [True: 40.0M, False: 10.4k]
  ------------------
   28|       |                             // that they are ascii
   29|  40.0M|        uint64_t v1{};
   30|  40.0M|        std::memcpy(&v1, data + pos, sizeof(uint64_t));
   31|  40.0M|        uint64_t v2{};
   32|  40.0M|        std::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   33|  40.0M|        uint64_t v{v1 | v2};
   34|  40.0M|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (34:13): [True: 1.53M, False: 38.5M]
  ------------------
   35|  1.53M|          pos = next_pos;
   36|  1.53M|          continue;
   37|  1.53M|        }
   38|  40.0M|      }
   39|  40.0M|    }
   40|       |
   41|  38.5M|    unsigned char byte = data[pos];
   42|       |
   43|  39.5M|    while (byte < 0b10000000) {
  ------------------
  |  Branch (43:12): [True: 1.00M, False: 38.5M]
  ------------------
   44|  1.00M|      if (++pos == len) {
  ------------------
  |  Branch (44:11): [True: 419, False: 1.00M]
  ------------------
   45|    419|        return true;
   46|    419|      }
   47|  1.00M|      byte = data[pos];
   48|  1.00M|    }
   49|       |
   50|  38.5M|    if ((byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (50:9): [True: 445k, False: 38.1M]
  ------------------
   51|   445k|      next_pos = pos + 2;
   52|   445k|      if (next_pos > len) {
  ------------------
  |  Branch (52:11): [True: 0, False: 445k]
  ------------------
   53|      0|        return false;
   54|      0|      }
   55|   445k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (55:11): [True: 0, False: 445k]
  ------------------
   56|      0|        return false;
   57|      0|      }
   58|       |      // range check
   59|   445k|      code_point = (byte & 0b00011111) << 6 | (data[pos + 1] & 0b00111111);
   60|   445k|      if (code_point < 0x80) {
  ------------------
  |  Branch (60:11): [True: 0, False: 445k]
  ------------------
   61|      0|        return false;
   62|      0|      }
   63|  38.1M|    } else if ((byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (63:16): [True: 38.0M, False: 53.1k]
  ------------------
   64|  38.0M|      next_pos = pos + 3;
   65|  38.0M|      if (next_pos > len) {
  ------------------
  |  Branch (65:11): [True: 0, False: 38.0M]
  ------------------
   66|      0|        return false;
   67|      0|      }
   68|  38.0M|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (68:11): [True: 0, False: 38.0M]
  ------------------
   69|      0|        return false;
   70|      0|      }
   71|  38.0M|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (71:11): [True: 0, False: 38.0M]
  ------------------
   72|      0|        return false;
   73|      0|      }
   74|       |      // range check
   75|  38.0M|      code_point = (byte & 0b00001111) << 12 |
   76|  38.0M|                   (data[pos + 1] & 0b00111111) << 6 |
   77|  38.0M|                   (data[pos + 2] & 0b00111111);
   78|  38.0M|      if ((code_point < 0x800) ||
  ------------------
  |  Branch (78:11): [True: 0, False: 38.0M]
  ------------------
   79|  38.0M|          (0xd7ff < code_point && code_point < 0xe000)) {
  ------------------
  |  Branch (79:12): [True: 6.38M, False: 31.6M]
  |  Branch (79:35): [True: 0, False: 6.38M]
  ------------------
   80|      0|        return false;
   81|      0|      }
   82|  38.0M|    } else if ((byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (82:16): [True: 53.1k, False: 0]
  ------------------
   83|  53.1k|      next_pos = pos + 4;
   84|  53.1k|      if (next_pos > len) {
  ------------------
  |  Branch (84:11): [True: 0, False: 53.1k]
  ------------------
   85|      0|        return false;
   86|      0|      }
   87|  53.1k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (87:11): [True: 0, False: 53.1k]
  ------------------
   88|      0|        return false;
   89|      0|      }
   90|  53.1k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (90:11): [True: 0, False: 53.1k]
  ------------------
   91|      0|        return false;
   92|      0|      }
   93|  53.1k|      if ((data[pos + 3] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (93:11): [True: 0, False: 53.1k]
  ------------------
   94|      0|        return false;
   95|      0|      }
   96|       |      // range check
   97|  53.1k|      code_point =
   98|  53.1k|          (byte & 0b00000111) << 18 | (data[pos + 1] & 0b00111111) << 12 |
   99|  53.1k|          (data[pos + 2] & 0b00111111) << 6 | (data[pos + 3] & 0b00111111);
  100|  53.1k|      if (code_point <= 0xffff || 0x10ffff < code_point) {
  ------------------
  |  Branch (100:11): [True: 0, False: 53.1k]
  |  Branch (100:35): [True: 0, False: 53.1k]
  ------------------
  101|      0|        return false;
  102|      0|      }
  103|  53.1k|    } else {
  104|       |      // we may have a continuation
  105|      0|      return false;
  106|      0|    }
  107|  38.5M|    pos = next_pos;
  108|  38.5M|  }
  109|  2.35k|  return true;
  110|  2.77k|}

_ZNK7simdutf8fallback14implementation13validate_utf8EPKcm:
   37|  2.77k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
   38|  2.77k|  return scalar::utf8::validate(buf, len);
   39|  2.77k|}
_ZNK7simdutf8fallback14implementation24utf8_length_from_utf16leEPKDsm:
  457|    497|    const char16_t *input, size_t length) const noexcept {
  458|    497|  return scalar::utf16::utf8_length_from_utf16<endianness::LITTLE>(input,
  459|    497|                                                                   length);
  460|    497|}
_ZNK7simdutf8fallback14implementation24utf8_length_from_utf16beEPKDsm:
  463|    455|    const char16_t *input, size_t length) const noexcept {
  464|    455|  return scalar::utf16::utf8_length_from_utf16<endianness::BIG>(input, length);
  465|    455|}
_ZNK7simdutf8fallback14implementation41utf8_length_from_utf16le_with_replacementEPKDsm:
  488|  1.42k|    const char16_t *input, size_t length) const noexcept {
  489|  1.42k|  return scalar::utf16::utf8_length_from_utf16_with_replacement<
  490|  1.42k|      endianness::LITTLE>(input, length);
  491|  1.42k|}
_ZNK7simdutf8fallback14implementation41utf8_length_from_utf16be_with_replacementEPKDsm:
  495|  1.35k|    const char16_t *input, size_t length) const noexcept {
  496|  1.35k|  return scalar::utf16::utf8_length_from_utf16_with_replacement<
  497|  1.35k|      endianness::BIG>(input, length);
  498|  1.35k|}
_ZNK7simdutf8fallback14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPc:
  502|  1.42k|    const char16_t *input, size_t length, char *utf8_buffer) const noexcept {
  503|  1.42k|  return scalar::utf16_to_utf8::convert_with_replacement<endianness::LITTLE>(
  504|  1.42k|      input, length, utf8_buffer);
  505|  1.42k|}
_ZNK7simdutf8fallback14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPc:
  509|  1.35k|    const char16_t *input, size_t length, char *utf8_buffer) const noexcept {
  510|  1.35k|  return scalar::utf16_to_utf8::convert_with_replacement<endianness::BIG>(
  511|  1.35k|      input, length, utf8_buffer);
  512|  1.35k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split9utf8_headIcEEmPKT_m:
   21|  2.77k|simdutf_really_inline size_t utf8_head(const T *p, size_t len) {
   22|  2.77k|  size_t h = head(p, len);
   23|  2.77k|  if (h != 0) {
  ------------------
  |  Branch (23:7): [True: 109, False: 2.66k]
  ------------------
   24|    169|    for (int i = 0; i < 3 && h < len && (uint8_t(p[h]) & 0xC0) == 0x80; i++) {
  ------------------
  |  Branch (24:21): [True: 169, False: 0]
  |  Branch (24:30): [True: 169, False: 0]
  |  Branch (24:41): [True: 60, False: 109]
  ------------------
   25|     60|      h++;
   26|     60|    }
   27|    109|  }
   28|  2.77k|  return h;
   29|  2.77k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split3allITnDaXadL_ZNS0_21validate_utf8_unsplitEPKcmEEcEEbPKT0_mm:
   57|  2.77k|simdutf_really_inline bool all(const T *p, size_t len, size_t h) {
   58|  2.77k|  if (h != 0 && !out_of_line<F>(p, h)) {
  ------------------
  |  Branch (58:7): [True: 109, False: 2.66k]
  |  Branch (58:17): [True: 0, False: 109]
  ------------------
   59|      0|    return false;
   60|      0|  }
   61|  2.77k|  return F(p + h, len - h);
   62|  2.77k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split11out_of_lineITnDaXadL_ZNS0_21validate_utf8_unsplitEPKcmEEJS5_mEEEDaDpT0_:
   46|    109|simdutf_never_inline auto out_of_line(Args... args) noexcept {
   47|    109|  return F(args...);
   48|    109|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split4headIcEEmPKT_m:
    8|  2.77k|simdutf_really_inline size_t head(const T *p, size_t len) {
    9|  2.77k|  if (len * sizeof(T) < min_bytes) {
  ------------------
  |  Branch (9:7): [True: 2.55k, False: 226]
  ------------------
   10|  2.55k|    return 0;
   11|  2.55k|  }
   12|    226|  const size_t misalignment = reinterpret_cast<uintptr_t>(p) % 64;
   13|    226|  if (misalignment == 0 || misalignment % sizeof(T) != 0) {
  ------------------
  |  Branch (13:7): [True: 117, False: 109]
  |  Branch (13:28): [True: 0, False: 109]
  ------------------
   14|    117|    return 0;
   15|    117|  }
   16|    109|  return (64 - misalignment) / sizeof(T);
   17|    226|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split4headIDsEEmPKT_m:
    8|    952|simdutf_really_inline size_t head(const T *p, size_t len) {
    9|    952|  if (len * sizeof(T) < min_bytes) {
  ------------------
  |  Branch (9:7): [True: 829, False: 123]
  ------------------
   10|    829|    return 0;
   11|    829|  }
   12|    123|  const size_t misalignment = reinterpret_cast<uintptr_t>(p) % 64;
   13|    123|  if (misalignment == 0 || misalignment % sizeof(T) != 0) {
  ------------------
  |  Branch (13:7): [True: 0, False: 123]
  |  Branch (13:28): [True: 0, False: 123]
  ------------------
   14|      0|    return 0;
   15|      0|  }
   16|    123|  return (64 - misalignment) / sizeof(T);
   17|    123|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split3sumITnDaXadL_ZNS0_32utf8_length_from_utf16le_unsplitEPKDsmEEDsEEmPKT0_mm:
   51|    497|simdutf_really_inline size_t sum(const T *p, size_t len, size_t h) {
   52|    497|  const size_t first = h == 0 ? 0 : out_of_line<F>(p, h);
  ------------------
  |  Branch (52:24): [True: 420, False: 77]
  ------------------
   53|    497|  return first + F(p + h, len - h);
   54|    497|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split11out_of_lineITnDaXadL_ZNS0_32utf8_length_from_utf16le_unsplitEPKDsmEEJS5_mEEEDaDpT0_:
   46|     77|simdutf_never_inline auto out_of_line(Args... args) noexcept {
   47|     77|  return F(args...);
   48|     77|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split3sumITnDaXadL_ZNS0_32utf8_length_from_utf16be_unsplitEPKDsmEEDsEEmPKT0_mm:
   51|    455|simdutf_really_inline size_t sum(const T *p, size_t len, size_t h) {
   52|    455|  const size_t first = h == 0 ? 0 : out_of_line<F>(p, h);
  ------------------
  |  Branch (52:24): [True: 409, False: 46]
  ------------------
   53|    455|  return first + F(p + h, len - h);
   54|    455|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split11out_of_lineITnDaXadL_ZNS0_32utf8_length_from_utf16be_unsplitEPKDsmEEJS5_mEEEDaDpT0_:
   46|     46|simdutf_never_inline auto out_of_line(Args... args) noexcept {
   47|     46|  return F(args...);
   48|     46|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113aligned_split9utf8_headIcEEmPKT_m:
   21|  2.77k|simdutf_really_inline size_t utf8_head(const T *p, size_t len) {
   22|  2.77k|  size_t h = head(p, len);
   23|  2.77k|  if (h != 0) {
  ------------------
  |  Branch (23:7): [True: 173, False: 2.60k]
  ------------------
   24|    310|    for (int i = 0; i < 3 && h < len && (uint8_t(p[h]) & 0xC0) == 0x80; i++) {
  ------------------
  |  Branch (24:21): [True: 310, False: 0]
  |  Branch (24:30): [True: 310, False: 0]
  |  Branch (24:41): [True: 137, False: 173]
  ------------------
   25|    137|      h++;
   26|    137|    }
   27|    173|  }
   28|  2.77k|  return h;
   29|  2.77k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113aligned_split3allITnDaXadL_ZNS0_21validate_utf8_unsplitEPKcmEEcEEbPKT0_mm:
   57|  2.77k|simdutf_really_inline bool all(const T *p, size_t len, size_t h) {
   58|  2.77k|  if (h != 0 && !out_of_line<F>(p, h)) {
  ------------------
  |  Branch (58:7): [True: 173, False: 2.60k]
  |  Branch (58:17): [True: 0, False: 173]
  ------------------
   59|      0|    return false;
   60|      0|  }
   61|  2.77k|  return F(p + h, len - h);
   62|  2.77k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113aligned_split11out_of_lineITnDaXadL_ZNS0_21validate_utf8_unsplitEPKcmEEJS5_mEEEDaDpT0_:
   46|    173|simdutf_never_inline auto out_of_line(Args... args) noexcept {
   47|    173|  return F(args...);
   48|    173|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113aligned_split4headIcEEmPKT_m:
    8|  2.77k|simdutf_really_inline size_t head(const T *p, size_t len) {
    9|  2.77k|  if (len * sizeof(T) < min_bytes) {
  ------------------
  |  Branch (9:7): [True: 2.55k, False: 226]
  ------------------
   10|  2.55k|    return 0;
   11|  2.55k|  }
   12|    226|  const size_t misalignment = reinterpret_cast<uintptr_t>(p) % 64;
   13|    226|  if (misalignment == 0 || misalignment % sizeof(T) != 0) {
  ------------------
  |  Branch (13:7): [True: 53, False: 173]
  |  Branch (13:28): [True: 0, False: 173]
  ------------------
   14|     53|    return 0;
   15|     53|  }
   16|    173|  return (64 - misalignment) / sizeof(T);
   17|    226|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EEC2EPKhm:
   36|  2.88k|    : buf{_buf}, len{_len}, lenminusstep{len < STEP_SIZE ? 0 : len - STEP_SIZE},
  ------------------
  |  Branch (36:42): [True: 1.61k, False: 1.26k]
  ------------------
   37|  2.88k|      idx{0} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE14has_full_blockEv:
   45|  2.20M|simdutf_really_inline bool buf_block_reader<STEP_SIZE>::has_full_block() const {
   46|  2.20M|  return idx < lenminusstep;
   47|  2.20M|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE10full_blockEv:
   51|  2.20M|buf_block_reader<STEP_SIZE>::full_block() const {
   52|  2.20M|  return &buf[idx];
   53|  2.20M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE11block_indexEv:
   40|  1.95M|simdutf_really_inline size_t buf_block_reader<STEP_SIZE>::block_index() {
   41|  1.95M|  return idx;
   42|  1.95M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE7advanceEv:
   69|  2.20M|simdutf_really_inline void buf_block_reader<STEP_SIZE>::advance() {
   70|  2.20M|  idx += STEP_SIZE;
   71|  2.20M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EEC2EPKhm:
   36|  2.95k|    : buf{_buf}, len{_len}, lenminusstep{len < STEP_SIZE ? 0 : len - STEP_SIZE},
  ------------------
  |  Branch (36:42): [True: 1.68k, False: 1.26k]
  ------------------
   37|  2.95k|      idx{0} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE14has_full_blockEv:
   45|  2.20M|simdutf_really_inline bool buf_block_reader<STEP_SIZE>::has_full_block() const {
   46|  2.20M|  return idx < lenminusstep;
   47|  2.20M|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE10full_blockEv:
   51|  2.20M|buf_block_reader<STEP_SIZE>::full_block() const {
   52|  2.20M|  return &buf[idx];
   53|  2.20M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE11block_indexEv:
   40|  1.95M|simdutf_really_inline size_t buf_block_reader<STEP_SIZE>::block_index() {
   41|  1.95M|  return idx;
   42|  1.95M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE7advanceEv:
   69|  2.20M|simdutf_really_inline void buf_block_reader<STEP_SIZE>::advance() {
   70|  2.20M|  idx += STEP_SIZE;
   71|  2.20M|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE0EEEmPKDsm:
   10|    574|                                                             size_t size) {
   11|    574|  size_t pos = 0;
   12|       |
   13|    574|  using vector_u16 = simd16<uint16_t>;
   14|    574|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|    574|  const auto one = vector_u16::splat(1);
   17|       |
   18|    574|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|    574|  size_t count = size / N * N;
   22|       |
   23|       |  // in a single iteration the increment is 0, 1 or 2, despite we have
   24|       |  // three additions
   25|    574|  constexpr size_t max_iterations = 65535 / 2;
   26|    574|  size_t iteration = max_iterations;
   27|       |
   28|  1.09M|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 1.09M, False: 574]
  ------------------
   29|  1.09M|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
   30|       |    if constexpr (!match_system(big_endian)) {
   31|       |      input = input.swap_bytes();
   32|       |    }
   33|       |    // 0xd800 .. 0xdbff - low surrogate
   34|       |    // 0xdc00 .. 0xdfff - high surrogate
   35|  1.09M|    const auto is_surrogate = ((input & uint16_t(0xf800)) == uint16_t(0xd800));
   36|       |
   37|       |    // c0 - chars that yield 2- or 3-byte UTF-8 codes
   38|  1.09M|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|  1.09M|    const auto c1 = min(input & uint16_t(0xf800), one);
   42|       |
   43|       |    /*
   44|       |        Explanation how the counting works.
   45|       |
   46|       |        In the case of a non-surrogate character we count:
   47|       |        * always 1 -- see how `count` is initialized above;
   48|       |        * c0 = 1 if the current char yields 2 or 3 bytes;
   49|       |        * c1 = 1 if the current char yields 3 bytes.
   50|       |
   51|       |        Thus, we always have correct count for the current char:
   52|       |        from 1, 2 or 3 bytes.
   53|       |
   54|       |        A trickier part is how we count surrogate pairs. Whether
   55|       |        we encounter a surrogate (low or high), we count it as
   56|       |        3 chars and then minus 1 (`is_surrogate` is -1 or 0).
   57|       |        Each surrogate char yields 2. A surrogate pair, that
   58|       |        is a low surrogate followed by a high one, yields
   59|       |        the expected 4 bytes.
   60|       |
   61|       |        It also correctly handles cases when low surrogate is
   62|       |        processed by the this loop, but high surrogate is counted
   63|       |        by the scalar procedure. The scalar procedure uses exactly
   64|       |        the described approach, thanks to that for valid UTF-16
   65|       |        strings it always count correctly.
   66|       |    */
   67|  1.09M|    v_count += c0;
   68|  1.09M|    v_count += c1;
   69|  1.09M|    v_count += vector_u16(is_surrogate);
   70|       |
   71|  1.09M|    iteration -= 1;
   72|  1.09M|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 1, False: 1.09M]
  ------------------
   73|      1|      count += v_count.sum();
   74|      1|      v_count = vector_u16::zero();
   75|      1|      iteration = max_iterations;
   76|      1|    }
   77|  1.09M|  }
   78|       |
   79|    574|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 574, False: 0]
  ------------------
   80|    574|    count += v_count.sum();
   81|    574|  }
   82|       |
   83|    574|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|    574|                                                                   size - pos);
   85|    574|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE1EEEmPKDsm:
   10|    501|                                                             size_t size) {
   11|    501|  size_t pos = 0;
   12|       |
   13|    501|  using vector_u16 = simd16<uint16_t>;
   14|    501|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|    501|  const auto one = vector_u16::splat(1);
   17|       |
   18|    501|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|    501|  size_t count = size / N * N;
   22|       |
   23|       |  // in a single iteration the increment is 0, 1 or 2, despite we have
   24|       |  // three additions
   25|    501|  constexpr size_t max_iterations = 65535 / 2;
   26|    501|  size_t iteration = max_iterations;
   27|       |
   28|   738k|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 738k, False: 501]
  ------------------
   29|   738k|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
   30|   738k|    if constexpr (!match_system(big_endian)) {
   31|   738k|      input = input.swap_bytes();
   32|   738k|    }
   33|       |    // 0xd800 .. 0xdbff - low surrogate
   34|       |    // 0xdc00 .. 0xdfff - high surrogate
   35|   738k|    const auto is_surrogate = ((input & uint16_t(0xf800)) == uint16_t(0xd800));
   36|       |
   37|       |    // c0 - chars that yield 2- or 3-byte UTF-8 codes
   38|   738k|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|   738k|    const auto c1 = min(input & uint16_t(0xf800), one);
   42|       |
   43|       |    /*
   44|       |        Explanation how the counting works.
   45|       |
   46|       |        In the case of a non-surrogate character we count:
   47|       |        * always 1 -- see how `count` is initialized above;
   48|       |        * c0 = 1 if the current char yields 2 or 3 bytes;
   49|       |        * c1 = 1 if the current char yields 3 bytes.
   50|       |
   51|       |        Thus, we always have correct count for the current char:
   52|       |        from 1, 2 or 3 bytes.
   53|       |
   54|       |        A trickier part is how we count surrogate pairs. Whether
   55|       |        we encounter a surrogate (low or high), we count it as
   56|       |        3 chars and then minus 1 (`is_surrogate` is -1 or 0).
   57|       |        Each surrogate char yields 2. A surrogate pair, that
   58|       |        is a low surrogate followed by a high one, yields
   59|       |        the expected 4 bytes.
   60|       |
   61|       |        It also correctly handles cases when low surrogate is
   62|       |        processed by the this loop, but high surrogate is counted
   63|       |        by the scalar procedure. The scalar procedure uses exactly
   64|       |        the described approach, thanks to that for valid UTF-16
   65|       |        strings it always count correctly.
   66|       |    */
   67|   738k|    v_count += c0;
   68|   738k|    v_count += c1;
   69|   738k|    v_count += vector_u16(is_surrogate);
   70|       |
   71|   738k|    iteration -= 1;
   72|   738k|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 1, False: 738k]
  ------------------
   73|      1|      count += v_count.sum();
   74|      1|      v_count = vector_u16::zero();
   75|      1|      iteration = max_iterations;
   76|      1|    }
   77|   738k|  }
   78|       |
   79|    501|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 501, False: 0]
  ------------------
   80|    501|    count += v_count.sum();
   81|    501|  }
   82|       |
   83|    501|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|    501|                                                                   size - pos);
   85|    501|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1639utf8_length_from_utf16_with_replacementILNS_10endiannessE0EEENS_6resultEPKDsm:
   89|  1.42k|utf8_length_from_utf16_with_replacement(const char16_t *in, size_t size) {
   90|  1.42k|  using vector_u16 = simd16<uint16_t>;
   91|  1.42k|  constexpr size_t N = vector_u16::ELEMENTS;
   92|  1.42k|  if (N + 1 > size) {
  ------------------
  |  Branch (92:7): [True: 492, False: 933]
  ------------------
   93|    492|    return scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
   94|    492|        in, size);
   95|    492|  } // special case for short inputs
   96|    933|  size_t pos = 0;
   97|    933|  bool any_surrogates = false;
   98|       |
   99|    933|  const auto one = vector_u16::splat(1);
  100|       |
  101|    933|  auto v_count = vector_u16::zero();
  102|    933|  auto v_mismatched_count = vector_u16::zero();
  103|       |
  104|    933|  size_t count = 0;
  105|    933|  size_t mismatched_count = 0;
  106|       |
  107|       |  // in a single iteration the increment is 0, 1 or 2, despite we have
  108|       |  // three additions
  109|    933|  constexpr size_t max_iterations = 65535 / 2;
  110|    933|  size_t iteration = max_iterations;
  111|       |
  112|    933|  if (scalar::utf16::is_low_surrogate<big_endian>(in[0])) {
  ------------------
  |  Branch (112:7): [True: 46, False: 887]
  ------------------
  113|     46|    any_surrogates = true;
  114|     46|    mismatched_count += 1;
  115|     46|  }
  116|       |
  117|  2.15M|  for (; pos < (size - 1) / N * N; pos += N) {
  ------------------
  |  Branch (117:10): [True: 2.15M, False: 933]
  ------------------
  118|  2.15M|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
  119|       |    if constexpr (!match_system(big_endian)) {
  120|       |      input = input.swap_bytes();
  121|       |    }
  122|       |    // 0xd800 .. 0xdbff - low surrogate
  123|       |    // 0xdc00 .. 0xdfff - high surrogate
  124|  2.15M|    const auto is_surrogate = ((input & uint16_t(0xf800)) == uint16_t(0xd800));
  125|       |
  126|       |    // c0 - chars that yield 2- or 3-byte UTF-8 codes
  127|  2.15M|    const auto c0 = min(input & uint16_t(0xff80), one);
  128|       |
  129|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
  130|  2.15M|    const auto c1 = min(input & uint16_t(0xf800), one);
  131|       |
  132|  2.15M|    v_count += c0;
  133|  2.15M|    v_count += c1;
  134|  2.15M|    v_count += vector_u16(is_surrogate);
  135|  2.15M|    if (is_surrogate.to_bitmask() != 0 ||
  ------------------
  |  Branch (135:9): [True: 229k, False: 1.92M]
  ------------------
  136|  1.92M|        scalar::utf16::is_low_surrogate<big_endian>(in[pos + N])) {
  ------------------
  |  Branch (136:9): [True: 1.27k, False: 1.92M]
  ------------------
  137|   230k|      any_surrogates = true;
  138|   230k|      auto input_next =
  139|   230k|          vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos + 1));
  140|       |      if constexpr (!match_system(big_endian)) {
  141|       |        input_next = input_next.swap_bytes();
  142|       |      }
  143|       |
  144|   230k|      const auto lb_masked = input & (0xfc00);
  145|   230k|      const auto block_masked = input_next & (0xfc00);
  146|       |
  147|   230k|      const auto lb_is_high = lb_masked == (0xd800);
  148|   230k|      const auto block_is_low = block_masked == (0xdc00);
  149|       |
  150|   230k|      const auto illseq = min(vector_u16(lb_is_high ^ block_is_low), one);
  151|       |
  152|   230k|      v_mismatched_count += illseq;
  153|   230k|    }
  154|       |
  155|  2.15M|    iteration -= 1;
  156|  2.15M|    if (iteration == 0) {
  ------------------
  |  Branch (156:9): [True: 35, False: 2.15M]
  ------------------
  157|     35|      count += v_count.sum();
  158|     35|      v_count = vector_u16::zero();
  159|     35|      mismatched_count += v_mismatched_count.sum();
  160|     35|      v_mismatched_count = vector_u16::zero();
  161|     35|      iteration = max_iterations;
  162|     35|    }
  163|  2.15M|  }
  164|       |
  165|    933|  if (iteration > 0) {
  ------------------
  |  Branch (165:7): [True: 933, False: 0]
  ------------------
  166|    933|    count += v_count.sum();
  167|    933|    mismatched_count += v_mismatched_count.sum();
  168|    933|  }
  169|       |
  170|    933|  if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (170:7): [True: 106, False: 827]
  ------------------
  171|    106|    any_surrogates = true;
  172|    106|    if (!scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (172:9): [True: 84, False: 22]
  ------------------
  173|     84|      mismatched_count -= 1;
  174|     84|      count += 2;
  175|     84|      pos += 1;
  176|     84|    }
  177|    106|  }
  178|    933|  count += pos;
  179|    933|  count += mismatched_count;
  180|    933|  if (scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (180:7): [True: 135, False: 798]
  ------------------
  181|    135|    any_surrogates = true;
  182|    135|    if (pos == size) {
  ------------------
  |  Branch (182:9): [True: 0, False: 135]
  ------------------
  183|      0|      count += 2;
  184|    135|    } else if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (184:16): [True: 22, False: 113]
  ------------------
  185|     22|      pos += 1;
  186|     22|      count += 2;
  187|     22|    }
  188|    135|  }
  189|    933|  result scalar_result =
  190|    933|      scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
  191|    933|          in + pos, size - pos);
  192|    933|  return {any_surrogates ? SURROGATE : scalar_result.error,
  ------------------
  |  Branch (192:11): [True: 537, False: 396]
  ------------------
  193|    933|          count + scalar_result.count};
  194|  1.42k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1639utf8_length_from_utf16_with_replacementILNS_10endiannessE1EEENS_6resultEPKDsm:
   89|  1.35k|utf8_length_from_utf16_with_replacement(const char16_t *in, size_t size) {
   90|  1.35k|  using vector_u16 = simd16<uint16_t>;
   91|  1.35k|  constexpr size_t N = vector_u16::ELEMENTS;
   92|  1.35k|  if (N + 1 > size) {
  ------------------
  |  Branch (92:7): [True: 504, False: 848]
  ------------------
   93|    504|    return scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
   94|    504|        in, size);
   95|    504|  } // special case for short inputs
   96|    848|  size_t pos = 0;
   97|    848|  bool any_surrogates = false;
   98|       |
   99|    848|  const auto one = vector_u16::splat(1);
  100|       |
  101|    848|  auto v_count = vector_u16::zero();
  102|    848|  auto v_mismatched_count = vector_u16::zero();
  103|       |
  104|    848|  size_t count = 0;
  105|    848|  size_t mismatched_count = 0;
  106|       |
  107|       |  // in a single iteration the increment is 0, 1 or 2, despite we have
  108|       |  // three additions
  109|    848|  constexpr size_t max_iterations = 65535 / 2;
  110|    848|  size_t iteration = max_iterations;
  111|       |
  112|    848|  if (scalar::utf16::is_low_surrogate<big_endian>(in[0])) {
  ------------------
  |  Branch (112:7): [True: 54, False: 794]
  ------------------
  113|     54|    any_surrogates = true;
  114|     54|    mismatched_count += 1;
  115|     54|  }
  116|       |
  117|  1.85M|  for (; pos < (size - 1) / N * N; pos += N) {
  ------------------
  |  Branch (117:10): [True: 1.85M, False: 848]
  ------------------
  118|  1.85M|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
  119|  1.85M|    if constexpr (!match_system(big_endian)) {
  120|  1.85M|      input = input.swap_bytes();
  121|  1.85M|    }
  122|       |    // 0xd800 .. 0xdbff - low surrogate
  123|       |    // 0xdc00 .. 0xdfff - high surrogate
  124|  1.85M|    const auto is_surrogate = ((input & uint16_t(0xf800)) == uint16_t(0xd800));
  125|       |
  126|       |    // c0 - chars that yield 2- or 3-byte UTF-8 codes
  127|  1.85M|    const auto c0 = min(input & uint16_t(0xff80), one);
  128|       |
  129|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
  130|  1.85M|    const auto c1 = min(input & uint16_t(0xf800), one);
  131|       |
  132|  1.85M|    v_count += c0;
  133|  1.85M|    v_count += c1;
  134|  1.85M|    v_count += vector_u16(is_surrogate);
  135|  1.85M|    if (is_surrogate.to_bitmask() != 0 ||
  ------------------
  |  Branch (135:9): [True: 228k, False: 1.62M]
  ------------------
  136|  1.62M|        scalar::utf16::is_low_surrogate<big_endian>(in[pos + N])) {
  ------------------
  |  Branch (136:9): [True: 2.14k, False: 1.62M]
  ------------------
  137|   230k|      any_surrogates = true;
  138|   230k|      auto input_next =
  139|   230k|          vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos + 1));
  140|   230k|      if constexpr (!match_system(big_endian)) {
  141|   230k|        input_next = input_next.swap_bytes();
  142|   230k|      }
  143|       |
  144|   230k|      const auto lb_masked = input & (0xfc00);
  145|   230k|      const auto block_masked = input_next & (0xfc00);
  146|       |
  147|   230k|      const auto lb_is_high = lb_masked == (0xd800);
  148|   230k|      const auto block_is_low = block_masked == (0xdc00);
  149|       |
  150|   230k|      const auto illseq = min(vector_u16(lb_is_high ^ block_is_low), one);
  151|       |
  152|   230k|      v_mismatched_count += illseq;
  153|   230k|    }
  154|       |
  155|  1.85M|    iteration -= 1;
  156|  1.85M|    if (iteration == 0) {
  ------------------
  |  Branch (156:9): [True: 35, False: 1.85M]
  ------------------
  157|     35|      count += v_count.sum();
  158|     35|      v_count = vector_u16::zero();
  159|     35|      mismatched_count += v_mismatched_count.sum();
  160|     35|      v_mismatched_count = vector_u16::zero();
  161|     35|      iteration = max_iterations;
  162|     35|    }
  163|  1.85M|  }
  164|       |
  165|    848|  if (iteration > 0) {
  ------------------
  |  Branch (165:7): [True: 848, False: 0]
  ------------------
  166|    848|    count += v_count.sum();
  167|    848|    mismatched_count += v_mismatched_count.sum();
  168|    848|  }
  169|       |
  170|    848|  if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (170:7): [True: 98, False: 750]
  ------------------
  171|     98|    any_surrogates = true;
  172|     98|    if (!scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (172:9): [True: 69, False: 29]
  ------------------
  173|     69|      mismatched_count -= 1;
  174|     69|      count += 2;
  175|     69|      pos += 1;
  176|     69|    }
  177|     98|  }
  178|    848|  count += pos;
  179|    848|  count += mismatched_count;
  180|    848|  if (scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (180:7): [True: 134, False: 714]
  ------------------
  181|    134|    any_surrogates = true;
  182|    134|    if (pos == size) {
  ------------------
  |  Branch (182:9): [True: 0, False: 134]
  ------------------
  183|      0|      count += 2;
  184|    134|    } else if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (184:16): [True: 29, False: 105]
  ------------------
  185|     29|      pos += 1;
  186|     29|      count += 2;
  187|     29|    }
  188|    134|  }
  189|    848|  result scalar_result =
  190|    848|      scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
  191|    848|          in + pos, size - pos);
  192|    848|  return {any_surrogates ? SURROGATE : scalar_result.error,
  ------------------
  |  Branch (192:11): [True: 519, False: 329]
  ------------------
  193|    848|          count + scalar_result.count};
  194|  1.35k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE0EEEmPKDsm:
   10|    497|                                                             size_t size) {
   11|    497|  size_t pos = 0;
   12|       |
   13|    497|  using vector_u16 = simd16<uint16_t>;
   14|    497|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|    497|  const auto one = vector_u16::splat(1);
   17|       |
   18|    497|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|    497|  size_t count = size / N * N;
   22|       |
   23|       |  // in a single iteration the increment is 0, 1 or 2, despite we have
   24|       |  // three additions
   25|    497|  constexpr size_t max_iterations = 65535 / 2;
   26|    497|  size_t iteration = max_iterations;
   27|       |
   28|  2.18M|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 2.18M, False: 497]
  ------------------
   29|  2.18M|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
   30|       |    if constexpr (!match_system(big_endian)) {
   31|       |      input = input.swap_bytes();
   32|       |    }
   33|       |    // 0xd800 .. 0xdbff - low surrogate
   34|       |    // 0xdc00 .. 0xdfff - high surrogate
   35|  2.18M|    const auto is_surrogate = ((input & uint16_t(0xf800)) == uint16_t(0xd800));
   36|       |
   37|       |    // c0 - chars that yield 2- or 3-byte UTF-8 codes
   38|  2.18M|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|  2.18M|    const auto c1 = min(input & uint16_t(0xf800), one);
   42|       |
   43|       |    /*
   44|       |        Explanation how the counting works.
   45|       |
   46|       |        In the case of a non-surrogate character we count:
   47|       |        * always 1 -- see how `count` is initialized above;
   48|       |        * c0 = 1 if the current char yields 2 or 3 bytes;
   49|       |        * c1 = 1 if the current char yields 3 bytes.
   50|       |
   51|       |        Thus, we always have correct count for the current char:
   52|       |        from 1, 2 or 3 bytes.
   53|       |
   54|       |        A trickier part is how we count surrogate pairs. Whether
   55|       |        we encounter a surrogate (low or high), we count it as
   56|       |        3 chars and then minus 1 (`is_surrogate` is -1 or 0).
   57|       |        Each surrogate char yields 2. A surrogate pair, that
   58|       |        is a low surrogate followed by a high one, yields
   59|       |        the expected 4 bytes.
   60|       |
   61|       |        It also correctly handles cases when low surrogate is
   62|       |        processed by the this loop, but high surrogate is counted
   63|       |        by the scalar procedure. The scalar procedure uses exactly
   64|       |        the described approach, thanks to that for valid UTF-16
   65|       |        strings it always count correctly.
   66|       |    */
   67|  2.18M|    v_count += c0;
   68|  2.18M|    v_count += c1;
   69|  2.18M|    v_count += vector_u16(is_surrogate);
   70|       |
   71|  2.18M|    iteration -= 1;
   72|  2.18M|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 50, False: 2.18M]
  ------------------
   73|     50|      count += v_count.sum();
   74|     50|      v_count = vector_u16::zero();
   75|     50|      iteration = max_iterations;
   76|     50|    }
   77|  2.18M|  }
   78|       |
   79|    497|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 497, False: 0]
  ------------------
   80|    497|    count += v_count.sum();
   81|    497|  }
   82|       |
   83|    497|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|    497|                                                                   size - pos);
   85|    497|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE1EEEmPKDsm:
   10|    455|                                                             size_t size) {
   11|    455|  size_t pos = 0;
   12|       |
   13|    455|  using vector_u16 = simd16<uint16_t>;
   14|    455|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|    455|  const auto one = vector_u16::splat(1);
   17|       |
   18|    455|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|    455|  size_t count = size / N * N;
   22|       |
   23|       |  // in a single iteration the increment is 0, 1 or 2, despite we have
   24|       |  // three additions
   25|    455|  constexpr size_t max_iterations = 65535 / 2;
   26|    455|  size_t iteration = max_iterations;
   27|       |
   28|  1.47M|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 1.47M, False: 455]
  ------------------
   29|  1.47M|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
   30|  1.47M|    if constexpr (!match_system(big_endian)) {
   31|  1.47M|      input = input.swap_bytes();
   32|  1.47M|    }
   33|       |    // 0xd800 .. 0xdbff - low surrogate
   34|       |    // 0xdc00 .. 0xdfff - high surrogate
   35|  1.47M|    const auto is_surrogate = ((input & uint16_t(0xf800)) == uint16_t(0xd800));
   36|       |
   37|       |    // c0 - chars that yield 2- or 3-byte UTF-8 codes
   38|  1.47M|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|  1.47M|    const auto c1 = min(input & uint16_t(0xf800), one);
   42|       |
   43|       |    /*
   44|       |        Explanation how the counting works.
   45|       |
   46|       |        In the case of a non-surrogate character we count:
   47|       |        * always 1 -- see how `count` is initialized above;
   48|       |        * c0 = 1 if the current char yields 2 or 3 bytes;
   49|       |        * c1 = 1 if the current char yields 3 bytes.
   50|       |
   51|       |        Thus, we always have correct count for the current char:
   52|       |        from 1, 2 or 3 bytes.
   53|       |
   54|       |        A trickier part is how we count surrogate pairs. Whether
   55|       |        we encounter a surrogate (low or high), we count it as
   56|       |        3 chars and then minus 1 (`is_surrogate` is -1 or 0).
   57|       |        Each surrogate char yields 2. A surrogate pair, that
   58|       |        is a low surrogate followed by a high one, yields
   59|       |        the expected 4 bytes.
   60|       |
   61|       |        It also correctly handles cases when low surrogate is
   62|       |        processed by the this loop, but high surrogate is counted
   63|       |        by the scalar procedure. The scalar procedure uses exactly
   64|       |        the described approach, thanks to that for valid UTF-16
   65|       |        strings it always count correctly.
   66|       |    */
   67|  1.47M|    v_count += c0;
   68|  1.47M|    v_count += c1;
   69|  1.47M|    v_count += vector_u16(is_surrogate);
   70|       |
   71|  1.47M|    iteration -= 1;
   72|  1.47M|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 35, False: 1.47M]
  ------------------
   73|     35|      count += v_count.sum();
   74|     35|      v_count = vector_u16::zero();
   75|     35|      iteration = max_iterations;
   76|     35|    }
   77|  1.47M|  }
   78|       |
   79|    455|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 455, False: 0]
  ------------------
   80|    455|    count += v_count.sum();
   81|    455|  }
   82|       |
   83|    455|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|    455|                                                                   size - pos);
   85|    455|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1639utf8_length_from_utf16_with_replacementILNS_10endiannessE0EEENS_6resultEPKDsm:
   89|  1.42k|utf8_length_from_utf16_with_replacement(const char16_t *in, size_t size) {
   90|  1.42k|  using vector_u16 = simd16<uint16_t>;
   91|  1.42k|  constexpr size_t N = vector_u16::ELEMENTS;
   92|  1.42k|  if (N + 1 > size) {
  ------------------
  |  Branch (92:7): [True: 227, False: 1.19k]
  ------------------
   93|    227|    return scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
   94|    227|        in, size);
   95|    227|  } // special case for short inputs
   96|  1.19k|  size_t pos = 0;
   97|  1.19k|  bool any_surrogates = false;
   98|       |
   99|  1.19k|  const auto one = vector_u16::splat(1);
  100|       |
  101|  1.19k|  auto v_count = vector_u16::zero();
  102|  1.19k|  auto v_mismatched_count = vector_u16::zero();
  103|       |
  104|  1.19k|  size_t count = 0;
  105|  1.19k|  size_t mismatched_count = 0;
  106|       |
  107|       |  // in a single iteration the increment is 0, 1 or 2, despite we have
  108|       |  // three additions
  109|  1.19k|  constexpr size_t max_iterations = 65535 / 2;
  110|  1.19k|  size_t iteration = max_iterations;
  111|       |
  112|  1.19k|  if (scalar::utf16::is_low_surrogate<big_endian>(in[0])) {
  ------------------
  |  Branch (112:7): [True: 72, False: 1.12k]
  ------------------
  113|     72|    any_surrogates = true;
  114|     72|    mismatched_count += 1;
  115|     72|  }
  116|       |
  117|  4.31M|  for (; pos < (size - 1) / N * N; pos += N) {
  ------------------
  |  Branch (117:10): [True: 4.31M, False: 1.19k]
  ------------------
  118|  4.31M|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
  119|       |    if constexpr (!match_system(big_endian)) {
  120|       |      input = input.swap_bytes();
  121|       |    }
  122|       |    // 0xd800 .. 0xdbff - low surrogate
  123|       |    // 0xdc00 .. 0xdfff - high surrogate
  124|  4.31M|    const auto is_surrogate = ((input & uint16_t(0xf800)) == uint16_t(0xd800));
  125|       |
  126|       |    // c0 - chars that yield 2- or 3-byte UTF-8 codes
  127|  4.31M|    const auto c0 = min(input & uint16_t(0xff80), one);
  128|       |
  129|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
  130|  4.31M|    const auto c1 = min(input & uint16_t(0xf800), one);
  131|       |
  132|  4.31M|    v_count += c0;
  133|  4.31M|    v_count += c1;
  134|  4.31M|    v_count += vector_u16(is_surrogate);
  135|  4.31M|    if (is_surrogate.to_bitmask() != 0 ||
  ------------------
  |  Branch (135:9): [True: 415k, False: 3.89M]
  ------------------
  136|  3.89M|        scalar::utf16::is_low_surrogate<big_endian>(in[pos + N])) {
  ------------------
  |  Branch (136:9): [True: 3.47k, False: 3.89M]
  ------------------
  137|   418k|      any_surrogates = true;
  138|   418k|      auto input_next =
  139|   418k|          vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos + 1));
  140|       |      if constexpr (!match_system(big_endian)) {
  141|       |        input_next = input_next.swap_bytes();
  142|       |      }
  143|       |
  144|   418k|      const auto lb_masked = input & (0xfc00);
  145|   418k|      const auto block_masked = input_next & (0xfc00);
  146|       |
  147|   418k|      const auto lb_is_high = lb_masked == (0xd800);
  148|   418k|      const auto block_is_low = block_masked == (0xdc00);
  149|       |
  150|   418k|      const auto illseq = min(vector_u16(lb_is_high ^ block_is_low), one);
  151|       |
  152|   418k|      v_mismatched_count += illseq;
  153|   418k|    }
  154|       |
  155|  4.31M|    iteration -= 1;
  156|  4.31M|    if (iteration == 0) {
  ------------------
  |  Branch (156:9): [True: 92, False: 4.31M]
  ------------------
  157|     92|      count += v_count.sum();
  158|     92|      v_count = vector_u16::zero();
  159|     92|      mismatched_count += v_mismatched_count.sum();
  160|     92|      v_mismatched_count = vector_u16::zero();
  161|     92|      iteration = max_iterations;
  162|     92|    }
  163|  4.31M|  }
  164|       |
  165|  1.19k|  if (iteration > 0) {
  ------------------
  |  Branch (165:7): [True: 1.19k, False: 0]
  ------------------
  166|  1.19k|    count += v_count.sum();
  167|  1.19k|    mismatched_count += v_mismatched_count.sum();
  168|  1.19k|  }
  169|       |
  170|  1.19k|  if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (170:7): [True: 166, False: 1.03k]
  ------------------
  171|    166|    any_surrogates = true;
  172|    166|    if (!scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (172:9): [True: 123, False: 43]
  ------------------
  173|    123|      mismatched_count -= 1;
  174|    123|      count += 2;
  175|    123|      pos += 1;
  176|    123|    }
  177|    166|  }
  178|  1.19k|  count += pos;
  179|  1.19k|  count += mismatched_count;
  180|  1.19k|  if (scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (180:7): [True: 202, False: 996]
  ------------------
  181|    202|    any_surrogates = true;
  182|    202|    if (pos == size) {
  ------------------
  |  Branch (182:9): [True: 0, False: 202]
  ------------------
  183|      0|      count += 2;
  184|    202|    } else if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (184:16): [True: 43, False: 159]
  ------------------
  185|     43|      pos += 1;
  186|     43|      count += 2;
  187|     43|    }
  188|    202|  }
  189|  1.19k|  result scalar_result =
  190|  1.19k|      scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
  191|  1.19k|          in + pos, size - pos);
  192|  1.19k|  return {any_surrogates ? SURROGATE : scalar_result.error,
  ------------------
  |  Branch (192:11): [True: 719, False: 479]
  ------------------
  193|  1.19k|          count + scalar_result.count};
  194|  1.42k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1639utf8_length_from_utf16_with_replacementILNS_10endiannessE1EEENS_6resultEPKDsm:
   89|  1.35k|utf8_length_from_utf16_with_replacement(const char16_t *in, size_t size) {
   90|  1.35k|  using vector_u16 = simd16<uint16_t>;
   91|  1.35k|  constexpr size_t N = vector_u16::ELEMENTS;
   92|  1.35k|  if (N + 1 > size) {
  ------------------
  |  Branch (92:7): [True: 231, False: 1.12k]
  ------------------
   93|    231|    return scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
   94|    231|        in, size);
   95|    231|  } // special case for short inputs
   96|  1.12k|  size_t pos = 0;
   97|  1.12k|  bool any_surrogates = false;
   98|       |
   99|  1.12k|  const auto one = vector_u16::splat(1);
  100|       |
  101|  1.12k|  auto v_count = vector_u16::zero();
  102|  1.12k|  auto v_mismatched_count = vector_u16::zero();
  103|       |
  104|  1.12k|  size_t count = 0;
  105|  1.12k|  size_t mismatched_count = 0;
  106|       |
  107|       |  // in a single iteration the increment is 0, 1 or 2, despite we have
  108|       |  // three additions
  109|  1.12k|  constexpr size_t max_iterations = 65535 / 2;
  110|  1.12k|  size_t iteration = max_iterations;
  111|       |
  112|  1.12k|  if (scalar::utf16::is_low_surrogate<big_endian>(in[0])) {
  ------------------
  |  Branch (112:7): [True: 78, False: 1.04k]
  ------------------
  113|     78|    any_surrogates = true;
  114|     78|    mismatched_count += 1;
  115|     78|  }
  116|       |
  117|  3.71M|  for (; pos < (size - 1) / N * N; pos += N) {
  ------------------
  |  Branch (117:10): [True: 3.71M, False: 1.12k]
  ------------------
  118|  3.71M|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
  119|  3.71M|    if constexpr (!match_system(big_endian)) {
  120|  3.71M|      input = input.swap_bytes();
  121|  3.71M|    }
  122|       |    // 0xd800 .. 0xdbff - low surrogate
  123|       |    // 0xdc00 .. 0xdfff - high surrogate
  124|  3.71M|    const auto is_surrogate = ((input & uint16_t(0xf800)) == uint16_t(0xd800));
  125|       |
  126|       |    // c0 - chars that yield 2- or 3-byte UTF-8 codes
  127|  3.71M|    const auto c0 = min(input & uint16_t(0xff80), one);
  128|       |
  129|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
  130|  3.71M|    const auto c1 = min(input & uint16_t(0xf800), one);
  131|       |
  132|  3.71M|    v_count += c0;
  133|  3.71M|    v_count += c1;
  134|  3.71M|    v_count += vector_u16(is_surrogate);
  135|  3.71M|    if (is_surrogate.to_bitmask() != 0 ||
  ------------------
  |  Branch (135:9): [True: 388k, False: 3.32M]
  ------------------
  136|  3.32M|        scalar::utf16::is_low_surrogate<big_endian>(in[pos + N])) {
  ------------------
  |  Branch (136:9): [True: 5.48k, False: 3.32M]
  ------------------
  137|   393k|      any_surrogates = true;
  138|   393k|      auto input_next =
  139|   393k|          vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos + 1));
  140|   393k|      if constexpr (!match_system(big_endian)) {
  141|   393k|        input_next = input_next.swap_bytes();
  142|   393k|      }
  143|       |
  144|   393k|      const auto lb_masked = input & (0xfc00);
  145|   393k|      const auto block_masked = input_next & (0xfc00);
  146|       |
  147|   393k|      const auto lb_is_high = lb_masked == (0xd800);
  148|   393k|      const auto block_is_low = block_masked == (0xdc00);
  149|       |
  150|   393k|      const auto illseq = min(vector_u16(lb_is_high ^ block_is_low), one);
  151|       |
  152|   393k|      v_mismatched_count += illseq;
  153|   393k|    }
  154|       |
  155|  3.71M|    iteration -= 1;
  156|  3.71M|    if (iteration == 0) {
  ------------------
  |  Branch (156:9): [True: 84, False: 3.71M]
  ------------------
  157|     84|      count += v_count.sum();
  158|     84|      v_count = vector_u16::zero();
  159|     84|      mismatched_count += v_mismatched_count.sum();
  160|     84|      v_mismatched_count = vector_u16::zero();
  161|     84|      iteration = max_iterations;
  162|     84|    }
  163|  3.71M|  }
  164|       |
  165|  1.12k|  if (iteration > 0) {
  ------------------
  |  Branch (165:7): [True: 1.12k, False: 0]
  ------------------
  166|  1.12k|    count += v_count.sum();
  167|  1.12k|    mismatched_count += v_mismatched_count.sum();
  168|  1.12k|  }
  169|       |
  170|  1.12k|  if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (170:7): [True: 173, False: 948]
  ------------------
  171|    173|    any_surrogates = true;
  172|    173|    if (!scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (172:9): [True: 120, False: 53]
  ------------------
  173|    120|      mismatched_count -= 1;
  174|    120|      count += 2;
  175|    120|      pos += 1;
  176|    120|    }
  177|    173|  }
  178|  1.12k|  count += pos;
  179|  1.12k|  count += mismatched_count;
  180|  1.12k|  if (scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (180:7): [True: 205, False: 916]
  ------------------
  181|    205|    any_surrogates = true;
  182|    205|    if (pos == size) {
  ------------------
  |  Branch (182:9): [True: 0, False: 205]
  ------------------
  183|      0|      count += 2;
  184|    205|    } else if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (184:16): [True: 53, False: 152]
  ------------------
  185|     53|      pos += 1;
  186|     53|      count += 2;
  187|     53|    }
  188|    205|  }
  189|  1.12k|  result scalar_result =
  190|  1.12k|      scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
  191|  1.12k|          in + pos, size - pos);
  192|  1.12k|  return {any_surrogates ? SURROGATE : scalar_result.error,
  ------------------
  |  Branch (192:11): [True: 713, False: 408]
  ------------------
  193|  1.12k|          count + scalar_result.count};
  194|  1.35k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf16_to_utf828convert_with_replacement_viaIZNKS0_14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPcE3$_0EEmT_S6_mS7_:
   15|  1.42k|    char *utf8_output) {
   16|  1.42k|  char *const start = utf8_output;
   17|  1.42k|  size_t pos = 0;
   18|  2.78M|  while (pos < len) {
  ------------------
  |  Branch (18:10): [True: 2.78M, False: 372]
  ------------------
   19|  2.78M|    full_result r = convert_with_details(buf + pos, len - pos, utf8_output);
   20|  2.78M|    utf8_output += r.output_count;
   21|  2.78M|    if (r.error != error_code::SURROGATE) {
  ------------------
  |  Branch (21:9): [True: 1.05k, False: 2.78M]
  ------------------
   22|  1.05k|      break;
   23|  1.05k|    }
   24|  2.78M|    pos += r.input_count + 1;
   25|  2.78M|    utf8_output[0] = char(0xef);
   26|  2.78M|    utf8_output[1] = char(0xbf);
   27|  2.78M|    utf8_output[2] = char(0xbd);
   28|  2.78M|    utf8_output += 3;
   29|  2.78M|  }
   30|  1.42k|  return size_t(utf8_output - start);
   31|  1.42k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf16_to_utf828convert_with_replacement_viaIZNKS0_14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPcE3$_0EEmT_S6_mS7_:
   15|  1.35k|    char *utf8_output) {
   16|  1.35k|  char *const start = utf8_output;
   17|  1.35k|  size_t pos = 0;
   18|  2.29M|  while (pos < len) {
  ------------------
  |  Branch (18:10): [True: 2.29M, False: 333]
  ------------------
   19|  2.29M|    full_result r = convert_with_details(buf + pos, len - pos, utf8_output);
   20|  2.29M|    utf8_output += r.output_count;
   21|  2.29M|    if (r.error != error_code::SURROGATE) {
  ------------------
  |  Branch (21:9): [True: 1.01k, False: 2.29M]
  ------------------
   22|  1.01k|      break;
   23|  1.01k|    }
   24|  2.29M|    pos += r.input_count + 1;
   25|  2.29M|    utf8_output[0] = char(0xef);
   26|  2.29M|    utf8_output[1] = char(0xbf);
   27|  2.29M|    utf8_output[2] = char(0xbd);
   28|  2.29M|    utf8_output += 3;
   29|  2.29M|  }
   30|  1.35k|  return size_t(utf8_output - start);
   31|  1.35k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf16_to_utf828convert_with_replacement_viaIZNKS0_14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPcE3$_0EEmT_S6_mS7_:
   15|  1.42k|    char *utf8_output) {
   16|  1.42k|  char *const start = utf8_output;
   17|  1.42k|  size_t pos = 0;
   18|  2.78M|  while (pos < len) {
  ------------------
  |  Branch (18:10): [True: 2.78M, False: 372]
  ------------------
   19|  2.78M|    full_result r = convert_with_details(buf + pos, len - pos, utf8_output);
   20|  2.78M|    utf8_output += r.output_count;
   21|  2.78M|    if (r.error != error_code::SURROGATE) {
  ------------------
  |  Branch (21:9): [True: 1.05k, False: 2.78M]
  ------------------
   22|  1.05k|      break;
   23|  1.05k|    }
   24|  2.78M|    pos += r.input_count + 1;
   25|  2.78M|    utf8_output[0] = char(0xef);
   26|  2.78M|    utf8_output[1] = char(0xbf);
   27|  2.78M|    utf8_output[2] = char(0xbd);
   28|  2.78M|    utf8_output += 3;
   29|  2.78M|  }
   30|  1.42k|  return size_t(utf8_output - start);
   31|  1.42k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf16_to_utf828convert_with_replacement_viaIZNKS0_14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPcE3$_0EEmT_S6_mS7_:
   15|  1.35k|    char *utf8_output) {
   16|  1.35k|  char *const start = utf8_output;
   17|  1.35k|  size_t pos = 0;
   18|  2.29M|  while (pos < len) {
  ------------------
  |  Branch (18:10): [True: 2.29M, False: 333]
  ------------------
   19|  2.29M|    full_result r = convert_with_details(buf + pos, len - pos, utf8_output);
   20|  2.29M|    utf8_output += r.output_count;
   21|  2.29M|    if (r.error != error_code::SURROGATE) {
  ------------------
  |  Branch (21:9): [True: 1.01k, False: 2.29M]
  ------------------
   22|  1.01k|      break;
   23|  1.01k|    }
   24|  2.29M|    pos += r.input_count + 1;
   25|  2.29M|    utf8_output[0] = char(0xef);
   26|  2.29M|    utf8_output[1] = char(0xbf);
   27|  2.29M|    utf8_output[2] = char(0xbd);
   28|  2.29M|    utf8_output += 3;
   29|  2.29M|  }
   30|  1.35k|  return size_t(utf8_output - start);
   31|  1.35k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker9check_eofEv:
  207|  2.88k|  simdutf_really_inline void check_eof() {
  208|       |    // If the previous block had incomplete UTF-8 characters at the end, an
  209|       |    // ASCII block can't possibly finish them.
  210|  2.88k|    this->error |= this->prev_incomplete;
  211|  2.88k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker16check_next_inputERKNS1_4simd8simd8x64IhEE:
  215|  2.20M|  simdutf_really_inline bool check_next_input(const simd8x64<uint8_t> &input) {
  216|  2.20M|    if (simdutf_likely(is_ascii(input))) {
  ------------------
  |  |   90|  2.20M|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 367k, False: 1.83M]
  |  |  ------------------
  ------------------
  217|   367k|      this->error |= this->prev_incomplete;
  218|   367k|      return true;
  219|  1.83M|    } else {
  220|       |      // you might think that a for-loop would work, but under Visual Studio, it
  221|       |      // is not good enough.
  222|  1.83M|      static_assert((simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  223|  1.83M|                        (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  224|  1.83M|                    "We support either two or four chunks per 64-byte block.");
  225|  1.83M|      if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  226|  1.83M|        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  227|  1.83M|        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  228|       |      } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  229|       |        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  230|       |        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  231|       |        this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  232|       |        this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  233|       |      }
  234|  1.83M|      this->prev_incomplete =
  235|  1.83M|          is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1]);
  236|  1.83M|      this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1];
  237|  1.83M|      return false;
  238|  1.83M|    }
  239|  2.20M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  195|  3.67M|                                              const simd8<uint8_t> prev_input) {
  196|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  197|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  198|       |    // small negative numbers)
  199|  3.67M|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  200|  3.67M|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  201|  3.67M|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  202|  3.67M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation19check_special_casesENS1_4simd5simd8IhEES5_:
    9|  3.67M|check_special_cases(const simd8<uint8_t> input, const simd8<uint8_t> prev1) {
   10|       |  // Bit 0 = Too Short (lead byte/ASCII followed by lead byte/ASCII)
   11|       |  // Bit 1 = Too Long (ASCII followed by continuation)
   12|       |  // Bit 2 = Overlong 3-byte
   13|       |  // Bit 4 = Surrogate
   14|       |  // Bit 5 = Overlong 2-byte
   15|       |  // Bit 7 = Two Continuations
   16|  3.67M|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   17|       |                                               // 11______ 11______
   18|  3.67M|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   19|  3.67M|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   20|  3.67M|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   21|  3.67M|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   22|  3.67M|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   23|  3.67M|  constexpr const uint8_t TOO_LARGE = 1 << 3;  // 11110100 1001____
   24|       |                                               // 11110100 101_____
   25|       |                                               // 11110101 1001____
   26|       |                                               // 11110101 101_____
   27|       |                                               // 1111011_ 1001____
   28|       |                                               // 1111011_ 101_____
   29|       |                                               // 11111___ 1001____
   30|       |                                               // 11111___ 101_____
   31|  3.67M|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   32|       |  // 11110101 1000____
   33|       |  // 1111011_ 1000____
   34|       |  // 11111___ 1000____
   35|  3.67M|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   36|       |
   37|  3.67M|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   38|       |      // 0_______ ________ <ASCII in byte 1>
   39|  3.67M|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   40|  3.67M|      TOO_LONG,
   41|       |      // 10______ ________ <continuation in byte 1>
   42|  3.67M|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   43|       |      // 1100____ ________ <two byte lead in byte 1>
   44|  3.67M|      TOO_SHORT | OVERLONG_2,
   45|       |      // 1101____ ________ <two byte lead in byte 1>
   46|  3.67M|      TOO_SHORT,
   47|       |      // 1110____ ________ <three byte lead in byte 1>
   48|  3.67M|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   49|       |      // 1111____ ________ <four+ byte lead in byte 1>
   50|  3.67M|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   51|  3.67M|  constexpr const uint8_t CARRY =
   52|  3.67M|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   53|  3.67M|  const simd8<uint8_t> byte_1_low =
   54|  3.67M|      (prev1 & 0x0F)
   55|  3.67M|          .lookup_16<uint8_t>(
   56|       |              // ____0000 ________
   57|  3.67M|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   58|       |              // ____0001 ________
   59|  3.67M|              CARRY | OVERLONG_2,
   60|       |              // ____001_ ________
   61|  3.67M|              CARRY, CARRY,
   62|       |
   63|       |              // ____0100 ________
   64|  3.67M|              CARRY | TOO_LARGE,
   65|       |              // ____0101 ________
   66|  3.67M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   67|       |              // ____011_ ________
   68|  3.67M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|  3.67M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   70|       |
   71|       |              // ____1___ ________
   72|  3.67M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  3.67M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  3.67M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  3.67M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|  3.67M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   77|       |              // ____1101 ________
   78|  3.67M|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   79|  3.67M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   80|  3.67M|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   81|  3.67M|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   82|       |      // ________ 0_______ <ASCII in byte 2>
   83|  3.67M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   84|  3.67M|      TOO_SHORT, TOO_SHORT,
   85|       |
   86|       |      // ________ 1000____
   87|  3.67M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   88|  3.67M|          OVERLONG_4,
   89|       |      // ________ 1001____
   90|  3.67M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   91|       |      // ________ 101_____
   92|  3.67M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|  3.67M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   94|       |
   95|       |      // ________ 11______
   96|  3.67M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   97|  3.67M|  return (byte_1_high & byte_1_low & byte_2_high);
   98|  3.67M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation23check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  102|  3.67M|                        const simd8<uint8_t> sc) {
  103|  3.67M|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  104|  3.67M|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  105|  3.67M|  simd8<uint8_t> must23 =
  106|  3.67M|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  107|  3.67M|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  108|  3.67M|  return must23_80 ^ sc;
  109|  3.67M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation13is_incompleteENS1_4simd5simd8IhEE:
  115|  1.83M|simdutf_really_inline simd8<uint8_t> is_incomplete(const simd8<uint8_t> input) {
  116|       |  // If the previous input's last 3 bytes match this, they're too short (they
  117|       |  // ended at EOF):
  118|       |  // ... 1111____ 111_____ 11______
  119|  1.83M|  static const uint8_t max_array[32] = {255,
  120|  1.83M|                                        255,
  121|  1.83M|                                        255,
  122|  1.83M|                                        255,
  123|  1.83M|                                        255,
  124|  1.83M|                                        255,
  125|  1.83M|                                        255,
  126|  1.83M|                                        255,
  127|  1.83M|                                        255,
  128|  1.83M|                                        255,
  129|  1.83M|                                        255,
  130|  1.83M|                                        255,
  131|  1.83M|                                        255,
  132|  1.83M|                                        255,
  133|  1.83M|                                        255,
  134|  1.83M|                                        255,
  135|  1.83M|                                        255,
  136|  1.83M|                                        255,
  137|  1.83M|                                        255,
  138|  1.83M|                                        255,
  139|  1.83M|                                        255,
  140|  1.83M|                                        255,
  141|  1.83M|                                        255,
  142|  1.83M|                                        255,
  143|  1.83M|                                        255,
  144|  1.83M|                                        255,
  145|  1.83M|                                        255,
  146|  1.83M|                                        255,
  147|  1.83M|                                        255,
  148|  1.83M|                                        0b11110000u - 1,
  149|  1.83M|                                        0b11100000u - 1,
  150|  1.83M|                                        0b11000000u - 1};
  151|  1.83M|  const simd8<uint8_t> max_value(
  152|  1.83M|      &max_array[sizeof(max_array) - sizeof(simd8<uint8_t>)]);
  153|  1.83M|  return input.gt_bits(max_value);
  154|  1.83M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker23check_overlapping_inputERKNS1_4simd8simd8x64IhEENS4_5simd8IhEE:
  246|    859|                          const simd8<uint8_t> prev_input) {
  247|    859|    this->prev_input_block = prev_input;
  248|    859|    this->check_next_input(input);
  249|    859|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker6errorsEv:
  252|   119k|  simdutf_really_inline bool errors() const {
  253|   119k|    return this->error.any_bits_set_anywhere();
  254|   119k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker9check_eofEv:
  207|  2.95k|  simdutf_really_inline void check_eof() {
  208|       |    // If the previous block had incomplete UTF-8 characters at the end, an
  209|       |    // ASCII block can't possibly finish them.
  210|  2.95k|    this->error |= this->prev_incomplete;
  211|  2.95k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker16check_next_inputERKNS1_4simd8simd8x64IhEE:
  215|  2.20M|  simdutf_really_inline bool check_next_input(const simd8x64<uint8_t> &input) {
  216|  2.20M|    if (simdutf_likely(is_ascii(input))) {
  ------------------
  |  |   90|  2.20M|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 367k, False: 1.83M]
  |  |  ------------------
  ------------------
  217|   367k|      this->error |= this->prev_incomplete;
  218|   367k|      return true;
  219|  1.83M|    } else {
  220|       |      // you might think that a for-loop would work, but under Visual Studio, it
  221|       |      // is not good enough.
  222|  1.83M|      static_assert((simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  223|  1.83M|                        (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  224|  1.83M|                    "We support either two or four chunks per 64-byte block.");
  225|       |      if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  226|       |        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  227|       |        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  228|  1.83M|      } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  229|  1.83M|        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  230|  1.83M|        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  231|  1.83M|        this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  232|  1.83M|        this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  233|  1.83M|      }
  234|  1.83M|      this->prev_incomplete =
  235|  1.83M|          is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1]);
  236|  1.83M|      this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1];
  237|  1.83M|      return false;
  238|  1.83M|    }
  239|  2.20M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  195|  7.34M|                                              const simd8<uint8_t> prev_input) {
  196|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  197|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  198|       |    // small negative numbers)
  199|  7.34M|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  200|  7.34M|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  201|  7.34M|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  202|  7.34M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation19check_special_casesENS1_4simd5simd8IhEES5_:
    9|  7.34M|check_special_cases(const simd8<uint8_t> input, const simd8<uint8_t> prev1) {
   10|       |  // Bit 0 = Too Short (lead byte/ASCII followed by lead byte/ASCII)
   11|       |  // Bit 1 = Too Long (ASCII followed by continuation)
   12|       |  // Bit 2 = Overlong 3-byte
   13|       |  // Bit 4 = Surrogate
   14|       |  // Bit 5 = Overlong 2-byte
   15|       |  // Bit 7 = Two Continuations
   16|  7.34M|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   17|       |                                               // 11______ 11______
   18|  7.34M|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   19|  7.34M|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   20|  7.34M|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   21|  7.34M|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   22|  7.34M|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   23|  7.34M|  constexpr const uint8_t TOO_LARGE = 1 << 3;  // 11110100 1001____
   24|       |                                               // 11110100 101_____
   25|       |                                               // 11110101 1001____
   26|       |                                               // 11110101 101_____
   27|       |                                               // 1111011_ 1001____
   28|       |                                               // 1111011_ 101_____
   29|       |                                               // 11111___ 1001____
   30|       |                                               // 11111___ 101_____
   31|  7.34M|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   32|       |  // 11110101 1000____
   33|       |  // 1111011_ 1000____
   34|       |  // 11111___ 1000____
   35|  7.34M|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   36|       |
   37|  7.34M|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   38|       |      // 0_______ ________ <ASCII in byte 1>
   39|  7.34M|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   40|  7.34M|      TOO_LONG,
   41|       |      // 10______ ________ <continuation in byte 1>
   42|  7.34M|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   43|       |      // 1100____ ________ <two byte lead in byte 1>
   44|  7.34M|      TOO_SHORT | OVERLONG_2,
   45|       |      // 1101____ ________ <two byte lead in byte 1>
   46|  7.34M|      TOO_SHORT,
   47|       |      // 1110____ ________ <three byte lead in byte 1>
   48|  7.34M|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   49|       |      // 1111____ ________ <four+ byte lead in byte 1>
   50|  7.34M|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   51|  7.34M|  constexpr const uint8_t CARRY =
   52|  7.34M|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   53|  7.34M|  const simd8<uint8_t> byte_1_low =
   54|  7.34M|      (prev1 & 0x0F)
   55|  7.34M|          .lookup_16<uint8_t>(
   56|       |              // ____0000 ________
   57|  7.34M|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   58|       |              // ____0001 ________
   59|  7.34M|              CARRY | OVERLONG_2,
   60|       |              // ____001_ ________
   61|  7.34M|              CARRY, CARRY,
   62|       |
   63|       |              // ____0100 ________
   64|  7.34M|              CARRY | TOO_LARGE,
   65|       |              // ____0101 ________
   66|  7.34M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   67|       |              // ____011_ ________
   68|  7.34M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|  7.34M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   70|       |
   71|       |              // ____1___ ________
   72|  7.34M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  7.34M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  7.34M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  7.34M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|  7.34M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   77|       |              // ____1101 ________
   78|  7.34M|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   79|  7.34M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   80|  7.34M|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   81|  7.34M|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   82|       |      // ________ 0_______ <ASCII in byte 2>
   83|  7.34M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   84|  7.34M|      TOO_SHORT, TOO_SHORT,
   85|       |
   86|       |      // ________ 1000____
   87|  7.34M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   88|  7.34M|          OVERLONG_4,
   89|       |      // ________ 1001____
   90|  7.34M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   91|       |      // ________ 101_____
   92|  7.34M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|  7.34M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   94|       |
   95|       |      // ________ 11______
   96|  7.34M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   97|  7.34M|  return (byte_1_high & byte_1_low & byte_2_high);
   98|  7.34M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation23check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  102|  7.34M|                        const simd8<uint8_t> sc) {
  103|  7.34M|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  104|  7.34M|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  105|  7.34M|  simd8<uint8_t> must23 =
  106|  7.34M|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  107|  7.34M|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  108|  7.34M|  return must23_80 ^ sc;
  109|  7.34M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation13is_incompleteENS1_4simd5simd8IhEE:
  115|  1.83M|simdutf_really_inline simd8<uint8_t> is_incomplete(const simd8<uint8_t> input) {
  116|       |  // If the previous input's last 3 bytes match this, they're too short (they
  117|       |  // ended at EOF):
  118|       |  // ... 1111____ 111_____ 11______
  119|  1.83M|  static const uint8_t max_array[32] = {255,
  120|  1.83M|                                        255,
  121|  1.83M|                                        255,
  122|  1.83M|                                        255,
  123|  1.83M|                                        255,
  124|  1.83M|                                        255,
  125|  1.83M|                                        255,
  126|  1.83M|                                        255,
  127|  1.83M|                                        255,
  128|  1.83M|                                        255,
  129|  1.83M|                                        255,
  130|  1.83M|                                        255,
  131|  1.83M|                                        255,
  132|  1.83M|                                        255,
  133|  1.83M|                                        255,
  134|  1.83M|                                        255,
  135|  1.83M|                                        255,
  136|  1.83M|                                        255,
  137|  1.83M|                                        255,
  138|  1.83M|                                        255,
  139|  1.83M|                                        255,
  140|  1.83M|                                        255,
  141|  1.83M|                                        255,
  142|  1.83M|                                        255,
  143|  1.83M|                                        255,
  144|  1.83M|                                        255,
  145|  1.83M|                                        255,
  146|  1.83M|                                        255,
  147|  1.83M|                                        255,
  148|  1.83M|                                        0b11110000u - 1,
  149|  1.83M|                                        0b11100000u - 1,
  150|  1.83M|                                        0b11000000u - 1};
  151|  1.83M|  const simd8<uint8_t> max_value(
  152|  1.83M|      &max_array[sizeof(max_array) - sizeof(simd8<uint8_t>)]);
  153|  1.83M|  return input.gt_bits(max_value);
  154|  1.83M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker23check_overlapping_inputERKNS1_4simd8simd8x64IhEENS4_5simd8IhEE:
  246|    944|                          const simd8<uint8_t> prev_input) {
  247|    944|    this->prev_input_block = prev_input;
  248|    944|    this->check_next_input(input);
  249|    944|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker6errorsEv:
  252|   119k|  simdutf_really_inline bool errors() const {
  253|   119k|    return this->error.any_bits_set_anywhere();
  254|   119k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation21generic_validate_utf8EPKcm:
   65|  2.88k|bool generic_validate_utf8(const char *input, size_t length) {
   66|  2.88k|  return generic_validate_utf8<utf8_checker>(
   67|  2.88k|      reinterpret_cast<const uint8_t *>(input), length);
   68|  2.88k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation21generic_validate_utf8INS2_12utf8_checkerEEEbPKhm:
   46|  2.88k|bool generic_validate_utf8(const uint8_t *input, size_t length) {
   47|  2.88k|  checker c{};
   48|  2.88k|  buf_block_reader<64> reader(input, length);
   49|  2.88k|  size_t next_check = 1024;
   50|  2.20M|  while (reader.has_full_block()) {
  ------------------
  |  Branch (50:10): [True: 2.20M, False: 2.88k]
  ------------------
   51|  2.20M|    simd::simd8x64<uint8_t> in(reader.full_block());
   52|  2.20M|    if (!c.check_next_input(in) &&
  ------------------
  |  Branch (52:9): [True: 1.83M, False: 367k]
  ------------------
   53|  1.83M|        simdutf_unlikely(reader.block_index() >= next_check)) {
  ------------------
  |  |   93|  1.83M|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 116k, False: 1.71M]
  |  |  ------------------
  ------------------
   54|   116k|      if (c.errors()) {
  ------------------
  |  Branch (54:11): [True: 0, False: 116k]
  ------------------
   55|      0|        return false;
   56|      0|      }
   57|   116k|      next_check = reader.block_index() + 1024;
   58|   116k|    }
   59|  2.20M|    reader.advance();
   60|  2.20M|  }
   61|  2.88k|  check_remainder(c, input, length, reader.block_index());
   62|  2.88k|  return !c.errors();
   63|  2.88k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation15check_remainderINS2_12utf8_checkerEEEvRT_PKhmm:
   15|  2.88k|                                           size_t length, size_t idx) {
   16|  2.88k|  constexpr size_t block = sizeof(simd::simd8x64<uint8_t>);
   17|  2.88k|  constexpr size_t width = sizeof(simd::simd8<uint8_t>);
   18|  2.88k|  static_assert(block == 8 * sizeof(uint64_t), "one mask bit per byte");
   19|  2.88k|  if (length >= block + width) {
  ------------------
  |  Branch (19:7): [True: 991, False: 1.89k]
  ------------------
   20|       |    // The window starts at or before idx: buf_block_reader leaves 1 to 64
   21|       |    // bytes, so 0 <= idx - start < 64.
   22|    991|    const size_t start = length - block;
   23|    991|    const simd::simd8x64<uint8_t> in(input + start);
   24|       |    // Bit i is set if byte start + i is not ASCII, so the bytes from idx on
   25|       |    // are the top length - idx bits. is_ascii() goes first because GCC, up
   26|       |    // to at least GCC 17, builds gteq_unsigned(0x80) from min and compare
   27|       |    // instead of one movemask, which costs ASCII tails about 0.5 ns.
   28|    991|    if (!in.is_ascii() && (in.gteq_unsigned(0x80) >> (idx - start)) != 0) {
  ------------------
  |  Branch (28:9): [True: 881, False: 110]
  |  Branch (28:27): [True: 859, False: 22]
  ------------------
   29|    859|      c.check_overlapping_input(in,
   30|    859|                                simd::simd8<uint8_t>(input + start - width));
   31|    859|    }
   32|  1.89k|  } else if (idx != length) {
  ------------------
  |  Branch (32:14): [True: 1.89k, False: 4]
  ------------------
   33|       |    // Only an empty input leaves no bytes. Its pointer may be null, and
   34|       |    // memcpy from a null pointer is undefined.
   35|  1.89k|    uint8_t buffer[block]{};
   36|  1.89k|    std::memcpy(buffer, input + idx, length - idx);
   37|  1.89k|    c.check_next_input(simd::simd8x64<uint8_t>(buffer));
   38|  1.89k|  }
   39|  2.88k|  c.check_eof();
   40|  2.88k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation21generic_validate_utf8EPKcm:
   65|  2.95k|bool generic_validate_utf8(const char *input, size_t length) {
   66|  2.95k|  return generic_validate_utf8<utf8_checker>(
   67|  2.95k|      reinterpret_cast<const uint8_t *>(input), length);
   68|  2.95k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation21generic_validate_utf8INS2_12utf8_checkerEEEbPKhm:
   46|  2.95k|bool generic_validate_utf8(const uint8_t *input, size_t length) {
   47|  2.95k|  checker c{};
   48|  2.95k|  buf_block_reader<64> reader(input, length);
   49|  2.95k|  size_t next_check = 1024;
   50|  2.20M|  while (reader.has_full_block()) {
  ------------------
  |  Branch (50:10): [True: 2.20M, False: 2.95k]
  ------------------
   51|  2.20M|    simd::simd8x64<uint8_t> in(reader.full_block());
   52|  2.20M|    if (!c.check_next_input(in) &&
  ------------------
  |  Branch (52:9): [True: 1.83M, False: 367k]
  ------------------
   53|  1.83M|        simdutf_unlikely(reader.block_index() >= next_check)) {
  ------------------
  |  |   93|  1.83M|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 116k, False: 1.71M]
  |  |  ------------------
  ------------------
   54|   116k|      if (c.errors()) {
  ------------------
  |  Branch (54:11): [True: 0, False: 116k]
  ------------------
   55|      0|        return false;
   56|      0|      }
   57|   116k|      next_check = reader.block_index() + 1024;
   58|   116k|    }
   59|  2.20M|    reader.advance();
   60|  2.20M|  }
   61|  2.95k|  check_remainder(c, input, length, reader.block_index());
   62|  2.95k|  return !c.errors();
   63|  2.95k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation15check_remainderINS2_12utf8_checkerEEEvRT_PKhmm:
   15|  2.95k|                                           size_t length, size_t idx) {
   16|  2.95k|  constexpr size_t block = sizeof(simd::simd8x64<uint8_t>);
   17|  2.95k|  constexpr size_t width = sizeof(simd::simd8<uint8_t>);
   18|  2.95k|  static_assert(block == 8 * sizeof(uint64_t), "one mask bit per byte");
   19|  2.95k|  if (length >= block + width) {
  ------------------
  |  Branch (19:7): [True: 1.07k, False: 1.87k]
  ------------------
   20|       |    // The window starts at or before idx: buf_block_reader leaves 1 to 64
   21|       |    // bytes, so 0 <= idx - start < 64.
   22|  1.07k|    const size_t start = length - block;
   23|  1.07k|    const simd::simd8x64<uint8_t> in(input + start);
   24|       |    // Bit i is set if byte start + i is not ASCII, so the bytes from idx on
   25|       |    // are the top length - idx bits. is_ascii() goes first because GCC, up
   26|       |    // to at least GCC 17, builds gteq_unsigned(0x80) from min and compare
   27|       |    // instead of one movemask, which costs ASCII tails about 0.5 ns.
   28|  1.07k|    if (!in.is_ascii() && (in.gteq_unsigned(0x80) >> (idx - start)) != 0) {
  ------------------
  |  Branch (28:9): [True: 968, False: 111]
  |  Branch (28:27): [True: 944, False: 24]
  ------------------
   29|    944|      c.check_overlapping_input(in,
   30|    944|                                simd::simd8<uint8_t>(input + start - width));
   31|    944|    }
   32|  1.87k|  } else if (idx != length) {
  ------------------
  |  Branch (32:14): [True: 1.86k, False: 4]
  ------------------
   33|       |    // Only an empty input leaves no bytes. Its pointer may be null, and
   34|       |    // memcpy from a null pointer is undefined.
   35|  1.86k|    uint8_t buffer[block]{};
   36|  1.86k|    std::memcpy(buffer, input + idx, length - idx);
   37|  1.86k|    c.check_next_input(simd::simd8x64<uint8_t>(buffer));
   38|  1.86k|  }
   39|  2.95k|  c.check_eof();
   40|  2.95k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_138avx2_convert_utf16_to_utf8_with_errorsILNS_10endiannessE0EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
  333|  2.78M|                                       char *utf8_output) {
  334|  2.78M|  const char16_t *start = buf;
  335|  2.78M|  const char16_t *end = buf + len;
  336|       |
  337|  2.78M|  const __m256i v_0000 = _mm256_setzero_si256();
  338|  2.78M|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
  339|  2.78M|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
  340|  2.78M|  const __m256i v_c080 = _mm256_set1_epi16((int16_t)0xc080);
  341|  2.78M|  const size_t safety_margin =
  342|  2.78M|      12; // to avoid overruns, see issue
  343|       |          // https://github.com/simdutf/simdutf/issues/92
  344|       |
  345|  4.73M|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (345:10): [True: 4.73M, False: 4.84k]
  ------------------
  346|  4.73M|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
  347|  4.73M|    if (big_endian) {
  ------------------
  |  Branch (347:9): [Folded, False: 4.73M]
  ------------------
  348|      0|      const __m256i swap = _mm256_setr_epi8(
  349|      0|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
  350|      0|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
  351|      0|      in = _mm256_shuffle_epi8(in, swap);
  352|      0|    }
  353|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
  354|  4.73M|    const __m256i v_ff80 = _mm256_set1_epi16((int16_t)0xff80);
  355|  4.73M|    if (_mm256_testz_si256(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (355:9): [True: 729k, False: 4.00M]
  ------------------
  356|       |      // 1. pack the bytes
  357|   729k|      const __m128i utf8_packed = _mm_packus_epi16(
  358|   729k|          _mm256_castsi256_si128(in), _mm256_extractf128_si256(in, 1));
  359|       |      // 2. store (16 bytes)
  360|   729k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  361|       |      // 3. adjust pointers
  362|   729k|      buf += 16;
  363|   729k|      utf8_output += 16;
  364|   729k|      continue; // we are done for this round!
  365|   729k|    }
  366|       |    // no bits set above 7th bit
  367|  4.00M|    const __m256i one_byte_bytemask =
  368|  4.00M|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_ff80), v_0000);
  369|  4.00M|    const uint32_t one_byte_bitmask =
  370|  4.00M|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
  371|       |
  372|       |    // no bits set above 11th bit
  373|  4.00M|    const __m256i one_or_two_bytes_bytemask =
  374|  4.00M|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_0000);
  375|  4.00M|    const uint32_t one_or_two_bytes_bitmask =
  376|  4.00M|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
  377|  4.00M|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (377:9): [True: 9.79k, False: 3.99M]
  ------------------
  378|       |
  379|       |      // 1. prepare 2-byte values
  380|       |      // input 16-bit word : [0000|0aaa|aabb|bbbb] x 8
  381|       |      // expected output   : [110a|aaaa|10bb|bbbb] x 8
  382|  9.79k|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
  383|  9.79k|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
  384|       |
  385|       |      // t0 = [000a|aaaa|bbbb|bb00]
  386|  9.79k|      const __m256i t0 = _mm256_slli_epi16(in, 2);
  387|       |      // t1 = [000a|aaaa|0000|0000]
  388|  9.79k|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
  389|       |      // t2 = [0000|0000|00bb|bbbb]
  390|  9.79k|      const __m256i t2 = _mm256_and_si256(in, v_003f);
  391|       |      // t3 = [000a|aaaa|00bb|bbbb]
  392|  9.79k|      const __m256i t3 = _mm256_or_si256(t1, t2);
  393|       |      // t4 = [110a|aaaa|10bb|bbbb]
  394|  9.79k|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
  395|       |
  396|       |      // 2. merge ASCII and 2-byte codewords
  397|  9.79k|      const __m256i utf8_unpacked =
  398|  9.79k|          _mm256_blendv_epi8(t4, in, one_byte_bytemask);
  399|       |
  400|       |      // 3. prepare bitmask for 8-bit lookup
  401|  9.79k|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
  402|  9.79k|      const uint32_t M1 = M0 >> 7;
  403|  9.79k|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
  404|       |      // 4. pack the bytes
  405|       |
  406|  9.79k|      const uint8_t *row =
  407|  9.79k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
  408|  9.79k|      const uint8_t *row_2 =
  409|  9.79k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
  410|  9.79k|                                                                       16)][0];
  411|       |
  412|  9.79k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  413|  9.79k|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
  414|       |
  415|  9.79k|      const __m256i utf8_packed = _mm256_shuffle_epi8(
  416|  9.79k|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|  9.79k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|  9.79k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  417|       |      // 5. store bytes
  418|  9.79k|      _mm_storeu_si128((__m128i *)utf8_output,
  419|  9.79k|                       _mm256_castsi256_si128(utf8_packed));
  420|  9.79k|      utf8_output += row[0];
  421|  9.79k|      _mm_storeu_si128((__m128i *)utf8_output,
  422|  9.79k|                       _mm256_extractf128_si256(utf8_packed, 1));
  423|  9.79k|      utf8_output += row_2[0];
  424|       |
  425|       |      // 6. adjust pointers
  426|  9.79k|      buf += 16;
  427|  9.79k|      continue;
  428|  9.79k|    }
  429|       |    // 1. Check if there are any surrogate word in the input chunk.
  430|       |    //    We have also deal with situation when there is a surrogate word
  431|       |    //    at the end of a chunk.
  432|  3.99M|    const __m256i surrogates_bytemask =
  433|  3.99M|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_d800);
  434|       |
  435|       |    // bitmask = 0x0000 if there are no surrogates
  436|       |    //         = 0xc000 if the last word is a surrogate
  437|  3.99M|    const uint32_t surrogates_bitmask =
  438|  3.99M|        static_cast<uint32_t>(_mm256_movemask_epi8(surrogates_bytemask));
  439|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  440|       |    // However, it is likely an uncommon occurrence.
  441|  3.99M|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (441:9): [True: 1.20M, False: 2.78M]
  ------------------
  442|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  443|  1.20M|      const __m256i dup_even = _mm256_setr_epi16(
  444|  1.20M|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  445|  1.20M|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  446|       |
  447|       |      /* In this branch we handle three cases:
  448|       |         1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  449|       |        single UFT-8 byte
  450|       |         2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              - two
  451|       |        UTF-8 bytes
  452|       |         3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  453|       |        three UTF-8 bytes
  454|       |
  455|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  456|       |        we have room for four bytes. However, we need five distinct bit
  457|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  458|       |
  459|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  460|       |        in register t2.
  461|       |
  462|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  463|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  464|       |        differ by exactly one bit.
  465|       |
  466|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  467|       |        into account the case (i.e, the number of bytes to write).
  468|       |      */
  469|       |      /**
  470|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  471|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  472|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  473|       |       */
  474|  1.20M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  475|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  476|  1.20M|      const __m256i t0 = _mm256_shuffle_epi8(in, dup_even);
  477|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  478|  1.20M|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  474|  1.20M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  479|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  480|  1.20M|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  474|  1.20M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  481|       |
  482|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  483|  1.20M|      const __m256i s0 = _mm256_srli_epi16(in, 4);
  484|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  485|  1.20M|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  474|  1.20M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  486|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  487|  1.20M|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  474|  1.20M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  488|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  489|  1.20M|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  474|  1.20M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  490|  1.20M|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  491|  1.20M|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  474|  1.20M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  492|  1.20M|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  493|  1.20M|#undef simdutf_vec
  494|       |
  495|       |      // 4. expand code units 16-bit => 32-bit
  496|  1.20M|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  497|  1.20M|      const __m256i out1 = _mm256_unpackhi_epi16(t2, s4);
  498|       |
  499|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  500|  1.20M|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  501|  1.20M|                            (one_or_two_bytes_bitmask & 0xaaaaaaaa);
  502|       |      // Due to the wider registers, the following path is less likely to be
  503|       |      // useful.
  504|       |      /*if(mask == 0) {
  505|       |        // We only have three-byte code units. Use fast path.
  506|       |        const __m256i shuffle =
  507|       |      _mm256_setr_epi8(2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1,
  508|       |      2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1); const __m256i utf8_0 =
  509|       |      _mm256_shuffle_epi8(out0, shuffle); const __m256i utf8_1 =
  510|       |      _mm256_shuffle_epi8(out1, shuffle);
  511|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_0));
  512|       |        utf8_output += 12;
  513|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_1));
  514|       |        utf8_output += 12;
  515|       |        _mm_storeu_si128((__m128i*)utf8_output,
  516|       |      _mm256_extractf128_si256(utf8_0,1)); utf8_output += 12;
  517|       |        _mm_storeu_si128((__m128i*)utf8_output,
  518|       |      _mm256_extractf128_si256(utf8_1,1)); utf8_output += 12; buf += 16;
  519|       |        continue;
  520|       |      }*/
  521|  1.20M|      const uint8_t mask0 = uint8_t(mask);
  522|  1.20M|      const uint8_t *row0 =
  523|  1.20M|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  524|  1.20M|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  525|  1.20M|      const __m128i utf8_0 =
  526|  1.20M|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  527|       |
  528|  1.20M|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  529|  1.20M|      const uint8_t *row1 =
  530|  1.20M|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  531|  1.20M|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  532|  1.20M|      const __m128i utf8_1 =
  533|  1.20M|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  534|       |
  535|  1.20M|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  536|  1.20M|      const uint8_t *row2 =
  537|  1.20M|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  538|  1.20M|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  539|  1.20M|      const __m128i utf8_2 =
  540|  1.20M|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  541|       |
  542|  1.20M|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  543|  1.20M|      const uint8_t *row3 =
  544|  1.20M|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  545|  1.20M|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  546|  1.20M|      const __m128i utf8_3 =
  547|  1.20M|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  548|       |
  549|  1.20M|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  550|  1.20M|      utf8_output += row0[0];
  551|  1.20M|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  552|  1.20M|      utf8_output += row1[0];
  553|  1.20M|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  554|  1.20M|      utf8_output += row2[0];
  555|  1.20M|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  556|  1.20M|      utf8_output += row3[0];
  557|  1.20M|      buf += 16;
  558|       |      // surrogate pair(s) in a register
  559|  2.78M|    } else {
  560|       |      // Let us do a scalar fallback.
  561|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  562|       |      // in the presence of surrogate pairs may require non-trivial tables.
  563|  2.78M|      size_t forward = 15;
  564|  2.78M|      size_t k = 0;
  565|  2.78M|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (565:11): [True: 0, False: 2.78M]
  ------------------
  566|      0|        forward = size_t(end - buf - 1);
  567|      0|      }
  568|  3.35M|      for (; k < forward; k++) {
  ------------------
  |  Branch (568:14): [True: 3.35M, False: 5.53k]
  ------------------
  569|  3.35M|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  570|  3.35M|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (570:13): [True: 45.3k, False: 3.30M]
  ------------------
  571|  45.3k|          *utf8_output++ = char(word);
  572|  3.30M|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (572:20): [True: 26.2k, False: 3.28M]
  ------------------
  573|  26.2k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  574|  26.2k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  575|  3.28M|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (575:20): [True: 476k, False: 2.80M]
  ------------------
  576|   476k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  577|   476k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  578|   476k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  579|  2.80M|        } else {
  580|       |          // must be a surrogate pair
  581|  2.80M|          uint16_t diff = uint16_t(word - 0xD800);
  582|  2.80M|          uint16_t next_word =
  583|  2.80M|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  584|  2.80M|          k++;
  585|  2.80M|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  586|  2.80M|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (586:15): [True: 2.78M, False: 21.5k]
  ------------------
  587|  2.78M|            return std::make_pair(
  588|  2.78M|                result(error_code::SURROGATE, buf - start + k - 1),
  589|  2.78M|                utf8_output);
  590|  2.78M|          }
  591|  21.5k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  592|  21.5k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  593|  21.5k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  594|  21.5k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  595|  21.5k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  596|  21.5k|        }
  597|  3.35M|      }
  598|  5.53k|      buf += k;
  599|  5.53k|    }
  600|  3.99M|  } // while
  601|  4.84k|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  602|  2.78M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_138avx2_convert_utf16_to_utf8_with_errorsILNS_10endiannessE1EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
  333|  2.29M|                                       char *utf8_output) {
  334|  2.29M|  const char16_t *start = buf;
  335|  2.29M|  const char16_t *end = buf + len;
  336|       |
  337|  2.29M|  const __m256i v_0000 = _mm256_setzero_si256();
  338|  2.29M|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
  339|  2.29M|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
  340|  2.29M|  const __m256i v_c080 = _mm256_set1_epi16((int16_t)0xc080);
  341|  2.29M|  const size_t safety_margin =
  342|  2.29M|      12; // to avoid overruns, see issue
  343|       |          // https://github.com/simdutf/simdutf/issues/92
  344|       |
  345|  3.95M|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (345:10): [True: 3.95M, False: 4.65k]
  ------------------
  346|  3.95M|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
  347|  3.95M|    if (big_endian) {
  ------------------
  |  Branch (347:9): [True: 3.95M, Folded]
  ------------------
  348|  3.95M|      const __m256i swap = _mm256_setr_epi8(
  349|  3.95M|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
  350|  3.95M|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
  351|  3.95M|      in = _mm256_shuffle_epi8(in, swap);
  352|  3.95M|    }
  353|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
  354|  3.95M|    const __m256i v_ff80 = _mm256_set1_epi16((int16_t)0xff80);
  355|  3.95M|    if (_mm256_testz_si256(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (355:9): [True: 789k, False: 3.16M]
  ------------------
  356|       |      // 1. pack the bytes
  357|   789k|      const __m128i utf8_packed = _mm_packus_epi16(
  358|   789k|          _mm256_castsi256_si128(in), _mm256_extractf128_si256(in, 1));
  359|       |      // 2. store (16 bytes)
  360|   789k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  361|       |      // 3. adjust pointers
  362|   789k|      buf += 16;
  363|   789k|      utf8_output += 16;
  364|   789k|      continue; // we are done for this round!
  365|   789k|    }
  366|       |    // no bits set above 7th bit
  367|  3.16M|    const __m256i one_byte_bytemask =
  368|  3.16M|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_ff80), v_0000);
  369|  3.16M|    const uint32_t one_byte_bitmask =
  370|  3.16M|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
  371|       |
  372|       |    // no bits set above 11th bit
  373|  3.16M|    const __m256i one_or_two_bytes_bytemask =
  374|  3.16M|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_0000);
  375|  3.16M|    const uint32_t one_or_two_bytes_bitmask =
  376|  3.16M|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
  377|  3.16M|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (377:9): [True: 5.20k, False: 3.15M]
  ------------------
  378|       |
  379|       |      // 1. prepare 2-byte values
  380|       |      // input 16-bit word : [0000|0aaa|aabb|bbbb] x 8
  381|       |      // expected output   : [110a|aaaa|10bb|bbbb] x 8
  382|  5.20k|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
  383|  5.20k|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
  384|       |
  385|       |      // t0 = [000a|aaaa|bbbb|bb00]
  386|  5.20k|      const __m256i t0 = _mm256_slli_epi16(in, 2);
  387|       |      // t1 = [000a|aaaa|0000|0000]
  388|  5.20k|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
  389|       |      // t2 = [0000|0000|00bb|bbbb]
  390|  5.20k|      const __m256i t2 = _mm256_and_si256(in, v_003f);
  391|       |      // t3 = [000a|aaaa|00bb|bbbb]
  392|  5.20k|      const __m256i t3 = _mm256_or_si256(t1, t2);
  393|       |      // t4 = [110a|aaaa|10bb|bbbb]
  394|  5.20k|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
  395|       |
  396|       |      // 2. merge ASCII and 2-byte codewords
  397|  5.20k|      const __m256i utf8_unpacked =
  398|  5.20k|          _mm256_blendv_epi8(t4, in, one_byte_bytemask);
  399|       |
  400|       |      // 3. prepare bitmask for 8-bit lookup
  401|  5.20k|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
  402|  5.20k|      const uint32_t M1 = M0 >> 7;
  403|  5.20k|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
  404|       |      // 4. pack the bytes
  405|       |
  406|  5.20k|      const uint8_t *row =
  407|  5.20k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
  408|  5.20k|      const uint8_t *row_2 =
  409|  5.20k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
  410|  5.20k|                                                                       16)][0];
  411|       |
  412|  5.20k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  413|  5.20k|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
  414|       |
  415|  5.20k|      const __m256i utf8_packed = _mm256_shuffle_epi8(
  416|  5.20k|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|  5.20k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|  5.20k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  417|       |      // 5. store bytes
  418|  5.20k|      _mm_storeu_si128((__m128i *)utf8_output,
  419|  5.20k|                       _mm256_castsi256_si128(utf8_packed));
  420|  5.20k|      utf8_output += row[0];
  421|  5.20k|      _mm_storeu_si128((__m128i *)utf8_output,
  422|  5.20k|                       _mm256_extractf128_si256(utf8_packed, 1));
  423|  5.20k|      utf8_output += row_2[0];
  424|       |
  425|       |      // 6. adjust pointers
  426|  5.20k|      buf += 16;
  427|  5.20k|      continue;
  428|  5.20k|    }
  429|       |    // 1. Check if there are any surrogate word in the input chunk.
  430|       |    //    We have also deal with situation when there is a surrogate word
  431|       |    //    at the end of a chunk.
  432|  3.15M|    const __m256i surrogates_bytemask =
  433|  3.15M|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_d800);
  434|       |
  435|       |    // bitmask = 0x0000 if there are no surrogates
  436|       |    //         = 0xc000 if the last word is a surrogate
  437|  3.15M|    const uint32_t surrogates_bitmask =
  438|  3.15M|        static_cast<uint32_t>(_mm256_movemask_epi8(surrogates_bytemask));
  439|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  440|       |    // However, it is likely an uncommon occurrence.
  441|  3.15M|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (441:9): [True: 863k, False: 2.29M]
  ------------------
  442|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  443|   863k|      const __m256i dup_even = _mm256_setr_epi16(
  444|   863k|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  445|   863k|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  446|       |
  447|       |      /* In this branch we handle three cases:
  448|       |         1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  449|       |        single UFT-8 byte
  450|       |         2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              - two
  451|       |        UTF-8 bytes
  452|       |         3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  453|       |        three UTF-8 bytes
  454|       |
  455|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  456|       |        we have room for four bytes. However, we need five distinct bit
  457|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  458|       |
  459|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  460|       |        in register t2.
  461|       |
  462|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  463|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  464|       |        differ by exactly one bit.
  465|       |
  466|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  467|       |        into account the case (i.e, the number of bytes to write).
  468|       |      */
  469|       |      /**
  470|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  471|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  472|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  473|       |       */
  474|   863k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  475|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  476|   863k|      const __m256i t0 = _mm256_shuffle_epi8(in, dup_even);
  477|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  478|   863k|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  474|   863k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  479|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  480|   863k|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  474|   863k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  481|       |
  482|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  483|   863k|      const __m256i s0 = _mm256_srli_epi16(in, 4);
  484|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  485|   863k|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  474|   863k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  486|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  487|   863k|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  474|   863k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  488|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  489|   863k|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  474|   863k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  490|   863k|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  491|   863k|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  474|   863k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  492|   863k|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  493|   863k|#undef simdutf_vec
  494|       |
  495|       |      // 4. expand code units 16-bit => 32-bit
  496|   863k|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  497|   863k|      const __m256i out1 = _mm256_unpackhi_epi16(t2, s4);
  498|       |
  499|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  500|   863k|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  501|   863k|                            (one_or_two_bytes_bitmask & 0xaaaaaaaa);
  502|       |      // Due to the wider registers, the following path is less likely to be
  503|       |      // useful.
  504|       |      /*if(mask == 0) {
  505|       |        // We only have three-byte code units. Use fast path.
  506|       |        const __m256i shuffle =
  507|       |      _mm256_setr_epi8(2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1,
  508|       |      2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1); const __m256i utf8_0 =
  509|       |      _mm256_shuffle_epi8(out0, shuffle); const __m256i utf8_1 =
  510|       |      _mm256_shuffle_epi8(out1, shuffle);
  511|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_0));
  512|       |        utf8_output += 12;
  513|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_1));
  514|       |        utf8_output += 12;
  515|       |        _mm_storeu_si128((__m128i*)utf8_output,
  516|       |      _mm256_extractf128_si256(utf8_0,1)); utf8_output += 12;
  517|       |        _mm_storeu_si128((__m128i*)utf8_output,
  518|       |      _mm256_extractf128_si256(utf8_1,1)); utf8_output += 12; buf += 16;
  519|       |        continue;
  520|       |      }*/
  521|   863k|      const uint8_t mask0 = uint8_t(mask);
  522|   863k|      const uint8_t *row0 =
  523|   863k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  524|   863k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  525|   863k|      const __m128i utf8_0 =
  526|   863k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  527|       |
  528|   863k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  529|   863k|      const uint8_t *row1 =
  530|   863k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  531|   863k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  532|   863k|      const __m128i utf8_1 =
  533|   863k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  534|       |
  535|   863k|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  536|   863k|      const uint8_t *row2 =
  537|   863k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  538|   863k|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  539|   863k|      const __m128i utf8_2 =
  540|   863k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  541|       |
  542|   863k|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  543|   863k|      const uint8_t *row3 =
  544|   863k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  545|   863k|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  546|   863k|      const __m128i utf8_3 =
  547|   863k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  548|       |
  549|   863k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  550|   863k|      utf8_output += row0[0];
  551|   863k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  552|   863k|      utf8_output += row1[0];
  553|   863k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  554|   863k|      utf8_output += row2[0];
  555|   863k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  556|   863k|      utf8_output += row3[0];
  557|   863k|      buf += 16;
  558|       |      // surrogate pair(s) in a register
  559|  2.29M|    } else {
  560|       |      // Let us do a scalar fallback.
  561|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  562|       |      // in the presence of surrogate pairs may require non-trivial tables.
  563|  2.29M|      size_t forward = 15;
  564|  2.29M|      size_t k = 0;
  565|  2.29M|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (565:11): [True: 0, False: 2.29M]
  ------------------
  566|      0|        forward = size_t(end - buf - 1);
  567|      0|      }
  568|  3.16M|      for (; k < forward; k++) {
  ------------------
  |  Branch (568:14): [True: 3.15M, False: 7.59k]
  ------------------
  569|  3.15M|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  570|  3.15M|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (570:13): [True: 47.7k, False: 3.11M]
  ------------------
  571|  47.7k|          *utf8_output++ = char(word);
  572|  3.11M|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (572:20): [True: 36.4k, False: 3.07M]
  ------------------
  573|  36.4k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  574|  36.4k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  575|  3.07M|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (575:20): [True: 756k, False: 2.31M]
  ------------------
  576|   756k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  577|   756k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  578|   756k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  579|  2.31M|        } else {
  580|       |          // must be a surrogate pair
  581|  2.31M|          uint16_t diff = uint16_t(word - 0xD800);
  582|  2.31M|          uint16_t next_word =
  583|  2.31M|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  584|  2.31M|          k++;
  585|  2.31M|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  586|  2.31M|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (586:15): [True: 2.28M, False: 30.8k]
  ------------------
  587|  2.28M|            return std::make_pair(
  588|  2.28M|                result(error_code::SURROGATE, buf - start + k - 1),
  589|  2.28M|                utf8_output);
  590|  2.28M|          }
  591|  30.8k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  592|  30.8k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  593|  30.8k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  594|  30.8k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  595|  30.8k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  596|  30.8k|        }
  597|  3.15M|      }
  598|  7.59k|      buf += k;
  599|  7.59k|    }
  600|  3.15M|  } // while
  601|  4.65k|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  602|  2.29M|}

_ZNK7simdutf7haswell14implementation13validate_utf8EPKcm:
  178|  2.77k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
  179|  2.77k|  return aligned_split::all<validate_utf8_unsplit>(
  180|  2.77k|      buf, len, aligned_split::utf8_head(buf, len));
  181|  2.77k|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16leEPKDsm:
 1133|    497|    const char16_t *input, size_t length) const noexcept {
 1134|    497|  return aligned_split::sum<utf8_length_from_utf16le_unsplit>(
 1135|    497|      input, length, aligned_split::head(input, length));
 1136|    497|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16beEPKDsm:
 1144|    455|    const char16_t *input, size_t length) const noexcept {
 1145|    455|  return aligned_split::sum<utf8_length_from_utf16be_unsplit>(
 1146|    455|      input, length, aligned_split::head(input, length));
 1147|    455|}
_ZNK7simdutf7haswell14implementation41utf8_length_from_utf16le_with_replacementEPKDsm:
 1187|  1.42k|    const char16_t *input, size_t length) const noexcept {
 1188|  1.42k|  return utf16::utf8_length_from_utf16_with_replacement<endianness::LITTLE>(
 1189|  1.42k|      input, length);
 1190|  1.42k|}
_ZNK7simdutf7haswell14implementation41utf8_length_from_utf16be_with_replacementEPKDsm:
 1194|  1.35k|    const char16_t *input, size_t length) const noexcept {
 1195|  1.35k|  return utf16::utf8_length_from_utf16_with_replacement<endianness::BIG>(
 1196|  1.35k|      input, length);
 1197|  1.35k|}
_ZNK7simdutf7haswell14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPc:
 1201|  1.42k|    const char16_t *input, size_t length, char *utf8_buffer) const noexcept {
 1202|  1.42k|  return utf16_to_utf8::convert_with_replacement_via(
 1203|  1.42k|      [](const char16_t *b, size_t l, char *o) {
 1204|  1.42k|        return convert_utf16_to_utf8_with_details<endianness::LITTLE>(b, l, o);
 1205|  1.42k|      },
 1206|  1.42k|      input, length, utf8_buffer);
 1207|  1.42k|}
_ZNK7simdutf7haswell14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPc:
 1211|  1.35k|    const char16_t *input, size_t length, char *utf8_buffer) const noexcept {
 1212|  1.35k|  return utf16_to_utf8::convert_with_replacement_via(
 1213|  1.35k|      [](const char16_t *b, size_t l, char *o) {
 1214|  1.35k|        return convert_utf16_to_utf8_with_details<endianness::BIG>(b, l, o);
 1215|  1.35k|      },
 1216|  1.35k|      input, length, utf8_buffer);
 1217|  1.35k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_18is_asciiERKNS1_4simd8simd8x64IhEE:
   12|  2.20M|simdutf_really_inline bool is_ascii(const simd8x64<uint8_t> &input) {
   13|  2.20M|  return input.reduce_or().is_ascii();
   14|  2.20M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_124must_be_2_3_continuationENS1_4simd5simd8IhEES4_:
   20|  3.67M|                         const simd8<uint8_t> prev3) {
   21|  3.67M|  simd8<uint8_t> is_third_byte =
   22|  3.67M|      prev2.saturating_sub(0xe0u - 0x80); // Only 111_____ will be > 0x80
   23|  3.67M|  simd8<uint8_t> is_fourth_byte =
   24|  3.67M|      prev3.saturating_sub(0xf0u - 0x80); // Only 1111____ will be > 0x80
   25|  3.67M|  return simd8<bool>(is_third_byte | is_fourth_byte);
   26|  3.67M|}
_ZN7simdutf7haswell21validate_utf8_unsplitEPKcm:
  173|  2.88k|                                                 size_t len) noexcept {
  174|  2.88k|  return haswell::utf8_validation::generic_validate_utf8(buf, len);
  175|  2.88k|}
_ZN7simdutf7haswell34convert_utf16_to_utf8_with_detailsILNS_10endiannessE0EEENS_11full_resultEPKDsmPc:
  711|  2.78M|    const char16_t *buf, size_t len, char *utf8_output) {
  712|  2.78M|  std::pair<result, char *> ret =
  713|  2.78M|      haswell::avx2_convert_utf16_to_utf8_with_errors<big_endian>(buf, len,
  714|  2.78M|                                                                  utf8_output);
  715|  2.78M|  if (ret.first.error) {
  ------------------
  |  Branch (715:7): [True: 2.78M, False: 4.84k]
  ------------------
  716|  2.78M|    return full_result(ret.first.error, ret.first.count,
  717|  2.78M|                       size_t(ret.second - utf8_output));
  718|  2.78M|  }
  719|  4.84k|  if (ret.first.count != len) {
  ------------------
  |  Branch (719:7): [True: 4.84k, False: 0]
  ------------------
  720|  4.84k|    full_result sres =
  721|  4.84k|        scalar::utf16_to_utf8::convert_with_errors<big_endian, false>(
  722|  4.84k|            buf + ret.first.count, len - ret.first.count, ret.second, 0);
  723|  4.84k|    return full_result(sres.error, ret.first.count + sres.input_count,
  724|  4.84k|                       size_t(ret.second - utf8_output) + sres.output_count);
  725|  4.84k|  }
  726|      0|  return full_result(error_code::SUCCESS, len,
  727|      0|                     size_t(ret.second - utf8_output));
  728|  4.84k|}
_ZN7simdutf7haswell34convert_utf16_to_utf8_with_detailsILNS_10endiannessE1EEENS_11full_resultEPKDsmPc:
  711|  2.29M|    const char16_t *buf, size_t len, char *utf8_output) {
  712|  2.29M|  std::pair<result, char *> ret =
  713|  2.29M|      haswell::avx2_convert_utf16_to_utf8_with_errors<big_endian>(buf, len,
  714|  2.29M|                                                                  utf8_output);
  715|  2.29M|  if (ret.first.error) {
  ------------------
  |  Branch (715:7): [True: 2.28M, False: 4.65k]
  ------------------
  716|  2.28M|    return full_result(ret.first.error, ret.first.count,
  717|  2.28M|                       size_t(ret.second - utf8_output));
  718|  2.28M|  }
  719|  4.65k|  if (ret.first.count != len) {
  ------------------
  |  Branch (719:7): [True: 4.65k, False: 0]
  ------------------
  720|  4.65k|    full_result sres =
  721|  4.65k|        scalar::utf16_to_utf8::convert_with_errors<big_endian, false>(
  722|  4.65k|            buf + ret.first.count, len - ret.first.count, ret.second, 0);
  723|  4.65k|    return full_result(sres.error, ret.first.count + sres.input_count,
  724|  4.65k|                       size_t(ret.second - utf8_output) + sres.output_count);
  725|  4.65k|  }
  726|      0|  return full_result(error_code::SUCCESS, len,
  727|      0|                     size_t(ret.second - utf8_output));
  728|  4.65k|}
_ZN7simdutf7haswell32utf8_length_from_utf16le_unsplitEPKDsm:
 1127|    574|    const char16_t *input, size_t length) noexcept {
 1128|    574|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1129|    574|                                                                    length);
 1130|    574|}
_ZN7simdutf7haswell32utf8_length_from_utf16be_unsplitEPKDsm:
 1139|    501|    const char16_t *input, size_t length) noexcept {
 1140|    501|  return utf16::utf8_length_from_utf16_bytemask<endianness::BIG>(input, length);
 1141|    501|}
simdutf.cpp:_ZZNK7simdutf7haswell14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPcENK3$_0clES3_mS4_:
 1203|  2.78M|      [](const char16_t *b, size_t l, char *o) {
 1204|  2.78M|        return convert_utf16_to_utf8_with_details<endianness::LITTLE>(b, l, o);
 1205|  2.78M|      },
simdutf.cpp:_ZZNK7simdutf7haswell14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPcENK3$_0clES3_mS4_:
 1213|  2.29M|      [](const char16_t *b, size_t l, char *o) {
 1214|  2.29M|        return convert_utf16_to_utf8_with_details<endianness::BIG>(b, l, o);
 1215|  2.29M|      },

_ZNK7simdutf14implementation27supported_by_runtime_systemEv:
   64|      8|bool implementation::supported_by_runtime_system() const {
   65|      8|  uint32_t required_instruction_sets = this->required_instruction_sets();
   66|      8|  uint32_t supported_instruction_sets =
   67|      8|      internal::detect_supported_architectures();
   68|      8|  return ((supported_instruction_sets & required_instruction_sets) ==
   69|      8|          required_instruction_sets);
   70|      8|}
_ZNK7simdutf8internal29available_implementation_list5beginEv:
 1513|      1|available_implementation_list::begin() const noexcept {
 1514|      1|  return internal::get_available_implementation_pointers().begin();
 1515|      1|}
_ZNK7simdutf8internal29available_implementation_list3endEv:
 1517|      1|available_implementation_list::end() const noexcept {
 1518|      1|  return internal::get_available_implementation_pointers().end();
 1519|      1|}
_ZN7simdutf29get_available_implementationsEv:
 1568|      1|get_available_implementations() {
 1569|      1|#if !SIMDUTF_USE_STATIC_INITIALIZATION
 1570|      1|  static const internal::available_implementation_list
 1571|      1|      available_implementations_instance{};
 1572|      1|#endif
 1573|      1|  return available_implementations_instance;
 1574|      1|}
simdutf.cpp:_ZN7simdutf8internalL37get_available_implementation_pointersEv:
  938|      2|get_available_implementation_pointers() {
  939|      2|#if !SIMDUTF_USE_STATIC_INITIALIZATION
  940|      2|  static const std::initializer_list<const implementation *>
  941|      2|      available_implementation_pointers{
  942|      2|  #if SIMDUTF_IMPLEMENTATION_ICELAKE
  943|      2|          get_icelake_singleton(),
  944|      2|  #endif
  945|      2|  #if SIMDUTF_IMPLEMENTATION_HASWELL
  946|      2|          get_haswell_singleton(),
  947|      2|  #endif
  948|      2|  #if SIMDUTF_IMPLEMENTATION_WESTMERE
  949|      2|          get_westmere_singleton(),
  950|      2|  #endif
  951|       |  #if SIMDUTF_IMPLEMENTATION_ARM64
  952|       |          get_arm64_singleton(),
  953|       |  #endif
  954|       |  #if SIMDUTF_IMPLEMENTATION_PPC64
  955|       |          get_ppc64_singleton(),
  956|       |  #endif
  957|       |  #if SIMDUTF_IMPLEMENTATION_RVV
  958|       |          get_rvv_singleton(),
  959|       |  #endif
  960|       |  #if SIMDUTF_IMPLEMENTATION_LASX
  961|       |          get_lasx_singleton(),
  962|       |  #endif
  963|       |  #if SIMDUTF_IMPLEMENTATION_LSX
  964|       |          get_lsx_singleton(),
  965|       |  #endif
  966|      2|  #if SIMDUTF_IMPLEMENTATION_FALLBACK
  967|      2|          get_fallback_singleton(),
  968|      2|  #endif
  969|      2|      };
  970|      2|#endif
  971|      2|  return available_implementation_pointers;
  972|      2|}
simdutf.cpp:_ZN7simdutf8internalL21get_icelake_singletonEv:
  157|      1|static const icelake::implementation *get_icelake_singleton() {
  158|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  159|      1|  static const icelake::implementation icelake_singleton{};
  160|      1|  #endif
  161|      1|  return &icelake_singleton;
  162|      1|}
simdutf.cpp:_ZN7simdutf8internalL21get_haswell_singletonEv:
  168|      1|static const haswell::implementation *get_haswell_singleton() {
  169|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  170|      1|  static const haswell::implementation haswell_singleton{};
  171|      1|  #endif
  172|      1|  return &haswell_singleton;
  173|      1|}
simdutf.cpp:_ZN7simdutf8internalL22get_westmere_singletonEv:
  179|      1|static const westmere::implementation *get_westmere_singleton() {
  180|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  181|      1|  static const westmere::implementation westmere_singleton{};
  182|      1|  #endif
  183|      1|  return &westmere_singleton;
  184|      1|}
simdutf.cpp:_ZN7simdutf8internalL22get_fallback_singletonEv:
  245|      1|static const fallback::implementation *get_fallback_singleton() {
  246|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  247|      1|  static const fallback::implementation fallback_singleton{};
  248|      1|  #endif
  249|      1|  return &fallback_singleton;
  250|      1|}

_ZN7simdutf8fallback14implementationC2Ev:
   16|      1|      : simdutf::implementation("fallback", "Generic fallback implementation",
   17|      1|                                0) {}

_ZN7simdutf7haswell14implementationC2Ev:
   16|      1|      : simdutf::implementation("haswell", "Intel/AMD AVX2",
   17|      1|                                internal::instruction_set::AVX2 |
   18|      1|                                    internal::instruction_set::BMI1 |
   19|      1|                                    internal::instruction_set::BMI2) {}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2Ev:
  191|  8.65k|  simdutf_really_inline simd8() : base8_numeric<uint8_t>() {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhEC2Ev:
  124|  8.65k|  simdutf_really_inline base8_numeric() : base8<T>() {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2Ev:
   71|  8.65k|  simdutf_really_inline base8() : base<simd8<T>>() {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2Ev:
   14|  8.65k|  simdutf_really_inline base() : value{__m256i()} {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IhEC2EPKh:
  274|  2.20M|      : chunks{simd8<T>::load(ptr),
  275|  2.20M|               simd8<T>::load(ptr + sizeof(simd8<T>) / sizeof(T))} {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE4loadEPKh:
  111|  6.24M|  static simdutf_really_inline simd8<T> load(const T values[32]) {
  112|  6.24M|    return _mm256_loadu_si256(reinterpret_cast<const __m256i *>(values));
  113|  6.24M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2EDv4_x:
  193|   117M|      : base8_numeric<uint8_t>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhEC2EDv4_x:
  126|   117M|      : base8<T>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2EDv4_x:
   73|   117M|  simdutf_really_inline base8(const __m256i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2EDv4_x:
   17|   117M|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEoRES5_:
   59|  4.04M|  simdutf_really_inline Child &operator|=(const Child other) {
   60|  4.04M|    auto this_cast = static_cast<Child *>(this);
   61|  4.04M|    *this_cast = *this_cast | other;
   62|  4.04M|    return *this_cast;
   63|  4.04M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEorES5_:
   50|  9.91M|  simdutf_really_inline Child operator|(const Child other) const {
   51|  9.91M|    return _mm256_or_si256(*this, other);
   52|  9.91M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEcvRKDv4_xEv:
   19|   158M|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IhE9reduce_orEv:
  294|  2.20M|  simdutf_really_inline simd8<T> reduce_or() const {
  295|  2.20M|    return this->chunks[0] | this->chunks[1];
  296|  2.20M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE8is_asciiEv:
  234|  2.20M|  simdutf_really_inline bool is_ascii() const {
  235|  2.20M|    return _mm256_movemask_epi8(*this) == 0;
  236|  2.20M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi1EEENS4_IhEES8_:
   83|  3.67M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   84|       |    return _mm256_alignr_epi8(
   85|  3.67M|        *this, _mm256_permute2x128_si256(prev_chunk, *this, 0x21), 16 - N);
   86|  3.67M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE3shrILi4EEES4_v:
  245|  7.34M|  template <int N> simdutf_really_inline simd8<uint8_t> shr() const {
  246|  7.34M|    return simd8<uint8_t>(_mm256_srli_epi16(*this, N)) & uint8_t(0xFFu >> N);
  247|  7.34M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE9lookup_16IhEENS2_5simd8IT_EES7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_:
  157|  11.0M|            L replace15) const {
  158|  11.0M|    return lookup_16(simd8<L>::repeat_16(
  159|  11.0M|        replace0, replace1, replace2, replace3, replace4, replace5, replace6,
  160|  11.0M|        replace7, replace8, replace9, replace10, replace11, replace12,
  161|  11.0M|        replace13, replace14, replace15));
  162|  11.0M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE9lookup_16IhEENS2_5simd8IT_EES8_:
  148|  11.0M|  simdutf_really_inline simd8<L> lookup_16(simd8<L> lookup_table) const {
  149|  11.0M|    return _mm256_shuffle_epi8(lookup_table, *this);
  150|  11.0M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE9repeat_16Ehhhhhhhhhhhhhhhh:
  118|  11.0M|                                                  T v14, T v15) {
  119|  11.0M|    return simd8<T>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
  120|  11.0M|                    v14, v15, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
  121|  11.0M|                    v12, v13, v14, v15);
  122|  11.0M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2Ehhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh:
  207|  11.0M|      : simd8(_mm256_setr_epi8(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
  208|  11.0M|                               v12, v13, v14, v15, v16, v17, v18, v19, v20, v21,
  209|  11.0M|                               v22, v23, v24, v25, v26, v27, v28, v29, v30,
  210|  11.0M|                               v31)) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEanES5_:
   53|  22.0M|  simdutf_really_inline Child operator&(const Child other) const {
   54|  22.0M|    return _mm256_and_si256(*this, other);
   55|  22.0M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2Eh:
  195|  22.0M|  simdutf_really_inline simd8(uint8_t _value) : simd8(splat(_value)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE5splatEh:
  105|  22.0M|  static simdutf_really_inline simd8<T> splat(T _value) {
  106|  22.0M|    return _mm256_set1_epi8(_value);
  107|  22.0M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi2EEENS4_IhEES8_:
   83|  3.67M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   84|       |    return _mm256_alignr_epi8(
   85|  3.67M|        *this, _mm256_permute2x128_si256(prev_chunk, *this, 0x21), 16 - N);
   86|  3.67M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi3EEENS4_IhEES8_:
   83|  3.67M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   84|       |    return _mm256_alignr_epi8(
   85|  3.67M|        *this, _mm256_permute2x128_si256(prev_chunk, *this, 0x21), 16 - N);
   86|  3.67M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE14saturating_subES4_:
  214|  9.17M|  saturating_sub(const simd8<uint8_t> other) const {
  215|  9.17M|    return _mm256_subs_epu8(*this, other);
  216|  9.17M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IbEC2EDv4_x:
   95|  3.67M|  simdutf_really_inline simd8(const __m256i _value) : base8<bool>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IbNS2_5simd8IbEEEC2EDv4_x:
   73|  3.67M|  simdutf_really_inline base8(const __m256i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEC2EDv4_x:
   17|  3.67M|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEcvRKDv4_xEv:
   19|  3.67M|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEeoES5_:
   56|  3.67M|  simdutf_really_inline Child operator^(const Child other) const {
   57|  3.67M|    return _mm256_xor_si256(*this, other);
   58|  3.67M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2EPKh:
  197|  1.83M|  simdutf_really_inline simd8(const uint8_t values[32]) : simd8(load(values)) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE7gt_bitsES4_:
  225|  1.83M|  gt_bits(const simd8<uint8_t> other) const {
  226|  1.83M|    return this->saturating_sub(other);
  227|  1.83M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IhE8is_asciiEv:
  298|    991|  simdutf_really_inline bool is_ascii() const {
  299|    991|    return this->reduce_or().is_ascii();
  300|    991|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IhE13gteq_unsignedEh:
  341|    881|  simdutf_really_inline uint64_t gteq_unsigned(const uint8_t m) const {
  342|    881|    const simd8<uint8_t> mask = simd8<uint8_t>::splat(m);
  343|    881|    return simd8x64<bool>((simd8<uint8_t>(__m256i(this->chunks[0])) >= mask),
  344|    881|                          (simd8<uint8_t>(__m256i(this->chunks[1])) >= mask))
  345|    881|        .to_bitmask();
  346|    881|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEgeES4_:
  229|  1.76k|  operator>=(const simd8<uint8_t> other) const {
  230|  1.76k|    return other.min_val(*this) == other;
  231|  1.76k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdeqENS2_5simd8IhEES4_:
   76|  1.76k|                                               const simd8<T> rhs) {
   77|  1.76k|    return _mm256_cmpeq_epi8(lhs, rhs);
   78|  1.76k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE7min_valES4_:
  220|  1.76k|  min_val(const simd8<uint8_t> other) const {
  221|  1.76k|    return _mm256_min_epu8(other, *this);
  222|  1.76k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IbEC2ENS2_5simd8IbEES6_:
  272|    881|      : chunks{chunk0, chunk1} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IbE10to_bitmaskEv:
  282|    881|  simdutf_really_inline uint64_t to_bitmask() const {
  283|    881|    uint64_t r_lo = uint32_t(this->chunks[0].to_bitmask());
  284|    881|    uint64_t r_hi = this->chunks[1].to_bitmask();
  285|    881|    return r_lo | (r_hi << 32);
  286|    881|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IbE10to_bitmaskEv:
   99|  1.76k|  simdutf_really_inline uint32_t to_bitmask() const {
  100|  1.76k|    return uint32_t(_mm256_movemask_epi8(value));
  101|  1.76k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE21any_bits_set_anywhereEv:
  241|   119k|  simdutf_really_inline bool any_bits_set_anywhere() const {
  242|   119k|    return !bits_not_set_anywhere();
  243|   119k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE21bits_not_set_anywhereEv:
  237|   119k|  simdutf_really_inline bool bits_not_set_anywhere() const {
  238|   119k|    return _mm256_testz_si256(*this, *this);
  239|   119k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEC2EDv4_x:
   17|  89.2M|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEcvRKDv4_xEv:
   19|  89.2M|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEC2EDv4_x:
   17|  7.22M|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEcvRKDv4_xEv:
   19|  11.2M|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEanES5_:
   53|  18.4M|  simdutf_really_inline Child operator&(const Child other) const {
   54|  18.4M|    return _mm256_and_si256(*this, other);
   55|  18.4M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEeoES5_:
   56|   460k|  simdutf_really_inline Child operator^(const Child other) const {
   57|   460k|    return _mm256_xor_si256(*this, other);
   58|   460k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE4loadEPKt:
   66|  6.30M|  static simdutf_really_inline simd16<T> load(const T values[8]) {
   67|  6.30M|    return _mm256_loadu_si256(reinterpret_cast<const __m256i *>(values));
   68|  6.30M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2EDv4_x:
   97|  89.2M|      : base16_numeric<uint16_t>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEC2EDv4_x:
   73|  89.2M|      : base16<T>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6base16ItNS2_6simd16IbEEEC2EDv4_x:
   20|  89.2M|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE10swap_bytesEv:
  139|  2.82M|  simdutf_really_inline simd16<uint16_t> swap_bytes() const {
  140|  2.82M|    const __m256i swap = _mm256_setr_epi8(
  141|  2.82M|        1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
  142|  2.82M|        21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
  143|  2.82M|    return _mm256_shuffle_epi8(*this, swap);
  144|  2.82M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE5splatEt:
   58|  25.2M|  static simdutf_really_inline simd16<T> splat(T _value) {
   59|  25.2M|    return _mm256_set1_epi16(_value);
   60|  25.2M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdeqENS2_6simd16ItEES4_:
   26|  6.76M|                                               const simd16<T> rhs) {
   27|  6.76M|    return _mm256_cmpeq_epi16(lhs, rhs);
   28|  6.76M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16IbEC2EDv4_x:
   45|  7.22M|  simdutf_really_inline simd16(const __m256i _value) : base16<bool>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6base16IbNS2_6simd16IbEEEC2EDv4_x:
   20|  7.22M|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16IbE10to_bitmaskEv:
   50|  4.01M|  simdutf_really_inline bitmask_type to_bitmask() const {
   51|  4.01M|    return _mm256_movemask_epi8(*this);
   52|  4.01M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2Et:
  100|  25.2M|  simdutf_really_inline simd16(uint16_t _value) : simd16(splat(_value)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE4zeroEv:
   62|  4.77k|  static simdutf_really_inline simd16<T> zero() {
   63|  4.77k|    return _mm256_setzero_si256();
   64|  4.77k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd3minENS2_6simd16ItEES4_:
  270|  12.1M|simd16<uint16_t> min(const simd16<uint16_t> a, simd16<uint16_t> b) {
  271|  12.1M|  return _mm256_min_epu16(a.value, b.value);
  272|  12.1M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEpLENS2_6simd16ItEE:
   87|  17.9M|  simdutf_really_inline simd16<T> &operator+=(const simd16<T> other) {
   88|  17.9M|    *this = *this + other;
   89|  17.9M|    return *static_cast<simd16<T> *>(this);
   90|  17.9M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEplENS2_6simd16ItEE:
   84|  17.9M|  simdutf_really_inline simd16<T> operator+(const simd16<T> other) const {
   85|  17.9M|    return _mm256_add_epi16(*this, other);
   86|  17.9M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE3sumEv:
  170|  4.77k|  simdutf_really_inline uint64_t sum() const {
  171|  4.77k|    const auto lo_u16 = _mm256_and_si256(value, _mm256_set1_epi32(0x0000ffff));
  172|  4.77k|    const auto hi_u16 = _mm256_srli_epi32(value, 16);
  173|  4.77k|    const auto sum_u32 = _mm256_add_epi32(lo_u16, hi_u16);
  174|       |
  175|  4.77k|    const auto lo_u32 =
  176|  4.77k|        _mm256_and_si256(sum_u32, _mm256_set1_epi64x(0xffffffff));
  177|  4.77k|    const auto hi_u32 = _mm256_srli_epi64(sum_u32, 32);
  178|  4.77k|    const auto sum_u64 = _mm256_add_epi64(lo_u32, hi_u32);
  179|       |
  180|  4.77k|    return uint64_t(_mm256_extract_epi64(sum_u64, 0)) +
  181|  4.77k|           uint64_t(_mm256_extract_epi64(sum_u64, 1)) +
  182|  4.77k|           uint64_t(_mm256_extract_epi64(sum_u64, 2)) +
  183|       |           uint64_t(_mm256_extract_epi64(sum_u64, 3));
  184|  4.77k|  }

_ZN7simdutf7icelake14implementationC2Ev:
   16|      1|      : simdutf::implementation(
   17|      1|            "icelake",
   18|      1|            "Intel AVX512 (AVX-512BW, AVX-512CD, AVX-512VL, AVX-512VBMI2 "
   19|      1|            "extensions)",
   20|      1|            internal::instruction_set::AVX2 | internal::instruction_set::BMI1 |
   21|      1|                internal::instruction_set::BMI2 |
   22|      1|                internal::instruction_set::AVX512BW |
   23|      1|                internal::instruction_set::AVX512CD |
   24|      1|                internal::instruction_set::AVX512VL |
   25|      1|                internal::instruction_set::AVX512VBMI2 |
   26|      1|                internal::instruction_set::AVX512VPOPCNTDQ) {}

_ZN7simdutf8westmere14implementationC2Ev:
   18|      1|      : simdutf::implementation("westmere", "Intel/AMD SSE4.2",
   19|      1|                                internal::instruction_set::SSE42) {}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2Ev:
  183|  8.85k|  simdutf_really_inline simd8() : base8_numeric<uint8_t>() {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhEC2Ev:
  118|  8.85k|  simdutf_really_inline base8_numeric() : base8<T>() {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2Ev:
   68|  8.85k|  simdutf_really_inline base8() : base<simd8<T>>() {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2Ev:
   13|  8.85k|  simdutf_really_inline base() : value{__m128i()} {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IhEC2EPKh:
  270|  2.20M|      : chunks{simd8<T>::load(ptr),
  271|  2.20M|               simd8<T>::load(ptr + sizeof(simd8<T>) / sizeof(T)),
  272|  2.20M|               simd8<T>::load(ptr + 2 * sizeof(simd8<T>) / sizeof(T)),
  273|  2.20M|               simd8<T>::load(ptr + 3 * sizeof(simd8<T>) / sizeof(T))} {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE4loadEPKh:
  106|  10.6M|  static simdutf_really_inline simd8<T> load(const T values[16]) {
  107|  10.6M|    return _mm_loadu_si128(reinterpret_cast<const __m128i *>(values));
  108|  10.6M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2EDv2_x:
  185|   232M|      : base8_numeric<uint8_t>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhEC2EDv2_x:
  120|   232M|      : base8<T>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2EDv2_x:
   69|   232M|  simdutf_really_inline base8(const __m128i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2EDv2_x:
   16|   232M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEoRES5_:
   51|  7.71M|  simdutf_really_inline Child &operator|=(const Child other) {
   52|  7.71M|    auto this_cast = static_cast<Child *>(this);
   53|  7.71M|    *this_cast = *this_cast | other;
   54|  7.71M|    return *this_cast;
   55|  7.71M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEorES5_:
   42|  21.6M|  simdutf_really_inline Child operator|(const Child other) const {
   43|  21.6M|    return _mm_or_si128(*this, other);
   44|  21.6M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEcvRKDv2_xEv:
   18|   291M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IhE9reduce_orEv:
  290|  2.20M|  simdutf_really_inline simd8<T> reduce_or() const {
  291|  2.20M|    return (this->chunks[0] | this->chunks[1]) |
  292|  2.20M|           (this->chunks[2] | this->chunks[3]);
  293|  2.20M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE8is_asciiEv:
  228|  2.20M|  simdutf_really_inline bool is_ascii() const {
  229|  2.20M|    return _mm_movemask_epi8(*this) == 0;
  230|  2.20M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi1EEENS4_IhEES8_:
   79|  7.34M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   80|       |    return _mm_alignr_epi8(*this, prev_chunk, 16 - N);
   81|  7.34M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE3shrILi4EEES4_v:
  238|  14.6M|  template <int N> simdutf_really_inline simd8<uint8_t> shr() const {
  239|  14.6M|    return simd8<uint8_t>(_mm_srli_epi16(*this, N)) & uint8_t(0xFFu >> N);
  240|  14.6M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE9lookup_16IhEENS2_5simd8IT_EES7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_:
  151|  22.0M|            L replace15) const {
  152|  22.0M|    return lookup_16(simd8<L>::repeat_16(
  153|  22.0M|        replace0, replace1, replace2, replace3, replace4, replace5, replace6,
  154|  22.0M|        replace7, replace8, replace9, replace10, replace11, replace12,
  155|  22.0M|        replace13, replace14, replace15));
  156|  22.0M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE9lookup_16IhEENS2_5simd8IT_EES8_:
  142|  22.0M|  simdutf_really_inline simd8<L> lookup_16(simd8<L> lookup_table) const {
  143|  22.0M|    return _mm_shuffle_epi8(lookup_table, *this);
  144|  22.0M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE9repeat_16Ehhhhhhhhhhhhhhhh:
  113|  22.0M|                                                  T v14, T v15) {
  114|  22.0M|    return simd8<T>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
  115|  22.0M|                    v14, v15);
  116|  22.0M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2Ehhhhhhhhhhhhhhhh:
  196|  22.0M|      : simd8(_mm_setr_epi8(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
  197|  22.0M|                            v12, v13, v14, v15)) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEanES5_:
   45|  44.0M|  simdutf_really_inline Child operator&(const Child other) const {
   46|  44.0M|    return _mm_and_si128(*this, other);
   47|  44.0M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2Eh:
  188|  44.0M|  simdutf_really_inline simd8(uint8_t _value) : simd8(splat(_value)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE5splatEh:
  102|  44.0M|  static simdutf_really_inline simd8<T> splat(T _value) {
  103|  44.0M|    return _mm_set1_epi8(_value);
  104|  44.0M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi2EEENS4_IhEES8_:
   79|  7.34M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   80|       |    return _mm_alignr_epi8(*this, prev_chunk, 16 - N);
   81|  7.34M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi3EEENS4_IhEES8_:
   79|  7.34M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   80|       |    return _mm_alignr_epi8(*this, prev_chunk, 16 - N);
   81|  7.34M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE14saturating_subES4_:
  201|  16.5M|  saturating_sub(const simd8<uint8_t> other) const {
  202|  16.5M|    return _mm_subs_epu8(*this, other);
  203|  16.5M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IbEC2EDv2_x:
   91|  7.34M|  simdutf_really_inline simd8(const __m128i _value) : base8<bool>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IbNS2_5simd8IbEEEC2EDv2_x:
   69|  7.34M|  simdutf_really_inline base8(const __m128i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEC2EDv2_x:
   16|  7.34M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEcvRKDv2_xEv:
   18|  7.34M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEeoES5_:
   48|  7.34M|  simdutf_really_inline Child operator^(const Child other) const {
   49|  7.34M|    return _mm_xor_si128(*this, other);
   50|  7.34M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2EPKh:
  190|  1.83M|  simdutf_really_inline simd8(const uint8_t *values) : simd8(load(values)) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE7gt_bitsES4_:
  212|  1.83M|  gt_bits(const simd8<uint8_t> other) const {
  213|  1.83M|    return this->saturating_sub(other);
  214|  1.83M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IhE8is_asciiEv:
  295|  1.07k|  simdutf_really_inline bool is_ascii() const {
  296|  1.07k|    return this->reduce_or().is_ascii();
  297|  1.07k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IhE13gteq_unsignedEh:
  352|    968|  simdutf_really_inline uint64_t gteq_unsigned(const uint8_t m) const {
  353|    968|    const simd8<uint8_t> mask = simd8<uint8_t>::splat(m);
  354|    968|    return simd8x64<bool>(simd8<uint8_t>(__m128i(this->chunks[0])) >= mask,
  355|    968|                          simd8<uint8_t>(__m128i(this->chunks[1])) >= mask,
  356|    968|                          simd8<uint8_t>(__m128i(this->chunks[2])) >= mask,
  357|    968|                          simd8<uint8_t>(__m128i(this->chunks[3])) >= mask)
  358|    968|        .to_bitmask();
  359|    968|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEgeES4_:
  217|  3.87k|  operator>=(const simd8<uint8_t> other) const {
  218|  3.87k|    return other.min_val(*this) == other;
  219|  3.87k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdeqENS2_5simd8IhEES4_:
   72|  3.87k|                                               const simd8<T> rhs) {
   73|  3.87k|    return _mm_cmpeq_epi8(lhs, rhs);
   74|  3.87k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE7min_valES4_:
  207|  3.87k|  min_val(const simd8<uint8_t> other) const {
  208|  3.87k|    return _mm_min_epu8(*this, other);
  209|  3.87k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IbEC2ENS2_5simd8IbEES6_S6_S6_:
  268|    968|      : chunks{chunk0, chunk1, chunk2, chunk3} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IbE10to_bitmaskEv:
  318|    968|  simdutf_really_inline uint64_t to_bitmask() const {
  319|    968|    uint64_t r0 = uint32_t(this->chunks[0].to_bitmask());
  320|    968|    uint64_t r1 = this->chunks[1].to_bitmask();
  321|    968|    uint64_t r2 = this->chunks[2].to_bitmask();
  322|    968|    uint64_t r3 = this->chunks[3].to_bitmask();
  323|    968|    return r0 | (r1 << 16) | (r2 << 32) | (r3 << 48);
  324|    968|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IbE10to_bitmaskEv:
   95|  3.87k|  simdutf_really_inline int to_bitmask() const {
   96|  3.87k|    return _mm_movemask_epi8(*this);
   97|  3.87k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE21any_bits_set_anywhereEv:
  235|   119k|  simdutf_really_inline bool any_bits_set_anywhere() const {
  236|   119k|    return !bits_not_set_anywhere();
  237|   119k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE21bits_not_set_anywhereEv:
  232|   119k|  simdutf_really_inline bool bits_not_set_anywhere() const {
  233|   119k|    return _mm_testz_si128(*this, *this);
  234|   119k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEC2EDv2_x:
   16|   177M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEcvRKDv2_xEv:
   18|   177M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEC2EDv2_x:
   16|  14.1M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEcvRKDv2_xEv:
   18|  22.1M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEanES5_:
   45|  36.7M|  simdutf_really_inline Child operator&(const Child other) const {
   46|  36.7M|    return _mm_and_si128(*this, other);
   47|  36.7M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEeoES5_:
   48|   812k|  simdutf_really_inline Child operator^(const Child other) const {
   49|   812k|    return _mm_xor_si128(*this, other);
   50|   812k|  }

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItE4loadEPKt:
   47|  12.5M|  static simdutf_really_inline simd16<T> load(const T values[8]) {
   48|  12.5M|    return _mm_loadu_si128(reinterpret_cast<const __m128i *>(values));
   49|  12.5M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16ItEC2EDv2_x:
   79|   177M|      : base16_numeric<uint16_t>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItEC2EDv2_x:
   54|   177M|      : base16<T>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6base16ItNS2_6simd16IbEEEC2EDv2_x:
    8|   177M|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16ItE10swap_bytesEv:
  121|  5.58M|  simdutf_really_inline simd16<uint16_t> swap_bytes() const {
  122|  5.58M|    const __m128i swap =
  123|  5.58M|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  124|  5.58M|    return _mm_shuffle_epi8(*this, swap);
  125|  5.58M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItE5splatEt:
   41|  50.0M|  static simdutf_really_inline simd16<T> splat(T _value) {
   42|  50.0M|    return _mm_set1_epi16(_value);
   43|  50.0M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdeqENS2_6simd16ItEES4_:
   11|  13.3M|                                               const simd16<T> rhs) {
   12|  13.3M|    return _mm_cmpeq_epi16(lhs, rhs);
   13|  13.3M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16IbEC2EDv2_x:
   28|  14.1M|  simdutf_really_inline simd16(const __m128i _value) : base16<bool>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6base16IbNS2_6simd16IbEEEC2EDv2_x:
    8|  14.1M|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16IbE10to_bitmaskEv:
   33|  8.02M|  simdutf_really_inline int to_bitmask() const {
   34|  8.02M|    return _mm_movemask_epi8(*this);
   35|  8.02M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16ItEC2Et:
   82|  50.0M|  simdutf_really_inline simd16(uint16_t _value) : simd16(splat(_value)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItE4zeroEv:
   45|  6.02k|  static simdutf_really_inline simd16<T> zero() { return _mm_setzero_si128(); }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd3minENS2_6simd16ItEES4_:
  253|  24.1M|simd16<uint16_t> min(const simd16<uint16_t> a, simd16<uint16_t> b) {
  254|  24.1M|  return _mm_min_epu16(a.value, b.value);
  255|  24.1M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItEpLENS2_6simd16ItEE:
   68|  35.8M|  simdutf_really_inline simd16<T> &operator+=(const simd16<T> other) {
   69|  35.8M|    *this = *this + other;
   70|  35.8M|    return *static_cast<simd16<T> *>(this);
   71|  35.8M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItEplENS2_6simd16ItEE:
   65|  35.8M|  simdutf_really_inline simd16<T> operator+(const simd16<T> other) const {
   66|  35.8M|    return _mm_add_epi16(*this, other);
   67|  35.8M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16ItE3sumEv:
  134|  6.02k|  simdutf_really_inline uint64_t sum() const {
  135|  6.02k|    const auto lo_u16 = _mm_and_si128(value, _mm_set1_epi32(0x0000ffff));
  136|  6.02k|    const auto hi_u16 = _mm_srli_epi32(value, 16);
  137|  6.02k|    const auto sum_u32 = _mm_add_epi32(lo_u16, hi_u16);
  138|       |
  139|  6.02k|    const auto lo_u32 = _mm_and_si128(sum_u32, _mm_set1_epi64x(0xffffffff));
  140|  6.02k|    const auto hi_u32 = _mm_srli_epi64(sum_u32, 32);
  141|  6.02k|    const auto sum_u64 = _mm_add_epi64(lo_u32, hi_u32);
  142|       |
  143|  6.02k|    return uint64_t(_mm_extract_epi64(sum_u64, 0)) +
  144|       |           uint64_t(_mm_extract_epi64(sum_u64, 1));
  145|  6.02k|  }

_ZNK7simdutf8westmere14implementation13validate_utf8EPKcm:
  180|  2.77k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
  181|  2.77k|  return aligned_split::all<validate_utf8_unsplit>(
  182|  2.77k|      buf, len, aligned_split::utf8_head(buf, len));
  183|  2.77k|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16leEPKDsm:
 1076|    497|    const char16_t *input, size_t length) const noexcept {
 1077|    497|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1078|    497|                                                                    length);
 1079|    497|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16beEPKDsm:
 1082|    455|    const char16_t *input, size_t length) const noexcept {
 1083|    455|  return utf16::utf8_length_from_utf16_bytemask<endianness::BIG>(input, length);
 1084|    455|}
_ZNK7simdutf8westmere14implementation41utf8_length_from_utf16le_with_replacementEPKDsm:
 1174|  1.42k|    const char16_t *input, size_t length) const noexcept {
 1175|  1.42k|  return utf16::utf8_length_from_utf16_with_replacement<endianness::LITTLE>(
 1176|  1.42k|      input, length);
 1177|  1.42k|}
_ZNK7simdutf8westmere14implementation41utf8_length_from_utf16be_with_replacementEPKDsm:
 1181|  1.35k|    const char16_t *input, size_t length) const noexcept {
 1182|  1.35k|  return utf16::utf8_length_from_utf16_with_replacement<endianness::BIG>(
 1183|  1.35k|      input, length);
 1184|  1.35k|}
_ZNK7simdutf8westmere14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPc:
 1188|  1.42k|    const char16_t *input, size_t length, char *utf8_buffer) const noexcept {
 1189|  1.42k|  return utf16_to_utf8::convert_with_replacement_via(
 1190|  1.42k|      [](const char16_t *b, size_t l, char *o) {
 1191|  1.42k|        return convert_utf16_to_utf8_with_details<endianness::LITTLE>(b, l, o);
 1192|  1.42k|      },
 1193|  1.42k|      input, length, utf8_buffer);
 1194|  1.42k|}
_ZNK7simdutf8westmere14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPc:
 1198|  1.35k|    const char16_t *input, size_t length, char *utf8_buffer) const noexcept {
 1199|  1.35k|  return utf16_to_utf8::convert_with_replacement_via(
 1200|  1.35k|      [](const char16_t *b, size_t l, char *o) {
 1201|  1.35k|        return convert_utf16_to_utf8_with_details<endianness::BIG>(b, l, o);
 1202|  1.35k|      },
 1203|  1.35k|      input, length, utf8_buffer);
 1204|  1.35k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_18is_asciiERKNS1_4simd8simd8x64IhEE:
   12|  2.20M|simdutf_really_inline bool is_ascii(const simd8x64<uint8_t> &input) {
   13|  2.20M|  return input.reduce_or().is_ascii();
   14|  2.20M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_124must_be_2_3_continuationENS1_4simd5simd8IhEES4_:
   20|  7.34M|                         const simd8<uint8_t> prev3) {
   21|  7.34M|  simd8<uint8_t> is_third_byte =
   22|  7.34M|      prev2.saturating_sub(0xe0u - 0x80); // Only 111_____ will be >= 0x80
   23|  7.34M|  simd8<uint8_t> is_fourth_byte =
   24|  7.34M|      prev3.saturating_sub(0xf0u - 0x80); // Only 1111____ will be >= 0x80
   25|  7.34M|  return simd8<bool>(is_third_byte | is_fourth_byte);
   26|  7.34M|}
_ZN7simdutf8westmere21validate_utf8_unsplitEPKcm:
  175|  2.95k|                                                 size_t len) noexcept {
  176|  2.95k|  return westmere::utf8_validation::generic_validate_utf8(buf, len);
  177|  2.95k|}
_ZN7simdutf8westmere34convert_utf16_to_utf8_with_detailsILNS_10endiannessE0EEENS_11full_resultEPKDsmPc:
  674|  2.78M|    const char16_t *buf, size_t len, char *utf8_output) {
  675|  2.78M|  std::pair<result, char *> ret =
  676|  2.78M|      westmere::sse_convert_utf16_to_utf8_with_errors<big_endian>(buf, len,
  677|  2.78M|                                                                  utf8_output);
  678|  2.78M|  if (ret.first.error) {
  ------------------
  |  Branch (678:7): [True: 2.78M, False: 4.88k]
  ------------------
  679|  2.78M|    return full_result(ret.first.error, ret.first.count,
  680|  2.78M|                       size_t(ret.second - utf8_output));
  681|  2.78M|  }
  682|  4.88k|  if (ret.first.count != len) {
  ------------------
  |  Branch (682:7): [True: 4.88k, False: 0]
  ------------------
  683|  4.88k|    full_result sres =
  684|  4.88k|        scalar::utf16_to_utf8::convert_with_errors<big_endian, false>(
  685|  4.88k|            buf + ret.first.count, len - ret.first.count, ret.second, 0);
  686|  4.88k|    return full_result(sres.error, ret.first.count + sres.input_count,
  687|  4.88k|                       size_t(ret.second - utf8_output) + sres.output_count);
  688|  4.88k|  }
  689|      0|  return full_result(error_code::SUCCESS, len,
  690|      0|                     size_t(ret.second - utf8_output));
  691|  4.88k|}
_ZN7simdutf8westmere34convert_utf16_to_utf8_with_detailsILNS_10endiannessE1EEENS_11full_resultEPKDsmPc:
  674|  2.29M|    const char16_t *buf, size_t len, char *utf8_output) {
  675|  2.29M|  std::pair<result, char *> ret =
  676|  2.29M|      westmere::sse_convert_utf16_to_utf8_with_errors<big_endian>(buf, len,
  677|  2.29M|                                                                  utf8_output);
  678|  2.29M|  if (ret.first.error) {
  ------------------
  |  Branch (678:7): [True: 2.28M, False: 4.69k]
  ------------------
  679|  2.28M|    return full_result(ret.first.error, ret.first.count,
  680|  2.28M|                       size_t(ret.second - utf8_output));
  681|  2.28M|  }
  682|  4.69k|  if (ret.first.count != len) {
  ------------------
  |  Branch (682:7): [True: 4.69k, False: 0]
  ------------------
  683|  4.69k|    full_result sres =
  684|  4.69k|        scalar::utf16_to_utf8::convert_with_errors<big_endian, false>(
  685|  4.69k|            buf + ret.first.count, len - ret.first.count, ret.second, 0);
  686|  4.69k|    return full_result(sres.error, ret.first.count + sres.input_count,
  687|  4.69k|                       size_t(ret.second - utf8_output) + sres.output_count);
  688|  4.69k|  }
  689|      0|  return full_result(error_code::SUCCESS, len,
  690|      0|                     size_t(ret.second - utf8_output));
  691|  4.69k|}
simdutf.cpp:_ZZNK7simdutf8westmere14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPcENK3$_0clES3_mS4_:
 1190|  2.78M|      [](const char16_t *b, size_t l, char *o) {
 1191|  2.78M|        return convert_utf16_to_utf8_with_details<endianness::LITTLE>(b, l, o);
 1192|  2.78M|      },
simdutf.cpp:_ZZNK7simdutf8westmere14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPcENK3$_0clES3_mS4_:
 1200|  2.29M|      [](const char16_t *b, size_t l, char *o) {
 1201|  2.29M|        return convert_utf16_to_utf8_with_details<endianness::BIG>(b, l, o);
 1202|  2.29M|      },

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_18internal8westmere26write_v_u16_11bits_to_utf8EDv2_xRPcS4_t:
   10|  25.0k|                                       const uint16_t one_byte_bitmask) {
   11|       |  // 0b1100_0000_1000_0000
   12|  25.0k|  const __m128i v_c080 = _mm_set1_epi16((int16_t)0xc080);
   13|       |  // 0b0001_1111_0000_0000
   14|  25.0k|  const __m128i v_1f00 = _mm_set1_epi16((int16_t)0x1f00);
   15|       |  // 0b0000_0000_0011_1111
   16|  25.0k|  const __m128i v_003f = _mm_set1_epi16((int16_t)0x003f);
   17|       |
   18|       |  // 1. prepare 2-byte values
   19|       |  // input 16-bit word : [0000|0aaa|aabb|bbbb] x 8
   20|       |  // expected output   : [110a|aaaa|10bb|bbbb] x 8
   21|       |
   22|       |  // t0 = [000a|aaaa|bbbb|bb00]
   23|  25.0k|  const __m128i t0 = _mm_slli_epi16(v_u16, 2);
   24|       |  // t1 = [000a|aaaa|0000|0000]
   25|  25.0k|  const __m128i t1 = _mm_and_si128(t0, v_1f00);
   26|       |  // t2 = [0000|0000|00bb|bbbb]
   27|  25.0k|  const __m128i t2 = _mm_and_si128(v_u16, v_003f);
   28|       |  // t3 = [000a|aaaa|00bb|bbbb]
   29|  25.0k|  const __m128i t3 = _mm_or_si128(t1, t2);
   30|       |  // t4 = [110a|aaaa|10bb|bbbb]
   31|  25.0k|  const __m128i t4 = _mm_or_si128(t3, v_c080);
   32|       |
   33|       |  // 2. merge ASCII and 2-byte codewords
   34|  25.0k|  const __m128i utf8_unpacked = _mm_blendv_epi8(t4, v_u16, one_byte_bytemask);
   35|       |
   36|       |  // 3. prepare bitmask for 8-bit lookup
   37|       |  //    one_byte_bitmask = hhggffeeddccbbaa -- the bits are doubled (h - MSB, a
   38|       |  //    - LSB)
   39|  25.0k|  const uint16_t m0 = one_byte_bitmask & 0x5555;      // m0 = 0h0g0f0e0d0c0b0a
   40|  25.0k|  const uint16_t m1 = static_cast<uint16_t>(m0 >> 7); // m1 = 00000000h0g0f0e0
   41|  25.0k|  const uint8_t m2 = static_cast<uint8_t>((m0 | m1) & 0xff); // m2 = hdgcfbea
   42|       |  // 4. pack the bytes
   43|  25.0k|  const uint8_t *row =
   44|  25.0k|      &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[m2][0];
   45|  25.0k|  const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
   46|  25.0k|  const __m128i utf8_packed = _mm_shuffle_epi8(utf8_unpacked, shuffle);
   47|       |
   48|       |  // 5. store bytes
   49|  25.0k|  _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   50|       |
   51|       |  // 6. adjust pointers
   52|  25.0k|  utf8_output += row[0];
   53|  25.0k|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_137sse_convert_utf16_to_utf8_with_errorsILNS_10endiannessE0EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
  285|  2.78M|                                      char *utf8_output) {
  286|  2.78M|  const char16_t *start = buf;
  287|  2.78M|  const char16_t *end = buf + len;
  288|       |
  289|  2.78M|  const __m128i v_0000 = _mm_setzero_si128();
  290|  2.78M|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
  291|  2.78M|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
  292|  2.78M|  const size_t safety_margin =
  293|  2.78M|      12; // to avoid overruns, see issue
  294|       |          // https://github.com/simdutf/simdutf/issues/92
  295|       |
  296|  5.95M|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (296:10): [True: 5.95M, False: 4.88k]
  ------------------
  297|  5.95M|    __m128i in = _mm_loadu_si128((__m128i *)buf);
  298|  5.95M|    if (big_endian) {
  ------------------
  |  Branch (298:9): [Folded, False: 5.95M]
  ------------------
  299|      0|      const __m128i swap =
  300|      0|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  301|      0|      in = _mm_shuffle_epi8(in, swap);
  302|      0|    }
  303|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
  304|  5.95M|    const __m128i v_ff80 = _mm_set1_epi16((int16_t)0xff80);
  305|  5.95M|    if (_mm_testz_si128(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (305:9): [True: 753k, False: 5.19M]
  ------------------
  306|   753k|      __m128i nextin = _mm_loadu_si128((__m128i *)buf + 1);
  307|   753k|      if (big_endian) {
  ------------------
  |  Branch (307:11): [Folded, False: 753k]
  ------------------
  308|      0|        const __m128i swap =
  309|      0|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  310|      0|        nextin = _mm_shuffle_epi8(nextin, swap);
  311|      0|      }
  312|   753k|      if (!_mm_testz_si128(nextin, v_ff80)) {
  ------------------
  |  Branch (312:11): [True: 16.8k, False: 736k]
  ------------------
  313|       |        // 1. pack the bytes
  314|       |        // obviously suboptimal.
  315|  16.8k|        const __m128i utf8_packed = _mm_packus_epi16(in, in);
  316|       |        // 2. store (16 bytes)
  317|  16.8k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  318|       |        // 3. adjust pointers
  319|  16.8k|        buf += 8;
  320|  16.8k|        utf8_output += 8;
  321|  16.8k|        in = nextin;
  322|   736k|      } else {
  323|       |        // 1. pack the bytes
  324|       |        // obviously suboptimal.
  325|   736k|        const __m128i utf8_packed = _mm_packus_epi16(in, nextin);
  326|       |        // 2. store (16 bytes)
  327|   736k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  328|       |        // 3. adjust pointers
  329|   736k|        buf += 16;
  330|   736k|        utf8_output += 16;
  331|   736k|        continue; // we are done for this round!
  332|   736k|      }
  333|   753k|    }
  334|       |
  335|       |    // no bits set above 7th bit
  336|  5.21M|    const __m128i one_byte_bytemask =
  337|  5.21M|        _mm_cmpeq_epi16(_mm_and_si128(in, v_ff80), v_0000);
  338|  5.21M|    const uint16_t one_byte_bitmask =
  339|  5.21M|        static_cast<uint16_t>(_mm_movemask_epi8(one_byte_bytemask));
  340|       |
  341|       |    // no bits set above 11th bit
  342|  5.21M|    const __m128i one_or_two_bytes_bytemask =
  343|  5.21M|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_0000);
  344|  5.21M|    const uint16_t one_or_two_bytes_bitmask =
  345|  5.21M|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  346|       |
  347|  5.21M|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (347:9): [True: 15.9k, False: 5.19M]
  ------------------
  348|  15.9k|      internal::westmere::write_v_u16_11bits_to_utf8(
  349|  15.9k|          in, utf8_output, one_byte_bytemask, one_byte_bitmask);
  350|  15.9k|      buf += 8;
  351|  15.9k|      continue;
  352|  15.9k|    }
  353|       |
  354|       |    // 1. Check if there are any surrogate word in the input chunk.
  355|       |    //    We have also deal with situation when there is a surrogate word
  356|       |    //    at the end of a chunk.
  357|  5.19M|    const __m128i surrogates_bytemask =
  358|  5.19M|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_d800);
  359|       |
  360|       |    // bitmask = 0x0000 if there are no surrogates
  361|       |    //         = 0xc000 if the last word is a surrogate
  362|  5.19M|    const uint16_t surrogates_bitmask =
  363|  5.19M|        static_cast<uint16_t>(_mm_movemask_epi8(surrogates_bytemask));
  364|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  365|       |    // However, it is likely an uncommon occurrence.
  366|  5.19M|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (366:9): [True: 2.41M, False: 2.78M]
  ------------------
  367|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  368|  2.41M|      const __m128i dup_even = _mm_setr_epi16(0x0000, 0x0202, 0x0404, 0x0606,
  369|  2.41M|                                              0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  370|       |
  371|       |      /* In this branch we handle three cases:
  372|       |         1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  373|       |        single UFT-8 byte
  374|       |         2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              - two
  375|       |        UTF-8 bytes
  376|       |         3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  377|       |        three UTF-8 bytes
  378|       |
  379|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  380|       |        we have room for four bytes. However, we need five distinct bit
  381|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  382|       |
  383|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  384|       |        in register t2.
  385|       |
  386|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  387|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  388|       |        differ by exactly one bit.
  389|       |
  390|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  391|       |        into account the case (i.e, the number of bytes to write).
  392|       |      */
  393|       |      /**
  394|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  395|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  396|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  397|       |       */
  398|  2.41M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  399|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  400|  2.41M|      const __m128i t0 = _mm_shuffle_epi8(in, dup_even);
  401|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  402|  2.41M|      const __m128i t1 = _mm_and_si128(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  398|  2.41M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  403|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  404|  2.41M|      const __m128i t2 = _mm_or_si128(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  398|  2.41M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  405|       |
  406|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  407|  2.41M|      const __m128i s0 = _mm_srli_epi16(in, 4);
  408|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  409|  2.41M|      const __m128i s1 = _mm_and_si128(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  398|  2.41M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  410|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  411|  2.41M|      const __m128i s2 = _mm_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  398|  2.41M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  412|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  413|  2.41M|      const __m128i s3 = _mm_or_si128(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  398|  2.41M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  414|  2.41M|      const __m128i m0 = _mm_andnot_si128(one_or_two_bytes_bytemask,
  415|  2.41M|                                          simdutf_vec(0b0100000000000000));
  ------------------
  |  |  398|  2.41M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  416|  2.41M|      const __m128i s4 = _mm_xor_si128(s3, m0);
  417|  2.41M|#undef simdutf_vec
  418|       |
  419|       |      // 4. expand code units 16-bit => 32-bit
  420|  2.41M|      const __m128i out0 = _mm_unpacklo_epi16(t2, s4);
  421|  2.41M|      const __m128i out1 = _mm_unpackhi_epi16(t2, s4);
  422|       |
  423|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  424|  2.41M|      const uint16_t mask =
  425|  2.41M|          (one_byte_bitmask & 0x5555) | (one_or_two_bytes_bitmask & 0xaaaa);
  426|  2.41M|      if (mask == 0) {
  ------------------
  |  Branch (426:11): [True: 2.22M, False: 184k]
  ------------------
  427|       |        // We only have three-byte code units. Use fast path.
  428|  2.22M|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  429|  2.22M|                                              15, 13, -1, -1, -1, -1);
  430|  2.22M|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  431|  2.22M|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  432|  2.22M|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  433|  2.22M|        utf8_output += 12;
  434|  2.22M|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  435|  2.22M|        utf8_output += 12;
  436|  2.22M|        buf += 8;
  437|  2.22M|        continue;
  438|  2.22M|      }
  439|   184k|      const uint8_t mask0 = uint8_t(mask);
  440|       |
  441|   184k|      const uint8_t *row0 =
  442|   184k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  443|   184k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  444|   184k|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  445|       |
  446|   184k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  447|       |
  448|   184k|      const uint8_t *row1 =
  449|   184k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  450|   184k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  451|   184k|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  452|       |
  453|   184k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  454|   184k|      utf8_output += row0[0];
  455|   184k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  456|   184k|      utf8_output += row1[0];
  457|       |
  458|   184k|      buf += 8;
  459|       |      // surrogate pair(s) in a register
  460|  2.78M|    } else {
  461|       |      // Let us do a scalar fallback.
  462|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  463|       |      // in the presence of surrogate pairs may require non-trivial tables.
  464|  2.78M|      size_t forward = 15;
  465|  2.78M|      size_t k = 0;
  466|  2.78M|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (466:11): [True: 0, False: 2.78M]
  ------------------
  467|      0|        forward = size_t(end - buf - 1);
  468|      0|      }
  469|  3.12M|      for (; k < forward; k++) {
  ------------------
  |  Branch (469:14): [True: 3.12M, False: 2.59k]
  ------------------
  470|  3.12M|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  471|  3.12M|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (471:13): [True: 29.4k, False: 3.09M]
  ------------------
  472|  29.4k|          *utf8_output++ = char(word);
  473|  3.09M|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (473:20): [True: 15.3k, False: 3.07M]
  ------------------
  474|  15.3k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  475|  15.3k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  476|  3.07M|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (476:20): [True: 272k, False: 2.80M]
  ------------------
  477|   272k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  478|   272k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  479|   272k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  480|  2.80M|        } else {
  481|       |          // must be a surrogate pair
  482|  2.80M|          uint16_t diff = uint16_t(word - 0xD800);
  483|  2.80M|          uint16_t next_word =
  484|  2.80M|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  485|  2.80M|          k++;
  486|  2.80M|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  487|  2.80M|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (487:15): [True: 2.78M, False: 21.5k]
  ------------------
  488|  2.78M|            return std::make_pair(
  489|  2.78M|                result(error_code::SURROGATE, buf - start + k - 1),
  490|  2.78M|                utf8_output);
  491|  2.78M|          }
  492|  21.5k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  493|  21.5k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  494|  21.5k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  495|  21.5k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  496|  21.5k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  497|  21.5k|        }
  498|  3.12M|      }
  499|  2.59k|      buf += k;
  500|  2.59k|    }
  501|  5.19M|  } // while
  502|       |
  503|  4.88k|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  504|  2.78M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_137sse_convert_utf16_to_utf8_with_errorsILNS_10endiannessE1EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
  285|  2.29M|                                      char *utf8_output) {
  286|  2.29M|  const char16_t *start = buf;
  287|  2.29M|  const char16_t *end = buf + len;
  288|       |
  289|  2.29M|  const __m128i v_0000 = _mm_setzero_si128();
  290|  2.29M|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
  291|  2.29M|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
  292|  2.29M|  const size_t safety_margin =
  293|  2.29M|      12; // to avoid overruns, see issue
  294|       |          // https://github.com/simdutf/simdutf/issues/92
  295|       |
  296|  4.85M|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (296:10): [True: 4.84M, False: 4.69k]
  ------------------
  297|  4.84M|    __m128i in = _mm_loadu_si128((__m128i *)buf);
  298|  4.84M|    if (big_endian) {
  ------------------
  |  Branch (298:9): [True: 4.84M, Folded]
  ------------------
  299|  4.84M|      const __m128i swap =
  300|  4.84M|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  301|  4.84M|      in = _mm_shuffle_epi8(in, swap);
  302|  4.84M|    }
  303|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
  304|  4.84M|    const __m128i v_ff80 = _mm_set1_epi16((int16_t)0xff80);
  305|  4.84M|    if (_mm_testz_si128(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (305:9): [True: 804k, False: 4.04M]
  ------------------
  306|   804k|      __m128i nextin = _mm_loadu_si128((__m128i *)buf + 1);
  307|   804k|      if (big_endian) {
  ------------------
  |  Branch (307:11): [True: 804k, Folded]
  ------------------
  308|   804k|        const __m128i swap =
  309|   804k|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  310|   804k|        nextin = _mm_shuffle_epi8(nextin, swap);
  311|   804k|      }
  312|   804k|      if (!_mm_testz_si128(nextin, v_ff80)) {
  ------------------
  |  Branch (312:11): [True: 10.2k, False: 793k]
  ------------------
  313|       |        // 1. pack the bytes
  314|       |        // obviously suboptimal.
  315|  10.2k|        const __m128i utf8_packed = _mm_packus_epi16(in, in);
  316|       |        // 2. store (16 bytes)
  317|  10.2k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  318|       |        // 3. adjust pointers
  319|  10.2k|        buf += 8;
  320|  10.2k|        utf8_output += 8;
  321|  10.2k|        in = nextin;
  322|   793k|      } else {
  323|       |        // 1. pack the bytes
  324|       |        // obviously suboptimal.
  325|   793k|        const __m128i utf8_packed = _mm_packus_epi16(in, nextin);
  326|       |        // 2. store (16 bytes)
  327|   793k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  328|       |        // 3. adjust pointers
  329|   793k|        buf += 16;
  330|   793k|        utf8_output += 16;
  331|   793k|        continue; // we are done for this round!
  332|   793k|      }
  333|   804k|    }
  334|       |
  335|       |    // no bits set above 7th bit
  336|  4.05M|    const __m128i one_byte_bytemask =
  337|  4.05M|        _mm_cmpeq_epi16(_mm_and_si128(in, v_ff80), v_0000);
  338|  4.05M|    const uint16_t one_byte_bitmask =
  339|  4.05M|        static_cast<uint16_t>(_mm_movemask_epi8(one_byte_bytemask));
  340|       |
  341|       |    // no bits set above 11th bit
  342|  4.05M|    const __m128i one_or_two_bytes_bytemask =
  343|  4.05M|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_0000);
  344|  4.05M|    const uint16_t one_or_two_bytes_bitmask =
  345|  4.05M|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  346|       |
  347|  4.05M|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (347:9): [True: 9.08k, False: 4.04M]
  ------------------
  348|  9.08k|      internal::westmere::write_v_u16_11bits_to_utf8(
  349|  9.08k|          in, utf8_output, one_byte_bytemask, one_byte_bitmask);
  350|  9.08k|      buf += 8;
  351|  9.08k|      continue;
  352|  9.08k|    }
  353|       |
  354|       |    // 1. Check if there are any surrogate word in the input chunk.
  355|       |    //    We have also deal with situation when there is a surrogate word
  356|       |    //    at the end of a chunk.
  357|  4.04M|    const __m128i surrogates_bytemask =
  358|  4.04M|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_d800);
  359|       |
  360|       |    // bitmask = 0x0000 if there are no surrogates
  361|       |    //         = 0xc000 if the last word is a surrogate
  362|  4.04M|    const uint16_t surrogates_bitmask =
  363|  4.04M|        static_cast<uint16_t>(_mm_movemask_epi8(surrogates_bytemask));
  364|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  365|       |    // However, it is likely an uncommon occurrence.
  366|  4.04M|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (366:9): [True: 1.75M, False: 2.29M]
  ------------------
  367|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  368|  1.75M|      const __m128i dup_even = _mm_setr_epi16(0x0000, 0x0202, 0x0404, 0x0606,
  369|  1.75M|                                              0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  370|       |
  371|       |      /* In this branch we handle three cases:
  372|       |         1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  373|       |        single UFT-8 byte
  374|       |         2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              - two
  375|       |        UTF-8 bytes
  376|       |         3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  377|       |        three UTF-8 bytes
  378|       |
  379|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  380|       |        we have room for four bytes. However, we need five distinct bit
  381|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  382|       |
  383|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  384|       |        in register t2.
  385|       |
  386|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  387|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  388|       |        differ by exactly one bit.
  389|       |
  390|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  391|       |        into account the case (i.e, the number of bytes to write).
  392|       |      */
  393|       |      /**
  394|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  395|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  396|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  397|       |       */
  398|  1.75M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  399|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  400|  1.75M|      const __m128i t0 = _mm_shuffle_epi8(in, dup_even);
  401|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  402|  1.75M|      const __m128i t1 = _mm_and_si128(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  398|  1.75M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  403|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  404|  1.75M|      const __m128i t2 = _mm_or_si128(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  398|  1.75M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  405|       |
  406|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  407|  1.75M|      const __m128i s0 = _mm_srli_epi16(in, 4);
  408|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  409|  1.75M|      const __m128i s1 = _mm_and_si128(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  398|  1.75M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  410|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  411|  1.75M|      const __m128i s2 = _mm_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  398|  1.75M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  412|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  413|  1.75M|      const __m128i s3 = _mm_or_si128(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  398|  1.75M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  414|  1.75M|      const __m128i m0 = _mm_andnot_si128(one_or_two_bytes_bytemask,
  415|  1.75M|                                          simdutf_vec(0b0100000000000000));
  ------------------
  |  |  398|  1.75M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  416|  1.75M|      const __m128i s4 = _mm_xor_si128(s3, m0);
  417|  1.75M|#undef simdutf_vec
  418|       |
  419|       |      // 4. expand code units 16-bit => 32-bit
  420|  1.75M|      const __m128i out0 = _mm_unpacklo_epi16(t2, s4);
  421|  1.75M|      const __m128i out1 = _mm_unpackhi_epi16(t2, s4);
  422|       |
  423|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  424|  1.75M|      const uint16_t mask =
  425|  1.75M|          (one_byte_bitmask & 0x5555) | (one_or_two_bytes_bitmask & 0xaaaa);
  426|  1.75M|      if (mask == 0) {
  ------------------
  |  Branch (426:11): [True: 1.59M, False: 156k]
  ------------------
  427|       |        // We only have three-byte code units. Use fast path.
  428|  1.59M|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  429|  1.59M|                                              15, 13, -1, -1, -1, -1);
  430|  1.59M|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  431|  1.59M|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  432|  1.59M|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  433|  1.59M|        utf8_output += 12;
  434|  1.59M|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  435|  1.59M|        utf8_output += 12;
  436|  1.59M|        buf += 8;
  437|  1.59M|        continue;
  438|  1.59M|      }
  439|   156k|      const uint8_t mask0 = uint8_t(mask);
  440|       |
  441|   156k|      const uint8_t *row0 =
  442|   156k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  443|   156k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  444|   156k|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  445|       |
  446|   156k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  447|       |
  448|   156k|      const uint8_t *row1 =
  449|   156k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  450|   156k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  451|   156k|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  452|       |
  453|   156k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  454|   156k|      utf8_output += row0[0];
  455|   156k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  456|   156k|      utf8_output += row1[0];
  457|       |
  458|   156k|      buf += 8;
  459|       |      // surrogate pair(s) in a register
  460|  2.29M|    } else {
  461|       |      // Let us do a scalar fallback.
  462|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  463|       |      // in the presence of surrogate pairs may require non-trivial tables.
  464|  2.29M|      size_t forward = 15;
  465|  2.29M|      size_t k = 0;
  466|  2.29M|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (466:11): [True: 0, False: 2.29M]
  ------------------
  467|      0|        forward = size_t(end - buf - 1);
  468|      0|      }
  469|  2.79M|      for (; k < forward; k++) {
  ------------------
  |  Branch (469:14): [True: 2.79M, False: 2.27k]
  ------------------
  470|  2.79M|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  471|  2.79M|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (471:13): [True: 28.5k, False: 2.76M]
  ------------------
  472|  28.5k|          *utf8_output++ = char(word);
  473|  2.76M|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (473:20): [True: 23.4k, False: 2.74M]
  ------------------
  474|  23.4k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  475|  23.4k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  476|  2.74M|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (476:20): [True: 424k, False: 2.31M]
  ------------------
  477|   424k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  478|   424k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  479|   424k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  480|  2.31M|        } else {
  481|       |          // must be a surrogate pair
  482|  2.31M|          uint16_t diff = uint16_t(word - 0xD800);
  483|  2.31M|          uint16_t next_word =
  484|  2.31M|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  485|  2.31M|          k++;
  486|  2.31M|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  487|  2.31M|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (487:15): [True: 2.28M, False: 30.8k]
  ------------------
  488|  2.28M|            return std::make_pair(
  489|  2.28M|                result(error_code::SURROGATE, buf - start + k - 1),
  490|  2.28M|                utf8_output);
  491|  2.28M|          }
  492|  30.8k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  493|  30.8k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  494|  30.8k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  495|  30.8k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  496|  30.8k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  497|  30.8k|        }
  498|  2.79M|      }
  499|  2.27k|      buf += k;
  500|  2.27k|    }
  501|  4.04M|  } // while
  502|       |
  503|  4.69k|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  504|  2.29M|}

