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

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

_ZNK7simdutf14implementation25required_instruction_setsEv:
 5172|      4|  virtual uint32_t required_instruction_sets() const {
 5173|      4|    return _required_instruction_sets;
 5174|      4|  }
_ZN7simdutf14implementationC2EPKcS2_j:
 7058|      5|      : _name(name), _description(description),
 7059|      5|        _required_instruction_sets(required_instruction_sets) {}
_ZN7simdutf8internal29available_implementation_listC2Ev:
 7090|      1|  simdutf_really_inline available_implementation_list() {}
simdutf.cpp:_ZN7simdutf6detail12_GLOBAL__N_13minEmm:
   59|  4.00k|constexpr std::size_t min(std::size_t a, std::size_t b) {
   60|  4.00k|  return a < b ? a : b;
  ------------------
  |  Branch (60:10): [True: 1.39k, False: 2.61k]
  ------------------
   61|  4.00k|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEC2EPS3_:
 7138|      1|  atomic_ptr(T *_ptr) : ptr{_ptr} {}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEptEv:
 7160|  5.89k|  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|    533|                                                     size_t len) {
   11|    533|  const uint8_t *c = reinterpret_cast<const uint8_t *>(buf);
   12|    533|  size_t answer = 0;
   13|  4.09k|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (13:22): [True: 3.56k, False: 533]
  ------------------
   14|  3.56k|    if ((c[i] >> 7)) {
  ------------------
  |  Branch (14:9): [True: 1.18k, False: 2.37k]
  ------------------
   15|  1.18k|      answer++;
   16|  1.18k|    }
   17|  3.56k|  }
   18|    533|  return answer + len;
   19|    533|}

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

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

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

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

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

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

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

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

_ZNK7simdutf7haswell14implementation22convert_latin1_to_utf8EPKcmPc:
  412|    795|    const char *buf, size_t len, char *utf8_output) const noexcept {
  413|    795|  std::pair<const char *, char *> ret =
  414|    795|      avx2_convert_latin1_to_utf8(buf, len, utf8_output);
  415|    795|  size_t converted_chars = ret.second - utf8_output;
  416|       |
  417|    795|  if (ret.first != buf + len) {
  ------------------
  |  Branch (417:7): [True: 784, False: 11]
  ------------------
  418|    784|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  419|    784|        ret.first, len - (ret.first - buf), ret.second);
  420|    784|    converted_chars += scalar_converted_chars;
  421|    784|  }
  422|       |
  423|    795|  return converted_chars;
  424|    795|}
_ZNK7simdutf7haswell14implementation23convert_utf16le_to_utf8EPKDsmPc:
  679|    690|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  680|    690|  std::pair<const char16_t *, char *> ret =
  681|    690|      haswell::avx2_convert_utf16_to_utf8<endianness::LITTLE>(buf, len,
  682|    690|                                                              utf8_output);
  683|    690|  if (ret.first == nullptr) {
  ------------------
  |  Branch (683:7): [True: 130, False: 560]
  ------------------
  684|    130|    return 0;
  685|    130|  }
  686|    560|  size_t saved_bytes = ret.second - utf8_output;
  687|    560|  if (ret.first != buf + len) {
  ------------------
  |  Branch (687:7): [True: 553, False: 7]
  ------------------
  688|    553|    const size_t scalar_saved_bytes =
  689|    553|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  690|    553|            ret.first, len - (ret.first - buf), ret.second);
  691|    553|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (691:9): [True: 129, False: 424]
  ------------------
  692|    129|      return 0;
  693|    129|    }
  694|    424|    saved_bytes += scalar_saved_bytes;
  695|    424|  }
  696|    431|  return saved_bytes;
  697|    560|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16leEPKDsm:
 1108|    390|    const char16_t *input, size_t length) const noexcept {
 1109|    390|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1110|    390|                                                                    length);
 1111|    390|}
