_Z19test_latin1_to_utf8NSt3__14spanIKhLm18446744073709551615EEEm:
   10|    710|                         std::size_t output_size) {
   11|    710|  std::vector<char> output(output_size);
   12|    710|  const auto written_bytes_safe =
   13|    710|      simdutf::convert_latin1_to_utf8_safe(input_bytes, output);
   14|    710|  if (written_bytes_safe > output_size) {
  ------------------
  |  Branch (14:7): [True: 0, False: 710]
  ------------------
   15|      0|    std::abort();
   16|      0|  }
   17|    710|  const auto needed_size = simdutf::utf8_length_from_latin1(input_bytes);
   18|    710|  std::vector<char> reference(needed_size);
   19|    710|  const auto written_bytes_unsafe =
   20|    710|      simdutf::convert_latin1_to_utf8(input_bytes, reference);
   21|    710|  if (written_bytes_unsafe != needed_size) {
  ------------------
  |  Branch (21:7): [True: 0, False: 710]
  ------------------
   22|      0|    std::abort();
   23|      0|  }
   24|    710|  if (written_bytes_safe > needed_size) {
  ------------------
  |  Branch (24:7): [True: 0, False: 710]
  ------------------
   25|       |    // convert_latin1_to_utf8_safe wrote more output buffer than the unsafe
   26|       |    // version needed!
   27|      0|    std::abort();
   28|      0|  }
   29|       |  // ensure output is equal to the beginning of reference
   30|    710|  if (!std::ranges::equal(
  ------------------
  |  Branch (30:7): [True: 0, False: 710]
  ------------------
   31|    710|          std::span(output).subspan(0, written_bytes_safe),
   32|    710|          std::span(reference).subspan(0, written_bytes_safe))) {
   33|      0|    std::abort();
   34|      0|  }
   35|    710|}
_Z18test_utf16_to_utf8NSt3__14spanIKDsLm18446744073709551615EEEm:
   38|    988|                        std::size_t output_size) {
   39|    988|  std::vector<char> output(output_size);
   40|    988|  const auto written_bytes_safe =
   41|    988|      simdutf::convert_utf16_to_utf8_safe(input, output);
   42|    988|  if (written_bytes_safe > output_size) {
  ------------------
  |  Branch (42:7): [True: 0, False: 988]
  ------------------
   43|      0|    std::abort();
   44|      0|  }
   45|       |  // result is implementation defined in case of garbage input
   46|    988|  const auto unreliable_needed_size = simdutf::utf8_length_from_utf16(input);
   47|    988|  std::vector<char> reference(unreliable_needed_size);
   48|    988|  const auto written_bytes_unsafe =
   49|    988|      simdutf::convert_utf16_to_utf8(input, reference);
   50|       |
   51|       |  // ensure output is equal to the beginning of reference
   52|    988|  const auto Ncompare =
   53|    988|      simdutf::detail::min(written_bytes_safe, written_bytes_unsafe);
   54|    988|  const auto matches =
   55|    988|      std::ranges::equal(std::span(output).subspan(0, Ncompare),
   56|    988|                         std::span(reference).subspan(0, Ncompare));
   57|    988|  assert(matches);
  ------------------
  |  Branch (57:3): [True: 988, False: 0]
  ------------------
   58|    988|  if (!matches) {
  ------------------
  |  Branch (58:7): [True: 0, False: 988]
  ------------------
   59|      0|    std::abort();
   60|      0|  }
   61|    988|}
LLVMFuzzerTestOneInput:
   80|  1.70k|extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
   81|       |
   82|  1.70k|  if (size < 4) {
  ------------------
  |  Branch (82:7): [True: 2, False: 1.69k]
  ------------------
   83|      2|    return 0;
   84|      2|  }
   85|       |
   86|  1.69k|  const auto action = data[0] & 0x1;
   87|  1.69k|  const auto output_size = (data[1] << 8 | data[2]);
   88|  1.69k|  const auto implementation_index = data[3] & 0b0111;
   89|  1.69k|  data += 4;
   90|  1.69k|  size -= 4;
   91|       |
   92|  1.69k|  const std::span<const uint8_t> input_bytes{data, data + size};
   93|       |
   94|  1.69k|  select_implementation(implementation_index);
   95|       |
   96|  1.69k|  switch (action) {
  ------------------
  |  Branch (96:11): [True: 1.69k, False: 0]
  ------------------
   97|    710|  case 0:
  ------------------
  |  Branch (97:3): [True: 710, False: 988]
  ------------------
   98|    710|    test_latin1_to_utf8(input_bytes, output_size);
   99|    710|    break;
  100|    988|  case 1: {
  ------------------
  |  Branch (100:3): [True: 988, False: 710]
  ------------------
  101|    988|    const auto* ptr = reinterpret_cast<const char16_t*>(input_bytes.data());
  102|    988|    test_utf16_to_utf8(std::span(ptr, ptr + input_bytes.size() / 2),
  103|    988|                       output_size);
  104|    988|  } break;
  105|  1.69k|  }
  106|       |
  107|  1.69k|  return 0;
  108|  1.69k|}
_Z21select_implementationIiEvT_:
   63|  1.69k|void select_implementation(auto index) {
   64|  1.69k|  static const auto implementations = []() {
   65|  1.69k|    const auto list = simdutf::get_available_implementations();
   66|  1.69k|    using Impl = std::decay_t<decltype(*list.begin())>;
   67|  1.69k|    std::vector<Impl> ret;
   68|  1.69k|    for (auto& e : list) {
   69|  1.69k|      if (e->supported_by_runtime_system()) {
   70|  1.69k|        ret.push_back(e);
   71|  1.69k|      }
   72|  1.69k|    }
   73|  1.69k|    return ret;
   74|  1.69k|  }();
   75|  1.69k|  assert(!implementations.empty());
  ------------------
  |  Branch (75:3): [True: 1.69k, False: 0]
  ------------------
   76|  1.69k|  simdutf::get_active_implementation() =
   77|  1.69k|      implementations.at(index % implementations.size());
   78|  1.69k|}
_ZZ21select_implementationIiEvT_ENKUlvE_clEv:
   64|      1|  static const auto implementations = []() {
   65|      1|    const auto list = simdutf::get_available_implementations();
   66|      1|    using Impl = std::decay_t<decltype(*list.begin())>;
   67|      1|    std::vector<Impl> ret;
   68|      4|    for (auto& e : list) {
  ------------------
  |  Branch (68:18): [True: 4, False: 1]
  ------------------
   69|      4|      if (e->supported_by_runtime_system()) {
  ------------------
  |  Branch (69:11): [True: 3, False: 1]
  ------------------
   70|      3|        ret.push_back(e);
   71|      3|      }
   72|      4|    }
   73|      1|    return ret;
   74|      1|  }();

_ZN7simdutf11full_resultC2ENS_10error_codeEmm:
  111|    818|      : error{err}, input_count{pos_in}, output_count{pos_out} {}

_ZNK7simdutf14implementation25required_instruction_setsEv:
 5157|      4|  virtual uint32_t required_instruction_sets() const {
 5158|      4|    return _required_instruction_sets;
 5159|      4|  }
_ZN7simdutf14implementationC2EPKcS2_j:
 7043|      5|      : _name(name), _description(description),
 7044|      5|        _required_instruction_sets(required_instruction_sets) {}
_ZN7simdutf8internal29available_implementation_listC2Ev:
 7075|      1|  simdutf_really_inline available_implementation_list() {}
simdutf.cpp:_ZN7simdutf6detail12_GLOBAL__N_13minEmm:
   59|  3.90k|constexpr std::size_t min(std::size_t a, std::size_t b) {
   60|  3.90k|  return a < b ? a : b;
  ------------------
  |  Branch (60:10): [True: 1.46k, False: 2.43k]
  ------------------
   61|  3.90k|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEC2EPS3_:
 7123|      1|  atomic_ptr(T *_ptr) : ptr{_ptr} {}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEptEv:
 7145|  5.76k|  T *operator->() { return ptr.load(); }

simdutf.cpp:_ZN7simdutf8internalL30detect_supported_architecturesEv:
  236|      4|static inline uint32_t detect_supported_architectures() {
  237|      4|  uint32_t eax;
  238|      4|  uint32_t ebx = 0;
  239|      4|  uint32_t ecx = 0;
  240|      4|  uint32_t edx = 0;
  241|      4|  uint32_t host_isa = 0x0;
  242|       |
  243|       |  // EBX for EAX=0x1
  244|      4|  eax = 0x1;
  245|      4|  cpuid(&eax, &ebx, &ecx, &edx);
  246|       |
  247|      4|  if (ecx & cpuid_bit::sse42) {
  ------------------
  |  Branch (247:7): [True: 4, False: 0]
  ------------------
  248|      4|    host_isa |= instruction_set::SSE42;
  249|      4|  }
  250|       |
  251|      4|  if (ecx & cpuid_bit::pclmulqdq) {
  ------------------
  |  Branch (251:7): [True: 4, False: 0]
  ------------------
  252|      4|    host_isa |= instruction_set::PCLMULQDQ;
  253|      4|  }
  254|       |
  255|      4|  if ((ecx & cpuid_bit::osxsave) != cpuid_bit::osxsave) {
  ------------------
  |  Branch (255:7): [True: 0, False: 4]
  ------------------
  256|      0|    return host_isa;
  257|      0|  }
  258|       |
  259|       |  // xgetbv for checking if the OS saves registers
  260|      4|  uint64_t xcr0 = xgetbv();
  261|       |
  262|      4|  if ((xcr0 & cpuid_bit::xcr0_bit::avx256_saved) == 0) {
  ------------------
  |  Branch (262:7): [True: 0, False: 4]
  ------------------
  263|      0|    return host_isa;
  264|      0|  }
  265|       |  // ECX for EAX=0x7
  266|      4|  eax = 0x7;
  267|      4|  ecx = 0x0; // Sub-leaf = 0
  268|      4|  cpuid(&eax, &ebx, &ecx, &edx);
  269|      4|  if (ebx & cpuid_bit::ebx::avx2) {
  ------------------
  |  Branch (269:7): [True: 4, False: 0]
  ------------------
  270|      4|    host_isa |= instruction_set::AVX2;
  271|      4|  }
  272|      4|  if (ebx & cpuid_bit::ebx::bmi1) {
  ------------------
  |  Branch (272:7): [True: 4, False: 0]
  ------------------
  273|      4|    host_isa |= instruction_set::BMI1;
  274|      4|  }
  275|      4|  if (ebx & cpuid_bit::ebx::bmi2) {
  ------------------
  |  Branch (275:7): [True: 4, False: 0]
  ------------------
  276|      4|    host_isa |= instruction_set::BMI2;
  277|      4|  }
  278|      4|  if (!((xcr0 & cpuid_bit::xcr0_bit::avx512_saved) ==
  ------------------
  |  Branch (278:7): [True: 4, False: 0]
  ------------------
  279|      4|        cpuid_bit::xcr0_bit::avx512_saved)) {
  280|      4|    return host_isa;
  281|      4|  }
  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|      4|}
simdutf.cpp:_ZN7simdutf8internalL5cpuidEPjS1_S1_S1_:
  202|      8|                         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|      8|  uint32_t a = *eax, b, c = *ecx, d;
  216|      8|  asm volatile("cpuid\n\t" : "+a"(a), "=b"(b), "+c"(c), "=d"(d));
  217|      8|  *eax = a;
  218|      8|  *ebx = b;
  219|      8|  *ecx = c;
  220|      8|  *edx = d;
  221|      8|  #endif
  222|      8|}
