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

_ZNK7simdutf14implementation25required_instruction_setsEv:
 5613|      4|  virtual uint32_t required_instruction_sets() const {
 5614|      4|    return _required_instruction_sets;
 5615|      4|  }
_ZN7simdutf14implementationC2EPKcS2_j:
 7514|      5|      : _name(name), _description(description),
 7515|      5|        _required_instruction_sets(required_instruction_sets) {}
_ZN7simdutf8internal29available_implementation_listC2Ev:
 7546|      1|  simdutf_really_inline available_implementation_list() {}
simdutf.cpp:_ZN7simdutf6detail12_GLOBAL__N_13minEmm:
   59|  4.06k|constexpr std::size_t min(std::size_t a, std::size_t b) {
   60|  4.06k|  return a < b ? a : b;
  ------------------
  |  Branch (60:10): [True: 1.41k, False: 2.64k]
  ------------------
   61|  4.06k|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEC2EPS3_:
 7594|      1|  atomic_ptr(T *_ptr) : ptr{_ptr} {}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEptEv:
 7616|  5.99k|  T *operator->() { return ptr.load(); }

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

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

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf812convert_safeEPKcmPcm:
   72|    733|                           size_t utf8_len) {
   73|    733|  const unsigned char *data = reinterpret_cast<const unsigned char *>(buf);
   74|    733|  size_t pos = 0;
   75|    733|  size_t skip_pos = 0;
   76|    733|  size_t utf8_pos = 0;
   77|  3.91k|  while (pos < len && utf8_pos < utf8_len) {
  ------------------
  |  Branch (77:10): [True: 3.49k, False: 418]
  |  Branch (77:23): [True: 3.21k, False: 286]
  ------------------
   78|       |    // try to convert the next block of 16 ASCII bytes
   79|  3.21k|    if (pos >= skip_pos && pos + 16 <= len &&
  ------------------
  |  Branch (79:9): [True: 1.90k, False: 1.30k]
  |  Branch (79:28): [True: 1.35k, False: 554]
  ------------------
   80|  1.35k|        utf8_pos + 16 <= utf8_len) { // if it is safe to read 16 more bytes,
  ------------------
  |  Branch (80:9): [True: 245, False: 1.10k]
  ------------------
   81|       |                                     // check that they are ascii
   82|    245|      uint64_t v1;
   83|    245|      ::memcpy(&v1, data + pos, sizeof(uint64_t));
   84|    245|      uint64_t v2;
   85|    245|      ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   86|    245|      uint64_t v{v1 |
   87|    245|                 v2}; // We are only interested in these bits: 1000 1000 1000
   88|       |                      // 1000, so it makes sense to concatenate everything
   89|    245|      if ((v & 0x8080808080808080) ==
  ------------------
  |  Branch (89:11): [True: 159, False: 86]
  ------------------
   90|    245|          0) { // if NONE of these are set, e.g. all of them are zero, then
   91|       |               // everything is ASCII
   92|    159|        ::memcpy(utf8_output + utf8_pos, buf + pos, 16);
   93|    159|        utf8_pos += 16;
   94|    159|        pos += 16;
   95|    159|      } else {
   96|       |        // At least one of the next 16 bytes are not ASCII, we will process them
   97|       |        // one by one
   98|     86|        skip_pos = pos + 16;
   99|     86|      }
  100|  2.96k|    } else {
  101|  2.96k|      const auto byte = data[pos];
  102|  2.96k|      if ((byte & 0x80) == 0) { // if ASCII
  ------------------
  |  Branch (102:11): [True: 2.16k, False: 800]
  ------------------
  103|       |        // will generate one UTF-8 bytes
  104|  2.16k|        utf8_output[utf8_pos++] = char(byte);
  105|  2.16k|        pos++;
  106|  2.16k|      } else if (utf8_pos + 2 <= utf8_len) {
  ------------------
  |  Branch (106:18): [True: 771, False: 29]
  ------------------
  107|       |        // will generate two UTF-8 bytes
  108|    771|        utf8_output[utf8_pos++] = char((byte >> 6) | 0b11000000);
  109|    771|        utf8_output[utf8_pos++] = char((byte & 0b111111) | 0b10000000);
  110|    771|        pos++;
  111|    771|      } else {
  112|     29|        break;
  113|     29|      }
  114|  2.96k|    }
  115|  3.21k|  }
  116|    733|  return utf8_pos;
  117|    733|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf87convertEPKcmPc:
   66|  1.99k|                                     char *utf8_output) {
   67|  1.99k|  return convert(reinterpret_cast<const unsigned char *>(buf), len,
   68|  1.99k|                 utf8_output);
   69|  1.99k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf87convertIPKhPcQaasr7simdutf6detailE22indexes_into_byte_likeIT_Esr7simdutf6detailE26index_assignable_from_charIT0_EEEmS7_mS8_:
   17|  1.99k|                                   OutputPtr utf8_output) {
   18|       |  // const unsigned char *data = reinterpret_cast<const unsigned char *>(buf);
   19|  1.99k|  size_t pos = 0;
   20|  1.99k|  size_t utf8_pos = 0;
   21|       |
   22|  5.42M|  while (pos < len) {
  ------------------
  |  Branch (22:10): [True: 5.42M, False: 1.99k]
  ------------------
   23|       |#if SIMDUTF_CPLUSPLUS23
   24|       |    if !consteval
   25|       |#endif
   26|  5.42M|    {
   27|       |      // try to convert the next block of 16 ASCII bytes
   28|  5.42M|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (28:11): [True: 5.40M, False: 18.6k]
  ------------------
   29|       |                             // they are ascii
   30|  5.40M|        uint64_t v1;
   31|  5.40M|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   32|  5.40M|        uint64_t v2;
   33|  5.40M|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   34|  5.40M|        uint64_t v{v1 |
   35|  5.40M|                   v2}; // We are only interested in these bits: 1000 1000 1000
   36|       |                        // 1000, so it makes sense to concatenate everything
   37|  5.40M|        if ((v & 0x8080808080808080) ==
  ------------------
  |  Branch (37:13): [True: 909k, False: 4.49M]
  ------------------
   38|  5.40M|            0) { // if NONE of these are set, e.g. all of them are zero, then
   39|       |                 // everything is ASCII
   40|   909k|          size_t final_pos = pos + 16;
   41|  15.4M|          while (pos < final_pos) {
  ------------------
  |  Branch (41:18): [True: 14.5M, False: 909k]
  ------------------
   42|  14.5M|            utf8_output[utf8_pos++] = char(data[pos]);
   43|  14.5M|            pos++;
   44|  14.5M|          }
   45|   909k|          continue;
   46|   909k|        }
   47|  5.40M|      } // if (pos + 16 <= len)
   48|  5.42M|    } // !consteval scope
   49|       |
   50|  4.51M|    unsigned char byte = data[pos];
   51|  4.51M|    if ((byte & 0x80) == 0) { // if ASCII
  ------------------
  |  Branch (51:9): [True: 1.83M, False: 2.68M]
  ------------------
   52|       |      // will generate one UTF-8 bytes
   53|  1.83M|      utf8_output[utf8_pos++] = char(byte);
   54|  1.83M|      pos++;
   55|  2.68M|    } else {
   56|       |      // will generate two UTF-8 bytes
   57|  2.68M|      utf8_output[utf8_pos++] = char((byte >> 6) | 0b11000000);
   58|  2.68M|      utf8_output[utf8_pos++] = char((byte & 0b111111) | 0b10000000);
   59|  2.68M|      pos++;
   60|  2.68M|    }
   61|  4.51M|  } // while
   62|  1.99k|  return utf8_pos;
   63|  1.99k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf823utf8_length_from_latin1IPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_m:
  199|    167|utf8_length_from_latin1(InputPtr input, size_t length) noexcept {
  200|    167|  size_t answer = length;
  201|    167|  size_t i = 0;
  202|       |
  203|       |#if SIMDUTF_CPLUSPLUS23
  204|       |  if !consteval
  205|       |#endif
  206|    167|  {
  207|    167|    auto pop = [](uint64_t v) {
  208|    167|      return (size_t)(((v >> 7) & UINT64_C(0x0101010101010101)) *
  209|    167|                          UINT64_C(0x0101010101010101) >>
  210|    167|                      56);
  211|    167|    };
  212|   581k|    for (; i + 32 <= length; i += 32) {
  ------------------
  |  Branch (212:12): [True: 580k, False: 167]
  ------------------
  213|   580k|      uint64_t v;
  214|   580k|      memcpy(&v, input + i, 8);
  215|   580k|      answer += pop(v);
  216|   580k|      memcpy(&v, input + i + 8, sizeof(v));
  217|   580k|      answer += pop(v);
  218|   580k|      memcpy(&v, input + i + 16, sizeof(v));
  219|   580k|      answer += pop(v);
  220|   580k|      memcpy(&v, input + i + 24, sizeof(v));
  221|   580k|      answer += pop(v);
  222|   580k|    }
  223|    409|    for (; i + 8 <= length; i += 8) {
  ------------------
  |  Branch (223:12): [True: 242, False: 167]
  ------------------
  224|    242|      uint64_t v;
  225|    242|      memcpy(&v, input + i, sizeof(v));
  226|    242|      answer += pop(v);
  227|    242|    }
  228|    167|  } // !consteval scope
  229|    576|  for (; i + 1 <= length; i += 1) {
  ------------------
  |  Branch (229:10): [True: 409, False: 167]
  ------------------
  230|    409|    answer += static_cast<uint8_t>(input[i]) >> 7;
  231|    409|  }
  232|    167|  return answer;
  233|    167|}
