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

LLVMFuzzerTestOneInput:
  211|  2.89k|extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  212|       |  // First 4 bytes: action selector + alignment padding.
  213|  2.89k|  if (size < 4) {
  ------------------
  |  Branch (213:7): [True: 2, False: 2.89k]
  ------------------
  214|      2|    return 0;
  215|      2|  }
  216|  2.89k|  constexpr auto Ncases = 2u;
  217|  2.89k|  constexpr auto actionmask = std::bit_ceil(Ncases) - 1;
  218|  2.89k|  const auto action = data[0] & actionmask;
  219|       |
  220|       |  // Advance by 4 so the remaining data is aligned to char16_t.
  221|  2.89k|  data += 4;
  222|  2.89k|  size -= 4;
  223|       |
  224|  2.89k|  const std::span<const char16_t> u16data{
  225|  2.89k|      reinterpret_cast<const char16_t*>(data), size / sizeof(char16_t)};
  226|       |
  227|  2.89k|  switch (action) {
  ------------------
  |  Branch (227:11): [True: 2.89k, False: 0]
  ------------------
  228|  1.49k|  case 0:
  ------------------
  |  Branch (228:3): [True: 1.49k, False: 1.40k]
  ------------------
  229|  1.49k|    test_utf16le_with_replacement(u16data);
  230|  1.49k|    break;
  231|  1.40k|  case 1:
  ------------------
  |  Branch (231:3): [True: 1.40k, False: 1.49k]
  ------------------
  232|  1.40k|    test_utf16be_with_replacement(u16data);
  233|  1.40k|    break;
  234|  2.89k|  }
  235|       |
  236|  2.89k|  return 0;
  237|  2.89k|}
with_replacement.cpp:_ZL29test_utf16le_with_replacementNSt3__14spanIKDsLm18446744073709551615EEE:
   27|  1.49k|static void test_utf16le_with_replacement(std::span<const char16_t> input) {
   28|  1.49k|  const auto implementations = get_supported_implementations();
   29|  1.49k|  if (implementations.empty()) {
  ------------------
  |  Branch (29:7): [True: 0, False: 1.49k]
  ------------------
   30|      0|    return;
   31|      0|  }
   32|       |
   33|       |  // Step 1: Collect length predictions from all implementations and check
   34|       |  // agreement.
   35|  1.49k|  std::vector<simdutf::result> len_results;
   36|  1.49k|  len_results.reserve(implementations.size());
   37|  4.47k|  for (auto impl : implementations) {
  ------------------
  |  Branch (37:18): [True: 4.47k, False: 1.49k]
  ------------------
   38|  4.47k|    len_results.push_back(impl->utf8_length_from_utf16le_with_replacement(
   39|  4.47k|        input.data(), input.size()));
   40|  4.47k|  }
   41|  1.49k|  {
   42|  1.49k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
   43|  1.49k|    if (std::ranges::adjacent_find(len_results, neq) != len_results.end()) {
  ------------------
  |  Branch (43:9): [True: 0, False: 1.49k]
  ------------------
   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.49k|  }
   54|       |
   55|  1.49k|  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.49k|  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.49k|  std::vector<std::vector<char>> outputs;
   63|  1.49k|  outputs.reserve(implementations.size());
   64|  4.47k|  for (auto impl : implementations) {
  ------------------
  |  Branch (64:18): [True: 4.47k, False: 1.49k]
  ------------------
   65|  4.47k|    std::vector<char> out(expected_len);
   66|  4.47k|    const auto written = impl->convert_utf16le_to_utf8_with_replacement(
   67|  4.47k|        input.data(), input.size(), out.data());
   68|  4.47k|    if (written != expected_len) {
  ------------------
  |  Branch (68:9): [True: 0, False: 4.47k]
  ------------------
   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.47k|    outputs.push_back(std::move(out));
   75|  4.47k|  }
   76|       |
   77|       |  // Step 3: All implementations must agree on the output bytes.
   78|  1.49k|  {
   79|  1.49k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
   80|  1.49k|    if (std::ranges::adjacent_find(outputs, neq) != outputs.end()) {
  ------------------
  |  Branch (80:9): [True: 0, False: 1.49k]
  ------------------
   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.49k|  }
   90|       |
   91|       |  // Step 4: Output must always be valid UTF-8.
   92|  5.96k|  for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (92:27): [True: 4.47k, False: 1.49k]
  ------------------
   93|  4.47k|    if (!implementations[i]->validate_utf8(outputs[i].data(),
  ------------------
  |  Branch (93:9): [True: 0, False: 4.47k]
  ------------------
   94|  4.47k|                                           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.47k|  }
  101|       |
  102|       |  // Step 5: When no surrogates were found, match the regular (non-replacement)
  103|       |  // length.
  104|  1.49k|  if (!has_surrogates) {
  ------------------
  |  Branch (104:7): [True: 440, False: 1.05k]
  ------------------
  105|  1.76k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (105:29): [True: 1.32k, False: 440]
  ------------------
  106|  1.32k|      auto impl = implementations[i];
  107|  1.32k|      const auto regular_len =
  108|  1.32k|          impl->utf8_length_from_utf16le(input.data(), input.size());
  109|  1.32k|      if (regular_len != expected_len) {
  ------------------
  |  Branch (109:11): [True: 0, False: 1.32k]
  ------------------
  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.32k|    }
  117|    440|  }
  118|  1.49k|}
with_replacement.cpp:_ZZL29test_utf16le_with_replacementNSt3__14spanIKDsLm18446744073709551615EEEENK3$_0clIN7simdutf6resultES6_EEDaRKT_RKT0_:
   42|  2.98k|    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.98k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
with_replacement.cpp:_ZL29test_utf16be_with_replacementNSt3__14spanIKDsLm18446744073709551615EEE:
  120|  1.40k|static void test_utf16be_with_replacement(std::span<const char16_t> input) {
  121|  1.40k|  const auto implementations = get_supported_implementations();
  122|  1.40k|  if (implementations.empty()) {
  ------------------
  |  Branch (122:7): [True: 0, False: 1.40k]
  ------------------
  123|      0|    return;
  124|      0|  }
  125|       |
  126|       |  // Step 1: Collect length predictions from all implementations and check
  127|       |  // agreement.
  128|  1.40k|  std::vector<simdutf::result> len_results;
  129|  1.40k|  len_results.reserve(implementations.size());
  130|  4.20k|  for (auto impl : implementations) {
  ------------------
  |  Branch (130:18): [True: 4.20k, False: 1.40k]
  ------------------
  131|  4.20k|    len_results.push_back(impl->utf8_length_from_utf16be_with_replacement(
  132|  4.20k|        input.data(), input.size()));
  133|  4.20k|  }
  134|  1.40k|  {
  135|  1.40k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  136|  1.40k|    if (std::ranges::adjacent_find(len_results, neq) != len_results.end()) {
  ------------------
  |  Branch (136:9): [True: 0, False: 1.40k]
  ------------------
  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.40k|  }
  147|       |
  148|  1.40k|  const std::size_t expected_len = len_results[0].count;
  149|  1.40k|  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.40k|  std::vector<std::vector<char>> outputs;
  154|  1.40k|  outputs.reserve(implementations.size());
  155|  4.20k|  for (auto impl : implementations) {
  ------------------
  |  Branch (155:18): [True: 4.20k, False: 1.40k]
  ------------------
  156|  4.20k|    std::vector<char> out(expected_len);
  157|  4.20k|    const auto written = impl->convert_utf16be_to_utf8_with_replacement(
  158|  4.20k|        input.data(), input.size(), out.data());
  159|  4.20k|    if (written != expected_len) {
  ------------------
  |  Branch (159:9): [True: 0, False: 4.20k]
  ------------------
  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.20k|    outputs.push_back(std::move(out));
  166|  4.20k|  }
  167|       |
  168|       |  // Step 3: All implementations must agree on the output bytes.
  169|  1.40k|  {
  170|  1.40k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  171|  1.40k|    if (std::ranges::adjacent_find(outputs, neq) != outputs.end()) {
  ------------------
  |  Branch (171:9): [True: 0, False: 1.40k]
  ------------------
  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.40k|  }
  181|       |
  182|       |  // Step 4: Output must always be valid UTF-8.
  183|  5.61k|  for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (183:27): [True: 4.20k, False: 1.40k]
  ------------------
  184|  4.20k|    if (!implementations[i]->validate_utf8(outputs[i].data(),
  ------------------
  |  Branch (184:9): [True: 0, False: 4.20k]
  ------------------
  185|  4.20k|                                           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.20k|  }
  192|       |
  193|       |  // Step 5: When no surrogates were found, match the regular (non-replacement)
  194|       |  // length.
  195|  1.40k|  if (!has_surrogates) {
  ------------------
  |  Branch (195:7): [True: 390, False: 1.01k]
  ------------------
  196|  1.56k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (196:29): [True: 1.17k, False: 390]
  ------------------
  197|  1.17k|      auto impl = implementations[i];
  198|  1.17k|      const auto regular_len =
  199|  1.17k|          impl->utf8_length_from_utf16be(input.data(), input.size());
  200|  1.17k|      if (regular_len != expected_len) {
  ------------------
  |  Branch (200:11): [True: 0, False: 1.17k]
  ------------------
  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.17k|    }
  208|    390|  }
  209|  1.40k|}
with_replacement.cpp:_ZZL29test_utf16be_with_replacementNSt3__14spanIKDsLm18446744073709551615EEEENK3$_0clIN7simdutf6resultES6_EEDaRKT_RKT0_:
  135|  2.80k|    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.80k|    auto neq = [](const auto& a, const auto& b) { return a != b; };

_ZN7simdutf6resultC2ENS_10error_codeEm:
   87|  3.41M|      : error{err}, count{pos} {}
_ZN7simdutf11full_resultC2ENS_10error_codeEmm:
  111|  17.9k|      : error{err}, input_count{pos_in}, output_count{pos_out} {}
_ZNK7simdutf11full_resultcvNS_6resultEEv:
  117|  17.9k|  simdutf_really_inline simdutf_constexpr23 operator result() const noexcept {
  118|  17.9k|    if (error == error_code::SUCCESS) {
  ------------------
  |  Branch (118:9): [True: 3.72k, False: 14.2k]
  ------------------
  119|  3.72k|      return result{error, output_count};
  120|  14.2k|    } else {
  121|  14.2k|      return result{error, input_count};
  122|  14.2k|    }
  123|  17.9k|  }

_ZNK7simdutf14implementation4nameEv:
 5106|      4|  virtual std::string_view name() const noexcept { return _name; }
_ZNK7simdutf14implementation25required_instruction_setsEv:
 5157|      8|  virtual uint32_t required_instruction_sets() const {
 5158|      8|    return _required_instruction_sets;
 5159|      8|  }
_ZN7simdutf14implementationC2EPKcS2_j:
 7043|      4|      : _name(name), _description(description),
 7044|      4|        _required_instruction_sets(required_instruction_sets) {}
_ZN7simdutf8internal29available_implementation_listC2Ev:
 7075|      1|  simdutf_really_inline available_implementation_list() {}

simdutf.cpp:_ZN7simdutf8internalL30detect_supported_architecturesEv:
  236|      8|static inline uint32_t detect_supported_architectures() {
  237|      8|  uint32_t eax;
  238|      8|  uint32_t ebx = 0;
  239|      8|  uint32_t ecx = 0;
  240|      8|  uint32_t edx = 0;
  241|      8|  uint32_t host_isa = 0x0;
  242|       |
  243|       |  // EBX for EAX=0x1
  244|      8|  eax = 0x1;
  245|      8|  cpuid(&eax, &ebx, &ecx, &edx);
  246|       |
  247|      8|  if (ecx & cpuid_bit::sse42) {
  ------------------
  |  Branch (247:7): [True: 8, False: 0]
  ------------------
  248|      8|    host_isa |= instruction_set::SSE42;
  249|      8|  }
  250|       |
  251|      8|  if (ecx & cpuid_bit::pclmulqdq) {
  ------------------
  |  Branch (251:7): [True: 8, False: 0]
  ------------------
  252|      8|    host_isa |= instruction_set::PCLMULQDQ;
  253|      8|  }
  254|       |
  255|      8|  if ((ecx & cpuid_bit::osxsave) != cpuid_bit::osxsave) {
  ------------------
  |  Branch (255:7): [True: 0, False: 8]
  ------------------
  256|      0|    return host_isa;
  257|      0|  }
  258|       |
  259|       |  // xgetbv for checking if the OS saves registers
  260|      8|  uint64_t xcr0 = xgetbv();
  261|       |
  262|      8|  if ((xcr0 & cpuid_bit::xcr0_bit::avx256_saved) == 0) {
  ------------------
  |  Branch (262:7): [True: 0, False: 8]
  ------------------
  263|      0|    return host_isa;
  264|      0|  }
  265|       |  // ECX for EAX=0x7
  266|      8|  eax = 0x7;
  267|      8|  ecx = 0x0; // Sub-leaf = 0
  268|      8|  cpuid(&eax, &ebx, &ecx, &edx);
  269|      8|  if (ebx & cpuid_bit::ebx::avx2) {
  ------------------
  |  Branch (269:7): [True: 8, False: 0]
  ------------------
  270|      8|    host_isa |= instruction_set::AVX2;
  271|      8|  }
  272|      8|  if (ebx & cpuid_bit::ebx::bmi1) {
  ------------------
  |  Branch (272:7): [True: 8, False: 0]
  ------------------
  273|      8|    host_isa |= instruction_set::BMI1;
  274|      8|  }
  275|      8|  if (ebx & cpuid_bit::ebx::bmi2) {
  ------------------
  |  Branch (275:7): [True: 8, False: 0]
  ------------------
  276|      8|    host_isa |= instruction_set::BMI2;
  277|      8|  }
  278|      8|  if (!((xcr0 & cpuid_bit::xcr0_bit::avx512_saved) ==
  ------------------
  |  Branch (278:7): [True: 8, False: 0]
  ------------------
  279|      8|        cpuid_bit::xcr0_bit::avx512_saved)) {
  280|      8|    return host_isa;
  281|      8|  }
  282|      0|  if (ebx & cpuid_bit::ebx::avx512f) {
  ------------------
  |  Branch (282:7): [True: 0, False: 0]
  ------------------
  283|      0|    host_isa |= instruction_set::AVX512F;
  284|      0|  }
  285|      0|  if (ebx & cpuid_bit::ebx::avx512bw) {
  ------------------
  |  Branch (285:7): [True: 0, False: 0]
  ------------------
  286|      0|    host_isa |= instruction_set::AVX512BW;
  287|      0|  }
  288|      0|  if (ebx & cpuid_bit::ebx::avx512cd) {
  ------------------
  |  Branch (288:7): [True: 0, False: 0]
  ------------------
  289|      0|    host_isa |= instruction_set::AVX512CD;
  290|      0|  }
  291|      0|  if (ebx & cpuid_bit::ebx::avx512dq) {
  ------------------
  |  Branch (291:7): [True: 0, False: 0]
  ------------------
  292|      0|    host_isa |= instruction_set::AVX512DQ;
  293|      0|  }
  294|      0|  if (ebx & cpuid_bit::ebx::avx512vl) {
  ------------------
  |  Branch (294:7): [True: 0, False: 0]
  ------------------
  295|      0|    host_isa |= instruction_set::AVX512VL;
  296|      0|  }
  297|      0|  if (ecx & cpuid_bit::ecx::avx512vbmi2) {
  ------------------
  |  Branch (297:7): [True: 0, False: 0]
  ------------------
  298|      0|    host_isa |= instruction_set::AVX512VBMI2;
  299|      0|  }
  300|      0|  if (ecx & cpuid_bit::ecx::avx512vpopcnt) {
  ------------------
  |  Branch (300:7): [True: 0, False: 0]
  ------------------
  301|      0|    host_isa |= instruction_set::AVX512VPOPCNTDQ;
  302|      0|  }
  303|      0|  return host_isa;
  304|      8|}
simdutf.cpp:_ZN7simdutf8internalL5cpuidEPjS1_S1_S1_:
  202|     16|                         uint32_t *edx) {
  203|       |  #if defined(_MSC_VER)
  204|       |  int cpu_info[4];
  205|       |  __cpuidex(cpu_info, *eax, *ecx);
  206|       |  *eax = cpu_info[0];
  207|       |  *ebx = cpu_info[1];
  208|       |  *ecx = cpu_info[2];
  209|       |  *edx = cpu_info[3];
  210|       |  #elif (defined(HAVE_GCC_GET_CPUID) && defined(USE_GCC_GET_CPUID)) ||         \
  211|       |      defined(__FILC__)
  212|       |  uint32_t level = *eax;
  213|       |  __get_cpuid(level, eax, ebx, ecx, edx);
  214|       |  #else
  215|     16|  uint32_t a = *eax, b, c = *ecx, d;
  216|     16|  asm volatile("cpuid\n\t" : "+a"(a), "=b"(b), "+c"(c), "=d"(d));
  217|     16|  *eax = a;
  218|     16|  *ebx = b;
  219|     16|  *ecx = c;
  220|     16|  *edx = d;
  221|     16|  #endif
  222|     16|}
simdutf.cpp:_ZN7simdutf8internalL6xgetbvEv:
  224|      8|static inline uint64_t xgetbv() {
  225|       |  #if defined(_MSC_VER)
  226|       |  return _xgetbv(0);
  227|       |  #elif defined(__FILC__)
  228|       |  return zxgetbv();
  229|       |  #else
  230|      8|  uint32_t xcr0_lo, xcr0_hi;
  231|      8|  asm volatile("xgetbv\n\t" : "=a"(xcr0_lo), "=d"(xcr0_hi) : "c"(0));
  232|      8|  return xcr0_lo | ((uint64_t)xcr0_hi << 32);
  233|      8|  #endif
  234|      8|}

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

_ZN7simdutf6scalar5utf1617is_high_surrogateILNS_10endiannessE0EEEbDs:
  137|  37.2M|template <endianness big_endian> constexpr bool is_high_surrogate(char16_t c) {
  138|  37.2M|  c = scalar::utf16::swap_if_needed<big_endian>(c);
  139|  37.2M|  return (0xd800 <= c && c <= 0xdbff);
  ------------------
  |  Branch (139:11): [True: 1.58M, False: 35.6M]
  |  Branch (139:26): [True: 432k, False: 1.15M]
  ------------------
  140|  37.2M|}
_ZN7simdutf6scalar5utf1616is_low_surrogateILNS_10endiannessE0EEEbDs:
  142|  43.7M|template <endianness big_endian> constexpr bool is_low_surrogate(char16_t c) {
  143|  43.7M|  c = scalar::utf16::swap_if_needed<big_endian>(c);
  144|  43.7M|  return (0xdc00 <= c && c <= 0xdfff);
  ------------------
  |  Branch (144:11): [True: 1.41M, False: 42.3M]
  |  Branch (144:26): [True: 396k, False: 1.02M]
  ------------------
  145|  43.7M|}
_ZN7simdutf6scalar5utf1617is_high_surrogateILNS_10endiannessE1EEEbDs:
  137|  28.8M|template <endianness big_endian> constexpr bool is_high_surrogate(char16_t c) {
  138|  28.8M|  c = scalar::utf16::swap_if_needed<big_endian>(c);
  139|  28.8M|  return (0xd800 <= c && c <= 0xdbff);
  ------------------
  |  Branch (139:11): [True: 1.81M, False: 27.0M]
  |  Branch (139:26): [True: 387k, False: 1.43M]
  ------------------
  140|  28.8M|}
_ZN7simdutf6scalar5utf1616is_low_surrogateILNS_10endiannessE1EEEbDs:
  142|  33.8M|template <endianness big_endian> constexpr bool is_low_surrogate(char16_t c) {
  143|  33.8M|  c = scalar::utf16::swap_if_needed<big_endian>(c);
  144|  33.8M|  return (0xdc00 <= c && c <= 0xdfff);
  ------------------
  |  Branch (144:11): [True: 1.66M, False: 32.2M]
  |  Branch (144:26): [True: 859k, False: 808k]
  ------------------
  145|  33.8M|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE0EEEmPKDsm:
   91|  1.27M|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|  1.27M|  size_t counter{0};
   94|  16.1M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 14.8M, False: 1.27M]
  ------------------
   95|  14.8M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|  14.8M|    counter++; // ASCII
   97|  14.8M|    counter += static_cast<size_t>(
   98|  14.8M|        word >
   99|  14.8M|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|  14.8M|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 8.65M, False: 6.21M]
  |  Branch (100:53): [True: 7.94M, False: 708k]
  ------------------
  101|  6.92M|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 387k, False: 6.53M]
  ------------------
  102|  14.8M|  }
  103|  1.27M|  return counter;
  104|  1.27M|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE1EEEmPKDsm:
   91|  2.10M|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|  2.10M|  size_t counter{0};
   94|  13.8M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 11.7M, False: 2.10M]
  ------------------
   95|  11.7M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|  11.7M|    counter++; // ASCII
   97|  11.7M|    counter += static_cast<size_t>(
   98|  11.7M|        word >
   99|  11.7M|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|  11.7M|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 6.53M, False: 5.19M]
  |  Branch (100:53): [True: 5.88M, False: 653k]
  ------------------
  101|  5.84M|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 311k, False: 5.53M]
  ------------------
  102|  11.7M|  }
  103|  2.10M|  return counter;
  104|  2.10M|}
_ZN7simdutf6scalar5utf1639utf8_length_from_utf16_with_replacementILNS_10endiannessE0EEENS_6resultEPKDsm:
  153|  4.47k|utf8_length_from_utf16_with_replacement(const char16_t *p, size_t len) {
  154|  4.47k|  bool any_surrogates = false;
  155|       |  // We are not BOM aware.
  156|  4.47k|  size_t counter{0};
  157|  37.2M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (157:22): [True: 37.2M, False: 4.47k]
  ------------------
  158|  37.2M|    if (is_high_surrogate<big_endian>(p[i])) {
  ------------------
  |  Branch (158:9): [True: 431k, False: 36.7M]
  ------------------
  159|   431k|      any_surrogates = true;
  160|       |      // surrogate pair
  161|   431k|      if (i + 1 < len && is_low_surrogate<big_endian>(p[i + 1])) {
  ------------------
  |  Branch (161:11): [True: 431k, False: 717]
  |  Branch (161:26): [True: 88.7k, False: 342k]
  ------------------
  162|  88.7k|        counter += 4;
  163|  88.7k|        i++; // skip low surrogate
  164|   343k|      } else {
  165|   343k|        counter += 3; // unpaired high surrogate replaced by U+FFFD
  166|   343k|      }
  167|   431k|      continue;
  168|  36.7M|    } else if (is_low_surrogate<big_endian>(p[i])) {
  ------------------
  |  Branch (168:16): [True: 295k, False: 36.4M]
  ------------------
  169|   295k|      any_surrogates = true;
  170|   295k|      counter += 3; // unpaired low surrogate replaced by U+FFFD
  171|   295k|      continue;
  172|   295k|    }
  173|  36.4M|    char16_t word = !match_system(big_endian) ? u16_swap_bytes(p[i]) : p[i];
  ------------------
  |  Branch (173:21): [Folded, False: 36.4M]
  ------------------
  174|  36.4M|    counter++; // at least 1 byte
  175|  36.4M|    counter +=
  176|  36.4M|        static_cast<size_t>(word > 0x7F); // non-ASCII is at least 2 bytes
  177|  36.4M|    counter += static_cast<size_t>(word > 0x7FF); // three-byte
  178|  36.4M|  }
  179|  4.47k|  return {any_surrogates ? error_code::SURROGATE : error_code::SUCCESS,
  ------------------
  |  Branch (179:11): [True: 2.45k, False: 2.01k]
  ------------------
  180|  4.47k|          counter};
  181|  4.47k|}