_ZNK7simdutf7haswell14implementation23utf8_length_from_latin1EPKcm:
 1174|    265|    const char *input, size_t len) const noexcept {
 1175|    265|  const uint8_t *data = reinterpret_cast<const uint8_t *>(input);
 1176|    265|  size_t answer = len / sizeof(__m256i) * sizeof(__m256i);
 1177|    265|  size_t i = 0;
 1178|    265|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1178:7): [True: 123, False: 142]
  ------------------
 1179|    123|    __m256i four_64bits = _mm256_setzero_si256();
 1180|  2.96k|    while (i + sizeof(__m256i) <= len) {
  ------------------
  |  Branch (1180:12): [True: 2.83k, False: 123]
  ------------------
 1181|  2.83k|      __m256i runner = _mm256_setzero_si256();
 1182|       |      // We can do up to 255 loops without overflow.
 1183|  2.83k|      size_t iterations = (len - i) / sizeof(__m256i);
 1184|  2.83k|      if (iterations > 255) {
  ------------------
  |  Branch (1184:11): [True: 2.71k, False: 123]
  ------------------
 1185|  2.71k|        iterations = 255;
 1186|  2.71k|      }
 1187|  2.83k|      size_t max_i = i + iterations * sizeof(__m256i) - sizeof(__m256i);
 1188|   176k|      for (; i + 4 * sizeof(__m256i) <= max_i; i += 4 * sizeof(__m256i)) {
  ------------------
  |  Branch (1188:14): [True: 173k, False: 2.83k]
  ------------------
 1189|   173k|        __m256i input1 = _mm256_loadu_si256((const __m256i *)(data + i));
 1190|   173k|        __m256i input2 =
 1191|   173k|            _mm256_loadu_si256((const __m256i *)(data + i + sizeof(__m256i)));
 1192|   173k|        __m256i input3 = _mm256_loadu_si256(
 1193|   173k|            (const __m256i *)(data + i + 2 * sizeof(__m256i)));
 1194|   173k|        __m256i input4 = _mm256_loadu_si256(
 1195|   173k|            (const __m256i *)(data + i + 3 * sizeof(__m256i)));
 1196|   173k|        __m256i input12 =
 1197|   173k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input1),
 1198|   173k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input2));
 1199|   173k|        __m256i input23 =
 1200|   173k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input3),
 1201|   173k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input4));
 1202|   173k|        __m256i input1234 = _mm256_add_epi8(input12, input23);
 1203|   173k|        runner = _mm256_sub_epi8(runner, input1234);
 1204|   173k|      }
 1205|  11.3k|      for (; i <= max_i; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1205:14): [True: 8.46k, False: 2.83k]
  ------------------
 1206|  8.46k|        __m256i input_256_chunk =
 1207|  8.46k|            _mm256_loadu_si256((const __m256i *)(data + i));
 1208|  8.46k|        runner = _mm256_sub_epi8(
 1209|  8.46k|            runner, _mm256_cmpgt_epi8(_mm256_setzero_si256(), input_256_chunk));
 1210|  8.46k|      }
 1211|  2.83k|      four_64bits = _mm256_add_epi64(
 1212|  2.83k|          four_64bits, _mm256_sad_epu8(runner, _mm256_setzero_si256()));
 1213|  2.83k|    }
 1214|    123|    answer += _mm256_extract_epi64(four_64bits, 0) +
 1215|    123|              _mm256_extract_epi64(four_64bits, 1) +
 1216|    123|              _mm256_extract_epi64(four_64bits, 2) +
 1217|    123|              _mm256_extract_epi64(four_64bits, 3);
 1218|    142|  } else if (answer > 0) {
  ------------------
  |  Branch (1218:14): [True: 61, False: 81]
  ------------------
 1219|    769|    for (; i + sizeof(__m256i) <= len; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1219:12): [True: 708, False: 61]
  ------------------
 1220|    708|      __m256i latin = _mm256_loadu_si256((const __m256i *)(data + i));
 1221|    708|      uint32_t non_ascii = _mm256_movemask_epi8(latin);
 1222|    708|      answer += count_ones(non_ascii);
 1223|    708|    }
 1224|     61|  }
 1225|    265|  return answer + scalar::latin1::utf8_length_from_latin1(
 1226|    265|                      reinterpret_cast<const char *>(data + i), len - i);
 1227|    265|}

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

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

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

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

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2EDv4_x:
   97|  4.00M|      : base16_numeric<uint16_t>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEC2EDv4_x:
   73|  4.00M|      : base16<T>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6base16ItNS2_6simd16IbEEEC2EDv4_x:
   20|  4.00M|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE4loadEPKt:
   66|   285k|  static simdutf_really_inline simd16<T> load(const T values[8]) {
   67|   285k|    return _mm256_loadu_si256(reinterpret_cast<const __m256i *>(values));
   68|   285k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE5splatEt:
   58|  1.14M|  static simdutf_really_inline simd16<T> splat(T _value) {
   59|  1.14M|    return _mm256_set1_epi16(_value);
   60|  1.14M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdeqENS2_6simd16ItEES4_:
   26|   285k|                                               const simd16<T> rhs) {
   27|   285k|    return _mm256_cmpeq_epi16(lhs, rhs);
   28|   285k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16IbEC2EDv4_x:
   45|   285k|  simdutf_really_inline simd16(const __m256i _value) : base16<bool>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6base16IbNS2_6simd16IbEEEC2EDv4_x:
   20|   285k|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2Et:
  100|  1.14M|  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|   571k|simd16<uint16_t> min(const simd16<uint16_t> a, simd16<uint16_t> b) {
  260|   571k|  return _mm256_min_epu16(a.value, b.value);
  261|   571k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEpLENS2_6simd16ItEE:
   87|   857k|  simdutf_really_inline simd16<T> &operator+=(const simd16<T> other) {
   88|   857k|    *this = *this + other;
   89|   857k|    return *static_cast<simd16<T> *>(this);
   90|   857k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEplENS2_6simd16ItEE:
   84|   857k|  simdutf_really_inline simd16<T> operator+(const simd16<T> other) const {
   85|   857k|    return _mm256_add_epi16(*this, other);
   86|   857k|  }
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.72k|simdutf_really_inline long long int count_ones(uint64_t input_num) {
   15|       |  return _popcnt64(input_num);
   16|  2.72k|}

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

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

_ZNK7simdutf8westmere14implementation22convert_latin1_to_utf8EPKcmPc:
  441|    853|    const char *buf, size_t len, char *utf8_output) const noexcept {
  442|       |
  443|    853|  std::pair<const char *, char *> ret =
  444|    853|      sse_convert_latin1_to_utf8(buf, len, utf8_output);
  445|    853|  size_t converted_chars = ret.second - utf8_output;
  446|       |
  447|    853|  if (ret.first != buf + len) {
  ------------------
  |  Branch (447:7): [True: 702, False: 151]
  ------------------
  448|    702|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  449|    702|        ret.first, len - (ret.first - buf), ret.second);
  450|    702|    converted_chars += scalar_converted_chars;
  451|    702|  }
  452|       |
  453|    853|  return converted_chars;
  454|    853|}
_ZNK7simdutf8westmere14implementation23convert_utf16le_to_utf8EPKDsmPc:
  709|    758|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  710|    758|  std::pair<const char16_t *, char *> ret =
  711|    758|      sse_convert_utf16_to_utf8<endianness::LITTLE>(buf, len, utf8_output);
  712|    758|  if (ret.first == nullptr) {
  ------------------
  |  Branch (712:7): [True: 104, False: 654]
  ------------------
  713|    104|    return 0;
  714|    104|  }
  715|    654|  size_t saved_bytes = ret.second - utf8_output;
  716|    654|  if (ret.first != buf + len) {
  ------------------
  |  Branch (716:7): [True: 646, False: 8]
  ------------------
  717|    646|    const size_t scalar_saved_bytes =
  718|    646|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  719|    646|            ret.first, len - (ret.first - buf), ret.second);
  720|    646|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (720:9): [True: 146, False: 500]
  ------------------
  721|    146|      return 0;
  722|    146|    }
  723|    500|    saved_bytes += scalar_saved_bytes;
  724|    500|  }
  725|    508|  return saved_bytes;
  726|    654|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16leEPKDsm:
 1135|    389|    const char16_t *input, size_t length) const noexcept {
 1136|    389|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1137|    389|                                                                    length);
 1138|    389|}