simdutf.cpp:_ZZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf823utf8_length_from_latin1IPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_mENKUlmE_clEm:
  207|  2.32M|    auto pop = [](uint64_t v) {
  208|  2.32M|      return (size_t)(((v >> 7) & UINT64_C(0x0101010101010101)) *
  209|       |                          UINT64_C(0x0101010101010101) >>
  210|  2.32M|                      56);
  211|  2.32M|    };

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

_ZN7simdutf6scalar5utf1614high_surrogateEDs:
  147|    792|simdutf_unused simdutf_really_inline constexpr bool high_surrogate(char16_t c) {
  148|    792|  return (0xd800 <= c && c <= 0xdbff);
  ------------------
  |  Branch (148:11): [True: 99, False: 693]
  |  Branch (148:26): [True: 46, False: 53]
  ------------------
  149|    792|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE0EEEmPKDsm:
   91|  1.00k|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|  1.00k|  size_t counter{0};
   94|  8.08M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 8.07M, False: 1.00k]
  ------------------
   95|  8.07M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|  8.07M|    counter++; // ASCII
   97|  8.07M|    counter += static_cast<size_t>(
   98|  8.07M|        word >
   99|  8.07M|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|  8.07M|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 1.37M, False: 6.70M]
  |  Branch (100:53): [True: 1.23M, False: 134k]
  ------------------
  101|  6.83M|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 124k, False: 6.71M]
  ------------------
  102|  8.07M|  }
  103|  1.00k|  return counter;
  104|  1.00k|}

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

_ZNK7simdutf8fallback14implementation22convert_latin1_to_utf8EPKcmPc:
  128|    393|    const char *buf, size_t len, char *utf8_output) const noexcept {
  129|    393|  return scalar::latin1_to_utf8::convert(buf, len, utf8_output);
  130|    393|}
_ZNK7simdutf8fallback14implementation23convert_utf16le_to_utf8EPKDsmPc:
  268|    619|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  269|    619|  return scalar::utf16_to_utf8::convert<endianness::LITTLE>(buf, len,
  270|    619|                                                            utf8_output);
  271|    619|}
_ZNK7simdutf8fallback14implementation23utf8_length_from_latin1EPKcm:
  450|    167|    const char *input, size_t length) const noexcept {
  451|    167|  return scalar::latin1_to_utf8::utf8_length_from_latin1(input, length);
  452|    167|}