simdutf.cpp:_ZN7simdutf8internalL6xgetbvEv:
  224|      4|static inline uint64_t xgetbv() {
  225|       |  #if defined(_MSC_VER)
  226|       |  return _xgetbv(0);
  227|       |  #elif defined(__FILC__)
  228|       |  return zxgetbv();
  229|       |  #else
  230|      4|  uint32_t xcr0_lo, xcr0_hi;
  231|      4|  asm volatile("xgetbv\n\t" : "=a"(xcr0_lo), "=d"(xcr0_hi) : "c"(0));
  232|      4|  return xcr0_lo | ((uint64_t)xcr0_hi << 32);
  233|      4|  #endif
  234|      4|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16latin123utf8_length_from_latin1EPKcm:
   10|    528|                                                     size_t len) {
   11|    528|  const uint8_t *c = reinterpret_cast<const uint8_t *>(buf);
   12|    528|  size_t answer = 0;
   13|  4.28k|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (13:22): [True: 3.76k, False: 528]
  ------------------
   14|  3.76k|    if ((c[i] >> 7)) {
  ------------------
  |  Branch (14:9): [True: 1.17k, False: 2.58k]
  ------------------
   15|  1.17k|      answer++;
   16|  1.17k|    }
   17|  3.76k|  }
   18|    528|  return answer + len;
   19|    528|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf812convert_safeEPKcmPcm:
   72|    710|                           size_t utf8_len) {
   73|    710|  const unsigned char *data = reinterpret_cast<const unsigned char *>(buf);
   74|    710|  size_t pos = 0;
   75|    710|  size_t skip_pos = 0;
   76|    710|  size_t utf8_pos = 0;
   77|  4.24k|  while (pos < len && utf8_pos < utf8_len) {
  ------------------
  |  Branch (77:10): [True: 3.82k, False: 417]
  |  Branch (77:23): [True: 3.57k, False: 256]
  ------------------
   78|       |    // try to convert the next block of 16 ASCII bytes
   79|  3.57k|    if (pos >= skip_pos && pos + 16 <= len &&
  ------------------
  |  Branch (79:9): [True: 1.85k, False: 1.72k]
  |  Branch (79:28): [True: 1.30k, False: 543]
  ------------------
   80|  1.30k|        utf8_pos + 16 <= utf8_len) { // if it is safe to read 16 more bytes,
  ------------------
  |  Branch (80:9): [True: 268, False: 1.04k]
  ------------------
   81|       |                                     // check that they are ascii
   82|    268|      uint64_t v1;
   83|    268|      ::memcpy(&v1, data + pos, sizeof(uint64_t));
   84|    268|      uint64_t v2;
   85|    268|      ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   86|    268|      uint64_t v{v1 |
   87|    268|                 v2}; // We are only interested in these bits: 1000 1000 1000
   88|       |                      // 1000, so it makes sense to concatenate everything
   89|    268|      if ((v & 0x8080808080808080) ==
  ------------------
  |  Branch (89:11): [True: 153, False: 115]
  ------------------
   90|    268|          0) { // if NONE of these are set, e.g. all of them are zero, then
   91|       |               // everything is ASCII
   92|    153|        ::memcpy(utf8_output + utf8_pos, buf + pos, 16);
   93|    153|        utf8_pos += 16;
   94|    153|        pos += 16;
   95|    153|      } else {
   96|       |        // At least one of the next 16 bytes are not ASCII, we will process them
   97|       |        // one by one
   98|    115|        skip_pos = pos + 16;
   99|    115|      }
  100|  3.30k|    } else {
  101|  3.30k|      const auto byte = data[pos];
  102|  3.30k|      if ((byte & 0x80) == 0) { // if ASCII
  ------------------
  |  Branch (102:11): [True: 2.41k, False: 884]
  ------------------
  103|       |        // will generate one UTF-8 bytes
  104|  2.41k|        utf8_output[utf8_pos++] = char(byte);
  105|  2.41k|        pos++;
  106|  2.41k|      } else if (utf8_pos + 2 <= utf8_len) {
  ------------------
  |  Branch (106:18): [True: 847, False: 37]
  ------------------
  107|       |        // will generate two UTF-8 bytes
  108|    847|        utf8_output[utf8_pos++] = char((byte >> 6) | 0b11000000);
  109|    847|        utf8_output[utf8_pos++] = char((byte & 0b111111) | 0b10000000);
  110|    847|        pos++;
  111|    847|      } else {
  112|     37|        break;
  113|     37|      }
  114|  3.30k|    }
  115|  3.57k|  }
  116|    710|  return utf8_pos;
  117|    710|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf87convertEPKcmPc:
   66|  1.95k|                                     char *utf8_output) {
   67|  1.95k|  return convert(reinterpret_cast<const unsigned char *>(buf), len,
   68|  1.95k|                 utf8_output);
   69|  1.95k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf87convertIPKhPcQaasr7simdutf6detailE22indexes_into_byte_likeIT_Esr7simdutf6detailE26index_assignable_from_charIT0_EEEmS7_mS8_:
   17|  1.95k|                                   OutputPtr utf8_output) {
   18|       |  // const unsigned char *data = reinterpret_cast<const unsigned char *>(buf);
   19|  1.95k|  size_t pos = 0;
   20|  1.95k|  size_t utf8_pos = 0;
   21|       |
   22|  4.08M|  while (pos < len) {
  ------------------
  |  Branch (22:10): [True: 4.08M, False: 1.95k]
  ------------------
   23|       |#if SIMDUTF_CPLUSPLUS23
   24|       |    if !consteval
   25|       |#endif
   26|  4.08M|    {
   27|       |      // try to convert the next block of 16 ASCII bytes
   28|  4.08M|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (28:11): [True: 4.06M, False: 17.8k]
  ------------------
   29|       |                             // they are ascii
   30|  4.06M|        uint64_t v1;
   31|  4.06M|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   32|  4.06M|        uint64_t v2;
   33|  4.06M|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   34|  4.06M|        uint64_t v{v1 |
   35|  4.06M|                   v2}; // We are only interested in these bits: 1000 1000 1000
   36|       |                        // 1000, so it makes sense to concatenate everything
   37|  4.06M|        if ((v & 0x8080808080808080) ==
  ------------------
  |  Branch (37:13): [True: 780k, False: 3.28M]
  ------------------
   38|  4.06M|            0) { // if NONE of these are set, e.g. all of them are zero, then
   39|       |                 // everything is ASCII
   40|   780k|          size_t final_pos = pos + 16;
   41|  13.2M|          while (pos < final_pos) {
  ------------------
  |  Branch (41:18): [True: 12.4M, False: 780k]
  ------------------
   42|  12.4M|            utf8_output[utf8_pos++] = char(data[pos]);
   43|  12.4M|            pos++;
   44|  12.4M|          }
   45|   780k|          continue;
   46|   780k|        }
   47|  4.06M|      } // if (pos + 16 <= len)
   48|  4.08M|    } // !consteval scope
   49|       |
   50|  3.30M|    unsigned char byte = data[pos];
   51|  3.30M|    if ((byte & 0x80) == 0) { // if ASCII
  ------------------
  |  Branch (51:9): [True: 1.49M, False: 1.80M]
  ------------------
   52|       |      // will generate one UTF-8 bytes
   53|  1.49M|      utf8_output[utf8_pos++] = char(byte);
   54|  1.49M|      pos++;
   55|  1.80M|    } else {
   56|       |      // will generate two UTF-8 bytes
   57|  1.80M|      utf8_output[utf8_pos++] = char((byte >> 6) | 0b11000000);
   58|  1.80M|      utf8_output[utf8_pos++] = char((byte & 0b111111) | 0b10000000);
   59|  1.80M|      pos++;
   60|  1.80M|    }
   61|  3.30M|  } // while
   62|  1.95k|  return utf8_pos;
   63|  1.95k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf823utf8_length_from_latin1IPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_m:
  152|    182|utf8_length_from_latin1(InputPtr input, size_t length) noexcept {
  153|    182|  size_t answer = length;
  154|    182|  size_t i = 0;
  155|       |
  156|       |#if SIMDUTF_CPLUSPLUS23
  157|       |  if !consteval
  158|       |#endif
  159|    182|  {
  160|    182|    auto pop = [](uint64_t v) {
  161|    182|      return (size_t)(((v >> 7) & UINT64_C(0x0101010101010101)) *
  162|    182|                          UINT64_C(0x0101010101010101) >>
  163|    182|                      56);
  164|    182|    };
  165|   473k|    for (; i + 32 <= length; i += 32) {
  ------------------
  |  Branch (165:12): [True: 473k, False: 182]
  ------------------
  166|   473k|      uint64_t v;
  167|   473k|      memcpy(&v, input + i, 8);
  168|   473k|      answer += pop(v);
  169|   473k|      memcpy(&v, input + i + 8, sizeof(v));
  170|   473k|      answer += pop(v);
  171|   473k|      memcpy(&v, input + i + 16, sizeof(v));
  172|   473k|      answer += pop(v);
  173|   473k|      memcpy(&v, input + i + 24, sizeof(v));
  174|   473k|      answer += pop(v);
  175|   473k|    }
  176|    449|    for (; i + 8 <= length; i += 8) {
  ------------------
  |  Branch (176:12): [True: 267, False: 182]
  ------------------
  177|    267|      uint64_t v;
  178|    267|      memcpy(&v, input + i, sizeof(v));
  179|    267|      answer += pop(v);
  180|    267|    }
  181|    182|  } // !consteval scope
  182|    671|  for (; i + 1 <= length; i += 1) {
  ------------------
  |  Branch (182:10): [True: 489, False: 182]
  ------------------
  183|    489|    answer += static_cast<uint8_t>(input[i]) >> 7;
  184|    489|  }
  185|    182|  return answer;
  186|    182|}
simdutf.cpp:_ZZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf823utf8_length_from_latin1IPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_mENKUlmE_clEm:
  160|  1.89M|    auto pop = [](uint64_t v) {
  161|  1.89M|      return (size_t)(((v >> 7) & UINT64_C(0x0101010101010101)) *
  162|       |                          UINT64_C(0x0101010101010101) >>
  163|  1.89M|                      56);
  164|  1.89M|    };

_ZN7simdutf6scalar5utf1614swap_if_neededILNS_10endiannessE0EEEtt:
   27|  7.00M|template <endianness big_endian> constexpr uint16_t swap_if_needed(uint16_t c) {
   28|  7.00M|  return !match_system(big_endian) ? scalar::u16_swap_bytes(c) : c;
  ------------------
  |  Branch (28:10): [Folded, False: 7.00M]
  ------------------
   29|  7.00M|}

