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

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

_ZNK7simdutf14implementation25required_instruction_setsEv:
 5143|      4|  virtual uint32_t required_instruction_sets() const {
 5144|      4|    return _required_instruction_sets;
 5145|      4|  }
_ZN7simdutf14implementationC2EPKcS2_j:
 7029|      5|      : _name(name), _description(description),
 7030|      5|        _required_instruction_sets(required_instruction_sets) {}
_ZN7simdutf8internal29available_implementation_listC2Ev:
 7061|      1|  simdutf_really_inline available_implementation_list() {}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEC2EPS3_:
 7109|      1|  atomic_ptr(T *_ptr) : ptr{_ptr} {}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEptEv:
 7131|  5.90k|  T *operator->() { return ptr.load(); }

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

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

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf812convert_safeEPKcmPcm:
   70|    735|                           size_t utf8_len) {
   71|    735|  const unsigned char *data = reinterpret_cast<const unsigned char *>(buf);
   72|    735|  size_t pos = 0;
   73|    735|  size_t skip_pos = 0;
   74|    735|  size_t utf8_pos = 0;
   75|  4.23k|  while (pos < len && utf8_pos < utf8_len) {
  ------------------
  |  Branch (75:10): [True: 3.81k, False: 421]
  |  Branch (75:23): [True: 3.53k, False: 274]
  ------------------
   76|       |    // try to convert the next block of 16 ASCII bytes
   77|  3.53k|    if (pos >= skip_pos && pos + 16 <= len &&
  ------------------
  |  Branch (77:9): [True: 1.99k, False: 1.54k]
  |  Branch (77:28): [True: 1.43k, False: 560]
  ------------------
   78|  1.43k|        utf8_pos + 16 <= utf8_len) { // if it is safe to read 16 more bytes,
  ------------------
  |  Branch (78:9): [True: 257, False: 1.17k]
  ------------------
   79|       |                                     // check that they are ascii
   80|    257|      uint64_t v1;
   81|    257|      ::memcpy(&v1, data + pos, sizeof(uint64_t));
   82|    257|      uint64_t v2;
   83|    257|      ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   84|    257|      uint64_t v{v1 |
   85|    257|                 v2}; // We are only interested in these bits: 1000 1000 1000
   86|       |                      // 1000, so it makes sense to concatenate everything
   87|    257|      if ((v & 0x8080808080808080) ==
  ------------------
  |  Branch (87:11): [True: 155, False: 102]
  ------------------
   88|    257|          0) { // if NONE of these are set, e.g. all of them are zero, then
   89|       |               // everything is ASCII
   90|    155|        ::memcpy(utf8_output + utf8_pos, buf + pos, 16);
   91|    155|        utf8_pos += 16;
   92|    155|        pos += 16;
   93|    155|      } else {
   94|       |        // At least one of the next 16 bytes are not ASCII, we will process them
   95|       |        // one by one
   96|    102|        skip_pos = pos + 16;
   97|    102|      }
   98|  3.27k|    } else {
   99|  3.27k|      const auto byte = data[pos];
  100|  3.27k|      if ((byte & 0x80) == 0) { // if ASCII
  ------------------
  |  Branch (100:11): [True: 2.45k, False: 825]
  ------------------
  101|       |        // will generate one UTF-8 bytes
  102|  2.45k|        utf8_output[utf8_pos++] = char(byte);
  103|  2.45k|        pos++;
  104|  2.45k|      } else if (utf8_pos + 2 <= utf8_len) {
  ------------------
  |  Branch (104:18): [True: 785, False: 40]
  ------------------
  105|       |        // will generate two UTF-8 bytes
  106|    785|        utf8_output[utf8_pos++] = char((byte >> 6) | 0b11000000);
  107|    785|        utf8_output[utf8_pos++] = char((byte & 0b111111) | 0b10000000);
  108|    785|        pos++;
  109|    785|      } else {
  110|     40|        break;
  111|     40|      }
  112|  3.27k|    }
  113|  3.53k|  }
  114|    735|  return utf8_pos;
  115|    735|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf87convertEPKcmPc:
   64|  2.04k|                                     char *utf8_output) {
   65|  2.04k|  return convert(reinterpret_cast<const unsigned char *>(buf), len,
   66|  2.04k|                 utf8_output);
   67|  2.04k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf87convertIPKhPcQaasr7simdutf6detailE22indexes_into_byte_likeIT_Esr7simdutf6detailE26index_assignable_from_charIT0_EEEmS7_mS8_:
   15|  2.04k|                                   OutputPtr utf8_output) {
   16|       |  // const unsigned char *data = reinterpret_cast<const unsigned char *>(buf);
   17|  2.04k|  size_t pos = 0;
   18|  2.04k|  size_t utf8_pos = 0;
   19|       |
   20|  4.36M|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 4.36M, False: 2.04k]
  ------------------
   21|       |#if SIMDUTF_CPLUSPLUS23
   22|       |    if !consteval
   23|       |#endif
   24|  4.36M|    {
   25|       |      // try to convert the next block of 16 ASCII bytes
   26|  4.36M|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (26:11): [True: 4.34M, False: 18.9k]
  ------------------
   27|       |                             // they are ascii
   28|  4.34M|        uint64_t v1;
   29|  4.34M|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   30|  4.34M|        uint64_t v2;
   31|  4.34M|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   32|  4.34M|        uint64_t v{v1 |
   33|  4.34M|                   v2}; // We are only interested in these bits: 1000 1000 1000
   34|       |                        // 1000, so it makes sense to concatenate everything
   35|  4.34M|        if ((v & 0x8080808080808080) ==
  ------------------
  |  Branch (35:13): [True: 823k, False: 3.51M]
  ------------------
   36|  4.34M|            0) { // if NONE of these are set, e.g. all of them are zero, then
   37|       |                 // everything is ASCII
   38|   823k|          size_t final_pos = pos + 16;
   39|  13.9M|          while (pos < final_pos) {
  ------------------
  |  Branch (39:18): [True: 13.1M, False: 823k]
  ------------------
   40|  13.1M|            utf8_output[utf8_pos++] = char(data[pos]);
   41|  13.1M|            pos++;
   42|  13.1M|          }
   43|   823k|          continue;
   44|   823k|        }
   45|  4.34M|      } // if (pos + 16 <= len)
   46|  4.36M|    } // !consteval scope
   47|       |
   48|  3.53M|    unsigned char byte = data[pos];
   49|  3.53M|    if ((byte & 0x80) == 0) { // if ASCII
  ------------------
  |  Branch (49:9): [True: 817k, False: 2.72M]
  ------------------
   50|       |      // will generate one UTF-8 bytes
   51|   817k|      utf8_output[utf8_pos++] = char(byte);
   52|   817k|      pos++;
   53|  2.72M|    } else {
   54|       |      // will generate two UTF-8 bytes
   55|  2.72M|      utf8_output[utf8_pos++] = char((byte >> 6) | 0b11000000);
   56|  2.72M|      utf8_output[utf8_pos++] = char((byte & 0b111111) | 0b10000000);
   57|  2.72M|      pos++;
   58|  2.72M|    }
   59|  3.53M|  } // while
   60|  2.04k|  return utf8_pos;
   61|  2.04k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf823utf8_length_from_latin1IPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_m:
  150|    180|utf8_length_from_latin1(InputPtr input, size_t length) noexcept {
  151|    180|  size_t answer = length;
  152|    180|  size_t i = 0;
  153|       |
  154|       |#if SIMDUTF_CPLUSPLUS23
  155|       |  if !consteval
  156|       |#endif
  157|    180|  {
  158|    180|    auto pop = [](uint64_t v) {
  159|    180|      return (size_t)(((v >> 7) & UINT64_C(0x0101010101010101)) *
  160|    180|                          UINT64_C(0x0101010101010101) >>
  161|    180|                      56);
  162|    180|    };
  163|   504k|    for (; i + 32 <= length; i += 32) {
  ------------------
  |  Branch (163:12): [True: 504k, False: 180]
  ------------------
  164|   504k|      uint64_t v;
  165|   504k|      memcpy(&v, input + i, 8);
  166|   504k|      answer += pop(v);
  167|   504k|      memcpy(&v, input + i + 8, sizeof(v));
  168|   504k|      answer += pop(v);
  169|   504k|      memcpy(&v, input + i + 16, sizeof(v));
  170|   504k|      answer += pop(v);
  171|   504k|      memcpy(&v, input + i + 24, sizeof(v));
  172|   504k|      answer += pop(v);
  173|   504k|    }
  174|    445|    for (; i + 8 <= length; i += 8) {
  ------------------
  |  Branch (174:12): [True: 265, False: 180]
  ------------------
  175|    265|      uint64_t v;
  176|    265|      memcpy(&v, input + i, sizeof(v));
  177|    265|      answer += pop(v);
  178|    265|    }
  179|    180|  } // !consteval scope
  180|    663|  for (; i + 1 <= length; i += 1) {
  ------------------
  |  Branch (180:10): [True: 483, False: 180]
  ------------------
  181|    483|    answer += static_cast<uint8_t>(input[i]) >> 7;
  182|    483|  }
  183|    180|  return answer;
  184|    180|}