_ZNK7simdutf8fallback14implementation24utf8_length_from_utf16leEPKDsm:
  457|    218|    const char16_t *input, size_t length) const noexcept {
  458|    218|  return scalar::utf16::utf8_length_from_utf16<endianness::LITTLE>(input,
  459|    218|                                                                   length);
  460|    218|}

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

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_126avx2_convert_utf16_to_utf8ILNS_10endiannessE0EEENSt3__14pairIPKDsPcEES7_mS8_:
   56|    744|avx2_convert_utf16_to_utf8(const char16_t *buf, size_t len, char *utf8_output) {
   57|    744|  const char16_t *end = buf + len;
   58|    744|  const __m256i v_0000 = _mm256_setzero_si256();
   59|    744|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
   60|    744|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
   61|    744|  const __m256i v_c080 = _mm256_set1_epi16((int16_t)0xc080);
   62|    744|  const size_t safety_margin =
   63|    744|      12; // to avoid overruns, see issue
   64|       |          // https://github.com/simdutf/simdutf/issues/92
   65|       |
   66|  84.3k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (66:10): [True: 83.7k, False: 592]
  ------------------
   67|  83.7k|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
   68|  83.7k|    if (big_endian) {
  ------------------
  |  Branch (68:9): [Folded, False: 83.7k]
  ------------------
   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|  83.7k|    const __m256i v_ff80 = _mm256_set1_epi16((int16_t)0xff80);
   76|  83.7k|    if (_mm256_testz_si256(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (76:9): [True: 72.8k, False: 10.8k]
  ------------------
   77|       |      // 1. pack the bytes
   78|  72.8k|      const __m128i utf8_packed = _mm_packus_epi16(
   79|  72.8k|          _mm256_castsi256_si128(in), _mm256_extractf128_si256(in, 1));
   80|       |      // 2. store (16 bytes)
   81|  72.8k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   82|       |      // 3. adjust pointers
   83|  72.8k|      buf += 16;
   84|  72.8k|      utf8_output += 16;
   85|  72.8k|      continue; // we are done for this round!
   86|  72.8k|    }
   87|       |    // no bits set above 7th bit
   88|  10.8k|    const __m256i one_byte_bytemask =
   89|  10.8k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_ff80), v_0000);
   90|  10.8k|    const uint32_t one_byte_bitmask =
   91|  10.8k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
   92|       |
   93|       |    // no bits set above 11th bit
   94|  10.8k|    const __m256i one_or_two_bytes_bytemask =
   95|  10.8k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_0000);
   96|  10.8k|    const uint32_t one_or_two_bytes_bitmask =
   97|  10.8k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
   98|  10.8k|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (98:9): [True: 1.34k, False: 9.48k]
  ------------------
   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.34k|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
  104|  1.34k|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
  105|       |
  106|       |      // t0 = [000a|aaaa|bbbb|bb00]
  107|  1.34k|      const __m256i t0 = _mm256_slli_epi16(in, 2);
  108|       |      // t1 = [000a|aaaa|0000|0000]
  109|  1.34k|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
  110|       |      // t2 = [0000|0000|00bb|bbbb]
  111|  1.34k|      const __m256i t2 = _mm256_and_si256(in, v_003f);
  112|       |      // t3 = [000a|aaaa|00bb|bbbb]
  113|  1.34k|      const __m256i t3 = _mm256_or_si256(t1, t2);
  114|       |      // t4 = [110a|aaaa|10bb|bbbb]
  115|  1.34k|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
  116|       |
  117|       |      // 2. merge ASCII and 2-byte codewords
  118|  1.34k|      const __m256i utf8_unpacked =
  119|  1.34k|          _mm256_blendv_epi8(t4, in, one_byte_bytemask);
  120|       |
  121|       |      // 3. prepare bitmask for 8-bit lookup
  122|  1.34k|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
  123|  1.34k|      const uint32_t M1 = M0 >> 7;
  124|  1.34k|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
  125|       |      // 4. pack the bytes
  126|       |
  127|  1.34k|      const uint8_t *row =
  128|  1.34k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
  129|  1.34k|      const uint8_t *row_2 =
  130|  1.34k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
  131|  1.34k|                                                                       16)][0];
  132|       |
  133|  1.34k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  134|  1.34k|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
  135|       |
  136|  1.34k|      const __m256i utf8_packed = _mm256_shuffle_epi8(
  137|  1.34k|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|  1.34k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|  1.34k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  138|       |      // 5. store bytes
  139|  1.34k|      _mm_storeu_si128((__m128i *)utf8_output,
  140|  1.34k|                       _mm256_castsi256_si128(utf8_packed));
  141|  1.34k|      utf8_output += row[0];
  142|  1.34k|      _mm_storeu_si128((__m128i *)utf8_output,
  143|  1.34k|                       _mm256_extractf128_si256(utf8_packed, 1));
  144|  1.34k|      utf8_output += row_2[0];
  145|       |
  146|       |      // 6. adjust pointers
  147|  1.34k|      buf += 16;
  148|  1.34k|      continue;
  149|  1.34k|    }
  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|  9.48k|    const __m256i surrogates_bytemask =
  154|  9.48k|        _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|  9.48k|    const uint32_t surrogates_bitmask =
  159|  9.48k|        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|  9.48k|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (162:9): [True: 8.49k, False: 991]
  ------------------
  163|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  164|  8.49k|      const __m256i dup_even = _mm256_setr_epi16(
  165|  8.49k|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  166|  8.49k|          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|  8.49k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  196|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  197|  8.49k|      const __m256i t0 = _mm256_shuffle_epi8(in, dup_even);
  198|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  199|  8.49k|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  195|  8.49k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  200|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  201|  8.49k|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  195|  8.49k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  202|       |
  203|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  204|  8.49k|      const __m256i s0 = _mm256_srli_epi16(in, 4);
  205|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  206|  8.49k|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  195|  8.49k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  207|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  208|  8.49k|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  195|  8.49k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  209|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  210|  8.49k|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  195|  8.49k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  211|  8.49k|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  212|  8.49k|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  195|  8.49k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  213|  8.49k|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  214|  8.49k|#undef simdutf_vec
  215|       |
  216|       |      // 4. expand code units 16-bit => 32-bit
  217|  8.49k|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  218|  8.49k|      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|  8.49k|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  222|  8.49k|                            (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|  8.49k|      const uint8_t mask0 = uint8_t(mask);
  243|  8.49k|      const uint8_t *row0 =
  244|  8.49k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  245|  8.49k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  246|  8.49k|      const __m128i utf8_0 =
  247|  8.49k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  248|       |
  249|  8.49k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  250|  8.49k|      const uint8_t *row1 =
  251|  8.49k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  252|  8.49k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  253|  8.49k|      const __m128i utf8_1 =
  254|  8.49k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  255|       |
  256|  8.49k|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  257|  8.49k|      const uint8_t *row2 =
  258|  8.49k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  259|  8.49k|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  260|  8.49k|      const __m128i utf8_2 =
  261|  8.49k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  262|       |
  263|  8.49k|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  264|  8.49k|      const uint8_t *row3 =
  265|  8.49k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  266|  8.49k|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  267|  8.49k|      const __m128i utf8_3 =
  268|  8.49k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  269|       |
  270|  8.49k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  271|  8.49k|      utf8_output += row0[0];
  272|  8.49k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  273|  8.49k|      utf8_output += row1[0];
  274|  8.49k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  275|  8.49k|      utf8_output += row2[0];
  276|  8.49k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  277|  8.49k|      utf8_output += row3[0];
  278|  8.49k|      buf += 16;
  279|       |      // surrogate pair(s) in a register
  280|  8.49k|    } 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|    991|      size_t forward = 15;
  285|    991|      size_t k = 0;
  286|    991|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (286:11): [True: 0, False: 991]
  ------------------
  287|      0|        forward = size_t(end - buf - 1);
  288|      0|      }
  289|  13.3k|      for (; k < forward; k++) {
  ------------------
  |  Branch (289:14): [True: 12.4k, False: 839]
  ------------------
  290|  12.4k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  291|  12.4k|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (291:13): [True: 3.90k, False: 8.59k]
  ------------------
  292|  3.90k|          *utf8_output++ = char(word);
  293|  8.59k|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (293:20): [True: 2.22k, False: 6.37k]
  ------------------
  294|  2.22k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  295|  2.22k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  296|  6.37k|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (296:20): [True: 4.92k, False: 1.44k]
  ------------------
  297|  4.92k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  298|  4.92k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  299|  4.92k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  300|  4.92k|        } else {
  301|       |          // must be a surrogate pair
  302|  1.44k|          uint16_t diff = uint16_t(word - 0xD800);
  303|  1.44k|          uint16_t next_word =
  304|  1.44k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  305|  1.44k|          k++;
  306|  1.44k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  307|  1.44k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (307:15): [True: 152, False: 1.29k]
  ------------------
  308|    152|            return std::make_pair(nullptr, utf8_output);
  309|    152|          }
  310|  1.29k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  311|  1.29k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  312|  1.29k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  313|  1.29k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  314|  1.29k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  315|  1.29k|        }
  316|  12.4k|      }
  317|    839|      buf += k;
  318|    839|    }
  319|  9.48k|  } // while
  320|    592|  return std::make_pair(buf, utf8_output);
  321|    744|}

_ZNK7simdutf7haswell14implementation22convert_latin1_to_utf8EPKcmPc:
  412|    813|    const char *buf, size_t len, char *utf8_output) const noexcept {
  413|    813|  std::pair<const char *, char *> ret =
  414|    813|      avx2_convert_latin1_to_utf8(buf, len, utf8_output);
  415|    813|  size_t converted_chars = ret.second - utf8_output;
  416|       |
  417|    813|  if (ret.first != buf + len) {
  ------------------
  |  Branch (417:7): [True: 803, False: 10]
  ------------------
  418|    803|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  419|    803|        ret.first, len - (ret.first - buf), ret.second);
  420|    803|    converted_chars += scalar_converted_chars;
  421|    803|  }
  422|       |
  423|    813|  return converted_chars;
  424|    813|}
_ZNK7simdutf7haswell14implementation23convert_utf16le_to_utf8EPKDsmPc:
  679|    744|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  680|    744|  std::pair<const char16_t *, char *> ret =
  681|    744|      haswell::avx2_convert_utf16_to_utf8<endianness::LITTLE>(buf, len,
  682|    744|                                                              utf8_output);
  683|    744|  if (ret.first == nullptr) {
  ------------------
  |  Branch (683:7): [True: 152, False: 592]
  ------------------
  684|    152|    return 0;
  685|    152|  }
  686|    592|  size_t saved_bytes = ret.second - utf8_output;
  687|    592|  if (ret.first != buf + len) {
  ------------------
  |  Branch (687:7): [True: 584, False: 8]
  ------------------
  688|    584|    const size_t scalar_saved_bytes =
  689|    584|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  690|    584|            ret.first, len - (ret.first - buf), ret.second);
  691|    584|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (691:9): [True: 135, False: 449]
  ------------------
  692|    135|      return 0;
  693|    135|    }
  694|    449|    saved_bytes += scalar_saved_bytes;
  695|    449|  }
  696|    457|  return saved_bytes;
  697|    592|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16leEPKDsm:
 1114|    395|    const char16_t *input, size_t length) const noexcept {
 1115|    395|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1116|    395|                                                                    length);
 1117|    395|}
