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

_ZN7simdutf11full_resultC2ENS_10error_codeEmm:
  111|    817|      : 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.12k|constexpr std::size_t min(std::size_t a, std::size_t b) {
   60|  4.12k|  return a < b ? a : b;
  ------------------
  |  Branch (60:10): [True: 1.37k, False: 2.74k]
  ------------------
   61|  4.12k|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEC2EPS3_:
 7594|      1|  atomic_ptr(T *_ptr) : ptr{_ptr} {}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEptEv:
 7616|  5.98k|  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|    550|                                                     size_t len) {
   11|    550|  const uint8_t *c = reinterpret_cast<const uint8_t *>(buf);
   12|    550|  size_t answer = 0;
   13|  4.31k|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (13:22): [True: 3.76k, False: 550]
  ------------------
   14|  3.76k|    if ((c[i] >> 7)) {
  ------------------
  |  Branch (14:9): [True: 1.10k, False: 2.66k]
  ------------------
   15|  1.10k|      answer++;
   16|  1.10k|    }
   17|  3.76k|  }
   18|    550|  return answer + len;
   19|    550|}

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

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

_ZN7simdutf6scalar5utf1614high_surrogateEDs:
  147|    801|simdutf_unused simdutf_really_inline constexpr bool high_surrogate(char16_t c) {
  148|    801|  return (0xd800 <= c && c <= 0xdbff);
  ------------------
  |  Branch (148:11): [True: 98, False: 703]
  |  Branch (148:26): [True: 48, False: 50]
  ------------------
  149|    801|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE0EEEmPKDsm:
   91|    984|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|    984|  size_t counter{0};
   94|  7.57M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 7.57M, False: 984]
  ------------------
   95|  7.57M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|  7.57M|    counter++; // ASCII
   97|  7.57M|    counter += static_cast<size_t>(
   98|  7.57M|        word >
   99|  7.57M|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|  7.57M|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 1.12M, False: 6.44M]
  |  Branch (100:53): [True: 989k, False: 136k]
  ------------------
  101|  6.58M|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 129k, False: 6.45M]
  ------------------
  102|  7.57M|  }
  103|    984|  return counter;
  104|    984|}

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

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

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

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

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

_ZNK7simdutf7haswell14implementation22convert_latin1_to_utf8EPKcmPc:
  412|    837|    const char *buf, size_t len, char *utf8_output) const noexcept {
  413|    837|  std::pair<const char *, char *> ret =
  414|    837|      avx2_convert_latin1_to_utf8(buf, len, utf8_output);
  415|    837|  size_t converted_chars = ret.second - utf8_output;
  416|       |
  417|    837|  if (ret.first != buf + len) {
  ------------------
  |  Branch (417:7): [True: 828, False: 9]
  ------------------
  418|    828|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  419|    828|        ret.first, len - (ret.first - buf), ret.second);
  420|    828|    converted_chars += scalar_converted_chars;
  421|    828|  }
  422|       |
  423|    837|  return converted_chars;
  424|    837|}
_ZNK7simdutf7haswell14implementation23convert_utf16le_to_utf8EPKDsmPc:
  679|    698|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  680|    698|  std::pair<const char16_t *, char *> ret =
  681|    698|      haswell::avx2_convert_utf16_to_utf8<endianness::LITTLE>(buf, len,
  682|    698|                                                              utf8_output);
  683|    698|  if (ret.first == nullptr) {
  ------------------
  |  Branch (683:7): [True: 141, False: 557]
  ------------------
  684|    141|    return 0;
  685|    141|  }
  686|    557|  size_t saved_bytes = ret.second - utf8_output;
  687|    557|  if (ret.first != buf + len) {
  ------------------
  |  Branch (687:7): [True: 548, False: 9]
  ------------------
  688|    548|    const size_t scalar_saved_bytes =
  689|    548|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  690|    548|            ret.first, len - (ret.first - buf), ret.second);
  691|    548|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (691:9): [True: 108, False: 440]
  ------------------
  692|    108|      return 0;
  693|    108|    }
  694|    440|    saved_bytes += scalar_saved_bytes;
  695|    440|  }
  696|    449|  return saved_bytes;
  697|    557|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16leEPKDsm:
 1114|    377|    const char16_t *input, size_t length) const noexcept {
 1115|    377|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1116|    377|                                                                    length);
 1117|    377|}