_ZN7simdutf6scalar5utf1639utf8_length_from_utf16_with_replacementILNS_10endiannessE1EEENS_6resultEPKDsm:
  153|  4.20k|utf8_length_from_utf16_with_replacement(const char16_t *p, size_t len) {
  154|  4.20k|  bool any_surrogates = false;
  155|       |  // We are not BOM aware.
  156|  4.20k|  size_t counter{0};
  157|  28.8M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (157:22): [True: 28.8M, False: 4.20k]
  ------------------
  158|  28.8M|    if (is_high_surrogate<big_endian>(p[i])) {
  ------------------
  |  Branch (158:9): [True: 387k, False: 28.5M]
  ------------------
  159|   387k|      any_surrogates = true;
  160|       |      // surrogate pair
  161|   387k|      if (i + 1 < len && is_low_surrogate<big_endian>(p[i + 1])) {
  ------------------
  |  Branch (161:11): [True: 386k, False: 759]
  |  Branch (161:26): [True: 91.4k, False: 295k]
  ------------------
  162|  91.4k|        counter += 4;
  163|  91.4k|        i++; // skip low surrogate
  164|   296k|      } else {
  165|   296k|        counter += 3; // unpaired high surrogate replaced by U+FFFD
  166|   296k|      }
  167|   387k|      continue;
  168|  28.5M|    } else if (is_low_surrogate<big_endian>(p[i])) {
  ------------------
  |  Branch (168:16): [True: 759k, False: 27.7M]
  ------------------
  169|   759k|      any_surrogates = true;
  170|   759k|      counter += 3; // unpaired low surrogate replaced by U+FFFD
  171|   759k|      continue;
  172|   759k|    }
  173|  27.7M|    char16_t word = !match_system(big_endian) ? u16_swap_bytes(p[i]) : p[i];
  ------------------
  |  Branch (173:21): [True: 27.7M, Folded]
  ------------------
  174|  27.7M|    counter++; // at least 1 byte
  175|  27.7M|    counter +=
  176|  27.7M|        static_cast<size_t>(word > 0x7F); // non-ASCII is at least 2 bytes
  177|  27.7M|    counter += static_cast<size_t>(word > 0x7FF); // three-byte
  178|  27.7M|  }
  179|  4.20k|  return {any_surrogates ? error_code::SURROGATE : error_code::SUCCESS,
  ------------------
  |  Branch (179:11): [True: 2.40k, False: 1.80k]
  ------------------
  180|  4.20k|          counter};
  181|  4.20k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf819convert_with_errorsILNS_10endiannessE0ELb0EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT1_Esr7simdutf6detailE26index_assignable_from_charIT2_EEENS_11full_resultES8_mS9_m:
  101|  8.90k|                                                    size_t utf8_len = 0) {
  102|  8.90k|  if (check_output && utf8_len == 0) {
  ------------------
  |  Branch (102:7): [Folded, False: 8.90k]
  |  Branch (102:23): [True: 0, False: 0]
  ------------------
  103|      0|    return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, 0, 0);
  104|      0|  }
  105|       |
  106|  8.90k|  size_t pos = 0;
  107|  8.90k|  auto start = utf8_output;
  108|  8.90k|  auto end = utf8_output + utf8_len;
  109|       |
  110|  38.8k|  while (pos < len) {
  ------------------
  |  Branch (110:10): [True: 36.9k, False: 1.93k]
  ------------------
  111|       |#if SIMDUTF_CPLUSPLUS23
  112|       |    if !consteval
  113|       |#endif
  114|  36.9k|    {
  115|       |      // try to convert the next block of 8 bytes
  116|  36.9k|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (116:11): [True: 29.4k, False: 7.47k]
  ------------------
  117|       |                            // they are ascii
  118|  29.4k|        uint64_t v;
  119|  29.4k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
  120|       |        if constexpr (!match_system(big_endian))
  121|       |          v = (v >> 8) | (v << (64 - 8));
  122|  29.4k|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (122:13): [True: 1.65k, False: 27.8k]
  ------------------
  123|  1.65k|          size_t final_pos = pos + 4;
  124|  8.26k|          while (pos < final_pos) {
  ------------------
  |  Branch (124:18): [True: 6.61k, False: 1.65k]
  ------------------
  125|  6.61k|            if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (125:17): [Folded, False: 6.61k]
  |  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.61k|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (129:30): [Folded, False: 6.61k]
  ------------------
  130|  6.61k|                                 ? char(u16_swap_bytes(data[pos]))
  131|  6.61k|                                 : char(data[pos]);
  132|  6.61k|            pos++;
  133|  6.61k|          }
  134|  1.65k|          continue;
  135|  1.65k|        }
  136|  29.4k|      }
  137|  36.9k|    }
  138|       |
  139|  35.2k|    uint16_t word =
  140|  35.2k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (140:9): [Folded, False: 35.2k]
  ------------------
  141|  35.2k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (141:9): [True: 4.51k, False: 30.7k]
  ------------------
  142|       |      // will generate one UTF-8 bytes
  143|  4.51k|      if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (143:11): [Folded, False: 4.51k]
  |  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.51k|      *utf8_output++ = char(word);
  148|  4.51k|      pos++;
  149|  30.7k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (149:16): [True: 3.23k, False: 27.5k]
  ------------------
  150|       |      // will generate two UTF-8 bytes
  151|       |      // we have 0b110XXXXX 0b10XXXXXX
  152|  3.23k|      if (check_output && size_t(end - utf8_output) < 2) {
  ------------------
  |  Branch (152:11): [Folded, False: 3.23k]
  |  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|  3.23k|      *utf8_output++ = char((word >> 6) | 0b11000000);
  157|  3.23k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  158|  3.23k|      pos++;
  159|       |
  160|  27.5k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (160:16): [True: 19.7k, False: 7.81k]
  ------------------
  161|       |      // will generate three UTF-8 bytes
  162|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
  163|  19.7k|      if (check_output && size_t(end - utf8_output) < 3) {
  ------------------
  |  Branch (163:11): [Folded, False: 19.7k]
  |  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|  19.7k|      *utf8_output++ = char((word >> 12) | 0b11100000);
  168|  19.7k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  169|  19.7k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  170|  19.7k|      pos++;
  171|  19.7k|    } else {
  172|       |
  173|  7.81k|      if (check_output && size_t(end - utf8_output) < 4) {
  ------------------
  |  Branch (173:11): [Folded, False: 7.81k]
  |  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|  7.81k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (178:11): [True: 1.05k, False: 6.75k]
  ------------------
  179|  1.05k|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  180|  1.05k|      }
  181|  6.75k|      uint16_t diff = uint16_t(word - 0xD800);
  182|  6.75k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (182:11): [True: 2.50k, False: 4.25k]
  ------------------
  183|  2.50k|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  184|  2.50k|      }
  185|  4.25k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (185:28): [Folded, False: 4.25k]
  ------------------
  186|  4.25k|                               ? u16_swap_bytes(data[pos + 1])
  187|  4.25k|                               : data[pos + 1];
  188|  4.25k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
  189|  4.25k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (189:11): [True: 3.41k, False: 835]
  ------------------
  190|  3.41k|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  191|  3.41k|      }
  192|    835|      uint32_t value = (diff << 10) + diff2 + 0x10000;
  193|       |      // will generate four UTF-8 bytes
  194|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
  195|    835|      *utf8_output++ = char((value >> 18) | 0b11110000);
  196|    835|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  197|    835|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  198|    835|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
  199|    835|      pos += 2;
  200|    835|    }
  201|  35.2k|  }
  202|  1.93k|  return full_result(error_code::SUCCESS, pos, utf8_output - start);
  203|  8.90k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf819convert_with_errorsILNS_10endiannessE1ELb0EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT1_Esr7simdutf6detailE26index_assignable_from_charIT2_EEENS_11full_resultES8_mS9_m:
  101|  9.08k|                                                    size_t utf8_len = 0) {
  102|  9.08k|  if (check_output && utf8_len == 0) {
  ------------------
  |  Branch (102:7): [Folded, False: 9.08k]
  |  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.08k|  size_t pos = 0;
  107|  9.08k|  auto start = utf8_output;
  108|  9.08k|  auto end = utf8_output + utf8_len;
  109|       |
  110|  36.0k|  while (pos < len) {
  ------------------
  |  Branch (110:10): [True: 34.2k, False: 1.79k]
  ------------------
  111|       |#if SIMDUTF_CPLUSPLUS23
  112|       |    if !consteval
  113|       |#endif
  114|  34.2k|    {
  115|       |      // try to convert the next block of 8 bytes
  116|  34.2k|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (116:11): [True: 27.3k, False: 6.88k]
  ------------------
  117|       |                            // they are ascii
  118|  27.3k|        uint64_t v;
  119|  27.3k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
  120|       |        if constexpr (!match_system(big_endian))
  121|  27.3k|          v = (v >> 8) | (v << (64 - 8));
  122|  27.3k|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (122:13): [True: 1.41k, False: 25.9k]
  ------------------
  123|  1.41k|          size_t final_pos = pos + 4;
  124|  7.08k|          while (pos < final_pos) {
  ------------------
  |  Branch (124:18): [True: 5.66k, False: 1.41k]
  ------------------
  125|  5.66k|            if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (125:17): [Folded, False: 5.66k]
  |  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|  5.66k|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (129:30): [True: 5.66k, Folded]
  ------------------
  130|  5.66k|                                 ? char(u16_swap_bytes(data[pos]))
  131|  5.66k|                                 : char(data[pos]);
  132|  5.66k|            pos++;
  133|  5.66k|          }
  134|  1.41k|          continue;
  135|  1.41k|        }
  136|  27.3k|      }
  137|  34.2k|    }
  138|       |
  139|  32.8k|    uint16_t word =
  140|  32.8k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (140:9): [True: 32.8k, Folded]
  ------------------
  141|  32.8k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (141:9): [True: 3.70k, False: 29.1k]
  ------------------
  142|       |      // will generate one UTF-8 bytes
  143|  3.70k|      if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (143:11): [Folded, False: 3.70k]
  |  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.70k|      *utf8_output++ = char(word);
  148|  3.70k|      pos++;
  149|  29.1k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (149:16): [True: 2.66k, False: 26.4k]
  ------------------
  150|       |      // will generate two UTF-8 bytes
  151|       |      // we have 0b110XXXXX 0b10XXXXXX
  152|  2.66k|      if (check_output && size_t(end - utf8_output) < 2) {
  ------------------
  |  Branch (152:11): [Folded, False: 2.66k]
  |  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.66k|      *utf8_output++ = char((word >> 6) | 0b11000000);
  157|  2.66k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  158|  2.66k|      pos++;
  159|       |
  160|  26.4k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (160:16): [True: 18.1k, False: 8.31k]
  ------------------
  161|       |      // will generate three UTF-8 bytes
  162|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
  163|  18.1k|      if (check_output && size_t(end - utf8_output) < 3) {
  ------------------
  |  Branch (163:11): [Folded, False: 18.1k]
  |  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.1k|      *utf8_output++ = char((word >> 12) | 0b11100000);
  168|  18.1k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  169|  18.1k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  170|  18.1k|      pos++;
  171|  18.1k|    } else {
  172|       |
  173|  8.31k|      if (check_output && size_t(end - utf8_output) < 4) {
  ------------------
  |  Branch (173:11): [Folded, False: 8.31k]
  |  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.31k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (178:11): [True: 1.00k, False: 7.30k]
  ------------------
  179|  1.00k|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  180|  1.00k|      }
  181|  7.30k|      uint16_t diff = uint16_t(word - 0xD800);
  182|  7.30k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (182:11): [True: 2.44k, False: 4.85k]
  ------------------
  183|  2.44k|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  184|  2.44k|      }
  185|  4.85k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (185:28): [True: 4.85k, Folded]
  ------------------
  186|  4.85k|                               ? u16_swap_bytes(data[pos + 1])
  187|  4.85k|                               : data[pos + 1];
  188|  4.85k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
  189|  4.85k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (189:11): [True: 3.83k, False: 1.02k]
  ------------------
  190|  3.83k|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  191|  3.83k|      }
  192|  1.02k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
  193|       |      // will generate four UTF-8 bytes
  194|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
  195|  1.02k|      *utf8_output++ = char((value >> 18) | 0b11110000);
  196|  1.02k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  197|  1.02k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  198|  1.02k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
  199|  1.02k|      pos += 2;
  200|  1.02k|    }
  201|  32.8k|  }
  202|  1.79k|  return full_result(error_code::SUCCESS, pos, utf8_output - start);
  203|  9.08k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf824convert_with_replacementILNS_10endiannessE0EEEmPKDsmPc:
  214|  1.49k|                                                    char *utf8_output) {
  215|  1.49k|  size_t pos = 0;
  216|  1.49k|  char *start = utf8_output;
  217|  24.7M|  while (pos < len) {
  ------------------
  |  Branch (217:10): [True: 24.7M, False: 1.49k]
  ------------------
  218|       |#if SIMDUTF_CPLUSPLUS23
  219|       |    if !consteval
  220|       |#endif
  221|  24.7M|    {
  222|       |      // try to convert the next block of 8 bytes
  223|  24.7M|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (223:11): [True: 24.7M, False: 3.72k]
  ------------------
  224|       |                            // they are ascii
  225|  24.7M|        uint64_t v;
  226|  24.7M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
  227|       |        if constexpr (!match_system(big_endian)) {
  228|       |          v = (v >> 8) | (v << (64 - 8));
  229|       |        }
  230|  24.7M|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (230:13): [True: 4.15M, False: 20.5M]
  ------------------
  231|  4.15M|          size_t final_pos = pos + 4;
  232|  20.7M|          while (pos < final_pos) {
  ------------------
  |  Branch (232:18): [True: 16.6M, False: 4.15M]
  ------------------
  233|  16.6M|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (233:30): [Folded, False: 16.6M]
  ------------------
  234|  16.6M|                                 ? char(u16_swap_bytes(data[pos]))
  235|  16.6M|                                 : char(data[pos]);
  236|  16.6M|            pos++;
  237|  16.6M|          }
  238|  4.15M|          continue;
  239|  4.15M|        }
  240|  24.7M|      }
  241|  24.7M|    }
  242|  20.5M|    uint16_t word =
  243|  20.5M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (243:9): [Folded, False: 20.5M]
  ------------------
  244|  20.5M|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (244:9): [True: 404k, False: 20.1M]
  ------------------
  245|       |      // will generate one UTF-8 bytes
  246|   404k|      *utf8_output++ = char(word);
  247|   404k|      pos++;
  248|  20.1M|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (248:16): [True: 508k, False: 19.6M]
  ------------------
  249|       |      // will generate two UTF-8 bytes
  250|       |      // we have 0b110XXXXX 0b10XXXXXX
  251|   508k|      *utf8_output++ = char((word >> 6) | 0b11000000);
  252|   508k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  253|   508k|      pos++;
  254|  19.6M|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (254:16): [True: 18.9M, False: 724k]
  ------------------
  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|   724k|      uint16_t diff = uint16_t(word - 0xD800);
  264|   724k|      if (diff <= 0x3FF && pos + 1 < len) {
  ------------------
  |  Branch (264:11): [True: 429k, False: 294k]
  |  Branch (264:28): [True: 429k, False: 239]
  ------------------
  265|       |        // high surrogate, check for valid pair
  266|   429k|        uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (266:30): [Folded, False: 429k]
  ------------------
  267|   429k|                                 ? u16_swap_bytes(data[pos + 1])
  268|   429k|                                 : data[pos + 1];
  269|   429k|        uint16_t diff2 = uint16_t(next_word - 0xDC00);
  270|   429k|        if (diff2 <= 0x3FF) {
  ------------------
  |  Branch (270:13): [True: 88.3k, False: 341k]
  ------------------
  271|       |          // valid surrogate pair
  272|  88.3k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  273|       |          // will generate four UTF-8 bytes
  274|  88.3k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  275|  88.3k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  276|  88.3k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  277|  88.3k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  278|  88.3k|          pos += 2;
  279|  88.3k|          continue;
  280|  88.3k|        }
  281|   429k|      }
  282|       |      // unpaired surrogate: replace with U+FFFD (0xEF 0xBF 0xBD)
  283|   636k|      *utf8_output++ = char(0xef);
  284|   636k|      *utf8_output++ = char(0xbf);
  285|   636k|      *utf8_output++ = char(0xbd);
  286|   636k|      pos++;
  287|   636k|    }
  288|  20.5M|  }
  289|  1.49k|  return utf8_output - start;
  290|  1.49k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf824convert_with_replacementILNS_10endiannessE1EEEmPKDsmPc:
  214|  1.40k|                                                    char *utf8_output) {
  215|  1.40k|  size_t pos = 0;
  216|  1.40k|  char *start = utf8_output;
  217|  18.9M|  while (pos < len) {
  ------------------
  |  Branch (217:10): [True: 18.8M, False: 1.40k]
  ------------------
  218|       |#if SIMDUTF_CPLUSPLUS23
  219|       |    if !consteval
  220|       |#endif
  221|  18.8M|    {
  222|       |      // try to convert the next block of 8 bytes
  223|  18.8M|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (223:11): [True: 18.8M, False: 3.45k]
  ------------------
  224|       |                            // they are ascii
  225|  18.8M|        uint64_t v;
  226|  18.8M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
  227|  18.8M|        if constexpr (!match_system(big_endian)) {
  228|  18.8M|          v = (v >> 8) | (v << (64 - 8));
  229|  18.8M|        }
  230|  18.8M|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (230:13): [True: 3.32M, False: 15.5M]
  ------------------
  231|  3.32M|          size_t final_pos = pos + 4;
  232|  16.6M|          while (pos < final_pos) {
  ------------------
  |  Branch (232:18): [True: 13.3M, False: 3.32M]
  ------------------
  233|  13.3M|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (233:30): [True: 13.3M, Folded]
  ------------------
  234|  13.3M|                                 ? char(u16_swap_bytes(data[pos]))
  235|  13.3M|                                 : char(data[pos]);
  236|  13.3M|            pos++;
  237|  13.3M|          }
  238|  3.32M|          continue;
  239|  3.32M|        }
  240|  18.8M|      }
  241|  18.8M|    }
  242|  15.5M|    uint16_t word =
  243|  15.5M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (243:9): [True: 15.5M, Folded]
  ------------------
  244|  15.5M|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (244:9): [True: 307k, False: 15.2M]
  ------------------
  245|       |      // will generate one UTF-8 bytes
  246|   307k|      *utf8_output++ = char(word);
  247|   307k|      pos++;
  248|  15.2M|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (248:16): [True: 288k, False: 14.9M]
  ------------------
  249|       |      // will generate two UTF-8 bytes
  250|       |      // we have 0b110XXXXX 0b10XXXXXX
  251|   288k|      *utf8_output++ = char((word >> 6) | 0b11000000);
  252|   288k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  253|   288k|      pos++;
  254|  14.9M|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (254:16): [True: 13.8M, False: 1.14M]
  ------------------
  255|       |      // will generate three UTF-8 bytes
  256|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
  257|  13.8M|      *utf8_output++ = char((word >> 12) | 0b11100000);
  258|  13.8M|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  259|  13.8M|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  260|  13.8M|      pos++;
  261|  13.8M|    } else {
  262|       |      // surrogate range
  263|  1.14M|      uint16_t diff = uint16_t(word - 0xD800);
  264|  1.14M|      if (diff <= 0x3FF && pos + 1 < len) {
  ------------------
  |  Branch (264:11): [True: 385k, False: 758k]
  |  Branch (264:28): [True: 385k, False: 253]
  ------------------
  265|       |        // high surrogate, check for valid pair
  266|   385k|        uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (266:30): [True: 385k, Folded]
  ------------------
  267|   385k|                                 ? u16_swap_bytes(data[pos + 1])
  268|   385k|                                 : data[pos + 1];
  269|   385k|        uint16_t diff2 = uint16_t(next_word - 0xDC00);
  270|   385k|        if (diff2 <= 0x3FF) {
  ------------------
  |  Branch (270:13): [True: 91.0k, False: 294k]
  ------------------
  271|       |          // valid surrogate pair
  272|  91.0k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  273|       |          // will generate four UTF-8 bytes
  274|  91.0k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  275|  91.0k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  276|  91.0k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  277|  91.0k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  278|  91.0k|          pos += 2;
  279|  91.0k|          continue;
  280|  91.0k|        }
  281|   385k|      }
  282|       |      // unpaired surrogate: replace with U+FFFD (0xEF 0xBF 0xBD)
  283|  1.05M|      *utf8_output++ = char(0xef);
  284|  1.05M|      *utf8_output++ = char(0xbf);
  285|  1.05M|      *utf8_output++ = char(0xbd);
  286|  1.05M|      pos++;
  287|  1.05M|    }
  288|  15.5M|  }
  289|  1.40k|  return utf8_output - start;
  290|  1.40k|}

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

