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

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

_ZNK7simdutf14implementation25required_instruction_setsEv:
 5705|      4|  virtual uint32_t required_instruction_sets() const {
 5706|      4|    return _required_instruction_sets;
 5707|      4|  }
_ZN7simdutf14implementationC2EPKcS2_j:
 7619|      5|      : _name(name), _description(description),
 7620|      5|        _required_instruction_sets(required_instruction_sets) {}
_ZN7simdutf8internal29available_implementation_listC2Ev:
 7651|      1|  simdutf_really_inline available_implementation_list() {}
simdutf.cpp:_ZN7simdutf6detail12_GLOBAL__N_13minEmm:
   59|  4.49k|constexpr std::size_t min(std::size_t a, std::size_t b) {
   60|  4.49k|  return a < b ? a : b;
  ------------------
  |  Branch (60:10): [True: 1.34k, False: 3.14k]
  ------------------
   61|  4.49k|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEC2EPS3_:
 7699|      1|  atomic_ptr(T *_ptr) : ptr{_ptr} {}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEptEv:
 7721|  6.45k|  T *operator->() { return ptr.load(); }

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

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

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

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

_ZN7simdutf6scalar5utf1614high_surrogateEDs:
  147|    812|simdutf_unused simdutf_really_inline constexpr bool high_surrogate(char16_t c) {
  148|    812|  return (0xd800 <= c && c <= 0xdbff);
  ------------------
  |  Branch (148:11): [True: 93, False: 719]
  |  Branch (148:26): [True: 55, False: 38]
  ------------------
  149|    812|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE0EEEmPKDsm:
   91|  1.05k|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|  1.05k|  size_t counter{0};
   94|  6.49M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 6.49M, False: 1.05k]
  ------------------
   95|  6.49M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|  6.49M|    counter++; // ASCII
   97|  6.49M|    counter += static_cast<size_t>(
   98|  6.49M|        word >
   99|  6.49M|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|  6.49M|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 970k, False: 5.52M]
  |  Branch (100:53): [True: 782k, False: 188k]
  ------------------
  101|  5.71M|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 182k, False: 5.52M]
  ------------------
  102|  6.49M|  }
  103|  1.05k|  return counter;
  104|  1.05k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf819convert_with_errorsILNS_10endiannessE0ELb1EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT1_Esr7simdutf6detailE26index_assignable_from_charIT2_EEENS_11full_resultES8_mS9_m:
  101|    823|                                                    size_t utf8_len = 0) {
  102|    823|  if (check_output && utf8_len == 0) {
  ------------------
  |  Branch (102:7): [True: 823, Folded]
  |  Branch (102:23): [True: 62, False: 761]
  ------------------
  103|     62|    return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, 0, 0);
  104|     62|  }
  105|       |
  106|    761|  size_t pos = 0;
  107|    761|  auto start = utf8_output;
  108|    761|  auto end = utf8_output + utf8_len;
  109|       |
  110|  3.31k|  while (pos < len) {
  ------------------
  |  Branch (110:10): [True: 2.85k, False: 461]
  ------------------
  111|       |#if SIMDUTF_CPLUSPLUS23
  112|       |    if !consteval
  113|       |#endif
  114|  2.85k|    {
  115|       |      // try to convert the next block of 8 bytes
  116|  2.85k|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (116:11): [True: 2.28k, False: 574]
  ------------------
  117|       |                            // they are ascii
  118|  2.28k|        uint64_t v;
  119|  2.28k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
  120|       |        if constexpr (!match_system(big_endian))
  121|       |          v = (v >> 8) | (v << (64 - 8));
  122|  2.28k|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (122:13): [True: 735, False: 1.54k]
  ------------------
  123|    735|          size_t final_pos = pos + 4;
  124|  3.54k|          while (pos < final_pos) {
  ------------------
  |  Branch (124:18): [True: 2.86k, False: 679]
  ------------------
  125|  2.86k|            if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (125:17): [True: 2.86k, Folded]
  |  Branch (125:33): [True: 56, False: 2.80k]
  ------------------
  126|     56|              return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  127|     56|                                 utf8_output - start);
  128|     56|            }
  129|  2.80k|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (129:30): [Folded, False: 2.80k]
  ------------------
  130|  2.80k|                                 ? char(u16_swap_bytes(data[pos]))
  131|  2.80k|                                 : char(data[pos]);
  132|  2.80k|            pos++;
  133|  2.80k|          }
  134|    679|          continue;
  135|    735|        }
  136|  2.28k|      }
  137|  2.85k|    }
  138|       |
  139|  2.12k|    uint16_t word =
  140|  2.12k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (140:9): [Folded, False: 2.12k]
  ------------------
  141|  2.12k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (141:9): [True: 542, False: 1.58k]
  ------------------
  142|       |      // will generate one UTF-8 bytes
  143|    542|      if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (143:11): [True: 542, Folded]
  |  Branch (143:27): [True: 10, False: 532]
  ------------------
  144|     10|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  145|     10|                           utf8_output - start);
  146|     10|      }
  147|    532|      *utf8_output++ = char(word);
  148|    532|      pos++;
  149|  1.58k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (149:16): [True: 331, False: 1.25k]
  ------------------
  150|       |      // will generate two UTF-8 bytes
  151|       |      // we have 0b110XXXXX 0b10XXXXXX
  152|    331|      if (check_output && size_t(end - utf8_output) < 2) {
  ------------------
  |  Branch (152:11): [True: 331, Folded]
  |  Branch (152:27): [True: 14, False: 317]
  ------------------
  153|     14|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  154|     14|                           utf8_output - start);
  155|     14|      }
  156|    317|      *utf8_output++ = char((word >> 6) | 0b11000000);
  157|    317|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  158|    317|      pos++;
  159|       |
  160|  1.25k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (160:16): [True: 988, False: 262]
  ------------------
  161|       |      // will generate three UTF-8 bytes
  162|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
  163|    988|      if (check_output && size_t(end - utf8_output) < 3) {
  ------------------
  |  Branch (163:11): [True: 988, Folded]
  |  Branch (163:27): [True: 64, False: 924]
  ------------------
  164|     64|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  165|     64|                           utf8_output - start);
  166|     64|      }
  167|    924|      *utf8_output++ = char((word >> 12) | 0b11100000);
  168|    924|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  169|    924|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  170|    924|      pos++;
  171|    924|    } else {
  172|       |
  173|    262|      if (check_output && size_t(end - utf8_output) < 4) {
  ------------------
  |  Branch (173:11): [True: 262, Folded]
  |  Branch (173:27): [True: 29, False: 233]
  ------------------
  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|    233|      if (pos + 1 >= len) {
  ------------------
  |  Branch (178:11): [True: 49, False: 184]
  ------------------
  179|     49|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  180|     49|      }
  181|    184|      uint16_t diff = uint16_t(word - 0xD800);
  182|    184|      if (diff > 0x3FF) {
  ------------------
  |  Branch (182:11): [True: 32, False: 152]
  ------------------
  183|     32|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  184|     32|      }
  185|    152|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (185:28): [Folded, False: 152]
  ------------------
  186|    152|                               ? u16_swap_bytes(data[pos + 1])
  187|    152|                               : data[pos + 1];
  188|    152|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
  189|    152|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (189:11): [True: 46, False: 106]
  ------------------
  190|     46|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  191|     46|      }
  192|    106|      uint32_t value = (diff << 10) + diff2 + 0x10000;
  193|       |      // will generate four UTF-8 bytes
  194|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
  195|    106|      *utf8_output++ = char((value >> 18) | 0b11110000);
  196|    106|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  197|    106|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  198|    106|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
  199|    106|      pos += 2;
  200|    106|    }
  201|  2.12k|  }
  202|    461|  return full_result(error_code::SUCCESS, pos, utf8_output - start);
  203|    761|}
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|  2.48M|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 2.48M, False: 1.47k]
  ------------------
   21|       |#if SIMDUTF_CPLUSPLUS23
   22|       |    if !consteval
   23|       |#endif
   24|  2.48M|    {
   25|       |      // try to convert the next block of 8 bytes
   26|  2.48M|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (26:11): [True: 2.48M, False: 3.08k]
  ------------------
   27|       |                            // they are ascii
   28|  2.48M|        uint64_t v;
   29|  2.48M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   30|       |        if constexpr (!match_system(big_endian)) {
   31|       |          v = (v >> 8) | (v << (64 - 8));
   32|       |        }
   33|  2.48M|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (33:13): [True: 1.45M, False: 1.02M]
  ------------------
   34|  1.45M|          size_t final_pos = pos + 4;
   35|  7.27M|          while (pos < final_pos) {
  ------------------
  |  Branch (35:18): [True: 5.82M, False: 1.45M]
  ------------------
   36|  5.82M|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (36:30): [Folded, False: 5.82M]
  ------------------
   37|  5.82M|                                 ? char(u16_swap_bytes(data[pos]))
   38|  5.82M|                                 : char(data[pos]);
   39|  5.82M|            pos++;
   40|  5.82M|          }
   41|  1.45M|          continue;
   42|  1.45M|        }
   43|  2.48M|      }
   44|  2.48M|    }
   45|  1.02M|    uint16_t word =
   46|  1.02M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (46:9): [Folded, False: 1.02M]
  ------------------
   47|  1.02M|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (47:9): [True: 19.1k, False: 1.00M]
  ------------------
   48|       |      // will generate one UTF-8 bytes
   49|  19.1k|      *utf8_output++ = char(word);
   50|  19.1k|      pos++;
   51|  1.00M|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (51:16): [True: 29.7k, False: 979k]
  ------------------
   52|       |      // will generate two UTF-8 bytes
   53|       |      // we have 0b110XXXXX 0b10XXXXXX
   54|  29.7k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   55|  29.7k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   56|  29.7k|      pos++;
   57|   979k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (57:16): [True: 976k, False: 3.19k]
  ------------------
   58|       |      // will generate three UTF-8 bytes
   59|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   60|   976k|      *utf8_output++ = char((word >> 12) | 0b11100000);
   61|   976k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   62|   976k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   63|   976k|      pos++;
   64|   976k|    } else {
   65|       |      // must be a surrogate pair
   66|  3.19k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (66:11): [True: 102, False: 3.09k]
  ------------------
   67|    102|        return 0;
   68|    102|      }
   69|  3.09k|      uint16_t diff = uint16_t(word - 0xD800);
   70|  3.09k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (70:11): [True: 99, False: 2.99k]
  ------------------
   71|     99|        return 0;
   72|     99|      }
   73|  2.99k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (73:28): [Folded, False: 2.99k]
  ------------------
   74|  2.99k|                               ? u16_swap_bytes(data[pos + 1])
   75|  2.99k|                               : data[pos + 1];
   76|  2.99k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   77|  2.99k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (77:11): [True: 116, False: 2.87k]
  ------------------
   78|    116|        return 0;
   79|    116|      }
   80|  2.87k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   81|       |      // will generate four UTF-8 bytes
   82|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   83|  2.87k|      *utf8_output++ = char((value >> 18) | 0b11110000);
   84|  2.87k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
   85|  2.87k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
   86|  2.87k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
   87|  2.87k|      pos += 2;
   88|  2.87k|    }
   89|  1.02M|  }
   90|  1.47k|  return utf8_output - start;
   91|  1.79k|}

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split4headIcEEmPKT_m:
    8|    303|simdutf_really_inline size_t head(const T *p, size_t len) {
    9|    303|  if (len * sizeof(T) < min_bytes) {
  ------------------
  |  Branch (9:7): [True: 254, False: 49]
  ------------------
   10|    254|    return 0;
   11|    254|  }
   12|     49|  const size_t misalignment = reinterpret_cast<uintptr_t>(p) % 64;
   13|     49|  if (misalignment == 0 || misalignment % sizeof(T) != 0) {
  ------------------
  |  Branch (13:7): [True: 0, False: 49]
  |  Branch (13:28): [True: 0, False: 49]
  ------------------
   14|      0|    return 0;
   15|      0|  }
   16|     49|  return (64 - misalignment) / sizeof(T);
   17|     49|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split4headIDsEEmPKT_m:
    8|    415|simdutf_really_inline size_t head(const T *p, size_t len) {
    9|    415|  if (len * sizeof(T) < min_bytes) {
  ------------------
  |  Branch (9:7): [True: 365, False: 50]
  ------------------
   10|    365|    return 0;
   11|    365|  }
   12|     50|  const size_t misalignment = reinterpret_cast<uintptr_t>(p) % 64;
   13|     50|  if (misalignment == 0 || misalignment % sizeof(T) != 0) {
  ------------------
  |  Branch (13:7): [True: 0, False: 50]
  |  Branch (13:28): [True: 0, False: 50]
  ------------------
   14|      0|    return 0;
   15|      0|  }
   16|     50|  return (64 - misalignment) / sizeof(T);
   17|     50|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split3sumITnDaXadL_ZNS0_32utf8_length_from_utf16le_unsplitEPKDsmEEDsEEmPKT0_mm:
   51|    415|simdutf_really_inline size_t sum(const T *p, size_t len, size_t h) {
   52|    415|  const size_t first = h == 0 ? 0 : out_of_line<F>(p, h);
  ------------------
  |  Branch (52:24): [True: 365, False: 50]
  ------------------
   53|    415|  return first + F(p + h, len - h);
   54|    415|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split11out_of_lineITnDaXadL_ZNS0_32utf8_length_from_utf16le_unsplitEPKDsmEEJS5_mEEEDaDpT0_:
   46|     50|simdutf_never_inline auto out_of_line(Args... args) noexcept {
   47|     50|  return F(args...);
   48|     50|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split3sumITnDaXadL_ZNS0_31utf8_length_from_latin1_unsplitEPKcmEEcEEmPKT0_mm:
   51|    303|simdutf_really_inline size_t sum(const T *p, size_t len, size_t h) {
   52|    303|  const size_t first = h == 0 ? 0 : out_of_line<F>(p, h);
  ------------------
  |  Branch (52:24): [True: 254, False: 49]
  ------------------
   53|    303|  return first + F(p + h, len - h);
   54|    303|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113aligned_split11out_of_lineITnDaXadL_ZNS0_31utf8_length_from_latin1_unsplitEPKcmEEJS5_mEEEDaDpT0_:
   46|     49|simdutf_never_inline auto out_of_line(Args... args) noexcept {
   47|     49|  return F(args...);
   48|     49|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113aligned_split4headIcEEmPKT_m:
    8|    301|simdutf_really_inline size_t head(const T *p, size_t len) {
    9|    301|  if (len * sizeof(T) < min_bytes) {
  ------------------
  |  Branch (9:7): [True: 251, False: 50]
  ------------------
   10|    251|    return 0;
   11|    251|  }
   12|     50|  const size_t misalignment = reinterpret_cast<uintptr_t>(p) % 64;
   13|     50|  if (misalignment == 0 || misalignment % sizeof(T) != 0) {
  ------------------
  |  Branch (13:7): [True: 0, False: 50]
  |  Branch (13:28): [True: 0, False: 50]
  ------------------
   14|      0|    return 0;
   15|      0|  }
   16|     50|  return (64 - misalignment) / sizeof(T);
   17|     50|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113aligned_split3sumITnDaXadL_ZNS0_31utf8_length_from_latin1_unsplitEPKcmEEcEEmPKT0_mm:
   51|    301|simdutf_really_inline size_t sum(const T *p, size_t len, size_t h) {
   52|    301|  const size_t first = h == 0 ? 0 : out_of_line<F>(p, h);
  ------------------
  |  Branch (52:24): [True: 251, False: 50]
  ------------------
   53|    301|  return first + F(p + h, len - h);
   54|    301|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113aligned_split11out_of_lineITnDaXadL_ZNS0_31utf8_length_from_latin1_unsplitEPKcmEEJS5_mEEEDaDpT0_:
   46|     50|simdutf_never_inline auto out_of_line(Args... args) noexcept {
   47|     50|  return F(args...);
   48|     50|}

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

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

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

_ZNK7simdutf7haswell14implementation22convert_latin1_to_utf8EPKcmPc:
  401|    981|    const char *buf, size_t len, char *utf8_output) const noexcept {
  402|    981|  std::pair<const char *, char *> ret =
  403|    981|      avx2_convert_latin1_to_utf8(buf, len, utf8_output);
  404|    981|  size_t converted_chars = ret.second - utf8_output;
  405|       |
  406|    981|  if (ret.first != buf + len) {
  ------------------
  |  Branch (406:7): [True: 968, False: 13]
  ------------------
  407|    968|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  408|    968|        ret.first, len - (ret.first - buf), ret.second);
  409|    968|    converted_chars += scalar_converted_chars;
  410|    968|  }
  411|       |
  412|    981|  return converted_chars;
  413|    981|}
_ZNK7simdutf7haswell14implementation23convert_utf16le_to_utf8EPKDsmPc:
  668|    731|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  669|    731|  std::pair<const char16_t *, char *> ret =
  670|    731|      haswell::avx2_convert_utf16_to_utf8<endianness::LITTLE>(buf, len,
  671|    731|                                                              utf8_output);
  672|    731|  if (ret.first == nullptr) {
  ------------------
  |  Branch (672:7): [True: 180, False: 551]
  ------------------
  673|    180|    return 0;
  674|    180|  }
  675|    551|  size_t saved_bytes = ret.second - utf8_output;
  676|    551|  if (ret.first != buf + len) {
  ------------------
  |  Branch (676:7): [True: 539, False: 12]
  ------------------
  677|    539|    const size_t scalar_saved_bytes =
  678|    539|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  679|    539|            ret.first, len - (ret.first - buf), ret.second);
  680|    539|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (680:9): [True: 132, False: 407]
  ------------------
  681|    132|      return 0;
  682|    132|    }
  683|    407|    saved_bytes += scalar_saved_bytes;
  684|    407|  }
  685|    419|  return saved_bytes;
  686|    551|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16leEPKDsm:
 1133|    415|    const char16_t *input, size_t length) const noexcept {
 1134|    415|  return aligned_split::sum<utf8_length_from_utf16le_unsplit>(
 1135|    415|      input, length, aligned_split::head(input, length));
 1136|    415|}
_ZNK7simdutf7haswell14implementation23utf8_length_from_latin1EPKcm:
 1279|    303|    const char *input, size_t len) const noexcept {
 1280|    303|  return aligned_split::sum<utf8_length_from_latin1_unsplit>(
 1281|    303|      input, len, aligned_split::head(input, len));
 1282|    303|}
_ZN7simdutf7haswell32utf8_length_from_utf16le_unsplitEPKDsm:
 1127|    465|    const char16_t *input, size_t length) noexcept {
 1128|    465|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1129|    465|                                                                    length);
 1130|    465|}