_ZNK7simdutf7haswell14implementation23utf8_length_from_latin1EPKcm:
 1180|    275|    const char *input, size_t len) const noexcept {
 1181|    275|  const uint8_t *data = reinterpret_cast<const uint8_t *>(input);
 1182|    275|  size_t answer = len / sizeof(__m256i) * sizeof(__m256i);
 1183|    275|  size_t i = 0;
 1184|    275|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1184:7): [True: 121, False: 154]
  ------------------
 1185|    121|    __m256i four_64bits = _mm256_setzero_si256();
 1186|  2.90k|    while (i + sizeof(__m256i) <= len) {
  ------------------
  |  Branch (1186:12): [True: 2.77k, False: 121]
  ------------------
 1187|  2.77k|      __m256i runner = _mm256_setzero_si256();
 1188|       |      // We can do up to 255 loops without overflow.
 1189|  2.77k|      size_t iterations = (len - i) / sizeof(__m256i);
 1190|  2.77k|      if (iterations > 255) {
  ------------------
  |  Branch (1190:11): [True: 2.65k, False: 121]
  ------------------
 1191|  2.65k|        iterations = 255;
 1192|  2.65k|      }
 1193|  2.77k|      size_t max_i = i + iterations * sizeof(__m256i) - sizeof(__m256i);
 1194|   172k|      for (; i + 4 * sizeof(__m256i) <= max_i; i += 4 * sizeof(__m256i)) {
  ------------------
  |  Branch (1194:14): [True: 169k, False: 2.77k]
  ------------------
 1195|   169k|        __m256i input1 = _mm256_loadu_si256((const __m256i *)(data + i));
 1196|   169k|        __m256i input2 =
 1197|   169k|            _mm256_loadu_si256((const __m256i *)(data + i + sizeof(__m256i)));
 1198|   169k|        __m256i input3 = _mm256_loadu_si256(
 1199|   169k|            (const __m256i *)(data + i + 2 * sizeof(__m256i)));
 1200|   169k|        __m256i input4 = _mm256_loadu_si256(
 1201|   169k|            (const __m256i *)(data + i + 3 * sizeof(__m256i)));
 1202|   169k|        __m256i input12 =
 1203|   169k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input1),
 1204|   169k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input2));
 1205|   169k|        __m256i input23 =
 1206|   169k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input3),
 1207|   169k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input4));
 1208|   169k|        __m256i input1234 = _mm256_add_epi8(input12, input23);
 1209|   169k|        runner = _mm256_sub_epi8(runner, input1234);
 1210|   169k|      }
 1211|  11.0k|      for (; i <= max_i; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1211:14): [True: 8.28k, False: 2.77k]
  ------------------
 1212|  8.28k|        __m256i input_256_chunk =
 1213|  8.28k|            _mm256_loadu_si256((const __m256i *)(data + i));
 1214|  8.28k|        runner = _mm256_sub_epi8(
 1215|  8.28k|            runner, _mm256_cmpgt_epi8(_mm256_setzero_si256(), input_256_chunk));
 1216|  8.28k|      }
 1217|  2.77k|      four_64bits = _mm256_add_epi64(
 1218|  2.77k|          four_64bits, _mm256_sad_epu8(runner, _mm256_setzero_si256()));
 1219|  2.77k|    }
 1220|    121|    answer += _mm256_extract_epi64(four_64bits, 0) +
 1221|    121|              _mm256_extract_epi64(four_64bits, 1) +
 1222|    121|              _mm256_extract_epi64(four_64bits, 2) +
 1223|    121|              _mm256_extract_epi64(four_64bits, 3);
 1224|    154|  } else if (answer > 0) {
  ------------------
  |  Branch (1224:14): [True: 74, False: 80]
  ------------------
 1225|  1.34k|    for (; i + sizeof(__m256i) <= len; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1225:12): [True: 1.27k, False: 74]
  ------------------
 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|     74|  }
 1231|    275|  return answer + scalar::latin1::utf8_length_from_latin1(
 1232|    275|                      reinterpret_cast<const char *>(data + i), len - i);
 1233|    275|}