_ZNK7simdutf8westmere14implementation23utf8_length_from_latin1EPKcm:
 1148|    268|    const char *input, size_t len) const noexcept {
 1149|    268|  const uint8_t *str = reinterpret_cast<const uint8_t *>(input);
 1150|    268|  size_t answer = len / sizeof(__m128i) * sizeof(__m128i);
 1151|    268|  size_t i = 0;
 1152|    268|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1152:7): [True: 122, False: 146]
  ------------------
 1153|    122|    __m128i two_64bits = _mm_setzero_si128();
 1154|  3.99k|    while (i + sizeof(__m128i) <= len) {
  ------------------
  |  Branch (1154:12): [True: 3.86k, False: 122]
  ------------------
 1155|  3.86k|      __m128i runner = _mm_setzero_si128();
 1156|  3.86k|      size_t iterations = (len - i) / sizeof(__m128i);
 1157|  3.86k|      if (iterations > 255) {
  ------------------
  |  Branch (1157:11): [True: 3.74k, False: 122]
  ------------------
 1158|  3.74k|        iterations = 255;
 1159|  3.74k|      }
 1160|  3.86k|      size_t max_i = i + iterations * sizeof(__m128i) - sizeof(__m128i);
 1161|   242k|      for (; i + 4 * sizeof(__m128i) <= max_i; i += 4 * sizeof(__m128i)) {
  ------------------
  |  Branch (1161:14): [True: 238k, False: 3.86k]
  ------------------
 1162|   238k|        __m128i input1 = _mm_loadu_si128((const __m128i *)(str + i));
 1163|   238k|        __m128i input2 =
 1164|   238k|            _mm_loadu_si128((const __m128i *)(str + i + sizeof(__m128i)));
 1165|   238k|        __m128i input3 =
 1166|   238k|            _mm_loadu_si128((const __m128i *)(str + i + 2 * sizeof(__m128i)));
 1167|   238k|        __m128i input4 =
 1168|   238k|            _mm_loadu_si128((const __m128i *)(str + i + 3 * sizeof(__m128i)));
 1169|   238k|        __m128i input12 =
 1170|   238k|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input1),
 1171|   238k|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input2));
 1172|   238k|        __m128i input34 =
 1173|   238k|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input3),
 1174|   238k|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input4));
 1175|   238k|        __m128i input1234 = _mm_add_epi8(input12, input34);
 1176|   238k|        runner = _mm_sub_epi8(runner, input1234);
 1177|   238k|      }
 1178|  15.4k|      for (; i <= max_i; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1178:14): [True: 11.5k, False: 3.86k]
  ------------------
 1179|  11.5k|        __m128i more_input = _mm_loadu_si128((const __m128i *)(str + i));
 1180|  11.5k|        runner = _mm_sub_epi8(runner,
 1181|  11.5k|                              _mm_cmpgt_epi8(_mm_setzero_si128(), more_input));
 1182|  11.5k|      }
 1183|  3.86k|      two_64bits =
 1184|  3.86k|          _mm_add_epi64(two_64bits, _mm_sad_epu8(runner, _mm_setzero_si128()));
 1185|  3.86k|    }
 1186|    122|    answer +=
 1187|    122|        _mm_extract_epi64(two_64bits, 0) + _mm_extract_epi64(two_64bits, 1);
 1188|    146|  } else if (answer > 0) { // short string optimization
  ------------------
  |  Branch (1188:14): [True: 104, False: 42]
  ------------------
 1189|  1.43k|    for (; i + 2 * sizeof(__m128i) <= len; i += 2 * sizeof(__m128i)) {
  ------------------
  |  Branch (1189:12): [True: 1.33k, False: 104]
  ------------------
 1190|  1.33k|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1191|  1.33k|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1192|  1.33k|      answer += count_ones(non_ascii);
 1193|  1.33k|      latin = _mm_loadu_si128((const __m128i *)(input + i) + 1);
 1194|  1.33k|      non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1195|  1.33k|      answer += count_ones(non_ascii);
 1196|  1.33k|    }
 1197|    162|    for (; i + sizeof(__m128i) <= len; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1197:12): [True: 58, False: 104]
  ------------------
 1198|     58|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1199|     58|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1200|     58|      answer += count_ones(non_ascii);
 1201|     58|    }
 1202|    104|  }
 1203|    268|  return answer + scalar::latin1::utf8_length_from_latin1(
 1204|    268|                      reinterpret_cast<const char *>(str + i), len - i);
 1205|    268|}

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

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

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