_ZNK7simdutf8fallback14implementation13validate_utf8EPKcm:
   37|  2.89k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
   38|  2.89k|  return scalar::utf8::validate(buf, len);
   39|  2.89k|}
_ZNK7simdutf8fallback14implementation24utf8_length_from_utf16leEPKDsm:
  452|    440|    const char16_t *input, size_t length) const noexcept {
  453|    440|  return scalar::utf16::utf8_length_from_utf16<endianness::LITTLE>(input,
  454|    440|                                                                   length);
  455|    440|}
_ZNK7simdutf8fallback14implementation24utf8_length_from_utf16beEPKDsm:
  458|    390|    const char16_t *input, size_t length) const noexcept {
  459|    390|  return scalar::utf16::utf8_length_from_utf16<endianness::BIG>(input, length);
  460|    390|}
_ZNK7simdutf8fallback14implementation41utf8_length_from_utf16le_with_replacementEPKDsm:
  483|  1.49k|    const char16_t *input, size_t length) const noexcept {
  484|  1.49k|  return scalar::utf16::utf8_length_from_utf16_with_replacement<
  485|  1.49k|      endianness::LITTLE>(input, length);
  486|  1.49k|}
_ZNK7simdutf8fallback14implementation41utf8_length_from_utf16be_with_replacementEPKDsm:
  490|  1.40k|    const char16_t *input, size_t length) const noexcept {
  491|  1.40k|  return scalar::utf16::utf8_length_from_utf16_with_replacement<
  492|  1.40k|      endianness::BIG>(input, length);
  493|  1.40k|}
_ZNK7simdutf8fallback14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPc:
  497|  1.49k|    const char16_t *input, size_t length, char *utf8_buffer) const noexcept {
  498|  1.49k|  return scalar::utf16_to_utf8::convert_with_replacement<endianness::LITTLE>(
  499|  1.49k|      input, length, utf8_buffer);
  500|  1.49k|}
_ZNK7simdutf8fallback14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPc:
  504|  1.40k|    const char16_t *input, size_t length, char *utf8_buffer) const noexcept {
  505|  1.40k|  return scalar::utf16_to_utf8::convert_with_replacement<endianness::BIG>(
  506|  1.40k|      input, length, utf8_buffer);
  507|  1.40k|}

simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE13get_remainderEPh:
   57|  2.89k|buf_block_reader<STEP_SIZE>::get_remainder(uint8_t *dst) const {
   58|  2.89k|  if (len == idx) {
  ------------------
  |  Branch (58:7): [True: 4, False: 2.89k]
  ------------------
   59|      4|    return 0;
   60|      4|  } // memcpy(dst, null, 0) will trigger an error with some sanitizers
   61|  2.89k|  std::memset(dst, 0x20,
   62|  2.89k|              STEP_SIZE); // std::memset STEP_SIZE because it is more efficient
   63|       |                          // to write out 8 or 16 bytes at once.
   64|  2.89k|  std::memcpy(dst, buf + idx, len - idx);
   65|  2.89k|  return len - idx;
   66|  2.89k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE13get_remainderEPh:
   57|  2.89k|buf_block_reader<STEP_SIZE>::get_remainder(uint8_t *dst) const {
   58|  2.89k|  if (len == idx) {
  ------------------
  |  Branch (58:7): [True: 4, False: 2.89k]
  ------------------
   59|      4|    return 0;
   60|      4|  } // memcpy(dst, null, 0) will trigger an error with some sanitizers
   61|  2.89k|  std::memset(dst, 0x20,
   62|  2.89k|              STEP_SIZE); // std::memset STEP_SIZE because it is more efficient
   63|       |                          // to write out 8 or 16 bytes at once.
   64|  2.89k|  std::memcpy(dst, buf + idx, len - idx);
   65|  2.89k|  return len - idx;
   66|  2.89k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EEC2EPKhm:
   36|  2.89k|    : buf{_buf}, len{_len}, lenminusstep{len < STEP_SIZE ? 0 : len - STEP_SIZE},
  ------------------
  |  Branch (36:42): [True: 1.72k, False: 1.17k]
  ------------------
   37|  2.89k|      idx{0} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE14has_full_blockEv:
   45|  2.13M|simdutf_really_inline bool buf_block_reader<STEP_SIZE>::has_full_block() const {
   46|  2.13M|  return idx < lenminusstep;
   47|  2.13M|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE10full_blockEv:
   51|  2.12M|buf_block_reader<STEP_SIZE>::full_block() const {
   52|  2.12M|  return &buf[idx];
   53|  2.12M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE7advanceEv:
   69|  2.13M|simdutf_really_inline void buf_block_reader<STEP_SIZE>::advance() {
   70|  2.13M|  idx += STEP_SIZE;
   71|  2.13M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EEC2EPKhm:
   36|  2.89k|    : buf{_buf}, len{_len}, lenminusstep{len < STEP_SIZE ? 0 : len - STEP_SIZE},
  ------------------
  |  Branch (36:42): [True: 1.72k, False: 1.17k]
  ------------------
   37|  2.89k|      idx{0} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE14has_full_blockEv:
   45|  2.13M|simdutf_really_inline bool buf_block_reader<STEP_SIZE>::has_full_block() const {
   46|  2.13M|  return idx < lenminusstep;
   47|  2.13M|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE10full_blockEv:
   51|  2.12M|buf_block_reader<STEP_SIZE>::full_block() const {
   52|  2.12M|  return &buf[idx];
   53|  2.12M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE7advanceEv:
   69|  2.13M|simdutf_really_inline void buf_block_reader<STEP_SIZE>::advance() {
   70|  2.13M|  idx += STEP_SIZE;
   71|  2.13M|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE0EEEmPKDsm:
   10|   636k|                                                             size_t size) {
   11|   636k|  size_t pos = 0;
   12|       |
   13|   636k|  using vector_u16 = simd16<uint16_t>;
   14|   636k|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|   636k|  const auto one = vector_u16::splat(1);
   17|       |
   18|   636k|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|   636k|  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|   636k|  constexpr size_t max_iterations = 65535 / 2;
   26|   636k|  size_t iteration = max_iterations;
   27|       |
   28|  2.32M|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 1.68M, False: 636k]
  ------------------
   29|  1.68M|    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.68M|    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.68M|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|  1.68M|    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.68M|    v_count += c0;
   68|  1.68M|    v_count += c1;
   69|  1.68M|    v_count += vector_u16(is_surrogate);
   70|       |
   71|  1.68M|    iteration -= 1;
   72|  1.68M|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 19, False: 1.68M]
  ------------------
   73|     19|      count += v_count.sum();
   74|     19|      v_count = vector_u16::zero();
   75|     19|      iteration = max_iterations;
   76|     19|    }
   77|  1.68M|  }
   78|       |
   79|   636k|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 636k, False: 0]
  ------------------
   80|   636k|    count += v_count.sum();
   81|   636k|  }
   82|       |
   83|   636k|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|   636k|                                                                   size - pos);
   85|   636k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE1EEEmPKDsm:
   10|  1.05M|                                                             size_t size) {
   11|  1.05M|  size_t pos = 0;
   12|       |
   13|  1.05M|  using vector_u16 = simd16<uint16_t>;
   14|  1.05M|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|  1.05M|  const auto one = vector_u16::splat(1);
   17|       |
   18|  1.05M|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|  1.05M|  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|  1.05M|  constexpr size_t max_iterations = 65535 / 2;
   26|  1.05M|  size_t iteration = max_iterations;
   27|       |
   28|  2.26M|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 1.20M, False: 1.05M]
  ------------------
   29|  1.20M|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
   30|  1.20M|    if constexpr (!match_system(big_endian)) {
   31|  1.20M|      input = input.swap_bytes();
   32|  1.20M|    }
   33|       |    // 0xd800 .. 0xdbff - low surrogate
   34|       |    // 0xdc00 .. 0xdfff - high surrogate
   35|  1.20M|    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.20M|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|  1.20M|    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.20M|    v_count += c0;
   68|  1.20M|    v_count += c1;
   69|  1.20M|    v_count += vector_u16(is_surrogate);
   70|       |
   71|  1.20M|    iteration -= 1;
   72|  1.20M|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 12, False: 1.20M]
  ------------------
   73|     12|      count += v_count.sum();
   74|     12|      v_count = vector_u16::zero();
   75|     12|      iteration = max_iterations;
   76|     12|    }
   77|  1.20M|  }
   78|       |
   79|  1.05M|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 1.05M, False: 0]
  ------------------
   80|  1.05M|    count += v_count.sum();
   81|  1.05M|  }
   82|       |
   83|  1.05M|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|  1.05M|                                                                   size - pos);
   85|  1.05M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1639utf8_length_from_utf16_with_replacementILNS_10endiannessE0EEENS_6resultEPKDsm:
   89|  1.49k|utf8_length_from_utf16_with_replacement(const char16_t *in, size_t size) {
   90|  1.49k|  using vector_u16 = simd16<uint16_t>;
   91|  1.49k|  constexpr size_t N = vector_u16::ELEMENTS;
   92|  1.49k|  if (N + 1 > size) {
  ------------------
  |  Branch (92:7): [True: 565, False: 927]
  ------------------
   93|    565|    return scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
   94|    565|        in, size);
   95|    565|  } // special case for short inputs
   96|    927|  size_t pos = 0;
   97|    927|  bool any_surrogates = false;
   98|       |
   99|    927|  const auto one = vector_u16::splat(1);
  100|       |
  101|    927|  auto v_count = vector_u16::zero();
  102|    927|  auto v_mismatched_count = vector_u16::zero();
  103|       |
  104|    927|  size_t count = 0;
  105|    927|  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|    927|  constexpr size_t max_iterations = 65535 / 2;
  110|    927|  size_t iteration = max_iterations;
  111|       |
  112|    927|  if (scalar::utf16::is_low_surrogate<big_endian>(in[0])) {
  ------------------
  |  Branch (112:7): [True: 39, False: 888]
  ------------------
  113|     39|    any_surrogates = true;
  114|     39|    mismatched_count += 1;
  115|     39|  }
  116|       |
  117|  2.33M|  for (; pos < (size - 1) / N * N; pos += N) {
  ------------------
  |  Branch (117:10): [True: 2.32M, False: 927]
  ------------------
  118|  2.32M|    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.32M|    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.32M|    const auto c0 = min(input & uint16_t(0xff80), one);
  128|       |
  129|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
  130|  2.32M|    const auto c1 = min(input & uint16_t(0xf800), one);
  131|       |
  132|  2.32M|    v_count += c0;
  133|  2.32M|    v_count += c1;
  134|  2.32M|    v_count += vector_u16(is_surrogate);
  135|  2.32M|    if (is_surrogate.to_bitmask() != 0 ||
  ------------------
  |  Branch (135:9): [True: 181k, False: 2.14M]
  ------------------
  136|  2.14M|        scalar::utf16::is_low_surrogate<big_endian>(in[pos + N])) {
  ------------------
  |  Branch (136:9): [True: 3.00k, False: 2.14M]
  ------------------
  137|   184k|      any_surrogates = true;
  138|   184k|      auto input_next =
  139|   184k|          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|   184k|      const auto lb_masked = input & (0xfc00);
  145|   184k|      const auto block_masked = input_next & (0xfc00);
  146|       |
  147|   184k|      const auto lb_is_high = lb_masked == (0xd800);
  148|   184k|      const auto block_is_low = block_masked == (0xdc00);
  149|       |
  150|   184k|      const auto illseq = min(vector_u16(lb_is_high ^ block_is_low), one);
  151|       |
  152|   184k|      v_mismatched_count += illseq;
  153|   184k|    }
  154|       |
  155|  2.32M|    iteration -= 1;
  156|  2.32M|    if (iteration == 0) {
  ------------------
  |  Branch (156:9): [True: 42, False: 2.32M]
  ------------------
  157|     42|      count += v_count.sum();
  158|     42|      v_count = vector_u16::zero();
  159|     42|      mismatched_count += v_mismatched_count.sum();
  160|     42|      v_mismatched_count = vector_u16::zero();
  161|     42|      iteration = max_iterations;
  162|     42|    }
  163|  2.32M|  }
  164|       |
  165|    927|  if (iteration > 0) {
  ------------------
  |  Branch (165:7): [True: 927, False: 0]
  ------------------
  166|    927|    count += v_count.sum();
  167|    927|    mismatched_count += v_mismatched_count.sum();
  168|    927|  }
  169|       |
  170|    927|  if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (170:7): [True: 127, False: 800]
  ------------------
  171|    127|    any_surrogates = true;
  172|    127|    if (!scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (172:9): [True: 97, False: 30]
  ------------------
  173|     97|      mismatched_count -= 1;
  174|     97|      count += 2;
  175|     97|      pos += 1;
  176|     97|    }
  177|    127|  }
  178|    927|  count += pos;
  179|    927|  count += mismatched_count;
  180|    927|  if (scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (180:7): [True: 139, False: 788]
  ------------------
  181|    139|    any_surrogates = true;
  182|    139|    if (pos == size) {
  ------------------
  |  Branch (182:9): [True: 0, False: 139]
  ------------------
  183|      0|      count += 2;
  184|    139|    } else if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (184:16): [True: 30, False: 109]
  ------------------
  185|     30|      pos += 1;
  186|     30|      count += 2;
  187|     30|    }
  188|    139|  }
  189|    927|  result scalar_result =
  190|    927|      scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
  191|    927|          in + pos, size - pos);
  192|    927|  return {any_surrogates ? SURROGATE : scalar_result.error,
  ------------------
  |  Branch (192:11): [True: 591, False: 336]
  ------------------
  193|    927|          count + scalar_result.count};
  194|  1.49k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1639utf8_length_from_utf16_with_replacementILNS_10endiannessE1EEENS_6resultEPKDsm:
   89|  1.40k|utf8_length_from_utf16_with_replacement(const char16_t *in, size_t size) {
   90|  1.40k|  using vector_u16 = simd16<uint16_t>;
   91|  1.40k|  constexpr size_t N = vector_u16::ELEMENTS;
   92|  1.40k|  if (N + 1 > size) {
  ------------------
  |  Branch (92:7): [True: 576, False: 827]
  ------------------
   93|    576|    return scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
   94|    576|        in, size);
   95|    576|  } // special case for short inputs
   96|    827|  size_t pos = 0;
   97|    827|  bool any_surrogates = false;
   98|       |
   99|    827|  const auto one = vector_u16::splat(1);
  100|       |
  101|    827|  auto v_count = vector_u16::zero();
  102|    827|  auto v_mismatched_count = vector_u16::zero();
  103|       |
  104|    827|  size_t count = 0;
  105|    827|  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|    827|  constexpr size_t max_iterations = 65535 / 2;
  110|    827|  size_t iteration = max_iterations;
  111|       |
  112|    827|  if (scalar::utf16::is_low_surrogate<big_endian>(in[0])) {
  ------------------
  |  Branch (112:7): [True: 44, False: 783]
  ------------------
  113|     44|    any_surrogates = true;
  114|     44|    mismatched_count += 1;
  115|     44|  }
  116|       |
  117|  1.81M|  for (; pos < (size - 1) / N * N; pos += N) {
  ------------------
  |  Branch (117:10): [True: 1.81M, False: 827]
  ------------------
  118|  1.81M|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
  119|  1.81M|    if constexpr (!match_system(big_endian)) {
  120|  1.81M|      input = input.swap_bytes();
  121|  1.81M|    }
  122|       |    // 0xd800 .. 0xdbff - low surrogate
  123|       |    // 0xdc00 .. 0xdfff - high surrogate
  124|  1.81M|    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.81M|    const auto c0 = min(input & uint16_t(0xff80), one);
  128|       |
  129|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
  130|  1.81M|    const auto c1 = min(input & uint16_t(0xf800), one);
  131|       |
  132|  1.81M|    v_count += c0;
  133|  1.81M|    v_count += c1;
  134|  1.81M|    v_count += vector_u16(is_surrogate);
  135|  1.81M|    if (is_surrogate.to_bitmask() != 0 ||
  ------------------
  |  Branch (135:9): [True: 169k, False: 1.64M]
  ------------------
  136|  1.64M|        scalar::utf16::is_low_surrogate<big_endian>(in[pos + N])) {
  ------------------
  |  Branch (136:9): [True: 2.14k, False: 1.63M]
  ------------------
  137|   171k|      any_surrogates = true;
  138|   171k|      auto input_next =
  139|   171k|          vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos + 1));
  140|   171k|      if constexpr (!match_system(big_endian)) {
  141|   171k|        input_next = input_next.swap_bytes();
  142|   171k|      }
  143|       |
  144|   171k|      const auto lb_masked = input & (0xfc00);
  145|   171k|      const auto block_masked = input_next & (0xfc00);
  146|       |
  147|   171k|      const auto lb_is_high = lb_masked == (0xd800);
  148|   171k|      const auto block_is_low = block_masked == (0xdc00);
  149|       |
  150|   171k|      const auto illseq = min(vector_u16(lb_is_high ^ block_is_low), one);
  151|       |
  152|   171k|      v_mismatched_count += illseq;
  153|   171k|    }
  154|       |
  155|  1.81M|    iteration -= 1;
  156|  1.81M|    if (iteration == 0) {
  ------------------
  |  Branch (156:9): [True: 33, False: 1.81M]
  ------------------
  157|     33|      count += v_count.sum();
  158|     33|      v_count = vector_u16::zero();
  159|     33|      mismatched_count += v_mismatched_count.sum();
  160|     33|      v_mismatched_count = vector_u16::zero();
  161|     33|      iteration = max_iterations;
  162|     33|    }
  163|  1.81M|  }
  164|       |
  165|    827|  if (iteration > 0) {
  ------------------
  |  Branch (165:7): [True: 827, False: 0]
  ------------------
  166|    827|    count += v_count.sum();
  167|    827|    mismatched_count += v_mismatched_count.sum();
  168|    827|  }
  169|       |
  170|    827|  if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (170:7): [True: 123, False: 704]
  ------------------
  171|    123|    any_surrogates = true;
  172|    123|    if (!scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (172:9): [True: 86, False: 37]
  ------------------
  173|     86|      mismatched_count -= 1;
  174|     86|      count += 2;
  175|     86|      pos += 1;
  176|     86|    }
  177|    123|  }
  178|    827|  count += pos;
  179|    827|  count += mismatched_count;
  180|    827|  if (scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (180:7): [True: 136, False: 691]
  ------------------
  181|    136|    any_surrogates = true;
  182|    136|    if (pos == size) {
  ------------------
  |  Branch (182:9): [True: 0, False: 136]
  ------------------
  183|      0|      count += 2;
  184|    136|    } else if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (184:16): [True: 37, False: 99]
  ------------------
  185|     37|      pos += 1;
  186|     37|      count += 2;
  187|     37|    }
  188|    136|  }
  189|    827|  result scalar_result =
  190|    827|      scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
  191|    827|          in + pos, size - pos);
  192|    827|  return {any_surrogates ? SURROGATE : scalar_result.error,
  ------------------
  |  Branch (192:11): [True: 549, False: 278]
  ------------------
  193|    827|          count + scalar_result.count};
  194|  1.40k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE0EEEmPKDsm:
   10|   636k|                                                             size_t size) {
   11|   636k|  size_t pos = 0;
   12|       |
   13|   636k|  using vector_u16 = simd16<uint16_t>;
   14|   636k|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|   636k|  const auto one = vector_u16::splat(1);
   17|       |
   18|   636k|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|   636k|  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|   636k|  constexpr size_t max_iterations = 65535 / 2;
   26|   636k|  size_t iteration = max_iterations;
   27|       |
   28|  4.08M|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 3.44M, False: 636k]
  ------------------
   29|  3.44M|    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|  3.44M|    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|  3.44M|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|  3.44M|    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|  3.44M|    v_count += c0;
   68|  3.44M|    v_count += c1;
   69|  3.44M|    v_count += vector_u16(is_surrogate);
   70|       |
   71|  3.44M|    iteration -= 1;
   72|  3.44M|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 47, False: 3.44M]
  ------------------
   73|     47|      count += v_count.sum();
   74|     47|      v_count = vector_u16::zero();
   75|     47|      iteration = max_iterations;
   76|     47|    }
   77|  3.44M|  }
   78|       |
   79|   636k|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 636k, False: 0]
  ------------------
   80|   636k|    count += v_count.sum();
   81|   636k|  }
   82|       |
   83|   636k|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|   636k|                                                                   size - pos);
   85|   636k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE1EEEmPKDsm:
   10|  1.05M|                                                             size_t size) {
   11|  1.05M|  size_t pos = 0;
   12|       |
   13|  1.05M|  using vector_u16 = simd16<uint16_t>;
   14|  1.05M|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|  1.05M|  const auto one = vector_u16::splat(1);
   17|       |
   18|  1.05M|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|  1.05M|  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|  1.05M|  constexpr size_t max_iterations = 65535 / 2;
   26|  1.05M|  size_t iteration = max_iterations;
   27|       |
   28|  3.52M|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 2.46M, False: 1.05M]
  ------------------
   29|  2.46M|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
   30|  2.46M|    if constexpr (!match_system(big_endian)) {
   31|  2.46M|      input = input.swap_bytes();
   32|  2.46M|    }
   33|       |    // 0xd800 .. 0xdbff - low surrogate
   34|       |    // 0xdc00 .. 0xdfff - high surrogate
   35|  2.46M|    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.46M|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|  2.46M|    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.46M|    v_count += c0;
   68|  2.46M|    v_count += c1;
   69|  2.46M|    v_count += vector_u16(is_surrogate);
   70|       |
   71|  2.46M|    iteration -= 1;
   72|  2.46M|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 34, False: 2.46M]
  ------------------
   73|     34|      count += v_count.sum();
   74|     34|      v_count = vector_u16::zero();
   75|     34|      iteration = max_iterations;
   76|     34|    }
   77|  2.46M|  }
   78|       |
   79|  1.05M|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 1.05M, False: 0]
  ------------------
   80|  1.05M|    count += v_count.sum();
   81|  1.05M|  }
   82|       |
   83|  1.05M|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|  1.05M|                                                                   size - pos);
   85|  1.05M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1639utf8_length_from_utf16_with_replacementILNS_10endiannessE0EEENS_6resultEPKDsm:
   89|  1.49k|utf8_length_from_utf16_with_replacement(const char16_t *in, size_t size) {
   90|  1.49k|  using vector_u16 = simd16<uint16_t>;
   91|  1.49k|  constexpr size_t N = vector_u16::ELEMENTS;
   92|  1.49k|  if (N + 1 > size) {
  ------------------
  |  Branch (92:7): [True: 298, False: 1.19k]
  ------------------
   93|    298|    return scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
   94|    298|        in, size);
   95|    298|  } // 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: 64, False: 1.13k]
  ------------------
  113|     64|    any_surrogates = true;
  114|     64|    mismatched_count += 1;
  115|     64|  }
  116|       |
  117|  4.66M|  for (; pos < (size - 1) / N * N; pos += N) {
  ------------------
  |  Branch (117:10): [True: 4.65M, False: 1.19k]
  ------------------
  118|  4.65M|    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.65M|    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.65M|    const auto c0 = min(input & uint16_t(0xff80), one);
  128|       |
  129|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
  130|  4.65M|    const auto c1 = min(input & uint16_t(0xf800), one);
  131|       |
  132|  4.65M|    v_count += c0;
  133|  4.65M|    v_count += c1;
  134|  4.65M|    v_count += vector_u16(is_surrogate);
  135|  4.65M|    if (is_surrogate.to_bitmask() != 0 ||
  ------------------
  |  Branch (135:9): [True: 260k, False: 4.39M]
  ------------------
  136|  4.39M|        scalar::utf16::is_low_surrogate<big_endian>(in[pos + N])) {
  ------------------
  |  Branch (136:9): [True: 8.21k, False: 4.39M]
  ------------------
  137|   268k|      any_surrogates = true;
  138|   268k|      auto input_next =
  139|   268k|          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|   268k|      const auto lb_masked = input & (0xfc00);
  145|   268k|      const auto block_masked = input_next & (0xfc00);
  146|       |
  147|   268k|      const auto lb_is_high = lb_masked == (0xd800);
  148|   268k|      const auto block_is_low = block_masked == (0xdc00);
  149|       |
  150|   268k|      const auto illseq = min(vector_u16(lb_is_high ^ block_is_low), one);
  151|       |
  152|   268k|      v_mismatched_count += illseq;
  153|   268k|    }
  154|       |
  155|  4.65M|    iteration -= 1;
  156|  4.65M|    if (iteration == 0) {
  ------------------
  |  Branch (156:9): [True: 109, False: 4.65M]
  ------------------
  157|    109|      count += v_count.sum();
  158|    109|      v_count = vector_u16::zero();
  159|    109|      mismatched_count += v_mismatched_count.sum();
  160|    109|      v_mismatched_count = vector_u16::zero();
  161|    109|      iteration = max_iterations;
  162|    109|    }
  163|  4.65M|  }
  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: 224, False: 970]
  ------------------
  171|    224|    any_surrogates = true;
  172|    224|    if (!scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (172:9): [True: 166, False: 58]
  ------------------
  173|    166|      mismatched_count -= 1;
  174|    166|      count += 2;
  175|    166|      pos += 1;
  176|    166|    }
  177|    224|  }
  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: 185, False: 1.00k]
  ------------------
  181|    185|    any_surrogates = true;
  182|    185|    if (pos == size) {
  ------------------
  |  Branch (182:9): [True: 0, False: 185]
  ------------------
  183|      0|      count += 2;
  184|    185|    } else if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (184:16): [True: 58, False: 127]
  ------------------
  185|     58|      pos += 1;
  186|     58|      count += 2;
  187|     58|    }
  188|    185|  }
  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: 777, False: 417]
  ------------------
  193|  1.19k|          count + scalar_result.count};
  194|  1.49k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1639utf8_length_from_utf16_with_replacementILNS_10endiannessE1EEENS_6resultEPKDsm:
   89|  1.40k|utf8_length_from_utf16_with_replacement(const char16_t *in, size_t size) {
   90|  1.40k|  using vector_u16 = simd16<uint16_t>;
   91|  1.40k|  constexpr size_t N = vector_u16::ELEMENTS;
   92|  1.40k|  if (N + 1 > size) {
  ------------------
  |  Branch (92:7): [True: 303, False: 1.10k]
  ------------------
   93|    303|    return scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
   94|    303|        in, size);
   95|    303|  } // special case for short inputs
   96|  1.10k|  size_t pos = 0;
   97|  1.10k|  bool any_surrogates = false;
   98|       |
   99|  1.10k|  const auto one = vector_u16::splat(1);
  100|       |
  101|  1.10k|  auto v_count = vector_u16::zero();
  102|  1.10k|  auto v_mismatched_count = vector_u16::zero();
  103|       |
  104|  1.10k|  size_t count = 0;
  105|  1.10k|  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.10k|  constexpr size_t max_iterations = 65535 / 2;
  110|  1.10k|  size_t iteration = max_iterations;
  111|       |
  112|  1.10k|  if (scalar::utf16::is_low_surrogate<big_endian>(in[0])) {
  ------------------
  |  Branch (112:7): [True: 65, False: 1.03k]
  ------------------
  113|     65|    any_surrogates = true;
  114|     65|    mismatched_count += 1;
  115|     65|  }
  116|       |
  117|  3.62M|  for (; pos < (size - 1) / N * N; pos += N) {
  ------------------
  |  Branch (117:10): [True: 3.62M, False: 1.10k]
  ------------------
  118|  3.62M|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
  119|  3.62M|    if constexpr (!match_system(big_endian)) {
  120|  3.62M|      input = input.swap_bytes();
  121|  3.62M|    }
  122|       |    // 0xd800 .. 0xdbff - low surrogate
  123|       |    // 0xdc00 .. 0xdfff - high surrogate
  124|  3.62M|    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.62M|    const auto c0 = min(input & uint16_t(0xff80), one);
  128|       |
  129|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
  130|  3.62M|    const auto c1 = min(input & uint16_t(0xf800), one);
  131|       |
  132|  3.62M|    v_count += c0;
  133|  3.62M|    v_count += c1;
  134|  3.62M|    v_count += vector_u16(is_surrogate);
  135|  3.62M|    if (is_surrogate.to_bitmask() != 0 ||
  ------------------
  |  Branch (135:9): [True: 272k, False: 3.34M]
  ------------------
  136|  3.34M|        scalar::utf16::is_low_surrogate<big_endian>(in[pos + N])) {
  ------------------
  |  Branch (136:9): [True: 5.74k, False: 3.34M]
  ------------------
  137|   277k|      any_surrogates = true;
  138|   277k|      auto input_next =
  139|   277k|          vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos + 1));
  140|   277k|      if constexpr (!match_system(big_endian)) {
  141|   277k|        input_next = input_next.swap_bytes();
  142|   277k|      }
  143|       |
  144|   277k|      const auto lb_masked = input & (0xfc00);
  145|   277k|      const auto block_masked = input_next & (0xfc00);
  146|       |
  147|   277k|      const auto lb_is_high = lb_masked == (0xd800);
  148|   277k|      const auto block_is_low = block_masked == (0xdc00);
  149|       |
  150|   277k|      const auto illseq = min(vector_u16(lb_is_high ^ block_is_low), one);
  151|       |
  152|   277k|      v_mismatched_count += illseq;
  153|   277k|    }
  154|       |
  155|  3.62M|    iteration -= 1;
  156|  3.62M|    if (iteration == 0) {
  ------------------
  |  Branch (156:9): [True: 78, False: 3.62M]
  ------------------
  157|     78|      count += v_count.sum();
  158|     78|      v_count = vector_u16::zero();
  159|     78|      mismatched_count += v_mismatched_count.sum();
  160|     78|      v_mismatched_count = vector_u16::zero();
  161|     78|      iteration = max_iterations;
  162|     78|    }
  163|  3.62M|  }
  164|       |
  165|  1.10k|  if (iteration > 0) {
  ------------------
  |  Branch (165:7): [True: 1.10k, False: 0]
  ------------------
  166|  1.10k|    count += v_count.sum();
  167|  1.10k|    mismatched_count += v_mismatched_count.sum();
  168|  1.10k|  }
  169|       |
  170|  1.10k|  if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (170:7): [True: 209, False: 891]
  ------------------
  171|    209|    any_surrogates = true;
  172|    209|    if (!scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (172:9): [True: 149, False: 60]
  ------------------
  173|    149|      mismatched_count -= 1;
  174|    149|      count += 2;
  175|    149|      pos += 1;
  176|    149|    }
  177|    209|  }
  178|  1.10k|  count += pos;
  179|  1.10k|  count += mismatched_count;
  180|  1.10k|  if (scalar::utf16::is_high_surrogate<big_endian>(in[pos - 1])) {
  ------------------
  |  Branch (180:7): [True: 212, False: 888]
  ------------------
  181|    212|    any_surrogates = true;
  182|    212|    if (pos == size) {
  ------------------
  |  Branch (182:9): [True: 0, False: 212]
  ------------------
  183|      0|      count += 2;
  184|    212|    } else if (scalar::utf16::is_low_surrogate<big_endian>(in[pos])) {
  ------------------
  |  Branch (184:16): [True: 60, False: 152]
  ------------------
  185|     60|      pos += 1;
  186|     60|      count += 2;
  187|     60|    }
  188|    212|  }
  189|  1.10k|  result scalar_result =
  190|  1.10k|      scalar::utf16::utf8_length_from_utf16_with_replacement<big_endian>(
  191|  1.10k|          in + pos, size - pos);
  192|  1.10k|  return {any_surrogates ? SURROGATE : scalar_result.error,
  ------------------
  |  Branch (192:11): [True: 746, False: 354]
  ------------------
  193|  1.10k|          count + scalar_result.count};
  194|  1.40k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf16_to_utf828convert_with_replacement_viaIZNKS0_14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPcE3$_0ZNKS4_40convert_utf16le_to_utf8_with_replacementES6_mS7_E3$_1EEmT_T0_S6_mS7_:
   21|  1.49k|    const char16_t *buf, size_t len, char *utf8_output) {
   22|  1.49k|  char *const start = utf8_output;
   23|  1.49k|  size_t pos = 0;
   24|   637k|  while (pos < len) {
  ------------------
  |  Branch (24:10): [True: 637k, False: 527]
  ------------------
   25|   637k|    result r = convert_with_errors(buf + pos, len - pos, utf8_output);
   26|   637k|    if (r.error != error_code::SURROGATE) {
  ------------------
  |  Branch (26:9): [True: 965, False: 636k]
  ------------------
   27|    965|      utf8_output += r.count; // SUCCESS: r.count == UTF-8 bytes written
   28|    965|      break;
   29|    965|    }
   30|       |    // buf[pos + r.count] is unpaired; the valid prefix is already written.
   31|   636k|    const size_t valid_units = r.count;
   32|   636k|    utf8_output += utf8_length(buf + pos, valid_units);
   33|   636k|    pos += valid_units;
   34|       |    // Emit U+FFFD and skip the offending code unit.
   35|   636k|    utf8_output[0] = char(0xef);
   36|   636k|    utf8_output[1] = char(0xbf);
   37|   636k|    utf8_output[2] = char(0xbd);
   38|   636k|    utf8_output += 3;
   39|   636k|    pos += 1;
   40|   636k|  }
   41|  1.49k|  return size_t(utf8_output - start);
   42|  1.49k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf16_to_utf828convert_with_replacement_viaIZNKS0_14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPcE3$_0ZNKS4_40convert_utf16be_to_utf8_with_replacementES6_mS7_E3$_1EEmT_T0_S6_mS7_:
   21|  1.40k|    const char16_t *buf, size_t len, char *utf8_output) {
   22|  1.40k|  char *const start = utf8_output;
   23|  1.40k|  size_t pos = 0;
   24|  1.05M|  while (pos < len) {
  ------------------
  |  Branch (24:10): [True: 1.05M, False: 506]
  ------------------
   25|  1.05M|    result r = convert_with_errors(buf + pos, len - pos, utf8_output);
   26|  1.05M|    if (r.error != error_code::SURROGATE) {
  ------------------
  |  Branch (26:9): [True: 897, False: 1.05M]
  ------------------
   27|    897|      utf8_output += r.count; // SUCCESS: r.count == UTF-8 bytes written
   28|    897|      break;
   29|    897|    }
   30|       |    // buf[pos + r.count] is unpaired; the valid prefix is already written.
   31|  1.05M|    const size_t valid_units = r.count;
   32|  1.05M|    utf8_output += utf8_length(buf + pos, valid_units);
   33|  1.05M|    pos += valid_units;
   34|       |    // Emit U+FFFD and skip the offending code unit.
   35|  1.05M|    utf8_output[0] = char(0xef);
   36|  1.05M|    utf8_output[1] = char(0xbf);
   37|  1.05M|    utf8_output[2] = char(0xbd);
   38|  1.05M|    utf8_output += 3;
   39|  1.05M|    pos += 1;
   40|  1.05M|  }
   41|  1.40k|  return size_t(utf8_output - start);
   42|  1.40k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf16_to_utf828convert_with_replacement_viaIZNKS0_14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPcE3$_0ZNKS4_40convert_utf16le_to_utf8_with_replacementES6_mS7_E3$_1EEmT_T0_S6_mS7_:
   21|  1.49k|    const char16_t *buf, size_t len, char *utf8_output) {
   22|  1.49k|  char *const start = utf8_output;
   23|  1.49k|  size_t pos = 0;
   24|   637k|  while (pos < len) {
  ------------------
  |  Branch (24:10): [True: 637k, False: 527]
  ------------------
   25|   637k|    result r = convert_with_errors(buf + pos, len - pos, utf8_output);
   26|   637k|    if (r.error != error_code::SURROGATE) {
  ------------------
  |  Branch (26:9): [True: 965, False: 636k]
  ------------------
   27|    965|      utf8_output += r.count; // SUCCESS: r.count == UTF-8 bytes written
   28|    965|      break;
   29|    965|    }
   30|       |    // buf[pos + r.count] is unpaired; the valid prefix is already written.
   31|   636k|    const size_t valid_units = r.count;
   32|   636k|    utf8_output += utf8_length(buf + pos, valid_units);
   33|   636k|    pos += valid_units;
   34|       |    // Emit U+FFFD and skip the offending code unit.
   35|   636k|    utf8_output[0] = char(0xef);
   36|   636k|    utf8_output[1] = char(0xbf);
   37|   636k|    utf8_output[2] = char(0xbd);
   38|   636k|    utf8_output += 3;
   39|   636k|    pos += 1;
   40|   636k|  }
   41|  1.49k|  return size_t(utf8_output - start);
   42|  1.49k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf16_to_utf828convert_with_replacement_viaIZNKS0_14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPcE3$_0ZNKS4_40convert_utf16be_to_utf8_with_replacementES6_mS7_E3$_1EEmT_T0_S6_mS7_:
   21|  1.40k|    const char16_t *buf, size_t len, char *utf8_output) {
   22|  1.40k|  char *const start = utf8_output;
   23|  1.40k|  size_t pos = 0;
   24|  1.05M|  while (pos < len) {
  ------------------
  |  Branch (24:10): [True: 1.05M, False: 506]
  ------------------
   25|  1.05M|    result r = convert_with_errors(buf + pos, len - pos, utf8_output);
   26|  1.05M|    if (r.error != error_code::SURROGATE) {
  ------------------
  |  Branch (26:9): [True: 897, False: 1.05M]
  ------------------
   27|    897|      utf8_output += r.count; // SUCCESS: r.count == UTF-8 bytes written
   28|    897|      break;
   29|    897|    }
   30|       |    // buf[pos + r.count] is unpaired; the valid prefix is already written.
   31|  1.05M|    const size_t valid_units = r.count;
   32|  1.05M|    utf8_output += utf8_length(buf + pos, valid_units);
   33|  1.05M|    pos += valid_units;
   34|       |    // Emit U+FFFD and skip the offending code unit.
   35|  1.05M|    utf8_output[0] = char(0xef);
   36|  1.05M|    utf8_output[1] = char(0xbf);
   37|  1.05M|    utf8_output[2] = char(0xbd);
   38|  1.05M|    utf8_output += 3;
   39|  1.05M|    pos += 1;
   40|  1.05M|  }
   41|  1.40k|  return size_t(utf8_output - start);
   42|  1.40k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker16check_next_inputERKNS1_4simd8simd8x64IhEE:
  187|  2.13M|  simdutf_really_inline void check_next_input(const simd8x64<uint8_t> &input) {
  188|  2.13M|    if (simdutf_likely(is_ascii(input))) {
  ------------------
  |  |   90|  2.13M|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 418k, False: 1.71M]
  |  |  ------------------
  ------------------
  189|   418k|      this->error |= this->prev_incomplete;
  190|  1.71M|    } else {
  191|       |      // you might think that a for-loop would work, but under Visual Studio, it
  192|       |      // is not good enough.
  193|  1.71M|      static_assert((simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  194|  1.71M|                        (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  195|  1.71M|                    "We support either two or four chunks per 64-byte block.");
  196|  1.71M|      if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  197|  1.71M|        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  198|  1.71M|        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  199|       |      } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  200|       |        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  201|       |        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  202|       |        this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  203|       |        this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  204|       |      }
  205|  1.71M|      this->prev_incomplete =
  206|  1.71M|          is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1]);
  207|  1.71M|      this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1];
  208|  1.71M|    }
  209|  2.13M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  169|  3.42M|                                              const simd8<uint8_t> prev_input) {
  170|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  171|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  172|       |    // small negative numbers)
  173|  3.42M|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  174|  3.42M|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  175|  3.42M|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  176|  3.42M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation19check_special_casesENS1_4simd5simd8IhEES5_:
    9|  3.42M|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.42M|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   17|       |                                               // 11______ 11______
   18|  3.42M|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   19|  3.42M|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   20|  3.42M|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   21|  3.42M|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   22|  3.42M|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   23|  3.42M|  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.42M|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   32|       |  // 11110101 1000____
   33|       |  // 1111011_ 1000____
   34|       |  // 11111___ 1000____
   35|  3.42M|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   36|       |
   37|  3.42M|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   38|       |      // 0_______ ________ <ASCII in byte 1>
   39|  3.42M|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   40|  3.42M|      TOO_LONG,
   41|       |      // 10______ ________ <continuation in byte 1>
   42|  3.42M|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   43|       |      // 1100____ ________ <two byte lead in byte 1>
   44|  3.42M|      TOO_SHORT | OVERLONG_2,
   45|       |      // 1101____ ________ <two byte lead in byte 1>
   46|  3.42M|      TOO_SHORT,
   47|       |      // 1110____ ________ <three byte lead in byte 1>
   48|  3.42M|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   49|       |      // 1111____ ________ <four+ byte lead in byte 1>
   50|  3.42M|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   51|  3.42M|  constexpr const uint8_t CARRY =
   52|  3.42M|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   53|  3.42M|  const simd8<uint8_t> byte_1_low =
   54|  3.42M|      (prev1 & 0x0F)
   55|  3.42M|          .lookup_16<uint8_t>(
   56|       |              // ____0000 ________
   57|  3.42M|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   58|       |              // ____0001 ________
   59|  3.42M|              CARRY | OVERLONG_2,
   60|       |              // ____001_ ________
   61|  3.42M|              CARRY, CARRY,
   62|       |
   63|       |              // ____0100 ________
   64|  3.42M|              CARRY | TOO_LARGE,
   65|       |              // ____0101 ________
   66|  3.42M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   67|       |              // ____011_ ________
   68|  3.42M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|  3.42M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   70|       |
   71|       |              // ____1___ ________
   72|  3.42M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  3.42M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  3.42M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  3.42M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|  3.42M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   77|       |              // ____1101 ________
   78|  3.42M|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   79|  3.42M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   80|  3.42M|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   81|  3.42M|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   82|       |      // ________ 0_______ <ASCII in byte 2>
   83|  3.42M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   84|  3.42M|      TOO_SHORT, TOO_SHORT,
   85|       |
   86|       |      // ________ 1000____
   87|  3.42M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   88|  3.42M|          OVERLONG_4,
   89|       |      // ________ 1001____
   90|  3.42M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   91|       |      // ________ 101_____
   92|  3.42M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|  3.42M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   94|       |
   95|       |      // ________ 11______
   96|  3.42M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   97|  3.42M|  return (byte_1_high & byte_1_low & byte_2_high);
   98|  3.42M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation23check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  102|  3.42M|                        const simd8<uint8_t> sc) {
  103|  3.42M|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  104|  3.42M|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  105|  3.42M|  simd8<uint8_t> must23 =
  106|  3.42M|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  107|  3.42M|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  108|  3.42M|  return must23_80 ^ sc;
  109|  3.42M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation13is_incompleteENS1_4simd5simd8IhEE:
  115|  1.71M|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.71M|  static const uint8_t max_array[32] = {255,
  120|  1.71M|                                        255,
  121|  1.71M|                                        255,
  122|  1.71M|                                        255,
  123|  1.71M|                                        255,
  124|  1.71M|                                        255,
  125|  1.71M|                                        255,
  126|  1.71M|                                        255,
  127|  1.71M|                                        255,
  128|  1.71M|                                        255,
  129|  1.71M|                                        255,
  130|  1.71M|                                        255,
  131|  1.71M|                                        255,
  132|  1.71M|                                        255,
  133|  1.71M|                                        255,
  134|  1.71M|                                        255,
  135|  1.71M|                                        255,
  136|  1.71M|                                        255,
  137|  1.71M|                                        255,
  138|  1.71M|                                        255,
  139|  1.71M|                                        255,
  140|  1.71M|                                        255,
  141|  1.71M|                                        255,
  142|  1.71M|                                        255,
  143|  1.71M|                                        255,
  144|  1.71M|                                        255,
  145|  1.71M|                                        255,
  146|  1.71M|                                        255,
  147|  1.71M|                                        255,
  148|  1.71M|                                        0b11110000u - 1,
  149|  1.71M|                                        0b11100000u - 1,
  150|  1.71M|                                        0b11000000u - 1};
  151|  1.71M|  const simd8<uint8_t> max_value(
  152|  1.71M|      &max_array[sizeof(max_array) - sizeof(simd8<uint8_t>)]);
  153|  1.71M|  return input.gt_bits(max_value);
  154|  1.71M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker9check_eofEv:
  181|  2.89k|  simdutf_really_inline void check_eof() {
  182|       |    // If the previous block had incomplete UTF-8 characters at the end, an
  183|       |    // ASCII block can't possibly finish them.
  184|  2.89k|    this->error |= this->prev_incomplete;
  185|  2.89k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker6errorsEv:
  212|  2.89k|  simdutf_really_inline bool errors() const {
  213|  2.89k|    return this->error.any_bits_set_anywhere();
  214|  2.89k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker16check_next_inputERKNS1_4simd8simd8x64IhEE:
  187|  2.13M|  simdutf_really_inline void check_next_input(const simd8x64<uint8_t> &input) {
  188|  2.13M|    if (simdutf_likely(is_ascii(input))) {
  ------------------
  |  |   90|  2.13M|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 418k, False: 1.71M]
  |  |  ------------------
  ------------------
  189|   418k|      this->error |= this->prev_incomplete;
  190|  1.71M|    } else {
  191|       |      // you might think that a for-loop would work, but under Visual Studio, it
  192|       |      // is not good enough.
  193|  1.71M|      static_assert((simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  194|  1.71M|                        (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  195|  1.71M|                    "We support either two or four chunks per 64-byte block.");
  196|       |      if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  197|       |        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  198|       |        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  199|  1.71M|      } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  200|  1.71M|        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  201|  1.71M|        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  202|  1.71M|        this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  203|  1.71M|        this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  204|  1.71M|      }
  205|  1.71M|      this->prev_incomplete =
  206|  1.71M|          is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1]);
  207|  1.71M|      this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1];
  208|  1.71M|    }
  209|  2.13M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  169|  6.84M|                                              const simd8<uint8_t> prev_input) {
  170|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  171|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  172|       |    // small negative numbers)
  173|  6.84M|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  174|  6.84M|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  175|  6.84M|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  176|  6.84M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation19check_special_casesENS1_4simd5simd8IhEES5_:
    9|  6.84M|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|  6.84M|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   17|       |                                               // 11______ 11______
   18|  6.84M|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   19|  6.84M|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   20|  6.84M|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   21|  6.84M|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   22|  6.84M|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   23|  6.84M|  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|  6.84M|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   32|       |  // 11110101 1000____
   33|       |  // 1111011_ 1000____
   34|       |  // 11111___ 1000____
   35|  6.84M|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   36|       |
   37|  6.84M|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   38|       |      // 0_______ ________ <ASCII in byte 1>
   39|  6.84M|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   40|  6.84M|      TOO_LONG,
   41|       |      // 10______ ________ <continuation in byte 1>
   42|  6.84M|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   43|       |      // 1100____ ________ <two byte lead in byte 1>
   44|  6.84M|      TOO_SHORT | OVERLONG_2,
   45|       |      // 1101____ ________ <two byte lead in byte 1>
   46|  6.84M|      TOO_SHORT,
   47|       |      // 1110____ ________ <three byte lead in byte 1>
   48|  6.84M|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   49|       |      // 1111____ ________ <four+ byte lead in byte 1>
   50|  6.84M|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   51|  6.84M|  constexpr const uint8_t CARRY =
   52|  6.84M|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   53|  6.84M|  const simd8<uint8_t> byte_1_low =
   54|  6.84M|      (prev1 & 0x0F)
   55|  6.84M|          .lookup_16<uint8_t>(
   56|       |              // ____0000 ________
   57|  6.84M|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   58|       |              // ____0001 ________
   59|  6.84M|              CARRY | OVERLONG_2,
   60|       |              // ____001_ ________
   61|  6.84M|              CARRY, CARRY,
   62|       |
   63|       |              // ____0100 ________
   64|  6.84M|              CARRY | TOO_LARGE,
   65|       |              // ____0101 ________
   66|  6.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   67|       |              // ____011_ ________
   68|  6.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|  6.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   70|       |
   71|       |              // ____1___ ________
   72|  6.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  6.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  6.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  6.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|  6.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   77|       |              // ____1101 ________
   78|  6.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   79|  6.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   80|  6.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   81|  6.84M|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   82|       |      // ________ 0_______ <ASCII in byte 2>
   83|  6.84M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   84|  6.84M|      TOO_SHORT, TOO_SHORT,
   85|       |
   86|       |      // ________ 1000____
   87|  6.84M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   88|  6.84M|          OVERLONG_4,
   89|       |      // ________ 1001____
   90|  6.84M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   91|       |      // ________ 101_____
   92|  6.84M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|  6.84M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   94|       |
   95|       |      // ________ 11______
   96|  6.84M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   97|  6.84M|  return (byte_1_high & byte_1_low & byte_2_high);
   98|  6.84M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation23check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  102|  6.84M|                        const simd8<uint8_t> sc) {
  103|  6.84M|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  104|  6.84M|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  105|  6.84M|  simd8<uint8_t> must23 =
  106|  6.84M|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  107|  6.84M|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  108|  6.84M|  return must23_80 ^ sc;
  109|  6.84M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation13is_incompleteENS1_4simd5simd8IhEE:
  115|  1.71M|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.71M|  static const uint8_t max_array[32] = {255,
  120|  1.71M|                                        255,
  121|  1.71M|                                        255,
  122|  1.71M|                                        255,
  123|  1.71M|                                        255,
  124|  1.71M|                                        255,
  125|  1.71M|                                        255,
  126|  1.71M|                                        255,
  127|  1.71M|                                        255,
  128|  1.71M|                                        255,
  129|  1.71M|                                        255,
  130|  1.71M|                                        255,
  131|  1.71M|                                        255,
  132|  1.71M|                                        255,
  133|  1.71M|                                        255,
  134|  1.71M|                                        255,
  135|  1.71M|                                        255,
  136|  1.71M|                                        255,
  137|  1.71M|                                        255,
  138|  1.71M|                                        255,
  139|  1.71M|                                        255,
  140|  1.71M|                                        255,
  141|  1.71M|                                        255,
  142|  1.71M|                                        255,
  143|  1.71M|                                        255,
  144|  1.71M|                                        255,
  145|  1.71M|                                        255,
  146|  1.71M|                                        255,
  147|  1.71M|                                        255,
  148|  1.71M|                                        0b11110000u - 1,
  149|  1.71M|                                        0b11100000u - 1,
  150|  1.71M|                                        0b11000000u - 1};
  151|  1.71M|  const simd8<uint8_t> max_value(
  152|  1.71M|      &max_array[sizeof(max_array) - sizeof(simd8<uint8_t>)]);
  153|  1.71M|  return input.gt_bits(max_value);
  154|  1.71M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker9check_eofEv:
  181|  2.89k|  simdutf_really_inline void check_eof() {
  182|       |    // If the previous block had incomplete UTF-8 characters at the end, an
  183|       |    // ASCII block can't possibly finish them.
  184|  2.89k|    this->error |= this->prev_incomplete;
  185|  2.89k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker6errorsEv:
  212|  2.89k|  simdutf_really_inline bool errors() const {
  213|  2.89k|    return this->error.any_bits_set_anywhere();
  214|  2.89k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation21generic_validate_utf8EPKcm:
   27|  2.89k|bool generic_validate_utf8(const char *input, size_t length) {
   28|  2.89k|  return generic_validate_utf8<utf8_checker>(
   29|  2.89k|      reinterpret_cast<const uint8_t *>(input), length);
   30|  2.89k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation21generic_validate_utf8INS2_12utf8_checkerEEEbPKhm:
   10|  2.89k|bool generic_validate_utf8(const uint8_t *input, size_t length) {
   11|  2.89k|  checker c{};
   12|  2.89k|  buf_block_reader<64> reader(input, length);
   13|  2.13M|  while (reader.has_full_block()) {
  ------------------
  |  Branch (13:10): [True: 2.12M, False: 2.89k]
  ------------------
   14|  2.12M|    simd::simd8x64<uint8_t> in(reader.full_block());
   15|  2.12M|    c.check_next_input(in);
   16|  2.12M|    reader.advance();
   17|  2.12M|  }
   18|  2.89k|  uint8_t block[64]{};
   19|  2.89k|  reader.get_remainder(block);
   20|  2.89k|  simd::simd8x64<uint8_t> in(block);
   21|  2.89k|  c.check_next_input(in);
   22|  2.89k|  reader.advance();
   23|  2.89k|  c.check_eof();
   24|  2.89k|  return !c.errors();
   25|  2.89k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation21generic_validate_utf8EPKcm:
   27|  2.89k|bool generic_validate_utf8(const char *input, size_t length) {
   28|  2.89k|  return generic_validate_utf8<utf8_checker>(
   29|  2.89k|      reinterpret_cast<const uint8_t *>(input), length);
   30|  2.89k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation21generic_validate_utf8INS2_12utf8_checkerEEEbPKhm:
   10|  2.89k|bool generic_validate_utf8(const uint8_t *input, size_t length) {
   11|  2.89k|  checker c{};
   12|  2.89k|  buf_block_reader<64> reader(input, length);
   13|  2.13M|  while (reader.has_full_block()) {
  ------------------
  |  Branch (13:10): [True: 2.12M, False: 2.89k]
  ------------------
   14|  2.12M|    simd::simd8x64<uint8_t> in(reader.full_block());
   15|  2.12M|    c.check_next_input(in);
   16|  2.12M|    reader.advance();
   17|  2.12M|  }
   18|  2.89k|  uint8_t block[64]{};
   19|  2.89k|  reader.get_remainder(block);
   20|  2.89k|  simd::simd8x64<uint8_t> in(block);
   21|  2.89k|  c.check_next_input(in);
   22|  2.89k|  reader.advance();
   23|  2.89k|  c.check_eof();
   24|  2.89k|  return !c.errors();
   25|  2.89k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_138avx2_convert_utf16_to_utf8_with_errorsILNS_10endiannessE0EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
  333|   637k|                                       char *utf8_output) {
  334|   637k|  const char16_t *start = buf;
  335|   637k|  const char16_t *end = buf + len;
  336|       |
  337|   637k|  const __m256i v_0000 = _mm256_setzero_si256();
  338|   637k|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
  339|   637k|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
  340|   637k|  const __m256i v_c080 = _mm256_set1_epi16((int16_t)0xc080);
  341|   637k|  const size_t safety_margin =
  342|   637k|      12; // to avoid overruns, see issue
  343|       |          // https://github.com/simdutf/simdutf/issues/92
  344|       |
  345|  2.83M|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (345:10): [True: 2.83M, False: 4.43k]
  ------------------
  346|  2.83M|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
  347|  2.83M|    if (big_endian) {
  ------------------
  |  Branch (347:9): [Folded, False: 2.83M]
  ------------------
  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|  2.83M|    const __m256i v_ff80 = _mm256_set1_epi16((int16_t)0xff80);
  355|  2.83M|    if (_mm256_testz_si256(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (355:9): [True: 998k, False: 1.83M]
  ------------------
  356|       |      // 1. pack the bytes
  357|   998k|      const __m128i utf8_packed = _mm_packus_epi16(
  358|   998k|          _mm256_castsi256_si128(in), _mm256_extractf128_si256(in, 1));
  359|       |      // 2. store (16 bytes)
  360|   998k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  361|       |      // 3. adjust pointers
  362|   998k|      buf += 16;
  363|   998k|      utf8_output += 16;
  364|   998k|      continue; // we are done for this round!
  365|   998k|    }
  366|       |    // no bits set above 7th bit
  367|  1.83M|    const __m256i one_byte_bytemask =
  368|  1.83M|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_ff80), v_0000);
  369|  1.83M|    const uint32_t one_byte_bitmask =
  370|  1.83M|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
  371|       |
  372|       |    // no bits set above 11th bit
  373|  1.83M|    const __m256i one_or_two_bytes_bytemask =
  374|  1.83M|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_0000);
  375|  1.83M|    const uint32_t one_or_two_bytes_bitmask =
  376|  1.83M|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
  377|  1.83M|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (377:9): [True: 15.4k, False: 1.82M]
  ------------------
  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|  15.4k|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
  383|  15.4k|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
  384|       |
  385|       |      // t0 = [000a|aaaa|bbbb|bb00]
  386|  15.4k|      const __m256i t0 = _mm256_slli_epi16(in, 2);
  387|       |      // t1 = [000a|aaaa|0000|0000]
  388|  15.4k|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
  389|       |      // t2 = [0000|0000|00bb|bbbb]
  390|  15.4k|      const __m256i t2 = _mm256_and_si256(in, v_003f);
  391|       |      // t3 = [000a|aaaa|00bb|bbbb]
  392|  15.4k|      const __m256i t3 = _mm256_or_si256(t1, t2);
  393|       |      // t4 = [110a|aaaa|10bb|bbbb]
  394|  15.4k|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
  395|       |
  396|       |      // 2. merge ASCII and 2-byte codewords
  397|  15.4k|      const __m256i utf8_unpacked =
  398|  15.4k|          _mm256_blendv_epi8(t4, in, one_byte_bytemask);
  399|       |
  400|       |      // 3. prepare bitmask for 8-bit lookup
  401|  15.4k|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
  402|  15.4k|      const uint32_t M1 = M0 >> 7;
  403|  15.4k|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
  404|       |      // 4. pack the bytes
  405|       |
  406|  15.4k|      const uint8_t *row =
  407|  15.4k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
  408|  15.4k|      const uint8_t *row_2 =
  409|  15.4k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
  410|  15.4k|                                                                       16)][0];
  411|       |
  412|  15.4k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  413|  15.4k|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
  414|       |
  415|  15.4k|      const __m256i utf8_packed = _mm256_shuffle_epi8(
  416|  15.4k|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|  15.4k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|  15.4k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  417|       |      // 5. store bytes
  418|  15.4k|      _mm_storeu_si128((__m128i *)utf8_output,
  419|  15.4k|                       _mm256_castsi256_si128(utf8_packed));
  420|  15.4k|      utf8_output += row[0];
  421|  15.4k|      _mm_storeu_si128((__m128i *)utf8_output,
  422|  15.4k|                       _mm256_extractf128_si256(utf8_packed, 1));
  423|  15.4k|      utf8_output += row_2[0];
  424|       |
  425|       |      // 6. adjust pointers
  426|  15.4k|      buf += 16;
  427|  15.4k|      continue;
  428|  15.4k|    }
  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|  1.82M|    const __m256i surrogates_bytemask =
  433|  1.82M|        _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|  1.82M|    const uint32_t surrogates_bitmask =
  438|  1.82M|        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|  1.82M|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (441:9): [True: 1.17M, False: 643k]
  ------------------
  442|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  443|  1.17M|      const __m256i dup_even = _mm256_setr_epi16(
  444|  1.17M|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  445|  1.17M|          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.17M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  475|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  476|  1.17M|      const __m256i t0 = _mm256_shuffle_epi8(in, dup_even);
  477|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  478|  1.17M|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  474|  1.17M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  479|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  480|  1.17M|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  474|  1.17M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  481|       |
  482|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  483|  1.17M|      const __m256i s0 = _mm256_srli_epi16(in, 4);
  484|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  485|  1.17M|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  474|  1.17M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  486|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  487|  1.17M|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  474|  1.17M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  488|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  489|  1.17M|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  474|  1.17M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  490|  1.17M|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  491|  1.17M|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  474|  1.17M|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  492|  1.17M|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  493|  1.17M|#undef simdutf_vec
  494|       |
  495|       |      // 4. expand code units 16-bit => 32-bit
  496|  1.17M|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  497|  1.17M|      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.17M|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  501|  1.17M|                            (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.17M|      const uint8_t mask0 = uint8_t(mask);
  522|  1.17M|      const uint8_t *row0 =
  523|  1.17M|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  524|  1.17M|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  525|  1.17M|      const __m128i utf8_0 =
  526|  1.17M|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  527|       |
  528|  1.17M|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  529|  1.17M|      const uint8_t *row1 =
  530|  1.17M|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  531|  1.17M|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  532|  1.17M|      const __m128i utf8_1 =
  533|  1.17M|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  534|       |
  535|  1.17M|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  536|  1.17M|      const uint8_t *row2 =
  537|  1.17M|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  538|  1.17M|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  539|  1.17M|      const __m128i utf8_2 =
  540|  1.17M|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  541|       |
  542|  1.17M|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  543|  1.17M|      const uint8_t *row3 =
  544|  1.17M|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  545|  1.17M|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  546|  1.17M|      const __m128i utf8_3 =
  547|  1.17M|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  548|       |
  549|  1.17M|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  550|  1.17M|      utf8_output += row0[0];
  551|  1.17M|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  552|  1.17M|      utf8_output += row1[0];
  553|  1.17M|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  554|  1.17M|      utf8_output += row2[0];
  555|  1.17M|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  556|  1.17M|      utf8_output += row3[0];
  557|  1.17M|      buf += 16;
  558|       |      // surrogate pair(s) in a register
  559|  1.17M|    } 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|   643k|      size_t forward = 15;
  564|   643k|      size_t k = 0;
  565|   643k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (565:11): [True: 0, False: 643k]
  ------------------
  566|      0|        forward = size_t(end - buf - 1);
  567|      0|      }
  568|  2.12M|      for (; k < forward; k++) {
  ------------------
  |  Branch (568:14): [True: 2.11M, False: 10.3k]
  ------------------
  569|  2.11M|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  570|  2.11M|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (570:13): [True: 109k, False: 2.00M]
  ------------------
  571|   109k|          *utf8_output++ = char(word);
  572|  2.00M|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (572:20): [True: 71.2k, False: 1.93M]
  ------------------
  573|  71.2k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  574|  71.2k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  575|  1.93M|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (575:20): [True: 1.21M, False: 720k]
  ------------------
  576|  1.21M|          *utf8_output++ = char((word >> 12) | 0b11100000);
  577|  1.21M|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  578|  1.21M|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  579|  1.21M|        } else {
  580|       |          // must be a surrogate pair
  581|   720k|          uint16_t diff = uint16_t(word - 0xD800);
  582|   720k|          uint16_t next_word =
  583|   720k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  584|   720k|          k++;
  585|   720k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  586|   720k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (586:15): [True: 632k, False: 87.9k]
  ------------------
  587|   632k|            return std::make_pair(
  588|   632k|                result(error_code::SURROGATE, buf - start + k - 1),
  589|   632k|                utf8_output);
  590|   632k|          }
  591|  87.9k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  592|  87.9k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  593|  87.9k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  594|  87.9k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  595|  87.9k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  596|  87.9k|        }
  597|  2.11M|      }
  598|  10.3k|      buf += k;
  599|  10.3k|    }
  600|  1.82M|  } // while
  601|  4.43k|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  602|   637k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_138avx2_convert_utf16_to_utf8_with_errorsILNS_10endiannessE1EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
  333|  1.05M|                                       char *utf8_output) {
  334|  1.05M|  const char16_t *start = buf;
  335|  1.05M|  const char16_t *end = buf + len;
  336|       |
  337|  1.05M|  const __m256i v_0000 = _mm256_setzero_si256();
  338|  1.05M|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
  339|  1.05M|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
  340|  1.05M|  const __m256i v_c080 = _mm256_set1_epi16((int16_t)0xc080);
  341|  1.05M|  const size_t safety_margin =
  342|  1.05M|      12; // to avoid overruns, see issue
  343|       |          // https://github.com/simdutf/simdutf/issues/92
  344|       |
  345|  2.73M|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (345:10): [True: 2.72M, False: 4.52k]
  ------------------
  346|  2.72M|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
  347|  2.72M|    if (big_endian) {
  ------------------
  |  Branch (347:9): [True: 2.72M, Folded]
  ------------------
  348|  2.72M|      const __m256i swap = _mm256_setr_epi8(
  349|  2.72M|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
  350|  2.72M|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
  351|  2.72M|      in = _mm256_shuffle_epi8(in, swap);
  352|  2.72M|    }
  353|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
  354|  2.72M|    const __m256i v_ff80 = _mm256_set1_epi16((int16_t)0xff80);
  355|  2.72M|    if (_mm256_testz_si256(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (355:9): [True: 761k, False: 1.96M]
  ------------------
  356|       |      // 1. pack the bytes
  357|   761k|      const __m128i utf8_packed = _mm_packus_epi16(
  358|   761k|          _mm256_castsi256_si128(in), _mm256_extractf128_si256(in, 1));
  359|       |      // 2. store (16 bytes)
  360|   761k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  361|       |      // 3. adjust pointers
  362|   761k|      buf += 16;
  363|   761k|      utf8_output += 16;
  364|   761k|      continue; // we are done for this round!
  365|   761k|    }
  366|       |    // no bits set above 7th bit
  367|  1.96M|    const __m256i one_byte_bytemask =
  368|  1.96M|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_ff80), v_0000);
  369|  1.96M|    const uint32_t one_byte_bitmask =
  370|  1.96M|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
  371|       |
  372|       |    // no bits set above 11th bit
  373|  1.96M|    const __m256i one_or_two_bytes_bytemask =
  374|  1.96M|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_0000);
  375|  1.96M|    const uint32_t one_or_two_bytes_bitmask =
  376|  1.96M|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
  377|  1.96M|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (377:9): [True: 18.3k, False: 1.94M]
  ------------------
  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|  18.3k|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
  383|  18.3k|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
  384|       |
  385|       |      // t0 = [000a|aaaa|bbbb|bb00]
  386|  18.3k|      const __m256i t0 = _mm256_slli_epi16(in, 2);
  387|       |      // t1 = [000a|aaaa|0000|0000]
  388|  18.3k|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
  389|       |      // t2 = [0000|0000|00bb|bbbb]
  390|  18.3k|      const __m256i t2 = _mm256_and_si256(in, v_003f);
  391|       |      // t3 = [000a|aaaa|00bb|bbbb]
  392|  18.3k|      const __m256i t3 = _mm256_or_si256(t1, t2);
  393|       |      // t4 = [110a|aaaa|10bb|bbbb]
  394|  18.3k|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
  395|       |
  396|       |      // 2. merge ASCII and 2-byte codewords
  397|  18.3k|      const __m256i utf8_unpacked =
  398|  18.3k|          _mm256_blendv_epi8(t4, in, one_byte_bytemask);
  399|       |
  400|       |      // 3. prepare bitmask for 8-bit lookup
  401|  18.3k|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
  402|  18.3k|      const uint32_t M1 = M0 >> 7;
  403|  18.3k|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
  404|       |      // 4. pack the bytes
  405|       |
  406|  18.3k|      const uint8_t *row =
  407|  18.3k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
  408|  18.3k|      const uint8_t *row_2 =
  409|  18.3k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
  410|  18.3k|                                                                       16)][0];
  411|       |
  412|  18.3k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  413|  18.3k|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
  414|       |
  415|  18.3k|      const __m256i utf8_packed = _mm256_shuffle_epi8(
  416|  18.3k|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|  18.3k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|  18.3k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  417|       |      // 5. store bytes
  418|  18.3k|      _mm_storeu_si128((__m128i *)utf8_output,
  419|  18.3k|                       _mm256_castsi256_si128(utf8_packed));
  420|  18.3k|      utf8_output += row[0];
  421|  18.3k|      _mm_storeu_si128((__m128i *)utf8_output,
  422|  18.3k|                       _mm256_extractf128_si256(utf8_packed, 1));
  423|  18.3k|      utf8_output += row_2[0];
  424|       |
  425|       |      // 6. adjust pointers
  426|  18.3k|      buf += 16;
  427|  18.3k|      continue;
  428|  18.3k|    }
  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|  1.94M|    const __m256i surrogates_bytemask =
  433|  1.94M|        _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|  1.94M|    const uint32_t surrogates_bitmask =
  438|  1.94M|        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|  1.94M|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (441:9): [True: 890k, False: 1.05M]
  ------------------
  442|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  443|   890k|      const __m256i dup_even = _mm256_setr_epi16(
  444|   890k|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  445|   890k|          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|   890k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  475|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  476|   890k|      const __m256i t0 = _mm256_shuffle_epi8(in, dup_even);
  477|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  478|   890k|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  474|   890k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  479|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  480|   890k|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  474|   890k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  481|       |
  482|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  483|   890k|      const __m256i s0 = _mm256_srli_epi16(in, 4);
  484|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  485|   890k|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  474|   890k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  486|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  487|   890k|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  474|   890k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  488|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  489|   890k|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  474|   890k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  490|   890k|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  491|   890k|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  474|   890k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  492|   890k|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  493|   890k|#undef simdutf_vec
  494|       |
  495|       |      // 4. expand code units 16-bit => 32-bit
  496|   890k|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  497|   890k|      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|   890k|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  501|   890k|                            (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|   890k|      const uint8_t mask0 = uint8_t(mask);
  522|   890k|      const uint8_t *row0 =
  523|   890k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  524|   890k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  525|   890k|      const __m128i utf8_0 =
  526|   890k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  527|       |
  528|   890k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  529|   890k|      const uint8_t *row1 =
  530|   890k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  531|   890k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  532|   890k|      const __m128i utf8_1 =
  533|   890k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  534|       |
  535|   890k|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  536|   890k|      const uint8_t *row2 =
  537|   890k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  538|   890k|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  539|   890k|      const __m128i utf8_2 =
  540|   890k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  541|       |
  542|   890k|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  543|   890k|      const uint8_t *row3 =
  544|   890k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  545|   890k|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  546|   890k|      const __m128i utf8_3 =
  547|   890k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  548|       |
  549|   890k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  550|   890k|      utf8_output += row0[0];
  551|   890k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  552|   890k|      utf8_output += row1[0];
  553|   890k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  554|   890k|      utf8_output += row2[0];
  555|   890k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  556|   890k|      utf8_output += row3[0];
  557|   890k|      buf += 16;
  558|       |      // surrogate pair(s) in a register
  559|  1.05M|    } 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|  1.05M|      size_t forward = 15;
  564|  1.05M|      size_t k = 0;
  565|  1.05M|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (565:11): [True: 0, False: 1.05M]
  ------------------
  566|      0|        forward = size_t(end - buf - 1);
  567|      0|      }
  568|  2.14M|      for (; k < forward; k++) {
  ------------------
  |  Branch (568:14): [True: 2.14M, False: 6.90k]
  ------------------
  569|  2.14M|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  570|  2.14M|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (570:13): [True: 98.4k, False: 2.04M]
  ------------------
  571|  98.4k|          *utf8_output++ = char(word);
  572|  2.04M|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (572:20): [True: 56.8k, False: 1.98M]
  ------------------
  573|  56.8k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  574|  56.8k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  575|  1.98M|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (575:20): [True: 847k, False: 1.13M]
  ------------------
  576|   847k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  577|   847k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  578|   847k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  579|  1.13M|        } else {
  580|       |          // must be a surrogate pair
  581|  1.13M|          uint16_t diff = uint16_t(word - 0xD800);
  582|  1.13M|          uint16_t next_word =
  583|  1.13M|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  584|  1.13M|          k++;
  585|  1.13M|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  586|  1.13M|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (586:15): [True: 1.04M, False: 90.5k]
  ------------------
  587|  1.04M|            return std::make_pair(
  588|  1.04M|                result(error_code::SURROGATE, buf - start + k - 1),
  589|  1.04M|                utf8_output);
  590|  1.04M|          }
  591|  90.5k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  592|  90.5k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  593|  90.5k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  594|  90.5k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  595|  90.5k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  596|  90.5k|        }
  597|  2.14M|      }
  598|  6.90k|      buf += k;
  599|  6.90k|    }
  600|  1.94M|  } // while
  601|  4.52k|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  602|  1.05M|}