simdutf.cpp:_ZZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf823utf8_length_from_latin1IPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_mENKUlmE_clEm:
  158|  2.01M|    auto pop = [](uint64_t v) {
  159|  2.01M|      return (size_t)(((v >> 7) & UINT64_C(0x0101010101010101)) *
  160|       |                          UINT64_C(0x0101010101010101) >>
  161|  2.01M|                      56);
  162|  2.01M|    };

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

_ZN7simdutf6scalar5utf1614high_surrogateEDs:
  147|    662|simdutf_unused simdutf_really_inline constexpr bool high_surrogate(char16_t c) {
  148|    662|  return (0xd800 <= c && c <= 0xdbff);
  ------------------
  |  Branch (148:11): [True: 92, False: 570]
  |  Branch (148:26): [True: 49, False: 43]
  ------------------
  149|    662|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE0EEEmPKDsm:
   91|  1.00k|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|  1.00k|  size_t counter{0};
   94|  7.00M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 7.00M, False: 1.00k]
  ------------------
   95|  7.00M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|  7.00M|    counter++; // ASCII
   97|  7.00M|    counter += static_cast<size_t>(
   98|  7.00M|        word >
   99|  7.00M|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|  7.00M|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 1.88M, False: 5.12M]
  |  Branch (100:53): [True: 1.66M, False: 218k]
  ------------------
  101|  5.34M|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 207k, False: 5.13M]
  ------------------
  102|  7.00M|  }
  103|  1.00k|  return counter;
  104|  1.00k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf819convert_with_errorsILNS_10endiannessE0ELb1EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT1_Esr7simdutf6detailE26index_assignable_from_charIT2_EEENS_11full_resultES8_mS9_m:
   99|    836|                                                    size_t utf8_len = 0) {
  100|    836|  if (check_output && utf8_len == 0) {
  ------------------
  |  Branch (100:7): [True: 836, Folded]
  |  Branch (100:23): [True: 63, False: 773]
  ------------------
  101|     63|    return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, 0, 0);
  102|     63|  }
  103|       |
  104|    773|  size_t pos = 0;
  105|    773|  auto start = utf8_output;
  106|    773|  auto end = utf8_output + utf8_len;
  107|       |
  108|  3.21k|  while (pos < len) {
  ------------------
  |  Branch (108:10): [True: 2.70k, False: 510]
  ------------------
  109|       |#if SIMDUTF_CPLUSPLUS23
  110|       |    if !consteval
  111|       |#endif
  112|  2.70k|    {
  113|       |      // try to convert the next block of 8 bytes
  114|  2.70k|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (114:11): [True: 2.13k, False: 566]
  ------------------
  115|       |                            // they are ascii
  116|  2.13k|        uint64_t v;
  117|  2.13k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
  118|       |        if constexpr (!match_system(big_endian))
  119|       |          v = (v >> 8) | (v << (64 - 8));
  120|  2.13k|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (120:13): [True: 544, False: 1.59k]
  ------------------
  121|    544|          size_t final_pos = pos + 4;
  122|  2.63k|          while (pos < final_pos) {
  ------------------
  |  Branch (122:18): [True: 2.13k, False: 508]
  ------------------
  123|  2.13k|            if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (123:17): [True: 2.13k, Folded]
  |  Branch (123:33): [True: 36, False: 2.09k]
  ------------------
  124|     36|              return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  125|     36|                                 utf8_output - start);
  126|     36|            }
  127|  2.09k|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (127:30): [Folded, False: 2.09k]
  ------------------
  128|  2.09k|                                 ? char(u16_swap_bytes(data[pos]))
  129|  2.09k|                                 : char(data[pos]);
  130|  2.09k|            pos++;
  131|  2.09k|          }
  132|    508|          continue;
  133|    544|        }
  134|  2.13k|      }
  135|  2.70k|    }
  136|       |
  137|  2.15k|    uint16_t word =
  138|  2.15k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (138:9): [Folded, False: 2.15k]
  ------------------
  139|  2.15k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (139:9): [True: 580, False: 1.57k]
  ------------------
  140|       |      // will generate one UTF-8 bytes
  141|    580|      if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (141:11): [True: 580, Folded]
  |  Branch (141:27): [True: 12, False: 568]
  ------------------
  142|     12|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  143|     12|                           utf8_output - start);
  144|     12|      }
  145|    568|      *utf8_output++ = char(word);
  146|    568|      pos++;
  147|  1.57k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (147:16): [True: 389, False: 1.18k]
  ------------------
  148|       |      // will generate two UTF-8 bytes
  149|       |      // we have 0b110XXXXX 0b10XXXXXX
  150|    389|      if (check_output && size_t(end - utf8_output) < 2) {
  ------------------
  |  Branch (150:11): [True: 389, Folded]
  |  Branch (150:27): [True: 19, False: 370]
  ------------------
  151|     19|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  152|     19|                           utf8_output - start);
  153|     19|      }
  154|    370|      *utf8_output++ = char((word >> 6) | 0b11000000);
  155|    370|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  156|    370|      pos++;
  157|       |
  158|  1.18k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (158:16): [True: 941, False: 246]
  ------------------
  159|       |      // will generate three UTF-8 bytes
  160|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
  161|    941|      if (check_output && size_t(end - utf8_output) < 3) {
  ------------------
  |  Branch (161:11): [True: 941, Folded]
  |  Branch (161:27): [True: 61, False: 880]
  ------------------
  162|     61|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  163|     61|                           utf8_output - start);
  164|     61|      }
  165|    880|      *utf8_output++ = char((word >> 12) | 0b11100000);
  166|    880|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  167|    880|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  168|    880|      pos++;
  169|    880|    } else {
  170|       |
  171|    246|      if (check_output && size_t(end - utf8_output) < 4) {
  ------------------
  |  Branch (171:11): [True: 246, Folded]
  |  Branch (171:27): [True: 12, False: 234]
  ------------------
  172|     12|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  173|     12|                           utf8_output - start);
  174|     12|      }
  175|       |      // must be a surrogate pair
  176|    234|      if (pos + 1 >= len) {
  ------------------
  |  Branch (176:11): [True: 56, False: 178]
  ------------------
  177|     56|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  178|     56|      }
  179|    178|      uint16_t diff = uint16_t(word - 0xD800);
  180|    178|      if (diff > 0x3FF) {
  ------------------
  |  Branch (180:11): [True: 16, False: 162]
  ------------------
  181|     16|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  182|     16|      }
  183|    162|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (183:28): [Folded, False: 162]
  ------------------
  184|    162|                               ? u16_swap_bytes(data[pos + 1])
  185|    162|                               : data[pos + 1];
  186|    162|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
  187|    162|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (187:11): [True: 51, False: 111]
  ------------------
  188|     51|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  189|     51|      }
  190|    111|      uint32_t value = (diff << 10) + diff2 + 0x10000;
  191|       |      // will generate four UTF-8 bytes
  192|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
  193|    111|      *utf8_output++ = char((value >> 18) | 0b11110000);
  194|    111|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  195|    111|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  196|    111|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
  197|    111|      pos += 2;
  198|    111|    }
  199|  2.15k|  }
  200|    510|  return full_result(error_code::SUCCESS, pos, utf8_output - start);
  201|    773|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf87convertILNS_10endiannessE0EPKDsPcQsr7simdutf6detailE18indexes_into_utf16IT0_EEEmS8_mT1_:
   15|  1.70k|                                   OutputPtr utf8_output) {
   16|  1.70k|  size_t pos = 0;
   17|  1.70k|  const auto start = utf8_output;
   18|  3.50M|  while (pos < len) {
  ------------------
  |  Branch (18:10): [True: 3.49M, False: 1.39k]
  ------------------
   19|       |#if SIMDUTF_CPLUSPLUS23
   20|       |    if !consteval
   21|       |#endif
   22|  3.49M|    {
   23|       |      // try to convert the next block of 8 bytes
   24|  3.49M|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (24:11): [True: 3.49M, False: 2.90k]
  ------------------
   25|       |                            // they are ascii
   26|  3.49M|        uint64_t v;
   27|  3.49M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   28|       |        if constexpr (!match_system(big_endian)) {
   29|       |          v = (v >> 8) | (v << (64 - 8));
   30|       |        }
   31|  3.49M|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (31:13): [True: 1.22M, False: 2.27M]
  ------------------
   32|  1.22M|          size_t final_pos = pos + 4;
   33|  6.10M|          while (pos < final_pos) {
  ------------------
  |  Branch (33:18): [True: 4.88M, False: 1.22M]
  ------------------
   34|  4.88M|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (34:30): [Folded, False: 4.88M]
  ------------------
   35|  4.88M|                                 ? char(u16_swap_bytes(data[pos]))
   36|  4.88M|                                 : char(data[pos]);
   37|  4.88M|            pos++;
   38|  4.88M|          }
   39|  1.22M|          continue;
   40|  1.22M|        }
   41|  3.49M|      }
   42|  3.49M|    }
   43|  2.27M|    uint16_t word =
   44|  2.27M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (44:9): [Folded, False: 2.27M]
  ------------------
   45|  2.27M|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (45:9): [True: 60.1k, False: 2.21M]
  ------------------
   46|       |      // will generate one UTF-8 bytes
   47|  60.1k|      *utf8_output++ = char(word);
   48|  60.1k|      pos++;
   49|  2.21M|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (49:16): [True: 561k, False: 1.65M]
  ------------------
   50|       |      // will generate two UTF-8 bytes
   51|       |      // we have 0b110XXXXX 0b10XXXXXX
   52|   561k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   53|   561k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   54|   561k|      pos++;
   55|  1.65M|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (55:16): [True: 1.65M, False: 4.32k]
  ------------------
   56|       |      // will generate three UTF-8 bytes
   57|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   58|  1.65M|      *utf8_output++ = char((word >> 12) | 0b11100000);
   59|  1.65M|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   60|  1.65M|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   61|  1.65M|      pos++;
   62|  1.65M|    } else {
   63|       |      // must be a surrogate pair
   64|  4.32k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (64:11): [True: 80, False: 4.24k]
  ------------------
   65|     80|        return 0;
   66|     80|      }
   67|  4.24k|      uint16_t diff = uint16_t(word - 0xD800);
   68|  4.24k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (68:11): [True: 90, False: 4.15k]
  ------------------
   69|     90|        return 0;
   70|     90|      }
   71|  4.15k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (71:28): [Folded, False: 4.15k]
  ------------------
   72|  4.15k|                               ? u16_swap_bytes(data[pos + 1])
   73|  4.15k|                               : data[pos + 1];
   74|  4.15k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   75|  4.15k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (75:11): [True: 138, False: 4.01k]
  ------------------
   76|    138|        return 0;
   77|    138|      }
   78|  4.01k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   79|       |      // will generate four UTF-8 bytes
   80|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   81|  4.01k|      *utf8_output++ = char((value >> 18) | 0b11110000);
   82|  4.01k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
   83|  4.01k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
   84|  4.01k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
   85|  4.01k|      pos += 2;
   86|  4.01k|    }
   87|  2.27M|  }
   88|  1.39k|  return utf8_output - start;
   89|  1.70k|}

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE0EEEmPKDsm:
   10|    391|                                                             size_t size) {
   11|    391|  size_t pos = 0;
   12|       |
   13|    391|  using vector_u16 = simd16<uint16_t>;
   14|    391|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|    391|  const auto one = vector_u16::splat(1);
   17|       |
   18|    391|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|    391|  size_t count = size / N * N;
   22|       |
   23|       |  // in a single iteration the increment is 0, 1 or 2, despite we have
   24|       |  // three additions
   25|    391|  constexpr size_t max_iterations = 65535 / 2;
   26|    391|  size_t iteration = max_iterations;
   27|       |
   28|   370k|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 370k, False: 391]
  ------------------
   29|   370k|    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|   370k|    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|   370k|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|   370k|    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|   370k|    v_count += c0;
   68|   370k|    v_count += c1;
   69|   370k|    v_count += vector_u16(is_surrogate);
   70|       |
   71|   370k|    iteration -= 1;
   72|   370k|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 4, False: 370k]
  ------------------
   73|      4|      count += v_count.sum();
   74|      4|      v_count = vector_u16::zero();
   75|      4|      iteration = max_iterations;
   76|      4|    }
   77|   370k|  }
   78|       |
   79|    391|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 391, False: 0]
  ------------------
   80|    391|    count += v_count.sum();
   81|    391|  }
   82|       |
   83|    391|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|    391|                                                                   size - pos);
   85|    391|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE0EEEmPKDsm:
   10|    381|                                                             size_t size) {
   11|    381|  size_t pos = 0;
   12|       |
   13|    381|  using vector_u16 = simd16<uint16_t>;
   14|    381|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|    381|  const auto one = vector_u16::splat(1);
   17|       |
   18|    381|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|    381|  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|    381|  constexpr size_t max_iterations = 65535 / 2;
   26|    381|  size_t iteration = max_iterations;
   27|       |
   28|  1.02M|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 1.02M, False: 381]
  ------------------
   29|  1.02M|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
   30|       |    if constexpr (!match_system(big_endian)) {
   31|       |      input = input.swap_bytes();
   32|       |    }
   33|       |    // 0xd800 .. 0xdbff - low surrogate
   34|       |    // 0xdc00 .. 0xdfff - high surrogate
   35|  1.02M|    const auto is_surrogate = ((input & uint16_t(0xf800)) == uint16_t(0xd800));
   36|       |
   37|       |    // c0 - chars that yield 2- or 3-byte UTF-8 codes
   38|  1.02M|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|  1.02M|    const auto c1 = min(input & uint16_t(0xf800), one);
   42|       |
   43|       |    /*
   44|       |        Explanation how the counting works.
   45|       |
   46|       |        In the case of a non-surrogate character we count:
   47|       |        * always 1 -- see how `count` is initialized above;
   48|       |        * c0 = 1 if the current char yields 2 or 3 bytes;
   49|       |        * c1 = 1 if the current char yields 3 bytes.
   50|       |
   51|       |        Thus, we always have correct count for the current char:
   52|       |        from 1, 2 or 3 bytes.
   53|       |
   54|       |        A trickier part is how we count surrogate pairs. Whether
   55|       |        we encounter a surrogate (low or high), we count it as
   56|       |        3 chars and then minus 1 (`is_surrogate` is -1 or 0).
   57|       |        Each surrogate char yields 2. A surrogate pair, that
   58|       |        is a low surrogate followed by a high one, yields
   59|       |        the expected 4 bytes.
   60|       |
   61|       |        It also correctly handles cases when low surrogate is
   62|       |        processed by the this loop, but high surrogate is counted
   63|       |        by the scalar procedure. The scalar procedure uses exactly
   64|       |        the described approach, thanks to that for valid UTF-16
   65|       |        strings it always count correctly.
   66|       |    */
   67|  1.02M|    v_count += c0;
   68|  1.02M|    v_count += c1;
   69|  1.02M|    v_count += vector_u16(is_surrogate);
   70|       |
   71|  1.02M|    iteration -= 1;
   72|  1.02M|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 19, False: 1.02M]
  ------------------
   73|     19|      count += v_count.sum();
   74|     19|      v_count = vector_u16::zero();
   75|     19|      iteration = max_iterations;
   76|     19|    }
   77|  1.02M|  }
   78|       |
   79|    381|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 381, False: 0]
  ------------------
   80|    381|    count += v_count.sum();
   81|    381|  }
   82|       |
   83|    381|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|    381|                                                                   size - pos);
   85|    381|}

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

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