_ZN7simdutf7haswell31utf8_length_from_latin1_unsplitEPKcm:
 1223|    352|utf8_length_from_latin1_unsplit(const char *input, size_t len) noexcept {
 1224|    352|  const uint8_t *data = reinterpret_cast<const uint8_t *>(input);
 1225|    352|  size_t answer = len / sizeof(__m256i) * sizeof(__m256i);
 1226|    352|  size_t i = 0;
 1227|    352|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1227:7): [True: 144, False: 208]
  ------------------
 1228|    144|    __m256i four_64bits = _mm256_setzero_si256();
 1229|  3.37k|    while (i + sizeof(__m256i) <= len) {
  ------------------
  |  Branch (1229:12): [True: 3.22k, False: 144]
  ------------------
 1230|  3.22k|      __m256i runner = _mm256_setzero_si256();
 1231|       |      // We can do up to 255 loops without overflow.
 1232|  3.22k|      size_t iterations = (len - i) / sizeof(__m256i);
 1233|  3.22k|      if (iterations > 255) {
  ------------------
  |  Branch (1233:11): [True: 3.08k, False: 144]
  ------------------
 1234|  3.08k|        iterations = 255;
 1235|  3.08k|      }
 1236|  3.22k|      size_t max_i = i + iterations * sizeof(__m256i) - sizeof(__m256i);
 1237|   200k|      for (; i + 4 * sizeof(__m256i) <= max_i; i += 4 * sizeof(__m256i)) {
  ------------------
  |  Branch (1237:14): [True: 196k, False: 3.22k]
  ------------------
 1238|   196k|        __m256i input1 = _mm256_loadu_si256((const __m256i *)(data + i));
 1239|   196k|        __m256i input2 =
 1240|   196k|            _mm256_loadu_si256((const __m256i *)(data + i + sizeof(__m256i)));
 1241|   196k|        __m256i input3 = _mm256_loadu_si256(
 1242|   196k|            (const __m256i *)(data + i + 2 * sizeof(__m256i)));
 1243|   196k|        __m256i input4 = _mm256_loadu_si256(
 1244|   196k|            (const __m256i *)(data + i + 3 * sizeof(__m256i)));
 1245|   196k|        __m256i input12 =
 1246|   196k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input1),
 1247|   196k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input2));
 1248|   196k|        __m256i input23 =
 1249|   196k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input3),
 1250|   196k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input4));
 1251|   196k|        __m256i input1234 = _mm256_add_epi8(input12, input23);
 1252|   196k|        runner = _mm256_sub_epi8(runner, input1234);
 1253|   196k|      }
 1254|  12.8k|      for (; i <= max_i; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1254:14): [True: 9.61k, False: 3.22k]
  ------------------
 1255|  9.61k|        __m256i input_256_chunk =
 1256|  9.61k|            _mm256_loadu_si256((const __m256i *)(data + i));
 1257|  9.61k|        runner = _mm256_sub_epi8(
 1258|  9.61k|            runner, _mm256_cmpgt_epi8(_mm256_setzero_si256(), input_256_chunk));
 1259|  9.61k|      }
 1260|  3.22k|      four_64bits = _mm256_add_epi64(
 1261|  3.22k|          four_64bits, _mm256_sad_epu8(runner, _mm256_setzero_si256()));
 1262|  3.22k|    }
 1263|    144|    answer += _mm256_extract_epi64(four_64bits, 0) +
 1264|    144|              _mm256_extract_epi64(four_64bits, 1) +
 1265|    144|              _mm256_extract_epi64(four_64bits, 2) +
 1266|    144|              _mm256_extract_epi64(four_64bits, 3);
 1267|    208|  } else if (answer > 0) {
  ------------------
  |  Branch (1267:14): [True: 90, False: 118]
  ------------------
 1268|  1.50k|    for (; i + sizeof(__m256i) <= len; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1268:12): [True: 1.41k, False: 90]
  ------------------
 1269|  1.41k|      __m256i latin = _mm256_loadu_si256((const __m256i *)(data + i));
 1270|  1.41k|      uint32_t non_ascii = _mm256_movemask_epi8(latin);
 1271|  1.41k|      answer += count_ones(non_ascii);
 1272|  1.41k|    }
 1273|     90|  }
 1274|    352|  return answer + scalar::latin1::utf8_length_from_latin1(
 1275|    352|                      reinterpret_cast<const char *>(data + i), len - i);
 1276|    352|}

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

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

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

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

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

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

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

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

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

