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

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

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

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

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

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

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

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

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

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

_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.73k|get_active_implementation() {
 1587|  7.73k|#if !SIMDUTF_USE_STATIC_INITIALIZATION
 1588|  7.73k|  #if !SIMDUTF_SINGLE_IMPLEMENTATION
 1589|  7.73k|  static const internal::detect_best_supported_implementation_on_first_use
 1590|  7.73k|      detect_best_supported_implementation_on_first_use_singleton;
 1591|  7.73k|  #endif
 1592|  7.73k|  static internal::atomic_ptr<const implementation>
 1593|  7.73k|      active_implementation_instance{
 1594|       |  #if SIMDUTF_SINGLE_IMPLEMENTATION
 1595|       |          internal::get_single_implementation()
 1596|       |  #else
 1597|  7.73k|          &detect_best_supported_implementation_on_first_use_singleton
 1598|  7.73k|  #endif
 1599|  7.73k|      };
 1600|  7.73k|#endif
 1601|  7.73k|  return active_implementation_instance;
 1602|  7.73k|}
_ZN7simdutf22convert_latin1_to_utf8EPKcmPc:
 1668|  2.17k|                                                  char *utf8_output) noexcept {
 1669|  2.17k|  return get_default_implementation()->convert_latin1_to_utf8(buf, len,
 1670|  2.17k|                                                              utf8_output);
 1671|  2.17k|}
_ZN7simdutf21convert_utf16_to_utf8EPKDsmPc:
 1954|  2.06k|                                                 char *utf8_buffer) noexcept {
 1955|       |  #if SIMDUTF_IS_BIG_ENDIAN
 1956|       |  return convert_utf16be_to_utf8(buf, len, utf8_buffer);
 1957|       |  #else
 1958|  2.06k|  return convert_utf16le_to_utf8(buf, len, utf8_buffer);
 1959|  2.06k|  #endif
 1960|  2.06k|}
_ZN7simdutf26convert_utf16_to_utf8_safeEPKDsmPcm:
 1964|  1.01k|                           size_t utf8_len) noexcept {
 1965|  1.01k|  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.88k|  while (true) {
  ------------------
  |  Branch (1970:10): [True: 1.88k, 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.88k|    auto read_len = detail::min(len, utf8_len / 3);
 1975|  1.88k|    if (read_len <= 16) {
  ------------------
  |  Branch (1975:9): [True: 838, False: 1.05k]
  ------------------
 1976|    838|      break;
 1977|    838|    }
 1978|  1.05k|    if (read_len < len) {
  ------------------
  |  Branch (1978:9): [True: 756, False: 295]
  ------------------
 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|    756|      if (scalar::utf16::high_surrogate(buf[read_len - 1])) {
  ------------------
  |  Branch (1981:11): [True: 49, False: 707]
  ------------------
 1982|     49|        read_len--;
 1983|     49|      }
 1984|    756|    }
 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: 179, False: 872]
  ------------------
 1992|       |      // There was an error in the conversion, we cannot continue.
 1993|    179|      return 0; // indicating failure
 1994|    179|    }
 1995|       |
 1996|    872|    utf8_output += write_len;
 1997|    872|    utf8_len -= write_len;
 1998|    872|    buf += read_len;
 1999|    872|    len -= read_len;
 2000|    872|  }
 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|    838|  full_result r =
 2007|    838|      scalar::utf16_to_utf8::convert_with_errors<endianness::LITTLE, true>(
 2008|    838|          buf, len, utf8_output, utf8_len);
 2009|    838|  #endif
 2010|    838|  if (r.error != error_code::SUCCESS &&
  ------------------
  |  Branch (2010:7): [True: 374, False: 464]
  ------------------
 2011|    374|      r.error != error_code::OUTPUT_BUFFER_TOO_SMALL) {
  ------------------
  |  Branch (2011:7): [True: 127, False: 247]
  ------------------
 2012|       |    // If there was an error, we return 0 to indicate failure.
 2013|    127|    return 0; // indicating failure
 2014|    127|  }
 2015|    711|  return r.output_count + (utf8_output - start);
 2016|    838|}
_ZN7simdutf23convert_utf16le_to_utf8EPKDsmPc:
 2074|  2.06k|                                                   char *utf8_buffer) noexcept {
 2075|  2.06k|  return get_default_implementation()->convert_utf16le_to_utf8(buf, len,
 2076|  2.06k|                                                               utf8_buffer);
 2077|  2.06k|}
_ZN7simdutf23utf8_length_from_latin1EPKcm:
 2340|    730|                                                   size_t len) noexcept {
 2341|    730|  return get_default_implementation()->utf8_length_from_latin1(buf, len);
 2342|    730|}