_ZN7simdutf22utf8_length_from_utf16ENSt3__14spanIKDsLm18446744073709551615EEE:
 2964|  1.00k|utf8_length_from_utf16(std::span<const char16_t> valid_utf16_input) noexcept {
 2965|       |    #if SIMDUTF_CPLUSPLUS23
 2966|       |  if consteval {
 2967|       |    return scalar::utf16::utf8_length_from_utf16<endianness::NATIVE>(
 2968|       |        valid_utf16_input.data(), valid_utf16_input.size());
 2969|       |  } else
 2970|       |    #endif
 2971|  1.00k|  {
 2972|  1.00k|    return utf8_length_from_utf16(valid_utf16_input.data(),
 2973|  1.00k|                                  valid_utf16_input.size());
 2974|  1.00k|  }
 2975|  1.00k|}
safe_conversion.cpp:_ZN7simdutf6detail12_GLOBAL__N_13minEmm:
   59|  1.00k|constexpr std::size_t min(std::size_t a, std::size_t b) {
   60|  1.00k|  return a < b ? a : b;
  ------------------
  |  Branch (60:10): [True: 127, False: 874]
  ------------------
   61|  1.00k|}
_ZN7simdutf27convert_latin1_to_utf8_safeITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  880|    712|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
  881|       |      // implementation note: outputspan is a forwarding ref to avoid copying
  882|       |      // and allow both lvalues and rvalues. std::span can be copied without
  883|       |      // problems, but std::vector should not, and this function should accept
  884|       |      // both. it will allow using an owning rvalue ref (example: passing a
  885|       |      // temporary std::string) as output, but the user will quickly find out
  886|       |      // that he has no way of getting the data out of the object in that case.
  887|       |    #if SIMDUTF_CPLUSPLUS23
  888|       |  if consteval {
  889|       |    return scalar::latin1_to_utf8::convert_safe_constexpr(
  890|       |        input.data(), input.size(), utf8_output.data(), utf8_output.size());
  891|       |  } else
  892|       |    #endif
  893|    712|  {
  894|    712|    return convert_latin1_to_utf8_safe(
  895|    712|        reinterpret_cast<const char *>(input.data()), input.size(),
  896|    712|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
  897|    712|  }
  898|    712|}