_ZNK7simdutf7haswell14implementation22convert_latin1_to_utf8EPKcmPc:
  410|    707|    const char *buf, size_t len, char *utf8_output) const noexcept {
  411|    707|  std::pair<const char *, char *> ret =
  412|    707|      avx2_convert_latin1_to_utf8(buf, len, utf8_output);
  413|    707|  size_t converted_chars = ret.second - utf8_output;
  414|       |
  415|    707|  if (ret.first != buf + len) {
  ------------------
  |  Branch (415:7): [True: 691, False: 16]
  ------------------
  416|    691|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  417|    691|        ret.first, len - (ret.first - buf), ret.second);
  418|    691|    converted_chars += scalar_converted_chars;
  419|    691|  }
  420|       |
  421|    707|  return converted_chars;
  422|    707|}
_ZNK7simdutf7haswell14implementation23convert_utf16le_to_utf8EPKDsmPc:
  677|    706|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  678|    706|  std::pair<const char16_t *, char *> ret =
  679|    706|      haswell::avx2_convert_utf16_to_utf8<endianness::LITTLE>(buf, len,
  680|    706|                                                              utf8_output);
  681|    706|  if (ret.first == nullptr) {
  ------------------
  |  Branch (681:7): [True: 134, False: 572]
  ------------------
  682|    134|    return 0;
  683|    134|  }
  684|    572|  size_t saved_bytes = ret.second - utf8_output;
  685|    572|  if (ret.first != buf + len) {
  ------------------
  |  Branch (685:7): [True: 557, False: 15]
  ------------------
  686|    557|    const size_t scalar_saved_bytes =
  687|    557|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  688|    557|            ret.first, len - (ret.first - buf), ret.second);
  689|    557|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (689:9): [True: 115, False: 442]
  ------------------
  690|    115|      return 0;
  691|    115|    }
  692|    442|    saved_bytes += scalar_saved_bytes;
  693|    442|  }
  694|    457|  return saved_bytes;
  695|    572|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16leEPKDsm:
 1129|    391|    const char16_t *input, size_t length) const noexcept {
 1130|    391|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1131|    391|                                                                    length);
 1132|    391|}