_ZNK7simdutf7haswell14implementation23utf8_length_from_latin1EPKcm:
 1180|    277|    const char *input, size_t len) const noexcept {
 1181|    277|  const uint8_t *data = reinterpret_cast<const uint8_t *>(input);
 1182|    277|  size_t answer = len / sizeof(__m256i) * sizeof(__m256i);
 1183|    277|  size_t i = 0;
 1184|    277|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1184:7): [True: 125, False: 152]
  ------------------
 1185|    125|    __m256i four_64bits = _mm256_setzero_si256();
 1186|  3.07k|    while (i + sizeof(__m256i) <= len) {
  ------------------
  |  Branch (1186:12): [True: 2.94k, False: 125]
  ------------------
 1187|  2.94k|      __m256i runner = _mm256_setzero_si256();
 1188|       |      // We can do up to 255 loops without overflow.
 1189|  2.94k|      size_t iterations = (len - i) / sizeof(__m256i);
 1190|  2.94k|      if (iterations > 255) {
  ------------------
  |  Branch (1190:11): [True: 2.82k, False: 125]
  ------------------
 1191|  2.82k|        iterations = 255;
 1192|  2.82k|      }
 1193|  2.94k|      size_t max_i = i + iterations * sizeof(__m256i) - sizeof(__m256i);
 1194|   183k|      for (; i + 4 * sizeof(__m256i) <= max_i; i += 4 * sizeof(__m256i)) {
  ------------------
  |  Branch (1194:14): [True: 180k, False: 2.94k]
  ------------------
 1195|   180k|        __m256i input1 = _mm256_loadu_si256((const __m256i *)(data + i));
 1196|   180k|        __m256i input2 =
 1197|   180k|            _mm256_loadu_si256((const __m256i *)(data + i + sizeof(__m256i)));
 1198|   180k|        __m256i input3 = _mm256_loadu_si256(
 1199|   180k|            (const __m256i *)(data + i + 2 * sizeof(__m256i)));
 1200|   180k|        __m256i input4 = _mm256_loadu_si256(
 1201|   180k|            (const __m256i *)(data + i + 3 * sizeof(__m256i)));
 1202|   180k|        __m256i input12 =
 1203|   180k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input1),
 1204|   180k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input2));
 1205|   180k|        __m256i input23 =
 1206|   180k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input3),
 1207|   180k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input4));
 1208|   180k|        __m256i input1234 = _mm256_add_epi8(input12, input23);
 1209|   180k|        runner = _mm256_sub_epi8(runner, input1234);
 1210|   180k|      }
 1211|  11.7k|      for (; i <= max_i; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1211:14): [True: 8.78k, False: 2.94k]
  ------------------
 1212|  8.78k|        __m256i input_256_chunk =
 1213|  8.78k|            _mm256_loadu_si256((const __m256i *)(data + i));
 1214|  8.78k|        runner = _mm256_sub_epi8(
 1215|  8.78k|            runner, _mm256_cmpgt_epi8(_mm256_setzero_si256(), input_256_chunk));
 1216|  8.78k|      }
 1217|  2.94k|      four_64bits = _mm256_add_epi64(
 1218|  2.94k|          four_64bits, _mm256_sad_epu8(runner, _mm256_setzero_si256()));
 1219|  2.94k|    }
 1220|    125|    answer += _mm256_extract_epi64(four_64bits, 0) +
 1221|    125|              _mm256_extract_epi64(four_64bits, 1) +
 1222|    125|              _mm256_extract_epi64(four_64bits, 2) +
 1223|    125|              _mm256_extract_epi64(four_64bits, 3);
 1224|    152|  } else if (answer > 0) {
  ------------------
  |  Branch (1224:14): [True: 73, False: 79]
  ------------------
 1225|  1.34k|    for (; i + sizeof(__m256i) <= len; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1225:12): [True: 1.27k, False: 73]
  ------------------
 1226|  1.27k|      __m256i latin = _mm256_loadu_si256((const __m256i *)(data + i));
 1227|  1.27k|      uint32_t non_ascii = _mm256_movemask_epi8(latin);
 1228|  1.27k|      answer += count_ones(non_ascii);
 1229|  1.27k|    }
 1230|     73|  }
 1231|    277|  return answer + scalar::latin1::utf8_length_from_latin1(
 1232|    277|                      reinterpret_cast<const char *>(data + i), len - i);
 1233|    277|}

_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:
 1513|      1|available_implementation_list::begin() const noexcept {
 1514|      1|  return internal::get_available_implementation_pointers().begin();
 1515|      1|}
_ZNK7simdutf8internal29available_implementation_list3endEv:
 1517|      1|available_implementation_list::end() const noexcept {
 1518|      1|  return internal::get_available_implementation_pointers().end();
 1519|      1|}
_ZN7simdutf29get_available_implementationsEv:
 1568|      1|get_available_implementations() {
 1569|      1|#if !SIMDUTF_USE_STATIC_INITIALIZATION
 1570|      1|  static const internal::available_implementation_list
 1571|      1|      available_implementations_instance{};
 1572|      1|#endif
 1573|      1|  return available_implementations_instance;
 1574|      1|}
_ZN7simdutf25get_active_implementationEv:
 1596|  7.72k|get_active_implementation() {
 1597|  7.72k|#if !SIMDUTF_USE_STATIC_INITIALIZATION
 1598|  7.72k|  #if !SIMDUTF_SINGLE_IMPLEMENTATION
 1599|  7.72k|  static const internal::detect_best_supported_implementation_on_first_use
 1600|  7.72k|      detect_best_supported_implementation_on_first_use_singleton;
 1601|  7.72k|  #endif
 1602|  7.72k|  static internal::atomic_ptr<const implementation>
 1603|  7.72k|      active_implementation_instance{
 1604|       |  #if SIMDUTF_SINGLE_IMPLEMENTATION
 1605|       |          internal::get_single_implementation()
 1606|       |  #else
 1607|  7.72k|          &detect_best_supported_implementation_on_first_use_singleton
 1608|  7.72k|  #endif
 1609|  7.72k|      };
 1610|  7.72k|#endif
 1611|  7.72k|  return active_implementation_instance;
 1612|  7.72k|}
_ZN7simdutf22convert_latin1_to_utf8EPKcmPc:
 1678|  2.15k|                                                  char *utf8_output) noexcept {
 1679|  2.15k|  return get_default_implementation()->convert_latin1_to_utf8(buf, len,
 1680|  2.15k|                                                              utf8_output);
 1681|  2.15k|}
_ZN7simdutf21convert_utf16_to_utf8EPKDsmPc:
 1964|  2.10k|                                                 char *utf8_buffer) noexcept {
 1965|       |  #if SIMDUTF_IS_BIG_ENDIAN
 1966|       |  return convert_utf16be_to_utf8(buf, len, utf8_buffer);
 1967|       |  #else
 1968|  2.10k|  return convert_utf16le_to_utf8(buf, len, utf8_buffer);
 1969|  2.10k|  #endif
 1970|  2.10k|}
_ZN7simdutf26convert_utf16_to_utf8_safeEPKDsmPcm:
 1974|  1.00k|                           size_t utf8_len) noexcept {
 1975|  1.00k|  const auto start{utf8_output};
 1976|       |  // We might be able to go faster by first scanning the input buffer to
 1977|       |  // determine how many char16_t characters we can read without exceeding the
 1978|       |  // utf8_len. This is a one-pass algorithm that has the benefit of not
 1979|       |  // requiring a first pass to determine the length.
 1980|  1.91k|  while (true) {
  ------------------
  |  Branch (1980:10): [True: 1.91k, Folded]
  ------------------
 1981|       |    // The worst case for convert_utf16_to_utf8 is when you go from 1 char16_t
 1982|       |    // to 3 characters of UTF-8. So we can read at most utf8_len / 3 char16_t
 1983|       |    // characters.
 1984|  1.91k|    auto read_len = detail::min(len, utf8_len / 3);
 1985|  1.91k|    if (read_len <= 16) {
  ------------------
  |  Branch (1985:9): [True: 811, False: 1.10k]
  ------------------
 1986|    811|      break;
 1987|    811|    }
 1988|  1.10k|    if (read_len < len) {
  ------------------
  |  Branch (1988:9): [True: 792, False: 312]
  ------------------
 1989|       |      //  If we have a high surrogate at the end of the buffer, we need to
 1990|       |      //  either read one more char16_t or backtrack.
 1991|    792|      if (scalar::utf16::high_surrogate(buf[read_len - 1])) {
  ------------------
  |  Branch (1991:11): [True: 46, False: 746]
  ------------------
 1992|     46|        read_len--;
 1993|     46|      }
 1994|    792|    }
 1995|  1.10k|    if (read_len == 0) {
  ------------------
  |  Branch (1995:9): [True: 0, False: 1.10k]
  ------------------
 1996|       |      // If we cannot read anything, we are done.
 1997|      0|      break;
 1998|      0|    }
 1999|  1.10k|    const auto write_len =
 2000|  1.10k|        simdutf::convert_utf16_to_utf8(buf, read_len, utf8_output);
 2001|  1.10k|    if (write_len == 0) {
  ------------------
  |  Branch (2001:9): [True: 190, False: 914]
  ------------------
 2002|       |      // There was an error in the conversion, we cannot continue.
 2003|    190|      return 0; // indicating failure
 2004|    190|    }
 2005|       |
 2006|    914|    utf8_output += write_len;
 2007|    914|    utf8_len -= write_len;
 2008|    914|    buf += read_len;
 2009|    914|    len -= read_len;
 2010|    914|  }
 2011|       |  #if SIMDUTF_IS_BIG_ENDIAN
 2012|       |  full_result r =
 2013|       |      scalar::utf16_to_utf8::convert_with_errors<endianness::BIG, true>(
 2014|       |          buf, len, utf8_output, utf8_len);
 2015|       |  #else
 2016|    811|  full_result r =
 2017|    811|      scalar::utf16_to_utf8::convert_with_errors<endianness::LITTLE, true>(
 2018|    811|          buf, len, utf8_output, utf8_len);
 2019|    811|  #endif
 2020|    811|  if (r.error != error_code::SUCCESS &&
  ------------------
  |  Branch (2020:7): [True: 328, False: 483]
  ------------------
 2021|    328|      r.error != error_code::OUTPUT_BUFFER_TOO_SMALL) {
  ------------------
  |  Branch (2021:7): [True: 98, False: 230]
  ------------------
 2022|       |    // If there was an error, we return 0 to indicate failure.
 2023|     98|    return 0; // indicating failure
 2024|     98|  }
 2025|    713|  return r.output_count + (utf8_output - start);
 2026|    811|}