_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.68k|get_active_implementation() {
 1597|  7.68k|#if !SIMDUTF_USE_STATIC_INITIALIZATION
 1598|  7.68k|  #if !SIMDUTF_SINGLE_IMPLEMENTATION
 1599|  7.68k|  static const internal::detect_best_supported_implementation_on_first_use
 1600|  7.68k|      detect_best_supported_implementation_on_first_use_singleton;
 1601|  7.68k|  #endif
 1602|  7.68k|  static internal::atomic_ptr<const implementation>
 1603|  7.68k|      active_implementation_instance{
 1604|       |  #if SIMDUTF_SINGLE_IMPLEMENTATION
 1605|       |          internal::get_single_implementation()
 1606|       |  #else
 1607|  7.68k|          &detect_best_supported_implementation_on_first_use_singleton
 1608|  7.68k|  #endif
 1609|  7.68k|      };
 1610|  7.68k|#endif
 1611|  7.68k|  return active_implementation_instance;
 1612|  7.68k|}
_ZN7simdutf22convert_latin1_to_utf8EPKcmPc:
 1678|  2.21k|                                                  char *utf8_output) noexcept {
 1679|  2.21k|  return get_default_implementation()->convert_latin1_to_utf8(buf, len,
 1680|  2.21k|                                                              utf8_output);
 1681|  2.21k|}
_ZN7simdutf21convert_utf16_to_utf8EPKDsmPc:
 1964|  2.07k|                                                 char *utf8_buffer) noexcept {
 1965|       |  #if SIMDUTF_IS_BIG_ENDIAN
 1966|       |  return convert_utf16be_to_utf8(buf, len, utf8_buffer);
 1967|       |  #else
 1968|  2.07k|  return convert_utf16le_to_utf8(buf, len, utf8_buffer);
 1969|  2.07k|  #endif
 1970|  2.07k|}
_ZN7simdutf26convert_utf16_to_utf8_safeEPKDsmPcm:
 1974|    984|                           size_t utf8_len) noexcept {
 1975|    984|  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.90k|  while (true) {
  ------------------
  |  Branch (1980:10): [True: 1.90k, 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.90k|    auto read_len = detail::min(len, utf8_len / 3);
 1985|  1.90k|    if (read_len <= 16) {
  ------------------
  |  Branch (1985:9): [True: 817, False: 1.09k]
  ------------------
 1986|    817|      break;
 1987|    817|    }
 1988|  1.09k|    if (read_len < len) {
  ------------------
  |  Branch (1988:9): [True: 801, False: 289]
  ------------------
 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|    801|      if (scalar::utf16::high_surrogate(buf[read_len - 1])) {
  ------------------
  |  Branch (1991:11): [True: 48, False: 753]
  ------------------
 1992|     48|        read_len--;
 1993|     48|      }
 1994|    801|    }
 1995|  1.09k|    if (read_len == 0) {
  ------------------
  |  Branch (1995:9): [True: 0, False: 1.09k]
  ------------------
 1996|       |      // If we cannot read anything, we are done.
 1997|      0|      break;
 1998|      0|    }
 1999|  1.09k|    const auto write_len =
 2000|  1.09k|        simdutf::convert_utf16_to_utf8(buf, read_len, utf8_output);
 2001|  1.09k|    if (write_len == 0) {
  ------------------
  |  Branch (2001:9): [True: 167, False: 923]
  ------------------
 2002|       |      // There was an error in the conversion, we cannot continue.
 2003|    167|      return 0; // indicating failure
 2004|    167|    }
 2005|       |
 2006|    923|    utf8_output += write_len;
 2007|    923|    utf8_len -= write_len;
 2008|    923|    buf += read_len;
 2009|    923|    len -= read_len;
 2010|    923|  }
 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|    817|  full_result r =
 2017|    817|      scalar::utf16_to_utf8::convert_with_errors<endianness::LITTLE, true>(
 2018|    817|          buf, len, utf8_output, utf8_len);
 2019|    817|  #endif
 2020|    817|  if (r.error != error_code::SUCCESS &&
  ------------------
  |  Branch (2020:7): [True: 339, False: 478]
  ------------------
 2021|    339|      r.error != error_code::OUTPUT_BUFFER_TOO_SMALL) {
  ------------------
  |  Branch (2021:7): [True: 101, False: 238]
  ------------------
 2022|       |    // If there was an error, we return 0 to indicate failure.
 2023|    101|    return 0; // indicating failure
 2024|    101|  }
 2025|    716|  return r.output_count + (utf8_output - start);
 2026|    817|}
_ZN7simdutf23convert_utf16le_to_utf8EPKDsmPc:
 2150|  2.07k|                                                   char *utf8_buffer) noexcept {
 2151|  2.07k|  return get_default_implementation()->convert_utf16le_to_utf8(buf, len,
 2152|  2.07k|                                                               utf8_buffer);
 2153|  2.07k|}