_ZN7simdutf6scalar5utf1614high_surrogateEDs:
  147|    695|simdutf_unused simdutf_really_inline constexpr bool high_surrogate(char16_t c) {
  148|    695|  return (0xd800 <= c && c <= 0xdbff);
  ------------------
  |  Branch (148:11): [True: 91, False: 604]
  |  Branch (148:26): [True: 48, False: 43]
  ------------------
  149|    695|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE0EEEmPKDsm:
   91|    988|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|    988|  size_t counter{0};
   94|  6.96M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 6.96M, False: 988]
  ------------------
   95|  6.96M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|  6.96M|    counter++; // ASCII
   97|  6.96M|    counter += static_cast<size_t>(
   98|  6.96M|        word >
   99|  6.96M|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|  6.96M|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 1.11M, False: 5.84M]
  |  Branch (100:53): [True: 1.02M, False: 89.2k]
  ------------------
  101|  5.93M|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 83.0k, False: 5.85M]
  ------------------
  102|  6.96M|  }
  103|    988|  return counter;
  104|    988|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf819convert_with_errorsILNS_10endiannessE0ELb1EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT1_Esr7simdutf6detailE26index_assignable_from_charIT2_EEENS_11full_resultES8_mS9_m:
  101|    818|                                                    size_t utf8_len = 0) {
  102|    818|  if (check_output && utf8_len == 0) {
  ------------------
  |  Branch (102:7): [True: 818, Folded]
  |  Branch (102:23): [True: 57, False: 761]
  ------------------
  103|     57|    return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, 0, 0);
  104|     57|  }
  105|       |
  106|    761|  size_t pos = 0;
  107|    761|  auto start = utf8_output;
  108|    761|  auto end = utf8_output + utf8_len;
  109|       |
  110|  2.93k|  while (pos < len) {
  ------------------
  |  Branch (110:10): [True: 2.43k, False: 501]
  ------------------
  111|       |#if SIMDUTF_CPLUSPLUS23
  112|       |    if !consteval
  113|       |#endif
  114|  2.43k|    {
  115|       |      // try to convert the next block of 8 bytes
  116|  2.43k|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (116:11): [True: 1.82k, False: 602]
  ------------------
  117|       |                            // they are ascii
  118|  1.82k|        uint64_t v;
  119|  1.82k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
  120|       |        if constexpr (!match_system(big_endian))
  121|       |          v = (v >> 8) | (v << (64 - 8));
  122|  1.82k|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (122:13): [True: 492, False: 1.33k]
  ------------------
  123|    492|          size_t final_pos = pos + 4;
  124|  2.37k|          while (pos < final_pos) {
  ------------------
  |  Branch (124:18): [True: 1.91k, False: 457]
  ------------------
  125|  1.91k|            if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (125:17): [True: 1.91k, Folded]
  |  Branch (125:33): [True: 35, False: 1.88k]
  ------------------
  126|     35|              return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  127|     35|                                 utf8_output - start);
  128|     35|            }
  129|  1.88k|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (129:30): [Folded, False: 1.88k]
  ------------------
  130|  1.88k|                                 ? char(u16_swap_bytes(data[pos]))
  131|  1.88k|                                 : char(data[pos]);
  132|  1.88k|            pos++;
  133|  1.88k|          }
  134|    457|          continue;
  135|    492|        }
  136|  1.82k|      }
  137|  2.43k|    }
  138|       |
  139|  1.93k|    uint16_t word =
  140|  1.93k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (140:9): [Folded, False: 1.93k]
  ------------------
  141|  1.93k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (141:9): [True: 443, False: 1.49k]
  ------------------
  142|       |      // will generate one UTF-8 bytes
  143|    443|      if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (143:11): [True: 443, Folded]
  |  Branch (143:27): [True: 9, False: 434]
  ------------------
  144|      9|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  145|      9|                           utf8_output - start);
  146|      9|      }
  147|    434|      *utf8_output++ = char(word);
  148|    434|      pos++;
  149|  1.49k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (149:16): [True: 306, False: 1.19k]
  ------------------
  150|       |      // will generate two UTF-8 bytes
  151|       |      // we have 0b110XXXXX 0b10XXXXXX
  152|    306|      if (check_output && size_t(end - utf8_output) < 2) {
  ------------------
  |  Branch (152:11): [True: 306, Folded]
  |  Branch (152:27): [True: 14, False: 292]
  ------------------
  153|     14|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  154|     14|                           utf8_output - start);
  155|     14|      }
  156|    292|      *utf8_output++ = char((word >> 6) | 0b11000000);
  157|    292|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  158|    292|      pos++;
  159|       |
  160|  1.19k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (160:16): [True: 979, False: 211]
  ------------------
  161|       |      // will generate three UTF-8 bytes
  162|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
  163|    979|      if (check_output && size_t(end - utf8_output) < 3) {
  ------------------
  |  Branch (163:11): [True: 979, Folded]
  |  Branch (163:27): [True: 72, False: 907]
  ------------------
  164|     72|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  165|     72|                           utf8_output - start);
  166|     72|      }
  167|    907|      *utf8_output++ = char((word >> 12) | 0b11100000);
  168|    907|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  169|    907|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  170|    907|      pos++;
  171|    907|    } else {
  172|       |
  173|    211|      if (check_output && size_t(end - utf8_output) < 4) {
  ------------------
  |  Branch (173:11): [True: 211, Folded]
  |  Branch (173:27): [True: 13, False: 198]
  ------------------
  174|     13|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  175|     13|                           utf8_output - start);
  176|     13|      }
  177|       |      // must be a surrogate pair
  178|    198|      if (pos + 1 >= len) {
  ------------------
  |  Branch (178:11): [True: 57, False: 141]
  ------------------
  179|     57|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  180|     57|      }
  181|    141|      uint16_t diff = uint16_t(word - 0xD800);
  182|    141|      if (diff > 0x3FF) {
  ------------------
  |  Branch (182:11): [True: 14, False: 127]
  ------------------
  183|     14|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  184|     14|      }
  185|    127|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (185:28): [Folded, False: 127]
  ------------------
  186|    127|                               ? u16_swap_bytes(data[pos + 1])
  187|    127|                               : data[pos + 1];
  188|    127|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
  189|    127|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (189:11): [True: 46, False: 81]
  ------------------
  190|     46|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  191|     46|      }
  192|     81|      uint32_t value = (diff << 10) + diff2 + 0x10000;
  193|       |      // will generate four UTF-8 bytes
  194|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
  195|     81|      *utf8_output++ = char((value >> 18) | 0b11110000);
  196|     81|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  197|     81|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  198|     81|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
  199|     81|      pos += 2;
  200|     81|    }
  201|  1.93k|  }
  202|    501|  return full_result(error_code::SUCCESS, pos, utf8_output - start);
  203|    761|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf87convertILNS_10endiannessE0EPKDsPcQsr7simdutf6detailE18indexes_into_utf16IT0_EEEmS8_mT1_:
   17|  1.71k|                                   OutputPtr utf8_output) {
   18|  1.71k|  size_t pos = 0;
   19|  1.71k|  const auto start = utf8_output;
   20|  2.95M|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 2.95M, False: 1.43k]
  ------------------
   21|       |#if SIMDUTF_CPLUSPLUS23
   22|       |    if !consteval
   23|       |#endif
   24|  2.95M|    {
   25|       |      // try to convert the next block of 8 bytes
   26|  2.95M|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (26:11): [True: 2.95M, False: 2.97k]
  ------------------
   27|       |                            // they are ascii
   28|  2.95M|        uint64_t v;
   29|  2.95M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   30|       |        if constexpr (!match_system(big_endian)) {
   31|       |          v = (v >> 8) | (v << (64 - 8));
   32|       |        }
   33|  2.95M|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (33:13): [True: 1.44M, False: 1.50M]
  ------------------
   34|  1.44M|          size_t final_pos = pos + 4;
   35|  7.22M|          while (pos < final_pos) {
  ------------------
  |  Branch (35:18): [True: 5.77M, False: 1.44M]
  ------------------
   36|  5.77M|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (36:30): [Folded, False: 5.77M]
  ------------------
   37|  5.77M|                                 ? char(u16_swap_bytes(data[pos]))
   38|  5.77M|                                 : char(data[pos]);
   39|  5.77M|            pos++;
   40|  5.77M|          }
   41|  1.44M|          continue;
   42|  1.44M|        }
   43|  2.95M|      }
   44|  2.95M|    }
   45|  1.50M|    uint16_t word =
   46|  1.50M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (46:9): [Folded, False: 1.50M]
  ------------------
   47|  1.50M|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (47:9): [True: 18.5k, False: 1.49M]
  ------------------
   48|       |      // will generate one UTF-8 bytes
   49|  18.5k|      *utf8_output++ = char(word);
   50|  18.5k|      pos++;
   51|  1.49M|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (51:16): [True: 291k, False: 1.19M]
  ------------------
   52|       |      // will generate two UTF-8 bytes
   53|       |      // we have 0b110XXXXX 0b10XXXXXX
   54|   291k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   55|   291k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   56|   291k|      pos++;
   57|  1.19M|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (57:16): [True: 1.19M, False: 3.77k]
  ------------------
   58|       |      // will generate three UTF-8 bytes
   59|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   60|  1.19M|      *utf8_output++ = char((word >> 12) | 0b11100000);
   61|  1.19M|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   62|  1.19M|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   63|  1.19M|      pos++;
   64|  1.19M|    } else {
   65|       |      // must be a surrogate pair
   66|  3.77k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (66:11): [True: 85, False: 3.69k]
  ------------------
   67|     85|        return 0;
   68|     85|      }
   69|  3.69k|      uint16_t diff = uint16_t(word - 0xD800);
   70|  3.69k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (70:11): [True: 82, False: 3.61k]
  ------------------
   71|     82|        return 0;
   72|     82|      }
   73|  3.61k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (73:28): [Folded, False: 3.61k]
  ------------------
   74|  3.61k|                               ? u16_swap_bytes(data[pos + 1])
   75|  3.61k|                               : data[pos + 1];
   76|  3.61k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   77|  3.61k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (77:11): [True: 119, False: 3.49k]
  ------------------
   78|    119|        return 0;
   79|    119|      }
   80|  3.49k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   81|       |      // will generate four UTF-8 bytes
   82|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   83|  3.49k|      *utf8_output++ = char((value >> 18) | 0b11110000);
   84|  3.49k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
   85|  3.49k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
   86|  3.49k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
   87|  3.49k|      pos += 2;
   88|  3.49k|    }
   89|  1.50M|  }
   90|  1.43k|  return utf8_output - start;
   91|  1.71k|}

_ZNK7simdutf8fallback14implementation22convert_latin1_to_utf8EPKcmPc:
  128|    492|    const char *buf, size_t len, char *utf8_output) const noexcept {
  129|    492|  return scalar::latin1_to_utf8::convert(buf, len, utf8_output);
  130|    492|}
_ZNK7simdutf8fallback14implementation23convert_utf16le_to_utf8EPKDsmPc:
  268|    630|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  269|    630|  return scalar::utf16_to_utf8::convert<endianness::LITTLE>(buf, len,
  270|    630|                                                            utf8_output);
  271|    630|}
_ZNK7simdutf8fallback14implementation23utf8_length_from_latin1EPKcm:
  445|    182|    const char *input, size_t length) const noexcept {
  446|    182|  return scalar::latin1_to_utf8::utf8_length_from_latin1(input, length);
  447|    182|}