_ZN7simdutf23utf8_length_from_latin1ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEEEEmRKT_:
 1663|    712|    const detail::input_span_of_byte_like auto &latin1_input) noexcept {
 1664|       |    #if SIMDUTF_CPLUSPLUS23
 1665|       |  if consteval {
 1666|       |    return scalar::latin1_to_utf8::utf8_length_from_latin1(latin1_input.data(),
 1667|       |                                                           latin1_input.size());
 1668|       |  } else
 1669|       |    #endif
 1670|    712|  {
 1671|    712|    return utf8_length_from_latin1(
 1672|    712|        reinterpret_cast<const char *>(latin1_input.data()),
 1673|    712|        latin1_input.size());
 1674|    712|  }
 1675|    712|}
_ZN7simdutf22convert_latin1_to_utf8ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  837|    712|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
  838|       |    #if SIMDUTF_CPLUSPLUS23
  839|       |  if consteval {
  840|       |    return scalar::latin1_to_utf8::convert(
  841|       |        detail::constexpr_cast_ptr<char>(latin1_input.data()),
  842|       |        latin1_input.size(),
  843|       |        detail::constexpr_cast_writeptr<char>(utf8_output.data()));
  844|       |  } else
  845|       |    #endif
  846|    712|  {
  847|    712|    return convert_latin1_to_utf8(
  848|    712|        reinterpret_cast<const char *>(latin1_input.data()),
  849|    712|        latin1_input.size(), reinterpret_cast<char *>(utf8_output.data()));
  850|    712|  }
  851|    712|}
_ZN7simdutf26convert_utf16_to_utf8_safeITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 1855|  1.00k|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
 1856|       |      // implementation note: outputspan is a forwarding ref to avoid copying
 1857|       |      // and allow both lvalues and rvalues. std::span can be copied without
 1858|       |      // problems, but std::vector should not, and this function should accept
 1859|       |      // both. it will allow using an owning rvalue ref (example: passing a
 1860|       |      // temporary std::string) as output, but the user will quickly find out
 1861|       |      // that he has no way of getting the data out of the object in that case.
 1862|       |    #if SIMDUTF_CPLUSPLUS23
 1863|       |  if consteval {
 1864|       |    const full_result r =
 1865|       |        scalar::utf16_to_utf8::convert_with_errors<endianness::NATIVE, true>(
 1866|       |            utf16_input.data(), utf16_input.size(), utf8_output.data(),
 1867|       |            utf8_output.size());
 1868|       |    if (r.error != error_code::SUCCESS &&
 1869|       |        r.error != error_code::OUTPUT_BUFFER_TOO_SMALL) {
 1870|       |      return 0;
 1871|       |    }
 1872|       |    return r.output_count;
 1873|       |  } else
 1874|       |    #endif
 1875|  1.00k|  {
 1876|  1.00k|    return convert_utf16_to_utf8_safe(
 1877|  1.00k|        utf16_input.data(), utf16_input.size(),
 1878|  1.00k|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
 1879|  1.00k|  }
 1880|  1.00k|}
_ZN7simdutf21convert_utf16_to_utf8ITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 1810|  1.00k|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
 1811|       |    #if SIMDUTF_CPLUSPLUS23
 1812|       |  if consteval {
 1813|       |    return scalar::utf16_to_utf8::convert<endianness::NATIVE>(
 1814|       |        utf16_input.data(), utf16_input.size(), utf8_output.data());
 1815|       |  } else
 1816|       |    #endif
 1817|  1.00k|  {
 1818|  1.00k|    return convert_utf16_to_utf8(utf16_input.data(), utf16_input.size(),
 1819|  1.00k|                                 reinterpret_cast<char *>(utf8_output.data()));
 1820|  1.00k|  }
 1821|  1.00k|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEaSEPS3_:
 7161|  1.71k|  atomic_ptr &operator=(T *_ptr) {
 7162|  1.71k|    ptr = _ptr;
 7163|  1.71k|    return *this;
 7164|  1.71k|  }