_ZN7simdutf23utf8_length_from_latin1EPKcm:
 2416|    713|                                                   size_t len) noexcept {
 2417|    713|  return get_default_implementation()->utf8_length_from_latin1(buf, len);
 2418|    713|}
_ZN7simdutf22utf8_length_from_utf16EPKDsm:
 2423|    984|                                                  size_t length) noexcept {
 2424|       |  #if SIMDUTF_IS_BIG_ENDIAN
 2425|       |  return utf8_length_from_utf16be(input, length);
 2426|       |  #else
 2427|    984|  return utf8_length_from_utf16le(input, length);
 2428|    984|  #endif
 2429|    984|}
_ZN7simdutf24utf8_length_from_utf16leEPKDsm:
 2439|    984|                                                    size_t length) noexcept {
 2440|    984|  return get_default_implementation()->utf8_length_from_utf16le(input, length);
 2441|    984|}
_ZN7simdutf27convert_latin1_to_utf8_safeEPKcmPcm:
 2694|    713|    const char *buf, size_t len, char *utf8_output, size_t utf8_len) noexcept {
 2695|    713|  const auto start{utf8_output};
 2696|       |
 2697|  2.21k|  while (true) {
  ------------------
  |  Branch (2697:10): [True: 2.21k, Folded]
  ------------------
 2698|       |    // convert_latin1_to_utf8 will never write more than input length * 2
 2699|  2.21k|    auto read_len = detail::min(len, utf8_len >> 1);
 2700|  2.21k|    if (read_len <= 16) {
  ------------------
  |  Branch (2700:9): [True: 713, False: 1.50k]
  ------------------
 2701|    713|      break;
 2702|    713|    }
 2703|       |
 2704|  1.50k|    const auto write_len =
 2705|  1.50k|        simdutf::convert_latin1_to_utf8(buf, read_len, utf8_output);
 2706|       |
 2707|  1.50k|    utf8_output += write_len;
 2708|  1.50k|    utf8_len -= write_len;
 2709|  1.50k|    buf += read_len;
 2710|  1.50k|    len -= read_len;
 2711|  1.50k|  }
 2712|       |
 2713|    713|  utf8_output +=
 2714|    713|      scalar::latin1_to_utf8::convert_safe(buf, len, utf8_output, utf8_len);
 2715|       |
 2716|    713|  return utf8_output - start;
 2717|    713|}
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.98k|get_default_implementation() {
 1621|  5.98k|  return get_active_implementation();
 1622|  5.98k|}