_ZNK7simdutf7haswell14implementation13validate_utf8EPKcm:
  266|  2.89k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
  267|  2.89k|  return haswell::utf8_validation::generic_validate_utf8(buf, len);
  268|  2.89k|}
_ZNK7simdutf7haswell14implementation35convert_utf16le_to_utf8_with_errorsEPKDsmPc:
  721|   637k|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  722|       |  // ret.first.count is always the position in the buffer, not the number of
  723|       |  // code units written even if finished
  724|   637k|  std::pair<result, char *> ret =
  725|   637k|      haswell::avx2_convert_utf16_to_utf8_with_errors<endianness::LITTLE>(
  726|   637k|          buf, len, utf8_output);
  727|   637k|  if (ret.first.error) {
  ------------------
  |  Branch (727:7): [True: 632k, False: 4.43k]
  ------------------
  728|   632k|    return ret.first;
  729|   632k|  } // Can return directly since scalar fallback already found correct
  730|       |    // ret.first.count
  731|  4.43k|  if (ret.first.count != len) { // All good so far, but not finished
  ------------------
  |  Branch (731:7): [True: 4.43k, False: 0]
  ------------------
  732|  4.43k|    result scalar_res =
  733|  4.43k|        scalar::utf16_to_utf8::convert_with_errors<endianness::LITTLE>(
  734|  4.43k|            buf + ret.first.count, len - ret.first.count, ret.second);
  735|  4.43k|    if (scalar_res.error) {
  ------------------
  |  Branch (735:9): [True: 3.46k, False: 965]
  ------------------
  736|  3.46k|      scalar_res.count += ret.first.count;
  737|  3.46k|      return scalar_res;
  738|  3.46k|    } else {
  739|    965|      ret.second += scalar_res.count;
  740|    965|    }
  741|  4.43k|  }
  742|    965|  ret.first.count =
  743|    965|      ret.second -
  744|    965|      utf8_output; // Set count to the number of 8-bit code units written
  745|    965|  return ret.first;
  746|  4.43k|}