_ZNK7simdutf8fallback14implementation24utf8_length_from_utf16leEPKDsm:
  452|    237|    const char16_t *input, size_t length) const noexcept {
  453|    237|  return scalar::utf16::utf8_length_from_utf16<endianness::LITTLE>(input,
  454|    237|                                                                   length);
  455|    237|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE0EEEmPKDsm:
   10|    391|                                                             size_t size) {
   11|    391|  size_t pos = 0;
   12|       |
   13|    391|  using vector_u16 = simd16<uint16_t>;
   14|    391|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|    391|  const auto one = vector_u16::splat(1);
   17|       |
   18|    391|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|    391|  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|    391|  constexpr size_t max_iterations = 65535 / 2;
   26|    391|  size_t iteration = max_iterations;
   27|       |
   28|   418k|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 418k, False: 391]
  ------------------
   29|   418k|    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|   418k|    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|   418k|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|   418k|    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|   418k|    v_count += c0;
   68|   418k|    v_count += c1;
   69|   418k|    v_count += vector_u16(is_surrogate);
   70|       |
   71|   418k|    iteration -= 1;
   72|   418k|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 4, False: 418k]
  ------------------
   73|      4|      count += v_count.sum();
   74|      4|      v_count = vector_u16::zero();
   75|      4|      iteration = max_iterations;
   76|      4|    }
   77|   418k|  }
   78|       |
   79|    391|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 391, False: 0]
  ------------------
   80|    391|    count += v_count.sum();
   81|    391|  }
   82|       |
   83|    391|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|    391|                                                                   size - pos);
   85|    391|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE0EEEmPKDsm:
   10|    360|                                                             size_t size) {
   11|    360|  size_t pos = 0;
   12|       |
   13|    360|  using vector_u16 = simd16<uint16_t>;
   14|    360|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|    360|  const auto one = vector_u16::splat(1);
   17|       |
   18|    360|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|    360|  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|    360|  constexpr size_t max_iterations = 65535 / 2;
   26|    360|  size_t iteration = max_iterations;
   27|       |
   28|   879k|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 878k, False: 360]
  ------------------
   29|   878k|    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|   878k|    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|   878k|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|   878k|    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|   878k|    v_count += c0;
   68|   878k|    v_count += c1;
   69|   878k|    v_count += vector_u16(is_surrogate);
   70|       |
   71|   878k|    iteration -= 1;
   72|   878k|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 19, False: 878k]
  ------------------
   73|     19|      count += v_count.sum();
   74|     19|      v_count = vector_u16::zero();
   75|     19|      iteration = max_iterations;
   76|     19|    }
   77|   878k|  }
   78|       |
   79|    360|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 360, False: 0]
  ------------------
   80|    360|    count += v_count.sum();
   81|    360|  }
   82|       |
   83|    360|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|    360|                                                                   size - pos);
   85|    360|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_127avx2_convert_latin1_to_utf8EPKcmPc:
    3|    766|                            char *utf8_output) {
    4|    766|  const char *end = latin1_input + len;
    5|    766|  const __m256i v_0000 = _mm256_setzero_si256();
    6|    766|  const __m256i v_c080 = _mm256_set1_epi16((int16_t)0xc080);
    7|    766|  const __m256i v_ff80 = _mm256_set1_epi16((int16_t)0xff80);
    8|    766|  const size_t safety_margin = 12;
    9|       |
   10|  1.40M|  while (end - latin1_input >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (10:10): [True: 1.40M, False: 766]
  ------------------
   11|  1.40M|    __m128i in8 = _mm_loadu_si128((__m128i *)latin1_input);
   12|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
   13|  1.40M|    const __m128i v_80 = _mm_set1_epi8((char)0x80);
   14|  1.40M|    if (_mm_testz_si128(in8, v_80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (14:9): [True: 1.09M, False: 307k]
  ------------------
   15|       |      // 1. store (16 bytes)
   16|  1.09M|      _mm_storeu_si128((__m128i *)utf8_output, in8);
   17|       |      // 2. adjust pointers
   18|  1.09M|      latin1_input += 16;
   19|  1.09M|      utf8_output += 16;
   20|  1.09M|      continue; // we are done for this round!
   21|  1.09M|    }
   22|       |    // We proceed only with the first 16 bytes.
   23|   307k|    const __m256i in = _mm256_cvtepu8_epi16((in8));
   24|       |
   25|       |    // 1. prepare 2-byte values
   26|       |    // input 16-bit word : [0000|0000|aabb|bbbb] x 8
   27|       |    // expected output   : [1100|00aa|10bb|bbbb] x 8
   28|   307k|    const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
   29|   307k|    const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
   30|       |
   31|       |    // t0 = [0000|00aa|bbbb|bb00]
   32|   307k|    const __m256i t0 = _mm256_slli_epi16(in, 2);
   33|       |    // t1 = [0000|00aa|0000|0000]
   34|   307k|    const __m256i t1 = _mm256_and_si256(t0, v_1f00);
   35|       |    // t2 = [0000|0000|00bb|bbbb]
   36|   307k|    const __m256i t2 = _mm256_and_si256(in, v_003f);
   37|       |    // t3 = [000a|aaaa|00bb|bbbb]
   38|   307k|    const __m256i t3 = _mm256_or_si256(t1, t2);
   39|       |    // t4 = [1100|00aa|10bb|bbbb]
   40|   307k|    const __m256i t4 = _mm256_or_si256(t3, v_c080);
   41|       |
   42|       |    // 2. merge ASCII and 2-byte codewords
   43|       |
   44|       |    // no bits set above 7th bit
   45|   307k|    const __m256i one_byte_bytemask =
   46|   307k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_ff80), v_0000);
   47|   307k|    const uint32_t one_byte_bitmask =
   48|   307k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
   49|       |
   50|   307k|    const __m256i utf8_unpacked = _mm256_blendv_epi8(t4, in, one_byte_bytemask);
   51|       |
   52|       |    // 3. prepare bitmask for 8-bit lookup
   53|   307k|    const uint32_t M0 = one_byte_bitmask & 0x55555555;
   54|   307k|    const uint32_t M1 = M0 >> 7;
   55|   307k|    const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
   56|       |    // 4. pack the bytes
   57|       |
   58|   307k|    const uint8_t *row =
   59|   307k|        &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
   60|   307k|    const uint8_t *row_2 =
   61|   307k|        &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >> 16)]
   62|   307k|                                                            [0];
   63|       |
   64|   307k|    const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
   65|   307k|    const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
   66|       |
   67|   307k|    const __m256i utf8_packed = _mm256_shuffle_epi8(
   68|   307k|        utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|   307k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|   307k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
   69|       |    // 5. store bytes
   70|   307k|    _mm_storeu_si128((__m128i *)utf8_output,
   71|   307k|                     _mm256_castsi256_si128(utf8_packed));
   72|   307k|    utf8_output += row[0];
   73|   307k|    _mm_storeu_si128((__m128i *)utf8_output,
   74|   307k|                     _mm256_extractf128_si256(utf8_packed, 1));
   75|   307k|    utf8_output += row_2[0];
   76|       |
   77|       |    // 6. adjust pointers
   78|   307k|    latin1_input += 16;
   79|   307k|    continue;
   80|       |
   81|  1.40M|  } // while
   82|    766|  return std::make_pair(latin1_input, utf8_output);
   83|    766|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_126avx2_convert_utf16_to_utf8ILNS_10endiannessE0EEENSt3__14pairIPKDsPcEES7_mS8_:
   56|    721|avx2_convert_utf16_to_utf8(const char16_t *buf, size_t len, char *utf8_output) {
   57|    721|  const char16_t *end = buf + len;
   58|    721|  const __m256i v_0000 = _mm256_setzero_si256();
   59|    721|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
   60|    721|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
   61|    721|  const __m256i v_c080 = _mm256_set1_epi16((int16_t)0xc080);
   62|    721|  const size_t safety_margin =
   63|    721|      12; // to avoid overruns, see issue
   64|       |          // https://github.com/simdutf/simdutf/issues/92
   65|       |
   66|   194k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (66:10): [True: 193k, False: 575]
  ------------------
   67|   193k|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
   68|   193k|    if (big_endian) {
  ------------------
  |  Branch (68:9): [Folded, False: 193k]
  ------------------
   69|      0|      const __m256i swap = _mm256_setr_epi8(
   70|      0|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   71|      0|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   72|      0|      in = _mm256_shuffle_epi8(in, swap);
   73|      0|    }
   74|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
   75|   193k|    const __m256i v_ff80 = _mm256_set1_epi16((int16_t)0xff80);
   76|   193k|    if (_mm256_testz_si256(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (76:9): [True: 86.2k, False: 107k]
  ------------------
   77|       |      // 1. pack the bytes
   78|  86.2k|      const __m128i utf8_packed = _mm_packus_epi16(
   79|  86.2k|          _mm256_castsi256_si128(in), _mm256_extractf128_si256(in, 1));
   80|       |      // 2. store (16 bytes)
   81|  86.2k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   82|       |      // 3. adjust pointers
   83|  86.2k|      buf += 16;
   84|  86.2k|      utf8_output += 16;
   85|  86.2k|      continue; // we are done for this round!
   86|  86.2k|    }
   87|       |    // no bits set above 7th bit
   88|   107k|    const __m256i one_byte_bytemask =
   89|   107k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_ff80), v_0000);
   90|   107k|    const uint32_t one_byte_bitmask =
   91|   107k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
   92|       |
   93|       |    // no bits set above 11th bit
   94|   107k|    const __m256i one_or_two_bytes_bytemask =
   95|   107k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_0000);
   96|   107k|    const uint32_t one_or_two_bytes_bitmask =
   97|   107k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
   98|   107k|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (98:9): [True: 1.02k, False: 106k]
  ------------------
   99|       |
  100|       |      // 1. prepare 2-byte values
  101|       |      // input 16-bit word : [0000|0aaa|aabb|bbbb] x 8
  102|       |      // expected output   : [110a|aaaa|10bb|bbbb] x 8
  103|  1.02k|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
  104|  1.02k|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
  105|       |
  106|       |      // t0 = [000a|aaaa|bbbb|bb00]
  107|  1.02k|      const __m256i t0 = _mm256_slli_epi16(in, 2);
  108|       |      // t1 = [000a|aaaa|0000|0000]
  109|  1.02k|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
  110|       |      // t2 = [0000|0000|00bb|bbbb]
  111|  1.02k|      const __m256i t2 = _mm256_and_si256(in, v_003f);
  112|       |      // t3 = [000a|aaaa|00bb|bbbb]
  113|  1.02k|      const __m256i t3 = _mm256_or_si256(t1, t2);
  114|       |      // t4 = [110a|aaaa|10bb|bbbb]
  115|  1.02k|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
  116|       |
  117|       |      // 2. merge ASCII and 2-byte codewords
  118|  1.02k|      const __m256i utf8_unpacked =
  119|  1.02k|          _mm256_blendv_epi8(t4, in, one_byte_bytemask);
  120|       |
  121|       |      // 3. prepare bitmask for 8-bit lookup
  122|  1.02k|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
  123|  1.02k|      const uint32_t M1 = M0 >> 7;
  124|  1.02k|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
  125|       |      // 4. pack the bytes
  126|       |
  127|  1.02k|      const uint8_t *row =
  128|  1.02k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
  129|  1.02k|      const uint8_t *row_2 =
  130|  1.02k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
  131|  1.02k|                                                                       16)][0];
  132|       |
  133|  1.02k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  134|  1.02k|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
  135|       |
  136|  1.02k|      const __m256i utf8_packed = _mm256_shuffle_epi8(
  137|  1.02k|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|  1.02k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|  1.02k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  138|       |      // 5. store bytes
  139|  1.02k|      _mm_storeu_si128((__m128i *)utf8_output,
  140|  1.02k|                       _mm256_castsi256_si128(utf8_packed));
  141|  1.02k|      utf8_output += row[0];
  142|  1.02k|      _mm_storeu_si128((__m128i *)utf8_output,
  143|  1.02k|                       _mm256_extractf128_si256(utf8_packed, 1));
  144|  1.02k|      utf8_output += row_2[0];
  145|       |
  146|       |      // 6. adjust pointers
  147|  1.02k|      buf += 16;
  148|  1.02k|      continue;
  149|  1.02k|    }
  150|       |    // 1. Check if there are any surrogate word in the input chunk.
  151|       |    //    We have also deal with situation when there is a surrogate word
  152|       |    //    at the end of a chunk.
  153|   106k|    const __m256i surrogates_bytemask =
  154|   106k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_d800);
  155|       |
  156|       |    // bitmask = 0x0000 if there are no surrogates
  157|       |    //         = 0xc000 if the last word is a surrogate
  158|   106k|    const uint32_t surrogates_bitmask =
  159|   106k|        static_cast<uint32_t>(_mm256_movemask_epi8(surrogates_bytemask));
  160|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  161|       |    // However, it is likely an uncommon occurrence.
  162|   106k|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (162:9): [True: 104k, False: 1.88k]
  ------------------
  163|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  164|   104k|      const __m256i dup_even = _mm256_setr_epi16(
  165|   104k|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  166|   104k|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  167|       |
  168|       |      /* In this branch we handle three cases:
  169|       |         1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  170|       |        single UFT-8 byte
  171|       |         2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              - two
  172|       |        UTF-8 bytes
  173|       |         3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  174|       |        three UTF-8 bytes
  175|       |
  176|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  177|       |        we have room for four bytes. However, we need five distinct bit
  178|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  179|       |
  180|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  181|       |        in register t2.
  182|       |
  183|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  184|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  185|       |        differ by exactly one bit.
  186|       |
  187|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  188|       |        into account the case (i.e, the number of bytes to write).
  189|       |      */
  190|       |      /**
  191|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  192|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  193|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  194|       |       */
  195|   104k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  196|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  197|   104k|      const __m256i t0 = _mm256_shuffle_epi8(in, dup_even);
  198|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  199|   104k|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  195|   104k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  200|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  201|   104k|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  195|   104k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  202|       |
  203|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  204|   104k|      const __m256i s0 = _mm256_srli_epi16(in, 4);
  205|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  206|   104k|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  195|   104k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  207|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  208|   104k|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  195|   104k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  209|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  210|   104k|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  195|   104k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  211|   104k|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  212|   104k|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  195|   104k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  213|   104k|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  214|   104k|#undef simdutf_vec
  215|       |
  216|       |      // 4. expand code units 16-bit => 32-bit
  217|   104k|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  218|   104k|      const __m256i out1 = _mm256_unpackhi_epi16(t2, s4);
  219|       |
  220|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  221|   104k|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  222|   104k|                            (one_or_two_bytes_bitmask & 0xaaaaaaaa);
  223|       |      // Due to the wider registers, the following path is less likely to be
  224|       |      // useful.
  225|       |      /*if(mask == 0) {
  226|       |        // We only have three-byte code units. Use fast path.
  227|       |        const __m256i shuffle =
  228|       |      _mm256_setr_epi8(2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1,
  229|       |      2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1); const __m256i utf8_0 =
  230|       |      _mm256_shuffle_epi8(out0, shuffle); const __m256i utf8_1 =
  231|       |      _mm256_shuffle_epi8(out1, shuffle);
  232|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_0));
  233|       |        utf8_output += 12;
  234|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_1));
  235|       |        utf8_output += 12;
  236|       |        _mm_storeu_si128((__m128i*)utf8_output,
  237|       |      _mm256_extractf128_si256(utf8_0,1)); utf8_output += 12;
  238|       |        _mm_storeu_si128((__m128i*)utf8_output,
  239|       |      _mm256_extractf128_si256(utf8_1,1)); utf8_output += 12; buf += 16;
  240|       |        continue;
  241|       |      }*/
  242|   104k|      const uint8_t mask0 = uint8_t(mask);
  243|   104k|      const uint8_t *row0 =
  244|   104k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  245|   104k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  246|   104k|      const __m128i utf8_0 =
  247|   104k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  248|       |
  249|   104k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  250|   104k|      const uint8_t *row1 =
  251|   104k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  252|   104k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  253|   104k|      const __m128i utf8_1 =
  254|   104k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  255|       |
  256|   104k|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  257|   104k|      const uint8_t *row2 =
  258|   104k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  259|   104k|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  260|   104k|      const __m128i utf8_2 =
  261|   104k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  262|       |
  263|   104k|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  264|   104k|      const uint8_t *row3 =
  265|   104k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  266|   104k|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  267|   104k|      const __m128i utf8_3 =
  268|   104k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  269|       |
  270|   104k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  271|   104k|      utf8_output += row0[0];
  272|   104k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  273|   104k|      utf8_output += row1[0];
  274|   104k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  275|   104k|      utf8_output += row2[0];
  276|   104k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  277|   104k|      utf8_output += row3[0];
  278|   104k|      buf += 16;
  279|       |      // surrogate pair(s) in a register
  280|   104k|    } else {
  281|       |      // Let us do a scalar fallback.
  282|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  283|       |      // in the presence of surrogate pairs may require non-trivial tables.
  284|  1.88k|      size_t forward = 15;
  285|  1.88k|      size_t k = 0;
  286|  1.88k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (286:11): [True: 0, False: 1.88k]
  ------------------
  287|      0|        forward = size_t(end - buf - 1);
  288|      0|      }
  289|  25.1k|      for (; k < forward; k++) {
  ------------------
  |  Branch (289:14): [True: 23.4k, False: 1.74k]
  ------------------
  290|  23.4k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  291|  23.4k|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (291:13): [True: 11.8k, False: 11.5k]
  ------------------
  292|  11.8k|          *utf8_output++ = char(word);
  293|  11.8k|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (293:20): [True: 1.88k, False: 9.63k]
  ------------------
  294|  1.88k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  295|  1.88k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  296|  9.63k|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (296:20): [True: 5.51k, False: 4.12k]
  ------------------
  297|  5.51k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  298|  5.51k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  299|  5.51k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  300|  5.51k|        } else {
  301|       |          // must be a surrogate pair
  302|  4.12k|          uint16_t diff = uint16_t(word - 0xD800);
  303|  4.12k|          uint16_t next_word =
  304|  4.12k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  305|  4.12k|          k++;
  306|  4.12k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  307|  4.12k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (307:15): [True: 146, False: 3.97k]
  ------------------
  308|    146|            return std::make_pair(nullptr, utf8_output);
  309|    146|          }
  310|  3.97k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  311|  3.97k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  312|  3.97k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  313|  3.97k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  314|  3.97k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  315|  3.97k|        }
  316|  23.4k|      }
  317|  1.74k|      buf += k;
  318|  1.74k|    }
  319|   106k|  } // while
  320|    575|  return std::make_pair(buf, utf8_output);
  321|    721|}