_ZN7simdutf23convert_utf16le_to_utf8EPKDsmPc:
 2150|  2.10k|                                                   char *utf8_buffer) noexcept {
 2151|  2.10k|  return get_default_implementation()->convert_utf16le_to_utf8(buf, len,
 2152|  2.10k|                                                               utf8_buffer);
 2153|  2.10k|}
_ZN7simdutf23utf8_length_from_latin1EPKcm:
 2416|    733|                                                   size_t len) noexcept {
 2417|    733|  return get_default_implementation()->utf8_length_from_latin1(buf, len);
 2418|    733|}
_ZN7simdutf22utf8_length_from_utf16EPKDsm:
 2423|  1.00k|                                                  size_t length) noexcept {
 2424|       |  #if SIMDUTF_IS_BIG_ENDIAN
 2425|       |  return utf8_length_from_utf16be(input, length);
 2426|       |  #else
 2427|  1.00k|  return utf8_length_from_utf16le(input, length);
 2428|  1.00k|  #endif
 2429|  1.00k|}
_ZN7simdutf24utf8_length_from_utf16leEPKDsm:
 2439|  1.00k|                                                    size_t length) noexcept {
 2440|  1.00k|  return get_default_implementation()->utf8_length_from_utf16le(input, length);
 2441|  1.00k|}
_ZN7simdutf27convert_latin1_to_utf8_safeEPKcmPcm:
 2694|    733|    const char *buf, size_t len, char *utf8_output, size_t utf8_len) noexcept {
 2695|    733|  const auto start{utf8_output};
 2696|       |
 2697|  2.15k|  while (true) {
  ------------------
  |  Branch (2697:10): [True: 2.15k, Folded]
  ------------------
 2698|       |    // convert_latin1_to_utf8 will never write more than input length * 2
 2699|  2.15k|    auto read_len = detail::min(len, utf8_len >> 1);
 2700|  2.15k|    if (read_len <= 16) {
  ------------------
  |  Branch (2700:9): [True: 733, False: 1.41k]
  ------------------
 2701|    733|      break;
 2702|    733|    }
 2703|       |
 2704|  1.41k|    const auto write_len =
 2705|  1.41k|        simdutf::convert_latin1_to_utf8(buf, read_len, utf8_output);
 2706|       |
 2707|  1.41k|    utf8_output += write_len;
 2708|  1.41k|    utf8_len -= write_len;
 2709|  1.41k|    buf += read_len;
 2710|  1.41k|    len -= read_len;
 2711|  1.41k|  }
 2712|       |
 2713|    733|  utf8_output +=
 2714|    733|      scalar::latin1_to_utf8::convert_safe(buf, len, utf8_output, utf8_len);
 2715|       |
 2716|    733|  return utf8_output - start;
 2717|    733|}
simdutf.cpp:_ZN7simdutf8internalL37get_available_implementation_pointersEv:
  938|      2|get_available_implementation_pointers() {
  939|      2|#if !SIMDUTF_USE_STATIC_INITIALIZATION
  940|      2|  static const std::initializer_list<const implementation *>
  941|      2|      available_implementation_pointers{
  942|      2|  #if SIMDUTF_IMPLEMENTATION_ICELAKE
  943|      2|          get_icelake_singleton(),
  944|      2|  #endif
  945|      2|  #if SIMDUTF_IMPLEMENTATION_HASWELL
  946|      2|          get_haswell_singleton(),
  947|      2|  #endif
  948|      2|  #if SIMDUTF_IMPLEMENTATION_WESTMERE
  949|      2|          get_westmere_singleton(),
  950|      2|  #endif
  951|       |  #if SIMDUTF_IMPLEMENTATION_ARM64
  952|       |          get_arm64_singleton(),
  953|       |  #endif
  954|       |  #if SIMDUTF_IMPLEMENTATION_PPC64
  955|       |          get_ppc64_singleton(),
  956|       |  #endif
  957|       |  #if SIMDUTF_IMPLEMENTATION_RVV
  958|       |          get_rvv_singleton(),
  959|       |  #endif
  960|       |  #if SIMDUTF_IMPLEMENTATION_LASX
  961|       |          get_lasx_singleton(),
  962|       |  #endif
  963|       |  #if SIMDUTF_IMPLEMENTATION_LSX
  964|       |          get_lsx_singleton(),
  965|       |  #endif
  966|      2|  #if SIMDUTF_IMPLEMENTATION_FALLBACK
  967|      2|          get_fallback_singleton(),
  968|      2|  #endif
  969|      2|      };
  970|      2|#endif
  971|      2|  return available_implementation_pointers;
  972|      2|}
simdutf.cpp:_ZN7simdutf8internalL21get_icelake_singletonEv:
  157|      1|static const icelake::implementation *get_icelake_singleton() {
  158|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  159|      1|  static const icelake::implementation icelake_singleton{};
  160|      1|  #endif
  161|      1|  return &icelake_singleton;
  162|      1|}
simdutf.cpp:_ZN7simdutf8internalL21get_haswell_singletonEv:
  168|      1|static const haswell::implementation *get_haswell_singleton() {
  169|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  170|      1|  static const haswell::implementation haswell_singleton{};
  171|      1|  #endif
  172|      1|  return &haswell_singleton;
  173|      1|}
simdutf.cpp:_ZN7simdutf8internalL22get_westmere_singletonEv:
  179|      1|static const westmere::implementation *get_westmere_singleton() {
  180|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  181|      1|  static const westmere::implementation westmere_singleton{};
  182|      1|  #endif
  183|      1|  return &westmere_singleton;
  184|      1|}
simdutf.cpp:_ZN7simdutf8internalL22get_fallback_singletonEv:
  245|      1|static const fallback::implementation *get_fallback_singleton() {
  246|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  247|      1|  static const fallback::implementation fallback_singleton{};
  248|      1|  #endif
  249|      1|  return &fallback_singleton;
  250|      1|}
_ZN7simdutf8internal49detect_best_supported_implementation_on_first_useC2Ev:
  892|      1|      : implementation("best_supported_detector",
  893|      1|                       "Detects the best supported implementation and sets it",
  894|      1|                       0) {}
_ZN7simdutf26get_default_implementationEv:
 1620|  5.99k|get_default_implementation() {
 1621|  5.99k|  return get_active_implementation();
 1622|  5.99k|}

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

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

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

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

_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.97k|simdutf_really_inline long long int count_ones(uint64_t input_num) {
   15|       |  return _popcnt64(input_num);
   16|  2.97k|}

_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|  13.3M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEcvRKDv2_xEv:
   18|  13.3M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEC2EDv2_x:
   16|   955k|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEcvRKDv2_xEv:
   18|   955k|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEanES5_:
   45|  2.86M|  simdutf_really_inline Child operator&(const Child other) const {
   46|  2.86M|    return _mm_and_si128(*this, other);
   47|  2.86M|  }

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

_ZNK7simdutf8westmere14implementation22convert_latin1_to_utf8EPKcmPc:
  441|    945|    const char *buf, size_t len, char *utf8_output) const noexcept {
  442|       |
  443|    945|  std::pair<const char *, char *> ret =
  444|    945|      sse_convert_latin1_to_utf8(buf, len, utf8_output);
  445|    945|  size_t converted_chars = ret.second - utf8_output;
  446|       |
  447|    945|  if (ret.first != buf + len) {
  ------------------
  |  Branch (447:7): [True: 799, False: 146]
  ------------------
  448|    799|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  449|    799|        ret.first, len - (ret.first - buf), ret.second);
  450|    799|    converted_chars += scalar_converted_chars;
  451|    799|  }
  452|       |
  453|    945|  return converted_chars;
  454|    945|}