_ZNK7simdutf8westmere14implementation22convert_latin1_to_utf8EPKcmPc:
  365|  1.15k|    const char *buf, size_t len, char *utf8_output) const noexcept {
  366|       |
  367|  1.15k|  std::pair<const char *, char *> ret =
  368|  1.15k|      sse_convert_latin1_to_utf8(buf, len, utf8_output);
  369|  1.15k|  size_t converted_chars = ret.second - utf8_output;
  370|       |
  371|  1.15k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (371:7): [True: 1.00k, False: 145]
  ------------------
  372|  1.00k|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  373|  1.00k|        ret.first, len - (ret.first - buf), ret.second);
  374|  1.00k|    converted_chars += scalar_converted_chars;
  375|  1.00k|  }
  376|       |
  377|  1.15k|  return converted_chars;
  378|  1.15k|}
_ZNK7simdutf8westmere14implementation23convert_utf16le_to_utf8EPKDsmPc:
  633|    735|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  634|    735|  std::pair<const char16_t *, char *> ret =
  635|    735|      sse_convert_utf16_to_utf8<endianness::LITTLE>(buf, len, utf8_output);
  636|    735|  if (ret.first == nullptr) {
  ------------------
  |  Branch (636:7): [True: 109, False: 626]
  ------------------
  637|    109|    return 0;
  638|    109|  }
  639|    626|  size_t saved_bytes = ret.second - utf8_output;
  640|    626|  if (ret.first != buf + len) {
  ------------------
  |  Branch (640:7): [True: 619, False: 7]
  ------------------
  641|    619|    const size_t scalar_saved_bytes =
  642|    619|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  643|    619|            ret.first, len - (ret.first - buf), ret.second);
  644|    619|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (644:9): [True: 117, False: 502]
  ------------------
  645|    117|      return 0;
  646|    117|    }
  647|    502|    saved_bytes += scalar_saved_bytes;
  648|    502|  }
  649|    509|  return saved_bytes;
  650|    626|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16leEPKDsm:
 1076|    374|    const char16_t *input, size_t length) const noexcept {
 1077|    374|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1078|    374|                                                                    length);
 1079|    374|}