_ZNK7simdutf7haswell14implementation22convert_latin1_to_utf8EPKcmPc:
  412|    766|    const char *buf, size_t len, char *utf8_output) const noexcept {
  413|    766|  std::pair<const char *, char *> ret =
  414|    766|      avx2_convert_latin1_to_utf8(buf, len, utf8_output);
  415|    766|  size_t converted_chars = ret.second - utf8_output;
  416|       |
  417|    766|  if (ret.first != buf + len) {
  ------------------
  |  Branch (417:7): [True: 754, False: 12]
  ------------------
  418|    754|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  419|    754|        ret.first, len - (ret.first - buf), ret.second);
  420|    754|    converted_chars += scalar_converted_chars;
  421|    754|  }
  422|       |
  423|    766|  return converted_chars;
  424|    766|}
_ZNK7simdutf7haswell14implementation23convert_utf16le_to_utf8EPKDsmPc:
  679|    721|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  680|    721|  std::pair<const char16_t *, char *> ret =
  681|    721|      haswell::avx2_convert_utf16_to_utf8<endianness::LITTLE>(buf, len,
  682|    721|                                                              utf8_output);
  683|    721|  if (ret.first == nullptr) {
  ------------------
  |  Branch (683:7): [True: 146, False: 575]
  ------------------
  684|    146|    return 0;
  685|    146|  }
  686|    575|  size_t saved_bytes = ret.second - utf8_output;
  687|    575|  if (ret.first != buf + len) {
  ------------------
  |  Branch (687:7): [True: 559, False: 16]
  ------------------
  688|    559|    const size_t scalar_saved_bytes =
  689|    559|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  690|    559|            ret.first, len - (ret.first - buf), ret.second);
  691|    559|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (691:9): [True: 115, False: 444]
  ------------------
  692|    115|      return 0;
  693|    115|    }
  694|    444|    saved_bytes += scalar_saved_bytes;
  695|    444|  }
  696|    460|  return saved_bytes;
  697|    575|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16leEPKDsm:
 1131|    391|    const char16_t *input, size_t length) const noexcept {
 1132|    391|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1133|    391|                                                                    length);
 1134|    391|}
_ZNK7simdutf7haswell14implementation23utf8_length_from_latin1EPKcm:
 1203|    264|    const char *input, size_t len) const noexcept {
 1204|    264|  const uint8_t *data = reinterpret_cast<const uint8_t *>(input);
 1205|    264|  size_t answer = len / sizeof(__m256i) * sizeof(__m256i);
 1206|    264|  size_t i = 0;
 1207|    264|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1207:7): [True: 109, False: 155]
  ------------------
 1208|    109|    __m256i four_64bits = _mm256_setzero_si256();
 1209|  2.74k|    while (i + sizeof(__m256i) <= len) {
  ------------------
  |  Branch (1209:12): [True: 2.63k, False: 109]
  ------------------
 1210|  2.63k|      __m256i runner = _mm256_setzero_si256();
 1211|       |      // We can do up to 255 loops without overflow.
 1212|  2.63k|      size_t iterations = (len - i) / sizeof(__m256i);
 1213|  2.63k|      if (iterations > 255) {
  ------------------
  |  Branch (1213:11): [True: 2.52k, False: 109]
  ------------------
 1214|  2.52k|        iterations = 255;
 1215|  2.52k|      }
 1216|  2.63k|      size_t max_i = i + iterations * sizeof(__m256i) - sizeof(__m256i);
 1217|   164k|      for (; i + 4 * sizeof(__m256i) <= max_i; i += 4 * sizeof(__m256i)) {
  ------------------
  |  Branch (1217:14): [True: 161k, False: 2.63k]
  ------------------
 1218|   161k|        __m256i input1 = _mm256_loadu_si256((const __m256i *)(data + i));
 1219|   161k|        __m256i input2 =
 1220|   161k|            _mm256_loadu_si256((const __m256i *)(data + i + sizeof(__m256i)));
 1221|   161k|        __m256i input3 = _mm256_loadu_si256(
 1222|   161k|            (const __m256i *)(data + i + 2 * sizeof(__m256i)));
 1223|   161k|        __m256i input4 = _mm256_loadu_si256(
 1224|   161k|            (const __m256i *)(data + i + 3 * sizeof(__m256i)));
 1225|   161k|        __m256i input12 =
 1226|   161k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input1),
 1227|   161k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input2));
 1228|   161k|        __m256i input23 =
 1229|   161k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input3),
 1230|   161k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input4));
 1231|   161k|        __m256i input1234 = _mm256_add_epi8(input12, input23);
 1232|   161k|        runner = _mm256_sub_epi8(runner, input1234);
 1233|   161k|      }
 1234|  10.5k|      for (; i <= max_i; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1234:14): [True: 7.86k, False: 2.63k]
  ------------------
 1235|  7.86k|        __m256i input_256_chunk =
 1236|  7.86k|            _mm256_loadu_si256((const __m256i *)(data + i));
 1237|  7.86k|        runner = _mm256_sub_epi8(
 1238|  7.86k|            runner, _mm256_cmpgt_epi8(_mm256_setzero_si256(), input_256_chunk));
 1239|  7.86k|      }
 1240|  2.63k|      four_64bits = _mm256_add_epi64(
 1241|  2.63k|          four_64bits, _mm256_sad_epu8(runner, _mm256_setzero_si256()));
 1242|  2.63k|    }
 1243|    109|    answer += _mm256_extract_epi64(four_64bits, 0) +
 1244|    109|              _mm256_extract_epi64(four_64bits, 1) +
 1245|    109|              _mm256_extract_epi64(four_64bits, 2) +
 1246|    109|              _mm256_extract_epi64(four_64bits, 3);
 1247|    155|  } else if (answer > 0) {
  ------------------
  |  Branch (1247:14): [True: 74, False: 81]
  ------------------
 1248|  1.48k|    for (; i + sizeof(__m256i) <= len; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1248:12): [True: 1.41k, False: 74]
  ------------------
 1249|  1.41k|      __m256i latin = _mm256_loadu_si256((const __m256i *)(data + i));
 1250|  1.41k|      uint32_t non_ascii = _mm256_movemask_epi8(latin);
 1251|  1.41k|      answer += count_ones(non_ascii);
 1252|  1.41k|    }
 1253|     74|  }
 1254|    264|  return answer + scalar::latin1::utf8_length_from_latin1(
 1255|    264|                      reinterpret_cast<const char *>(data + i), len - i);
 1256|    264|}

_ZNK7simdutf14implementation27supported_by_runtime_systemEv:
   64|      4|bool implementation::supported_by_runtime_system() const {
   65|      4|  uint32_t required_instruction_sets = this->required_instruction_sets();
   66|      4|  uint32_t supported_instruction_sets =
   67|      4|      internal::detect_supported_architectures();
   68|      4|  return ((supported_instruction_sets & required_instruction_sets) ==
   69|      4|          required_instruction_sets);
   70|      4|}
_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|}
_ZN7simdutf25get_active_implementationEv:
 1586|  7.46k|get_active_implementation() {
 1587|  7.46k|#if !SIMDUTF_USE_STATIC_INITIALIZATION
 1588|  7.46k|  #if !SIMDUTF_SINGLE_IMPLEMENTATION
 1589|  7.46k|  static const internal::detect_best_supported_implementation_on_first_use
 1590|  7.46k|      detect_best_supported_implementation_on_first_use_singleton;
 1591|  7.46k|  #endif
 1592|  7.46k|  static internal::atomic_ptr<const implementation>
 1593|  7.46k|      active_implementation_instance{
 1594|       |  #if SIMDUTF_SINGLE_IMPLEMENTATION
 1595|       |          internal::get_single_implementation()
 1596|       |  #else
 1597|  7.46k|          &detect_best_supported_implementation_on_first_use_singleton
 1598|  7.46k|  #endif
 1599|  7.46k|      };
 1600|  7.46k|#endif
 1601|  7.46k|  return active_implementation_instance;
 1602|  7.46k|}
_ZN7simdutf22convert_latin1_to_utf8EPKcmPc:
 1668|  2.09k|                                                  char *utf8_output) noexcept {
 1669|  2.09k|  return get_default_implementation()->convert_latin1_to_utf8(buf, len,
 1670|  2.09k|                                                              utf8_output);
 1671|  2.09k|}
_ZN7simdutf21convert_utf16_to_utf8EPKDsmPc:
 1954|  1.97k|                                                 char *utf8_buffer) noexcept {
 1955|       |  #if SIMDUTF_IS_BIG_ENDIAN
 1956|       |  return convert_utf16be_to_utf8(buf, len, utf8_buffer);
 1957|       |  #else
 1958|  1.97k|  return convert_utf16le_to_utf8(buf, len, utf8_buffer);
 1959|  1.97k|  #endif
 1960|  1.97k|}
_ZN7simdutf26convert_utf16_to_utf8_safeEPKDsmPcm:
 1964|    988|                           size_t utf8_len) noexcept {
 1965|    988|  const auto start{utf8_output};
 1966|       |  // We might be able to go faster by first scanning the input buffer to
 1967|       |  // determine how many char16_t characters we can read without exceeding the
 1968|       |  // utf8_len. This is a one-pass algorithm that has the benefit of not
 1969|       |  // requiring a first pass to determine the length.
 1970|  1.80k|  while (true) {
  ------------------
  |  Branch (1970:10): [True: 1.80k, Folded]
  ------------------
 1971|       |    // The worst case for convert_utf16_to_utf8 is when you go from 1 char16_t
 1972|       |    // to 3 characters of UTF-8. So we can read at most utf8_len / 3 char16_t
 1973|       |    // characters.
 1974|  1.80k|    auto read_len = detail::min(len, utf8_len / 3);
 1975|  1.80k|    if (read_len <= 16) {
  ------------------
  |  Branch (1975:9): [True: 818, False: 988]
  ------------------
 1976|    818|      break;
 1977|    818|    }
 1978|    988|    if (read_len < len) {
  ------------------
  |  Branch (1978:9): [True: 695, False: 293]
  ------------------
 1979|       |      //  If we have a high surrogate at the end of the buffer, we need to
 1980|       |      //  either read one more char16_t or backtrack.
 1981|    695|      if (scalar::utf16::high_surrogate(buf[read_len - 1])) {
  ------------------
  |  Branch (1981:11): [True: 48, False: 647]
  ------------------
 1982|     48|        read_len--;
 1983|     48|      }
 1984|    695|    }
 1985|    988|    if (read_len == 0) {
  ------------------
  |  Branch (1985:9): [True: 0, False: 988]
  ------------------
 1986|       |      // If we cannot read anything, we are done.
 1987|      0|      break;
 1988|      0|    }
 1989|    988|    const auto write_len =
 1990|    988|        simdutf::convert_utf16_to_utf8(buf, read_len, utf8_output);
 1991|    988|    if (write_len == 0) {
  ------------------
  |  Branch (1991:9): [True: 170, False: 818]
  ------------------
 1992|       |      // There was an error in the conversion, we cannot continue.
 1993|    170|      return 0; // indicating failure
 1994|    170|    }
 1995|       |
 1996|    818|    utf8_output += write_len;
 1997|    818|    utf8_len -= write_len;
 1998|    818|    buf += read_len;
 1999|    818|    len -= read_len;
 2000|    818|  }
 2001|       |  #if SIMDUTF_IS_BIG_ENDIAN
 2002|       |  full_result r =
 2003|       |      scalar::utf16_to_utf8::convert_with_errors<endianness::BIG, true>(
 2004|       |          buf, len, utf8_output, utf8_len);
 2005|       |  #else
 2006|    818|  full_result r =
 2007|    818|      scalar::utf16_to_utf8::convert_with_errors<endianness::LITTLE, true>(
 2008|    818|          buf, len, utf8_output, utf8_len);
 2009|    818|  #endif
 2010|    818|  if (r.error != error_code::SUCCESS &&
  ------------------
  |  Branch (2010:7): [True: 317, False: 501]
  ------------------
 2011|    317|      r.error != error_code::OUTPUT_BUFFER_TOO_SMALL) {
  ------------------
  |  Branch (2011:7): [True: 117, False: 200]
  ------------------
 2012|       |    // If there was an error, we return 0 to indicate failure.
 2013|    117|    return 0; // indicating failure
 2014|    117|  }
 2015|    701|  return r.output_count + (utf8_output - start);
 2016|    818|}