_ZNK7simdutf7haswell14implementation23utf8_length_from_latin1EPKcm:
 1189|    275|    const char *input, size_t len) const noexcept {
 1190|    275|  const uint8_t *data = reinterpret_cast<const uint8_t *>(input);
 1191|    275|  size_t answer = len / sizeof(__m256i) * sizeof(__m256i);
 1192|    275|  size_t i = 0;
 1193|    275|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1193:7): [True: 112, False: 163]
  ------------------
 1194|    112|    __m256i four_64bits = _mm256_setzero_si256();
 1195|  2.71k|    while (i + sizeof(__m256i) <= len) {
  ------------------
  |  Branch (1195:12): [True: 2.60k, False: 112]
  ------------------
 1196|  2.60k|      __m256i runner = _mm256_setzero_si256();
 1197|       |      // We can do up to 255 loops without overflow.
 1198|  2.60k|      size_t iterations = (len - i) / sizeof(__m256i);
 1199|  2.60k|      if (iterations > 255) {
  ------------------
  |  Branch (1199:11): [True: 2.48k, False: 112]
  ------------------
 1200|  2.48k|        iterations = 255;
 1201|  2.48k|      }
 1202|  2.60k|      size_t max_i = i + iterations * sizeof(__m256i) - sizeof(__m256i);
 1203|   161k|      for (; i + 4 * sizeof(__m256i) <= max_i; i += 4 * sizeof(__m256i)) {
  ------------------
  |  Branch (1203:14): [True: 158k, False: 2.60k]
  ------------------
 1204|   158k|        __m256i input1 = _mm256_loadu_si256((const __m256i *)(data + i));
 1205|   158k|        __m256i input2 =
 1206|   158k|            _mm256_loadu_si256((const __m256i *)(data + i + sizeof(__m256i)));
 1207|   158k|        __m256i input3 = _mm256_loadu_si256(
 1208|   158k|            (const __m256i *)(data + i + 2 * sizeof(__m256i)));
 1209|   158k|        __m256i input4 = _mm256_loadu_si256(
 1210|   158k|            (const __m256i *)(data + i + 3 * sizeof(__m256i)));
 1211|   158k|        __m256i input12 =
 1212|   158k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input1),
 1213|   158k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input2));
 1214|   158k|        __m256i input23 =
 1215|   158k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input3),
 1216|   158k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input4));
 1217|   158k|        __m256i input1234 = _mm256_add_epi8(input12, input23);
 1218|   158k|        runner = _mm256_sub_epi8(runner, input1234);
 1219|   158k|      }
 1220|  10.3k|      for (; i <= max_i; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1220:14): [True: 7.75k, False: 2.60k]
  ------------------
 1221|  7.75k|        __m256i input_256_chunk =
 1222|  7.75k|            _mm256_loadu_si256((const __m256i *)(data + i));
 1223|  7.75k|        runner = _mm256_sub_epi8(
 1224|  7.75k|            runner, _mm256_cmpgt_epi8(_mm256_setzero_si256(), input_256_chunk));
 1225|  7.75k|      }
 1226|  2.60k|      four_64bits = _mm256_add_epi64(
 1227|  2.60k|          four_64bits, _mm256_sad_epu8(runner, _mm256_setzero_si256()));
 1228|  2.60k|    }
 1229|    112|    answer += _mm256_extract_epi64(four_64bits, 0) +
 1230|    112|              _mm256_extract_epi64(four_64bits, 1) +
 1231|    112|              _mm256_extract_epi64(four_64bits, 2) +
 1232|    112|              _mm256_extract_epi64(four_64bits, 3);
 1233|    163|  } else if (answer > 0) {
  ------------------
  |  Branch (1233:14): [True: 79, False: 84]
  ------------------
 1234|  1.59k|    for (; i + sizeof(__m256i) <= len; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1234:12): [True: 1.51k, False: 79]
  ------------------
 1235|  1.51k|      __m256i latin = _mm256_loadu_si256((const __m256i *)(data + i));
 1236|  1.51k|      uint32_t non_ascii = _mm256_movemask_epi8(latin);
 1237|  1.51k|      answer += count_ones(non_ascii);
 1238|  1.51k|    }
 1239|     79|  }
 1240|    275|  return answer + scalar::latin1::utf8_length_from_latin1(
 1241|    275|                      reinterpret_cast<const char *>(data + i), len - i);
 1242|    275|}