_ZNK7simdutf8westmere14implementation23utf8_length_from_latin1EPKcm:
 1149|    301|    const char *input, size_t len) const noexcept {
 1150|    301|  return aligned_split::sum<utf8_length_from_latin1_unsplit>(
 1151|    301|      input, len, aligned_split::head(input, len));
 1152|    301|}
_ZN7simdutf8westmere31utf8_length_from_latin1_unsplitEPKcm:
 1089|    351|utf8_length_from_latin1_unsplit(const char *input, size_t len) noexcept {
 1090|    351|  const uint8_t *str = reinterpret_cast<const uint8_t *>(input);
 1091|    351|  size_t answer = len / sizeof(__m128i) * sizeof(__m128i);
 1092|    351|  size_t i = 0;
 1093|    351|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1093:7): [True: 163, False: 188]
  ------------------
 1094|    163|    __m128i two_64bits = _mm_setzero_si128();
 1095|  5.85k|    while (i + sizeof(__m128i) <= len) {
  ------------------
  |  Branch (1095:12): [True: 5.69k, False: 163]
  ------------------
 1096|  5.69k|      __m128i runner = _mm_setzero_si128();
 1097|  5.69k|      size_t iterations = (len - i) / sizeof(__m128i);
 1098|  5.69k|      if (iterations > 255) {
  ------------------
  |  Branch (1098:11): [True: 5.53k, False: 163]
  ------------------
 1099|  5.53k|        iterations = 255;
 1100|  5.53k|      }
 1101|  5.69k|      size_t max_i = i + iterations * sizeof(__m128i) - sizeof(__m128i);
 1102|   357k|      for (; i + 4 * sizeof(__m128i) <= max_i; i += 4 * sizeof(__m128i)) {
  ------------------
  |  Branch (1102:14): [True: 352k, False: 5.69k]
  ------------------
 1103|   352k|        __m128i input1 = _mm_loadu_si128((const __m128i *)(str + i));
 1104|   352k|        __m128i input2 =
 1105|   352k|            _mm_loadu_si128((const __m128i *)(str + i + sizeof(__m128i)));
 1106|   352k|        __m128i input3 =
 1107|   352k|            _mm_loadu_si128((const __m128i *)(str + i + 2 * sizeof(__m128i)));
 1108|   352k|        __m128i input4 =
 1109|   352k|            _mm_loadu_si128((const __m128i *)(str + i + 3 * sizeof(__m128i)));
 1110|   352k|        __m128i input12 =
 1111|   352k|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input1),
 1112|   352k|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input2));
 1113|   352k|        __m128i input34 =
 1114|   352k|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input3),
 1115|   352k|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input4));
 1116|   352k|        __m128i input1234 = _mm_add_epi8(input12, input34);
 1117|   352k|        runner = _mm_sub_epi8(runner, input1234);
 1118|   352k|      }
 1119|  22.6k|      for (; i <= max_i; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1119:14): [True: 16.9k, False: 5.69k]
  ------------------
 1120|  16.9k|        __m128i more_input = _mm_loadu_si128((const __m128i *)(str + i));
 1121|  16.9k|        runner = _mm_sub_epi8(runner,
 1122|  16.9k|                              _mm_cmpgt_epi8(_mm_setzero_si128(), more_input));
 1123|  16.9k|      }
 1124|  5.69k|      two_64bits =
 1125|  5.69k|          _mm_add_epi64(two_64bits, _mm_sad_epu8(runner, _mm_setzero_si128()));
 1126|  5.69k|    }
 1127|    163|    answer +=
 1128|    163|        _mm_extract_epi64(two_64bits, 0) + _mm_extract_epi64(two_64bits, 1);
 1129|    188|  } else if (answer > 0) { // short string optimization
  ------------------
  |  Branch (1129:14): [True: 141, False: 47]
  ------------------
 1130|  1.45k|    for (; i + 2 * sizeof(__m128i) <= len; i += 2 * sizeof(__m128i)) {
  ------------------
  |  Branch (1130:12): [True: 1.31k, False: 141]
  ------------------
 1131|  1.31k|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1132|  1.31k|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1133|  1.31k|      answer += count_ones(non_ascii);
 1134|  1.31k|      latin = _mm_loadu_si128((const __m128i *)(input + i) + 1);
 1135|  1.31k|      non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1136|  1.31k|      answer += count_ones(non_ascii);
 1137|  1.31k|    }
 1138|    222|    for (; i + sizeof(__m128i) <= len; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1138:12): [True: 81, False: 141]
  ------------------
 1139|     81|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1140|     81|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1141|     81|      answer += count_ones(non_ascii);
 1142|     81|    }
 1143|    141|  }
 1144|    351|  return answer + scalar::latin1::utf8_length_from_latin1(
 1145|    351|                      reinterpret_cast<const char *>(str + i), len - i);
 1146|    351|}

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

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

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