_ZN7simdutf23convert_utf16le_to_utf8EPKDsmPc:
 2074|  1.97k|                                                   char *utf8_buffer) noexcept {
 2075|  1.97k|  return get_default_implementation()->convert_utf16le_to_utf8(buf, len,
 2076|  1.97k|                                                               utf8_buffer);
 2077|  1.97k|}
_ZN7simdutf23utf8_length_from_latin1EPKcm:
 2340|    710|                                                   size_t len) noexcept {
 2341|    710|  return get_default_implementation()->utf8_length_from_latin1(buf, len);
 2342|    710|}
_ZN7simdutf22utf8_length_from_utf16EPKDsm:
 2347|    988|                                                  size_t length) noexcept {
 2348|       |  #if SIMDUTF_IS_BIG_ENDIAN
 2349|       |  return utf8_length_from_utf16be(input, length);
 2350|       |  #else
 2351|    988|  return utf8_length_from_utf16le(input, length);
 2352|    988|  #endif
 2353|    988|}
_ZN7simdutf24utf8_length_from_utf16leEPKDsm:
 2363|    988|                                                    size_t length) noexcept {
 2364|    988|  return get_default_implementation()->utf8_length_from_utf16le(input, length);
 2365|    988|}
_ZN7simdutf27convert_latin1_to_utf8_safeEPKcmPcm:
 2568|    710|    const char *buf, size_t len, char *utf8_output, size_t utf8_len) noexcept {
 2569|    710|  const auto start{utf8_output};
 2570|       |
 2571|  2.09k|  while (true) {
  ------------------
  |  Branch (2571:10): [True: 2.09k, Folded]
  ------------------
 2572|       |    // convert_latin1_to_utf8 will never write more than input length * 2
 2573|  2.09k|    auto read_len = detail::min(len, utf8_len >> 1);
 2574|  2.09k|    if (read_len <= 16) {
  ------------------
  |  Branch (2574:9): [True: 710, False: 1.38k]
  ------------------
 2575|    710|      break;
 2576|    710|    }
 2577|       |
 2578|  1.38k|    const auto write_len =
 2579|  1.38k|        simdutf::convert_latin1_to_utf8(buf, read_len, utf8_output);
 2580|       |
 2581|  1.38k|    utf8_output += write_len;
 2582|  1.38k|    utf8_len -= write_len;
 2583|  1.38k|    buf += read_len;
 2584|  1.38k|    len -= read_len;
 2585|  1.38k|  }
 2586|       |
 2587|    710|  utf8_output +=
 2588|    710|      scalar::latin1_to_utf8::convert_safe(buf, len, utf8_output, utf8_len);
 2589|       |
 2590|    710|  return utf8_output - start;
 2591|    710|}
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|}
_ZN7simdutf8internal49detect_best_supported_implementation_on_first_useC2Ev:
  887|      1|      : implementation("best_supported_detector",
  888|      1|                       "Detects the best supported implementation and sets it",
  889|      1|                       0) {}
_ZN7simdutf26get_default_implementationEv:
 1610|  5.76k|get_default_implementation() {
 1611|  5.76k|  return get_active_implementation();
 1612|  5.76k|}

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_110count_onesEm:
   14|  1.41k|simdutf_really_inline long long int count_ones(uint64_t input_num) {
   15|       |  return _popcnt64(input_num);
   16|  1.41k|}