_ZNK7simdutf7haswell14implementation35convert_utf16be_to_utf8_with_errorsEPKDsmPc:
  749|  1.05M|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  750|       |  // ret.first.count is always the position in the buffer, not the number of
  751|       |  // code units written even if finished
  752|  1.05M|  std::pair<result, char *> ret =
  753|  1.05M|      haswell::avx2_convert_utf16_to_utf8_with_errors<endianness::BIG>(
  754|  1.05M|          buf, len, utf8_output);
  755|  1.05M|  if (ret.first.error) {
  ------------------
  |  Branch (755:7): [True: 1.04M, False: 4.52k]
  ------------------
  756|  1.04M|    return ret.first;
  757|  1.04M|  } // Can return directly since scalar fallback already found correct
  758|       |    // ret.first.count
  759|  4.52k|  if (ret.first.count != len) { // All good so far, but not finished
  ------------------
  |  Branch (759:7): [True: 4.52k, False: 0]
  ------------------
  760|  4.52k|    result scalar_res =
  761|  4.52k|        scalar::utf16_to_utf8::convert_with_errors<endianness::BIG>(
  762|  4.52k|            buf + ret.first.count, len - ret.first.count, ret.second);
  763|  4.52k|    if (scalar_res.error) {
  ------------------
  |  Branch (763:9): [True: 3.63k, False: 897]
  ------------------
  764|  3.63k|      scalar_res.count += ret.first.count;
  765|  3.63k|      return scalar_res;
  766|  3.63k|    } else {
  767|    897|      ret.second += scalar_res.count;
  768|    897|    }
  769|  4.52k|  }
  770|    897|  ret.first.count =
  771|    897|      ret.second -
  772|    897|      utf8_output; // Set count to the number of 8-bit code units written
  773|    897|  return ret.first;
  774|  4.52k|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16leEPKDsm:
 1131|   636k|    const char16_t *input, size_t length) const noexcept {
 1132|   636k|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1133|   636k|                                                                    length);
 1134|   636k|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16beEPKDsm:
 1137|  1.05M|    const char16_t *input, size_t length) const noexcept {
 1138|  1.05M|  return utf16::utf8_length_from_utf16_bytemask<endianness::BIG>(input, length);
 1139|  1.05M|}
_ZNK7simdutf7haswell14implementation41utf8_length_from_utf16le_with_replacementEPKDsm:
 1161|  1.49k|    const char16_t *input, size_t length) const noexcept {
 1162|  1.49k|  return utf16::utf8_length_from_utf16_with_replacement<endianness::LITTLE>(
 1163|  1.49k|      input, length);
 1164|  1.49k|}
_ZNK7simdutf7haswell14implementation41utf8_length_from_utf16be_with_replacementEPKDsm:
 1168|  1.40k|    const char16_t *input, size_t length) const noexcept {
 1169|  1.40k|  return utf16::utf8_length_from_utf16_with_replacement<endianness::BIG>(
 1170|  1.40k|      input, length);
 1171|  1.40k|}
_ZNK7simdutf7haswell14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPc:
 1175|  1.49k|    const char16_t *input, size_t length, char *utf8_buffer) const noexcept {
 1176|  1.49k|  return utf16_to_utf8::convert_with_replacement_via(
 1177|  1.49k|      [this](const char16_t *b, size_t l, char *o) {
 1178|  1.49k|        return this->convert_utf16le_to_utf8_with_errors(b, l, o);
 1179|  1.49k|      },
 1180|  1.49k|      [this](const char16_t *b, size_t l) {
 1181|  1.49k|        return this->utf8_length_from_utf16le(b, l);
 1182|  1.49k|      },
 1183|  1.49k|      input, length, utf8_buffer);
 1184|  1.49k|}