_ZNK7simdutf14implementation27supported_by_runtime_systemEv:
   65|      4|bool implementation::supported_by_runtime_system() const {
   66|      4|  uint32_t required_instruction_sets = this->required_instruction_sets();
   67|      4|  uint32_t supported_instruction_sets =
   68|      4|      internal::detect_supported_architectures();
   69|      4|  return ((supported_instruction_sets & required_instruction_sets) ==
   70|      4|          required_instruction_sets);
   71|      4|}
_ZNK7simdutf8internal29available_implementation_list5beginEv:
 1504|      1|available_implementation_list::begin() const noexcept {
 1505|      1|  return internal::get_available_implementation_pointers().begin();
 1506|      1|}
_ZNK7simdutf8internal29available_implementation_list3endEv:
 1508|      1|available_implementation_list::end() const noexcept {
 1509|      1|  return internal::get_available_implementation_pointers().end();
 1510|      1|}
_ZN7simdutf29get_available_implementationsEv:
 1559|      1|get_available_implementations() {
 1560|      1|#if !SIMDUTF_USE_STATIC_INITIALIZATION
 1561|      1|  static const internal::available_implementation_list
 1562|      1|      available_implementations_instance{};
 1563|      1|#endif
 1564|      1|  return available_implementations_instance;
 1565|      1|}
_ZN7simdutf25get_active_implementationEv:
 1587|  7.65k|get_active_implementation() {
 1588|  7.65k|#if !SIMDUTF_USE_STATIC_INITIALIZATION
 1589|  7.65k|  #if !SIMDUTF_SINGLE_IMPLEMENTATION
 1590|  7.65k|  static const internal::detect_best_supported_implementation_on_first_use
 1591|  7.65k|      detect_best_supported_implementation_on_first_use_singleton;
 1592|  7.65k|  #endif
 1593|  7.65k|  static internal::atomic_ptr<const implementation>
 1594|  7.65k|      active_implementation_instance{
 1595|       |  #if SIMDUTF_SINGLE_IMPLEMENTATION
 1596|       |          internal::get_single_implementation()
 1597|       |  #else
 1598|  7.65k|          &detect_best_supported_implementation_on_first_use_singleton
 1599|  7.65k|  #endif
 1600|  7.65k|      };
 1601|  7.65k|#endif
 1602|  7.65k|  return active_implementation_instance;
 1603|  7.65k|}
_ZN7simdutf22convert_latin1_to_utf8EPKcmPc:
 1669|  2.18k|                                                  char *utf8_output) noexcept {
 1670|  2.18k|  return get_default_implementation()->convert_latin1_to_utf8(buf, len,
 1671|  2.18k|                                                              utf8_output);
 1672|  2.18k|}
_ZN7simdutf21convert_utf16_to_utf8EPKDsmPc:
 1955|  1.98k|                                                 char *utf8_buffer) noexcept {
 1956|       |  #if SIMDUTF_IS_BIG_ENDIAN
 1957|       |  return convert_utf16be_to_utf8(buf, len, utf8_buffer);
 1958|       |  #else
 1959|  1.98k|  return convert_utf16le_to_utf8(buf, len, utf8_buffer);
 1960|  1.98k|  #endif
 1961|  1.98k|}