_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_14simd4baseINS2_6simd16ItEEEC2EDv4_x:
   17|  5.85M|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEcvRKDv4_xEv:
   19|  5.85M|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEC2EDv4_x:
   17|   418k|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEcvRKDv4_xEv:
   19|   418k|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEanES5_:
   53|  1.25M|  simdutf_really_inline Child operator&(const Child other) const {
   54|  1.25M|    return _mm256_and_si256(*this, other);
   55|  1.25M|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2EDv4_x:
   97|  5.85M|      : base16_numeric<uint16_t>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEC2EDv4_x:
   73|  5.85M|      : base16<T>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6base16ItNS2_6simd16IbEEEC2EDv4_x:
   20|  5.85M|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE4loadEPKt:
   66|   418k|  static simdutf_really_inline simd16<T> load(const T values[8]) {
   67|   418k|    return _mm256_loadu_si256(reinterpret_cast<const __m256i *>(values));
   68|   418k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE5splatEt:
   58|  1.67M|  static simdutf_really_inline simd16<T> splat(T _value) {
   59|  1.67M|    return _mm256_set1_epi16(_value);
   60|  1.67M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdeqENS2_6simd16ItEES4_:
   26|   418k|                                               const simd16<T> rhs) {
   27|   418k|    return _mm256_cmpeq_epi16(lhs, rhs);
   28|   418k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16IbEC2EDv4_x:
   45|   418k|  simdutf_really_inline simd16(const __m256i _value) : base16<bool>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6base16IbNS2_6simd16IbEEEC2EDv4_x:
   20|   418k|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2Et:
  100|  1.67M|  simdutf_really_inline simd16(uint16_t _value) : simd16(splat(_value)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE4zeroEv:
   62|    395|  static simdutf_really_inline simd16<T> zero() {
   63|    395|    return _mm256_setzero_si256();
   64|    395|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd3minENS2_6simd16ItEES4_:
  259|   836k|simd16<uint16_t> min(const simd16<uint16_t> a, simd16<uint16_t> b) {
  260|   836k|  return _mm256_min_epu16(a.value, b.value);
  261|   836k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEpLENS2_6simd16ItEE:
   87|  1.25M|  simdutf_really_inline simd16<T> &operator+=(const simd16<T> other) {
   88|  1.25M|    *this = *this + other;
   89|  1.25M|    return *static_cast<simd16<T> *>(this);
   90|  1.25M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEplENS2_6simd16ItEE:
   84|  1.25M|  simdutf_really_inline simd16<T> operator+(const simd16<T> other) const {
   85|  1.25M|    return _mm256_add_epi16(*this, other);
   86|  1.25M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE3sumEv:
  170|    395|  simdutf_really_inline uint64_t sum() const {
  171|    395|    const auto lo_u16 = _mm256_and_si256(value, _mm256_set1_epi32(0x0000ffff));
  172|    395|    const auto hi_u16 = _mm256_srli_epi32(value, 16);
  173|    395|    const auto sum_u32 = _mm256_add_epi32(lo_u16, hi_u16);
  174|       |
  175|    395|    const auto lo_u32 =
  176|    395|        _mm256_and_si256(sum_u32, _mm256_set1_epi64x(0xffffffff));
  177|    395|    const auto hi_u32 = _mm256_srli_epi64(sum_u32, 32);
  178|    395|    const auto sum_u64 = _mm256_add_epi64(lo_u32, hi_u32);
  179|       |
  180|    395|    return uint64_t(_mm256_extract_epi64(sum_u64, 0)) +
  181|    395|           uint64_t(_mm256_extract_epi64(sum_u64, 1)) +
  182|    395|           uint64_t(_mm256_extract_epi64(sum_u64, 2)) +
  183|       |           uint64_t(_mm256_extract_epi64(sum_u64, 3));
  184|    395|  }

_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) {}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_110count_onesEm:
   14|  2.55k|simdutf_really_inline long long int count_ones(uint64_t input_num) {
   15|       |  return _popcnt64(input_num);
   16|  2.55k|}

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

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEC2EDv2_x:
   16|  12.3M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEcvRKDv2_xEv:
   18|  12.3M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEC2EDv2_x:
   16|   878k|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEcvRKDv2_xEv:
   18|   878k|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEanES5_:
   45|  2.63M|  simdutf_really_inline Child operator&(const Child other) const {
   46|  2.63M|    return _mm_and_si128(*this, other);
   47|  2.63M|  }

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16ItEC2EDv2_x:
   79|  12.3M|      : base16_numeric<uint16_t>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItEC2EDv2_x:
   54|  12.3M|      : base16<T>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6base16ItNS2_6simd16IbEEEC2EDv2_x:
    8|  12.3M|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItE4loadEPKt:
   47|   878k|  static simdutf_really_inline simd16<T> load(const T values[8]) {
   48|   878k|    return _mm_loadu_si128(reinterpret_cast<const __m128i *>(values));
   49|   878k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItE5splatEt:
   41|  3.51M|  static simdutf_really_inline simd16<T> splat(T _value) {
   42|  3.51M|    return _mm_set1_epi16(_value);
   43|  3.51M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdeqENS2_6simd16ItEES4_:
   11|   878k|                                               const simd16<T> rhs) {
   12|   878k|    return _mm_cmpeq_epi16(lhs, rhs);
   13|   878k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16IbEC2EDv2_x:
   28|   878k|  simdutf_really_inline simd16(const __m128i _value) : base16<bool>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6base16IbNS2_6simd16IbEEEC2EDv2_x:
    8|   878k|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16ItEC2Et:
   82|  3.51M|  simdutf_really_inline simd16(uint16_t _value) : simd16(splat(_value)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItE4zeroEv:
   45|    379|  static simdutf_really_inline simd16<T> zero() { return _mm_setzero_si128(); }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd3minENS2_6simd16ItEES4_:
  240|  1.75M|simd16<uint16_t> min(const simd16<uint16_t> a, simd16<uint16_t> b) {
  241|  1.75M|  return _mm_min_epu16(a.value, b.value);
  242|  1.75M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItEpLENS2_6simd16ItEE:
   68|  2.63M|  simdutf_really_inline simd16<T> &operator+=(const simd16<T> other) {
   69|  2.63M|    *this = *this + other;
   70|  2.63M|    return *static_cast<simd16<T> *>(this);
   71|  2.63M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItEplENS2_6simd16ItEE:
   65|  2.63M|  simdutf_really_inline simd16<T> operator+(const simd16<T> other) const {
   66|  2.63M|    return _mm_add_epi16(*this, other);
   67|  2.63M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16ItE3sumEv:
  134|    379|  simdutf_really_inline uint64_t sum() const {
  135|    379|    const auto lo_u16 = _mm_and_si128(value, _mm_set1_epi32(0x0000ffff));
  136|    379|    const auto hi_u16 = _mm_srli_epi32(value, 16);
  137|    379|    const auto sum_u32 = _mm_add_epi32(lo_u16, hi_u16);
  138|       |
  139|    379|    const auto lo_u32 = _mm_and_si128(sum_u32, _mm_set1_epi64x(0xffffffff));
  140|    379|    const auto hi_u32 = _mm_srli_epi64(sum_u32, 32);
  141|    379|    const auto sum_u64 = _mm_add_epi64(lo_u32, hi_u32);
  142|       |
  143|    379|    return uint64_t(_mm_extract_epi64(sum_u64, 0)) +
  144|       |           uint64_t(_mm_extract_epi64(sum_u64, 1));
  145|    379|  }

_ZNK7simdutf8westmere14implementation22convert_latin1_to_utf8EPKcmPc:
  441|    837|    const char *buf, size_t len, char *utf8_output) const noexcept {
  442|       |
  443|    837|  std::pair<const char *, char *> ret =
  444|    837|      sse_convert_latin1_to_utf8(buf, len, utf8_output);
  445|    837|  size_t converted_chars = ret.second - utf8_output;
  446|       |
  447|    837|  if (ret.first != buf + len) {
  ------------------
  |  Branch (447:7): [True: 704, False: 133]
  ------------------
  448|    704|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  449|    704|        ret.first, len - (ret.first - buf), ret.second);
  450|    704|    converted_chars += scalar_converted_chars;
  451|    704|  }
  452|       |
  453|    837|  return converted_chars;
  454|    837|}
_ZNK7simdutf8westmere14implementation23convert_utf16le_to_utf8EPKDsmPc:
  709|    625|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  710|    625|  std::pair<const char16_t *, char *> ret =
  711|    625|      sse_convert_utf16_to_utf8<endianness::LITTLE>(buf, len, utf8_output);
  712|    625|  if (ret.first == nullptr) {
  ------------------
  |  Branch (712:7): [True: 89, False: 536]
  ------------------
  713|     89|    return 0;
  714|     89|  }
  715|    536|  size_t saved_bytes = ret.second - utf8_output;
  716|    536|  if (ret.first != buf + len) {
  ------------------
  |  Branch (716:7): [True: 528, False: 8]
  ------------------
  717|    528|    const size_t scalar_saved_bytes =
  718|    528|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  719|    528|            ret.first, len - (ret.first - buf), ret.second);
  720|    528|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (720:9): [True: 102, False: 426]
  ------------------
  721|    102|      return 0;
  722|    102|    }
  723|    426|    saved_bytes += scalar_saved_bytes;
  724|    426|  }
  725|    434|  return saved_bytes;
  726|    536|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16leEPKDsm:
 1158|    360|    const char16_t *input, size_t length) const noexcept {
 1159|    360|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1160|    360|                                                                    length);
 1161|    360|}
_ZNK7simdutf8westmere14implementation23utf8_length_from_latin1EPKcm:
 1171|    264|    const char *input, size_t len) const noexcept {
 1172|    264|  const uint8_t *str = reinterpret_cast<const uint8_t *>(input);
 1173|    264|  size_t answer = len / sizeof(__m128i) * sizeof(__m128i);
 1174|    264|  size_t i = 0;
 1175|    264|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1175:7): [True: 124, False: 140]
  ------------------
 1176|    124|    __m128i two_64bits = _mm_setzero_si128();
 1177|  5.30k|    while (i + sizeof(__m128i) <= len) {
  ------------------
  |  Branch (1177:12): [True: 5.18k, False: 124]
  ------------------
 1178|  5.18k|      __m128i runner = _mm_setzero_si128();
 1179|  5.18k|      size_t iterations = (len - i) / sizeof(__m128i);
 1180|  5.18k|      if (iterations > 255) {
  ------------------
  |  Branch (1180:11): [True: 5.06k, False: 124]
  ------------------
 1181|  5.06k|        iterations = 255;
 1182|  5.06k|      }
 1183|  5.18k|      size_t max_i = i + iterations * sizeof(__m128i) - sizeof(__m128i);
 1184|   327k|      for (; i + 4 * sizeof(__m128i) <= max_i; i += 4 * sizeof(__m128i)) {
  ------------------
  |  Branch (1184:14): [True: 322k, False: 5.18k]
  ------------------
 1185|   322k|        __m128i input1 = _mm_loadu_si128((const __m128i *)(str + i));
 1186|   322k|        __m128i input2 =
 1187|   322k|            _mm_loadu_si128((const __m128i *)(str + i + sizeof(__m128i)));
 1188|   322k|        __m128i input3 =
 1189|   322k|            _mm_loadu_si128((const __m128i *)(str + i + 2 * sizeof(__m128i)));
 1190|   322k|        __m128i input4 =
 1191|   322k|            _mm_loadu_si128((const __m128i *)(str + i + 3 * sizeof(__m128i)));
 1192|   322k|        __m128i input12 =
 1193|   322k|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input1),
 1194|   322k|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input2));
 1195|   322k|        __m128i input34 =
 1196|   322k|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input3),
 1197|   322k|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input4));
 1198|   322k|        __m128i input1234 = _mm_add_epi8(input12, input34);
 1199|   322k|        runner = _mm_sub_epi8(runner, input1234);
 1200|   322k|      }
 1201|  20.6k|      for (; i <= max_i; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1201:14): [True: 15.4k, False: 5.18k]
  ------------------
 1202|  15.4k|        __m128i more_input = _mm_loadu_si128((const __m128i *)(str + i));
 1203|  15.4k|        runner = _mm_sub_epi8(runner,
 1204|  15.4k|                              _mm_cmpgt_epi8(_mm_setzero_si128(), more_input));
 1205|  15.4k|      }
 1206|  5.18k|      two_64bits =
 1207|  5.18k|          _mm_add_epi64(two_64bits, _mm_sad_epu8(runner, _mm_setzero_si128()));
 1208|  5.18k|    }
 1209|    124|    answer +=
 1210|    124|        _mm_extract_epi64(two_64bits, 0) + _mm_extract_epi64(two_64bits, 1);
 1211|    140|  } else if (answer > 0) { // short string optimization
  ------------------
  |  Branch (1211:14): [True: 100, False: 40]
  ------------------
 1212|  1.35k|    for (; i + 2 * sizeof(__m128i) <= len; i += 2 * sizeof(__m128i)) {
  ------------------
  |  Branch (1212:12): [True: 1.25k, False: 100]
  ------------------
 1213|  1.25k|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1214|  1.25k|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1215|  1.25k|      answer += count_ones(non_ascii);
 1216|  1.25k|      latin = _mm_loadu_si128((const __m128i *)(input + i) + 1);
 1217|  1.25k|      non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1218|  1.25k|      answer += count_ones(non_ascii);
 1219|  1.25k|    }
 1220|    152|    for (; i + sizeof(__m128i) <= len; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1220:12): [True: 52, False: 100]
  ------------------
 1221|     52|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1222|     52|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1223|     52|      answer += count_ones(non_ascii);
 1224|     52|    }
 1225|    100|  }
 1226|    264|  return answer + scalar::latin1::utf8_length_from_latin1(
 1227|    264|                      reinterpret_cast<const char *>(str + i), len - i);
 1228|    264|}

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

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_126sse_convert_latin1_to_utf8EPKcmPc:
    3|    837|                           const size_t latin_input_length, char *utf8_output) {
    4|    837|  const char *end = latin_input + latin_input_length;
    5|       |
    6|    837|  const __m128i v_0000 = _mm_setzero_si128();
    7|       |  // 0b1000_0000
    8|    837|  const __m128i v_80 = _mm_set1_epi8((uint8_t)0x80);
    9|       |  // 0b1111_1111_1000_0000
   10|    837|  const __m128i v_ff80 = _mm_set1_epi16((uint16_t)0xff80);
   11|       |
   12|    837|  const __m128i latin_1_half_into_u16_byte_mask =
   13|    837|      _mm_setr_epi8(0, '\x80', 1, '\x80', 2, '\x80', 3, '\x80', 4, '\x80', 5,
   14|    837|                    '\x80', 6, '\x80', 7, '\x80');
   15|       |
   16|    837|  const __m128i latin_2_half_into_u16_byte_mask =
   17|    837|      _mm_setr_epi8(8, '\x80', 9, '\x80', 10, '\x80', 11, '\x80', 12, '\x80',
   18|    837|                    13, '\x80', 14, '\x80', 15, '\x80');
   19|       |
   20|       |  // each latin1 takes 1-2 utf8 bytes
   21|       |  // slow path writes useful 8-15 bytes twice (eagerly writes 16 bytes and then
   22|       |  // adjust the pointer) so the last write can exceed the utf8_output size by
   23|       |  // 8-1 bytes by reserving 8 extra input bytes, we expect the output to have
   24|       |  // 8-16 bytes free
   25|  1.42M|  while (end - latin_input >= 16 + 8) {
  ------------------
  |  Branch (25:10): [True: 1.42M, False: 837]
  ------------------
   26|       |    // Load 16 Latin1 characters (16 bytes) into a 128-bit register
   27|  1.42M|    __m128i v_latin = _mm_loadu_si128((__m128i *)latin_input);
   28|       |
   29|  1.42M|    if (_mm_testz_si128(v_latin, v_80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (29:9): [True: 705k, False: 714k]
  ------------------
   30|   705k|      _mm_storeu_si128((__m128i *)utf8_output, v_latin);
   31|   705k|      latin_input += 16;
   32|   705k|      utf8_output += 16;
   33|   705k|      continue;
   34|   705k|    }
   35|       |
   36|       |    // assuming a/b are bytes and A/B are uint16 of the same value
   37|       |    // aaaa_aaaa_bbbb_bbbb -> AAAA_AAAA
   38|   714k|    __m128i v_u16_latin_1_half =
   39|   714k|        _mm_shuffle_epi8(v_latin, latin_1_half_into_u16_byte_mask);
   40|       |    // aaaa_aaaa_bbbb_bbbb -> BBBB_BBBB
   41|   714k|    __m128i v_u16_latin_2_half =
   42|   714k|        _mm_shuffle_epi8(v_latin, latin_2_half_into_u16_byte_mask);
   43|       |
   44|   714k|    internal::westmere::write_v_u16_11bits_to_utf8(v_u16_latin_1_half,
   45|   714k|                                                   utf8_output, v_0000, v_ff80);
   46|   714k|    internal::westmere::write_v_u16_11bits_to_utf8(v_u16_latin_2_half,
   47|   714k|                                                   utf8_output, v_0000, v_ff80);
   48|   714k|    latin_input += 16;
   49|   714k|  }
   50|       |
   51|    837|  if (end - latin_input >= 16) {
  ------------------
  |  Branch (51:7): [True: 429, False: 408]
  ------------------
   52|       |    // Load 16 Latin1 characters (16 bytes) into a 128-bit register
   53|    429|    __m128i v_latin = _mm_loadu_si128((__m128i *)latin_input);
   54|       |
   55|    429|    if (_mm_testz_si128(v_latin, v_80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (55:9): [True: 237, False: 192]
  ------------------
   56|    237|      _mm_storeu_si128((__m128i *)utf8_output, v_latin);
   57|    237|      latin_input += 16;
   58|    237|      utf8_output += 16;
   59|    237|    } else {
   60|       |      // assuming a/b are bytes and A/B are uint16 of the same value
   61|       |      // aaaa_aaaa_bbbb_bbbb -> AAAA_AAAA
   62|    192|      __m128i v_u16_latin_1_half =
   63|    192|          _mm_shuffle_epi8(v_latin, latin_1_half_into_u16_byte_mask);
   64|    192|      internal::westmere::write_v_u16_11bits_to_utf8(
   65|    192|          v_u16_latin_1_half, utf8_output, v_0000, v_ff80);
   66|    192|      latin_input += 8;
   67|    192|    }
   68|    429|  }
   69|       |
   70|    837|  return std::make_pair(latin_input, utf8_output);
   71|    837|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_125sse_convert_utf16_to_utf8ILNS_10endiannessE0EEENSt3__14pairIPKDsPcEES7_mS8_:
   56|    625|sse_convert_utf16_to_utf8(const char16_t *buf, size_t len, char *utf8_output) {
   57|       |
   58|    625|  const char16_t *end = buf + len;
   59|       |
   60|    625|  const __m128i v_0000 = _mm_setzero_si128();
   61|    625|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
   62|    625|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
   63|    625|  const size_t safety_margin =
   64|    625|      12; // to avoid overruns, see issue
   65|       |          // https://github.com/simdutf/simdutf/issues/92
   66|       |
   67|   468k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (67:10): [True: 467k, False: 536]
  ------------------
   68|   467k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
   69|   467k|    if (big_endian) {
  ------------------
  |  Branch (69:9): [Folded, False: 467k]
  ------------------
   70|      0|      const __m128i swap =
   71|      0|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   72|      0|      in = _mm_shuffle_epi8(in, swap);
   73|      0|    }
   74|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
   75|   467k|    const __m128i v_ff80 = _mm_set1_epi16((int16_t)0xff80);
   76|   467k|    if (_mm_testz_si128(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (76:9): [True: 109k, False: 357k]
  ------------------
   77|   109k|      __m128i nextin = _mm_loadu_si128((__m128i *)buf + 1);
   78|   109k|      if (big_endian) {
  ------------------
  |  Branch (78:11): [Folded, False: 109k]
  ------------------
   79|      0|        const __m128i swap =
   80|      0|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   81|      0|        nextin = _mm_shuffle_epi8(nextin, swap);
   82|      0|      }
   83|   109k|      if (!_mm_testz_si128(nextin, v_ff80)) {
  ------------------
  |  Branch (83:11): [True: 1.20k, False: 108k]
  ------------------
   84|       |        // 1. pack the bytes
   85|       |        // obviously suboptimal.
   86|  1.20k|        const __m128i utf8_packed = _mm_packus_epi16(in, in);
   87|       |        // 2. store (16 bytes)
   88|  1.20k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   89|       |        // 3. adjust pointers
   90|  1.20k|        buf += 8;
   91|  1.20k|        utf8_output += 8;
   92|  1.20k|        in = nextin;
   93|   108k|      } else {
   94|       |        // 1. pack the bytes
   95|       |        // obviously suboptimal.
   96|   108k|        const __m128i utf8_packed = _mm_packus_epi16(in, nextin);
   97|       |        // 2. store (16 bytes)
   98|   108k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   99|       |        // 3. adjust pointers
  100|   108k|        buf += 16;
  101|   108k|        utf8_output += 16;
  102|   108k|        continue; // we are done for this round!
  103|   108k|      }
  104|   109k|    }
  105|       |
  106|       |    // no bits set above 7th bit
  107|   359k|    const __m128i one_byte_bytemask =
  108|   359k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_ff80), v_0000);
  109|   359k|    const uint16_t one_byte_bitmask =
  110|   359k|        static_cast<uint16_t>(_mm_movemask_epi8(one_byte_bytemask));
  111|       |
  112|       |    // no bits set above 11th bit
  113|   359k|    const __m128i one_or_two_bytes_bytemask =
  114|   359k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_0000);
  115|   359k|    const uint16_t one_or_two_bytes_bitmask =
  116|   359k|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  117|       |
  118|   359k|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (118:9): [True: 68.7k, False: 290k]
  ------------------
  119|  68.7k|      internal::westmere::write_v_u16_11bits_to_utf8(
  120|  68.7k|          in, utf8_output, one_byte_bytemask, one_byte_bitmask);
  121|  68.7k|      buf += 8;
  122|  68.7k|      continue;
  123|  68.7k|    }
  124|       |
  125|       |    // 1. Check if there are any surrogate word in the input chunk.
  126|       |    //    We have also deal with situation when there is a surrogate word
  127|       |    //    at the end of a chunk.
  128|   290k|    const __m128i surrogates_bytemask =
  129|   290k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_d800);
  130|       |
  131|       |    // bitmask = 0x0000 if there are no surrogates
  132|       |    //         = 0xc000 if the last word is a surrogate
  133|   290k|    const uint16_t surrogates_bitmask =
  134|   290k|        static_cast<uint16_t>(_mm_movemask_epi8(surrogates_bytemask));
  135|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  136|       |    // However, it is likely an uncommon occurrence.
  137|   290k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (137:9): [True: 289k, False: 689]
  ------------------
  138|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  139|   289k|      const __m128i dup_even = _mm_setr_epi16(0x0000, 0x0202, 0x0404, 0x0606,
  140|   289k|                                              0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  141|       |
  142|       |      /* In this branch we handle three cases:
  143|       |         1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  144|       |        single UFT-8 byte
  145|       |         2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              - two
  146|       |        UTF-8 bytes
  147|       |         3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  148|       |        three UTF-8 bytes
  149|       |
  150|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  151|       |        we have room for four bytes. However, we need five distinct bit
  152|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  153|       |
  154|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  155|       |        in register t2.
  156|       |
  157|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  158|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  159|       |        differ by exactly one bit.
  160|       |
  161|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  162|       |        into account the case (i.e, the number of bytes to write).
  163|       |      */
  164|       |      /**
  165|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  166|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  167|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  168|       |       */
  169|   289k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  170|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  171|   289k|      const __m128i t0 = _mm_shuffle_epi8(in, dup_even);
  172|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  173|   289k|      const __m128i t1 = _mm_and_si128(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  169|   289k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  174|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  175|   289k|      const __m128i t2 = _mm_or_si128(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  169|   289k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  176|       |
  177|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  178|   289k|      const __m128i s0 = _mm_srli_epi16(in, 4);
  179|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  180|   289k|      const __m128i s1 = _mm_and_si128(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  169|   289k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  181|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  182|   289k|      const __m128i s2 = _mm_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  169|   289k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  183|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  184|   289k|      const __m128i s3 = _mm_or_si128(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  169|   289k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  185|   289k|      const __m128i m0 = _mm_andnot_si128(one_or_two_bytes_bytemask,
  186|   289k|                                          simdutf_vec(0b0100000000000000));
  ------------------
  |  |  169|   289k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  187|   289k|      const __m128i s4 = _mm_xor_si128(s3, m0);
  188|   289k|#undef simdutf_vec
  189|       |
  190|       |      // 4. expand code units 16-bit => 32-bit
  191|   289k|      const __m128i out0 = _mm_unpacklo_epi16(t2, s4);
  192|   289k|      const __m128i out1 = _mm_unpackhi_epi16(t2, s4);
  193|       |
  194|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  195|   289k|      const uint16_t mask =
  196|   289k|          (one_byte_bitmask & 0x5555) | (one_or_two_bytes_bitmask & 0xaaaa);
  197|   289k|      if (mask == 0) {
  ------------------
  |  Branch (197:11): [True: 283k, False: 6.63k]
  ------------------
  198|       |        // We only have three-byte code units. Use fast path.
  199|   283k|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  200|   283k|                                              15, 13, -1, -1, -1, -1);
  201|   283k|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  202|   283k|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  203|   283k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  204|   283k|        utf8_output += 12;
  205|   283k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  206|   283k|        utf8_output += 12;
  207|   283k|        buf += 8;
  208|   283k|        continue;
  209|   283k|      }
  210|  6.63k|      const uint8_t mask0 = uint8_t(mask);
  211|       |
  212|  6.63k|      const uint8_t *row0 =
  213|  6.63k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  214|  6.63k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  215|  6.63k|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  216|       |
  217|  6.63k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  218|       |
  219|  6.63k|      const uint8_t *row1 =
  220|  6.63k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  221|  6.63k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  222|  6.63k|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  223|       |
  224|  6.63k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  225|  6.63k|      utf8_output += row0[0];
  226|  6.63k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  227|  6.63k|      utf8_output += row1[0];
  228|       |
  229|  6.63k|      buf += 8;
  230|       |      // surrogate pair(s) in a register
  231|  6.63k|    } else {
  232|       |      // Let us do a scalar fallback.
  233|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  234|       |      // in the presence of surrogate pairs may require non-trivial tables.
  235|    689|      size_t forward = 15;
  236|    689|      size_t k = 0;
  237|    689|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (237:11): [True: 0, False: 689]
  ------------------
  238|      0|        forward = size_t(end - buf - 1);
  239|      0|      }
  240|  9.15k|      for (; k < forward; k++) {
  ------------------
  |  Branch (240:14): [True: 8.55k, False: 600]
  ------------------
  241|  8.55k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  242|  8.55k|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (242:13): [True: 2.18k, False: 6.37k]
  ------------------
  243|  2.18k|          *utf8_output++ = char(word);
  244|  6.37k|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (244:20): [True: 815, False: 5.55k]
  ------------------
  245|    815|          *utf8_output++ = char((word >> 6) | 0b11000000);
  246|    815|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  247|  5.55k|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (247:20): [True: 4.39k, False: 1.16k]
  ------------------
  248|  4.39k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  249|  4.39k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  250|  4.39k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  251|  4.39k|        } else {
  252|       |          // must be a surrogate pair
  253|  1.16k|          uint16_t diff = uint16_t(word - 0xD800);
  254|  1.16k|          uint16_t next_word =
  255|  1.16k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  256|  1.16k|          k++;
  257|  1.16k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  258|  1.16k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (258:15): [True: 89, False: 1.07k]
  ------------------
  259|     89|            return std::make_pair(nullptr, utf8_output);
  260|     89|          }
  261|  1.07k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  262|  1.07k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  263|  1.07k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  264|  1.07k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  265|  1.07k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  266|  1.07k|        }
  267|  8.55k|      }
  268|    600|      buf += k;
  269|    600|    }
  270|   290k|  } // while
  271|       |
  272|    536|  return std::make_pair(buf, utf8_output);
  273|    625|}