_ZNK7simdutf8westmere14implementation23convert_utf16le_to_utf8EPKDsmPc:
  709|    742|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  710|    742|  std::pair<const char16_t *, char *> ret =
  711|    742|      sse_convert_utf16_to_utf8<endianness::LITTLE>(buf, len, utf8_output);
  712|    742|  if (ret.first == nullptr) {
  ------------------
  |  Branch (712:7): [True: 115, False: 627]
  ------------------
  713|    115|    return 0;
  714|    115|  }
  715|    627|  size_t saved_bytes = ret.second - utf8_output;
  716|    627|  if (ret.first != buf + len) {
  ------------------
  |  Branch (716:7): [True: 620, False: 7]
  ------------------
  717|    620|    const size_t scalar_saved_bytes =
  718|    620|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  719|    620|            ret.first, len - (ret.first - buf), ret.second);
  720|    620|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (720:9): [True: 123, False: 497]
  ------------------
  721|    123|      return 0;
  722|    123|    }
  723|    497|    saved_bytes += scalar_saved_bytes;
  724|    497|  }
  725|    504|  return saved_bytes;
  726|    627|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16leEPKDsm:
 1140|    388|    const char16_t *input, size_t length) const noexcept {
 1141|    388|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1142|    388|                                                                    length);
 1143|    388|}