_ZN7simdutf26convert_utf16_to_utf8_safeEPKDsmPcm:
 1965|  1.00k|                           size_t utf8_len) noexcept {
 1966|  1.00k|  const auto start{utf8_output};
 1967|       |  // We might be able to go faster by first scanning the input buffer to
 1968|       |  // determine how many char16_t characters we can read without exceeding the
 1969|       |  // utf8_len. This is a one-pass algorithm that has the benefit of not
 1970|       |  // requiring a first pass to determine the length.
 1971|  1.80k|  while (true) {
  ------------------
  |  Branch (1971:10): [True: 1.80k, Folded]
  ------------------
 1972|       |    // The worst case for convert_utf16_to_utf8 is when you go from 1 char16_t
 1973|       |    // to 3 characters of UTF-8. So we can read at most utf8_len / 3 char16_t
 1974|       |    // characters.
 1975|  1.80k|    auto read_len = std::min(len, utf8_len / 3);
 1976|  1.80k|    if (read_len <= 16) {
  ------------------
  |  Branch (1976:9): [True: 836, False: 973]
  ------------------
 1977|    836|      break;
 1978|    836|    }
 1979|    973|    if (read_len < len) {
  ------------------
  |  Branch (1979:9): [True: 662, False: 311]
  ------------------
 1980|       |      //  If we have a high surrogate at the end of the buffer, we need to
 1981|       |      //  either read one more char16_t or backtrack.
 1982|    662|      if (scalar::utf16::high_surrogate(buf[read_len - 1])) {
  ------------------
  |  Branch (1982:11): [True: 49, False: 613]
  ------------------
 1983|     49|        read_len--;
 1984|     49|      }
 1985|    662|    }
 1986|    973|    if (read_len == 0) {
  ------------------
  |  Branch (1986:9): [True: 0, False: 973]
  ------------------
 1987|       |      // If we cannot read anything, we are done.
 1988|      0|      break;
 1989|      0|    }
 1990|    973|    const auto write_len =
 1991|    973|        simdutf::convert_utf16_to_utf8(buf, read_len, utf8_output);
 1992|    973|    if (write_len == 0) {
  ------------------
  |  Branch (1992:9): [True: 171, False: 802]
  ------------------
 1993|       |      // There was an error in the conversion, we cannot continue.
 1994|    171|      return 0; // indicating failure
 1995|    171|    }
 1996|       |
 1997|    802|    utf8_output += write_len;
 1998|    802|    utf8_len -= write_len;
 1999|    802|    buf += read_len;
 2000|    802|    len -= read_len;
 2001|    802|  }
 2002|       |  #if SIMDUTF_IS_BIG_ENDIAN
 2003|       |  full_result r =
 2004|       |      scalar::utf16_to_utf8::convert_with_errors<endianness::BIG, true>(
 2005|       |          buf, len, utf8_output, utf8_len);
 2006|       |  #else
 2007|    836|  full_result r =
 2008|    836|      scalar::utf16_to_utf8::convert_with_errors<endianness::LITTLE, true>(
 2009|    836|          buf, len, utf8_output, utf8_len);
 2010|    836|  #endif
 2011|    836|  if (r.error != error_code::SUCCESS &&
  ------------------
  |  Branch (2011:7): [True: 326, False: 510]
  ------------------
 2012|    326|      r.error != error_code::OUTPUT_BUFFER_TOO_SMALL) {
  ------------------
  |  Branch (2012:7): [True: 123, False: 203]
  ------------------
 2013|       |    // If there was an error, we return 0 to indicate failure.
 2014|    123|    return 0; // indicating failure
 2015|    123|  }
 2016|    713|  return r.output_count + (utf8_output - start);
 2017|    836|}
_ZN7simdutf23convert_utf16le_to_utf8EPKDsmPc:
 2075|  1.98k|                                                   char *utf8_buffer) noexcept {
 2076|  1.98k|  return get_default_implementation()->convert_utf16le_to_utf8(buf, len,
 2077|  1.98k|                                                               utf8_buffer);
 2078|  1.98k|}
_ZN7simdutf23utf8_length_from_latin1EPKcm:
 2341|    735|                                                   size_t len) noexcept {
 2342|    735|  return get_default_implementation()->utf8_length_from_latin1(buf, len);
 2343|    735|}
_ZN7simdutf22utf8_length_from_utf16EPKDsm:
 2348|  1.00k|                                                  size_t length) noexcept {
 2349|       |  #if SIMDUTF_IS_BIG_ENDIAN
 2350|       |  return utf8_length_from_utf16be(input, length);
 2351|       |  #else
 2352|  1.00k|  return utf8_length_from_utf16le(input, length);
 2353|  1.00k|  #endif
 2354|  1.00k|}
_ZN7simdutf24utf8_length_from_utf16leEPKDsm:
 2364|  1.00k|                                                    size_t length) noexcept {
 2365|  1.00k|  return get_default_implementation()->utf8_length_from_utf16le(input, length);
 2366|  1.00k|}
_ZN7simdutf27convert_latin1_to_utf8_safeEPKcmPcm:
 2569|    735|    const char *buf, size_t len, char *utf8_output, size_t utf8_len) noexcept {
 2570|    735|  const auto start{utf8_output};
 2571|       |
 2572|  2.18k|  while (true) {
  ------------------
  |  Branch (2572:10): [True: 2.18k, Folded]
  ------------------
 2573|       |    // convert_latin1_to_utf8 will never write more than input length * 2
 2574|  2.18k|    auto read_len = std::min(len, utf8_len >> 1);
 2575|  2.18k|    if (read_len <= 16) {
  ------------------
  |  Branch (2575:9): [True: 735, False: 1.45k]
  ------------------
 2576|    735|      break;
 2577|    735|    }
 2578|       |
 2579|  1.45k|    const auto write_len =
 2580|  1.45k|        simdutf::convert_latin1_to_utf8(buf, read_len, utf8_output);
 2581|       |
 2582|  1.45k|    utf8_output += write_len;
 2583|  1.45k|    utf8_len -= write_len;
 2584|  1.45k|    buf += read_len;
 2585|  1.45k|    len -= read_len;
 2586|  1.45k|  }
 2587|       |
 2588|    735|  utf8_output +=
 2589|    735|      scalar::latin1_to_utf8::convert_safe(buf, len, utf8_output, utf8_len);
 2590|       |
 2591|    735|  return utf8_output - start;
 2592|    735|}
simdutf.cpp:_ZN7simdutf8internalL37get_available_implementation_pointersEv:
  934|      2|get_available_implementation_pointers() {
  935|      2|#if !SIMDUTF_USE_STATIC_INITIALIZATION
  936|      2|  static const std::initializer_list<const implementation *>
  937|      2|      available_implementation_pointers{
  938|      2|  #if SIMDUTF_IMPLEMENTATION_ICELAKE
  939|      2|          get_icelake_singleton(),
  940|      2|  #endif
  941|      2|  #if SIMDUTF_IMPLEMENTATION_HASWELL
  942|      2|          get_haswell_singleton(),
  943|      2|  #endif
  944|      2|  #if SIMDUTF_IMPLEMENTATION_WESTMERE
  945|      2|          get_westmere_singleton(),
  946|      2|  #endif
  947|       |  #if SIMDUTF_IMPLEMENTATION_ARM64
  948|       |          get_arm64_singleton(),
  949|       |  #endif
  950|       |  #if SIMDUTF_IMPLEMENTATION_PPC64
  951|       |          get_ppc64_singleton(),
  952|       |  #endif
  953|       |  #if SIMDUTF_IMPLEMENTATION_RVV
  954|       |          get_rvv_singleton(),
  955|       |  #endif
  956|       |  #if SIMDUTF_IMPLEMENTATION_LASX
  957|       |          get_lasx_singleton(),
  958|       |  #endif
  959|       |  #if SIMDUTF_IMPLEMENTATION_LSX
  960|       |          get_lsx_singleton(),
  961|       |  #endif
  962|      2|  #if SIMDUTF_IMPLEMENTATION_FALLBACK
  963|      2|          get_fallback_singleton(),
  964|      2|  #endif
  965|      2|      };
  966|      2|#endif
  967|      2|  return available_implementation_pointers;
  968|      2|}
simdutf.cpp:_ZN7simdutf8internalL21get_icelake_singletonEv:
  158|      1|static const icelake::implementation *get_icelake_singleton() {
  159|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  160|      1|  static const icelake::implementation icelake_singleton{};
  161|      1|  #endif
  162|      1|  return &icelake_singleton;
  163|      1|}