_ZN7simdutf22utf8_length_from_utf16ENSt3__14spanIKDsLm18446744073709551615EEE:
 3456|  1.00k|utf8_length_from_utf16(std::span<const char16_t> valid_utf16_input) noexcept {
 3457|       |    #if SIMDUTF_CPLUSPLUS23
 3458|       |  if consteval {
 3459|       |    return scalar::utf16::utf8_length_from_utf16<endianness::NATIVE>(
 3460|       |        valid_utf16_input.data(), valid_utf16_input.size());
 3461|       |  } else
 3462|       |    #endif
 3463|  1.00k|  {
 3464|  1.00k|    return utf8_length_from_utf16(valid_utf16_input.data(),
 3465|  1.00k|                                  valid_utf16_input.size());
 3466|  1.00k|  }
 3467|  1.00k|}
safe_conversion.cpp:_ZN7simdutf6detail12_GLOBAL__N_13minEmm:
   59|  1.00k|constexpr std::size_t min(std::size_t a, std::size_t b) {
   60|  1.00k|  return a < b ? a : b;
  ------------------
  |  Branch (60:10): [True: 109, False: 892]
  ------------------
   61|  1.00k|}
_ZN7simdutf27convert_latin1_to_utf8_safeITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  956|    782|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
  957|       |      // implementation note: outputspan is a forwarding ref to avoid copying
  958|       |      // and allow both lvalues and rvalues. std::span can be copied without
  959|       |      // problems, but std::vector should not, and this function should accept
  960|       |      // both. it will allow using an owning rvalue ref (example: passing a
  961|       |      // temporary std::string) as output, but the user will quickly find out
  962|       |      // that he has no way of getting the data out of the object in that case.
  963|       |    #if SIMDUTF_CPLUSPLUS23
  964|       |  if consteval {
  965|       |    return scalar::latin1_to_utf8::convert_safe_constexpr(
  966|       |        input.data(), input.size(), utf8_output.data(), utf8_output.size());
  967|       |  } else
  968|       |    #endif
  969|    782|  {
  970|    782|    return convert_latin1_to_utf8_safe(
  971|    782|        reinterpret_cast<const char *>(input.data()), input.size(),
  972|    782|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
  973|    782|  }
  974|    782|}