_ZN7simdutf22utf8_length_from_utf16ENSt3__14spanIKDsLm18446744073709551615EEE:
 2953|    988|utf8_length_from_utf16(std::span<const char16_t> valid_utf16_input) noexcept {
 2954|       |    #if SIMDUTF_CPLUSPLUS23
 2955|       |  if consteval {
 2956|       |    return scalar::utf16::utf8_length_from_utf16<endianness::NATIVE>(
 2957|       |        valid_utf16_input.data(), valid_utf16_input.size());
 2958|       |  } else
 2959|       |    #endif
 2960|    988|  {
 2961|    988|    return utf8_length_from_utf16(valid_utf16_input.data(),
 2962|    988|                                  valid_utf16_input.size());
 2963|    988|  }
 2964|    988|}
safe_conversion.cpp:_ZN7simdutf6detail12_GLOBAL__N_13minEmm:
   59|    988|constexpr std::size_t min(std::size_t a, std::size_t b) {
   60|    988|  return a < b ? a : b;
  ------------------
  |  Branch (60:10): [True: 134, False: 854]
  ------------------
   61|    988|}
_ZN7simdutf27convert_latin1_to_utf8_safeITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  874|    710|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
  875|       |      // implementation note: outputspan is a forwarding ref to avoid copying
  876|       |      // and allow both lvalues and rvalues. std::span can be copied without
  877|       |      // problems, but std::vector should not, and this function should accept
  878|       |      // both. it will allow using an owning rvalue ref (example: passing a
  879|       |      // temporary std::string) as output, but the user will quickly find out
  880|       |      // that he has no way of getting the data out of the object in that case.
  881|       |    #if SIMDUTF_CPLUSPLUS23
  882|       |  if consteval {
  883|       |    return scalar::latin1_to_utf8::convert_safe_constexpr(
  884|       |        input.data(), input.size(), utf8_output.data(), utf8_output.size());
  885|       |  } else
  886|       |    #endif
  887|    710|  {
  888|    710|    return convert_latin1_to_utf8_safe(
  889|    710|        reinterpret_cast<const char *>(input.data()), input.size(),
  890|    710|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
  891|    710|  }
  892|    710|}
_ZN7simdutf23utf8_length_from_latin1ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEEEEmRKT_:
 1657|    710|    const detail::input_span_of_byte_like auto &latin1_input) noexcept {
 1658|       |    #if SIMDUTF_CPLUSPLUS23
 1659|       |  if consteval {
 1660|       |    return scalar::latin1_to_utf8::utf8_length_from_latin1(latin1_input.data(),
 1661|       |                                                           latin1_input.size());
 1662|       |  } else
 1663|       |    #endif
 1664|    710|  {
 1665|    710|    return utf8_length_from_latin1(
 1666|    710|        reinterpret_cast<const char *>(latin1_input.data()),
 1667|    710|        latin1_input.size());
 1668|    710|  }
 1669|    710|}
_ZN7simdutf22convert_latin1_to_utf8ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  837|    710|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
  838|       |    #if SIMDUTF_CPLUSPLUS23
  839|       |  if consteval {
  840|       |    return scalar::latin1_to_utf8::convert(
  841|       |        detail::constexpr_cast_ptr<char>(latin1_input.data()),
  842|       |        latin1_input.size(),
  843|       |        detail::constexpr_cast_writeptr<char>(utf8_output.data()));
  844|       |  } else
  845|       |    #endif
  846|    710|  {
  847|    710|    return convert_latin1_to_utf8(
  848|    710|        reinterpret_cast<const char *>(latin1_input.data()),
  849|    710|        latin1_input.size(), reinterpret_cast<char *>(utf8_output.data()));
  850|    710|  }
  851|    710|}
_ZN7simdutf26convert_utf16_to_utf8_safeITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 1844|    988|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
 1845|       |      // implementation note: outputspan is a forwarding ref to avoid copying
 1846|       |      // and allow both lvalues and rvalues. std::span can be copied without
 1847|       |      // problems, but std::vector should not, and this function should accept
 1848|       |      // both. it will allow using an owning rvalue ref (example: passing a
 1849|       |      // temporary std::string) as output, but the user will quickly find out
 1850|       |      // that he has no way of getting the data out of the object in that case.
 1851|       |    #if SIMDUTF_CPLUSPLUS23
 1852|       |  if consteval {
 1853|       |    const full_result r =
 1854|       |        scalar::utf16_to_utf8::convert_with_errors<endianness::NATIVE, true>(
 1855|       |            utf16_input.data(), utf16_input.size(), utf8_output.data(),
 1856|       |            utf8_output.size());
 1857|       |    if (r.error != error_code::SUCCESS &&
 1858|       |        r.error != error_code::OUTPUT_BUFFER_TOO_SMALL) {
 1859|       |      return 0;
 1860|       |    }
 1861|       |    return r.output_count;
 1862|       |  } else
 1863|       |    #endif
 1864|    988|  {
 1865|    988|    return convert_utf16_to_utf8_safe(
 1866|    988|        utf16_input.data(), utf16_input.size(),
 1867|    988|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
 1868|    988|  }
 1869|    988|}
_ZN7simdutf21convert_utf16_to_utf8ITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 1804|    988|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
 1805|       |    #if SIMDUTF_CPLUSPLUS23
 1806|       |  if consteval {
 1807|       |    return scalar::utf16_to_utf8::convert<endianness::NATIVE>(
 1808|       |        utf16_input.data(), utf16_input.size(), utf8_output.data());
 1809|       |  } else
 1810|       |    #endif
 1811|    988|  {
 1812|    988|    return convert_utf16_to_utf8(utf16_input.data(), utf16_input.size(),
 1813|    988|                                 reinterpret_cast<char *>(utf8_output.data()));
 1814|    988|  }
 1815|    988|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEaSEPS3_:
 7146|  1.69k|  atomic_ptr &operator=(T *_ptr) {
 7147|  1.69k|    ptr = _ptr;
 7148|  1.69k|    return *this;
 7149|  1.69k|  }