simdutf.cpp:_ZN7simdutf8internalL21get_haswell_singletonEv:
  169|      1|static const haswell::implementation *get_haswell_singleton() {
  170|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  171|      1|  static const haswell::implementation haswell_singleton{};
  172|      1|  #endif
  173|      1|  return &haswell_singleton;
  174|      1|}
simdutf.cpp:_ZN7simdutf8internalL22get_westmere_singletonEv:
  180|      1|static const westmere::implementation *get_westmere_singleton() {
  181|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  182|      1|  static const westmere::implementation westmere_singleton{};
  183|      1|  #endif
  184|      1|  return &westmere_singleton;
  185|      1|}
simdutf.cpp:_ZN7simdutf8internalL22get_fallback_singletonEv:
  246|      1|static const fallback::implementation *get_fallback_singleton() {
  247|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  248|      1|  static const fallback::implementation fallback_singleton{};
  249|      1|  #endif
  250|      1|  return &fallback_singleton;
  251|      1|}
_ZN7simdutf8internal49detect_best_supported_implementation_on_first_useC2Ev:
  888|      1|      : implementation("best_supported_detector",
  889|      1|                       "Detects the best supported implementation and sets it",
  890|      1|                       0) {}
_ZN7simdutf26get_default_implementationEv:
 1611|  5.90k|get_default_implementation() {
 1612|  5.90k|  return get_active_implementation();
 1613|  5.90k|}

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

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

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEC2EDv4_x:
   17|  5.18M|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEcvRKDv4_xEv:
   19|  5.18M|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEC2EDv4_x:
   17|   370k|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEcvRKDv4_xEv:
   19|   370k|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEanES5_:
   53|  1.11M|  simdutf_really_inline Child operator&(const Child other) const {
   54|  1.11M|    return _mm256_and_si256(*this, other);
   55|  1.11M|  }

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

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

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

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

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

_ZNK7simdutf8westmere14implementation22convert_latin1_to_utf8EPKcmPc:
  439|    956|    const char *buf, size_t len, char *utf8_output) const noexcept {
  440|       |
  441|    956|  std::pair<const char *, char *> ret =
  442|    956|      sse_convert_latin1_to_utf8(buf, len, utf8_output);
  443|    956|  size_t converted_chars = ret.second - utf8_output;
  444|       |
  445|    956|  if (ret.first != buf + len) {
  ------------------
  |  Branch (445:7): [True: 828, False: 128]
  ------------------
  446|    828|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  447|    828|        ret.first, len - (ret.first - buf), ret.second);
  448|    828|    converted_chars += scalar_converted_chars;
  449|    828|  }
  450|       |
  451|    956|  return converted_chars;
  452|    956|}
_ZNK7simdutf8westmere14implementation23convert_utf16le_to_utf8EPKDsmPc:
  707|    694|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  708|    694|  std::pair<const char16_t *, char *> ret =
  709|    694|      sse_convert_utf16_to_utf8<endianness::LITTLE>(buf, len, utf8_output);
  710|    694|  if (ret.first == nullptr) {
  ------------------
  |  Branch (710:7): [True: 113, False: 581]
  ------------------
  711|    113|    return 0;
  712|    113|  }
  713|    581|  size_t saved_bytes = ret.second - utf8_output;
  714|    581|  if (ret.first != buf + len) {
  ------------------
  |  Branch (714:7): [True: 570, False: 11]
  ------------------
  715|    570|    const size_t scalar_saved_bytes =
  716|    570|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  717|    570|            ret.first, len - (ret.first - buf), ret.second);
  718|    570|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (718:9): [True: 124, False: 446]
  ------------------
  719|    124|      return 0;
  720|    124|    }
  721|    446|    saved_bytes += scalar_saved_bytes;
  722|    446|  }
  723|    457|  return saved_bytes;
  724|    581|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16leEPKDsm:
 1156|    381|    const char16_t *input, size_t length) const noexcept {
 1157|    381|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1158|    381|                                                                    length);
 1159|    381|}
_ZNK7simdutf8westmere14implementation23utf8_length_from_latin1EPKcm:
 1169|    280|    const char *input, size_t len) const noexcept {
 1170|    280|  const uint8_t *str = reinterpret_cast<const uint8_t *>(input);
 1171|    280|  size_t answer = len / sizeof(__m128i) * sizeof(__m128i);
 1172|    280|  size_t i = 0;
 1173|    280|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1173:7): [True: 127, False: 153]
  ------------------
 1174|    127|    __m128i two_64bits = _mm_setzero_si128();
 1175|  4.85k|    while (i + sizeof(__m128i) <= len) {
  ------------------
  |  Branch (1175:12): [True: 4.73k, False: 127]
  ------------------
 1176|  4.73k|      __m128i runner = _mm_setzero_si128();
 1177|  4.73k|      size_t iterations = (len - i) / sizeof(__m128i);
 1178|  4.73k|      if (iterations > 255) {
  ------------------
  |  Branch (1178:11): [True: 4.60k, False: 127]
  ------------------
 1179|  4.60k|        iterations = 255;
 1180|  4.60k|      }
 1181|  4.73k|      size_t max_i = i + iterations * sizeof(__m128i) - sizeof(__m128i);
 1182|   298k|      for (; i + 4 * sizeof(__m128i) <= max_i; i += 4 * sizeof(__m128i)) {
  ------------------
  |  Branch (1182:14): [True: 293k, False: 4.73k]
  ------------------
 1183|   293k|        __m128i input1 = _mm_loadu_si128((const __m128i *)(str + i));
 1184|   293k|        __m128i input2 =
 1185|   293k|            _mm_loadu_si128((const __m128i *)(str + i + sizeof(__m128i)));
 1186|   293k|        __m128i input3 =
 1187|   293k|            _mm_loadu_si128((const __m128i *)(str + i + 2 * sizeof(__m128i)));
 1188|   293k|        __m128i input4 =
 1189|   293k|            _mm_loadu_si128((const __m128i *)(str + i + 3 * sizeof(__m128i)));
 1190|   293k|        __m128i input12 =
 1191|   293k|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input1),
 1192|   293k|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input2));
 1193|   293k|        __m128i input34 =
 1194|   293k|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input3),
 1195|   293k|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input4));
 1196|   293k|        __m128i input1234 = _mm_add_epi8(input12, input34);
 1197|   293k|        runner = _mm_sub_epi8(runner, input1234);
 1198|   293k|      }
 1199|  18.8k|      for (; i <= max_i; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1199:14): [True: 14.1k, False: 4.73k]
  ------------------
 1200|  14.1k|        __m128i more_input = _mm_loadu_si128((const __m128i *)(str + i));
 1201|  14.1k|        runner = _mm_sub_epi8(runner,
 1202|  14.1k|                              _mm_cmpgt_epi8(_mm_setzero_si128(), more_input));
 1203|  14.1k|      }
 1204|  4.73k|      two_64bits =
 1205|  4.73k|          _mm_add_epi64(two_64bits, _mm_sad_epu8(runner, _mm_setzero_si128()));
 1206|  4.73k|    }
 1207|    127|    answer +=
 1208|    127|        _mm_extract_epi64(two_64bits, 0) + _mm_extract_epi64(two_64bits, 1);
 1209|    153|  } else if (answer > 0) { // short string optimization
  ------------------
  |  Branch (1209:14): [True: 108, False: 45]
  ------------------
 1210|  1.57k|    for (; i + 2 * sizeof(__m128i) <= len; i += 2 * sizeof(__m128i)) {
  ------------------
  |  Branch (1210:12): [True: 1.46k, False: 108]
  ------------------
 1211|  1.46k|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1212|  1.46k|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1213|  1.46k|      answer += count_ones(non_ascii);
 1214|  1.46k|      latin = _mm_loadu_si128((const __m128i *)(input + i) + 1);
 1215|  1.46k|      non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1216|  1.46k|      answer += count_ones(non_ascii);
 1217|  1.46k|    }
 1218|    163|    for (; i + sizeof(__m128i) <= len; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1218:12): [True: 55, False: 108]
  ------------------
 1219|     55|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1220|     55|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1221|     55|      answer += count_ones(non_ascii);
 1222|     55|    }
 1223|    108|  }
 1224|    280|  return answer + scalar::latin1::utf8_length_from_latin1(
 1225|    280|                      reinterpret_cast<const char *>(str + i), len - i);
 1226|    280|}

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

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

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