_ZNK7simdutf7haswell14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPc:
 1188|  1.40k|    const char16_t *input, size_t length, char *utf8_buffer) const noexcept {
 1189|  1.40k|  return utf16_to_utf8::convert_with_replacement_via(
 1190|  1.40k|      [this](const char16_t *b, size_t l, char *o) {
 1191|  1.40k|        return this->convert_utf16be_to_utf8_with_errors(b, l, o);
 1192|  1.40k|      },
 1193|  1.40k|      [this](const char16_t *b, size_t l) {
 1194|  1.40k|        return this->utf8_length_from_utf16be(b, l);
 1195|  1.40k|      },
 1196|  1.40k|      input, length, utf8_buffer);
 1197|  1.40k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_18is_asciiERKNS1_4simd8simd8x64IhEE:
   13|  2.13M|simdutf_really_inline bool is_ascii(const simd8x64<uint8_t> &input) {
   14|  2.13M|  return input.reduce_or().is_ascii();
   15|  2.13M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_124must_be_2_3_continuationENS1_4simd5simd8IhEES4_:
   22|  3.42M|                         const simd8<uint8_t> prev3) {
   23|  3.42M|  simd8<uint8_t> is_third_byte =
   24|  3.42M|      prev2.saturating_sub(0xe0u - 0x80); // Only 111_____ will be > 0x80
   25|  3.42M|  simd8<uint8_t> is_fourth_byte =
   26|  3.42M|      prev3.saturating_sub(0xf0u - 0x80); // Only 1111____ will be > 0x80
   27|  3.42M|  return simd8<bool>(is_third_byte | is_fourth_byte);
   28|  3.42M|}
simdutf.cpp:_ZZNK7simdutf7haswell14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPcENK3$_0clES3_mS4_:
 1177|   637k|      [this](const char16_t *b, size_t l, char *o) {
 1178|   637k|        return this->convert_utf16le_to_utf8_with_errors(b, l, o);
 1179|   637k|      },
simdutf.cpp:_ZZNK7simdutf7haswell14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPcENK3$_1clES3_m:
 1180|   636k|      [this](const char16_t *b, size_t l) {
 1181|   636k|        return this->utf8_length_from_utf16le(b, l);
 1182|   636k|      },
simdutf.cpp:_ZZNK7simdutf7haswell14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPcENK3$_0clES3_mS4_:
 1190|  1.05M|      [this](const char16_t *b, size_t l, char *o) {
 1191|  1.05M|        return this->convert_utf16be_to_utf8_with_errors(b, l, o);
 1192|  1.05M|      },
simdutf.cpp:_ZZNK7simdutf7haswell14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPcENK3$_1clES3_m:
 1193|  1.05M|      [this](const char16_t *b, size_t l) {
 1194|  1.05M|        return this->utf8_length_from_utf16be(b, l);
 1195|  1.05M|      },

_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:
 1503|      1|available_implementation_list::begin() const noexcept {
 1504|      1|  return internal::get_available_implementation_pointers().begin();
 1505|      1|}
_ZNK7simdutf8internal29available_implementation_list3endEv:
 1507|      1|available_implementation_list::end() const noexcept {
 1508|      1|  return internal::get_available_implementation_pointers().end();
 1509|      1|}
_ZN7simdutf29get_available_implementationsEv:
 1558|      1|get_available_implementations() {
 1559|      1|#if !SIMDUTF_USE_STATIC_INITIALIZATION
 1560|      1|  static const internal::available_implementation_list
 1561|      1|      available_implementations_instance{};
 1562|      1|#endif
 1563|      1|  return available_implementations_instance;
 1564|      1|}
simdutf.cpp:_ZN7simdutf8internalL37get_available_implementation_pointersEv:
  933|      2|get_available_implementation_pointers() {
  934|      2|#if !SIMDUTF_USE_STATIC_INITIALIZATION
  935|      2|  static const std::initializer_list<const implementation *>
  936|      2|      available_implementation_pointers{
  937|      2|  #if SIMDUTF_IMPLEMENTATION_ICELAKE
  938|      2|          get_icelake_singleton(),
  939|      2|  #endif
  940|      2|  #if SIMDUTF_IMPLEMENTATION_HASWELL
  941|      2|          get_haswell_singleton(),
  942|      2|  #endif
  943|      2|  #if SIMDUTF_IMPLEMENTATION_WESTMERE
  944|      2|          get_westmere_singleton(),
  945|      2|  #endif
  946|       |  #if SIMDUTF_IMPLEMENTATION_ARM64
  947|       |          get_arm64_singleton(),
  948|       |  #endif
  949|       |  #if SIMDUTF_IMPLEMENTATION_PPC64
  950|       |          get_ppc64_singleton(),
  951|       |  #endif
  952|       |  #if SIMDUTF_IMPLEMENTATION_RVV
  953|       |          get_rvv_singleton(),
  954|       |  #endif
  955|       |  #if SIMDUTF_IMPLEMENTATION_LASX
  956|       |          get_lasx_singleton(),
  957|       |  #endif
  958|       |  #if SIMDUTF_IMPLEMENTATION_LSX
  959|       |          get_lsx_singleton(),
  960|       |  #endif
  961|      2|  #if SIMDUTF_IMPLEMENTATION_FALLBACK
  962|      2|          get_fallback_singleton(),
  963|      2|  #endif
  964|      2|      };
  965|      2|#endif
  966|      2|  return available_implementation_pointers;
  967|      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.68k|  simdutf_really_inline simd8() : base8_numeric<uint8_t>() {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhEC2Ev:
  124|  8.68k|  simdutf_really_inline base8_numeric() : base8<T>() {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2Ev:
   71|  8.68k|  simdutf_really_inline base8() : base<simd8<T>>() {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2Ev:
   14|  8.68k|  simdutf_really_inline base() : value{__m256i()} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IhE9reduce_orEv:
  294|  2.13M|  simdutf_really_inline simd8<T> reduce_or() const {
  295|  2.13M|    return this->chunks[0] | this->chunks[1];
  296|  2.13M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEorES5_:
   50|  9.40M|  simdutf_really_inline Child operator|(const Child other) const {
   51|  9.40M|    return _mm256_or_si256(*this, other);
   52|  9.40M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2EDv4_x:
  193|   109M|      : base8_numeric<uint8_t>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhEC2EDv4_x:
  126|   109M|      : base8<T>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2EDv4_x:
   73|   109M|  simdutf_really_inline base8(const __m256i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2EDv4_x:
   17|   109M|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE8is_asciiEv:
  234|  2.13M|  simdutf_really_inline bool is_ascii() const {
  235|  2.13M|    return _mm256_movemask_epi8(*this) == 0;
  236|  2.13M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEoRES5_:
   59|  3.84M|  simdutf_really_inline Child &operator|=(const Child other) {
   60|  3.84M|    auto this_cast = static_cast<Child *>(this);
   61|  3.84M|    *this_cast = *this_cast | other;
   62|  3.84M|    return *this_cast;
   63|  3.84M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi1EEENS4_IhEES8_:
   83|  3.42M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   84|       |    return _mm256_alignr_epi8(
   85|  3.42M|        *this, _mm256_permute2x128_si256(prev_chunk, *this, 0x21), 16 - N);
   86|  3.42M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE3shrILi4EEES4_v:
  245|  6.84M|  template <int N> simdutf_really_inline simd8<uint8_t> shr() const {
  246|  6.84M|    return simd8<uint8_t>(_mm256_srli_epi16(*this, N)) & uint8_t(0xFFu >> N);
  247|  6.84M|  }
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|  10.2M|            L replace15) const {
  158|  10.2M|    return lookup_16(simd8<L>::repeat_16(
  159|  10.2M|        replace0, replace1, replace2, replace3, replace4, replace5, replace6,
  160|  10.2M|        replace7, replace8, replace9, replace10, replace11, replace12,
  161|  10.2M|        replace13, replace14, replace15));
  162|  10.2M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE9lookup_16IhEENS2_5simd8IT_EES8_:
  148|  10.2M|  simdutf_really_inline simd8<L> lookup_16(simd8<L> lookup_table) const {
  149|  10.2M|    return _mm256_shuffle_epi8(lookup_table, *this);
  150|  10.2M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE9repeat_16Ehhhhhhhhhhhhhhhh:
  118|  10.2M|                                                  T v14, T v15) {
  119|  10.2M|    return simd8<T>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
  120|  10.2M|                    v14, v15, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
  121|  10.2M|                    v12, v13, v14, v15);
  122|  10.2M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2Ehhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh:
  207|  10.2M|      : simd8(_mm256_setr_epi8(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
  208|  10.2M|                               v12, v13, v14, v15, v16, v17, v18, v19, v20, v21,
  209|  10.2M|                               v22, v23, v24, v25, v26, v27, v28, v29, v30,
  210|  10.2M|                               v31)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2Eh:
  195|  20.5M|  simdutf_really_inline simd8(uint8_t _value) : simd8(splat(_value)) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi2EEENS4_IhEES8_:
   83|  3.42M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   84|       |    return _mm256_alignr_epi8(
   85|  3.42M|        *this, _mm256_permute2x128_si256(prev_chunk, *this, 0x21), 16 - N);
   86|  3.42M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi3EEENS4_IhEES8_:
   83|  3.42M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   84|       |    return _mm256_alignr_epi8(
   85|  3.42M|        *this, _mm256_permute2x128_si256(prev_chunk, *this, 0x21), 16 - N);
   86|  3.42M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE14saturating_subES4_:
  214|  8.56M|  saturating_sub(const simd8<uint8_t> other) const {
  215|  8.56M|    return _mm256_subs_epu8(*this, other);
  216|  8.56M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IbEC2EDv4_x:
   95|  3.42M|  simdutf_really_inline simd8(const __m256i _value) : base8<bool>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IbNS2_5simd8IbEEEC2EDv4_x:
   73|  3.42M|  simdutf_really_inline base8(const __m256i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEC2EDv4_x:
   17|  3.42M|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEcvRKDv4_xEv:
   19|  3.42M|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEeoES5_:
   56|  3.42M|  simdutf_really_inline Child operator^(const Child other) const {
   57|  3.42M|    return _mm256_xor_si256(*this, other);
   58|  3.42M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2EPKh:
  197|  1.71M|  simdutf_really_inline simd8(const uint8_t values[32]) : simd8(load(values)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE4loadEPKh:
  111|  5.97M|  static simdutf_really_inline simd8<T> load(const T values[32]) {
  112|  5.97M|    return _mm256_loadu_si256(reinterpret_cast<const __m256i *>(values));
  113|  5.97M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE7gt_bitsES4_:
  225|  1.71M|  gt_bits(const simd8<uint8_t> other) const {
  226|  1.71M|    return this->saturating_sub(other);
  227|  1.71M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEC2EDv4_x:
   17|   108M|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEcvRKDv4_xEv:
   19|   105M|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE21any_bits_set_anywhereEv:
  241|  2.89k|  simdutf_really_inline bool any_bits_set_anywhere() const {
  242|  2.89k|    return !bits_not_set_anywhere();
  243|  2.89k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE21bits_not_set_anywhereEv:
  237|  2.89k|  simdutf_really_inline bool bits_not_set_anywhere() const {
  238|  2.89k|    return _mm256_testz_si256(*this, *this);
  239|  2.89k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEC2EDv4_x:
   17|  8.10M|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEcvRKDv4_xEv:
   19|  12.2M|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE5splatEh:
  105|  20.5M|  static simdutf_really_inline simd8<T> splat(T _value) {
  106|  20.5M|    return _mm256_set1_epi8(_value);
  107|  20.5M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEcvRKDv4_xEv:
   19|   147M|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEanES5_:
   53|  20.5M|  simdutf_really_inline Child operator&(const Child other) const {
   54|  20.5M|    return _mm256_and_si256(*this, other);
   55|  20.5M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IhEC2EPKh:
  274|  2.13M|      : chunks{simd8<T>::load(ptr),
  275|  2.13M|               simd8<T>::load(ptr + sizeof(simd8<T>) / sizeof(T))} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEanES5_:
   53|  21.8M|  simdutf_really_inline Child operator&(const Child other) const {
   54|  21.8M|    return _mm256_and_si256(*this, other);
   55|  21.8M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEeoES5_:
   56|   355k|  simdutf_really_inline Child operator^(const Child other) const {
   57|   355k|    return _mm256_xor_si256(*this, other);
   58|   355k|  }

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

_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.68k|  simdutf_really_inline simd8() : base8_numeric<uint8_t>() {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhEC2Ev:
  118|  8.68k|  simdutf_really_inline base8_numeric() : base8<T>() {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2Ev:
   68|  8.68k|  simdutf_really_inline base8() : base<simd8<T>>() {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2Ev:
   13|  8.68k|  simdutf_really_inline base() : value{__m128i()} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IhE9reduce_orEv:
  290|  2.13M|  simdutf_really_inline simd8<T> reduce_or() const {
  291|  2.13M|    return (this->chunks[0] | this->chunks[1]) |
  292|  2.13M|           (this->chunks[2] | this->chunks[3]);
  293|  2.13M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEorES5_:
   42|  20.5M|  simdutf_really_inline Child operator|(const Child other) const {
   43|  20.5M|    return _mm_or_si128(*this, other);
   44|  20.5M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2EDv2_x:
  185|   217M|      : base8_numeric<uint8_t>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhEC2EDv2_x:
  120|   217M|      : base8<T>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2EDv2_x:
   69|   217M|  simdutf_really_inline base8(const __m128i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2EDv2_x:
   16|   217M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE8is_asciiEv:
  228|  2.13M|  simdutf_really_inline bool is_ascii() const {
  229|  2.13M|    return _mm_movemask_epi8(*this) == 0;
  230|  2.13M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEoRES5_:
   51|  7.27M|  simdutf_really_inline Child &operator|=(const Child other) {
   52|  7.27M|    auto this_cast = static_cast<Child *>(this);
   53|  7.27M|    *this_cast = *this_cast | other;
   54|  7.27M|    return *this_cast;
   55|  7.27M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi1EEENS4_IhEES8_:
   79|  6.84M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   80|       |    return _mm_alignr_epi8(*this, prev_chunk, 16 - N);
   81|  6.84M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE3shrILi4EEES4_v:
  238|  13.6M|  template <int N> simdutf_really_inline simd8<uint8_t> shr() const {
  239|  13.6M|    return simd8<uint8_t>(_mm_srli_epi16(*this, N)) & uint8_t(0xFFu >> N);
  240|  13.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|  20.5M|            L replace15) const {
  152|  20.5M|    return lookup_16(simd8<L>::repeat_16(
  153|  20.5M|        replace0, replace1, replace2, replace3, replace4, replace5, replace6,
  154|  20.5M|        replace7, replace8, replace9, replace10, replace11, replace12,
  155|  20.5M|        replace13, replace14, replace15));
  156|  20.5M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE9lookup_16IhEENS2_5simd8IT_EES8_:
  142|  20.5M|  simdutf_really_inline simd8<L> lookup_16(simd8<L> lookup_table) const {
  143|  20.5M|    return _mm_shuffle_epi8(lookup_table, *this);
  144|  20.5M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE9repeat_16Ehhhhhhhhhhhhhhhh:
  113|  20.5M|                                                  T v14, T v15) {
  114|  20.5M|    return simd8<T>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
  115|  20.5M|                    v14, v15);
  116|  20.5M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2Ehhhhhhhhhhhhhhhh:
  196|  20.5M|      : simd8(_mm_setr_epi8(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
  197|  20.5M|                            v12, v13, v14, v15)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2Eh:
  188|  41.0M|  simdutf_really_inline simd8(uint8_t _value) : simd8(splat(_value)) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi2EEENS4_IhEES8_:
   79|  6.84M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   80|       |    return _mm_alignr_epi8(*this, prev_chunk, 16 - N);
   81|  6.84M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi3EEENS4_IhEES8_:
   79|  6.84M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   80|       |    return _mm_alignr_epi8(*this, prev_chunk, 16 - N);
   81|  6.84M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE14saturating_subES4_:
  201|  15.4M|  saturating_sub(const simd8<uint8_t> other) const {
  202|  15.4M|    return _mm_subs_epu8(*this, other);
  203|  15.4M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IbEC2EDv2_x:
   91|  6.84M|  simdutf_really_inline simd8(const __m128i _value) : base8<bool>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IbNS2_5simd8IbEEEC2EDv2_x:
   69|  6.84M|  simdutf_really_inline base8(const __m128i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEC2EDv2_x:
   16|  6.84M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEcvRKDv2_xEv:
   18|  6.84M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEeoES5_:
   48|  6.84M|  simdutf_really_inline Child operator^(const Child other) const {
   49|  6.84M|    return _mm_xor_si128(*this, other);
   50|  6.84M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2EPKh:
  190|  1.71M|  simdutf_really_inline simd8(const uint8_t *values) : simd8(load(values)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE4loadEPKh:
  106|  10.2M|  static simdutf_really_inline simd8<T> load(const T values[16]) {
  107|  10.2M|    return _mm_loadu_si128(reinterpret_cast<const __m128i *>(values));
  108|  10.2M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE7gt_bitsES4_:
  212|  1.71M|  gt_bits(const simd8<uint8_t> other) const {
  213|  1.71M|    return this->saturating_sub(other);
  214|  1.71M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEC2EDv2_x:
   16|   213M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEcvRKDv2_xEv:
   18|   210M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE21any_bits_set_anywhereEv:
  235|  2.89k|  simdutf_really_inline bool any_bits_set_anywhere() const {
  236|  2.89k|    return !bits_not_set_anywhere();
  237|  2.89k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE21bits_not_set_anywhereEv:
  232|  2.89k|  simdutf_really_inline bool bits_not_set_anywhere() const {
  233|  2.89k|    return _mm_testz_si128(*this, *this);
  234|  2.89k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEC2EDv2_x:
   16|  15.8M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEcvRKDv2_xEv:
   18|  24.1M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE5splatEh:
  102|  41.0M|  static simdutf_really_inline simd8<T> splat(T _value) {
  103|  41.0M|    return _mm_set1_epi8(_value);
  104|  41.0M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEcvRKDv2_xEv:
   18|   272M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEanES5_:
   45|  41.0M|  simdutf_really_inline Child operator&(const Child other) const {
   46|  41.0M|    return _mm_and_si128(*this, other);
   47|  41.0M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IhEC2EPKh:
  270|  2.13M|      : chunks{simd8<T>::load(ptr),
  271|  2.13M|               simd8<T>::load(ptr + sizeof(simd8<T>) / sizeof(T)),
  272|  2.13M|               simd8<T>::load(ptr + 2 * sizeof(simd8<T>) / sizeof(T)),
  273|  2.13M|               simd8<T>::load(ptr + 3 * sizeof(simd8<T>) / sizeof(T))} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEanES5_:
   45|  43.6M|  simdutf_really_inline Child operator&(const Child other) const {
   46|  43.6M|    return _mm_and_si128(*this, other);
   47|  43.6M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEeoES5_:
   48|   546k|  simdutf_really_inline Child operator^(const Child other) const {
   49|   546k|    return _mm_xor_si128(*this, other);
   50|   546k|  }

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

_ZNK7simdutf8westmere14implementation13validate_utf8EPKcm:
  299|  2.89k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
  300|  2.89k|  return westmere::utf8_validation::generic_validate_utf8(buf, len);
  301|  2.89k|}
_ZNK7simdutf8westmere14implementation35convert_utf16le_to_utf8_with_errorsEPKDsmPc:
  749|   637k|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  750|       |  // ret.first.count is always the position in the buffer, not the number of
  751|       |  // code units written even if finished
  752|   637k|  std::pair<result, char *> ret =
  753|   637k|      westmere::sse_convert_utf16_to_utf8_with_errors<endianness::LITTLE>(
  754|   637k|          buf, len, utf8_output);
  755|   637k|  if (ret.first.error) {
  ------------------
  |  Branch (755:7): [True: 632k, False: 4.47k]
  ------------------
  756|   632k|    return ret.first;
  757|   632k|  } // Can return directly since scalar fallback already found correct
  758|       |    // ret.first.count
  759|  4.47k|  if (ret.first.count != len) { // All good so far, but not finished
  ------------------
  |  Branch (759:7): [True: 4.47k, False: 0]
  ------------------
  760|  4.47k|    result scalar_res =
  761|  4.47k|        scalar::utf16_to_utf8::convert_with_errors<endianness::LITTLE>(
  762|  4.47k|            buf + ret.first.count, len - ret.first.count, ret.second);
  763|  4.47k|    if (scalar_res.error) {
  ------------------
  |  Branch (763:9): [True: 3.50k, False: 965]
  ------------------
  764|  3.50k|      scalar_res.count += ret.first.count;
  765|  3.50k|      return scalar_res;
  766|  3.50k|    } else {
  767|    965|      ret.second += scalar_res.count;
  768|    965|    }
  769|  4.47k|  }
  770|    965|  ret.first.count =
  771|    965|      ret.second -
  772|    965|      utf8_output; // Set count to the number of 8-bit code units written
  773|    965|  return ret.first;
  774|  4.47k|}
_ZNK7simdutf8westmere14implementation35convert_utf16be_to_utf8_with_errorsEPKDsmPc:
  777|  1.05M|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  778|       |  // ret.first.count is always the position in the buffer, not the number of
  779|       |  // code units written even if finished
  780|  1.05M|  std::pair<result, char *> ret =
  781|  1.05M|      westmere::sse_convert_utf16_to_utf8_with_errors<endianness::BIG>(
  782|  1.05M|          buf, len, utf8_output);
  783|  1.05M|  if (ret.first.error) {
  ------------------
  |  Branch (783:7): [True: 1.04M, False: 4.55k]
  ------------------
  784|  1.04M|    return ret.first;
  785|  1.04M|  } // Can return directly since scalar fallback already found correct
  786|       |    // ret.first.count
  787|  4.55k|  if (ret.first.count != len) { // All good so far, but not finished
  ------------------
  |  Branch (787:7): [True: 4.55k, False: 0]
  ------------------
  788|  4.55k|    result scalar_res =
  789|  4.55k|        scalar::utf16_to_utf8::convert_with_errors<endianness::BIG>(
  790|  4.55k|            buf + ret.first.count, len - ret.first.count, ret.second);
  791|  4.55k|    if (scalar_res.error) {
  ------------------
  |  Branch (791:9): [True: 3.65k, False: 897]
  ------------------
  792|  3.65k|      scalar_res.count += ret.first.count;
  793|  3.65k|      return scalar_res;
  794|  3.65k|    } else {
  795|    897|      ret.second += scalar_res.count;
  796|    897|    }
  797|  4.55k|  }
  798|    897|  ret.first.count =
  799|    897|      ret.second -
  800|    897|      utf8_output; // Set count to the number of 8-bit code units written
  801|    897|  return ret.first;
  802|  4.55k|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16leEPKDsm:
 1158|   636k|    const char16_t *input, size_t length) const noexcept {
 1159|   636k|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1160|   636k|                                                                    length);
 1161|   636k|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16beEPKDsm:
 1164|  1.05M|    const char16_t *input, size_t length) const noexcept {
 1165|  1.05M|  return utf16::utf8_length_from_utf16_bytemask<endianness::BIG>(input, length);
 1166|  1.05M|}
_ZNK7simdutf8westmere14implementation41utf8_length_from_utf16le_with_replacementEPKDsm:
 1250|  1.49k|    const char16_t *input, size_t length) const noexcept {
 1251|  1.49k|  return utf16::utf8_length_from_utf16_with_replacement<endianness::LITTLE>(
 1252|  1.49k|      input, length);
 1253|  1.49k|}
_ZNK7simdutf8westmere14implementation41utf8_length_from_utf16be_with_replacementEPKDsm:
 1257|  1.40k|    const char16_t *input, size_t length) const noexcept {
 1258|  1.40k|  return utf16::utf8_length_from_utf16_with_replacement<endianness::BIG>(
 1259|  1.40k|      input, length);
 1260|  1.40k|}
_ZNK7simdutf8westmere14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPc:
 1264|  1.49k|    const char16_t *input, size_t length, char *utf8_buffer) const noexcept {
 1265|  1.49k|  return utf16_to_utf8::convert_with_replacement_via(
 1266|  1.49k|      [this](const char16_t *b, size_t l, char *o) {
 1267|  1.49k|        return this->convert_utf16le_to_utf8_with_errors(b, l, o);
 1268|  1.49k|      },
 1269|  1.49k|      [this](const char16_t *b, size_t l) {
 1270|  1.49k|        return this->utf8_length_from_utf16le(b, l);
 1271|  1.49k|      },
 1272|  1.49k|      input, length, utf8_buffer);
 1273|  1.49k|}
_ZNK7simdutf8westmere14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPc:
 1277|  1.40k|    const char16_t *input, size_t length, char *utf8_buffer) const noexcept {
 1278|  1.40k|  return utf16_to_utf8::convert_with_replacement_via(
 1279|  1.40k|      [this](const char16_t *b, size_t l, char *o) {
 1280|  1.40k|        return this->convert_utf16be_to_utf8_with_errors(b, l, o);
 1281|  1.40k|      },
 1282|  1.40k|      [this](const char16_t *b, size_t l) {
 1283|  1.40k|        return this->utf8_length_from_utf16be(b, l);
 1284|  1.40k|      },
 1285|  1.40k|      input, length, utf8_buffer);
 1286|  1.40k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_18is_asciiERKNS1_4simd8simd8x64IhEE:
   13|  2.13M|simdutf_really_inline bool is_ascii(const simd8x64<uint8_t> &input) {
   14|  2.13M|  return input.reduce_or().is_ascii();
   15|  2.13M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_124must_be_2_3_continuationENS1_4simd5simd8IhEES4_:
   22|  6.84M|                         const simd8<uint8_t> prev3) {
   23|  6.84M|  simd8<uint8_t> is_third_byte =
   24|  6.84M|      prev2.saturating_sub(0xe0u - 0x80); // Only 111_____ will be >= 0x80
   25|  6.84M|  simd8<uint8_t> is_fourth_byte =
   26|  6.84M|      prev3.saturating_sub(0xf0u - 0x80); // Only 1111____ will be >= 0x80
   27|  6.84M|  return simd8<bool>(is_third_byte | is_fourth_byte);
   28|  6.84M|}
simdutf.cpp:_ZZNK7simdutf8westmere14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPcENK3$_0clES3_mS4_:
 1266|   637k|      [this](const char16_t *b, size_t l, char *o) {
 1267|   637k|        return this->convert_utf16le_to_utf8_with_errors(b, l, o);
 1268|   637k|      },
simdutf.cpp:_ZZNK7simdutf8westmere14implementation40convert_utf16le_to_utf8_with_replacementEPKDsmPcENK3$_1clES3_m:
 1269|   636k|      [this](const char16_t *b, size_t l) {
 1270|   636k|        return this->utf8_length_from_utf16le(b, l);
 1271|   636k|      },
simdutf.cpp:_ZZNK7simdutf8westmere14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPcENK3$_0clES3_mS4_:
 1279|  1.05M|      [this](const char16_t *b, size_t l, char *o) {
 1280|  1.05M|        return this->convert_utf16be_to_utf8_with_errors(b, l, o);
 1281|  1.05M|      },
simdutf.cpp:_ZZNK7simdutf8westmere14implementation40convert_utf16be_to_utf8_with_replacementEPKDsmPcENK3$_1clES3_m:
 1282|  1.05M|      [this](const char16_t *b, size_t l) {
 1283|  1.05M|        return this->utf8_length_from_utf16be(b, l);
 1284|  1.05M|      },

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_18internal8westmere26write_v_u16_11bits_to_utf8EDv2_xRPcS4_t:
   10|  59.0k|                                       const uint16_t one_byte_bitmask) {
   11|       |  // 0b1100_0000_1000_0000
   12|  59.0k|  const __m128i v_c080 = _mm_set1_epi16((int16_t)0xc080);
   13|       |  // 0b0001_1111_0000_0000
   14|  59.0k|  const __m128i v_1f00 = _mm_set1_epi16((int16_t)0x1f00);
   15|       |  // 0b0000_0000_0011_1111
   16|  59.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|  59.0k|  const __m128i t0 = _mm_slli_epi16(v_u16, 2);
   24|       |  // t1 = [000a|aaaa|0000|0000]
   25|  59.0k|  const __m128i t1 = _mm_and_si128(t0, v_1f00);
   26|       |  // t2 = [0000|0000|00bb|bbbb]
   27|  59.0k|  const __m128i t2 = _mm_and_si128(v_u16, v_003f);
   28|       |  // t3 = [000a|aaaa|00bb|bbbb]
   29|  59.0k|  const __m128i t3 = _mm_or_si128(t1, t2);
   30|       |  // t4 = [110a|aaaa|10bb|bbbb]
   31|  59.0k|  const __m128i t4 = _mm_or_si128(t3, v_c080);
   32|       |
   33|       |  // 2. merge ASCII and 2-byte codewords
   34|  59.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|  59.0k|  const uint16_t m0 = one_byte_bitmask & 0x5555;      // m0 = 0h0g0f0e0d0c0b0a
   40|  59.0k|  const uint16_t m1 = static_cast<uint16_t>(m0 >> 7); // m1 = 00000000h0g0f0e0
   41|  59.0k|  const uint8_t m2 = static_cast<uint8_t>((m0 | m1) & 0xff); // m2 = hdgcfbea
   42|       |  // 4. pack the bytes
   43|  59.0k|  const uint8_t *row =
   44|  59.0k|      &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[m2][0];
   45|  59.0k|  const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
   46|  59.0k|  const __m128i utf8_packed = _mm_shuffle_epi8(utf8_unpacked, shuffle);
   47|       |
   48|       |  // 5. store bytes
   49|  59.0k|  _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   50|       |
   51|       |  // 6. adjust pointers
   52|  59.0k|  utf8_output += row[0];
   53|  59.0k|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_137sse_convert_utf16_to_utf8_with_errorsILNS_10endiannessE0EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
  285|   637k|                                      char *utf8_output) {
  286|   637k|  const char16_t *start = buf;
  287|   637k|  const char16_t *end = buf + len;
  288|       |
  289|   637k|  const __m128i v_0000 = _mm_setzero_si128();
  290|   637k|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
  291|   637k|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
  292|   637k|  const size_t safety_margin =
  293|   637k|      12; // to avoid overruns, see issue
  294|       |          // https://github.com/simdutf/simdutf/issues/92
  295|       |
  296|  4.06M|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (296:10): [True: 4.06M, False: 4.47k]
  ------------------
  297|  4.06M|    __m128i in = _mm_loadu_si128((__m128i *)buf);
  298|  4.06M|    if (big_endian) {
  ------------------
  |  Branch (298:9): [Folded, False: 4.06M]
  ------------------
  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|  4.06M|    const __m128i v_ff80 = _mm_set1_epi16((int16_t)0xff80);
  305|  4.06M|    if (_mm_testz_si128(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (305:9): [True: 1.02M, False: 3.03M]
  ------------------
  306|  1.02M|      __m128i nextin = _mm_loadu_si128((__m128i *)buf + 1);
  307|  1.02M|      if (big_endian) {
  ------------------
  |  Branch (307:11): [Folded, False: 1.02M]
  ------------------
  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|  1.02M|      if (!_mm_testz_si128(nextin, v_ff80)) {
  ------------------
  |  Branch (312:11): [True: 19.6k, False: 1.00M]
  ------------------
  313|       |        // 1. pack the bytes
  314|       |        // obviously suboptimal.
  315|  19.6k|        const __m128i utf8_packed = _mm_packus_epi16(in, in);
  316|       |        // 2. store (16 bytes)
  317|  19.6k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  318|       |        // 3. adjust pointers
  319|  19.6k|        buf += 8;
  320|  19.6k|        utf8_output += 8;
  321|  19.6k|        in = nextin;
  322|  1.00M|      } else {
  323|       |        // 1. pack the bytes
  324|       |        // obviously suboptimal.
  325|  1.00M|        const __m128i utf8_packed = _mm_packus_epi16(in, nextin);
  326|       |        // 2. store (16 bytes)
  327|  1.00M|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  328|       |        // 3. adjust pointers
  329|  1.00M|        buf += 16;
  330|  1.00M|        utf8_output += 16;
  331|  1.00M|        continue; // we are done for this round!
  332|  1.00M|      }
  333|  1.02M|    }
  334|       |
  335|       |    // no bits set above 7th bit
  336|  3.05M|    const __m128i one_byte_bytemask =
  337|  3.05M|        _mm_cmpeq_epi16(_mm_and_si128(in, v_ff80), v_0000);
  338|  3.05M|    const uint16_t one_byte_bitmask =
  339|  3.05M|        static_cast<uint16_t>(_mm_movemask_epi8(one_byte_bytemask));
  340|       |
  341|       |    // no bits set above 11th bit
  342|  3.05M|    const __m128i one_or_two_bytes_bytemask =
  343|  3.05M|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_0000);
  344|  3.05M|    const uint16_t one_or_two_bytes_bitmask =
  345|  3.05M|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  346|       |
  347|  3.05M|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (347:9): [True: 30.4k, False: 3.02M]
  ------------------
  348|  30.4k|      internal::westmere::write_v_u16_11bits_to_utf8(
  349|  30.4k|          in, utf8_output, one_byte_bytemask, one_byte_bitmask);
  350|  30.4k|      buf += 8;
  351|  30.4k|      continue;
  352|  30.4k|    }
  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|  3.02M|    const __m128i surrogates_bytemask =
  358|  3.02M|        _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|  3.02M|    const uint16_t surrogates_bitmask =
  363|  3.02M|        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|  3.02M|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (366:9): [True: 2.38M, False: 635k]
  ------------------
  367|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  368|  2.38M|      const __m128i dup_even = _mm_setr_epi16(0x0000, 0x0202, 0x0404, 0x0606,
  369|  2.38M|                                              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.38M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  399|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  400|  2.38M|      const __m128i t0 = _mm_shuffle_epi8(in, dup_even);
  401|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  402|  2.38M|      const __m128i t1 = _mm_and_si128(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  398|  2.38M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  403|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  404|  2.38M|      const __m128i t2 = _mm_or_si128(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  398|  2.38M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  405|       |
  406|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  407|  2.38M|      const __m128i s0 = _mm_srli_epi16(in, 4);
  408|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  409|  2.38M|      const __m128i s1 = _mm_and_si128(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  398|  2.38M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  410|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  411|  2.38M|      const __m128i s2 = _mm_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  398|  2.38M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  412|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  413|  2.38M|      const __m128i s3 = _mm_or_si128(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  398|  2.38M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  414|  2.38M|      const __m128i m0 = _mm_andnot_si128(one_or_two_bytes_bytemask,
  415|  2.38M|                                          simdutf_vec(0b0100000000000000));
  ------------------
  |  |  398|  2.38M|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  416|  2.38M|      const __m128i s4 = _mm_xor_si128(s3, m0);
  417|  2.38M|#undef simdutf_vec
  418|       |
  419|       |      // 4. expand code units 16-bit => 32-bit
  420|  2.38M|      const __m128i out0 = _mm_unpacklo_epi16(t2, s4);
  421|  2.38M|      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.38M|      const uint16_t mask =
  425|  2.38M|          (one_byte_bitmask & 0x5555) | (one_or_two_bytes_bitmask & 0xaaaa);
  426|  2.38M|      if (mask == 0) {
  ------------------
  |  Branch (426:11): [True: 2.10M, False: 285k]
  ------------------
  427|       |        // We only have three-byte code units. Use fast path.
  428|  2.10M|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  429|  2.10M|                                              15, 13, -1, -1, -1, -1);
  430|  2.10M|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  431|  2.10M|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  432|  2.10M|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  433|  2.10M|        utf8_output += 12;
  434|  2.10M|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  435|  2.10M|        utf8_output += 12;
  436|  2.10M|        buf += 8;
  437|  2.10M|        continue;
  438|  2.10M|      }
  439|   285k|      const uint8_t mask0 = uint8_t(mask);
  440|       |
  441|   285k|      const uint8_t *row0 =
  442|   285k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  443|   285k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  444|   285k|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  445|       |
  446|   285k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  447|       |
  448|   285k|      const uint8_t *row1 =
  449|   285k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  450|   285k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  451|   285k|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  452|       |
  453|   285k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  454|   285k|      utf8_output += row0[0];
  455|   285k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  456|   285k|      utf8_output += row1[0];
  457|       |
  458|   285k|      buf += 8;
  459|       |      // surrogate pair(s) in a register
  460|   635k|    } 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|   635k|      size_t forward = 15;
  465|   635k|      size_t k = 0;
  466|   635k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (466:11): [True: 0, False: 635k]
  ------------------
  467|      0|        forward = size_t(end - buf - 1);
  468|      0|      }
  469|  1.55M|      for (; k < forward; k++) {
  ------------------
  |  Branch (469:14): [True: 1.54M, False: 3.01k]
  ------------------
  470|  1.54M|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  471|  1.54M|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (471:13): [True: 71.0k, False: 1.47M]
  ------------------
  472|  71.0k|          *utf8_output++ = char(word);
  473|  1.47M|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (473:20): [True: 43.8k, False: 1.43M]
  ------------------
  474|  43.8k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  475|  43.8k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  476|  1.43M|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (476:20): [True: 711k, False: 720k]
  ------------------
  477|   711k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  478|   711k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  479|   711k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  480|   720k|        } else {
  481|       |          // must be a surrogate pair
  482|   720k|          uint16_t diff = uint16_t(word - 0xD800);
  483|   720k|          uint16_t next_word =
  484|   720k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  485|   720k|          k++;
  486|   720k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  487|   720k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (487:15): [True: 632k, False: 87.9k]
  ------------------
  488|   632k|            return std::make_pair(
  489|   632k|                result(error_code::SURROGATE, buf - start + k - 1),
  490|   632k|                utf8_output);
  491|   632k|          }
  492|  87.9k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  493|  87.9k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  494|  87.9k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  495|  87.9k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  496|  87.9k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  497|  87.9k|        }
  498|  1.54M|      }
  499|  3.01k|      buf += k;
  500|  3.01k|    }
  501|  3.02M|  } // while
  502|       |
  503|  4.47k|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  504|   637k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_137sse_convert_utf16_to_utf8_with_errorsILNS_10endiannessE1EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
  285|  1.05M|                                      char *utf8_output) {
  286|  1.05M|  const char16_t *start = buf;
  287|  1.05M|  const char16_t *end = buf + len;
  288|       |
  289|  1.05M|  const __m128i v_0000 = _mm_setzero_si128();
  290|  1.05M|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
  291|  1.05M|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
  292|  1.05M|  const size_t safety_margin =
  293|  1.05M|      12; // to avoid overruns, see issue
  294|       |          // https://github.com/simdutf/simdutf/issues/92
  295|       |
  296|  3.61M|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (296:10): [True: 3.61M, False: 4.55k]
  ------------------
  297|  3.61M|    __m128i in = _mm_loadu_si128((__m128i *)buf);
  298|  3.61M|    if (big_endian) {
  ------------------
  |  Branch (298:9): [True: 3.61M, Folded]
  ------------------
  299|  3.61M|      const __m128i swap =
  300|  3.61M|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  301|  3.61M|      in = _mm_shuffle_epi8(in, swap);
  302|  3.61M|    }
  303|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
  304|  3.61M|    const __m128i v_ff80 = _mm_set1_epi16((int16_t)0xff80);
  305|  3.61M|    if (_mm_testz_si128(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (305:9): [True: 821k, False: 2.79M]
  ------------------
  306|   821k|      __m128i nextin = _mm_loadu_si128((__m128i *)buf + 1);
  307|   821k|      if (big_endian) {
  ------------------
  |  Branch (307:11): [True: 821k, Folded]
  ------------------
  308|   821k|        const __m128i swap =
  309|   821k|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  310|   821k|        nextin = _mm_shuffle_epi8(nextin, swap);
  311|   821k|      }
  312|   821k|      if (!_mm_testz_si128(nextin, v_ff80)) {
  ------------------
  |  Branch (312:11): [True: 40.8k, False: 780k]
  ------------------
  313|       |        // 1. pack the bytes
  314|       |        // obviously suboptimal.
  315|  40.8k|        const __m128i utf8_packed = _mm_packus_epi16(in, in);
  316|       |        // 2. store (16 bytes)
  317|  40.8k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  318|       |        // 3. adjust pointers
  319|  40.8k|        buf += 8;
  320|  40.8k|        utf8_output += 8;
  321|  40.8k|        in = nextin;
  322|   780k|      } else {
  323|       |        // 1. pack the bytes
  324|       |        // obviously suboptimal.
  325|   780k|        const __m128i utf8_packed = _mm_packus_epi16(in, nextin);
  326|       |        // 2. store (16 bytes)
  327|   780k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  328|       |        // 3. adjust pointers
  329|   780k|        buf += 16;
  330|   780k|        utf8_output += 16;
  331|   780k|        continue; // we are done for this round!
  332|   780k|      }
  333|   821k|    }
  334|       |
  335|       |    // no bits set above 7th bit
  336|  2.83M|    const __m128i one_byte_bytemask =
  337|  2.83M|        _mm_cmpeq_epi16(_mm_and_si128(in, v_ff80), v_0000);
  338|  2.83M|    const uint16_t one_byte_bitmask =
  339|  2.83M|        static_cast<uint16_t>(_mm_movemask_epi8(one_byte_bytemask));
  340|       |
  341|       |    // no bits set above 11th bit
  342|  2.83M|    const __m128i one_or_two_bytes_bytemask =
  343|  2.83M|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_0000);
  344|  2.83M|    const uint16_t one_or_two_bytes_bitmask =
  345|  2.83M|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  346|       |
  347|  2.83M|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (347:9): [True: 28.5k, False: 2.80M]
  ------------------
  348|  28.5k|      internal::westmere::write_v_u16_11bits_to_utf8(
  349|  28.5k|          in, utf8_output, one_byte_bytemask, one_byte_bitmask);
  350|  28.5k|      buf += 8;
  351|  28.5k|      continue;
  352|  28.5k|    }
  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|  2.80M|    const __m128i surrogates_bytemask =
  358|  2.80M|        _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|  2.80M|    const uint16_t surrogates_bitmask =
  363|  2.80M|        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|  2.80M|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (366:9): [True: 1.75M, False: 1.05M]
  ------------------
  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.53M, False: 221k]
  ------------------
  427|       |        // We only have three-byte code units. Use fast path.
  428|  1.53M|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  429|  1.53M|                                              15, 13, -1, -1, -1, -1);
  430|  1.53M|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  431|  1.53M|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  432|  1.53M|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  433|  1.53M|        utf8_output += 12;
  434|  1.53M|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  435|  1.53M|        utf8_output += 12;
  436|  1.53M|        buf += 8;
  437|  1.53M|        continue;
  438|  1.53M|      }
  439|   221k|      const uint8_t mask0 = uint8_t(mask);
  440|       |
  441|   221k|      const uint8_t *row0 =
  442|   221k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  443|   221k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  444|   221k|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  445|       |
  446|   221k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  447|       |
  448|   221k|      const uint8_t *row1 =
  449|   221k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  450|   221k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  451|   221k|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  452|       |
  453|   221k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  454|   221k|      utf8_output += row0[0];
  455|   221k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  456|   221k|      utf8_output += row1[0];
  457|       |
  458|   221k|      buf += 8;
  459|       |      // surrogate pair(s) in a register
  460|  1.05M|    } 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|  1.05M|      size_t forward = 15;
  465|  1.05M|      size_t k = 0;
  466|  1.05M|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (466:11): [True: 0, False: 1.05M]
  ------------------
  467|      0|        forward = size_t(end - buf - 1);
  468|      0|      }
  469|  1.78M|      for (; k < forward; k++) {
  ------------------
  |  Branch (469:14): [True: 1.78M, False: 1.51k]
  ------------------
  470|  1.78M|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  471|  1.78M|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (471:13): [True: 60.4k, False: 1.72M]
  ------------------
  472|  60.4k|          *utf8_output++ = char(word);
  473|  1.72M|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (473:20): [True: 40.8k, False: 1.68M]
  ------------------
  474|  40.8k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  475|  40.8k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  476|  1.68M|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (476:20): [True: 541k, False: 1.13M]
  ------------------
  477|   541k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  478|   541k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  479|   541k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  480|  1.13M|        } else {
  481|       |          // must be a surrogate pair
  482|  1.13M|          uint16_t diff = uint16_t(word - 0xD800);
  483|  1.13M|          uint16_t next_word =
  484|  1.13M|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  485|  1.13M|          k++;
  486|  1.13M|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  487|  1.13M|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (487:15): [True: 1.04M, False: 90.4k]
  ------------------
  488|  1.04M|            return std::make_pair(
  489|  1.04M|                result(error_code::SURROGATE, buf - start + k - 1),
  490|  1.04M|                utf8_output);
  491|  1.04M|          }
  492|  90.4k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  493|  90.4k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  494|  90.4k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  495|  90.4k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  496|  90.4k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  497|  90.4k|        }
  498|  1.78M|      }
  499|  1.51k|      buf += k;
  500|  1.51k|    }
  501|  2.80M|  } // while
  502|       |
  503|  4.55k|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  504|  1.05M|}