_ZN7simdutf22utf8_length_from_utf16EPKDsm:
 2347|  1.01k|                                                  size_t length) noexcept {
 2348|       |  #if SIMDUTF_IS_BIG_ENDIAN
 2349|       |  return utf8_length_from_utf16be(input, length);
 2350|       |  #else
 2351|  1.01k|  return utf8_length_from_utf16le(input, length);
 2352|  1.01k|  #endif
 2353|  1.01k|}
_ZN7simdutf24utf8_length_from_utf16leEPKDsm:
 2363|  1.01k|                                                    size_t length) noexcept {
 2364|  1.01k|  return get_default_implementation()->utf8_length_from_utf16le(input, length);
 2365|  1.01k|}
_ZN7simdutf27convert_latin1_to_utf8_safeEPKcmPcm:
 2568|    730|    const char *buf, size_t len, char *utf8_output, size_t utf8_len) noexcept {
 2569|    730|  const auto start{utf8_output};
 2570|       |
 2571|  2.17k|  while (true) {
  ------------------
  |  Branch (2571:10): [True: 2.17k, Folded]
  ------------------
 2572|       |    // convert_latin1_to_utf8 will never write more than input length * 2
 2573|  2.17k|    auto read_len = detail::min(len, utf8_len >> 1);
 2574|  2.17k|    if (read_len <= 16) {
  ------------------
  |  Branch (2574:9): [True: 730, False: 1.44k]
  ------------------
 2575|    730|      break;
 2576|    730|    }
 2577|       |
 2578|  1.44k|    const auto write_len =
 2579|  1.44k|        simdutf::convert_latin1_to_utf8(buf, read_len, utf8_output);
 2580|       |
 2581|  1.44k|    utf8_output += write_len;
 2582|  1.44k|    utf8_len -= write_len;
 2583|  1.44k|    buf += read_len;
 2584|  1.44k|    len -= read_len;
 2585|  1.44k|  }
 2586|       |
 2587|    730|  utf8_output +=
 2588|    730|      scalar::latin1_to_utf8::convert_safe(buf, len, utf8_output, utf8_len);
 2589|       |
 2590|    730|  return utf8_output - start;
 2591|    730|}
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.98k|get_default_implementation() {
 1611|  5.98k|  return get_active_implementation();
 1612|  5.98k|}

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

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

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

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

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

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

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

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

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

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_18internal8westmere26write_v_u16_11bits_to_utf8EDv2_xRPcS4_S4_:
   57|  1.05M|                                       const __m128i v_ff80) {
   58|       |  // no bits set above 7th bit
   59|  1.05M|  const __m128i one_byte_bytemask =
   60|  1.05M|      _mm_cmpeq_epi16(_mm_and_si128(v_u16, v_ff80), v_0000);
   61|  1.05M|  const uint16_t one_byte_bitmask =
   62|  1.05M|      static_cast<uint16_t>(_mm_movemask_epi8(one_byte_bytemask));
   63|       |
   64|  1.05M|  write_v_u16_11bits_to_utf8(v_u16, utf8_output, one_byte_bytemask,
   65|  1.05M|                             one_byte_bitmask);
   66|  1.05M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_18internal8westmere26write_v_u16_11bits_to_utf8EDv2_xRPcS4_t:
   10|  1.12M|                                       const uint16_t one_byte_bitmask) {
   11|       |  // 0b1100_0000_1000_0000
   12|  1.12M|  const __m128i v_c080 = _mm_set1_epi16((int16_t)0xc080);
   13|       |  // 0b0001_1111_0000_0000
   14|  1.12M|  const __m128i v_1f00 = _mm_set1_epi16((int16_t)0x1f00);
   15|       |  // 0b0000_0000_0011_1111
   16|  1.12M|  const __m128i v_003f = _mm_set1_epi16((int16_t)0x003f);
   17|       |
   18|       |  // 1. prepare 2-byte values
   19|       |  // input 16-bit word : [0000|0aaa|aabb|bbbb] x 8
   20|       |  // expected output   : [110a|aaaa|10bb|bbbb] x 8
   21|       |
   22|       |  // t0 = [000a|aaaa|bbbb|bb00]
   23|  1.12M|  const __m128i t0 = _mm_slli_epi16(v_u16, 2);
   24|       |  // t1 = [000a|aaaa|0000|0000]
   25|  1.12M|  const __m128i t1 = _mm_and_si128(t0, v_1f00);
   26|       |  // t2 = [0000|0000|00bb|bbbb]
   27|  1.12M|  const __m128i t2 = _mm_and_si128(v_u16, v_003f);
   28|       |  // t3 = [000a|aaaa|00bb|bbbb]
   29|  1.12M|  const __m128i t3 = _mm_or_si128(t1, t2);
   30|       |  // t4 = [110a|aaaa|10bb|bbbb]
   31|  1.12M|  const __m128i t4 = _mm_or_si128(t3, v_c080);
   32|       |
   33|       |  // 2. merge ASCII and 2-byte codewords
   34|  1.12M|  const __m128i utf8_unpacked = _mm_blendv_epi8(t4, v_u16, one_byte_bytemask);
   35|       |
   36|       |  // 3. prepare bitmask for 8-bit lookup
   37|       |  //    one_byte_bitmask = hhggffeeddccbbaa -- the bits are doubled (h - MSB, a
   38|       |  //    - LSB)
   39|  1.12M|  const uint16_t m0 = one_byte_bitmask & 0x5555;      // m0 = 0h0g0f0e0d0c0b0a
   40|  1.12M|  const uint16_t m1 = static_cast<uint16_t>(m0 >> 7); // m1 = 00000000h0g0f0e0
   41|  1.12M|  const uint8_t m2 = static_cast<uint8_t>((m0 | m1) & 0xff); // m2 = hdgcfbea
   42|       |  // 4. pack the bytes
   43|  1.12M|  const uint8_t *row =
   44|  1.12M|      &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[m2][0];
   45|  1.12M|  const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
   46|  1.12M|  const __m128i utf8_packed = _mm_shuffle_epi8(utf8_unpacked, shuffle);
   47|       |
   48|       |  // 5. store bytes
   49|  1.12M|  _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   50|       |
   51|       |  // 6. adjust pointers
   52|  1.12M|  utf8_output += row[0];
   53|  1.12M|}

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

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