_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|    382|  static simdutf_really_inline simd16<T> zero() {
   63|    382|    return _mm256_setzero_si256();
   64|    382|  }
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|    382|  simdutf_really_inline uint64_t sum() const {
  171|    382|    const auto lo_u16 = _mm256_and_si256(value, _mm256_set1_epi32(0x0000ffff));
  172|    382|    const auto hi_u16 = _mm256_srli_epi32(value, 16);
  173|    382|    const auto sum_u32 = _mm256_add_epi32(lo_u16, hi_u16);
  174|       |
  175|    382|    const auto lo_u32 =
  176|    382|        _mm256_and_si256(sum_u32, _mm256_set1_epi64x(0xffffffff));
  177|    382|    const auto hi_u32 = _mm256_srli_epi64(sum_u32, 32);
  178|    382|    const auto sum_u64 = _mm256_add_epi64(lo_u32, hi_u32);
  179|       |
  180|    382|    return uint64_t(_mm256_extract_epi64(sum_u64, 0)) +
  181|    382|           uint64_t(_mm256_extract_epi64(sum_u64, 1)) +
  182|    382|           uint64_t(_mm256_extract_epi64(sum_u64, 2)) +
  183|       |           uint64_t(_mm256_extract_epi64(sum_u64, 3));
  184|    382|  }

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

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

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

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

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

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

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

_ZN7simdutf22utf8_length_from_utf16ENSt3__14spanIKDsLm18446744073709551615EEE:
 3405|    984|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|    984|  {
 3413|    984|    return utf8_length_from_utf16(valid_utf16_input.data(),
 3414|    984|                                  valid_utf16_input.size());
 3415|    984|  }
 3416|    984|}
safe_conversion.cpp:_ZN7simdutf6detail12_GLOBAL__N_13minEmm:
   59|    984|constexpr std::size_t min(std::size_t a, std::size_t b) {
   60|    984|  return a < b ? a : b;
  ------------------
  |  Branch (60:10): [True: 121, False: 863]
  ------------------
   61|    984|}
_ZN7simdutf27convert_latin1_to_utf8_safeITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  920|    713|    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|    713|  {
  934|    713|    return convert_latin1_to_utf8_safe(
  935|    713|        reinterpret_cast<const char *>(input.data()), input.size(),
  936|    713|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
  937|    713|  }
  938|    713|}
_ZN7simdutf23utf8_length_from_latin1ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEEEEmRKT_:
 1974|    713|    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|    713|  {
 1982|    713|    return utf8_length_from_latin1(
 1983|    713|        reinterpret_cast<const char *>(latin1_input.data()),
 1984|    713|        latin1_input.size());
 1985|    713|  }
 1986|    713|}
_ZN7simdutf22convert_latin1_to_utf8ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  877|    713|    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|    713|  {
  887|    713|    return convert_latin1_to_utf8(
  888|    713|        reinterpret_cast<const char *>(latin1_input.data()),
  889|    713|        latin1_input.size(), reinterpret_cast<char *>(utf8_output.data()));
  890|    713|  }
  891|    713|}
_ZN7simdutf26convert_utf16_to_utf8_safeITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 2217|    984|    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|    984|  {
 2238|    984|    return convert_utf16_to_utf8_safe(
 2239|    984|        utf16_input.data(), utf16_input.size(),
 2240|    984|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
 2241|    984|  }
 2242|    984|}
_ZN7simdutf21convert_utf16_to_utf8ITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 2172|    984|    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|    984|  {
 2180|    984|    return convert_utf16_to_utf8(utf16_input.data(), utf16_input.size(),
 2181|    984|                                 reinterpret_cast<char *>(utf8_output.data()));
 2182|    984|  }
 2183|    984|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEaSEPS3_:
 7617|  1.69k|  atomic_ptr &operator=(T *_ptr) {
 7618|  1.69k|    ptr = _ptr;
 7619|  1.69k|    return *this;
 7620|  1.69k|  }