_ZNK7simdutf8westmere14implementation23utf8_length_from_latin1EPKcm:
 1153|    289|    const char *input, size_t len) const noexcept {
 1154|    289|  const uint8_t *str = reinterpret_cast<const uint8_t *>(input);
 1155|    289|  size_t answer = len / sizeof(__m128i) * sizeof(__m128i);
 1156|    289|  size_t i = 0;
 1157|    289|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1157:7): [True: 130, False: 159]
  ------------------
 1158|    130|    __m128i two_64bits = _mm_setzero_si128();
 1159|  4.58k|    while (i + sizeof(__m128i) <= len) {
  ------------------
  |  Branch (1159:12): [True: 4.45k, False: 130]
  ------------------
 1160|  4.45k|      __m128i runner = _mm_setzero_si128();
 1161|  4.45k|      size_t iterations = (len - i) / sizeof(__m128i);
 1162|  4.45k|      if (iterations > 255) {
  ------------------
  |  Branch (1162:11): [True: 4.32k, False: 130]
  ------------------
 1163|  4.32k|        iterations = 255;
 1164|  4.32k|      }
 1165|  4.45k|      size_t max_i = i + iterations * sizeof(__m128i) - sizeof(__m128i);
 1166|   279k|      for (; i + 4 * sizeof(__m128i) <= max_i; i += 4 * sizeof(__m128i)) {
  ------------------
  |  Branch (1166:14): [True: 275k, False: 4.45k]
  ------------------
 1167|   275k|        __m128i input1 = _mm_loadu_si128((const __m128i *)(str + i));
 1168|   275k|        __m128i input2 =
 1169|   275k|            _mm_loadu_si128((const __m128i *)(str + i + sizeof(__m128i)));
 1170|   275k|        __m128i input3 =
 1171|   275k|            _mm_loadu_si128((const __m128i *)(str + i + 2 * sizeof(__m128i)));
 1172|   275k|        __m128i input4 =
 1173|   275k|            _mm_loadu_si128((const __m128i *)(str + i + 3 * sizeof(__m128i)));
 1174|   275k|        __m128i input12 =
 1175|   275k|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input1),
 1176|   275k|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input2));
 1177|   275k|        __m128i input34 =
 1178|   275k|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input3),
 1179|   275k|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input4));
 1180|   275k|        __m128i input1234 = _mm_add_epi8(input12, input34);
 1181|   275k|        runner = _mm_sub_epi8(runner, input1234);
 1182|   275k|      }
 1183|  17.7k|      for (; i <= max_i; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1183:14): [True: 13.2k, False: 4.45k]
  ------------------
 1184|  13.2k|        __m128i more_input = _mm_loadu_si128((const __m128i *)(str + i));
 1185|  13.2k|        runner = _mm_sub_epi8(runner,
 1186|  13.2k|                              _mm_cmpgt_epi8(_mm_setzero_si128(), more_input));
 1187|  13.2k|      }
 1188|  4.45k|      two_64bits =
 1189|  4.45k|          _mm_add_epi64(two_64bits, _mm_sad_epu8(runner, _mm_setzero_si128()));
 1190|  4.45k|    }
 1191|    130|    answer +=
 1192|    130|        _mm_extract_epi64(two_64bits, 0) + _mm_extract_epi64(two_64bits, 1);
 1193|    159|  } else if (answer > 0) { // short string optimization
  ------------------
  |  Branch (1193:14): [True: 116, False: 43]
  ------------------
 1194|  1.57k|    for (; i + 2 * sizeof(__m128i) <= len; i += 2 * sizeof(__m128i)) {
  ------------------
  |  Branch (1194:12): [True: 1.45k, False: 116]
  ------------------
 1195|  1.45k|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1196|  1.45k|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1197|  1.45k|      answer += count_ones(non_ascii);
 1198|  1.45k|      latin = _mm_loadu_si128((const __m128i *)(input + i) + 1);
 1199|  1.45k|      non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1200|  1.45k|      answer += count_ones(non_ascii);
 1201|  1.45k|    }
 1202|    178|    for (; i + sizeof(__m128i) <= len; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1202:12): [True: 62, False: 116]
  ------------------
 1203|     62|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1204|     62|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1205|     62|      answer += count_ones(non_ascii);
 1206|     62|    }
 1207|    116|  }
 1208|    289|  return answer + scalar::latin1::utf8_length_from_latin1(
 1209|    289|                      reinterpret_cast<const char *>(str + i), len - i);
 1210|    289|}

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

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_126sse_convert_latin1_to_utf8EPKcmPc:
    3|    945|                           const size_t latin_input_length, char *utf8_output) {
    4|    945|  const char *end = latin_input + latin_input_length;
    5|       |
    6|    945|  const __m128i v_0000 = _mm_setzero_si128();
    7|       |  // 0b1000_0000
    8|    945|  const __m128i v_80 = _mm_set1_epi8((uint8_t)0x80);
    9|       |  // 0b1111_1111_1000_0000
   10|    945|  const __m128i v_ff80 = _mm_set1_epi16((uint16_t)0xff80);
   11|       |
   12|    945|  const __m128i latin_1_half_into_u16_byte_mask =
   13|    945|      _mm_setr_epi8(0, '\x80', 1, '\x80', 2, '\x80', 3, '\x80', 4, '\x80', 5,
   14|    945|                    '\x80', 6, '\x80', 7, '\x80');
   15|       |
   16|    945|  const __m128i latin_2_half_into_u16_byte_mask =
   17|    945|      _mm_setr_epi8(8, '\x80', 9, '\x80', 10, '\x80', 11, '\x80', 12, '\x80',
   18|    945|                    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.23M|  while (end - latin_input >= 16 + 8) {
  ------------------
  |  Branch (25:10): [True: 1.23M, False: 945]
  ------------------
   26|       |    // Load 16 Latin1 characters (16 bytes) into a 128-bit register
   27|  1.23M|    __m128i v_latin = _mm_loadu_si128((__m128i *)latin_input);
   28|       |
   29|  1.23M|    if (_mm_testz_si128(v_latin, v_80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (29:9): [True: 610k, False: 621k]
  ------------------
   30|   610k|      _mm_storeu_si128((__m128i *)utf8_output, v_latin);
   31|   610k|      latin_input += 16;
   32|   610k|      utf8_output += 16;
   33|   610k|      continue;
   34|   610k|    }
   35|       |
   36|       |    // assuming a/b are bytes and A/B are uint16 of the same value
   37|       |    // aaaa_aaaa_bbbb_bbbb -> AAAA_AAAA
   38|   621k|    __m128i v_u16_latin_1_half =
   39|   621k|        _mm_shuffle_epi8(v_latin, latin_1_half_into_u16_byte_mask);
   40|       |    // aaaa_aaaa_bbbb_bbbb -> BBBB_BBBB
   41|   621k|    __m128i v_u16_latin_2_half =
   42|   621k|        _mm_shuffle_epi8(v_latin, latin_2_half_into_u16_byte_mask);
   43|       |
   44|   621k|    internal::westmere::write_v_u16_11bits_to_utf8(v_u16_latin_1_half,
   45|   621k|                                                   utf8_output, v_0000, v_ff80);
   46|   621k|    internal::westmere::write_v_u16_11bits_to_utf8(v_u16_latin_2_half,
   47|   621k|                                                   utf8_output, v_0000, v_ff80);
   48|   621k|    latin_input += 16;
   49|   621k|  }
   50|       |
   51|    945|  if (end - latin_input >= 16) {
  ------------------
  |  Branch (51:7): [True: 504, False: 441]
  ------------------
   52|       |    // Load 16 Latin1 characters (16 bytes) into a 128-bit register
   53|    504|    __m128i v_latin = _mm_loadu_si128((__m128i *)latin_input);
   54|       |
   55|    504|    if (_mm_testz_si128(v_latin, v_80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (55:9): [True: 268, False: 236]
  ------------------
   56|    268|      _mm_storeu_si128((__m128i *)utf8_output, v_latin);
   57|    268|      latin_input += 16;
   58|    268|      utf8_output += 16;
   59|    268|    } else {
   60|       |      // assuming a/b are bytes and A/B are uint16 of the same value
   61|       |      // aaaa_aaaa_bbbb_bbbb -> AAAA_AAAA
   62|    236|      __m128i v_u16_latin_1_half =
   63|    236|          _mm_shuffle_epi8(v_latin, latin_1_half_into_u16_byte_mask);
   64|    236|      internal::westmere::write_v_u16_11bits_to_utf8(
   65|    236|          v_u16_latin_1_half, utf8_output, v_0000, v_ff80);
   66|    236|      latin_input += 8;
   67|    236|    }
   68|    504|  }
   69|       |
   70|    945|  return std::make_pair(latin_input, utf8_output);
   71|    945|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_125sse_convert_utf16_to_utf8ILNS_10endiannessE0EEENSt3__14pairIPKDsPcEES7_mS8_:
   56|    742|sse_convert_utf16_to_utf8(const char16_t *buf, size_t len, char *utf8_output) {
   57|       |
   58|    742|  const char16_t *end = buf + len;
   59|       |
   60|    742|  const __m128i v_0000 = _mm_setzero_si128();
   61|    742|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
   62|    742|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
   63|    742|  const size_t safety_margin =
   64|    742|      12; // to avoid overruns, see issue
   65|       |          // https://github.com/simdutf/simdutf/issues/92
   66|       |
   67|   285k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (67:10): [True: 285k, False: 627]
  ------------------
   68|   285k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
   69|   285k|    if (big_endian) {
  ------------------
  |  Branch (69:9): [Folded, False: 285k]
  ------------------
   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|   285k|    const __m128i v_ff80 = _mm_set1_epi16((int16_t)0xff80);
   76|   285k|    if (_mm_testz_si128(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (76:9): [True: 126k, False: 158k]
  ------------------
   77|   126k|      __m128i nextin = _mm_loadu_si128((__m128i *)buf + 1);
   78|   126k|      if (big_endian) {
  ------------------
  |  Branch (78:11): [Folded, False: 126k]
  ------------------
   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|   126k|      if (!_mm_testz_si128(nextin, v_ff80)) {
  ------------------
  |  Branch (83:11): [True: 2.11k, False: 124k]
  ------------------
   84|       |        // 1. pack the bytes
   85|       |        // obviously suboptimal.
   86|  2.11k|        const __m128i utf8_packed = _mm_packus_epi16(in, in);
   87|       |        // 2. store (16 bytes)
   88|  2.11k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   89|       |        // 3. adjust pointers
   90|  2.11k|        buf += 8;
   91|  2.11k|        utf8_output += 8;
   92|  2.11k|        in = nextin;
   93|   124k|      } else {
   94|       |        // 1. pack the bytes
   95|       |        // obviously suboptimal.
   96|   124k|        const __m128i utf8_packed = _mm_packus_epi16(in, nextin);
   97|       |        // 2. store (16 bytes)
   98|   124k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   99|       |        // 3. adjust pointers
  100|   124k|        buf += 16;
  101|   124k|        utf8_output += 16;
  102|   124k|        continue; // we are done for this round!
  103|   124k|      }
  104|   126k|    }
  105|       |
  106|       |    // no bits set above 7th bit
  107|   160k|    const __m128i one_byte_bytemask =
  108|   160k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_ff80), v_0000);
  109|   160k|    const uint16_t one_byte_bitmask =
  110|   160k|        static_cast<uint16_t>(_mm_movemask_epi8(one_byte_bytemask));
  111|       |
  112|       |    // no bits set above 11th bit
  113|   160k|    const __m128i one_or_two_bytes_bytemask =
  114|   160k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_0000);
  115|   160k|    const uint16_t one_or_two_bytes_bitmask =
  116|   160k|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  117|       |
  118|   160k|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (118:9): [True: 71.5k, False: 88.9k]
  ------------------
  119|  71.5k|      internal::westmere::write_v_u16_11bits_to_utf8(
  120|  71.5k|          in, utf8_output, one_byte_bytemask, one_byte_bitmask);
  121|  71.5k|      buf += 8;
  122|  71.5k|      continue;
  123|  71.5k|    }
  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|  88.9k|    const __m128i surrogates_bytemask =
  129|  88.9k|        _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|  88.9k|    const uint16_t surrogates_bitmask =
  134|  88.9k|        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|  88.9k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (137:9): [True: 86.5k, False: 2.41k]
  ------------------
  138|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  139|  86.5k|      const __m128i dup_even = _mm_setr_epi16(0x0000, 0x0202, 0x0404, 0x0606,
  140|  86.5k|                                              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|  86.5k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  170|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  171|  86.5k|      const __m128i t0 = _mm_shuffle_epi8(in, dup_even);
  172|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  173|  86.5k|      const __m128i t1 = _mm_and_si128(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  169|  86.5k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  174|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  175|  86.5k|      const __m128i t2 = _mm_or_si128(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  169|  86.5k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  176|       |
  177|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  178|  86.5k|      const __m128i s0 = _mm_srli_epi16(in, 4);
  179|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  180|  86.5k|      const __m128i s1 = _mm_and_si128(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  169|  86.5k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  181|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  182|  86.5k|      const __m128i s2 = _mm_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  169|  86.5k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  183|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  184|  86.5k|      const __m128i s3 = _mm_or_si128(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  169|  86.5k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  185|  86.5k|      const __m128i m0 = _mm_andnot_si128(one_or_two_bytes_bytemask,
  186|  86.5k|                                          simdutf_vec(0b0100000000000000));
  ------------------
  |  |  169|  86.5k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  187|  86.5k|      const __m128i s4 = _mm_xor_si128(s3, m0);
  188|  86.5k|#undef simdutf_vec
  189|       |
  190|       |      // 4. expand code units 16-bit => 32-bit
  191|  86.5k|      const __m128i out0 = _mm_unpacklo_epi16(t2, s4);
  192|  86.5k|      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|  86.5k|      const uint16_t mask =
  196|  86.5k|          (one_byte_bitmask & 0x5555) | (one_or_two_bytes_bitmask & 0xaaaa);
  197|  86.5k|      if (mask == 0) {
  ------------------
  |  Branch (197:11): [True: 65.1k, False: 21.4k]
  ------------------
  198|       |        // We only have three-byte code units. Use fast path.
  199|  65.1k|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  200|  65.1k|                                              15, 13, -1, -1, -1, -1);
  201|  65.1k|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  202|  65.1k|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  203|  65.1k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  204|  65.1k|        utf8_output += 12;
  205|  65.1k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  206|  65.1k|        utf8_output += 12;
  207|  65.1k|        buf += 8;
  208|  65.1k|        continue;
  209|  65.1k|      }
  210|  21.4k|      const uint8_t mask0 = uint8_t(mask);
  211|       |
  212|  21.4k|      const uint8_t *row0 =
  213|  21.4k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  214|  21.4k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  215|  21.4k|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  216|       |
  217|  21.4k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  218|       |
  219|  21.4k|      const uint8_t *row1 =
  220|  21.4k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  221|  21.4k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  222|  21.4k|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  223|       |
  224|  21.4k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  225|  21.4k|      utf8_output += row0[0];
  226|  21.4k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  227|  21.4k|      utf8_output += row1[0];
  228|       |
  229|  21.4k|      buf += 8;
  230|       |      // surrogate pair(s) in a register
  231|  21.4k|    } 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|  2.41k|      size_t forward = 15;
  236|  2.41k|      size_t k = 0;
  237|  2.41k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (237:11): [True: 0, False: 2.41k]
  ------------------
  238|      0|        forward = size_t(end - buf - 1);
  239|      0|      }
  240|  34.2k|      for (; k < forward; k++) {
  ------------------
  |  Branch (240:14): [True: 31.9k, False: 2.30k]
  ------------------
  241|  31.9k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  242|  31.9k|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (242:13): [True: 11.7k, False: 20.1k]
  ------------------
  243|  11.7k|          *utf8_output++ = char(word);
  244|  20.1k|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (244:20): [True: 3.14k, False: 17.0k]
  ------------------
  245|  3.14k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  246|  3.14k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  247|  17.0k|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (247:20): [True: 13.6k, False: 3.32k]
  ------------------
  248|  13.6k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  249|  13.6k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  250|  13.6k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  251|  13.6k|        } else {
  252|       |          // must be a surrogate pair
  253|  3.32k|          uint16_t diff = uint16_t(word - 0xD800);
  254|  3.32k|          uint16_t next_word =
  255|  3.32k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  256|  3.32k|          k++;
  257|  3.32k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  258|  3.32k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (258:15): [True: 115, False: 3.20k]
  ------------------
  259|    115|            return std::make_pair(nullptr, utf8_output);
  260|    115|          }
  261|  3.20k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  262|  3.20k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  263|  3.20k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  264|  3.20k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  265|  3.20k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  266|  3.20k|        }
  267|  31.9k|      }
  268|  2.30k|      buf += k;
  269|  2.30k|    }
  270|  88.9k|  } // while
  271|       |
  272|    627|  return std::make_pair(buf, utf8_output);
  273|    742|}

_ZN7simdutf22utf8_length_from_utf16ENSt3__14spanIKDsLm18446744073709551615EEE:
 3405|  1.00k|utf8_length_from_utf16(std::span<const char16_t> valid_utf16_input) noexcept {
 3406|       |    #if SIMDUTF_CPLUSPLUS23
 3407|       |  if consteval {
 3408|       |    return scalar::utf16::utf8_length_from_utf16<endianness::NATIVE>(
 3409|       |        valid_utf16_input.data(), valid_utf16_input.size());
 3410|       |  } else
 3411|       |    #endif
 3412|  1.00k|  {
 3413|  1.00k|    return utf8_length_from_utf16(valid_utf16_input.data(),
 3414|  1.00k|                                  valid_utf16_input.size());
 3415|  1.00k|  }
 3416|  1.00k|}
safe_conversion.cpp:_ZN7simdutf6detail12_GLOBAL__N_13minEmm:
   59|  1.00k|constexpr std::size_t min(std::size_t a, std::size_t b) {
   60|  1.00k|  return a < b ? a : b;
  ------------------
  |  Branch (60:10): [True: 117, False: 884]
  ------------------
   61|  1.00k|}
_ZN7simdutf27convert_latin1_to_utf8_safeITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  920|    733|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
  921|       |      // implementation note: outputspan is a forwarding ref to avoid copying
  922|       |      // and allow both lvalues and rvalues. std::span can be copied without
  923|       |      // problems, but std::vector should not, and this function should accept
  924|       |      // both. it will allow using an owning rvalue ref (example: passing a
  925|       |      // temporary std::string) as output, but the user will quickly find out
  926|       |      // that he has no way of getting the data out of the object in that case.
  927|       |    #if SIMDUTF_CPLUSPLUS23
  928|       |  if consteval {
  929|       |    return scalar::latin1_to_utf8::convert_safe_constexpr(
  930|       |        input.data(), input.size(), utf8_output.data(), utf8_output.size());
  931|       |  } else
  932|       |    #endif
  933|    733|  {
  934|    733|    return convert_latin1_to_utf8_safe(
  935|    733|        reinterpret_cast<const char *>(input.data()), input.size(),
  936|    733|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
  937|    733|  }
  938|    733|}
_ZN7simdutf23utf8_length_from_latin1ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEEEEmRKT_:
 1974|    733|    const detail::input_span_of_byte_like auto &latin1_input) noexcept {
 1975|       |    #if SIMDUTF_CPLUSPLUS23
 1976|       |  if consteval {
 1977|       |    return scalar::latin1_to_utf8::utf8_length_from_latin1(latin1_input.data(),
 1978|       |                                                           latin1_input.size());
 1979|       |  } else
 1980|       |    #endif
 1981|    733|  {
 1982|    733|    return utf8_length_from_latin1(
 1983|    733|        reinterpret_cast<const char *>(latin1_input.data()),
 1984|    733|        latin1_input.size());
 1985|    733|  }
 1986|    733|}