_ZN7simdutf22utf8_length_from_utf16ENSt3__14spanIKDsLm18446744073709551615EEE:
 2964|  1.01k|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.01k|  {
 2972|  1.01k|    return utf8_length_from_utf16(valid_utf16_input.data(),
 2973|  1.01k|                                  valid_utf16_input.size());
 2974|  1.01k|  }
 2975|  1.01k|}
safe_conversion.cpp:_ZN7simdutf6detail12_GLOBAL__N_13minEmm:
   59|  1.01k|constexpr std::size_t min(std::size_t a, std::size_t b) {
   60|  1.01k|  return a < b ? a : b;
  ------------------
  |  Branch (60:10): [True: 128, False: 889]
  ------------------
   61|  1.01k|}
_ZN7simdutf27convert_latin1_to_utf8_safeITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  880|    730|    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|    730|  {
  894|    730|    return convert_latin1_to_utf8_safe(
  895|    730|        reinterpret_cast<const char *>(input.data()), input.size(),
  896|    730|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
  897|    730|  }
  898|    730|}
_ZN7simdutf23utf8_length_from_latin1ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEEEEmRKT_:
 1663|    730|    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|    730|  {
 1671|    730|    return utf8_length_from_latin1(
 1672|    730|        reinterpret_cast<const char *>(latin1_input.data()),
 1673|    730|        latin1_input.size());
 1674|    730|  }
 1675|    730|}
_ZN7simdutf22convert_latin1_to_utf8ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  837|    730|    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|    730|  {
  847|    730|    return convert_latin1_to_utf8(
  848|    730|        reinterpret_cast<const char *>(latin1_input.data()),
  849|    730|        latin1_input.size(), reinterpret_cast<char *>(utf8_output.data()));
  850|    730|  }
  851|    730|}
_ZN7simdutf26convert_utf16_to_utf8_safeITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 1855|  1.01k|    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.01k|  {
 1876|  1.01k|    return convert_utf16_to_utf8_safe(
 1877|  1.01k|        utf16_input.data(), utf16_input.size(),
 1878|  1.01k|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
 1879|  1.01k|  }
 1880|  1.01k|}
_ZN7simdutf21convert_utf16_to_utf8ITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 1810|  1.01k|    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.01k|  {
 1818|  1.01k|    return convert_utf16_to_utf8(utf16_input.data(), utf16_input.size(),
 1819|  1.01k|                                 reinterpret_cast<char *>(utf8_output.data()));
 1820|  1.01k|  }
 1821|  1.01k|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEaSEPS3_:
 7161|  1.74k|  atomic_ptr &operator=(T *_ptr) {
 7162|  1.74k|    ptr = _ptr;
 7163|  1.74k|    return *this;
 7164|  1.74k|  }