_ZN7simdutf23utf8_length_from_latin1ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEEEEmRKT_:
 2010|    782|    const detail::input_span_of_byte_like auto &latin1_input) noexcept {
 2011|       |    #if SIMDUTF_CPLUSPLUS23
 2012|       |  if consteval {
 2013|       |    return scalar::latin1_to_utf8::utf8_length_from_latin1(latin1_input.data(),
 2014|       |                                                           latin1_input.size());
 2015|       |  } else
 2016|       |    #endif
 2017|    782|  {
 2018|    782|    return utf8_length_from_latin1(
 2019|    782|        reinterpret_cast<const char *>(latin1_input.data()),
 2020|    782|        latin1_input.size());
 2021|    782|  }
 2022|    782|}
_ZN7simdutf22convert_latin1_to_utf8ITkNS_6detail23input_span_of_byte_likeENSt3__14spanIKhLm18446744073709551615EEETkNS1_24output_span_of_byte_likeERNS2_6vectorIcNS2_9allocatorIcEEEEEEmRKT_OT0_:
  913|    782|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
  914|       |    #if SIMDUTF_CPLUSPLUS23
  915|       |  if consteval {
  916|       |    return scalar::latin1_to_utf8::convert(
  917|       |        detail::constexpr_cast_ptr<char>(latin1_input.data()),
  918|       |        latin1_input.size(),
  919|       |        detail::constexpr_cast_writeptr<char>(utf8_output.data()));
  920|       |  } else
  921|       |    #endif
  922|    782|  {
  923|    782|    return convert_latin1_to_utf8(
  924|    782|        reinterpret_cast<const char *>(latin1_input.data()),
  925|    782|        latin1_input.size(), reinterpret_cast<char *>(utf8_output.data()));
  926|    782|  }
  927|    782|}