_ZN7simdutf22convert_latin1_to_utf8ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  877|    733|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
  878|       |    #if SIMDUTF_CPLUSPLUS23
  879|       |  if consteval {
  880|       |    return scalar::latin1_to_utf8::convert(
  881|       |        detail::constexpr_cast_ptr<char>(latin1_input.data()),
  882|       |        latin1_input.size(),
  883|       |        detail::constexpr_cast_writeptr<char>(utf8_output.data()));
  884|       |  } else
  885|       |    #endif
  886|    733|  {
  887|    733|    return convert_latin1_to_utf8(
  888|    733|        reinterpret_cast<const char *>(latin1_input.data()),
  889|    733|        latin1_input.size(), reinterpret_cast<char *>(utf8_output.data()));
  890|    733|  }
  891|    733|}
_ZN7simdutf26convert_utf16_to_utf8_safeITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 2217|  1.00k|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
 2218|       |      // implementation note: outputspan is a forwarding ref to avoid copying
 2219|       |      // and allow both lvalues and rvalues. std::span can be copied without
 2220|       |      // problems, but std::vector should not, and this function should accept
 2221|       |      // both. it will allow using an owning rvalue ref (example: passing a
 2222|       |      // temporary std::string) as output, but the user will quickly find out
 2223|       |      // that he has no way of getting the data out of the object in that case.
 2224|       |    #if SIMDUTF_CPLUSPLUS23
 2225|       |  if consteval {
 2226|       |    const full_result r =
 2227|       |        scalar::utf16_to_utf8::convert_with_errors<endianness::NATIVE, true>(
 2228|       |            utf16_input.data(), utf16_input.size(), utf8_output.data(),
 2229|       |            utf8_output.size());
 2230|       |    if (r.error != error_code::SUCCESS &&
 2231|       |        r.error != error_code::OUTPUT_BUFFER_TOO_SMALL) {
 2232|       |      return 0;
 2233|       |    }
 2234|       |    return r.output_count;
 2235|       |  } else
 2236|       |    #endif
 2237|  1.00k|  {
 2238|  1.00k|    return convert_utf16_to_utf8_safe(
 2239|  1.00k|        utf16_input.data(), utf16_input.size(),
 2240|  1.00k|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
 2241|  1.00k|  }
 2242|  1.00k|}
_ZN7simdutf21convert_utf16_to_utf8ITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 2172|  1.00k|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
 2173|       |    #if SIMDUTF_CPLUSPLUS23
 2174|       |  if consteval {
 2175|       |    return scalar::utf16_to_utf8::convert<endianness::NATIVE>(
 2176|       |        utf16_input.data(), utf16_input.size(), utf8_output.data());
 2177|       |  } else
 2178|       |    #endif
 2179|  1.00k|  {
 2180|  1.00k|    return convert_utf16_to_utf8(utf16_input.data(), utf16_input.size(),
 2181|  1.00k|                                 reinterpret_cast<char *>(utf8_output.data()));
 2182|  1.00k|  }
 2183|  1.00k|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEaSEPS3_:
 7617|  1.73k|  atomic_ptr &operator=(T *_ptr) {
 7618|  1.73k|    ptr = _ptr;
 7619|  1.73k|    return *this;
 7620|  1.73k|  }