_ZN7simdutf22utf8_length_from_utf16ENSt3__14spanIKDsLm18446744073709551615EEE:
 2939|  1.00k|utf8_length_from_utf16(std::span<const char16_t> valid_utf16_input) noexcept {
 2940|       |    #if SIMDUTF_CPLUSPLUS23
 2941|       |  if consteval {
 2942|       |    return scalar::utf16::utf8_length_from_utf16<endianness::NATIVE>(
 2943|       |        valid_utf16_input.data(), valid_utf16_input.size());
 2944|       |  } else
 2945|       |    #endif
 2946|  1.00k|  {
 2947|  1.00k|    return utf8_length_from_utf16(valid_utf16_input.data(),
 2948|  1.00k|                                  valid_utf16_input.size());
 2949|  1.00k|  }
 2950|  1.00k|}
_ZN7simdutf27convert_latin1_to_utf8_safeITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  860|    735|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
  861|       |      // implementation note: outputspan is a forwarding ref to avoid copying
  862|       |      // and allow both lvalues and rvalues. std::span can be copied without
  863|       |      // problems, but std::vector should not, and this function should accept
  864|       |      // both. it will allow using an owning rvalue ref (example: passing a
  865|       |      // temporary std::string) as output, but the user will quickly find out
  866|       |      // that he has no way of getting the data out of the object in that case.
  867|       |    #if SIMDUTF_CPLUSPLUS23
  868|       |  if consteval {
  869|       |    return scalar::latin1_to_utf8::convert_safe_constexpr(
  870|       |        input.data(), input.size(), utf8_output.data(), utf8_output.size());
  871|       |  } else
  872|       |    #endif
  873|    735|  {
  874|    735|    return convert_latin1_to_utf8_safe(
  875|    735|        reinterpret_cast<const char *>(input.data()), input.size(),
  876|    735|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
  877|    735|  }
  878|    735|}
_ZN7simdutf23utf8_length_from_latin1ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEEEEmRKT_:
 1643|    735|    const detail::input_span_of_byte_like auto &latin1_input) noexcept {
 1644|       |    #if SIMDUTF_CPLUSPLUS23
 1645|       |  if consteval {
 1646|       |    return scalar::latin1_to_utf8::utf8_length_from_latin1(latin1_input.data(),
 1647|       |                                                           latin1_input.size());
 1648|       |  } else
 1649|       |    #endif
 1650|    735|  {
 1651|    735|    return utf8_length_from_latin1(
 1652|    735|        reinterpret_cast<const char *>(latin1_input.data()),
 1653|    735|        latin1_input.size());
 1654|    735|  }
 1655|    735|}
_ZN7simdutf22convert_latin1_to_utf8ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  823|    735|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
  824|       |    #if SIMDUTF_CPLUSPLUS23
  825|       |  if consteval {
  826|       |    return scalar::latin1_to_utf8::convert(
  827|       |        detail::constexpr_cast_ptr<char>(latin1_input.data()),
  828|       |        latin1_input.size(),
  829|       |        detail::constexpr_cast_writeptr<char>(utf8_output.data()));
  830|       |  } else
  831|       |    #endif
  832|    735|  {
  833|    735|    return convert_latin1_to_utf8(
  834|    735|        reinterpret_cast<const char *>(latin1_input.data()),
  835|    735|        latin1_input.size(), reinterpret_cast<char *>(utf8_output.data()));
  836|    735|  }
  837|    735|}
_ZN7simdutf26convert_utf16_to_utf8_safeITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 1830|  1.00k|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
 1831|       |      // implementation note: outputspan is a forwarding ref to avoid copying
 1832|       |      // and allow both lvalues and rvalues. std::span can be copied without
 1833|       |      // problems, but std::vector should not, and this function should accept
 1834|       |      // both. it will allow using an owning rvalue ref (example: passing a
 1835|       |      // temporary std::string) as output, but the user will quickly find out
 1836|       |      // that he has no way of getting the data out of the object in that case.
 1837|       |    #if SIMDUTF_CPLUSPLUS23
 1838|       |  if consteval {
 1839|       |    const full_result r =
 1840|       |        scalar::utf16_to_utf8::convert_with_errors<endianness::NATIVE, true>(
 1841|       |            utf16_input.data(), utf16_input.size(), utf8_output.data(),
 1842|       |            utf8_output.size());
 1843|       |    if (r.error != error_code::SUCCESS &&
 1844|       |        r.error != error_code::OUTPUT_BUFFER_TOO_SMALL) {
 1845|       |      return 0;
 1846|       |    }
 1847|       |    return r.output_count;
 1848|       |  } else
 1849|       |    #endif
 1850|  1.00k|  {
 1851|  1.00k|    return convert_utf16_to_utf8_safe(
 1852|  1.00k|        utf16_input.data(), utf16_input.size(),
 1853|  1.00k|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
 1854|  1.00k|  }
 1855|  1.00k|}
_ZN7simdutf21convert_utf16_to_utf8ITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 1790|  1.00k|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
 1791|       |    #if SIMDUTF_CPLUSPLUS23
 1792|       |  if consteval {
 1793|       |    return scalar::utf16_to_utf8::convert<endianness::NATIVE>(
 1794|       |        utf16_input.data(), utf16_input.size(), utf8_output.data());
 1795|       |  } else
 1796|       |    #endif
 1797|  1.00k|  {
 1798|  1.00k|    return convert_utf16_to_utf8(utf16_input.data(), utf16_input.size(),
 1799|  1.00k|                                 reinterpret_cast<char *>(utf8_output.data()));
 1800|  1.00k|  }
 1801|  1.00k|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEaSEPS3_:
 7132|  1.74k|  atomic_ptr &operator=(T *_ptr) {
 7133|  1.74k|    ptr = _ptr;
 7134|  1.74k|    return *this;
 7135|  1.74k|  }