_ZN7simdutf26convert_utf16_to_utf8_safeITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 2265|  1.00k|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
 2266|       |      // implementation note: outputspan is a forwarding ref to avoid copying
 2267|       |      // and allow both lvalues and rvalues. std::span can be copied without
 2268|       |      // problems, but std::vector should not, and this function should accept
 2269|       |      // both. it will allow using an owning rvalue ref (example: passing a
 2270|       |      // temporary std::string) as output, but the user will quickly find out
 2271|       |      // that he has no way of getting the data out of the object in that case.
 2272|       |    #if SIMDUTF_CPLUSPLUS23
 2273|       |  if consteval {
 2274|       |    const full_result r =
 2275|       |        scalar::utf16_to_utf8::convert_with_errors<endianness::NATIVE, true>(
 2276|       |            utf16_input.data(), utf16_input.size(), utf8_output.data(),
 2277|       |            utf8_output.size());
 2278|       |    if (r.error != error_code::SUCCESS &&
 2279|       |        r.error != error_code::OUTPUT_BUFFER_TOO_SMALL) {
 2280|       |      return 0;
 2281|       |    }
 2282|       |    return r.output_count;
 2283|       |  } else
 2284|       |    #endif
 2285|  1.00k|  {
 2286|  1.00k|    return convert_utf16_to_utf8_safe(
 2287|  1.00k|        utf16_input.data(), utf16_input.size(),
 2288|  1.00k|        reinterpret_cast<char *>(utf8_output.data()), utf8_output.size());
 2289|  1.00k|  }
 2290|  1.00k|}
_ZN7simdutf21convert_utf16_to_utf8ITkNS_6detail24output_span_of_byte_likeERNSt3__16vectorIcNS2_9allocatorIcEEEEEEmNS2_4spanIKDsLm18446744073709551615EEEOT_:
 2220|  1.00k|    detail::output_span_of_byte_like auto &&utf8_output) noexcept {
 2221|       |    #if SIMDUTF_CPLUSPLUS23
 2222|       |  if consteval {
 2223|       |    return scalar::utf16_to_utf8::convert<endianness::NATIVE>(
 2224|       |        utf16_input.data(), utf16_input.size(), utf8_output.data());
 2225|       |  } else
 2226|       |    #endif
 2227|  1.00k|  {
 2228|  1.00k|    return convert_utf16_to_utf8(utf16_input.data(), utf16_input.size(),
 2229|  1.00k|                                 reinterpret_cast<char *>(utf8_output.data()));
 2230|  1.00k|  }
 2231|  1.00k|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEaSEPS3_:
 7722|  1.78k|  atomic_ptr &operator=(T *_ptr) {
 7723|  1.78k|    ptr = _ptr;
 7724|  1.78k|    return *this;
 7725|  1.78k|  }

