LLVMFuzzerTestOneInput:
   28|  5.56k|extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
   29|  5.56k|  FuzzedDataProvider fdp(data, size);
   30|  5.56k|  constexpr int kMaxStringSize = 1024;
   31|  5.56k|  std::string source = fdp.ConsumeRandomLengthString(kMaxStringSize);
   32|  22.2k|  for (auto& e : simdutf::get_available_implementations()) {
  ------------------
  |  Branch (32:16): [True: 22.2k, False: 5.56k]
  ------------------
   33|  22.2k|    if (!e->supported_by_runtime_system()) {
  ------------------
  |  Branch (33:9): [True: 5.56k, False: 16.6k]
  ------------------
   34|  5.56k|      continue;
   35|  5.56k|    }
   36|       |    /**
   37|       |     * Transcoding from UTF-8 to UTF-16LE.
   38|       |     */
   39|  16.6k|    bool validutf8 = e->validate_utf8(source.c_str(), source.size());
   40|  16.6k|    auto rutf8 = e->validate_utf8_with_errors(source.c_str(), source.size());
   41|  16.6k|    if (validutf8 != (rutf8.error == simdutf::SUCCESS)) { // they should agree
  ------------------
  |  Branch (41:9): [True: 0, False: 16.6k]
  ------------------
   42|      0|      print_input(source, e);
   43|      0|      abort();
   44|      0|    }
   45|  16.6k|    if (validutf8) {
  ------------------
  |  Branch (45:9): [True: 15.4k, False: 1.23k]
  ------------------
   46|       |      // We need a buffer of size where to write the UTF-16LE words.
   47|  15.4k|      size_t expected_utf16words =
   48|  15.4k|          e->utf16_length_from_utf8(source.c_str(), source.size());
   49|  15.4k|      std::unique_ptr<char16_t[]> utf16_output{
   50|  15.4k|          new char16_t[expected_utf16words]};
   51|       |      // convert to UTF-16LE
   52|  15.4k|      size_t utf16words = e->convert_utf8_to_utf16le(
   53|  15.4k|          source.c_str(), source.size(), utf16_output.get());
   54|       |      // It wrote utf16words * sizeof(char16_t) bytes.
   55|  15.4k|      bool validutf16 = e->validate_utf16le(utf16_output.get(), utf16words);
   56|  15.4k|      if (!validutf16) {
  ------------------
  |  Branch (56:11): [True: 0, False: 15.4k]
  ------------------
   57|      0|        print_input(source, e);
   58|      0|        abort();
   59|      0|      }
   60|       |      // convert it back:
   61|       |      // We need a buffer of size where to write the UTF-8 words.
   62|  15.4k|      size_t expected_utf8words =
   63|  15.4k|          e->utf8_length_from_utf16le(utf16_output.get(), utf16words);
   64|  15.4k|      std::unique_ptr<char[]> utf8_output{new char[expected_utf8words]};
   65|       |      // convert to UTF-8
   66|  15.4k|      size_t utf8words = e->convert_utf16le_to_utf8(
   67|  15.4k|          utf16_output.get(), utf16words, utf8_output.get());
   68|  15.4k|      std::string final_string(utf8_output.get(), utf8words);
   69|  15.4k|      if (final_string != source) {
  ------------------
  |  Branch (69:11): [True: 0, False: 15.4k]
  ------------------
   70|      0|        print_input(source, e);
   71|      0|        abort();
   72|      0|      }
   73|  15.4k|    } else {
   74|       |      // invalid input!!!
   75|       |      // We need a buffer of size where to write the UTF-16LE words.
   76|  1.23k|      size_t expected_utf16words =
   77|  1.23k|          e->utf16_length_from_utf8(source.c_str(), source.size());
   78|  1.23k|      std::unique_ptr<char16_t[]> utf16_output{
   79|  1.23k|          new char16_t[expected_utf16words]};
   80|       |      // convert to UTF-16LE
   81|  1.23k|      size_t utf16words = e->convert_utf8_to_utf16le(
   82|  1.23k|          source.c_str(), source.size(), utf16_output.get());
   83|  1.23k|      if (utf16words != 0) {
  ------------------
  |  Branch (83:11): [True: 0, False: 1.23k]
  ------------------
   84|      0|        print_input(source, e);
   85|      0|        abort();
   86|      0|      }
   87|  1.23k|    }
   88|       |
   89|       |    /**
   90|       |     * Transcoding from UTF-8 to UTF-16BE.
   91|       |     */
   92|  16.6k|    if (validutf8) {
  ------------------
  |  Branch (92:9): [True: 15.4k, False: 1.23k]
  ------------------
   93|       |      // We need a buffer of size where to write the UTF-16BE words.
   94|  15.4k|      size_t expected_utf16words =
   95|  15.4k|          e->utf16_length_from_utf8(source.c_str(), source.size());
   96|  15.4k|      std::unique_ptr<char16_t[]> utf16_output{
   97|  15.4k|          new char16_t[expected_utf16words]};
   98|       |      // convert to UTF-16BE
   99|  15.4k|      size_t utf16words = e->convert_utf8_to_utf16be(
  100|  15.4k|          source.c_str(), source.size(), utf16_output.get());
  101|       |      // It wrote utf16words * sizeof(char16_t) bytes.
  102|  15.4k|      bool validutf16 = e->validate_utf16be(utf16_output.get(), utf16words);
  103|  15.4k|      if (!validutf16) {
  ------------------
  |  Branch (103:11): [True: 0, False: 15.4k]
  ------------------
  104|      0|        print_input(source, e);
  105|      0|        abort();
  106|      0|      }
  107|       |      // convert it back:
  108|       |      // We need a buffer of size where to write the UTF-8 words.
  109|  15.4k|      size_t expected_utf8words =
  110|  15.4k|          e->utf8_length_from_utf16be(utf16_output.get(), utf16words);
  111|  15.4k|      std::unique_ptr<char[]> utf8_output{new char[expected_utf8words]};
  112|       |      // convert to UTF-8
  113|  15.4k|      size_t utf8words = e->convert_utf16be_to_utf8(
  114|  15.4k|          utf16_output.get(), utf16words, utf8_output.get());
  115|  15.4k|      std::string final_string(utf8_output.get(), utf8words);
  116|  15.4k|      if (final_string != source) {
  ------------------
  |  Branch (116:11): [True: 0, False: 15.4k]
  ------------------
  117|      0|        print_input(source, e);
  118|      0|        abort();
  119|      0|      }
  120|  15.4k|    } else {
  121|       |      // invalid input!!!
  122|       |      // We need a buffer of size where to write the UTF-16BE words.
  123|  1.23k|      size_t expected_utf16words =
  124|  1.23k|          e->utf16_length_from_utf8(source.c_str(), source.size());
  125|  1.23k|      std::unique_ptr<char16_t[]> utf16_output{
  126|  1.23k|          new char16_t[expected_utf16words]};
  127|       |      // convert to UTF-16BE
  128|  1.23k|      size_t utf16words = e->convert_utf8_to_utf16be(
  129|  1.23k|          source.c_str(), source.size(), utf16_output.get());
  130|  1.23k|      if (utf16words != 0) {
  ------------------
  |  Branch (130:11): [True: 0, False: 1.23k]
  ------------------
  131|      0|        print_input(source, e);
  132|      0|        abort();
  133|      0|      }
  134|  1.23k|    }
  135|       |    /**
  136|       |     * Transcoding from UTF-8 to UTF-32.
  137|       |     */
  138|  16.6k|    if (validutf8) {
  ------------------
  |  Branch (138:9): [True: 15.4k, False: 1.23k]
  ------------------
  139|       |      // We need a buffer of size where to write the UTF-32 words.
  140|  15.4k|      size_t expected_utf32words =
  141|  15.4k|          e->utf32_length_from_utf8(source.c_str(), source.size());
  142|  15.4k|      std::unique_ptr<char32_t[]> utf32_output{
  143|  15.4k|          new char32_t[expected_utf32words]};
  144|       |      // convert to UTF-32
  145|  15.4k|      size_t utf32words = e->convert_utf8_to_utf32(
  146|  15.4k|          source.c_str(), source.size(), utf32_output.get());
  147|       |      // It wrote utf32words * sizeof(char32_t) bytes.
  148|  15.4k|      bool validutf32 = e->validate_utf32(utf32_output.get(), utf32words);
  149|  15.4k|      if (!validutf32) {
  ------------------
  |  Branch (149:11): [True: 0, False: 15.4k]
  ------------------
  150|      0|        return -1;
  151|      0|      }
  152|       |      // convert it back:
  153|       |      // We need a buffer of size where to write the UTF-8 words.
  154|  15.4k|      size_t expected_utf8words =
  155|  15.4k|          e->utf8_length_from_utf32(utf32_output.get(), utf32words);
  156|  15.4k|      std::unique_ptr<char[]> utf8_output{new char[expected_utf8words]};
  157|       |      // convert to UTF-8
  158|  15.4k|      size_t utf8words = e->convert_utf32_to_utf8(
  159|  15.4k|          utf32_output.get(), utf32words, utf8_output.get());
  160|  15.4k|      std::string final_string(utf8_output.get(), utf8words);
  161|  15.4k|      if (source != final_string) {
  ------------------
  |  Branch (161:11): [True: 0, False: 15.4k]
  ------------------
  162|      0|        print_input(source, e);
  163|      0|        abort();
  164|      0|      }
  165|  15.4k|    } else {
  166|       |      // invalid input!!!
  167|  1.23k|      size_t expected_utf32words =
  168|  1.23k|          e->utf32_length_from_utf8(source.c_str(), source.size());
  169|  1.23k|      std::unique_ptr<char32_t[]> utf32_output{
  170|  1.23k|          new char32_t[expected_utf32words]};
  171|       |      // convert to UTF-32
  172|  1.23k|      size_t utf32words = e->convert_utf8_to_utf32(
  173|  1.23k|          source.c_str(), source.size(), utf32_output.get());
  174|  1.23k|      if (utf32words != 0) {
  ------------------
  |  Branch (174:11): [True: 0, False: 1.23k]
  ------------------
  175|      0|        print_input(source, e);
  176|      0|        abort();
  177|      0|      }
  178|  1.23k|    }
  179|       |
  180|       |    /**
  181|       |     * Transcoding from UTF-8 to Latin 1
  182|       |     */
  183|  16.6k|    if (validutf8) {
  ------------------
  |  Branch (183:9): [True: 15.4k, False: 1.23k]
  ------------------
  184|       |      // We need a buffer of size where to write the UTF-16LE words.
  185|  15.4k|      size_t expected_latin1words =
  186|  15.4k|          e->latin1_length_from_utf8(source.c_str(), source.size());
  187|  15.4k|      std::unique_ptr<char[]> latin1_output{new char[expected_latin1words]};
  188|       |      // convert to latin1
  189|  15.4k|      size_t latin1words = e->convert_utf8_to_latin1(
  190|  15.4k|          source.c_str(), source.size(), latin1_output.get());
  191|  15.4k|      if (latin1words != 0) {
  ------------------
  |  Branch (191:11): [True: 745, False: 14.7k]
  ------------------
  192|       |        // convert it back:
  193|       |        // We need a buffer of size where to write the UTF-8 words.
  194|    745|        size_t expected_utf8words =
  195|    745|            e->utf8_length_from_latin1(latin1_output.get(), latin1words);
  196|    745|        std::unique_ptr<char[]> utf8_output{new char[expected_utf8words]};
  197|       |        // convert to UTF-8
  198|    745|        size_t utf8words = e->convert_latin1_to_utf8(
  199|    745|            latin1_output.get(), latin1words, utf8_output.get());
  200|    745|        std::string final_string(utf8_output.get(), utf8words);
  201|    745|        if (final_string != source) {
  ------------------
  |  Branch (201:13): [True: 0, False: 745]
  ------------------
  202|      0|          print_input(source, e);
  203|      0|          abort();
  204|      0|        }
  205|    745|      }
  206|  15.4k|    } else {
  207|       |      // invalid input!!!
  208|       |      // We need a buffer of size where to write the Latin 1 words.
  209|  1.23k|      size_t expected_latin1words =
  210|  1.23k|          e->latin1_length_from_utf8(source.c_str(), source.size());
  211|  1.23k|      std::unique_ptr<char[]> latin1_output{new char[expected_latin1words]};
  212|       |      // convert to Latin 1
  213|  1.23k|      size_t latin1words = e->convert_utf8_to_latin1(
  214|  1.23k|          source.c_str(), source.size(), latin1_output.get());
  215|  1.23k|      if (latin1words != 0) {
  ------------------
  |  Branch (215:11): [True: 0, False: 1.23k]
  ------------------
  216|      0|        print_input(source, e);
  217|      0|        abort();
  218|      0|      }
  219|  1.23k|    }
  220|       |    /**
  221|       |     * Transcoding from UTF-16LE to UTF-8.
  222|       |     */
  223|  16.6k|    {
  224|       |      // Get new source data here as this will allow the fuzzer to optimize it's
  225|       |      // input for UTF16-LE.
  226|  16.6k|      source = fdp.ConsumeRandomLengthString(kMaxStringSize);
  227|       |      // We copy to avoid alignment issues.
  228|  16.6k|      std::unique_ptr<char16_t[]> utf16_source{new char16_t[source.size() / 2]};
  229|  16.6k|      if (source.data() != nullptr) {
  ------------------
  |  Branch (229:11): [True: 16.6k, False: 0]
  ------------------
  230|  16.6k|        std::memcpy(utf16_source.get(), source.data(), source.size() / 2 * 2);
  231|  16.6k|      }
  232|  16.6k|      bool validutf16le =
  233|  16.6k|          e->validate_utf16le(utf16_source.get(), source.size() / 2);
  234|  16.6k|      auto rutf16le = e->validate_utf16le_with_errors(utf16_source.get(),
  235|  16.6k|                                                      source.size() / 2);
  236|  16.6k|      if (validutf16le !=
  ------------------
  |  Branch (236:11): [True: 0, False: 16.6k]
  ------------------
  237|  16.6k|          (rutf16le.error == simdutf::SUCCESS)) { // they should agree
  238|      0|        print_input(source, e);
  239|      0|        abort();
  240|      0|      }
  241|  16.6k|      if (validutf16le) {
  ------------------
  |  Branch (241:11): [True: 16.4k, False: 242]
  ------------------
  242|       |        // We need a buffer of size where to write the UTF-16 words.
  243|  16.4k|        size_t expected_utf8words =
  244|  16.4k|            e->utf8_length_from_utf16le(utf16_source.get(), source.size() / 2);
  245|  16.4k|        std::unique_ptr<char[]> utf8_output{new char[expected_utf8words]};
  246|  16.4k|        size_t utf8words = e->convert_utf16le_to_utf8(
  247|  16.4k|            utf16_source.get(), source.size() / 2, utf8_output.get());
  248|       |        // It wrote utf16words * sizeof(char16_t) bytes.
  249|  16.4k|        bool validutf8 = e->validate_utf8(utf8_output.get(), utf8words);
  250|  16.4k|        if (!validutf8) {
  ------------------
  |  Branch (250:13): [True: 0, False: 16.4k]
  ------------------
  251|      0|          print_input(source, e);
  252|      0|          abort();
  253|      0|        }
  254|       |        // convert it back:
  255|       |        // We need a buffer of size where to write the UTF-16 words.
  256|  16.4k|        size_t expected_utf16words =
  257|  16.4k|            e->utf16_length_from_utf8(utf8_output.get(), utf8words);
  258|  16.4k|        std::unique_ptr<char16_t[]> utf16_output{
  259|  16.4k|            new char16_t[expected_utf16words]};
  260|       |        // convert to UTF-8
  261|  16.4k|        size_t utf16words = e->convert_utf8_to_utf16le(
  262|  16.4k|            utf8_output.get(), utf8words, utf16_output.get());
  263|   106k|        for (size_t i = 0; i < source.size() / 2; i++) {
  ------------------
  |  Branch (263:28): [True: 89.9k, False: 16.4k]
  ------------------
  264|  89.9k|          if (utf16_output.get()[i] != (utf16_source.get())[i]) {
  ------------------
  |  Branch (264:15): [True: 0, False: 89.9k]
  ------------------
  265|      0|            print_input(source, e);
  266|      0|            abort();
  267|      0|          }
  268|  89.9k|        }
  269|  16.4k|      } else {
  270|       |        // invalid input!!!
  271|       |        // We need a buffer of size where to write the UTF-16 words.
  272|    242|        size_t expected_utf8words =
  273|    242|            e->utf8_length_from_utf16le(utf16_source.get(), source.size() / 2);
  274|    242|        std::unique_ptr<char[]> utf8_output{new char[expected_utf8words]};
  275|    242|        size_t utf8words = e->convert_utf16le_to_utf8(
  276|    242|            utf16_source.get(), source.size() / 2, utf8_output.get());
  277|    242|        if (utf8words != 0) {
  ------------------
  |  Branch (277:13): [True: 0, False: 242]
  ------------------
  278|      0|          print_input(source, e);
  279|      0|          abort();
  280|      0|        }
  281|    242|      }
  282|  16.6k|    }
  283|       |
  284|       |    /**
  285|       |     * Transcoding from UTF-16BE to UTF-8.
  286|       |     */
  287|  16.6k|    {
  288|       |      // Get new source data here as this will allow the fuzzer to optimize it's
  289|       |      // input for UTF16-BE.
  290|  16.6k|      source = fdp.ConsumeRandomLengthString(kMaxStringSize);
  291|  16.6k|      std::unique_ptr<char16_t[]> utf16_source{new char16_t[source.size() / 2]};
  292|  16.6k|      if (source.data() != nullptr) {
  ------------------
  |  Branch (292:11): [True: 16.6k, False: 0]
  ------------------
  293|  16.6k|        std::memcpy(utf16_source.get(), source.data(), source.size() / 2 * 2);
  294|  16.6k|      }
  295|  16.6k|      bool validutf16be =
  296|  16.6k|          e->validate_utf16be(utf16_source.get(), source.size() / 2);
  297|  16.6k|      auto rutf16be = e->validate_utf16be_with_errors(utf16_source.get(),
  298|  16.6k|                                                      source.size() / 2);
  299|  16.6k|      if (validutf16be !=
  ------------------
  |  Branch (299:11): [True: 0, False: 16.6k]
  ------------------
  300|  16.6k|          (rutf16be.error == simdutf::SUCCESS)) { // they should agree
  301|      0|        print_input(source, e);
  302|      0|        abort();
  303|      0|      }
  304|  16.6k|      if (validutf16be) {
  ------------------
  |  Branch (304:11): [True: 16.4k, False: 221]
  ------------------
  305|       |        // We need a buffer of size where to write the UTF-16 words.
  306|  16.4k|        size_t expected_utf8words =
  307|  16.4k|            e->utf8_length_from_utf16be(utf16_source.get(), source.size() / 2);
  308|  16.4k|        std::unique_ptr<char[]> utf8_output{new char[expected_utf8words]};
  309|  16.4k|        size_t utf8words = e->convert_utf16be_to_utf8(
  310|  16.4k|            utf16_source.get(), source.size() / 2, utf8_output.get());
  311|       |        // It wrote utf16words * sizeof(char16_t) bytes.
  312|  16.4k|        bool validutf8 = e->validate_utf8(utf8_output.get(), utf8words);
  313|  16.4k|        if (!validutf8) {
  ------------------
  |  Branch (313:13): [True: 0, False: 16.4k]
  ------------------
  314|      0|          print_input(source, e);
  315|      0|          abort();
  316|      0|        }
  317|       |        // convert it back:
  318|       |        // We need a buffer of size where to write the UTF-16 words.
  319|  16.4k|        size_t expected_utf16words =
  320|  16.4k|            e->utf16_length_from_utf8(utf8_output.get(), utf8words);
  321|  16.4k|        std::unique_ptr<char16_t[]> utf16_output{
  322|  16.4k|            new char16_t[expected_utf16words]};
  323|       |        // convert to UTF-8
  324|  16.4k|        size_t utf16words = e->convert_utf8_to_utf16be(
  325|  16.4k|            utf8_output.get(), utf8words, utf16_output.get());
  326|   109k|        for (size_t i = 0; i < source.size() / 2; i++) {
  ------------------
  |  Branch (326:28): [True: 92.9k, False: 16.4k]
  ------------------
  327|  92.9k|          if (utf16_output.get()[i] != (utf16_source.get())[i]) {
  ------------------
  |  Branch (327:15): [True: 0, False: 92.9k]
  ------------------
  328|      0|            print_input(source, e);
  329|      0|            abort();
  330|      0|          }
  331|  92.9k|        }
  332|  16.4k|      } else {
  333|       |        // invalid input!!!
  334|       |        // We need a buffer of size where to write the UTF-16 words.
  335|    221|        size_t expected_utf8words =
  336|    221|            e->utf8_length_from_utf16be(utf16_source.get(), source.size() / 2);
  337|    221|        std::unique_ptr<char[]> utf8_output{new char[expected_utf8words]};
  338|    221|        size_t utf8words = e->convert_utf16be_to_utf8(
  339|    221|            utf16_source.get(), source.size() / 2, utf8_output.get());
  340|    221|        if (utf8words != 0) {
  ------------------
  |  Branch (340:13): [True: 0, False: 221]
  ------------------
  341|      0|          print_input(source, e);
  342|      0|          abort();
  343|      0|        }
  344|    221|      }
  345|  16.6k|    }
  346|       |
  347|       |    /**
  348|       |     * Transcoding from latin1 to UTF-8.
  349|       |     */
  350|       |    // Get new source data here as this will allow the fuzzer to optimize it's
  351|       |    // input for latin1.
  352|  16.6k|    source = fdp.ConsumeRandomLengthString(kMaxStringSize);
  353|  16.6k|    bool validlatin1 = true; // has to be
  354|  16.6k|    if (validlatin1) {
  ------------------
  |  Branch (354:9): [True: 16.6k, False: 0]
  ------------------
  355|       |      // We need a buffer of size where to write the UTF-8 words.
  356|  16.6k|      size_t expected_utf8words =
  357|  16.6k|          e->utf8_length_from_latin1(source.c_str(), source.size());
  358|  16.6k|      std::unique_ptr<char[]> utf8_output{new char[expected_utf8words]};
  359|  16.6k|      size_t utf8words = e->convert_latin1_to_utf8(
  360|  16.6k|          source.c_str(), source.size(), utf8_output.get());
  361|       |      // It wrote utf8words * sizeof(char) bytes.
  362|  16.6k|      bool validutf8 = e->validate_utf8(utf8_output.get(), utf8words);
  363|  16.6k|      if (!validutf8) {
  ------------------
  |  Branch (363:11): [True: 0, False: 16.6k]
  ------------------
  364|      0|        print_input(source, e);
  365|      0|        abort();
  366|      0|      }
  367|       |      // convert it back:
  368|       |      // We need a buffer of size where to write the latin1 words.
  369|  16.6k|      size_t expected_latin1words =
  370|  16.6k|          e->latin1_length_from_utf8(utf8_output.get(), utf8words);
  371|  16.6k|      std::unique_ptr<char[]> latin1_output{new char[expected_latin1words]};
  372|       |      // convert to latin1
  373|  16.6k|      size_t latin1words = e->convert_utf8_to_latin1(
  374|  16.6k|          utf8_output.get(), utf8words, latin1_output.get());
  375|   430k|      for (size_t i = 0; i < source.size(); i++) {
  ------------------
  |  Branch (375:26): [True: 414k, False: 16.6k]
  ------------------
  376|   414k|        if (latin1_output.get()[i] != (source.c_str())[i]) {
  ------------------
  |  Branch (376:13): [True: 0, False: 414k]
  ------------------
  377|      0|          print_input(source, e);
  378|      0|          abort();
  379|      0|        }
  380|   414k|      }
  381|  16.6k|    }
  382|  16.6k|    if (validlatin1) {
  ------------------
  |  Branch (382:9): [True: 16.6k, False: 0]
  ------------------
  383|       |      // We need a buffer of size where to write the UTF-16 words.
  384|  16.6k|      size_t expected_utf16words = e->utf16_length_from_latin1(source.size());
  385|  16.6k|      std::unique_ptr<char16_t[]> utf16_output{
  386|  16.6k|          new char16_t[expected_utf16words]};
  387|  16.6k|      size_t utf16words = e->convert_latin1_to_utf16le(
  388|  16.6k|          source.c_str(), source.size(), utf16_output.get());
  389|       |      // It wrote utf16words * sizeof(char16_t) bytes.
  390|  16.6k|      bool validutf16 = e->validate_utf16le(utf16_output.get(), utf16words);
  391|  16.6k|      if (!validutf16) {
  ------------------
  |  Branch (391:11): [True: 0, False: 16.6k]
  ------------------
  392|      0|        print_input(source, e);
  393|      0|        abort();
  394|      0|      }
  395|       |      // convert it back:
  396|       |      // We need a buffer of size where to write the latin1 words.
  397|  16.6k|      size_t expected_latin1words = e->latin1_length_from_utf16(utf16words);
  398|  16.6k|      std::unique_ptr<char[]> latin1_output{new char[expected_latin1words]};
  399|       |      // convert to latin1
  400|  16.6k|      size_t latin1words = e->convert_utf16le_to_latin1(
  401|  16.6k|          utf16_output.get(), utf16words, latin1_output.get());
  402|   430k|      for (size_t i = 0; i < source.size(); i++) {
  ------------------
  |  Branch (402:26): [True: 414k, False: 16.6k]
  ------------------
  403|   414k|        if (latin1_output.get()[i] != (source.c_str())[i]) {
  ------------------
  |  Branch (403:13): [True: 0, False: 414k]
  ------------------
  404|      0|          print_input(source, e);
  405|      0|          abort();
  406|      0|        }
  407|   414k|      }
  408|  16.6k|    }
  409|  16.6k|    if (validlatin1) {
  ------------------
  |  Branch (409:9): [True: 16.6k, False: 0]
  ------------------
  410|       |      // We need a buffer of size where to write the UTF-16 words.
  411|  16.6k|      size_t expected_utf16words = e->utf16_length_from_latin1(source.size());
  412|  16.6k|      std::unique_ptr<char16_t[]> utf16_output{
  413|  16.6k|          new char16_t[expected_utf16words]};
  414|  16.6k|      size_t utf16words = e->convert_latin1_to_utf16be(
  415|  16.6k|          source.c_str(), source.size(), utf16_output.get());
  416|       |      // It wrote utf16words * sizeof(char16_t) bytes.
  417|  16.6k|      bool validutf16 = e->validate_utf16be(utf16_output.get(), utf16words);
  418|  16.6k|      if (!validutf16) {
  ------------------
  |  Branch (418:11): [True: 0, False: 16.6k]
  ------------------
  419|      0|        print_input(source, e);
  420|      0|        abort();
  421|      0|      }
  422|       |      // convert it back:
  423|       |      // We need a buffer of size where to write the latin1 words.
  424|  16.6k|      size_t expected_latin1words = e->latin1_length_from_utf16(utf16words);
  425|  16.6k|      std::unique_ptr<char[]> latin1_output{new char[expected_latin1words]};
  426|       |      // convert to latin1
  427|  16.6k|      size_t latin1words = e->convert_utf16be_to_latin1(
  428|  16.6k|          utf16_output.get(), utf16words, latin1_output.get());
  429|   430k|      for (size_t i = 0; i < source.size(); i++) {
  ------------------
  |  Branch (429:26): [True: 414k, False: 16.6k]
  ------------------
  430|   414k|        if (latin1_output.get()[i] != (source.c_str())[i]) {
  ------------------
  |  Branch (430:13): [True: 0, False: 414k]
  ------------------
  431|      0|          print_input(source, e);
  432|      0|          abort();
  433|      0|        }
  434|   414k|      }
  435|  16.6k|    }
  436|       |
  437|  16.6k|    if (validlatin1) {
  ------------------
  |  Branch (437:9): [True: 16.6k, False: 0]
  ------------------
  438|       |      // We need a buffer of size where to write the UTF-16 words.
  439|  16.6k|      size_t expected_utf32words = e->utf32_length_from_latin1(source.size());
  440|  16.6k|      std::unique_ptr<char32_t[]> utf32_output{
  441|  16.6k|          new char32_t[expected_utf32words]};
  442|  16.6k|      size_t utf32words = e->convert_latin1_to_utf32(
  443|  16.6k|          source.c_str(), source.size(), utf32_output.get());
  444|       |      // It wrote utf16words * sizeof(char16_t) bytes.
  445|  16.6k|      bool validutf32 = e->validate_utf32(utf32_output.get(), utf32words);
  446|  16.6k|      if (!validutf32) {
  ------------------
  |  Branch (446:11): [True: 0, False: 16.6k]
  ------------------
  447|      0|        print_input(source, e);
  448|      0|        abort();
  449|      0|      }
  450|       |      // convert it back:
  451|       |      // We need a buffer of size where to write the latin1 words.
  452|  16.6k|      size_t expected_latin1words = e->latin1_length_from_utf32(utf32words);
  453|  16.6k|      std::unique_ptr<char[]> latin1_output{new char[expected_latin1words]};
  454|       |      // convert to latin1
  455|  16.6k|      size_t latin1words = e->convert_utf32_to_latin1(
  456|  16.6k|          utf32_output.get(), utf32words, latin1_output.get());
  457|   430k|      for (size_t i = 0; i < source.size(); i++) {
  ------------------
  |  Branch (457:26): [True: 414k, False: 16.6k]
  ------------------
  458|   414k|        if (latin1_output.get()[i] != (source.c_str())[i]) {
  ------------------
  |  Branch (458:13): [True: 0, False: 414k]
  ------------------
  459|      0|          print_input(source, e);
  460|      0|          abort();
  461|      0|        }
  462|   414k|      }
  463|  16.6k|    }
  464|       |
  465|       |    /// Base64 tests. We begin by trying to decode the input, even if we
  466|       |    /// expect it to fail.
  467|  16.6k|    {
  468|  16.6k|      size_t max_length_needed =
  469|  16.6k|          e->maximal_binary_length_from_base64(source.data(), source.size());
  470|  16.6k|      std::vector<char> back(max_length_needed);
  471|  16.6k|      simdutf::result r =
  472|  16.6k|          e->base64_to_binary(source.data(), source.size(), back.data());
  473|  16.6k|      if (r.error == simdutf::error_code::SUCCESS) {
  ------------------
  |  Branch (473:11): [True: 15.2k, False: 1.46k]
  ------------------
  474|       |        // We expect failure but if we succeed, then we should have a roundtrip.
  475|  15.2k|        back.resize(r.count);
  476|  15.2k|        std::vector<char> back2(e->base64_length_from_binary(back.size()));
  477|  15.2k|        size_t base64size =
  478|  15.2k|            e->binary_to_base64(back.data(), back.size(), back2.data());
  479|  15.2k|        back2.resize(base64size);
  480|  15.2k|        std::vector<char> back3(
  481|  15.2k|            e->maximal_binary_length_from_base64(back2.data(), back2.size()));
  482|  15.2k|        simdutf::result r2 =
  483|  15.2k|            e->base64_to_binary(back2.data(), back2.size(), back3.data());
  484|  15.2k|        if (r2.error != simdutf::error_code::SUCCESS) {
  ------------------
  |  Branch (484:13): [True: 0, False: 15.2k]
  ------------------
  485|      0|          print_input(source, e);
  486|      0|          return false;
  487|      0|        }
  488|  15.2k|        if (r2.count != back.size()) {
  ------------------
  |  Branch (488:13): [True: 0, False: 15.2k]
  ------------------
  489|      0|          print_input(source, e);
  490|      0|          return false;
  491|      0|        }
  492|  15.2k|        if (back3.size() != back.size()) {
  ------------------
  |  Branch (492:13): [True: 0, False: 15.2k]
  ------------------
  493|      0|          print_input(source, e);
  494|      0|          return false;
  495|      0|        }
  496|  15.2k|      }
  497|  16.6k|    }
  498|       |
  499|       |    // Same as above, but we use the safe decoder version.
  500|  16.6k|    {
  501|  16.6k|      size_t max_length_needed =
  502|  16.6k|          e->maximal_binary_length_from_base64(source.data(), source.size());
  503|  16.6k|      std::vector<char> back(max_length_needed);
  504|  16.6k|      simdutf::result r = simdutf::base64_to_binary_safe(
  505|  16.6k|          source.data(), source.size(), back.data(), max_length_needed);
  506|  16.6k|      if (r.error == simdutf::error_code::SUCCESS) {
  ------------------
  |  Branch (506:11): [True: 15.2k, False: 1.46k]
  ------------------
  507|       |        // We expect failure but if we succeed, then we should have a roundtrip.
  508|  15.2k|        back.resize(max_length_needed);
  509|  15.2k|        std::vector<char> back2(e->base64_length_from_binary(back.size()));
  510|  15.2k|        size_t base64size =
  511|  15.2k|            e->binary_to_base64(back.data(), back.size(), back2.data());
  512|  15.2k|        back2.resize(base64size);
  513|  15.2k|        size_t max_length_needed2 =
  514|  15.2k|            e->maximal_binary_length_from_base64(back2.data(), back2.size());
  515|  15.2k|        std::vector<char> back3(max_length_needed2);
  516|  15.2k|        simdutf::result r2 = simdutf::base64_to_binary_safe(
  517|  15.2k|            back2.data(), back2.size(), back3.data(), max_length_needed2);
  518|  15.2k|        if (r2.error != simdutf::error_code::SUCCESS) {
  ------------------
  |  Branch (518:13): [True: 0, False: 15.2k]
  ------------------
  519|      0|          print_input(source, e);
  520|      0|          return false;
  521|      0|        }
  522|  15.2k|        if (max_length_needed != back.size()) {
  ------------------
  |  Branch (522:13): [True: 0, False: 15.2k]
  ------------------
  523|      0|          print_input(source, e);
  524|      0|          return false;
  525|      0|        }
  526|  15.2k|        if (back3.size() != back.size()) {
  ------------------
  |  Branch (526:13): [True: 0, False: 15.2k]
  ------------------
  527|      0|          print_input(source, e);
  528|      0|          return false;
  529|      0|        }
  530|  15.2k|      }
  531|  16.6k|    }
  532|       |    /// Base64 tests. We encode the content as binary in base64 and we decode
  533|       |    /// it, it should always succeed.
  534|  16.6k|    {
  535|  16.6k|      source = fdp.ConsumeRandomLengthString(kMaxStringSize);
  536|  16.6k|      std::vector<char> base64buffer(
  537|  16.6k|          e->base64_length_from_binary(source.size()));
  538|  16.6k|      size_t base64size = e->binary_to_base64(source.data(), source.size(),
  539|  16.6k|                                              base64buffer.data());
  540|  16.6k|      if (base64size != base64buffer.size()) {
  ------------------
  |  Branch (540:11): [True: 0, False: 16.6k]
  ------------------
  541|      0|        print_input(source, e);
  542|      0|        abort();
  543|      0|      }
  544|  16.6k|      std::vector<char> back(e->maximal_binary_length_from_base64(
  545|  16.6k|          base64buffer.data(), base64buffer.size()));
  546|  16.6k|      simdutf::result r = e->base64_to_binary(base64buffer.data(),
  547|  16.6k|                                              base64buffer.size(), back.data());
  548|  16.6k|      if (r.error != simdutf::error_code::SUCCESS) {
  ------------------
  |  Branch (548:11): [True: 0, False: 16.6k]
  ------------------
  549|      0|        print_input(source, e);
  550|      0|        abort();
  551|      0|      }
  552|  16.6k|      if (r.count != source.size()) {
  ------------------
  |  Branch (552:11): [True: 0, False: 16.6k]
  ------------------
  553|      0|        print_input(source, e);
  554|      0|        abort();
  555|      0|      }
  556|   376k|      for (size_t i = 0; i < source.size(); i++) {
  ------------------
  |  Branch (556:26): [True: 360k, False: 16.6k]
  ------------------
  557|   360k|        if (back[i] != (source.c_str())[i]) {
  ------------------
  |  Branch (557:13): [True: 0, False: 360k]
  ------------------
  558|      0|          print_input(source, e);
  559|      0|          abort();
  560|      0|        }
  561|   360k|      }
  562|  16.6k|      size_t max_length = back.size();
  563|  16.6k|      r = simdutf::base64_to_binary_safe(
  564|  16.6k|          base64buffer.data(), base64buffer.size(), back.data(), max_length);
  565|  16.6k|      if (r.error != simdutf::error_code::SUCCESS) {
  ------------------
  |  Branch (565:11): [True: 0, False: 16.6k]
  ------------------
  566|      0|        printf("base64 round trip failed, error code %d\n", r.error);
  567|      0|        print_input(source, e);
  568|      0|        return false;
  569|      0|      }
  570|  16.6k|      if (max_length != source.size()) {
  ------------------
  |  Branch (570:11): [True: 0, False: 16.6k]
  ------------------
  571|      0|        printf("base64 safe round trip failed, not the same size %zu %zu\n",
  572|      0|               max_length, source.size());
  573|      0|        print_input(source, e);
  574|      0|        return false;
  575|      0|      }
  576|   376k|      for (size_t i = 0; i < source.size(); i++) {
  ------------------
  |  Branch (576:26): [True: 360k, False: 16.6k]
  ------------------
  577|   360k|        if (back[i] != (source.c_str())[i]) {
  ------------------
  |  Branch (577:13): [True: 0, False: 360k]
  ------------------
  578|      0|          printf("base64 round trip failed, same size, different content\n");
  579|      0|          print_input(source, e);
  580|      0|          return false;
  581|      0|        }
  582|   360k|      }
  583|  16.6k|    }
  584|       |
  585|  16.6k|  } // for (auto &e : simdutf::get_available_implementations()) {
  586|       |
  587|  5.56k|  return 0;
  588|  5.56k|} // extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {

_ZN7simdutf26base64_to_binary_safe_implIcEENS_6resultEPKT_mPcRmNS_14base64_optionsENS_27last_chunk_handling_optionsEb:
   63|  48.5k|    bool decode_up_to_bad_char) noexcept {
   64|  48.5k|  static_assert(std::is_same<chartype, char>::value ||
   65|  48.5k|                    std::is_same<chartype, char16_t>::value,
   66|  48.5k|                "Only char and char16_t are supported.");
   67|  48.5k|  size_t remaining_input_length = length;
   68|  48.5k|  size_t remaining_output_length = outlen;
   69|  48.5k|  size_t input_position = 0;
   70|  48.5k|  size_t output_position = 0;
   71|       |
   72|       |  // We also do a first pass using the fast path to decode as much as possible
   73|  48.5k|  size_t safe_input = (std::min)(
   74|  48.5k|      remaining_input_length,
   75|  48.5k|      base64_length_from_binary(remaining_output_length / 3 * 3, options));
   76|  48.5k|  bool done_with_partial = (safe_input == remaining_input_length);
   77|  48.5k|  simdutf::full_result r;
   78|       |
   79|       |#if SIMDUTF_CPLUSPLUS23
   80|       |  if consteval {
   81|       |    r = scalar::base64::base64_to_binary_details_impl(
   82|       |        input + input_position, safe_input, output + output_position, options,
   83|       |        done_with_partial
   84|       |            ? last_chunk_handling_options
   85|       |            : simdutf::last_chunk_handling_options::only_full_chunks);
   86|       |  } else
   87|       |#endif
   88|  48.5k|  {
   89|  48.5k|    r = get_active_implementation()->base64_to_binary_details(
   90|  48.5k|        input + input_position, safe_input, output + output_position, options,
   91|  48.5k|        done_with_partial
  ------------------
  |  Branch (91:9): [True: 45.7k, False: 2.87k]
  ------------------
   92|  48.5k|            ? last_chunk_handling_options
   93|  48.5k|            : simdutf::last_chunk_handling_options::only_full_chunks);
   94|  48.5k|  }
   95|  48.5k|  simdutf_log_assert(r.input_count <= safe_input,
   96|  48.5k|                     "You should not read more than safe_input");
   97|  48.5k|  simdutf_log_assert(r.output_count <= remaining_output_length,
   98|  48.5k|                     "You should not write more than remaining_output_length");
   99|       |  // Technically redundant, but we want to be explicit about it.
  100|  48.5k|  input_position += r.input_count;
  101|  48.5k|  output_position += r.output_count;
  102|  48.5k|  remaining_input_length -= r.input_count;
  103|  48.5k|  remaining_output_length -= r.output_count;
  104|  48.5k|  if (r.error != simdutf::error_code::SUCCESS) {
  ------------------
  |  Branch (104:7): [True: 1.14k, False: 47.4k]
  ------------------
  105|       |    // There is an error. We return.
  106|  1.14k|    if (decode_up_to_bad_char &&
  ------------------
  |  Branch (106:9): [True: 0, False: 1.14k]
  ------------------
  107|      0|        r.error == error_code::INVALID_BASE64_CHARACTER) {
  ------------------
  |  Branch (107:9): [True: 0, False: 0]
  ------------------
  108|      0|      return slow_base64_to_binary_safe_impl(
  109|      0|          input, length, output, outlen, options, last_chunk_handling_options);
  110|      0|    }
  111|  1.14k|    outlen = output_position;
  112|  1.14k|    return {r.error, input_position};
  113|  1.14k|  }
  114|       |
  115|  47.4k|  if (done_with_partial) {
  ------------------
  |  Branch (115:7): [True: 45.0k, False: 2.37k]
  ------------------
  116|       |    // We are done. We have decoded everything.
  117|  45.0k|    outlen = output_position;
  118|  45.0k|    return {simdutf::error_code::SUCCESS, input_position};
  119|  45.0k|  }
  120|       |  // We have decoded some data, but we still have some data to decode.
  121|       |  // We need to decode the rest of the input buffer.
  122|  2.37k|  r = simdutf::scalar::base64::base64_to_binary_details_safe_impl(
  123|  2.37k|      input + input_position, remaining_input_length, output + output_position,
  124|  2.37k|      remaining_output_length, options, last_chunk_handling_options);
  125|  2.37k|  input_position += r.input_count;
  126|  2.37k|  output_position += r.output_count;
  127|  2.37k|  remaining_input_length -= r.input_count;
  128|  2.37k|  remaining_output_length -= r.output_count;
  129|       |
  130|  2.37k|  if (r.error != simdutf::error_code::SUCCESS) {
  ------------------
  |  Branch (130:7): [True: 324, False: 2.05k]
  ------------------
  131|       |    // There is an error. We return.
  132|    324|    if (decode_up_to_bad_char &&
  ------------------
  |  Branch (132:9): [True: 0, False: 324]
  ------------------
  133|      0|        r.error == error_code::INVALID_BASE64_CHARACTER) {
  ------------------
  |  Branch (133:9): [True: 0, False: 0]
  ------------------
  134|      0|      return slow_base64_to_binary_safe_impl(
  135|      0|          input, length, output, outlen, options, last_chunk_handling_options);
  136|      0|    }
  137|    324|    outlen = output_position;
  138|    324|    return {r.error, input_position};
  139|    324|  }
  140|  2.05k|  if (input_position < length) {
  ------------------
  |  Branch (140:7): [True: 0, False: 2.05k]
  ------------------
  141|       |    // We cannot process the entire input in one go, so we need to
  142|       |    // process it in two steps: first the fast path, then the slow path.
  143|       |    // In some cases, the processing might 'eat up' trailing ignorable
  144|       |    // characters in the fast path, but that can be a problem.
  145|       |    // suppose we have just white space followed by a single base64 character.
  146|       |    // If we first process the white space with the fast path, it will
  147|       |    // eat all of it. But, by the JavaScript standard, we should consume
  148|       |    // no character. See
  149|       |    // https://tc39.es/proposal-arraybuffer-base64/spec/#sec-frombase64
  150|      0|    while (input_position > 0 &&
  ------------------
  |  Branch (150:12): [True: 0, False: 0]
  ------------------
  151|      0|           base64_ignorable(input[input_position - 1], options)) {
  ------------------
  |  Branch (151:12): [True: 0, False: 0]
  ------------------
  152|      0|      input_position--;
  153|      0|    }
  154|      0|  }
  155|  2.05k|  outlen = output_position;
  156|  2.05k|  return {simdutf::error_code::SUCCESS, input_position};
  157|  2.37k|}

_ZN7simdutf6resultC2ENS_10error_codeEm:
   87|   158k|      : error{err}, count{pos} {}
_ZNK7simdutf6result6is_errEv:
   93|  8.50k|  simdutf_really_inline simdutf_constexpr23 bool is_err() const noexcept {
   94|  8.50k|    return error != error_code::SUCCESS;
   95|  8.50k|  }
_ZN7simdutf11full_resultC2Ev:
  106|  48.5k|      : error{error_code::SUCCESS}, input_count{0}, output_count{0} {}
_ZN7simdutf11full_resultC2ENS_10error_codeEmm:
  111|  99.4k|      : error{err}, input_count{pos_in}, output_count{pos_out} {}
_ZN7simdutf11full_resultC2ENS_10error_codeEmmb:
  114|    127|      : error{err}, input_count{pos_in}, output_count{pos_out},
  115|    127|        padding_error{padding_err} {}
_ZNK7simdutf11full_resultcvNS_6resultEEv:
  117|  48.5k|  simdutf_really_inline simdutf_constexpr23 operator result() const noexcept {
  118|  48.5k|    if (error == error_code::SUCCESS) {
  ------------------
  |  Branch (118:9): [True: 47.1k, False: 1.46k]
  ------------------
  119|  47.1k|      return result{error, output_count};
  120|  47.1k|    } else {
  121|  1.46k|      return result{error, input_count};
  122|  1.46k|    }
  123|  48.5k|  }

_ZN7simdutf10is_partialENS_27last_chunk_handling_optionsE:
 4122|  20.0k|is_partial(last_chunk_handling_options options) {
 4123|  20.0k|  return (options == stop_before_partial) || (options == only_full_chunks);
  ------------------
  |  Branch (4123:10): [True: 0, False: 20.0k]
  |  Branch (4123:46): [True: 3.67k, False: 16.3k]
  ------------------
 4124|  20.0k|}
_ZNK7simdutf14implementation25required_instruction_setsEv:
 5143|  22.2k|  virtual uint32_t required_instruction_sets() const {
 5144|  22.2k|    return _required_instruction_sets;
 5145|  22.2k|  }
_ZNK7simdutf14implementation24utf16_length_from_latin1Em:
 6333|  33.3k|  utf16_length_from_latin1(size_t length) const noexcept {
 6334|  33.3k|    return length;
 6335|  33.3k|  }
_ZNK7simdutf14implementation24latin1_length_from_utf32Em:
 6521|  16.6k|  latin1_length_from_utf32(size_t length) const noexcept {
 6522|  16.6k|    return length;
 6523|  16.6k|  }
_ZNK7simdutf14implementation24latin1_length_from_utf16Em:
 6558|  33.3k|  latin1_length_from_utf16(size_t length) const noexcept {
 6559|  33.3k|    return length;
 6560|  33.3k|  }
_ZNK7simdutf14implementation24utf32_length_from_latin1Em:
 6591|  16.6k|  utf32_length_from_latin1(size_t length) const noexcept {
 6592|  16.6k|    return length;
 6593|  16.6k|  }
_ZN7simdutf14implementationC2EPKcS2_j:
 7029|      5|      : _name(name), _description(description),
 7030|      5|        _required_instruction_sets(required_instruction_sets) {}
_ZN7simdutf8internal29available_implementation_listC2Ev:
 7061|      1|  simdutf_really_inline available_implementation_list() {}
_ZN7simdutf25base64_length_from_binaryEmNS_14base64_optionsE:
 4433|  48.5k|    size_t length, base64_options options = base64_default) noexcept {
 4434|  48.5k|  return scalar::base64::base64_length_from_binary(length, options);
 4435|  48.5k|}
_ZN7simdutf16base64_ignorableEcNS_14base64_optionsE:
 4848|  3.48k|base64_ignorable(char input, base64_options options = base64_default) noexcept {
 4849|  3.48k|  return scalar::base64::is_ignorable(input, options);
 4850|  3.48k|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEaSEPS3_:
 7132|      1|  atomic_ptr &operator=(T *_ptr) {
 7133|      1|    ptr = _ptr;
 7134|      1|    return *this;
 7135|      1|  }
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEcvPS3_Ev:
 7129|      1|  operator T *() { return ptr.load(); }
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEC2EPS3_:
 7109|      1|  atomic_ptr(T *_ptr) : ptr{_ptr} {}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEptEv:
 7131|  48.5k|  T *operator->() { return ptr.load(); }

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

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6425base64_length_from_binaryEmNS_14base64_optionsE:
  836|  95.7k|base64_length_from_binary(size_t length, base64_options options) noexcept {
  837|       |  // By default, we use padding if we are not using the URL variant.
  838|       |  // This is check with ((options & base64_url) == 0) which returns true if we
  839|       |  // are not using the URL variant. However, we also allow 'inversion' of the
  840|       |  // convention with the base64_reverse_padding option. If the
  841|       |  // base64_reverse_padding option is set, we use padding if we are using the
  842|       |  // URL variant, and we omit it if we are not using the URL variant. This is
  843|       |  // checked with
  844|       |  // ((options & base64_reverse_padding) == base64_reverse_padding).
  845|  95.7k|  bool use_padding =
  846|  95.7k|      ((options & base64_url) == 0) ^
  847|  95.7k|      ((options & base64_reverse_padding) == base64_reverse_padding);
  848|  95.7k|  if (!use_padding) {
  ------------------
  |  Branch (848:7): [True: 0, False: 95.7k]
  ------------------
  849|      0|    return length / 3 * 4 + ((length % 3) ? (length % 3) + 1 : 0);
  ------------------
  |  Branch (849:30): [True: 0, False: 0]
  ------------------
  850|      0|  }
  851|  95.7k|  return (length + 2) / 3 *
  852|  95.7k|         4; // We use padding to make the length a multiple of 4.
  853|  95.7k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6418tail_encode_base64EPcPKcmNS_14base64_optionsE:
  648|  16.3k|    char *dst, const char *src, size_t srclen, base64_options options) {
  649|  16.3k|  return tail_encode_base64_impl(dst, src, srclen, options);
  650|  16.3k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6423tail_encode_base64_implILb0EEEmPcPKcmNS_14base64_optionsEmm:
  418|  47.1k|    size_t line_length = simdutf::default_line_length, size_t line_offset = 0) {
  419|       |  if constexpr (use_lines) {
  420|       |    // sanitize line_length and starting_line_offset.
  421|       |    // line_length must be greater than 3.
  422|       |    if (line_length < 4) {
  423|       |      line_length = 4;
  424|       |    }
  425|       |    simdutf_log_assert(line_offset <= line_length,
  426|       |                       "line_offset should be less than line_length");
  427|       |  }
  428|       |  // By default, we use padding if we are not using the URL variant.
  429|       |  // This is check with ((options & base64_url) == 0) which returns true if we
  430|       |  // are not using the URL variant. However, we also allow 'inversion' of the
  431|       |  // convention with the base64_reverse_padding option. If the
  432|       |  // base64_reverse_padding option is set, we use padding if we are using the
  433|       |  // URL variant, and we omit it if we are not using the URL variant. This is
  434|       |  // checked with
  435|       |  // ((options & base64_reverse_padding) == base64_reverse_padding).
  436|  47.1k|  bool use_padding =
  437|  47.1k|      ((options & base64_url) == 0) ^
  438|  47.1k|      ((options & base64_reverse_padding) == base64_reverse_padding);
  439|       |  // This looks like 3 branches, but we expect the compiler to resolve this to
  440|       |  // a single branch:
  441|  47.1k|  const char *e0 = (options & base64_url) ? tables::base64::base64_url::e0
  ------------------
  |  Branch (441:20): [True: 0, False: 47.1k]
  ------------------
  442|  47.1k|                                          : tables::base64::base64_default::e0;
  443|  47.1k|  const char *e1 = (options & base64_url) ? tables::base64::base64_url::e1
  ------------------
  |  Branch (443:20): [True: 0, False: 47.1k]
  ------------------
  444|  47.1k|                                          : tables::base64::base64_default::e1;
  445|  47.1k|  const char *e2 = (options & base64_url) ? tables::base64::base64_url::e2
  ------------------
  |  Branch (445:20): [True: 0, False: 47.1k]
  ------------------
  446|  47.1k|                                          : tables::base64::base64_default::e2;
  447|  47.1k|  char *out = dst;
  448|  47.1k|  size_t i = 0;
  449|  47.1k|  uint8_t t1, t2, t3;
  450|  92.4k|  for (; i + 2 < srclen; i += 3) {
  ------------------
  |  Branch (450:10): [True: 45.3k, False: 47.1k]
  ------------------
  451|  45.3k|    t1 = uint8_t(src[i]);
  452|  45.3k|    t2 = uint8_t(src[i + 1]);
  453|  45.3k|    t3 = uint8_t(src[i + 2]);
  454|       |    if constexpr (use_lines) {
  455|       |      if (line_offset + 3 >= line_length) {
  456|       |        if (line_offset == line_length) {
  457|       |          *out++ = '\n';
  458|       |          *out++ = e0[t1];
  459|       |          *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  460|       |          *out++ = e1[((t2 & 0x0F) << 2) | ((t3 >> 6) & 0x03)];
  461|       |          *out++ = e2[t3];
  462|       |          line_offset = 4;
  463|       |        } else if (line_offset + 1 == line_length) {
  464|       |          *out++ = e0[t1];
  465|       |          *out++ = '\n';
  466|       |          *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  467|       |          *out++ = e1[((t2 & 0x0F) << 2) | ((t3 >> 6) & 0x03)];
  468|       |          *out++ = e2[t3];
  469|       |          line_offset = 3;
  470|       |        } else if (line_offset + 2 == line_length) {
  471|       |          *out++ = e0[t1];
  472|       |          *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  473|       |          *out++ = '\n';
  474|       |          *out++ = e1[((t2 & 0x0F) << 2) | ((t3 >> 6) & 0x03)];
  475|       |          *out++ = e2[t3];
  476|       |          line_offset = 2;
  477|       |        } else if (line_offset + 3 == line_length) {
  478|       |          *out++ = e0[t1];
  479|       |          *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  480|       |          *out++ = e1[((t2 & 0x0F) << 2) | ((t3 >> 6) & 0x03)];
  481|       |          *out++ = '\n';
  482|       |          *out++ = e2[t3];
  483|       |          line_offset = 1;
  484|       |        }
  485|       |      } else {
  486|       |        *out++ = e0[t1];
  487|       |        *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  488|       |        *out++ = e1[((t2 & 0x0F) << 2) | ((t3 >> 6) & 0x03)];
  489|       |        *out++ = e2[t3];
  490|       |        line_offset += 4;
  491|       |      }
  492|  45.3k|    } else {
  493|  45.3k|      *out++ = e0[t1];
  494|  45.3k|      *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  495|  45.3k|      *out++ = e1[((t2 & 0x0F) << 2) | ((t3 >> 6) & 0x03)];
  496|  45.3k|      *out++ = e2[t3];
  497|  45.3k|    }
  498|  45.3k|  }
  499|  47.1k|  switch (srclen - i) {
  500|  44.9k|  case 0:
  ------------------
  |  Branch (500:3): [True: 44.9k, False: 2.13k]
  ------------------
  501|  44.9k|    break;
  502|  1.35k|  case 1:
  ------------------
  |  Branch (502:3): [True: 1.35k, False: 45.7k]
  ------------------
  503|  1.35k|    t1 = uint8_t(src[i]);
  504|       |    if constexpr (use_lines) {
  505|       |      if (use_padding) {
  506|       |        if (line_offset + 3 >= line_length) {
  507|       |          if (line_offset == line_length) {
  508|       |            *out++ = '\n';
  509|       |            *out++ = e0[t1];
  510|       |            *out++ = e1[(t1 & 0x03) << 4];
  511|       |            *out++ = '=';
  512|       |            *out++ = '=';
  513|       |          } else if (line_offset + 1 == line_length) {
  514|       |            *out++ = e0[t1];
  515|       |            *out++ = '\n';
  516|       |            *out++ = e1[(t1 & 0x03) << 4];
  517|       |            *out++ = '=';
  518|       |            *out++ = '=';
  519|       |          } else if (line_offset + 2 == line_length) {
  520|       |            *out++ = e0[t1];
  521|       |            *out++ = e1[(t1 & 0x03) << 4];
  522|       |            *out++ = '\n';
  523|       |            *out++ = '=';
  524|       |            *out++ = '=';
  525|       |          } else if (line_offset + 3 == line_length) {
  526|       |            *out++ = e0[t1];
  527|       |            *out++ = e1[(t1 & 0x03) << 4];
  528|       |            *out++ = '=';
  529|       |            *out++ = '\n';
  530|       |            *out++ = '=';
  531|       |          }
  532|       |        } else {
  533|       |          *out++ = e0[t1];
  534|       |          *out++ = e1[(t1 & 0x03) << 4];
  535|       |          *out++ = '=';
  536|       |          *out++ = '=';
  537|       |        }
  538|       |      } else {
  539|       |        if (line_offset + 2 >= line_length) {
  540|       |          if (line_offset == line_length) {
  541|       |            *out++ = '\n';
  542|       |            *out++ = e0[uint8_t(src[i])];
  543|       |            *out++ = e1[(uint8_t(src[i]) & 0x03) << 4];
  544|       |          } else if (line_offset + 1 == line_length) {
  545|       |            *out++ = e0[uint8_t(src[i])];
  546|       |            *out++ = '\n';
  547|       |            *out++ = e1[(uint8_t(src[i]) & 0x03) << 4];
  548|       |          } else {
  549|       |            *out++ = e0[uint8_t(src[i])];
  550|       |            *out++ = e1[(uint8_t(src[i]) & 0x03) << 4];
  551|       |            // *out++ = '\n'; ==> no newline at the end of the output
  552|       |          }
  553|       |        } else {
  554|       |          *out++ = e0[uint8_t(src[i])];
  555|       |          *out++ = e1[(uint8_t(src[i]) & 0x03) << 4];
  556|       |        }
  557|       |      }
  558|  1.35k|    } else {
  559|  1.35k|      *out++ = e0[t1];
  560|  1.35k|      *out++ = e1[(t1 & 0x03) << 4];
  561|  1.35k|      if (use_padding) {
  ------------------
  |  Branch (561:11): [True: 1.35k, False: 0]
  ------------------
  562|  1.35k|        *out++ = '=';
  563|  1.35k|        *out++ = '=';
  564|  1.35k|      }
  565|  1.35k|    }
  566|  1.35k|    break;
  567|    779|  default: /* case 2 */
  ------------------
  |  Branch (567:3): [True: 779, False: 46.3k]
  ------------------
  568|    779|    t1 = uint8_t(src[i]);
  569|    779|    t2 = uint8_t(src[i + 1]);
  570|       |    if constexpr (use_lines) {
  571|       |      if (use_padding) {
  572|       |        if (line_offset + 3 >= line_length) {
  573|       |          if (line_offset == line_length) {
  574|       |            *out++ = '\n';
  575|       |            *out++ = e0[t1];
  576|       |            *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  577|       |            *out++ = e2[(t2 & 0x0F) << 2];
  578|       |            *out++ = '=';
  579|       |          } else if (line_offset + 1 == line_length) {
  580|       |            *out++ = e0[t1];
  581|       |            *out++ = '\n';
  582|       |            *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  583|       |            *out++ = e2[(t2 & 0x0F) << 2];
  584|       |            *out++ = '=';
  585|       |          } else if (line_offset + 2 == line_length) {
  586|       |            *out++ = e0[t1];
  587|       |            *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  588|       |            *out++ = '\n';
  589|       |            *out++ = e2[(t2 & 0x0F) << 2];
  590|       |            *out++ = '=';
  591|       |          } else if (line_offset + 3 == line_length) {
  592|       |            *out++ = e0[t1];
  593|       |            *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  594|       |            *out++ = e2[(t2 & 0x0F) << 2];
  595|       |            *out++ = '\n';
  596|       |            *out++ = '=';
  597|       |          }
  598|       |        } else {
  599|       |          *out++ = e0[t1];
  600|       |          *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  601|       |          *out++ = e2[(t2 & 0x0F) << 2];
  602|       |          *out++ = '=';
  603|       |        }
  604|       |      } else {
  605|       |        if (line_offset + 3 >= line_length) {
  606|       |          if (line_offset == line_length) {
  607|       |            *out++ = '\n';
  608|       |            *out++ = e0[t1];
  609|       |            *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  610|       |            *out++ = e2[(t2 & 0x0F) << 2];
  611|       |          } else if (line_offset + 1 == line_length) {
  612|       |            *out++ = e0[t1];
  613|       |            *out++ = '\n';
  614|       |            *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  615|       |            *out++ = e2[(t2 & 0x0F) << 2];
  616|       |          } else if (line_offset + 2 == line_length) {
  617|       |            *out++ = e0[t1];
  618|       |            *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  619|       |            *out++ = '\n';
  620|       |            *out++ = e2[(t2 & 0x0F) << 2];
  621|       |          } else {
  622|       |            *out++ = e0[t1];
  623|       |            *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  624|       |            *out++ = e2[(t2 & 0x0F) << 2];
  625|       |            // *out++ = '\n'; ==> no newline at the end of the output
  626|       |          }
  627|       |        } else {
  628|       |          *out++ = e0[t1];
  629|       |          *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  630|       |          *out++ = e2[(t2 & 0x0F) << 2];
  631|       |        }
  632|       |      }
  633|    779|    } else {
  634|    779|      *out++ = e0[t1];
  635|    779|      *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  636|    779|      *out++ = e2[(t2 & 0x0F) << 2];
  637|    779|      if (use_padding) {
  ------------------
  |  Branch (637:11): [True: 779, False: 0]
  ------------------
  638|    779|        *out++ = '=';
  639|    779|      }
  640|    779|    }
  641|  47.1k|  }
  642|  47.1k|  return (size_t)(out - dst);
  643|  47.1k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6413is_eight_byteIcEEbT_:
   19|   354k|template <class char_type> simdutf_constexpr23 bool is_eight_byte(char_type c) {
   20|   354k|  if constexpr (sizeof(char_type) == 1) {
   21|   354k|    return true;
   22|   354k|  }
   23|      0|  return uint8_t(c) == c;
   24|   354k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6433maximal_binary_length_from_base64IPKcEEmT_m:
  654|  80.5k|maximal_binary_length_from_base64(InputPtr input, size_t length) noexcept {
  655|       |  // We process the padding characters ('=') at the end to make sure
  656|       |  // that we return an exact result when the input has no ignorable characters
  657|       |  // (e.g., spaces).
  658|  80.5k|  size_t padding = 0;
  659|  80.5k|  if (length > 0) {
  ------------------
  |  Branch (659:7): [True: 7.62k, False: 72.8k]
  ------------------
  660|  7.62k|    if (input[length - 1] == '=') {
  ------------------
  |  Branch (660:9): [True: 2.31k, False: 5.30k]
  ------------------
  661|  2.31k|      padding++;
  662|  2.31k|      if (length > 1 && input[length - 2] == '=') {
  ------------------
  |  Branch (662:11): [True: 2.28k, False: 38]
  |  Branch (662:25): [True: 1.40k, False: 875]
  ------------------
  663|  1.40k|        padding++;
  664|  1.40k|      }
  665|  2.31k|    }
  666|  7.62k|  }
  667|       |  // The input is not otherwise processed for ignorable characters or
  668|       |  // validation, so that the function runs in constant time (very fast). In
  669|       |  // practice, base64 inputs without ignorable characters are common and the
  670|       |  // common case are line separated inputs with relatively long lines (e.g., 76
  671|       |  // characters) which leads this function to a slight (1%) overestimation of
  672|       |  // the output size.
  673|       |  //
  674|       |  // Of course, some inputs might contain an arbitrary number of spaces or
  675|       |  // newlines, which would make this function return a very pessimistic output
  676|       |  // size but systems that produce base64 outputs typically do not do that and
  677|       |  // if they do, they do not care much about minimizing memory usage.
  678|       |  //
  679|       |  // In specialized applications, users may know that their input is line
  680|       |  // separated, which can be checked very quickly by by iterating (e.g., over 76
  681|       |  // character chunks, looking for the linefeed characters only). We could
  682|       |  // provide a specialized function for that, but it is not clear that the added
  683|       |  // complexity is worth it for us.
  684|       |  //
  685|  80.5k|  size_t actual_length = length - padding;
  686|  80.5k|  if (actual_length % 4 <= 1) {
  ------------------
  |  Branch (686:7): [True: 77.4k, False: 3.09k]
  ------------------
  687|  77.4k|    return actual_length / 4 * 3;
  688|  77.4k|  }
  689|       |  // if we have a valid input, then the remainder must be 2 or 3 adding one or
  690|       |  // two extra bytes.
  691|  3.09k|  return actual_length / 4 * 3 + (actual_length % 4) - 1;
  692|  80.5k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6412is_ignorableIcEEbT_NS_14base64_optionsE:
   28|  3.48k|                                      simdutf::base64_options options) {
   29|  3.48k|  const uint8_t *to_base64 =
   30|  3.48k|      (options & base64_default_or_url)
  ------------------
  |  Branch (30:7): [True: 0, False: 3.48k]
  ------------------
   31|  3.48k|          ? tables::base64::to_base64_default_or_url_value
   32|  3.48k|          : ((options & base64_url) ? tables::base64::to_base64_url_value
  ------------------
  |  Branch (32:14): [True: 0, False: 3.48k]
  ------------------
   33|  3.48k|                                    : tables::base64::to_base64_value);
   34|  3.48k|  const bool ignore_garbage =
   35|  3.48k|      (options == base64_options::base64_url_accept_garbage) ||
  ------------------
  |  Branch (35:7): [True: 0, False: 3.48k]
  ------------------
   36|  3.48k|      (options == base64_options::base64_default_accept_garbage) ||
  ------------------
  |  Branch (36:7): [True: 0, False: 3.48k]
  ------------------
   37|  3.48k|      (options == base64_options::base64_default_or_url_accept_garbage);
  ------------------
  |  Branch (37:7): [True: 0, False: 3.48k]
  ------------------
   38|  3.48k|  uint8_t code = to_base64[uint8_t(c)];
   39|  3.48k|  if (is_eight_byte(c) && code <= 63) {
  ------------------
  |  Branch (39:7): [True: 3.48k, False: 0]
  |  Branch (39:27): [True: 460, False: 3.02k]
  ------------------
   40|    460|    return false;
   41|    460|  }
   42|  3.02k|  if (is_eight_byte(c) && code == 64) {
  ------------------
  |  Branch (42:7): [True: 3.02k, False: 0]
  |  Branch (42:27): [True: 3.02k, False: 0]
  ------------------
   43|  3.02k|    return true;
   44|  3.02k|  }
   45|      0|  return ignore_garbage;
   46|  3.02k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base648find_endIcEENS2_13reduced_inputEPKT_mNS_14base64_optionsE:
  100|  99.5k|                                           simdutf::base64_options options) {
  101|  99.5k|  const uint8_t *to_base64 =
  102|  99.5k|      (options & base64_default_or_url)
  ------------------
  |  Branch (102:7): [True: 0, False: 99.5k]
  ------------------
  103|  99.5k|          ? tables::base64::to_base64_default_or_url_value
  104|  99.5k|          : ((options & base64_url) ? tables::base64::to_base64_url_value
  ------------------
  |  Branch (104:14): [True: 0, False: 99.5k]
  ------------------
  105|  99.5k|                                    : tables::base64::to_base64_value);
  106|  99.5k|  const bool ignore_garbage =
  107|  99.5k|      (options == base64_options::base64_url_accept_garbage) ||
  ------------------
  |  Branch (107:7): [True: 0, False: 99.5k]
  ------------------
  108|  99.5k|      (options == base64_options::base64_default_accept_garbage) ||
  ------------------
  |  Branch (108:7): [True: 0, False: 99.5k]
  ------------------
  109|  99.5k|      (options == base64_options::base64_default_or_url_accept_garbage);
  ------------------
  |  Branch (109:7): [True: 0, False: 99.5k]
  ------------------
  110|       |
  111|  99.5k|  size_t equalsigns = 0;
  112|       |  // We intentionally include trailing spaces in the full input length.
  113|       |  // See https://github.com/simdutf/simdutf/issues/824
  114|  99.5k|  size_t full_input_length = srclen;
  115|       |  // skip trailing spaces
  116|   108k|  while (!ignore_garbage && srclen > 0 &&
  ------------------
  |  Branch (116:10): [True: 108k, False: 0]
  |  Branch (116:29): [True: 19.7k, False: 88.4k]
  ------------------
  117|  19.7k|         scalar::base64::is_eight_byte(src[srclen - 1]) &&
  ------------------
  |  Branch (117:10): [True: 19.7k, False: 0]
  ------------------
  118|  19.7k|         to_base64[uint8_t(src[srclen - 1])] == 64) {
  ------------------
  |  Branch (118:10): [True: 8.59k, False: 11.1k]
  ------------------
  119|  8.59k|    srclen--;
  120|  8.59k|  }
  121|  99.5k|  size_t equallocation =
  122|  99.5k|      srclen; // location of the first padding character if any
  123|  99.5k|  if (ignore_garbage) {
  ------------------
  |  Branch (123:7): [True: 0, False: 99.5k]
  ------------------
  124|       |    // Technically, we don't need to find the first padding character, we can
  125|       |    // just change our algorithms, but it adds substantial complexity.
  126|      0|    auto it = simdutf::find(src, src + srclen, '=');
  127|      0|    if (it != src + srclen) {
  ------------------
  |  Branch (127:9): [True: 0, False: 0]
  ------------------
  128|      0|      equallocation = it - src;
  129|      0|      equalsigns = 1;
  130|      0|      srclen = equallocation;
  131|      0|      full_input_length = equallocation + 1;
  132|      0|    }
  133|      0|    return {equalsigns, equallocation, srclen, full_input_length};
  134|      0|  }
  135|  99.5k|  if (!ignore_garbage && srclen > 0 && src[srclen - 1] == '=') {
  ------------------
  |  Branch (135:7): [True: 99.5k, False: 0]
  |  Branch (135:26): [True: 11.1k, False: 88.4k]
  |  Branch (135:40): [True: 3.73k, False: 7.37k]
  ------------------
  136|       |    // This is the last '=' sign.
  137|  3.73k|    equallocation = srclen - 1;
  138|  3.73k|    srclen--;
  139|  3.73k|    equalsigns = 1;
  140|       |    // skip trailing spaces
  141|  4.10k|    while (srclen > 0 && scalar::base64::is_eight_byte(src[srclen - 1]) &&
  ------------------
  |  Branch (141:12): [True: 4.04k, False: 61]
  |  Branch (141:26): [True: 4.04k, False: 0]
  ------------------
  142|  4.04k|           to_base64[uint8_t(src[srclen - 1])] == 64) {
  ------------------
  |  Branch (142:12): [True: 371, False: 3.66k]
  ------------------
  143|    371|      srclen--;
  144|    371|    }
  145|  3.73k|    if (srclen > 0 && src[srclen - 1] == '=') {
  ------------------
  |  Branch (145:9): [True: 3.66k, False: 61]
  |  Branch (145:23): [True: 2.34k, False: 1.32k]
  ------------------
  146|       |      // This is the second '=' sign.
  147|  2.34k|      equallocation = srclen - 1;
  148|  2.34k|      srclen--;
  149|  2.34k|      equalsigns = 2;
  150|  2.34k|    }
  151|  3.73k|  }
  152|  99.5k|  return {equalsigns, equallocation, srclen, full_input_length};
  153|  99.5k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6423base64_tail_decode_safeIcEENS_11full_resultEPcmPKT_mmNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  385|  2.32k|    base64_options options, last_chunk_handling_options last_chunk_options) {
  386|  2.32k|  return base64_tail_decode_impl<true>(dst, outlen, src, length,
  387|  2.32k|                                       padding_characters, options,
  388|  2.32k|                                       last_chunk_options);
  389|  2.32k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6423base64_tail_decode_implILb1EcEENS_11full_resultEPcmPKT0_mmNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  164|  2.32k|    base64_options options, last_chunk_handling_options last_chunk_options) {
  165|  2.32k|  char *dstend = dst + outlen;
  166|  2.32k|  (void)dstend;
  167|       |  // This looks like 10 branches, but we expect the compiler to resolve this to
  168|       |  // two branches (easily predicted):
  169|  2.32k|  const uint8_t *to_base64 =
  170|  2.32k|      (options & base64_default_or_url)
  ------------------
  |  Branch (170:7): [True: 0, False: 2.32k]
  ------------------
  171|  2.32k|          ? tables::base64::to_base64_default_or_url_value
  172|  2.32k|          : ((options & base64_url) ? tables::base64::to_base64_url_value
  ------------------
  |  Branch (172:14): [True: 0, False: 2.32k]
  ------------------
  173|  2.32k|                                    : tables::base64::to_base64_value);
  174|  2.32k|  const uint32_t *d0 =
  175|  2.32k|      (options & base64_default_or_url)
  ------------------
  |  Branch (175:7): [True: 0, False: 2.32k]
  ------------------
  176|  2.32k|          ? tables::base64::base64_default_or_url::d0
  177|  2.32k|          : ((options & base64_url) ? tables::base64::base64_url::d0
  ------------------
  |  Branch (177:14): [True: 0, False: 2.32k]
  ------------------
  178|  2.32k|                                    : tables::base64::base64_default::d0);
  179|  2.32k|  const uint32_t *d1 =
  180|  2.32k|      (options & base64_default_or_url)
  ------------------
  |  Branch (180:7): [True: 0, False: 2.32k]
  ------------------
  181|  2.32k|          ? tables::base64::base64_default_or_url::d1
  182|  2.32k|          : ((options & base64_url) ? tables::base64::base64_url::d1
  ------------------
  |  Branch (182:14): [True: 0, False: 2.32k]
  ------------------
  183|  2.32k|                                    : tables::base64::base64_default::d1);
  184|  2.32k|  const uint32_t *d2 =
  185|  2.32k|      (options & base64_default_or_url)
  ------------------
  |  Branch (185:7): [True: 0, False: 2.32k]
  ------------------
  186|  2.32k|          ? tables::base64::base64_default_or_url::d2
  187|  2.32k|          : ((options & base64_url) ? tables::base64::base64_url::d2
  ------------------
  |  Branch (187:14): [True: 0, False: 2.32k]
  ------------------
  188|  2.32k|                                    : tables::base64::base64_default::d2);
  189|  2.32k|  const uint32_t *d3 =
  190|  2.32k|      (options & base64_default_or_url)
  ------------------
  |  Branch (190:7): [True: 0, False: 2.32k]
  ------------------
  191|  2.32k|          ? tables::base64::base64_default_or_url::d3
  192|  2.32k|          : ((options & base64_url) ? tables::base64::base64_url::d3
  ------------------
  |  Branch (192:14): [True: 0, False: 2.32k]
  ------------------
  193|  2.32k|                                    : tables::base64::base64_default::d3);
  194|  2.32k|  const bool ignore_garbage =
  195|  2.32k|      (options == base64_options::base64_url_accept_garbage) ||
  ------------------
  |  Branch (195:7): [True: 0, False: 2.32k]
  ------------------
  196|  2.32k|      (options == base64_options::base64_default_accept_garbage) ||
  ------------------
  |  Branch (196:7): [True: 0, False: 2.32k]
  ------------------
  197|  2.32k|      (options == base64_options::base64_default_or_url_accept_garbage);
  ------------------
  |  Branch (197:7): [True: 0, False: 2.32k]
  ------------------
  198|       |
  199|  2.32k|  const char_type *srcend = src + length;
  200|  2.32k|  const char_type *srcinit = src;
  201|  2.32k|  const char *dstinit = dst;
  202|       |
  203|  2.32k|  uint32_t x;
  204|  2.32k|  size_t idx;
  205|  2.32k|  uint8_t buffer[4];
  206|  2.36k|  while (true) {
  ------------------
  |  Branch (206:10): [True: 2.36k, Folded]
  ------------------
  207|  2.42k|    while (srcend - src >= 4 && is_eight_byte(src[0]) &&
  ------------------
  |  Branch (207:12): [True: 249, False: 2.17k]
  |  Branch (207:33): [True: 249, False: 0]
  ------------------
  208|    249|           is_eight_byte(src[1]) && is_eight_byte(src[2]) &&
  ------------------
  |  Branch (208:12): [True: 249, False: 0]
  |  Branch (208:37): [True: 249, False: 0]
  ------------------
  209|    249|           is_eight_byte(src[3]) &&
  ------------------
  |  Branch (209:12): [True: 249, False: 0]
  ------------------
  210|    249|           (x = d0[uint8_t(src[0])] | d1[uint8_t(src[1])] |
  ------------------
  |  Branch (210:12): [True: 62, False: 187]
  ------------------
  211|    249|                d2[uint8_t(src[2])] | d3[uint8_t(src[3])]) < 0x01FFFFFF) {
  212|     62|      if (check_capacity && dstend - dst < 3) {
  ------------------
  |  Branch (212:11): [True: 62, Folded]
  |  Branch (212:29): [True: 0, False: 62]
  ------------------
  213|      0|        return {OUTPUT_BUFFER_TOO_SMALL, size_t(src - srcinit),
  214|      0|                size_t(dst - dstinit)};
  215|      0|      }
  216|     62|      *dst++ = static_cast<char>(x & 0xFF);
  217|     62|      *dst++ = static_cast<char>((x >> 8) & 0xFF);
  218|     62|      *dst++ = static_cast<char>((x >> 16) & 0xFF);
  219|     62|      src += 4;
  220|     62|    }
  221|  2.36k|    const char_type *srccur = src;
  222|  2.36k|    idx = 0;
  223|       |    // we need at least four characters.
  224|  2.36k|#ifdef __clang__
  225|       |    // If possible, we read four characters at a time. (It is an optimization.)
  226|  2.36k|    if (ignore_garbage && src + 4 <= srcend) {
  ------------------
  |  Branch (226:9): [True: 0, False: 2.36k]
  |  Branch (226:27): [True: 0, False: 0]
  ------------------
  227|      0|      char_type c0 = src[0];
  228|      0|      char_type c1 = src[1];
  229|      0|      char_type c2 = src[2];
  230|      0|      char_type c3 = src[3];
  231|       |
  232|      0|      uint8_t code0 = to_base64[uint8_t(c0)];
  233|      0|      uint8_t code1 = to_base64[uint8_t(c1)];
  234|      0|      uint8_t code2 = to_base64[uint8_t(c2)];
  235|      0|      uint8_t code3 = to_base64[uint8_t(c3)];
  236|       |
  237|      0|      buffer[idx] = code0;
  238|      0|      idx += (is_eight_byte(c0) && code0 <= 63);
  ------------------
  |  Branch (238:15): [True: 0, False: 0]
  |  Branch (238:36): [True: 0, False: 0]
  ------------------
  239|      0|      buffer[idx] = code1;
  240|      0|      idx += (is_eight_byte(c1) && code1 <= 63);
  ------------------
  |  Branch (240:15): [True: 0, False: 0]
  |  Branch (240:36): [True: 0, False: 0]
  ------------------
  241|      0|      buffer[idx] = code2;
  242|      0|      idx += (is_eight_byte(c2) && code2 <= 63);
  ------------------
  |  Branch (242:15): [True: 0, False: 0]
  |  Branch (242:36): [True: 0, False: 0]
  ------------------
  243|      0|      buffer[idx] = code3;
  244|      0|      idx += (is_eight_byte(c3) && code3 <= 63);
  ------------------
  |  Branch (244:15): [True: 0, False: 0]
  |  Branch (244:36): [True: 0, False: 0]
  ------------------
  245|      0|      src += 4;
  246|      0|    }
  247|  2.36k|#endif
  248|  13.6k|    while ((idx < 4) && (src < srcend)) {
  ------------------
  |  Branch (248:12): [True: 13.5k, False: 41]
  |  Branch (248:25): [True: 11.4k, False: 2.13k]
  ------------------
  249|  11.4k|      char_type c = *src;
  250|       |
  251|  11.4k|      uint8_t code = to_base64[uint8_t(c)];
  252|  11.4k|      buffer[idx] = uint8_t(code);
  253|  11.4k|      if (is_eight_byte(c) && code <= 63) {
  ------------------
  |  Branch (253:11): [True: 11.4k, False: 0]
  |  Branch (253:31): [True: 4.93k, False: 6.51k]
  ------------------
  254|  4.93k|        idx++;
  255|  6.51k|      } else if (!ignore_garbage &&
  ------------------
  |  Branch (255:18): [True: 6.51k, False: 0]
  ------------------
  256|  6.51k|                 (code > 64 || !scalar::base64::is_eight_byte(c))) {
  ------------------
  |  Branch (256:19): [True: 191, False: 6.32k]
  |  Branch (256:32): [True: 0, False: 6.32k]
  ------------------
  257|    191|        return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  258|    191|                size_t(dst - dstinit)};
  259|  6.32k|      } else {
  260|       |        // We have a space or a newline or garbage. We ignore it.
  261|  6.32k|      }
  262|  11.2k|      src++;
  263|  11.2k|    }
  264|  2.17k|    if (idx != 4) {
  ------------------
  |  Branch (264:9): [True: 2.13k, False: 41]
  ------------------
  265|  2.13k|      simdutf_log_assert(idx < 4, "idx should be less than 4");
  266|       |      // We never should have that the number of base64 characters + the
  267|       |      // number of padding characters is more than 4.
  268|  2.13k|      if (!ignore_garbage && (idx + padding_characters > 4)) {
  ------------------
  |  Branch (268:11): [True: 2.13k, False: 0]
  |  Branch (268:30): [True: 7, False: 2.12k]
  ------------------
  269|      7|        return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  270|      7|                size_t(dst - dstinit), true};
  271|      7|      }
  272|       |
  273|       |      // The idea here is that in loose mode,
  274|       |      // if there is padding at all, it must be used
  275|       |      // to form 4-wise chunk. However, in loose mode,
  276|       |      // we do accept no padding at all.
  277|  2.12k|      if (!ignore_garbage &&
  ------------------
  |  Branch (277:11): [True: 2.12k, False: 0]
  ------------------
  278|  2.12k|          last_chunk_options == last_chunk_handling_options::loose &&
  ------------------
  |  Branch (278:11): [True: 2.12k, False: 0]
  ------------------
  279|  2.12k|          (idx >= 2) && padding_characters > 0 &&
  ------------------
  |  Branch (279:11): [True: 1.94k, False: 177]
  |  Branch (279:25): [True: 1.76k, False: 184]
  ------------------
  280|  1.76k|          ((idx + padding_characters) & 3) != 0) {
  ------------------
  |  Branch (280:11): [True: 11, False: 1.75k]
  ------------------
  281|     11|        return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  282|     11|                size_t(dst - dstinit), true};
  283|     11|      } else
  284|       |
  285|       |        // The idea here is that in strict mode, we do not want to accept
  286|       |        // incomplete base64 chunks. So if the chunk was otherwise valid, we
  287|       |        // return BASE64_INPUT_REMAINDER.
  288|  2.11k|        if (!ignore_garbage &&
  ------------------
  |  Branch (288:13): [True: 2.11k, False: 0]
  ------------------
  289|  2.11k|            last_chunk_options == last_chunk_handling_options::strict &&
  ------------------
  |  Branch (289:13): [True: 0, False: 2.11k]
  ------------------
  290|      0|            (idx >= 2) && ((idx + padding_characters) & 3) != 0) {
  ------------------
  |  Branch (290:13): [True: 0, False: 0]
  |  Branch (290:27): [True: 0, False: 0]
  ------------------
  291|       |          // The partial chunk was at src - idx
  292|      0|          return {BASE64_INPUT_REMAINDER, size_t(src - srcinit),
  293|      0|                  size_t(dst - dstinit), true};
  294|      0|        } else
  295|       |          // If there is a partial chunk with insufficient padding, with
  296|       |          // stop_before_partial, we need to just ignore it. In "only full"
  297|       |          // mode, skip the minute there are padding characters.
  298|  2.11k|          if ((last_chunk_options ==
  ------------------
  |  Branch (298:16): [True: 0, False: 2.11k]
  ------------------
  299|  2.11k|                   last_chunk_handling_options::stop_before_partial &&
  300|      0|               (padding_characters + idx < 4) && (idx != 0) &&
  ------------------
  |  Branch (300:16): [True: 0, False: 0]
  |  Branch (300:50): [True: 0, False: 0]
  ------------------
  301|      0|               (idx >= 2 || padding_characters == 0)) ||
  ------------------
  |  Branch (301:17): [True: 0, False: 0]
  |  Branch (301:29): [True: 0, False: 0]
  ------------------
  302|  2.11k|              (last_chunk_options ==
  ------------------
  |  Branch (302:16): [True: 0, False: 2.11k]
  ------------------
  303|  2.11k|                   last_chunk_handling_options::only_full_chunks &&
  304|      0|               (idx >= 2 || padding_characters == 0))) {
  ------------------
  |  Branch (304:17): [True: 0, False: 0]
  |  Branch (304:29): [True: 0, False: 0]
  ------------------
  305|       |            // partial means that we are *not* going to consume the read
  306|       |            // characters. We need to rewind the src pointer.
  307|      0|            src = srccur;
  308|      0|            return {SUCCESS, size_t(src - srcinit), size_t(dst - dstinit)};
  309|  2.11k|          } else {
  310|  2.11k|            if (idx == 2) {
  ------------------
  |  Branch (310:17): [True: 1.27k, False: 841]
  ------------------
  311|  1.27k|              uint32_t triple = (uint32_t(buffer[0]) << 3 * 6) +
  312|  1.27k|                                (uint32_t(buffer[1]) << 2 * 6);
  313|  1.27k|              if (!ignore_garbage &&
  ------------------
  |  Branch (313:19): [True: 1.27k, False: 0]
  ------------------
  314|  1.27k|                  (last_chunk_options == last_chunk_handling_options::strict) &&
  ------------------
  |  Branch (314:19): [True: 0, False: 1.27k]
  ------------------
  315|      0|                  (triple & 0xffff)) {
  ------------------
  |  Branch (315:19): [True: 0, False: 0]
  ------------------
  316|      0|                return {BASE64_EXTRA_BITS, size_t(src - srcinit),
  317|      0|                        size_t(dst - dstinit)};
  318|      0|              }
  319|  1.27k|              if (check_capacity && dstend - dst < 1) {
  ------------------
  |  Branch (319:19): [True: 1.27k, Folded]
  |  Branch (319:37): [True: 0, False: 1.27k]
  ------------------
  320|      0|                return {OUTPUT_BUFFER_TOO_SMALL, size_t(srccur - srcinit),
  321|      0|                        size_t(dst - dstinit)};
  322|      0|              }
  323|  1.27k|              *dst++ = static_cast<char>((triple >> 16) & 0xFF);
  324|  1.27k|            } else if (idx == 3) {
  ------------------
  |  Branch (324:24): [True: 664, False: 177]
  ------------------
  325|    664|              uint32_t triple = (uint32_t(buffer[0]) << 3 * 6) +
  326|    664|                                (uint32_t(buffer[1]) << 2 * 6) +
  327|    664|                                (uint32_t(buffer[2]) << 1 * 6);
  328|    664|              if (!ignore_garbage &&
  ------------------
  |  Branch (328:19): [True: 664, False: 0]
  ------------------
  329|    664|                  (last_chunk_options == last_chunk_handling_options::strict) &&
  ------------------
  |  Branch (329:19): [True: 0, False: 664]
  ------------------
  330|      0|                  (triple & 0xff)) {
  ------------------
  |  Branch (330:19): [True: 0, False: 0]
  ------------------
  331|      0|                return {BASE64_EXTRA_BITS, size_t(src - srcinit),
  332|      0|                        size_t(dst - dstinit)};
  333|      0|              }
  334|    664|              if (check_capacity && dstend - dst < 2) {
  ------------------
  |  Branch (334:19): [True: 664, Folded]
  |  Branch (334:37): [True: 0, False: 664]
  ------------------
  335|      0|                return {OUTPUT_BUFFER_TOO_SMALL, size_t(srccur - srcinit),
  336|      0|                        size_t(dst - dstinit)};
  337|      0|              }
  338|    664|              *dst++ = static_cast<char>((triple >> 16) & 0xFF);
  339|    664|              *dst++ = static_cast<char>((triple >> 8) & 0xFF);
  340|    664|            } else if (!ignore_garbage && idx == 1 &&
  ------------------
  |  Branch (340:24): [True: 177, False: 0]
  |  Branch (340:43): [True: 82, False: 95]
  ------------------
  341|     82|                       (!is_partial(last_chunk_options) ||
  ------------------
  |  Branch (341:25): [True: 82, False: 0]
  ------------------
  342|      0|                        (is_partial(last_chunk_options) &&
  ------------------
  |  Branch (342:26): [True: 0, False: 0]
  ------------------
  343|     82|                         padding_characters > 0))) {
  ------------------
  |  Branch (343:26): [True: 0, False: 0]
  ------------------
  344|     82|              return {BASE64_INPUT_REMAINDER, size_t(src - srcinit),
  345|     82|                      size_t(dst - dstinit)};
  346|     95|            } else if (!ignore_garbage && idx == 0 && padding_characters > 0) {
  ------------------
  |  Branch (346:24): [True: 95, False: 0]
  |  Branch (346:43): [True: 95, False: 0]
  |  Branch (346:55): [True: 7, False: 88]
  ------------------
  347|      7|              return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  348|      7|                      size_t(dst - dstinit), true};
  349|      7|            }
  350|  2.02k|            return {SUCCESS, size_t(src - srcinit), size_t(dst - dstinit)};
  351|  2.11k|          }
  352|  2.12k|    }
  353|     41|    if (check_capacity && dstend - dst < 3) {
  ------------------
  |  Branch (353:9): [True: 41, Folded]
  |  Branch (353:27): [True: 0, False: 41]
  ------------------
  354|      0|      return {OUTPUT_BUFFER_TOO_SMALL, size_t(srccur - srcinit),
  355|      0|              size_t(dst - dstinit)};
  356|      0|    }
  357|     41|    uint32_t triple =
  358|     41|        (uint32_t(buffer[0]) << 3 * 6) + (uint32_t(buffer[1]) << 2 * 6) +
  359|     41|        (uint32_t(buffer[2]) << 1 * 6) + (uint32_t(buffer[3]) << 0 * 6);
  360|     41|    *dst++ = static_cast<char>((triple >> 16) & 0xFF);
  361|     41|    *dst++ = static_cast<char>((triple >> 8) & 0xFF);
  362|     41|    *dst++ = static_cast<char>(triple & 0xFF);
  363|     41|  }
  364|  2.32k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6417patch_tail_resultENS_11full_resultEmmmmNS_27last_chunk_handling_optionsE:
  394|  9.36k|                  last_chunk_handling_options last_chunk_options) {
  395|  9.36k|  r.input_count += previous_input;
  396|  9.36k|  r.output_count += previous_output;
  397|  9.36k|  if (r.padding_error) {
  ------------------
  |  Branch (397:7): [True: 90, False: 9.27k]
  ------------------
  398|     90|    r.input_count = equallocation;
  399|     90|  }
  400|       |
  401|  9.36k|  if (r.error == error_code::SUCCESS) {
  ------------------
  |  Branch (401:7): [True: 7.65k, False: 1.71k]
  ------------------
  402|  7.65k|    if (!is_partial(last_chunk_options)) {
  ------------------
  |  Branch (402:9): [True: 5.97k, False: 1.67k]
  ------------------
  403|       |      // A success when we are not in stop_before_partial mode.
  404|       |      // means that we have consumed the whole input buffer.
  405|  5.97k|      r.input_count = full_input_length;
  406|  5.97k|    } else if (r.output_count % 3 != 0) {
  ------------------
  |  Branch (406:16): [True: 0, False: 1.67k]
  ------------------
  407|      0|      r.input_count = full_input_length;
  408|      0|    }
  409|  7.65k|  }
  410|  9.36k|  return r;
  411|  9.36k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6434base64_to_binary_details_safe_implIcEENS_11full_resultEPKT_mPcmNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  783|  2.37k|    last_chunk_handling_options last_chunk_options) noexcept {
  784|  2.37k|  const bool ignore_garbage =
  785|  2.37k|      (options == base64_options::base64_url_accept_garbage) ||
  ------------------
  |  Branch (785:7): [True: 0, False: 2.37k]
  ------------------
  786|  2.37k|      (options == base64_options::base64_default_accept_garbage) ||
  ------------------
  |  Branch (786:7): [True: 0, False: 2.37k]
  ------------------
  787|  2.37k|      (options == base64_options::base64_default_or_url_accept_garbage);
  ------------------
  |  Branch (787:7): [True: 0, False: 2.37k]
  ------------------
  788|  2.37k|  auto ri = simdutf::scalar::base64::find_end(input, length, options);
  789|  2.37k|  size_t equallocation = ri.equallocation;
  790|  2.37k|  size_t equalsigns = ri.equalsigns;
  791|  2.37k|  length = ri.srclen;
  792|  2.37k|  size_t full_input_length = ri.full_input_length;
  793|  2.37k|  if (length == 0) {
  ------------------
  |  Branch (793:7): [True: 56, False: 2.32k]
  ------------------
  794|     56|    if (!ignore_garbage && equalsigns > 0) {
  ------------------
  |  Branch (794:9): [True: 56, False: 0]
  |  Branch (794:28): [True: 26, False: 30]
  ------------------
  795|     26|      return {INVALID_BASE64_CHARACTER, equallocation, 0};
  796|     26|    }
  797|     30|    return {SUCCESS, full_input_length, 0};
  798|     56|  }
  799|  2.32k|  full_result r = scalar::base64::base64_tail_decode_safe(
  800|  2.32k|      output, outlen, input, length, equalsigns, options, last_chunk_options);
  801|  2.32k|  r = scalar::base64::patch_tail_result(r, 0, 0, equallocation,
  802|  2.32k|                                        full_input_length, last_chunk_options);
  803|  2.32k|  if (!is_partial(last_chunk_options) && r.error == error_code::SUCCESS &&
  ------------------
  |  Branch (803:7): [True: 2.32k, False: 0]
  |  Branch (803:42): [True: 2.02k, False: 298]
  ------------------
  804|  2.02k|      equalsigns > 0 && !ignore_garbage) {
  ------------------
  |  Branch (804:7): [True: 1.75k, False: 272]
  |  Branch (804:25): [True: 1.75k, False: 0]
  ------------------
  805|       |    // additional checks
  806|  1.75k|    if ((r.output_count % 3 == 0) ||
  ------------------
  |  Branch (806:9): [True: 0, False: 1.75k]
  ------------------
  807|  1.75k|        ((r.output_count % 3) + 1 + equalsigns != 4)) {
  ------------------
  |  Branch (807:9): [True: 0, False: 1.75k]
  ------------------
  808|      0|      return {INVALID_BASE64_CHARACTER, equallocation, r.output_count};
  809|      0|    }
  810|  1.75k|  }
  811|       |
  812|       |  // When is_partial(last_chunk_options) is true, we must either end with
  813|       |  // the end of the stream (beyond whitespace) or right after a non-ignorable
  814|       |  // character or at the very beginning of the stream.
  815|       |  // See https://tc39.es/proposal-arraybuffer-base64/spec/#sec-frombase64
  816|  2.32k|  if (is_partial(last_chunk_options) && r.error == error_code::SUCCESS &&
  ------------------
  |  Branch (816:7): [True: 0, False: 2.32k]
  |  Branch (816:41): [True: 0, False: 0]
  ------------------
  817|      0|      r.input_count < full_input_length) {
  ------------------
  |  Branch (817:7): [True: 0, False: 0]
  ------------------
  818|       |    // First check if we can extend the input to the end of the stream
  819|      0|    while (r.input_count < full_input_length &&
  ------------------
  |  Branch (819:12): [True: 0, False: 0]
  ------------------
  820|      0|           base64_ignorable(*(input + r.input_count), options)) {
  ------------------
  |  Branch (820:12): [True: 0, False: 0]
  ------------------
  821|      0|      r.input_count++;
  822|      0|    }
  823|       |    // If we are still not at the end of the stream, then we must backtrack
  824|       |    // to the last non-ignorable character.
  825|      0|    if (r.input_count < full_input_length) {
  ------------------
  |  Branch (825:9): [True: 0, False: 0]
  ------------------
  826|      0|      while (r.input_count > 0 &&
  ------------------
  |  Branch (826:14): [True: 0, False: 0]
  ------------------
  827|      0|             base64_ignorable(*(input + r.input_count - 1), options)) {
  ------------------
  |  Branch (827:14): [True: 0, False: 0]
  ------------------
  828|      0|        r.input_count--;
  829|      0|      }
  830|      0|    }
  831|      0|  }
  832|  2.32k|  return r;
  833|  2.32k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6429base64_to_binary_details_implIcEENS_11full_resultEPKT_mPcNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  727|  16.4k|    last_chunk_handling_options last_chunk_options) noexcept {
  728|  16.4k|  const bool ignore_garbage =
  729|  16.4k|      (options == base64_options::base64_url_accept_garbage) ||
  ------------------
  |  Branch (729:7): [True: 0, False: 16.4k]
  ------------------
  730|  16.4k|      (options == base64_options::base64_default_accept_garbage) ||
  ------------------
  |  Branch (730:7): [True: 0, False: 16.4k]
  ------------------
  731|  16.4k|      (options == base64_options::base64_default_or_url_accept_garbage);
  ------------------
  |  Branch (731:7): [True: 0, False: 16.4k]
  ------------------
  732|  16.4k|  auto ri = simdutf::scalar::base64::find_end(input, length, options);
  733|  16.4k|  size_t equallocation = ri.equallocation;
  734|  16.4k|  size_t equalsigns = ri.equalsigns;
  735|  16.4k|  length = ri.srclen;
  736|  16.4k|  size_t full_input_length = ri.full_input_length;
  737|  16.4k|  if (length == 0) {
  ------------------
  |  Branch (737:7): [True: 16.0k, False: 415]
  ------------------
  738|  16.0k|    if (!ignore_garbage && equalsigns > 0) {
  ------------------
  |  Branch (738:9): [True: 16.0k, False: 0]
  |  Branch (738:28): [True: 6, False: 16.0k]
  ------------------
  739|      6|      return {INVALID_BASE64_CHARACTER, equallocation, 0, true};
  740|      6|    }
  741|  16.0k|    return {SUCCESS, full_input_length, 0};
  742|  16.0k|  }
  743|    415|  full_result r = scalar::base64::base64_tail_decode(
  744|    415|      output, input, length, equalsigns, options, last_chunk_options);
  745|    415|  r = scalar::base64::patch_tail_result(r, 0, 0, equallocation,
  746|    415|                                        full_input_length, last_chunk_options);
  747|    415|  if (!is_partial(last_chunk_options) && r.error == error_code::SUCCESS &&
  ------------------
  |  Branch (747:7): [True: 415, False: 0]
  |  Branch (747:42): [True: 233, False: 182]
  ------------------
  748|    233|      equalsigns > 0 && !ignore_garbage) {
  ------------------
  |  Branch (748:7): [True: 122, False: 111]
  |  Branch (748:25): [True: 122, False: 0]
  ------------------
  749|       |    // additional checks
  750|    122|    if ((r.output_count % 3 == 0) ||
  ------------------
  |  Branch (750:9): [True: 0, False: 122]
  ------------------
  751|    122|        ((r.output_count % 3) + 1 + equalsigns != 4)) {
  ------------------
  |  Branch (751:9): [True: 0, False: 122]
  ------------------
  752|      0|      return {INVALID_BASE64_CHARACTER, equallocation, r.output_count, true};
  753|      0|    }
  754|    122|  }
  755|       |  // When is_partial(last_chunk_options) is true, we must either end with
  756|       |  // the end of the stream (beyond whitespace) or right after a non-ignorable
  757|       |  // character or at the very beginning of the stream.
  758|       |  // See https://tc39.es/proposal-arraybuffer-base64/spec/#sec-frombase64
  759|    415|  if (is_partial(last_chunk_options) && r.error == error_code::SUCCESS &&
  ------------------
  |  Branch (759:7): [True: 0, False: 415]
  |  Branch (759:41): [True: 0, False: 0]
  ------------------
  760|      0|      r.input_count < full_input_length) {
  ------------------
  |  Branch (760:7): [True: 0, False: 0]
  ------------------
  761|       |    // First check if we can extend the input to the end of the stream
  762|      0|    while (r.input_count < full_input_length &&
  ------------------
  |  Branch (762:12): [True: 0, False: 0]
  ------------------
  763|      0|           base64_ignorable(*(input + r.input_count), options)) {
  ------------------
  |  Branch (763:12): [True: 0, False: 0]
  ------------------
  764|      0|      r.input_count++;
  765|      0|    }
  766|       |    // If we are still not at the end of the stream, then we must backtrack
  767|       |    // to the last non-ignorable character.
  768|      0|    if (r.input_count < full_input_length) {
  ------------------
  |  Branch (768:9): [True: 0, False: 0]
  ------------------
  769|      0|      while (r.input_count > 0 &&
  ------------------
  |  Branch (769:14): [True: 0, False: 0]
  ------------------
  770|      0|             base64_ignorable(*(input + r.input_count - 1), options)) {
  ------------------
  |  Branch (770:14): [True: 0, False: 0]
  ------------------
  771|      0|        r.input_count--;
  772|      0|      }
  773|      0|    }
  774|      0|  }
  775|    415|  return r;
  776|    415|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6418base64_tail_decodeIcEENS_11full_resultEPcPKT_mmNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  371|  7.04k|    base64_options options, last_chunk_handling_options last_chunk_options) {
  372|  7.04k|  return base64_tail_decode_impl<false>(dst, 0, src, length, padding_characters,
  373|  7.04k|                                        options, last_chunk_options);
  374|  7.04k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6423base64_tail_decode_implILb0EcEENS_11full_resultEPcmPKT0_mmNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  164|  7.04k|    base64_options options, last_chunk_handling_options last_chunk_options) {
  165|  7.04k|  char *dstend = dst + outlen;
  166|  7.04k|  (void)dstend;
  167|       |  // This looks like 10 branches, but we expect the compiler to resolve this to
  168|       |  // two branches (easily predicted):
  169|  7.04k|  const uint8_t *to_base64 =
  170|  7.04k|      (options & base64_default_or_url)
  ------------------
  |  Branch (170:7): [True: 0, False: 7.04k]
  ------------------
  171|  7.04k|          ? tables::base64::to_base64_default_or_url_value
  172|  7.04k|          : ((options & base64_url) ? tables::base64::to_base64_url_value
  ------------------
  |  Branch (172:14): [True: 0, False: 7.04k]
  ------------------
  173|  7.04k|                                    : tables::base64::to_base64_value);
  174|  7.04k|  const uint32_t *d0 =
  175|  7.04k|      (options & base64_default_or_url)
  ------------------
  |  Branch (175:7): [True: 0, False: 7.04k]
  ------------------
  176|  7.04k|          ? tables::base64::base64_default_or_url::d0
  177|  7.04k|          : ((options & base64_url) ? tables::base64::base64_url::d0
  ------------------
  |  Branch (177:14): [True: 0, False: 7.04k]
  ------------------
  178|  7.04k|                                    : tables::base64::base64_default::d0);
  179|  7.04k|  const uint32_t *d1 =
  180|  7.04k|      (options & base64_default_or_url)
  ------------------
  |  Branch (180:7): [True: 0, False: 7.04k]
  ------------------
  181|  7.04k|          ? tables::base64::base64_default_or_url::d1
  182|  7.04k|          : ((options & base64_url) ? tables::base64::base64_url::d1
  ------------------
  |  Branch (182:14): [True: 0, False: 7.04k]
  ------------------
  183|  7.04k|                                    : tables::base64::base64_default::d1);
  184|  7.04k|  const uint32_t *d2 =
  185|  7.04k|      (options & base64_default_or_url)
  ------------------
  |  Branch (185:7): [True: 0, False: 7.04k]
  ------------------
  186|  7.04k|          ? tables::base64::base64_default_or_url::d2
  187|  7.04k|          : ((options & base64_url) ? tables::base64::base64_url::d2
  ------------------
  |  Branch (187:14): [True: 0, False: 7.04k]
  ------------------
  188|  7.04k|                                    : tables::base64::base64_default::d2);
  189|  7.04k|  const uint32_t *d3 =
  190|  7.04k|      (options & base64_default_or_url)
  ------------------
  |  Branch (190:7): [True: 0, False: 7.04k]
  ------------------
  191|  7.04k|          ? tables::base64::base64_default_or_url::d3
  192|  7.04k|          : ((options & base64_url) ? tables::base64::base64_url::d3
  ------------------
  |  Branch (192:14): [True: 0, False: 7.04k]
  ------------------
  193|  7.04k|                                    : tables::base64::base64_default::d3);
  194|  7.04k|  const bool ignore_garbage =
  195|  7.04k|      (options == base64_options::base64_url_accept_garbage) ||
  ------------------
  |  Branch (195:7): [True: 0, False: 7.04k]
  ------------------
  196|  7.04k|      (options == base64_options::base64_default_accept_garbage) ||
  ------------------
  |  Branch (196:7): [True: 0, False: 7.04k]
  ------------------
  197|  7.04k|      (options == base64_options::base64_default_or_url_accept_garbage);
  ------------------
  |  Branch (197:7): [True: 0, False: 7.04k]
  ------------------
  198|       |
  199|  7.04k|  const char_type *srcend = src + length;
  200|  7.04k|  const char_type *srcinit = src;
  201|  7.04k|  const char *dstinit = dst;
  202|       |
  203|  7.04k|  uint32_t x;
  204|  7.04k|  size_t idx;
  205|  7.04k|  uint8_t buffer[4];
  206|  7.82k|  while (true) {
  ------------------
  |  Branch (206:10): [True: 7.82k, Folded]
  ------------------
  207|  71.1k|    while (srcend - src >= 4 && is_eight_byte(src[0]) &&
  ------------------
  |  Branch (207:12): [True: 65.4k, False: 5.71k]
  |  Branch (207:33): [True: 65.4k, False: 0]
  ------------------
  208|  65.4k|           is_eight_byte(src[1]) && is_eight_byte(src[2]) &&
  ------------------
  |  Branch (208:12): [True: 65.4k, False: 0]
  |  Branch (208:37): [True: 65.4k, False: 0]
  ------------------
  209|  65.4k|           is_eight_byte(src[3]) &&
  ------------------
  |  Branch (209:12): [True: 65.4k, False: 0]
  ------------------
  210|  65.4k|           (x = d0[uint8_t(src[0])] | d1[uint8_t(src[1])] |
  ------------------
  |  Branch (210:12): [True: 63.3k, False: 2.11k]
  ------------------
  211|  65.4k|                d2[uint8_t(src[2])] | d3[uint8_t(src[3])]) < 0x01FFFFFF) {
  212|  63.3k|      if (check_capacity && dstend - dst < 3) {
  ------------------
  |  Branch (212:11): [Folded, False: 63.3k]
  |  Branch (212:29): [True: 0, False: 0]
  ------------------
  213|      0|        return {OUTPUT_BUFFER_TOO_SMALL, size_t(src - srcinit),
  214|      0|                size_t(dst - dstinit)};
  215|      0|      }
  216|  63.3k|      *dst++ = static_cast<char>(x & 0xFF);
  217|  63.3k|      *dst++ = static_cast<char>((x >> 8) & 0xFF);
  218|  63.3k|      *dst++ = static_cast<char>((x >> 16) & 0xFF);
  219|  63.3k|      src += 4;
  220|  63.3k|    }
  221|  7.82k|    const char_type *srccur = src;
  222|  7.82k|    idx = 0;
  223|       |    // we need at least four characters.
  224|  7.82k|#ifdef __clang__
  225|       |    // If possible, we read four characters at a time. (It is an optimization.)
  226|  7.82k|    if (ignore_garbage && src + 4 <= srcend) {
  ------------------
  |  Branch (226:9): [True: 0, False: 7.82k]
  |  Branch (226:27): [True: 0, False: 0]
  ------------------
  227|      0|      char_type c0 = src[0];
  228|      0|      char_type c1 = src[1];
  229|      0|      char_type c2 = src[2];
  230|      0|      char_type c3 = src[3];
  231|       |
  232|      0|      uint8_t code0 = to_base64[uint8_t(c0)];
  233|      0|      uint8_t code1 = to_base64[uint8_t(c1)];
  234|      0|      uint8_t code2 = to_base64[uint8_t(c2)];
  235|      0|      uint8_t code3 = to_base64[uint8_t(c3)];
  236|       |
  237|      0|      buffer[idx] = code0;
  238|      0|      idx += (is_eight_byte(c0) && code0 <= 63);
  ------------------
  |  Branch (238:15): [True: 0, False: 0]
  |  Branch (238:36): [True: 0, False: 0]
  ------------------
  239|      0|      buffer[idx] = code1;
  240|      0|      idx += (is_eight_byte(c1) && code1 <= 63);
  ------------------
  |  Branch (240:15): [True: 0, False: 0]
  |  Branch (240:36): [True: 0, False: 0]
  ------------------
  241|      0|      buffer[idx] = code2;
  242|      0|      idx += (is_eight_byte(c2) && code2 <= 63);
  ------------------
  |  Branch (242:15): [True: 0, False: 0]
  |  Branch (242:36): [True: 0, False: 0]
  ------------------
  243|      0|      buffer[idx] = code3;
  244|      0|      idx += (is_eight_byte(c3) && code3 <= 63);
  ------------------
  |  Branch (244:15): [True: 0, False: 0]
  |  Branch (244:36): [True: 0, False: 0]
  ------------------
  245|      0|      src += 4;
  246|      0|    }
  247|  7.82k|#endif
  248|  33.1k|    while ((idx < 4) && (src < srcend)) {
  ------------------
  |  Branch (248:12): [True: 32.4k, False: 786]
  |  Branch (248:25): [True: 26.4k, False: 5.91k]
  ------------------
  249|  26.4k|      char_type c = *src;
  250|       |
  251|  26.4k|      uint8_t code = to_base64[uint8_t(c)];
  252|  26.4k|      buffer[idx] = uint8_t(code);
  253|  26.4k|      if (is_eight_byte(c) && code <= 63) {
  ------------------
  |  Branch (253:11): [True: 26.4k, False: 0]
  |  Branch (253:31): [True: 9.98k, False: 16.4k]
  ------------------
  254|  9.98k|        idx++;
  255|  16.4k|      } else if (!ignore_garbage &&
  ------------------
  |  Branch (255:18): [True: 16.4k, False: 0]
  ------------------
  256|  16.4k|                 (code > 64 || !scalar::base64::is_eight_byte(c))) {
  ------------------
  |  Branch (256:19): [True: 1.12k, False: 15.3k]
  |  Branch (256:32): [True: 0, False: 15.3k]
  ------------------
  257|  1.12k|        return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  258|  1.12k|                size_t(dst - dstinit)};
  259|  15.3k|      } else {
  260|       |        // We have a space or a newline or garbage. We ignore it.
  261|  15.3k|      }
  262|  25.3k|      src++;
  263|  25.3k|    }
  264|  6.70k|    if (idx != 4) {
  ------------------
  |  Branch (264:9): [True: 5.91k, False: 786]
  ------------------
  265|  5.91k|      simdutf_log_assert(idx < 4, "idx should be less than 4");
  266|       |      // We never should have that the number of base64 characters + the
  267|       |      // number of padding characters is more than 4.
  268|  5.91k|      if (!ignore_garbage && (idx + padding_characters > 4)) {
  ------------------
  |  Branch (268:11): [True: 5.91k, False: 0]
  |  Branch (268:30): [True: 15, False: 5.90k]
  ------------------
  269|     15|        return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  270|     15|                size_t(dst - dstinit), true};
  271|     15|      }
  272|       |
  273|       |      // The idea here is that in loose mode,
  274|       |      // if there is padding at all, it must be used
  275|       |      // to form 4-wise chunk. However, in loose mode,
  276|       |      // we do accept no padding at all.
  277|  5.90k|      if (!ignore_garbage &&
  ------------------
  |  Branch (277:11): [True: 5.90k, False: 0]
  ------------------
  278|  5.90k|          last_chunk_options == last_chunk_handling_options::loose &&
  ------------------
  |  Branch (278:11): [True: 4.21k, False: 1.68k]
  ------------------
  279|  4.21k|          (idx >= 2) && padding_characters > 0 &&
  ------------------
  |  Branch (279:11): [True: 2.36k, False: 1.85k]
  |  Branch (279:25): [True: 1.78k, False: 582]
  ------------------
  280|  1.78k|          ((idx + padding_characters) & 3) != 0) {
  ------------------
  |  Branch (280:11): [True: 29, False: 1.75k]
  ------------------
  281|     29|        return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  282|     29|                size_t(dst - dstinit), true};
  283|     29|      } else
  284|       |
  285|       |        // The idea here is that in strict mode, we do not want to accept
  286|       |        // incomplete base64 chunks. So if the chunk was otherwise valid, we
  287|       |        // return BASE64_INPUT_REMAINDER.
  288|  5.87k|        if (!ignore_garbage &&
  ------------------
  |  Branch (288:13): [True: 5.87k, False: 0]
  ------------------
  289|  5.87k|            last_chunk_options == last_chunk_handling_options::strict &&
  ------------------
  |  Branch (289:13): [True: 0, False: 5.87k]
  ------------------
  290|      0|            (idx >= 2) && ((idx + padding_characters) & 3) != 0) {
  ------------------
  |  Branch (290:13): [True: 0, False: 0]
  |  Branch (290:27): [True: 0, False: 0]
  ------------------
  291|       |          // The partial chunk was at src - idx
  292|      0|          return {BASE64_INPUT_REMAINDER, size_t(src - srcinit),
  293|      0|                  size_t(dst - dstinit), true};
  294|      0|        } else
  295|       |          // If there is a partial chunk with insufficient padding, with
  296|       |          // stop_before_partial, we need to just ignore it. In "only full"
  297|       |          // mode, skip the minute there are padding characters.
  298|  5.87k|          if ((last_chunk_options ==
  ------------------
  |  Branch (298:16): [True: 0, False: 5.87k]
  ------------------
  299|  5.87k|                   last_chunk_handling_options::stop_before_partial &&
  300|      0|               (padding_characters + idx < 4) && (idx != 0) &&
  ------------------
  |  Branch (300:16): [True: 0, False: 0]
  |  Branch (300:50): [True: 0, False: 0]
  ------------------
  301|      0|               (idx >= 2 || padding_characters == 0)) ||
  ------------------
  |  Branch (301:17): [True: 0, False: 0]
  |  Branch (301:29): [True: 0, False: 0]
  ------------------
  302|  5.87k|              (last_chunk_options ==
  ------------------
  |  Branch (302:16): [True: 1.68k, False: 4.18k]
  ------------------
  303|  5.87k|                   last_chunk_handling_options::only_full_chunks &&
  304|  1.68k|               (idx >= 2 || padding_characters == 0))) {
  ------------------
  |  Branch (304:17): [True: 187, False: 1.49k]
  |  Branch (304:29): [True: 1.49k, False: 8]
  ------------------
  305|       |            // partial means that we are *not* going to consume the read
  306|       |            // characters. We need to rewind the src pointer.
  307|  1.67k|            src = srccur;
  308|  1.67k|            return {SUCCESS, size_t(src - srcinit), size_t(dst - dstinit)};
  309|  4.19k|          } else {
  310|  4.19k|            if (idx == 2) {
  ------------------
  |  Branch (310:17): [True: 1.44k, False: 2.75k]
  ------------------
  311|  1.44k|              uint32_t triple = (uint32_t(buffer[0]) << 3 * 6) +
  312|  1.44k|                                (uint32_t(buffer[1]) << 2 * 6);
  313|  1.44k|              if (!ignore_garbage &&
  ------------------
  |  Branch (313:19): [True: 1.44k, False: 0]
  ------------------
  314|  1.44k|                  (last_chunk_options == last_chunk_handling_options::strict) &&
  ------------------
  |  Branch (314:19): [True: 0, False: 1.44k]
  ------------------
  315|      0|                  (triple & 0xffff)) {
  ------------------
  |  Branch (315:19): [True: 0, False: 0]
  ------------------
  316|      0|                return {BASE64_EXTRA_BITS, size_t(src - srcinit),
  317|      0|                        size_t(dst - dstinit)};
  318|      0|              }
  319|  1.44k|              if (check_capacity && dstend - dst < 1) {
  ------------------
  |  Branch (319:19): [Folded, False: 1.44k]
  |  Branch (319:37): [True: 0, False: 0]
  ------------------
  320|      0|                return {OUTPUT_BUFFER_TOO_SMALL, size_t(srccur - srcinit),
  321|      0|                        size_t(dst - dstinit)};
  322|      0|              }
  323|  1.44k|              *dst++ = static_cast<char>((triple >> 16) & 0xFF);
  324|  2.75k|            } else if (idx == 3) {
  ------------------
  |  Branch (324:24): [True: 894, False: 1.85k]
  ------------------
  325|    894|              uint32_t triple = (uint32_t(buffer[0]) << 3 * 6) +
  326|    894|                                (uint32_t(buffer[1]) << 2 * 6) +
  327|    894|                                (uint32_t(buffer[2]) << 1 * 6);
  328|    894|              if (!ignore_garbage &&
  ------------------
  |  Branch (328:19): [True: 894, False: 0]
  ------------------
  329|    894|                  (last_chunk_options == last_chunk_handling_options::strict) &&
  ------------------
  |  Branch (329:19): [True: 0, False: 894]
  ------------------
  330|      0|                  (triple & 0xff)) {
  ------------------
  |  Branch (330:19): [True: 0, False: 0]
  ------------------
  331|      0|                return {BASE64_EXTRA_BITS, size_t(src - srcinit),
  332|      0|                        size_t(dst - dstinit)};
  333|      0|              }
  334|    894|              if (check_capacity && dstend - dst < 2) {
  ------------------
  |  Branch (334:19): [Folded, False: 894]
  |  Branch (334:37): [True: 0, False: 0]
  ------------------
  335|      0|                return {OUTPUT_BUFFER_TOO_SMALL, size_t(srccur - srcinit),
  336|      0|                        size_t(dst - dstinit)};
  337|      0|              }
  338|    894|              *dst++ = static_cast<char>((triple >> 16) & 0xFF);
  339|    894|              *dst++ = static_cast<char>((triple >> 8) & 0xFF);
  340|  1.85k|            } else if (!ignore_garbage && idx == 1 &&
  ------------------
  |  Branch (340:24): [True: 1.85k, False: 0]
  |  Branch (340:43): [True: 227, False: 1.63k]
  ------------------
  341|    227|                       (!is_partial(last_chunk_options) ||
  ------------------
  |  Branch (341:25): [True: 219, False: 8]
  ------------------
  342|      8|                        (is_partial(last_chunk_options) &&
  ------------------
  |  Branch (342:26): [True: 8, False: 0]
  ------------------
  343|    227|                         padding_characters > 0))) {
  ------------------
  |  Branch (343:26): [True: 8, False: 0]
  ------------------
  344|    227|              return {BASE64_INPUT_REMAINDER, size_t(src - srcinit),
  345|    227|                      size_t(dst - dstinit)};
  346|  1.63k|            } else if (!ignore_garbage && idx == 0 && padding_characters > 0) {
  ------------------
  |  Branch (346:24): [True: 1.63k, False: 0]
  |  Branch (346:43): [True: 1.63k, False: 0]
  |  Branch (346:55): [True: 21, False: 1.61k]
  ------------------
  347|     21|              return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  348|     21|                      size_t(dst - dstinit), true};
  349|     21|            }
  350|  3.94k|            return {SUCCESS, size_t(src - srcinit), size_t(dst - dstinit)};
  351|  4.19k|          }
  352|  5.90k|    }
  353|    786|    if (check_capacity && dstend - dst < 3) {
  ------------------
  |  Branch (353:9): [Folded, False: 786]
  |  Branch (353:27): [True: 0, False: 0]
  ------------------
  354|      0|      return {OUTPUT_BUFFER_TOO_SMALL, size_t(srccur - srcinit),
  355|      0|              size_t(dst - dstinit)};
  356|      0|    }
  357|    786|    uint32_t triple =
  358|    786|        (uint32_t(buffer[0]) << 3 * 6) + (uint32_t(buffer[1]) << 2 * 6) +
  359|    786|        (uint32_t(buffer[2]) << 1 * 6) + (uint32_t(buffer[3]) << 0 * 6);
  360|    786|    *dst++ = static_cast<char>((triple >> 16) & 0xFF);
  361|    786|    *dst++ = static_cast<char>((triple >> 8) & 0xFF);
  362|    786|    *dst++ = static_cast<char>(triple & 0xFF);
  363|    786|  }
  364|  7.04k|}

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

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_115latin1_to_utf167convertILNS_10endiannessE0EPKcQsr7simdutf6detailE22indexes_into_byte_likeIT0_EEEmS7_mPDs:
   14|  6.82k|                                   char16_t *utf16_output) {
   15|  6.82k|  size_t pos = 0;
   16|  6.82k|  char16_t *start{utf16_output};
   17|       |
   18|   106k|  while (pos < len) {
  ------------------
  |  Branch (18:10): [True: 99.6k, False: 6.82k]
  ------------------
   19|  99.6k|    uint16_t word =
   20|  99.6k|        uint8_t(data[pos]); // extend Latin-1 char to 16-bit Unicode code point
   21|  99.6k|    *utf16_output++ =
   22|  99.6k|        char16_t(match_system(big_endian) ? word : u16_swap_bytes(word));
  ------------------
  |  Branch (22:18): [True: 99.6k, Folded]
  ------------------
   23|  99.6k|    pos++;
   24|  99.6k|  }
   25|       |
   26|  6.82k|  return utf16_output - start;
   27|  6.82k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_115latin1_to_utf167convertILNS_10endiannessE1EPKcQsr7simdutf6detailE22indexes_into_byte_likeIT0_EEEmS7_mPDs:
   14|  6.82k|                                   char16_t *utf16_output) {
   15|  6.82k|  size_t pos = 0;
   16|  6.82k|  char16_t *start{utf16_output};
   17|       |
   18|   106k|  while (pos < len) {
  ------------------
  |  Branch (18:10): [True: 99.6k, False: 6.82k]
  ------------------
   19|  99.6k|    uint16_t word =
   20|  99.6k|        uint8_t(data[pos]); // extend Latin-1 char to 16-bit Unicode code point
   21|  99.6k|    *utf16_output++ =
   22|  99.6k|        char16_t(match_system(big_endian) ? word : u16_swap_bytes(word));
  ------------------
  |  Branch (22:18): [Folded, False: 99.6k]
  ------------------
   23|  99.6k|    pos++;
   24|  99.6k|  }
   25|       |
   26|  6.82k|  return utf16_output - start;
   27|  6.82k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_115latin1_to_utf327convertIPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_mPDi:
   14|  6.77k|                                   char32_t *utf32_output) {
   15|  6.77k|  char32_t *start{utf32_output};
   16|   104k|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (16:22): [True: 98.0k, False: 6.77k]
  ------------------
   17|  98.0k|    *utf32_output++ = uint8_t(data[i]);
   18|  98.0k|  }
   19|  6.77k|  return utf32_output - start;
   20|  6.77k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf87convertEPKcmPc:
   64|  8.00k|                                     char *utf8_output) {
   65|  8.00k|  return convert(reinterpret_cast<const unsigned char *>(buf), len,
   66|  8.00k|                 utf8_output);
   67|  8.00k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf87convertIPKhPcQaasr7simdutf6detailE22indexes_into_byte_likeIT_Esr7simdutf6detailE26index_assignable_from_charIT0_EEEmS7_mS8_:
   15|  8.00k|                                   OutputPtr utf8_output) {
   16|       |  // const unsigned char *data = reinterpret_cast<const unsigned char *>(buf);
   17|  8.00k|  size_t pos = 0;
   18|  8.00k|  size_t utf8_pos = 0;
   19|       |
   20|  78.2k|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 70.2k, False: 8.00k]
  ------------------
   21|       |#if SIMDUTF_CPLUSPLUS23
   22|       |    if !consteval
   23|       |#endif
   24|  70.2k|    {
   25|       |      // try to convert the next block of 16 ASCII bytes
   26|  70.2k|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (26:11): [True: 52.0k, False: 18.2k]
  ------------------
   27|       |                             // they are ascii
   28|  52.0k|        uint64_t v1;
   29|  52.0k|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   30|  52.0k|        uint64_t v2;
   31|  52.0k|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   32|  52.0k|        uint64_t v{v1 |
   33|  52.0k|                   v2}; // We are only interested in these bits: 1000 1000 1000
   34|       |                        // 1000, so it makes sense to concatenate everything
   35|  52.0k|        if ((v & 0x8080808080808080) ==
  ------------------
  |  Branch (35:13): [True: 6.05k, False: 45.9k]
  ------------------
   36|  52.0k|            0) { // if NONE of these are set, e.g. all of them are zero, then
   37|       |                 // everything is ASCII
   38|  6.05k|          size_t final_pos = pos + 16;
   39|   102k|          while (pos < final_pos) {
  ------------------
  |  Branch (39:18): [True: 96.9k, False: 6.05k]
  ------------------
   40|  96.9k|            utf8_output[utf8_pos++] = char(data[pos]);
   41|  96.9k|            pos++;
   42|  96.9k|          }
   43|  6.05k|          continue;
   44|  6.05k|        }
   45|  52.0k|      } // if (pos + 16 <= len)
   46|  70.2k|    } // !consteval scope
   47|       |
   48|  64.2k|    unsigned char byte = data[pos];
   49|  64.2k|    if ((byte & 0x80) == 0) { // if ASCII
  ------------------
  |  Branch (49:9): [True: 28.0k, False: 36.2k]
  ------------------
   50|       |      // will generate one UTF-8 bytes
   51|  28.0k|      utf8_output[utf8_pos++] = char(byte);
   52|  28.0k|      pos++;
   53|  36.2k|    } else {
   54|       |      // will generate two UTF-8 bytes
   55|  36.2k|      utf8_output[utf8_pos++] = char((byte >> 6) | 0b11000000);
   56|  36.2k|      utf8_output[utf8_pos++] = char((byte & 0b111111) | 0b10000000);
   57|  36.2k|      pos++;
   58|  36.2k|    }
   59|  64.2k|  } // while
   60|  8.00k|  return utf8_pos;
   61|  8.00k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf823utf8_length_from_latin1IPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_m:
  150|  5.73k|utf8_length_from_latin1(InputPtr input, size_t length) noexcept {
  151|  5.73k|  size_t answer = length;
  152|  5.73k|  size_t i = 0;
  153|       |
  154|       |#if SIMDUTF_CPLUSPLUS23
  155|       |  if !consteval
  156|       |#endif
  157|  5.73k|  {
  158|  5.73k|    auto pop = [](uint64_t v) {
  159|  5.73k|      return (size_t)(((v >> 7) & UINT64_C(0x0101010101010101)) *
  160|  5.73k|                          UINT64_C(0x0101010101010101) >>
  161|  5.73k|                      56);
  162|  5.73k|    };
  163|  9.87k|    for (; i + 32 <= length; i += 32) {
  ------------------
  |  Branch (163:12): [True: 4.14k, False: 5.73k]
  ------------------
  164|  4.14k|      uint64_t v;
  165|  4.14k|      memcpy(&v, input + i, 8);
  166|  4.14k|      answer += pop(v);
  167|  4.14k|      memcpy(&v, input + i + 8, sizeof(v));
  168|  4.14k|      answer += pop(v);
  169|  4.14k|      memcpy(&v, input + i + 16, sizeof(v));
  170|  4.14k|      answer += pop(v);
  171|  4.14k|      memcpy(&v, input + i + 24, sizeof(v));
  172|  4.14k|      answer += pop(v);
  173|  4.14k|    }
  174|  6.02k|    for (; i + 8 <= length; i += 8) {
  ------------------
  |  Branch (174:12): [True: 295, False: 5.73k]
  ------------------
  175|    295|      uint64_t v;
  176|    295|      memcpy(&v, input + i, sizeof(v));
  177|    295|      answer += pop(v);
  178|    295|    }
  179|  5.73k|  } // !consteval scope
  180|  6.57k|  for (; i + 1 <= length; i += 1) {
  ------------------
  |  Branch (180:10): [True: 846, False: 5.73k]
  ------------------
  181|    846|    answer += static_cast<uint8_t>(input[i]) >> 7;
  182|    846|  }
  183|  5.73k|  return answer;
  184|  5.73k|}
simdutf.cpp:_ZZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf823utf8_length_from_latin1IPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_mENKUlmE_clEm:
  158|  16.8k|    auto pop = [](uint64_t v) {
  159|  16.8k|      return (size_t)(((v >> 7) & UINT64_C(0x0101010101010101)) *
  160|       |                          UINT64_C(0x0101010101010101) >>
  161|  16.8k|                      56);
  162|  16.8k|    };

_ZN7simdutf6scalar14u16_swap_bytesEt:
    8|   910k|u16_swap_bytes(const uint16_t word) {
    9|   910k|  return uint16_t((word >> 8) | (word << 8));
   10|   910k|}
_ZN7simdutf6scalar14u32_swap_bytesEj:
   13|  7.04k|u32_swap_bytes(const uint32_t word) {
   14|  7.04k|  return ((word >> 24) & 0xff) |      // move byte 3 to byte 0
   15|  7.04k|         ((word << 8) & 0xff0000) |   // move byte 1 to byte 2
   16|  7.04k|         ((word >> 8) & 0xff00) |     // move byte 2 to byte 1
   17|  7.04k|         ((word << 24) & 0xff000000); // byte 0 to byte 3
   18|  7.04k|}
_ZN7simdutf6scalar5utf1614swap_if_neededILNS_10endiannessE1EEEtt:
   27|   464k|template <endianness big_endian> constexpr uint16_t swap_if_needed(uint16_t c) {
   28|   464k|  return !match_system(big_endian) ? scalar::u16_swap_bytes(c) : c;
  ------------------
  |  Branch (28:10): [True: 464k, Folded]
  ------------------
   29|   464k|}
_ZN7simdutf6scalar5utf1614swap_if_neededILNS_10endiannessE0EEEtt:
   27|   475k|template <endianness big_endian> constexpr uint16_t swap_if_needed(uint16_t c) {
   28|   475k|  return !match_system(big_endian) ? scalar::u16_swap_bytes(c) : c;
  ------------------
  |  Branch (28:10): [Folded, False: 475k]
  ------------------
   29|   475k|}

_ZN7simdutf6scalar5utf168validateILNS_10endiannessE0EEEbPKDsm:
   22|  20.6k|validate(const char16_t *data, size_t len) noexcept {
   23|  20.6k|  uint64_t pos = 0;
   24|   309k|  while (pos < len) {
  ------------------
  |  Branch (24:10): [True: 288k, False: 20.4k]
  ------------------
   25|   288k|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(data[pos]);
   26|   288k|    if ((word & 0xF800) == 0xD800) {
  ------------------
  |  Branch (26:9): [True: 2.57k, False: 286k]
  ------------------
   27|  2.57k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (27:11): [True: 24, False: 2.54k]
  ------------------
   28|     24|        return false;
   29|     24|      }
   30|  2.54k|      char16_t diff = char16_t(word - 0xD800);
   31|  2.54k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (31:11): [True: 48, False: 2.50k]
  ------------------
   32|     48|        return false;
   33|     48|      }
   34|  2.50k|      char16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (34:28): [Folded, False: 2.50k]
  ------------------
   35|  2.50k|                               ? u16_swap_bytes(data[pos + 1])
   36|  2.50k|                               : data[pos + 1];
   37|  2.50k|      char16_t diff2 = char16_t(next_word - 0xDC00);
   38|  2.50k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (38:11): [True: 75, False: 2.42k]
  ------------------
   39|     75|        return false;
   40|     75|      }
   41|  2.42k|      pos += 2;
   42|   286k|    } else {
   43|   286k|      pos++;
   44|   286k|    }
   45|   288k|  }
   46|  20.4k|  return true;
   47|  20.6k|}
_ZN7simdutf6scalar5utf168validateILNS_10endiannessE1EEEbPKDsm:
   22|  20.6k|validate(const char16_t *data, size_t len) noexcept {
   23|  20.6k|  uint64_t pos = 0;
   24|   305k|  while (pos < len) {
  ------------------
  |  Branch (24:10): [True: 285k, False: 20.4k]
  ------------------
   25|   285k|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(data[pos]);
   26|   285k|    if ((word & 0xF800) == 0xD800) {
  ------------------
  |  Branch (26:9): [True: 2.51k, False: 282k]
  ------------------
   27|  2.51k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (27:11): [True: 20, False: 2.49k]
  ------------------
   28|     20|        return false;
   29|     20|      }
   30|  2.49k|      char16_t diff = char16_t(word - 0xD800);
   31|  2.49k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (31:11): [True: 41, False: 2.45k]
  ------------------
   32|     41|        return false;
   33|     41|      }
   34|  2.45k|      char16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (34:28): [True: 2.45k, Folded]
  ------------------
   35|  2.45k|                               ? u16_swap_bytes(data[pos + 1])
   36|  2.45k|                               : data[pos + 1];
   37|  2.45k|      char16_t diff2 = char16_t(next_word - 0xDC00);
   38|  2.45k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (38:11): [True: 72, False: 2.38k]
  ------------------
   39|     72|        return false;
   40|     72|      }
   41|  2.38k|      pos += 2;
   42|   282k|    } else {
   43|   282k|      pos++;
   44|   282k|    }
   45|   285k|  }
   46|  20.4k|  return true;
   47|  20.6k|}
_ZN7simdutf6scalar5utf1620validate_with_errorsILNS_10endiannessE0EEENS_6resultEPKDsm:
   51|  6.26k|validate_with_errors(const char16_t *data, size_t len) noexcept {
   52|  6.26k|  size_t pos = 0;
   53|  54.6k|  while (pos < len) {
  ------------------
  |  Branch (53:10): [True: 48.5k, False: 6.02k]
  ------------------
   54|  48.5k|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(data[pos]);
   55|  48.5k|    if ((word & 0xF800) == 0xD800) {
  ------------------
  |  Branch (55:9): [True: 931, False: 47.6k]
  ------------------
   56|    931|      if (pos + 1 >= len) {
  ------------------
  |  Branch (56:11): [True: 24, False: 907]
  ------------------
   57|     24|        return result(error_code::SURROGATE, pos);
   58|     24|      }
   59|    907|      char16_t diff = char16_t(word - 0xD800);
   60|    907|      if (diff > 0x3FF) {
  ------------------
  |  Branch (60:11): [True: 100, False: 807]
  ------------------
   61|    100|        return result(error_code::SURROGATE, pos);
   62|    100|      }
   63|    807|      char16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (63:28): [Folded, False: 807]
  ------------------
   64|    807|                               ? u16_swap_bytes(data[pos + 1])
   65|    807|                               : data[pos + 1];
   66|    807|      char16_t diff2 = uint16_t(next_word - 0xDC00);
   67|    807|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (67:11): [True: 118, False: 689]
  ------------------
   68|    118|        return result(error_code::SURROGATE, pos);
   69|    118|      }
   70|    689|      pos += 2;
   71|  47.6k|    } else {
   72|  47.6k|      pos++;
   73|  47.6k|    }
   74|  48.5k|  }
   75|  6.02k|  return result(error_code::SUCCESS, pos);
   76|  6.26k|}
_ZN7simdutf6scalar5utf1620validate_with_errorsILNS_10endiannessE1EEENS_6resultEPKDsm:
   51|  6.25k|validate_with_errors(const char16_t *data, size_t len) noexcept {
   52|  6.25k|  size_t pos = 0;
   53|  51.1k|  while (pos < len) {
  ------------------
  |  Branch (53:10): [True: 45.0k, False: 6.03k]
  ------------------
   54|  45.0k|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(data[pos]);
   55|  45.0k|    if ((word & 0xF800) == 0xD800) {
  ------------------
  |  Branch (55:9): [True: 880, False: 44.1k]
  ------------------
   56|    880|      if (pos + 1 >= len) {
  ------------------
  |  Branch (56:11): [True: 20, False: 860]
  ------------------
   57|     20|        return result(error_code::SURROGATE, pos);
   58|     20|      }
   59|    860|      char16_t diff = char16_t(word - 0xD800);
   60|    860|      if (diff > 0x3FF) {
  ------------------
  |  Branch (60:11): [True: 88, False: 772]
  ------------------
   61|     88|        return result(error_code::SURROGATE, pos);
   62|     88|      }
   63|    772|      char16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (63:28): [True: 772, Folded]
  ------------------
   64|    772|                               ? u16_swap_bytes(data[pos + 1])
   65|    772|                               : data[pos + 1];
   66|    772|      char16_t diff2 = uint16_t(next_word - 0xDC00);
   67|    772|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (67:11): [True: 113, False: 659]
  ------------------
   68|    113|        return result(error_code::SURROGATE, pos);
   69|    113|      }
   70|    659|      pos += 2;
   71|  44.1k|    } else {
   72|  44.1k|      pos++;
   73|  44.1k|    }
   74|  45.0k|  }
   75|  6.03k|  return result(error_code::SUCCESS, pos);
   76|  6.25k|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE0EEEmPKDsm:
   91|  32.1k|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|  32.1k|  size_t counter{0};
   94|   135k|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 103k, False: 32.1k]
  ------------------
   95|   103k|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|   103k|    counter++; // ASCII
   97|   103k|    counter += static_cast<size_t>(
   98|   103k|        word >
   99|   103k|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|   103k|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 41.5k, False: 62.1k]
  |  Branch (100:53): [True: 35.6k, False: 5.83k]
  ------------------
  101|  67.9k|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 3.39k, False: 64.5k]
  ------------------
  102|   103k|  }
  103|  32.1k|  return counter;
  104|  32.1k|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE1EEEmPKDsm:
   91|  32.1k|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|  32.1k|  size_t counter{0};
   94|   133k|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 101k, False: 32.1k]
  ------------------
   95|   101k|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|   101k|    counter++; // ASCII
   97|   101k|    counter += static_cast<size_t>(
   98|   101k|        word >
   99|   101k|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|   101k|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 39.2k, False: 62.1k]
  |  Branch (100:53): [True: 33.4k, False: 5.87k]
  ------------------
  101|  67.9k|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 3.13k, False: 64.8k]
  ------------------
  102|   101k|  }
  103|  32.1k|  return counter;
  104|  32.1k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_115utf16_to_latin17convertILNS_10endiannessE0EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT0_Esr7simdutf6detailE26index_assignable_from_charIT1_EEEmS8_mS9_:
   17|  6.81k|                                   OutputPtr latin_output) {
   18|  6.81k|  if (len == 0) {
  ------------------
  |  Branch (18:7): [True: 5.31k, False: 1.50k]
  ------------------
   19|  5.31k|    return 0;
   20|  5.31k|  }
   21|  1.50k|  size_t pos = 0;
   22|  1.50k|  const auto latin_output_start = latin_output;
   23|  1.50k|  uint16_t word = 0;
   24|  1.50k|  uint16_t too_large = 0;
   25|       |
   26|   103k|  while (pos < len) {
  ------------------
  |  Branch (26:10): [True: 102k, False: 1.50k]
  ------------------
   27|   102k|    word = !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (27:12): [Folded, False: 102k]
  ------------------
   28|   102k|    too_large |= word;
   29|   102k|    *latin_output++ = char(word & 0xFF);
   30|   102k|    pos++;
   31|   102k|  }
   32|  1.50k|  if ((too_large & 0xFF00) != 0) {
  ------------------
  |  Branch (32:7): [True: 0, False: 1.50k]
  ------------------
   33|      0|    return 0;
   34|      0|  }
   35|       |
   36|  1.50k|  return latin_output - latin_output_start;
   37|  1.50k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_115utf16_to_latin17convertILNS_10endiannessE1EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT0_Esr7simdutf6detailE26index_assignable_from_charIT1_EEEmS8_mS9_:
   17|  6.81k|                                   OutputPtr latin_output) {
   18|  6.81k|  if (len == 0) {
  ------------------
  |  Branch (18:7): [True: 5.31k, False: 1.50k]
  ------------------
   19|  5.31k|    return 0;
   20|  5.31k|  }
   21|  1.50k|  size_t pos = 0;
   22|  1.50k|  const auto latin_output_start = latin_output;
   23|  1.50k|  uint16_t word = 0;
   24|  1.50k|  uint16_t too_large = 0;
   25|       |
   26|   103k|  while (pos < len) {
  ------------------
  |  Branch (26:10): [True: 102k, False: 1.50k]
  ------------------
   27|   102k|    word = !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (27:12): [True: 102k, Folded]
  ------------------
   28|   102k|    too_large |= word;
   29|   102k|    *latin_output++ = char(word & 0xFF);
   30|   102k|    pos++;
   31|   102k|  }
   32|  1.50k|  if ((too_large & 0xFF00) != 0) {
  ------------------
  |  Branch (32:7): [True: 0, False: 1.50k]
  ------------------
   33|      0|    return 0;
   34|      0|  }
   35|       |
   36|  1.50k|  return latin_output - latin_output_start;
   37|  1.50k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf87convertILNS_10endiannessE0EPKDsPcQsr7simdutf6detailE18indexes_into_utf16IT0_EEEmS8_mT1_:
   15|  13.1k|                                   OutputPtr utf8_output) {
   16|  13.1k|  size_t pos = 0;
   17|  13.1k|  const auto start = utf8_output;
   18|  75.9k|  while (pos < len) {
  ------------------
  |  Branch (18:10): [True: 62.9k, False: 12.9k]
  ------------------
   19|       |#if SIMDUTF_CPLUSPLUS23
   20|       |    if !consteval
   21|       |#endif
   22|  62.9k|    {
   23|       |      // try to convert the next block of 8 bytes
   24|  62.9k|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (24:11): [True: 58.6k, False: 4.26k]
  ------------------
   25|       |                            // they are ascii
   26|  58.6k|        uint64_t v;
   27|  58.6k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   28|       |        if constexpr (!match_system(big_endian)) {
   29|       |          v = (v >> 8) | (v << (64 - 8));
   30|       |        }
   31|  58.6k|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (31:13): [True: 16.0k, False: 42.5k]
  ------------------
   32|  16.0k|          size_t final_pos = pos + 4;
   33|  80.3k|          while (pos < final_pos) {
  ------------------
  |  Branch (33:18): [True: 64.2k, False: 16.0k]
  ------------------
   34|  64.2k|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (34:30): [Folded, False: 64.2k]
  ------------------
   35|  64.2k|                                 ? char(u16_swap_bytes(data[pos]))
   36|  64.2k|                                 : char(data[pos]);
   37|  64.2k|            pos++;
   38|  64.2k|          }
   39|  16.0k|          continue;
   40|  16.0k|        }
   41|  58.6k|      }
   42|  62.9k|    }
   43|  46.8k|    uint16_t word =
   44|  46.8k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (44:9): [Folded, False: 46.8k]
  ------------------
   45|  46.8k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (45:9): [True: 4.89k, False: 41.9k]
  ------------------
   46|       |      // will generate one UTF-8 bytes
   47|  4.89k|      *utf8_output++ = char(word);
   48|  4.89k|      pos++;
   49|  41.9k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (49:16): [True: 3.04k, False: 38.9k]
  ------------------
   50|       |      // will generate two UTF-8 bytes
   51|       |      // we have 0b110XXXXX 0b10XXXXXX
   52|  3.04k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   53|  3.04k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   54|  3.04k|      pos++;
   55|  38.9k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (55:16): [True: 37.4k, False: 1.48k]
  ------------------
   56|       |      // will generate three UTF-8 bytes
   57|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   58|  37.4k|      *utf8_output++ = char((word >> 12) | 0b11100000);
   59|  37.4k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   60|  37.4k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   61|  37.4k|      pos++;
   62|  37.4k|    } else {
   63|       |      // must be a surrogate pair
   64|  1.48k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (64:11): [True: 24, False: 1.46k]
  ------------------
   65|     24|        return 0;
   66|     24|      }
   67|  1.46k|      uint16_t diff = uint16_t(word - 0xD800);
   68|  1.46k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (68:11): [True: 42, False: 1.41k]
  ------------------
   69|     42|        return 0;
   70|     42|      }
   71|  1.41k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (71:28): [Folded, False: 1.41k]
  ------------------
   72|  1.41k|                               ? u16_swap_bytes(data[pos + 1])
   73|  1.41k|                               : data[pos + 1];
   74|  1.41k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   75|  1.41k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (75:11): [True: 62, False: 1.35k]
  ------------------
   76|     62|        return 0;
   77|     62|      }
   78|  1.35k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   79|       |      // will generate four UTF-8 bytes
   80|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   81|  1.35k|      *utf8_output++ = char((value >> 18) | 0b11110000);
   82|  1.35k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
   83|  1.35k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
   84|  1.35k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
   85|  1.35k|      pos += 2;
   86|  1.35k|    }
   87|  46.8k|  }
   88|  12.9k|  return utf8_output - start;
   89|  13.1k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf87convertILNS_10endiannessE1EPKDsPcQsr7simdutf6detailE18indexes_into_utf16IT0_EEEmS8_mT1_:
   15|  13.0k|                                   OutputPtr utf8_output) {
   16|  13.0k|  size_t pos = 0;
   17|  13.0k|  const auto start = utf8_output;
   18|  71.2k|  while (pos < len) {
  ------------------
  |  Branch (18:10): [True: 58.3k, False: 12.9k]
  ------------------
   19|       |#if SIMDUTF_CPLUSPLUS23
   20|       |    if !consteval
   21|       |#endif
   22|  58.3k|    {
   23|       |      // try to convert the next block of 8 bytes
   24|  58.3k|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (24:11): [True: 54.0k, False: 4.21k]
  ------------------
   25|       |                            // they are ascii
   26|  54.0k|        uint64_t v;
   27|  54.0k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   28|  54.0k|        if constexpr (!match_system(big_endian)) {
   29|  54.0k|          v = (v >> 8) | (v << (64 - 8));
   30|  54.0k|        }
   31|  54.0k|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (31:13): [True: 16.1k, False: 37.9k]
  ------------------
   32|  16.1k|          size_t final_pos = pos + 4;
   33|  80.8k|          while (pos < final_pos) {
  ------------------
  |  Branch (33:18): [True: 64.7k, False: 16.1k]
  ------------------
   34|  64.7k|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (34:30): [True: 64.7k, Folded]
  ------------------
   35|  64.7k|                                 ? char(u16_swap_bytes(data[pos]))
   36|  64.7k|                                 : char(data[pos]);
   37|  64.7k|            pos++;
   38|  64.7k|          }
   39|  16.1k|          continue;
   40|  16.1k|        }
   41|  54.0k|      }
   42|  58.3k|    }
   43|  42.1k|    uint16_t word =
   44|  42.1k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (44:9): [True: 42.1k, Folded]
  ------------------
   45|  42.1k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (45:9): [True: 4.77k, False: 37.3k]
  ------------------
   46|       |      // will generate one UTF-8 bytes
   47|  4.77k|      *utf8_output++ = char(word);
   48|  4.77k|      pos++;
   49|  37.3k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (49:16): [True: 2.26k, False: 35.0k]
  ------------------
   50|       |      // will generate two UTF-8 bytes
   51|       |      // we have 0b110XXXXX 0b10XXXXXX
   52|  2.26k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   53|  2.26k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   54|  2.26k|      pos++;
   55|  35.0k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (55:16): [True: 33.6k, False: 1.43k]
  ------------------
   56|       |      // will generate three UTF-8 bytes
   57|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   58|  33.6k|      *utf8_output++ = char((word >> 12) | 0b11100000);
   59|  33.6k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   60|  33.6k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   61|  33.6k|      pos++;
   62|  33.6k|    } else {
   63|       |      // must be a surrogate pair
   64|  1.43k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (64:11): [True: 20, False: 1.41k]
  ------------------
   65|     20|        return 0;
   66|     20|      }
   67|  1.41k|      uint16_t diff = uint16_t(word - 0xD800);
   68|  1.41k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (68:11): [True: 28, False: 1.38k]
  ------------------
   69|     28|        return 0;
   70|     28|      }
   71|  1.38k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (71:28): [True: 1.38k, Folded]
  ------------------
   72|  1.38k|                               ? u16_swap_bytes(data[pos + 1])
   73|  1.38k|                               : data[pos + 1];
   74|  1.38k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   75|  1.38k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (75:11): [True: 65, False: 1.32k]
  ------------------
   76|     65|        return 0;
   77|     65|      }
   78|  1.32k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   79|       |      // will generate four UTF-8 bytes
   80|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   81|  1.32k|      *utf8_output++ = char((value >> 18) | 0b11110000);
   82|  1.32k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
   83|  1.32k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
   84|  1.32k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
   85|  1.32k|      pos += 2;
   86|  1.32k|    }
   87|  42.1k|  }
   88|  12.9k|  return utf8_output - start;
   89|  13.0k|}

_ZN7simdutf6scalar5utf328validateEPKDim:
   25|  14.4k|                                                        size_t len) noexcept {
   26|  14.4k|  return validate(reinterpret_cast<const uint32_t *>(buf), len);
   27|  14.4k|}
_ZN7simdutf6scalar5utf3222utf8_length_from_utf32EPKDim:
   54|  15.4k|                                                         size_t len) {
   55|       |  // We are not BOM aware.
   56|  15.4k|  size_t counter{0};
   57|  68.8k|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (57:22): [True: 53.4k, False: 15.4k]
  ------------------
   58|       |    // credit: @ttsugriy  for the vectorizable approach
   59|  53.4k|    counter++;                                     // ASCII
   60|  53.4k|    counter += static_cast<size_t>(p[i] > 0x7F);   // two-byte
   61|  53.4k|    counter += static_cast<size_t>(p[i] > 0x7FF);  // three-byte
   62|  53.4k|    counter += static_cast<size_t>(p[i] > 0xFFFF); // four-bytes
   63|  53.4k|  }
   64|  15.4k|  return counter;
   65|  15.4k|}
_ZN7simdutf6scalar5utf328validateIPKjQsr7simdutf6detailE19indexes_into_uint32IT_EEEbS5_m:
   13|  14.4k|                                                      size_t len) noexcept {
   14|  14.4k|  uint64_t pos = 0;
   15|   171k|  for (; pos < len; pos++) {
  ------------------
  |  Branch (15:10): [True: 156k, False: 14.4k]
  ------------------
   16|   156k|    uint32_t word = data[pos];
   17|   156k|    if (word > 0x10FFFF || (word >= 0xD800 && word <= 0xDFFF)) {
  ------------------
  |  Branch (17:9): [True: 0, False: 156k]
  |  Branch (17:29): [True: 1.04k, False: 155k]
  |  Branch (17:47): [True: 0, False: 1.04k]
  ------------------
   18|      0|      return false;
   19|      0|    }
   20|   156k|  }
   21|  14.4k|  return true;
   22|  14.4k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_115utf32_to_latin17convertEPKDimPc:
   10|  6.84k|                                          char *latin1_output) {
   11|  6.84k|  char *start = latin1_output;
   12|  6.84k|  uint32_t utf32_char;
   13|  6.84k|  size_t pos = 0;
   14|  6.84k|  uint32_t too_large = 0;
   15|       |
   16|   110k|  while (pos < len) {
  ------------------
  |  Branch (16:10): [True: 103k, False: 6.84k]
  ------------------
   17|   103k|    utf32_char = (uint32_t)data[pos];
   18|   103k|    too_large |= utf32_char;
   19|   103k|    *latin1_output++ = (char)(utf32_char & 0xFF);
   20|   103k|    pos++;
   21|   103k|  }
   22|  6.84k|  if ((too_large & 0xFFFFFF00) != 0) {
  ------------------
  |  Branch (22:7): [True: 0, False: 6.84k]
  ------------------
   23|      0|    return 0;
   24|      0|  }
   25|  6.84k|  return latin1_output - start;
   26|  6.84k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf32_to_utf87convertIPKDiPcQaasr7simdutf6detailE18indexes_into_utf32IT_Esr7simdutf6detailE26index_assignable_from_charIT0_EEEmS7_mS8_:
   15|  6.95k|                                   OutputPtr utf8_output) {
   16|  6.95k|  size_t pos = 0;
   17|  6.95k|  auto start = utf8_output;
   18|  44.1k|  while (pos < len) {
  ------------------
  |  Branch (18:10): [True: 37.2k, False: 6.95k]
  ------------------
   19|       |#if SIMDUTF_CPLUSPLUS23
   20|       |    if !consteval
   21|       |#endif
   22|  37.2k|    { // try to convert the next block of 2 ASCII characters
   23|  37.2k|      if (pos + 2 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (23:11): [True: 35.9k, False: 1.32k]
  ------------------
   24|       |                            // they are ascii
   25|  35.9k|        uint64_t v;
   26|  35.9k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   27|  35.9k|        if ((v & 0xFFFFFF80FFFFFF80) == 0) {
  ------------------
  |  Branch (27:13): [True: 32.0k, False: 3.87k]
  ------------------
   28|  32.0k|          *utf8_output++ = char(data[pos]);
   29|  32.0k|          *utf8_output++ = char(data[pos + 1]);
   30|  32.0k|          pos += 2;
   31|  32.0k|          continue;
   32|  32.0k|        }
   33|  35.9k|      }
   34|  37.2k|    }
   35|       |
   36|  5.19k|    uint32_t word = data[pos];
   37|  5.19k|    if ((word & 0xFFFFFF80) == 0) {
  ------------------
  |  Branch (37:9): [True: 1.67k, False: 3.52k]
  ------------------
   38|       |      // will generate one UTF-8 bytes
   39|  1.67k|      *utf8_output++ = char(word);
   40|  1.67k|      pos++;
   41|  3.52k|    } else if ((word & 0xFFFFF800) == 0) {
  ------------------
  |  Branch (41:16): [True: 1.38k, False: 2.14k]
  ------------------
   42|       |      // will generate two UTF-8 bytes
   43|       |      // we have 0b110XXXXX 0b10XXXXXX
   44|  1.38k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   45|  1.38k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   46|  1.38k|      pos++;
   47|  2.14k|    } else if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (47:16): [True: 952, False: 1.18k]
  ------------------
   48|       |      // will generate three UTF-8 bytes
   49|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   50|    952|      if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (50:11): [True: 494, False: 458]
  |  Branch (50:29): [True: 0, False: 494]
  ------------------
   51|      0|        return 0;
   52|      0|      }
   53|    952|      *utf8_output++ = char((word >> 12) | 0b11100000);
   54|    952|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   55|    952|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   56|    952|      pos++;
   57|  1.18k|    } else {
   58|       |      // will generate four UTF-8 bytes
   59|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   60|  1.18k|      if (word > 0x10FFFF) {
  ------------------
  |  Branch (60:11): [True: 0, False: 1.18k]
  ------------------
   61|      0|        return 0;
   62|      0|      }
   63|  1.18k|      *utf8_output++ = char((word >> 18) | 0b11110000);
   64|  1.18k|      *utf8_output++ = char(((word >> 12) & 0b111111) | 0b10000000);
   65|  1.18k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   66|  1.18k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   67|  1.18k|      pos++;
   68|  1.18k|    }
   69|  5.19k|  }
   70|  6.95k|  return utf8_output - start;
   71|  6.95k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf88validateEPKcm:
  111|  22.1k|                                                        size_t len) noexcept {
  112|  22.1k|  return validate(reinterpret_cast<const uint8_t *>(buf), len);
  113|  22.1k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf88validateIPKhEEbT_m:
   12|  22.1k|                                                      size_t len) noexcept {
   13|  22.1k|  static_assert(
   14|  22.1k|      std::is_same<typename std::decay<decltype(*data)>::type, uint8_t>::value,
   15|  22.1k|      "dereferencing the data pointer must result in a uint8_t");
   16|  22.1k|  uint64_t pos = 0;
   17|  22.1k|  uint32_t code_point = 0;
   18|   113k|  while (pos < len) {
  ------------------
  |  Branch (18:10): [True: 91.4k, False: 21.6k]
  ------------------
   19|  91.4k|    uint64_t next_pos;
   20|       |#if SIMDUTF_CPLUSPLUS23
   21|       |    if !consteval
   22|       |#endif
   23|  91.4k|    { // check if the next 16 bytes are ascii.
   24|  91.4k|      next_pos = pos + 16;
   25|  91.4k|      if (next_pos <= len) { // if it is safe to read 16 more bytes, check
  ------------------
  |  Branch (25:11): [True: 89.0k, False: 2.33k]
  ------------------
   26|       |                             // that they are ascii
   27|  89.0k|        uint64_t v1{};
   28|  89.0k|        std::memcpy(&v1, data + pos, sizeof(uint64_t));
   29|  89.0k|        uint64_t v2{};
   30|  89.0k|        std::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   31|  89.0k|        uint64_t v{v1 | v2};
   32|  89.0k|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (32:13): [True: 6.34k, False: 82.7k]
  ------------------
   33|  6.34k|          pos = next_pos;
   34|  6.34k|          continue;
   35|  6.34k|        }
   36|  89.0k|      }
   37|  91.4k|    }
   38|       |
   39|  85.0k|    unsigned char byte = data[pos];
   40|       |
   41|   110k|    while (byte < 0b10000000) {
  ------------------
  |  Branch (41:12): [True: 25.6k, False: 84.7k]
  ------------------
   42|  25.6k|      if (++pos == len) {
  ------------------
  |  Branch (42:11): [True: 290, False: 25.3k]
  ------------------
   43|    290|        return true;
   44|    290|      }
   45|  25.3k|      byte = data[pos];
   46|  25.3k|    }
   47|       |
   48|  84.7k|    if ((byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (48:9): [True: 32.4k, False: 52.2k]
  ------------------
   49|  32.4k|      next_pos = pos + 2;
   50|  32.4k|      if (next_pos > len) {
  ------------------
  |  Branch (50:11): [True: 11, False: 32.4k]
  ------------------
   51|     11|        return false;
   52|     11|      }
   53|  32.4k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (53:11): [True: 31, False: 32.4k]
  ------------------
   54|     31|        return false;
   55|     31|      }
   56|       |      // range check
   57|  32.4k|      code_point = (byte & 0b00011111) << 6 | (data[pos + 1] & 0b00111111);
   58|  32.4k|      if (code_point < 0x80) {
  ------------------
  |  Branch (58:11): [True: 4, False: 32.4k]
  ------------------
   59|      4|        return false;
   60|      4|      }
   61|  52.2k|    } else if ((byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (61:16): [True: 51.0k, False: 1.20k]
  ------------------
   62|  51.0k|      next_pos = pos + 3;
   63|  51.0k|      if (next_pos > len) {
  ------------------
  |  Branch (63:11): [True: 10, False: 51.0k]
  ------------------
   64|     10|        return false;
   65|     10|      }
   66|  51.0k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (66:11): [True: 8, False: 51.0k]
  ------------------
   67|      8|        return false;
   68|      8|      }
   69|  51.0k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (69:11): [True: 4, False: 51.0k]
  ------------------
   70|      4|        return false;
   71|      4|      }
   72|       |      // range check
   73|  51.0k|      code_point = (byte & 0b00001111) << 12 |
   74|  51.0k|                   (data[pos + 1] & 0b00111111) << 6 |
   75|  51.0k|                   (data[pos + 2] & 0b00111111);
   76|  51.0k|      if ((code_point < 0x800) ||
  ------------------
  |  Branch (76:11): [True: 8, False: 51.0k]
  ------------------
   77|  51.0k|          (0xd7ff < code_point && code_point < 0xe000)) {
  ------------------
  |  Branch (77:12): [True: 4.02k, False: 47.0k]
  |  Branch (77:35): [True: 4, False: 4.01k]
  ------------------
   78|     12|        return false;
   79|     12|      }
   80|  51.0k|    } else if ((byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (80:16): [True: 1.11k, False: 89]
  ------------------
   81|  1.11k|      next_pos = pos + 4;
   82|  1.11k|      if (next_pos > len) {
  ------------------
  |  Branch (82:11): [True: 7, False: 1.11k]
  ------------------
   83|      7|        return false;
   84|      7|      }
   85|  1.11k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (85:11): [True: 6, False: 1.10k]
  ------------------
   86|      6|        return false;
   87|      6|      }
   88|  1.10k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (88:11): [True: 12, False: 1.09k]
  ------------------
   89|     12|        return false;
   90|     12|      }
   91|  1.09k|      if ((data[pos + 3] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (91:11): [True: 4, False: 1.08k]
  ------------------
   92|      4|        return false;
   93|      4|      }
   94|       |      // range check
   95|  1.08k|      code_point =
   96|  1.08k|          (byte & 0b00000111) << 18 | (data[pos + 1] & 0b00111111) << 12 |
   97|  1.08k|          (data[pos + 2] & 0b00111111) << 6 | (data[pos + 3] & 0b00111111);
   98|  1.08k|      if (code_point <= 0xffff || 0x10ffff < code_point) {
  ------------------
  |  Branch (98:11): [True: 7, False: 1.08k]
  |  Branch (98:35): [True: 5, False: 1.07k]
  ------------------
   99|     12|        return false;
  100|     12|      }
  101|  1.08k|    } else {
  102|       |      // we may have a continuation
  103|     89|      return false;
  104|     89|    }
  105|  84.5k|    pos = next_pos;
  106|  84.5k|  }
  107|  21.6k|  return true;
  108|  22.1k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf820validate_with_errorsEPKcm:
  219|  6.50k|validate_with_errors(const char *buf, size_t len) noexcept {
  220|  6.50k|  return validate_with_errors(reinterpret_cast<const uint8_t *>(buf), len);
  221|  6.50k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf820validate_with_errorsIPKhEENS_6resultET_m:
  117|  6.50k|validate_with_errors(BytePtr data, size_t len) noexcept {
  118|  6.50k|  static_assert(
  119|  6.50k|      std::is_same<typename std::decay<decltype(*data)>::type, uint8_t>::value,
  120|  6.50k|      "dereferencing the data pointer must result in a uint8_t");
  121|  6.50k|  size_t pos = 0;
  122|  6.50k|  uint32_t code_point = 0;
  123|  13.2k|  while (pos < len) {
  ------------------
  |  Branch (123:10): [True: 8.04k, False: 5.22k]
  ------------------
  124|       |    // check of the next 16 bytes are ascii.
  125|  8.04k|    size_t next_pos = pos + 16;
  126|  8.04k|    if (next_pos <=
  ------------------
  |  Branch (126:9): [True: 6.96k, False: 1.08k]
  ------------------
  127|  8.04k|        len) { // if it is safe to read 16 more bytes, check that they are ascii
  128|  6.96k|      uint64_t v1;
  129|  6.96k|      std::memcpy(&v1, data + pos, sizeof(uint64_t));
  130|  6.96k|      uint64_t v2;
  131|  6.96k|      std::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
  132|  6.96k|      uint64_t v{v1 | v2};
  133|  6.96k|      if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (133:11): [True: 3.16k, False: 3.79k]
  ------------------
  134|  3.16k|        pos = next_pos;
  135|  3.16k|        continue;
  136|  3.16k|      }
  137|  6.96k|    }
  138|  4.87k|    unsigned char byte = data[pos];
  139|       |
  140|  14.5k|    while (byte < 0b10000000) {
  ------------------
  |  Branch (140:12): [True: 9.84k, False: 4.74k]
  ------------------
  141|  9.84k|      if (++pos == len) {
  ------------------
  |  Branch (141:11): [True: 132, False: 9.71k]
  ------------------
  142|    132|        return result(error_code::SUCCESS, len);
  143|    132|      }
  144|  9.71k|      byte = data[pos];
  145|  9.71k|    }
  146|       |
  147|  4.74k|    if ((byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (147:9): [True: 2.14k, False: 2.60k]
  ------------------
  148|  2.14k|      next_pos = pos + 2;
  149|  2.14k|      if (next_pos > len) {
  ------------------
  |  Branch (149:11): [True: 45, False: 2.09k]
  ------------------
  150|     45|        return result(error_code::TOO_SHORT, pos);
  151|     45|      }
  152|  2.09k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (152:11): [True: 123, False: 1.97k]
  ------------------
  153|    123|        return result(error_code::TOO_SHORT, pos);
  154|    123|      }
  155|       |      // range check
  156|  1.97k|      code_point = (byte & 0b00011111) << 6 | (data[pos + 1] & 0b00111111);
  157|  1.97k|      if (code_point < 0x80) {
  ------------------
  |  Branch (157:11): [True: 21, False: 1.95k]
  ------------------
  158|     21|        return result(error_code::OVERLONG, pos);
  159|     21|      }
  160|  2.60k|    } else if ((byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (160:16): [True: 1.11k, False: 1.48k]
  ------------------
  161|  1.11k|      next_pos = pos + 3;
  162|  1.11k|      if (next_pos > len) {
  ------------------
  |  Branch (162:11): [True: 57, False: 1.05k]
  ------------------
  163|     57|        return result(error_code::TOO_SHORT, pos);
  164|     57|      }
  165|  1.05k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (165:11): [True: 74, False: 985]
  ------------------
  166|     74|        return result(error_code::TOO_SHORT, pos);
  167|     74|      }
  168|    985|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (168:11): [True: 45, False: 940]
  ------------------
  169|     45|        return result(error_code::TOO_SHORT, pos);
  170|     45|      }
  171|       |      // range check
  172|    940|      code_point = (byte & 0b00001111) << 12 |
  173|    940|                   (data[pos + 1] & 0b00111111) << 6 |
  174|    940|                   (data[pos + 2] & 0b00111111);
  175|    940|      if (code_point < 0x800) {
  ------------------
  |  Branch (175:11): [True: 25, False: 915]
  ------------------
  176|     25|        return result(error_code::OVERLONG, pos);
  177|     25|      }
  178|    915|      if (0xd7ff < code_point && code_point < 0xe000) {
  ------------------
  |  Branch (178:11): [True: 394, False: 521]
  |  Branch (178:34): [True: 16, False: 378]
  ------------------
  179|     16|        return result(error_code::SURROGATE, pos);
  180|     16|      }
  181|  1.48k|    } else if ((byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (181:16): [True: 980, False: 509]
  ------------------
  182|    980|      next_pos = pos + 4;
  183|    980|      if (next_pos > len) {
  ------------------
  |  Branch (183:11): [True: 38, False: 942]
  ------------------
  184|     38|        return result(error_code::TOO_SHORT, pos);
  185|     38|      }
  186|    942|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (186:11): [True: 71, False: 871]
  ------------------
  187|     71|        return result(error_code::TOO_SHORT, pos);
  188|     71|      }
  189|    871|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (189:11): [True: 49, False: 822]
  ------------------
  190|     49|        return result(error_code::TOO_SHORT, pos);
  191|     49|      }
  192|    822|      if ((data[pos + 3] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (192:11): [True: 44, False: 778]
  ------------------
  193|     44|        return result(error_code::TOO_SHORT, pos);
  194|     44|      }
  195|       |      // range check
  196|    778|      code_point =
  197|    778|          (byte & 0b00000111) << 18 | (data[pos + 1] & 0b00111111) << 12 |
  198|    778|          (data[pos + 2] & 0b00111111) << 6 | (data[pos + 3] & 0b00111111);
  199|    778|      if (code_point <= 0xffff) {
  ------------------
  |  Branch (199:11): [True: 18, False: 760]
  ------------------
  200|     18|        return result(error_code::OVERLONG, pos);
  201|     18|      }
  202|    760|      if (0x10ffff < code_point) {
  ------------------
  |  Branch (202:11): [True: 19, False: 741]
  ------------------
  203|     19|        return result(error_code::TOO_LARGE, pos);
  204|     19|      }
  205|    760|    } else {
  206|       |      // we either have too many continuation bytes or an invalid leading byte
  207|    509|      if ((byte & 0b11000000) == 0b10000000) {
  ------------------
  |  Branch (207:11): [True: 302, False: 207]
  ------------------
  208|    302|        return result(error_code::TOO_LONG, pos);
  209|    302|      } else {
  210|    207|        return result(error_code::HEADER_BITS, pos);
  211|    207|      }
  212|    509|    }
  213|  3.59k|    pos = next_pos;
  214|  3.59k|  }
  215|  5.22k|  return result(error_code::SUCCESS, len);
  216|  6.50k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf831rewind_and_validate_with_errorsEPKcS4_m:
  230|  1.02k|    const char *start, const char *buf, size_t len) noexcept {
  231|       |  // First check that we start with a leading byte
  232|  1.02k|  if ((*start & 0b11000000) == 0b10000000) {
  ------------------
  |  Branch (232:7): [True: 76, False: 944]
  ------------------
  233|     76|    return result(error_code::TOO_LONG, 0);
  234|     76|  }
  235|    944|  size_t extra_len{0};
  236|       |  // A leading byte cannot be further than 4 bytes away
  237|    982|  for (int i = 0; i < 5; i++) {
  ------------------
  |  Branch (237:19): [True: 982, False: 0]
  ------------------
  238|    982|    unsigned char byte = *buf;
  239|    982|    if ((byte & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (239:9): [True: 944, False: 38]
  ------------------
  240|    944|      break;
  241|    944|    } else {
  242|     38|      buf--;
  243|     38|      extra_len++;
  244|     38|    }
  245|    982|  }
  246|       |
  247|    944|  result res = validate_with_errors(buf, len + extra_len);
  248|    944|  res.count -= extra_len; // Might underflow
  249|    944|  return res;
  250|  1.02k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf817count_code_pointsIPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_m:
  256|  50.0k|simdutf_constexpr23 size_t count_code_points(InputPtr data, size_t len) {
  257|  50.0k|  size_t counter{0};
  258|   546k|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (258:22): [True: 496k, False: 50.0k]
  ------------------
  259|       |    // -65 is 0b10111111, anything larger in two-complement's should start a new
  260|       |    // code point.
  261|   496k|    if (int8_t(data[i]) > -65) {
  ------------------
  |  Branch (261:9): [True: 412k, False: 84.5k]
  ------------------
  262|   412k|      counter++;
  263|   412k|    }
  264|   496k|  }
  265|  50.0k|  return counter;
  266|  50.0k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf822utf16_length_from_utf8IPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_m:
  272|  66.2k|simdutf_constexpr23 size_t utf16_length_from_utf8(InputPtr data, size_t len) {
  273|  66.2k|  size_t counter{0};
  274|   479k|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (274:22): [True: 412k, False: 66.2k]
  ------------------
  275|   412k|    if (int8_t(data[i]) > -65) {
  ------------------
  |  Branch (275:9): [True: 276k, False: 136k]
  ------------------
  276|   276k|      counter++;
  277|   276k|    }
  278|   412k|    if (uint8_t(data[i]) >= 240) {
  ------------------
  |  Branch (278:9): [True: 10.1k, False: 402k]
  ------------------
  279|  10.1k|      counter++;
  280|  10.1k|    }
  281|   412k|  }
  282|  66.2k|  return counter;
  283|  66.2k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf8_to_latin17convertIPKcPcQaasr7simdutf6detailE22indexes_into_byte_likeIT_Esr7simdutf6detailE22indexes_into_byte_likeIT0_EEEmS7_mS8_:
   15|  15.3k|                                   OutputPtr latin_output) {
   16|  15.3k|  size_t pos = 0;
   17|  15.3k|  auto start = latin_output;
   18|       |
   19|   107k|  while (pos < len) {
  ------------------
  |  Branch (19:10): [True: 93.9k, False: 13.2k]
  ------------------
   20|       |#if SIMDUTF_CPLUSPLUS23
   21|       |    if !consteval
   22|       |#endif
   23|  93.9k|    {
   24|       |      // try to convert the next block of 16 ASCII bytes
   25|  93.9k|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (25:11): [True: 76.6k, False: 17.2k]
  ------------------
   26|       |                             // they are ascii
   27|  76.6k|        uint64_t v1;
   28|  76.6k|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   29|  76.6k|        uint64_t v2;
   30|  76.6k|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   31|  76.6k|        uint64_t v{v1 | v2}; // We are only interested in these bits: 1000 1000
   32|       |                             // 1000 1000 .... etc
   33|  76.6k|        if ((v & 0x8080808080808080) ==
  ------------------
  |  Branch (33:13): [True: 9.69k, False: 67.0k]
  ------------------
   34|  76.6k|            0) { // if NONE of these are set, e.g. all of them are zero, then
   35|       |                 // everything is ASCII
   36|  9.69k|          size_t final_pos = pos + 16;
   37|   164k|          while (pos < final_pos) {
  ------------------
  |  Branch (37:18): [True: 155k, False: 9.69k]
  ------------------
   38|   155k|            *latin_output++ = char(data[pos]);
   39|   155k|            pos++;
   40|   155k|          }
   41|  9.69k|          continue;
   42|  9.69k|        }
   43|  76.6k|      }
   44|  93.9k|    }
   45|       |
   46|       |    // suppose it is not an all ASCII byte sequence
   47|  84.2k|    uint8_t leading_byte = data[pos]; // leading byte
   48|  84.2k|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (48:9): [True: 39.1k, False: 45.0k]
  ------------------
   49|       |      // converting one ASCII byte !!!
   50|  39.1k|      *latin_output++ = char(leading_byte);
   51|  39.1k|      pos++;
   52|  45.0k|    } else if ((leading_byte & 0b11100000) ==
  ------------------
  |  Branch (52:16): [True: 43.2k, False: 1.72k]
  ------------------
   53|  45.0k|               0b11000000) { // the first three bits indicate:
   54|       |      // We have a two-byte UTF-8
   55|  43.2k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (55:11): [True: 24, False: 43.2k]
  ------------------
   56|     24|        return 0;
   57|     24|      } // minimal bound checking
   58|  43.2k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (58:11): [True: 86, False: 43.1k]
  ------------------
   59|     86|        return 0;
   60|     86|      } // checks if the next byte is a valid continuation byte in UTF-8. A
   61|       |        // valid continuation byte starts with 10.
   62|       |      // range check -
   63|  43.1k|      uint32_t code_point =
   64|  43.1k|          (leading_byte & 0b00011111) << 6 |
   65|  43.1k|          (data[pos + 1] &
   66|  43.1k|           0b00111111); // assembles the Unicode code point from the two bytes.
   67|       |                        // It does this by discarding the leading 110 and 10
   68|       |                        // bits from the two bytes, shifting the remaining bits
   69|       |                        // of the first byte, and then combining the results
   70|       |                        // with a bitwise OR operation.
   71|  43.1k|      if (code_point < 0x80 || 0xFF < code_point) {
  ------------------
  |  Branch (71:11): [True: 21, False: 43.1k]
  |  Branch (71:32): [True: 171, False: 42.9k]
  ------------------
   72|    192|        return 0; // We only care about the range 129-255 which is Non-ASCII
   73|       |                  // latin1 characters. A code_point beneath 0x80 is invalid as
   74|       |                  // it is already covered by bytes whose leading bit is zero.
   75|    192|      }
   76|  42.9k|      *latin_output++ = char(code_point);
   77|  42.9k|      pos += 2;
   78|  42.9k|    } else {
   79|  1.72k|      return 0;
   80|  1.72k|    }
   81|  84.2k|  }
   82|  13.2k|  return latin_output - start;
   83|  15.3k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf167convertILNS_10endiannessE0EPKcQsr7simdutf6detailE22indexes_into_byte_likeIT0_EEEmS7_mPDs:
   14|  13.7k|                                   char16_t *utf16_output) {
   15|  13.7k|  size_t pos = 0;
   16|  13.7k|  char16_t *start{utf16_output};
   17|  82.2k|  while (pos < len) {
  ------------------
  |  Branch (17:10): [True: 69.2k, False: 12.9k]
  ------------------
   18|       |#if SIMDUTF_CPLUSPLUS23
   19|       |    if !consteval
   20|       |#endif
   21|       |    // try to convert the next block of 16 ASCII bytes
   22|  69.2k|    {
   23|  69.2k|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (23:11): [True: 54.6k, False: 14.6k]
  ------------------
   24|       |                             // they are ascii
   25|  54.6k|        uint64_t v1;
   26|  54.6k|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   27|  54.6k|        uint64_t v2;
   28|  54.6k|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   29|  54.6k|        uint64_t v{v1 | v2};
   30|  54.6k|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (30:13): [True: 4.43k, False: 50.1k]
  ------------------
   31|  4.43k|          size_t final_pos = pos + 16;
   32|  75.4k|          while (pos < final_pos) {
  ------------------
  |  Branch (32:18): [True: 71.0k, False: 4.43k]
  ------------------
   33|  71.0k|            *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (33:31): [Folded, False: 71.0k]
  ------------------
   34|  71.0k|                                  ? char16_t(u16_swap_bytes(data[pos]))
   35|  71.0k|                                  : char16_t(data[pos]);
   36|  71.0k|            pos++;
   37|  71.0k|          }
   38|  4.43k|          continue;
   39|  4.43k|        }
   40|  54.6k|      }
   41|  69.2k|    }
   42|       |
   43|  64.8k|    uint8_t leading_byte = data[pos]; // leading byte
   44|  64.8k|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (44:9): [True: 23.5k, False: 41.2k]
  ------------------
   45|       |      // converting one ASCII byte !!!
   46|  23.5k|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (46:25): [Folded, False: 23.5k]
  ------------------
   47|  23.5k|                            ? char16_t(u16_swap_bytes(leading_byte))
   48|  23.5k|                            : char16_t(leading_byte);
   49|  23.5k|      pos++;
   50|  41.2k|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (50:16): [True: 4.40k, False: 36.8k]
  ------------------
   51|       |      // We have a two-byte UTF-8, it should become
   52|       |      // a single UTF-16 word.
   53|  4.40k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (53:11): [True: 45, False: 4.35k]
  ------------------
   54|     45|        return 0;
   55|     45|      } // minimal bound checking
   56|  4.35k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (56:11): [True: 83, False: 4.27k]
  ------------------
   57|     83|        return 0;
   58|     83|      }
   59|       |      // range check
   60|  4.27k|      uint32_t code_point =
   61|  4.27k|          (leading_byte & 0b00011111) << 6 | (data[pos + 1] & 0b00111111);
   62|  4.27k|      if (code_point < 0x80) {
  ------------------
  |  Branch (62:11): [True: 21, False: 4.25k]
  ------------------
   63|     21|        return 0;
   64|     21|      }
   65|       |      if constexpr (!match_system(big_endian)) {
   66|       |        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
   67|       |      }
   68|  4.25k|      *utf16_output++ = char16_t(code_point);
   69|  4.25k|      pos += 2;
   70|  36.8k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (70:16): [True: 33.8k, False: 3.00k]
  ------------------
   71|       |      // We have a three-byte UTF-8, it should become
   72|       |      // a single UTF-16 word.
   73|  33.8k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (73:11): [True: 57, False: 33.8k]
  ------------------
   74|     57|        return 0;
   75|     57|      } // minimal bound checking
   76|       |
   77|  33.8k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (77:11): [True: 34, False: 33.7k]
  ------------------
   78|     34|        return 0;
   79|     34|      }
   80|  33.7k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (80:11): [True: 22, False: 33.7k]
  ------------------
   81|     22|        return 0;
   82|     22|      }
   83|       |      // range check
   84|  33.7k|      uint32_t code_point = (leading_byte & 0b00001111) << 12 |
   85|  33.7k|                            (data[pos + 1] & 0b00111111) << 6 |
   86|  33.7k|                            (data[pos + 2] & 0b00111111);
   87|  33.7k|      if (code_point < 0x800 || (0xd7ff < code_point && code_point < 0xe000)) {
  ------------------
  |  Branch (87:11): [True: 25, False: 33.7k]
  |  Branch (87:34): [True: 3.94k, False: 29.7k]
  |  Branch (87:57): [True: 15, False: 3.92k]
  ------------------
   88|     40|        return 0;
   89|     40|      }
   90|       |      if constexpr (!match_system(big_endian)) {
   91|       |        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
   92|       |      }
   93|  33.7k|      *utf16_output++ = char16_t(code_point);
   94|  33.7k|      pos += 3;
   95|  33.7k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (95:16): [True: 2.65k, False: 353]
  ------------------
   96|       |      // we have a 4-byte UTF-8 word.
   97|  2.65k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (97:11): [True: 38, False: 2.61k]
  ------------------
   98|     38|        return 0;
   99|     38|      } // minimal bound checking
  100|  2.61k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (100:11): [True: 31, False: 2.58k]
  ------------------
  101|     31|        return 0;
  102|     31|      }
  103|  2.58k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (103:11): [True: 27, False: 2.55k]
  ------------------
  104|     27|        return 0;
  105|     27|      }
  106|  2.55k|      if ((data[pos + 3] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (106:11): [True: 24, False: 2.53k]
  ------------------
  107|     24|        return 0;
  108|     24|      }
  109|       |
  110|       |      // range check
  111|  2.53k|      uint32_t code_point = (leading_byte & 0b00000111) << 18 |
  112|  2.53k|                            (data[pos + 1] & 0b00111111) << 12 |
  113|  2.53k|                            (data[pos + 2] & 0b00111111) << 6 |
  114|  2.53k|                            (data[pos + 3] & 0b00111111);
  115|  2.53k|      if (code_point <= 0xffff || 0x10ffff < code_point) {
  ------------------
  |  Branch (115:11): [True: 16, False: 2.51k]
  |  Branch (115:35): [True: 19, False: 2.50k]
  ------------------
  116|     35|        return 0;
  117|     35|      }
  118|  2.50k|      code_point -= 0x10000;
  119|  2.50k|      uint16_t high_surrogate = uint16_t(0xD800 + (code_point >> 10));
  120|  2.50k|      uint16_t low_surrogate = uint16_t(0xDC00 + (code_point & 0x3FF));
  121|       |      if constexpr (!match_system(big_endian)) {
  122|       |        high_surrogate = u16_swap_bytes(high_surrogate);
  123|       |        low_surrogate = u16_swap_bytes(low_surrogate);
  124|       |      }
  125|  2.50k|      *utf16_output++ = char16_t(high_surrogate);
  126|  2.50k|      *utf16_output++ = char16_t(low_surrogate);
  127|  2.50k|      pos += 4;
  128|  2.50k|    } else {
  129|    353|      return 0;
  130|    353|    }
  131|  64.8k|  }
  132|  12.9k|  return utf16_output - start;
  133|  13.7k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf167convertILNS_10endiannessE1EPKcQsr7simdutf6detailE22indexes_into_byte_likeIT0_EEEmS7_mPDs:
   14|  13.7k|                                   char16_t *utf16_output) {
   15|  13.7k|  size_t pos = 0;
   16|  13.7k|  char16_t *start{utf16_output};
   17|  77.8k|  while (pos < len) {
  ------------------
  |  Branch (17:10): [True: 64.8k, False: 12.9k]
  ------------------
   18|       |#if SIMDUTF_CPLUSPLUS23
   19|       |    if !consteval
   20|       |#endif
   21|       |    // try to convert the next block of 16 ASCII bytes
   22|  64.8k|    {
   23|  64.8k|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (23:11): [True: 50.2k, False: 14.5k]
  ------------------
   24|       |                             // they are ascii
   25|  50.2k|        uint64_t v1;
   26|  50.2k|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   27|  50.2k|        uint64_t v2;
   28|  50.2k|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   29|  50.2k|        uint64_t v{v1 | v2};
   30|  50.2k|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (30:13): [True: 4.44k, False: 45.8k]
  ------------------
   31|  4.44k|          size_t final_pos = pos + 16;
   32|  75.4k|          while (pos < final_pos) {
  ------------------
  |  Branch (32:18): [True: 71.0k, False: 4.44k]
  ------------------
   33|  71.0k|            *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (33:31): [True: 71.0k, Folded]
  ------------------
   34|  71.0k|                                  ? char16_t(u16_swap_bytes(data[pos]))
   35|  71.0k|                                  : char16_t(data[pos]);
   36|  71.0k|            pos++;
   37|  71.0k|          }
   38|  4.44k|          continue;
   39|  4.44k|        }
   40|  50.2k|      }
   41|  64.8k|    }
   42|       |
   43|  60.3k|    uint8_t leading_byte = data[pos]; // leading byte
   44|  60.3k|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (44:9): [True: 23.6k, False: 36.6k]
  ------------------
   45|       |      // converting one ASCII byte !!!
   46|  23.6k|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (46:25): [True: 23.6k, Folded]
  ------------------
   47|  23.6k|                            ? char16_t(u16_swap_bytes(leading_byte))
   48|  23.6k|                            : char16_t(leading_byte);
   49|  23.6k|      pos++;
   50|  36.6k|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (50:16): [True: 3.74k, False: 32.9k]
  ------------------
   51|       |      // We have a two-byte UTF-8, it should become
   52|       |      // a single UTF-16 word.
   53|  3.74k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (53:11): [True: 45, False: 3.70k]
  ------------------
   54|     45|        return 0;
   55|     45|      } // minimal bound checking
   56|  3.70k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (56:11): [True: 83, False: 3.61k]
  ------------------
   57|     83|        return 0;
   58|     83|      }
   59|       |      // range check
   60|  3.61k|      uint32_t code_point =
   61|  3.61k|          (leading_byte & 0b00011111) << 6 | (data[pos + 1] & 0b00111111);
   62|  3.61k|      if (code_point < 0x80) {
  ------------------
  |  Branch (62:11): [True: 21, False: 3.59k]
  ------------------
   63|     21|        return 0;
   64|     21|      }
   65|  3.59k|      if constexpr (!match_system(big_endian)) {
   66|  3.59k|        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
   67|  3.59k|      }
   68|  3.59k|      *utf16_output++ = char16_t(code_point);
   69|  3.59k|      pos += 2;
   70|  32.9k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (70:16): [True: 30.2k, False: 2.69k]
  ------------------
   71|       |      // We have a three-byte UTF-8, it should become
   72|       |      // a single UTF-16 word.
   73|  30.2k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (73:11): [True: 57, False: 30.2k]
  ------------------
   74|     57|        return 0;
   75|     57|      } // minimal bound checking
   76|       |
   77|  30.2k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (77:11): [True: 34, False: 30.1k]
  ------------------
   78|     34|        return 0;
   79|     34|      }
   80|  30.1k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (80:11): [True: 22, False: 30.1k]
  ------------------
   81|     22|        return 0;
   82|     22|      }
   83|       |      // range check
   84|  30.1k|      uint32_t code_point = (leading_byte & 0b00001111) << 12 |
   85|  30.1k|                            (data[pos + 1] & 0b00111111) << 6 |
   86|  30.1k|                            (data[pos + 2] & 0b00111111);
   87|  30.1k|      if (code_point < 0x800 || (0xd7ff < code_point && code_point < 0xe000)) {
  ------------------
  |  Branch (87:11): [True: 25, False: 30.1k]
  |  Branch (87:34): [True: 3.82k, False: 26.2k]
  |  Branch (87:57): [True: 15, False: 3.81k]
  ------------------
   88|     40|        return 0;
   89|     40|      }
   90|  30.1k|      if constexpr (!match_system(big_endian)) {
   91|  30.1k|        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
   92|  30.1k|      }
   93|  30.1k|      *utf16_output++ = char16_t(code_point);
   94|  30.1k|      pos += 3;
   95|  30.1k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (95:16): [True: 2.33k, False: 353]
  ------------------
   96|       |      // we have a 4-byte UTF-8 word.
   97|  2.33k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (97:11): [True: 38, False: 2.30k]
  ------------------
   98|     38|        return 0;
   99|     38|      } // minimal bound checking
  100|  2.30k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (100:11): [True: 31, False: 2.26k]
  ------------------
  101|     31|        return 0;
  102|     31|      }
  103|  2.26k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (103:11): [True: 27, False: 2.24k]
  ------------------
  104|     27|        return 0;
  105|     27|      }
  106|  2.24k|      if ((data[pos + 3] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (106:11): [True: 24, False: 2.21k]
  ------------------
  107|     24|        return 0;
  108|     24|      }
  109|       |
  110|       |      // range check
  111|  2.21k|      uint32_t code_point = (leading_byte & 0b00000111) << 18 |
  112|  2.21k|                            (data[pos + 1] & 0b00111111) << 12 |
  113|  2.21k|                            (data[pos + 2] & 0b00111111) << 6 |
  114|  2.21k|                            (data[pos + 3] & 0b00111111);
  115|  2.21k|      if (code_point <= 0xffff || 0x10ffff < code_point) {
  ------------------
  |  Branch (115:11): [True: 16, False: 2.20k]
  |  Branch (115:35): [True: 19, False: 2.18k]
  ------------------
  116|     35|        return 0;
  117|     35|      }
  118|  2.18k|      code_point -= 0x10000;
  119|  2.18k|      uint16_t high_surrogate = uint16_t(0xD800 + (code_point >> 10));
  120|  2.18k|      uint16_t low_surrogate = uint16_t(0xDC00 + (code_point & 0x3FF));
  121|  2.18k|      if constexpr (!match_system(big_endian)) {
  122|  2.18k|        high_surrogate = u16_swap_bytes(high_surrogate);
  123|  2.18k|        low_surrogate = u16_swap_bytes(low_surrogate);
  124|  2.18k|      }
  125|  2.18k|      *utf16_output++ = char16_t(high_surrogate);
  126|  2.18k|      *utf16_output++ = char16_t(low_surrogate);
  127|  2.18k|      pos += 4;
  128|  2.18k|    } else {
  129|    353|      return 0;
  130|    353|    }
  131|  60.3k|  }
  132|  12.9k|  return utf16_output - start;
  133|  13.7k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf327convertIPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_mPDi:
   14|  7.76k|                                   char32_t *utf32_output) {
   15|  7.76k|  size_t pos = 0;
   16|  7.76k|  char32_t *start{utf32_output};
   17|  40.0k|  while (pos < len) {
  ------------------
  |  Branch (17:10): [True: 33.0k, False: 6.95k]
  ------------------
   18|       |#if SIMDUTF_CPLUSPLUS23
   19|       |    if !consteval
   20|       |#endif
   21|  33.0k|    {
   22|       |      // try to convert the next block of 16 ASCII bytes
   23|  33.0k|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (23:11): [True: 21.4k, False: 11.6k]
  ------------------
   24|       |                             // they are ascii
   25|  21.4k|        uint64_t v1;
   26|  21.4k|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   27|  21.4k|        uint64_t v2;
   28|  21.4k|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   29|  21.4k|        uint64_t v{v1 | v2};
   30|  21.4k|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (30:13): [True: 4.26k, False: 17.1k]
  ------------------
   31|  4.26k|          size_t final_pos = pos + 16;
   32|  72.4k|          while (pos < final_pos) {
  ------------------
  |  Branch (32:18): [True: 68.1k, False: 4.26k]
  ------------------
   33|  68.1k|            *utf32_output++ = uint8_t(data[pos]);
   34|  68.1k|            pos++;
   35|  68.1k|          }
   36|  4.26k|          continue;
   37|  4.26k|        }
   38|  21.4k|      }
   39|  33.0k|    }
   40|  28.8k|    auto leading_byte = uint8_t(data[pos]); // leading byte
   41|  28.8k|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (41:9): [True: 21.5k, False: 7.22k]
  ------------------
   42|       |      // converting one ASCII byte !!!
   43|  21.5k|      *utf32_output++ = char32_t(leading_byte);
   44|  21.5k|      pos++;
   45|  21.5k|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (45:16): [True: 2.83k, False: 4.38k]
  ------------------
   46|       |      // We have a two-byte UTF-8
   47|  2.83k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (47:11): [True: 45, False: 2.79k]
  ------------------
   48|     45|        return 0;
   49|     45|      } // minimal bound checking
   50|  2.79k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (50:11): [True: 83, False: 2.71k]
  ------------------
   51|     83|        return 0;
   52|     83|      }
   53|       |      // range check
   54|  2.71k|      uint32_t code_point = (leading_byte & 0b00011111) << 6 |
   55|  2.71k|                            (uint8_t(data[pos + 1]) & 0b00111111);
   56|  2.71k|      if (code_point < 0x80) {
  ------------------
  |  Branch (56:11): [True: 21, False: 2.69k]
  ------------------
   57|     21|        return 0;
   58|     21|      }
   59|  2.69k|      *utf32_output++ = char32_t(code_point);
   60|  2.69k|      pos += 2;
   61|  4.38k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (61:16): [True: 1.92k, False: 2.46k]
  ------------------
   62|       |      // We have a three-byte UTF-8
   63|  1.92k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (63:11): [True: 57, False: 1.86k]
  ------------------
   64|     57|        return 0;
   65|     57|      } // minimal bound checking
   66|       |
   67|  1.86k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (67:11): [True: 34, False: 1.83k]
  ------------------
   68|     34|        return 0;
   69|     34|      }
   70|  1.83k|      if ((uint8_t(data[pos + 2]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (70:11): [True: 22, False: 1.81k]
  ------------------
   71|     22|        return 0;
   72|     22|      }
   73|       |      // range check
   74|  1.81k|      uint32_t code_point = (leading_byte & 0b00001111) << 12 |
   75|  1.81k|                            (uint8_t(data[pos + 1]) & 0b00111111) << 6 |
   76|  1.81k|                            (uint8_t(data[pos + 2]) & 0b00111111);
   77|  1.81k|      if (code_point < 0x800 || (0xd7ff < code_point && code_point < 0xe000)) {
  ------------------
  |  Branch (77:11): [True: 25, False: 1.78k]
  |  Branch (77:34): [True: 879, False: 907]
  |  Branch (77:57): [True: 15, False: 864]
  ------------------
   78|     40|        return 0;
   79|     40|      }
   80|  1.77k|      *utf32_output++ = char32_t(code_point);
   81|  1.77k|      pos += 3;
   82|  2.46k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (82:16): [True: 2.11k, False: 353]
  ------------------
   83|       |      // we have a 4-byte UTF-8 word.
   84|  2.11k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (84:11): [True: 38, False: 2.07k]
  ------------------
   85|     38|        return 0;
   86|     38|      } // minimal bound checking
   87|  2.07k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (87:11): [True: 31, False: 2.04k]
  ------------------
   88|     31|        return 0;
   89|     31|      }
   90|  2.04k|      if ((uint8_t(data[pos + 2]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (90:11): [True: 27, False: 2.01k]
  ------------------
   91|     27|        return 0;
   92|     27|      }
   93|  2.01k|      if ((uint8_t(data[pos + 3]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (93:11): [True: 24, False: 1.99k]
  ------------------
   94|     24|        return 0;
   95|     24|      }
   96|       |
   97|       |      // range check
   98|  1.99k|      uint32_t code_point = (leading_byte & 0b00000111) << 18 |
   99|  1.99k|                            (uint8_t(data[pos + 1]) & 0b00111111) << 12 |
  100|  1.99k|                            (uint8_t(data[pos + 2]) & 0b00111111) << 6 |
  101|  1.99k|                            (uint8_t(data[pos + 3]) & 0b00111111);
  102|  1.99k|      if (code_point <= 0xffff || 0x10ffff < code_point) {
  ------------------
  |  Branch (102:11): [True: 16, False: 1.97k]
  |  Branch (102:35): [True: 19, False: 1.95k]
  ------------------
  103|     35|        return 0;
  104|     35|      }
  105|  1.95k|      *utf32_output++ = char32_t(code_point);
  106|  1.95k|      pos += 4;
  107|  1.95k|    } else {
  108|    353|      return 0;
  109|    353|    }
  110|  28.8k|  }
  111|  6.95k|  return utf32_output - start;
  112|  7.76k|}

_ZNK7simdutf8fallback14implementation13validate_utf8EPKcm:
   37|  22.1k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
   38|  22.1k|  return scalar::utf8::validate(buf, len);
   39|  22.1k|}
_ZNK7simdutf8fallback14implementation25validate_utf8_with_errorsEPKcm:
   44|  5.56k|    const char *buf, size_t len) const noexcept {
   45|  5.56k|  return scalar::utf8::validate_with_errors(buf, len);
   46|  5.56k|}
_ZNK7simdutf8fallback14implementation16validate_utf16leEPKDsm:
   77|  16.4k|                                 size_t len) const noexcept {
   78|  16.4k|  return scalar::utf16::validate<endianness::LITTLE>(buf, len);
   79|  16.4k|}
_ZNK7simdutf8fallback14implementation16validate_utf16beEPKDsm:
   85|  16.4k|                                 size_t len) const noexcept {
   86|  16.4k|  return scalar::utf16::validate<endianness::BIG>(buf, len);
   87|  16.4k|}
_ZNK7simdutf8fallback14implementation28validate_utf16le_with_errorsEPKDsm:
   90|  5.56k|    const char16_t *buf, size_t len) const noexcept {
   91|  5.56k|  return scalar::utf16::validate_with_errors<endianness::LITTLE>(buf, len);
   92|  5.56k|}
_ZNK7simdutf8fallback14implementation28validate_utf16be_with_errorsEPKDsm:
   95|  5.56k|    const char16_t *buf, size_t len) const noexcept {
   96|  5.56k|  return scalar::utf16::validate_with_errors<endianness::BIG>(buf, len);
   97|  5.56k|}
_ZNK7simdutf8fallback14implementation14validate_utf32EPKDim:
  114|  10.9k|implementation::validate_utf32(const char32_t *buf, size_t len) const noexcept {
  115|  10.9k|  return scalar::utf32::validate(buf, len);
  116|  10.9k|}
_ZNK7simdutf8fallback14implementation22convert_latin1_to_utf8EPKcmPc:
  128|  5.73k|    const char *buf, size_t len, char *utf8_output) const noexcept {
  129|  5.73k|  return scalar::latin1_to_utf8::convert(buf, len, utf8_output);
  130|  5.73k|}
_ZNK7simdutf8fallback14implementation25convert_latin1_to_utf16leEPKcmPDs:
  135|  5.56k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  136|  5.56k|  return scalar::latin1_to_utf16::convert<endianness::LITTLE>(buf, len,
  137|  5.56k|                                                              utf16_output);
  138|  5.56k|}
_ZNK7simdutf8fallback14implementation25convert_latin1_to_utf16beEPKcmPDs:
  141|  5.56k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  142|  5.56k|  return scalar::latin1_to_utf16::convert<endianness::BIG>(buf, len,
  143|  5.56k|                                                           utf16_output);
  144|  5.56k|}
_ZNK7simdutf8fallback14implementation23convert_latin1_to_utf32EPKcmPDi:
  149|  5.56k|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  150|  5.56k|  return scalar::latin1_to_utf32::convert(buf, len, utf32_output);
  151|  5.56k|}
_ZNK7simdutf8fallback14implementation22convert_utf8_to_latin1EPKcmPc:
  156|  11.1k|    const char *buf, size_t len, char *latin1_output) const noexcept {
  157|  11.1k|  return scalar::utf8_to_latin1::convert(buf, len, latin1_output);
  158|  11.1k|}
_ZNK7simdutf8fallback14implementation23convert_utf8_to_utf16leEPKcmPDs:
  173|  11.0k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  174|  11.0k|  return scalar::utf8_to_utf16::convert<endianness::LITTLE>(buf, len,
  175|  11.0k|                                                            utf16_output);
  176|  11.0k|}
_ZNK7simdutf8fallback14implementation23convert_utf8_to_utf16beEPKcmPDs:
  179|  11.0k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  180|  11.0k|  return scalar::utf8_to_utf16::convert<endianness::BIG>(buf, len,
  181|  11.0k|                                                         utf16_output);
  182|  11.0k|}
_ZNK7simdutf8fallback14implementation21convert_utf8_to_utf32EPKcmPDi:
  211|  5.56k|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  212|  5.56k|  return scalar::utf8_to_utf32::convert(buf, len, utf32_output);
  213|  5.56k|}
_ZNK7simdutf8fallback14implementation25convert_utf16le_to_latin1EPKDsmPc:
  228|  5.56k|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  229|  5.56k|  return scalar::utf16_to_latin1::convert<endianness::LITTLE>(buf, len,
  230|  5.56k|                                                              latin1_output);
  231|  5.56k|}
_ZNK7simdutf8fallback14implementation25convert_utf16be_to_latin1EPKDsmPc:
  234|  5.56k|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  235|  5.56k|  return scalar::utf16_to_latin1::convert<endianness::BIG>(buf, len,
  236|  5.56k|                                                           latin1_output);
  237|  5.56k|}
_ZNK7simdutf8fallback14implementation23convert_utf16le_to_utf8EPKDsmPc:
  268|  10.9k|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  269|  10.9k|  return scalar::utf16_to_utf8::convert<endianness::LITTLE>(buf, len,
  270|  10.9k|                                                            utf8_output);
  271|  10.9k|}
_ZNK7simdutf8fallback14implementation23convert_utf16be_to_utf8EPKDsmPc:
  274|  10.9k|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  275|  10.9k|  return scalar::utf16_to_utf8::convert<endianness::BIG>(buf, len, utf8_output);
  276|  10.9k|}
_ZNK7simdutf8fallback14implementation23convert_utf32_to_latin1EPKDimPc:
  305|  5.56k|    const char32_t *buf, size_t len, char *latin1_output) const noexcept {
  306|  5.56k|  return scalar::utf32_to_latin1::convert(buf, len, latin1_output);
  307|  5.56k|}
_ZNK7simdutf8fallback14implementation21convert_utf32_to_utf8EPKDimPc:
  322|  5.35k|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  323|  5.35k|  return scalar::utf32_to_utf8::convert(buf, len, utf8_output);
  324|  5.35k|}
_ZNK7simdutf8fallback14implementation23latin1_length_from_utf8EPKcm:
  438|  11.1k|    const char *buf, size_t len) const noexcept {
  439|  11.1k|  return scalar::utf8::count_code_points(buf, len);
  440|  11.1k|}
_ZNK7simdutf8fallback14implementation23utf8_length_from_latin1EPKcm:
  445|  5.73k|    const char *input, size_t length) const noexcept {
  446|  5.73k|  return scalar::latin1_to_utf8::utf8_length_from_latin1(input, length);
  447|  5.73k|}
_ZNK7simdutf8fallback14implementation24utf8_length_from_utf16leEPKDsm:
  452|  10.9k|    const char16_t *input, size_t length) const noexcept {
  453|  10.9k|  return scalar::utf16::utf8_length_from_utf16<endianness::LITTLE>(input,
  454|  10.9k|                                                                   length);
  455|  10.9k|}
_ZNK7simdutf8fallback14implementation24utf8_length_from_utf16beEPKDsm:
  458|  10.9k|    const char16_t *input, size_t length) const noexcept {
  459|  10.9k|  return scalar::utf16::utf8_length_from_utf16<endianness::BIG>(input, length);
  460|  10.9k|}
_ZNK7simdutf8fallback14implementation22utf16_length_from_utf8EPKcm:
  478|  22.1k|    const char *input, size_t length) const noexcept {
  479|  22.1k|  return scalar::utf8::utf16_length_from_utf8(input, length);
  480|  22.1k|}
_ZNK7simdutf8fallback14implementation22utf8_length_from_utf32EPKDim:
  513|  5.35k|    const char32_t *input, size_t length) const noexcept {
  514|  5.35k|  return scalar::utf32::utf8_length_from_utf32(input, length);
  515|  5.35k|}
_ZNK7simdutf8fallback14implementation22utf32_length_from_utf8EPKcm:
  527|  5.56k|    const char *input, size_t length) const noexcept {
  528|  5.56k|  return scalar::utf8::count_code_points(input, length);
  529|  5.56k|}
_ZNK7simdutf8fallback14implementation16base64_to_binaryEPKcmPcNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  536|  16.4k|    last_chunk_handling_options last_chunk_options) const noexcept {
  537|  16.4k|  return simdutf::scalar::base64::base64_to_binary_details_impl(
  538|  16.4k|      input, length, output, options, last_chunk_options);
  539|  16.4k|}
_ZNK7simdutf8fallback14implementation16binary_to_base64EPKcmPcNS_14base64_optionsE:
  564|  16.3k|                                        base64_options options) const noexcept {
  565|  16.3k|  return scalar::base64::tail_encode_base64(output, input, length, options);
  566|  16.3k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_16base6422compress_decode_base64ILb0ELb0ELb0EcEENS_11full_resultEPcPKT2_mNS_14base64_optionsENS_27last_chunk_handling_optionsE:
   45|  64.5k|                       last_chunk_handling_options last_chunk_options) {
   46|  64.5k|  const uint8_t *to_base64 =
   47|  64.5k|      default_or_url ? tables::base64::to_base64_default_or_url_value
  ------------------
  |  Branch (47:7): [Folded, False: 64.5k]
  ------------------
   48|  64.5k|                     : (base64_url ? tables::base64::to_base64_url_value
  ------------------
  |  Branch (48:25): [Folded, False: 64.5k]
  ------------------
   49|  64.5k|                                   : tables::base64::to_base64_value);
   50|  64.5k|  auto ri = simdutf::scalar::base64::find_end(src, srclen, options);
   51|  64.5k|  size_t equallocation = ri.equallocation;
   52|  64.5k|  size_t equalsigns = ri.equalsigns;
   53|  64.5k|  srclen = ri.srclen;
   54|  64.5k|  size_t full_input_length = ri.full_input_length;
   55|  64.5k|  if (srclen == 0) {
  ------------------
  |  Branch (55:7): [True: 57.7k, False: 6.74k]
  ------------------
   56|  57.7k|    if (!ignore_garbage && equalsigns > 0) {
  ------------------
  |  Branch (56:9): [True: 57.7k, Folded]
  |  Branch (56:28): [True: 20, False: 57.7k]
  ------------------
   57|     20|      return {INVALID_BASE64_CHARACTER, equallocation, 0, true};
   58|     20|    }
   59|  57.7k|    return {SUCCESS, full_input_length, 0};
   60|  57.7k|  }
   61|  6.74k|  char *end_of_safe_64byte_zone =
   62|  6.74k|      dst == nullptr
  ------------------
  |  Branch (62:7): [True: 85, False: 6.66k]
  ------------------
   63|  6.74k|          ? nullptr
   64|  6.74k|          : ((srclen + 3) / 4 * 3 >= 63 ? dst + (srclen + 3) / 4 * 3 - 63
  ------------------
  |  Branch (64:14): [True: 2.38k, False: 4.27k]
  ------------------
   65|  6.66k|                                        : dst);
   66|       |
   67|  6.74k|  const chartype *const srcinit = src;
   68|  6.74k|  const char *const dstinit = dst;
   69|  6.74k|  const chartype *const srcend = src + srclen;
   70|       |
   71|  6.74k|  constexpr size_t block_size = 6;
   72|  6.74k|  static_assert(block_size >= 2, "block_size must be at least two");
   73|  6.74k|  char buffer[block_size * 64];
   74|  6.74k|  char *bufferptr = buffer;
   75|  6.74k|  if (srclen >= 64) {
  ------------------
  |  Branch (75:7): [True: 3.36k, False: 3.38k]
  ------------------
   76|  3.36k|    const chartype *const srcend64 = src + srclen - 64;
   77|  19.7k|    while (src <= srcend64) {
  ------------------
  |  Branch (77:12): [True: 17.2k, False: 2.48k]
  ------------------
   78|  17.2k|      block64 b(src);
   79|  17.2k|      src += 64;
   80|  17.2k|      uint64_t error = 0;
   81|  17.2k|      const uint64_t badcharmask =
   82|  17.2k|          b.to_base64_mask<base64_url, ignore_garbage, default_or_url>(&error);
   83|  17.2k|      if (!ignore_garbage && error) {
  ------------------
  |  Branch (83:11): [True: 17.2k, Folded]
  |  Branch (83:30): [True: 885, False: 16.3k]
  ------------------
   84|    885|        src -= 64;
   85|    885|        const size_t error_offset = trailing_zeroes(error);
   86|    885|        return {error_code::INVALID_BASE64_CHARACTER,
   87|    885|                size_t(src - srcinit + error_offset), size_t(dst - dstinit)};
   88|    885|      }
   89|  16.3k|      if (badcharmask != 0) {
  ------------------
  |  Branch (89:11): [True: 2.32k, False: 14.0k]
  ------------------
   90|  2.32k|        bufferptr += b.compress_block(badcharmask, bufferptr);
   91|  14.0k|      } else if (bufferptr != buffer) {
  ------------------
  |  Branch (91:18): [True: 326, False: 13.7k]
  ------------------
   92|    326|        b.copy_block(bufferptr);
   93|    326|        bufferptr += 64;
   94|  13.7k|      } else {
   95|  13.7k|        if (dst >= end_of_safe_64byte_zone) {
  ------------------
  |  Branch (95:13): [True: 836, False: 12.8k]
  ------------------
   96|    836|          b.base64_decode_block_safe(dst);
   97|  12.8k|        } else {
   98|  12.8k|          b.base64_decode_block(dst);
   99|  12.8k|        }
  100|  13.7k|        dst += 48;
  101|  13.7k|      }
  102|  16.3k|      if (bufferptr >= (block_size - 1) * 64 + buffer) {
  ------------------
  |  Branch (102:11): [True: 233, False: 16.1k]
  ------------------
  103|  1.16k|        for (size_t i = 0; i < (block_size - 2); i++) {
  ------------------
  |  Branch (103:28): [True: 932, False: 233]
  ------------------
  104|    932|          base64_decode_block(dst, buffer + i * 64);
  105|    932|          dst += 48;
  106|    932|        }
  107|    233|        if (dst >= end_of_safe_64byte_zone) {
  ------------------
  |  Branch (107:13): [True: 0, False: 233]
  ------------------
  108|      0|          base64_decode_block_safe(dst, buffer + (block_size - 2) * 64);
  109|    233|        } else {
  110|    233|          base64_decode_block(dst, buffer + (block_size - 2) * 64);
  111|    233|        }
  112|    233|        dst += 48;
  113|    233|        std::memcpy(buffer, buffer + (block_size - 1) * 64,
  114|    233|                    64); // 64 might be too much
  115|    233|        bufferptr -= (block_size - 1) * 64;
  116|    233|      }
  117|  16.3k|    }
  118|  3.36k|  }
  119|       |
  120|  5.86k|  char *buffer_start = buffer;
  121|       |  // Optimization note: if this is almost full, then it is worth our
  122|       |  // time, otherwise, we should just decode directly.
  123|  5.86k|  int last_block = (int)((bufferptr - buffer_start) % 64);
  124|  5.86k|  if (last_block != 0 && srcend - src + last_block >= 64) {
  ------------------
  |  Branch (124:7): [True: 710, False: 5.15k]
  |  Branch (124:26): [True: 125, False: 585]
  ------------------
  125|       |
  126|  1.56k|    while ((bufferptr - buffer_start) % 64 != 0 && src < srcend) {
  ------------------
  |  Branch (126:12): [True: 1.48k, False: 84]
  |  Branch (126:52): [True: 1.45k, False: 29]
  ------------------
  127|  1.45k|      uint8_t val = to_base64[uint8_t(*src)];
  128|  1.45k|      *bufferptr = char(val);
  129|  1.45k|      if (!ignore_garbage &&
  ------------------
  |  Branch (129:11): [True: 1.45k, Folded]
  ------------------
  130|  1.45k|          (!scalar::base64::is_eight_byte(*src) || val > 64)) {
  ------------------
  |  Branch (130:12): [True: 0, False: 1.45k]
  |  Branch (130:52): [True: 12, False: 1.44k]
  ------------------
  131|     12|        return {error_code::INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  132|     12|                size_t(dst - dstinit)};
  133|     12|      }
  134|  1.44k|      bufferptr += (val <= 63);
  135|  1.44k|      src++;
  136|  1.44k|    }
  137|    125|  }
  138|       |
  139|  6.37k|  for (; buffer_start + 64 <= bufferptr; buffer_start += 64) {
  ------------------
  |  Branch (139:10): [True: 525, False: 5.85k]
  ------------------
  140|    525|    if (dst >= end_of_safe_64byte_zone) {
  ------------------
  |  Branch (140:9): [True: 50, False: 475]
  ------------------
  141|     50|      base64_decode_block_safe(dst, buffer_start);
  142|    475|    } else {
  143|    475|      base64_decode_block(dst, buffer_start);
  144|    475|    }
  145|    525|    dst += 48;
  146|    525|  }
  147|  5.85k|  if ((bufferptr - buffer_start) % 64 != 0) {
  ------------------
  |  Branch (147:7): [True: 614, False: 5.23k]
  ------------------
  148|  5.81k|    while (buffer_start + 4 < bufferptr) {
  ------------------
  |  Branch (148:12): [True: 5.20k, False: 614]
  ------------------
  149|  5.20k|      uint32_t triple = ((uint32_t(uint8_t(buffer_start[0])) << 3 * 6) +
  150|  5.20k|                         (uint32_t(uint8_t(buffer_start[1])) << 2 * 6) +
  151|  5.20k|                         (uint32_t(uint8_t(buffer_start[2])) << 1 * 6) +
  152|  5.20k|                         (uint32_t(uint8_t(buffer_start[3])) << 0 * 6))
  153|  5.20k|                        << 8;
  154|  5.20k|#if !SIMDUTF_IS_BIG_ENDIAN
  155|  5.20k|      triple = scalar::u32_swap_bytes(triple);
  156|  5.20k|#endif
  157|  5.20k|      std::memcpy(dst, &triple, 3);
  158|       |
  159|  5.20k|      dst += 3;
  160|  5.20k|      buffer_start += 4;
  161|  5.20k|    }
  162|    614|    if (buffer_start + 4 <= bufferptr) {
  ------------------
  |  Branch (162:9): [True: 150, False: 464]
  ------------------
  163|    150|      uint32_t triple = ((uint32_t(uint8_t(buffer_start[0])) << 3 * 6) +
  164|    150|                         (uint32_t(uint8_t(buffer_start[1])) << 2 * 6) +
  165|    150|                         (uint32_t(uint8_t(buffer_start[2])) << 1 * 6) +
  166|    150|                         (uint32_t(uint8_t(buffer_start[3])) << 0 * 6))
  167|    150|                        << 8;
  168|    150|#if !SIMDUTF_IS_BIG_ENDIAN
  169|    150|      triple = scalar::u32_swap_bytes(triple);
  170|    150|#endif
  171|    150|      std::memcpy(dst, &triple, 3);
  172|       |
  173|    150|      dst += 3;
  174|    150|      buffer_start += 4;
  175|    150|    }
  176|       |    // we may have 1, 2 or 3 bytes left and we need to decode them so let us
  177|       |    // backtrack
  178|    614|    int leftover = int(bufferptr - buffer_start);
  179|  1.61k|    while (leftover > 0) {
  ------------------
  |  Branch (179:12): [True: 1.00k, False: 614]
  ------------------
  180|  1.00k|      if (!ignore_garbage) {
  ------------------
  |  Branch (180:11): [True: 1.00k, Folded]
  ------------------
  181|  8.63k|        while (to_base64[uint8_t(*(src - 1))] == 64) {
  ------------------
  |  Branch (181:16): [True: 7.63k, False: 1.00k]
  ------------------
  182|  7.63k|          src--;
  183|  7.63k|        }
  184|  1.00k|      } else {
  185|      0|        while (to_base64[uint8_t(*(src - 1))] >= 64) {
  ------------------
  |  Branch (185:16): [True: 0, False: 0]
  ------------------
  186|      0|          src--;
  187|      0|        }
  188|      0|      }
  189|  1.00k|      src--;
  190|  1.00k|      leftover--;
  191|  1.00k|    }
  192|    614|  }
  193|  5.85k|  if (src < srcend + equalsigns) {
  ------------------
  |  Branch (193:7): [True: 5.44k, False: 403]
  ------------------
  194|  5.44k|    full_result r = scalar::base64::base64_tail_decode(
  195|  5.44k|        dst, src, srcend - src, equalsigns, options, last_chunk_options);
  196|  5.44k|    r = scalar::base64::patch_tail_result(
  197|  5.44k|        r, size_t(src - srcinit), size_t(dst - dstinit), equallocation,
  198|  5.44k|        full_input_length, last_chunk_options);
  199|       |    // When is_partial(last_chunk_options) is true, we must either end with
  200|       |    // the end of the stream (beyond whitespace) or right after a non-ignorable
  201|       |    // character or at the very beginning of the stream.
  202|       |    // See https://tc39.es/proposal-arraybuffer-base64/spec/#sec-frombase64
  203|  5.44k|    if (is_partial(last_chunk_options) && r.error == error_code::SUCCESS &&
  ------------------
  |  Branch (203:9): [True: 1.97k, False: 3.47k]
  |  Branch (203:43): [True: 1.67k, False: 298]
  ------------------
  204|  1.67k|        r.input_count < full_input_length) {
  ------------------
  |  Branch (204:9): [True: 317, False: 1.36k]
  ------------------
  205|       |      // First check if we can extend the input to the end of the stream
  206|  2.25k|      while (r.input_count < full_input_length &&
  ------------------
  |  Branch (206:14): [True: 2.21k, False: 42]
  ------------------
  207|  2.21k|             base64_ignorable(*(srcinit + r.input_count), options)) {
  ------------------
  |  Branch (207:14): [True: 1.94k, False: 275]
  ------------------
  208|  1.94k|        r.input_count++;
  209|  1.94k|      }
  210|       |      // If we are still not at the end of the stream, then we must backtrack
  211|       |      // to the last non-ignorable character.
  212|    317|      if (r.input_count < full_input_length) {
  ------------------
  |  Branch (212:11): [True: 275, False: 42]
  ------------------
  213|  1.35k|        while (r.input_count > 0 &&
  ------------------
  |  Branch (213:16): [True: 1.26k, False: 90]
  ------------------
  214|  1.26k|               base64_ignorable(*(srcinit + r.input_count - 1), options)) {
  ------------------
  |  Branch (214:16): [True: 1.08k, False: 185]
  ------------------
  215|  1.08k|          r.input_count--;
  216|  1.08k|        }
  217|    275|      }
  218|    317|    }
  219|  5.44k|    return r;
  220|  5.44k|  }
  221|    403|  if (!ignore_garbage && equalsigns > 0) {
  ------------------
  |  Branch (221:7): [True: 403, Folded]
  |  Branch (221:26): [True: 0, False: 403]
  ------------------
  222|      0|    if ((size_t(dst - dstinit) % 3 == 0) ||
  ------------------
  |  Branch (222:9): [True: 0, False: 0]
  ------------------
  223|      0|        ((size_t(dst - dstinit) % 3) + 1 + equalsigns != 4)) {
  ------------------
  |  Branch (223:9): [True: 0, False: 0]
  ------------------
  224|      0|      return {INVALID_BASE64_CHARACTER, equallocation, size_t(dst - dstinit),
  225|      0|              true};
  226|      0|    }
  227|      0|  }
  228|    403|  return {SUCCESS, srclen, size_t(dst - dstinit)};
  229|    403|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_16base6422compress_decode_base64ILb0ELb0ELb0EcEENS_11full_resultEPcPKT2_mNS_14base64_optionsENS_27last_chunk_handling_optionsE:
   45|  16.1k|                       last_chunk_handling_options last_chunk_options) {
   46|  16.1k|  const uint8_t *to_base64 =
   47|  16.1k|      default_or_url ? tables::base64::to_base64_default_or_url_value
  ------------------
  |  Branch (47:7): [Folded, False: 16.1k]
  ------------------
   48|  16.1k|                     : (base64_url ? tables::base64::to_base64_url_value
  ------------------
  |  Branch (48:25): [Folded, False: 16.1k]
  ------------------
   49|  16.1k|                                   : tables::base64::to_base64_value);
   50|  16.1k|  auto ri = simdutf::scalar::base64::find_end(src, srclen, options);
   51|  16.1k|  size_t equallocation = ri.equallocation;
   52|  16.1k|  size_t equalsigns = ri.equalsigns;
   53|  16.1k|  srclen = ri.srclen;
   54|  16.1k|  size_t full_input_length = ri.full_input_length;
   55|  16.1k|  if (srclen == 0) {
  ------------------
  |  Branch (55:7): [True: 14.6k, False: 1.55k]
  ------------------
   56|  14.6k|    if (!ignore_garbage && equalsigns > 0) {
  ------------------
  |  Branch (56:9): [True: 14.6k, Folded]
  |  Branch (56:28): [True: 11, False: 14.5k]
  ------------------
   57|     11|      return {INVALID_BASE64_CHARACTER, equallocation, 0, true};
   58|     11|    }
   59|  14.5k|    return {SUCCESS, full_input_length, 0};
   60|  14.6k|  }
   61|  1.55k|  char *end_of_safe_64byte_zone =
   62|  1.55k|      dst == nullptr
  ------------------
  |  Branch (62:7): [True: 32, False: 1.52k]
  ------------------
   63|  1.55k|          ? nullptr
   64|  1.55k|          : ((srclen + 3) / 4 * 3 >= 63 ? dst + (srclen + 3) / 4 * 3 - 63
  ------------------
  |  Branch (64:14): [True: 508, False: 1.01k]
  ------------------
   65|  1.52k|                                        : dst);
   66|       |
   67|  1.55k|  const chartype *const srcinit = src;
   68|  1.55k|  const char *const dstinit = dst;
   69|  1.55k|  const chartype *const srcend = src + srclen;
   70|       |
   71|  1.55k|  constexpr size_t block_size = 6;
   72|  1.55k|  static_assert(block_size >= 2, "block_size must be at least two");
   73|  1.55k|  char buffer[block_size * 64];
   74|  1.55k|  char *bufferptr = buffer;
   75|  1.55k|  if (srclen >= 64) {
  ------------------
  |  Branch (75:7): [True: 809, False: 745]
  ------------------
   76|    809|    const chartype *const srcend64 = src + srclen - 64;
   77|  4.52k|    while (src <= srcend64) {
  ------------------
  |  Branch (77:12): [True: 3.97k, False: 556]
  ------------------
   78|  3.97k|      block64 b(src);
   79|  3.97k|      src += 64;
   80|  3.97k|      uint64_t error = 0;
   81|  3.97k|      const uint64_t badcharmask =
   82|  3.97k|          b.to_base64_mask<base64_url, ignore_garbage, default_or_url>(&error);
   83|  3.97k|      if (!ignore_garbage && error) {
  ------------------
  |  Branch (83:11): [True: 3.97k, Folded]
  |  Branch (83:30): [True: 253, False: 3.71k]
  ------------------
   84|    253|        src -= 64;
   85|    253|        const size_t error_offset = trailing_zeroes(error);
   86|    253|        return {error_code::INVALID_BASE64_CHARACTER,
   87|    253|                size_t(src - srcinit + error_offset), size_t(dst - dstinit)};
   88|    253|      }
   89|  3.71k|      if (badcharmask != 0) {
  ------------------
  |  Branch (89:11): [True: 752, False: 2.96k]
  ------------------
   90|    752|        bufferptr += b.compress_block(badcharmask, bufferptr);
   91|  2.96k|      } else if (bufferptr != buffer) {
  ------------------
  |  Branch (91:18): [True: 68, False: 2.89k]
  ------------------
   92|     68|        b.copy_block(bufferptr);
   93|     68|        bufferptr += 64;
   94|  2.89k|      } else {
   95|  2.89k|        if (dst >= end_of_safe_64byte_zone) {
  ------------------
  |  Branch (95:13): [True: 120, False: 2.77k]
  ------------------
   96|    120|          b.base64_decode_block_safe(dst);
   97|  2.77k|        } else {
   98|  2.77k|          b.base64_decode_block(dst);
   99|  2.77k|        }
  100|  2.89k|        dst += 48;
  101|  2.89k|      }
  102|  3.71k|      if (bufferptr >= (block_size - 1) * 64 + buffer) {
  ------------------
  |  Branch (102:11): [True: 68, False: 3.65k]
  ------------------
  103|    340|        for (size_t i = 0; i < (block_size - 2); i++) {
  ------------------
  |  Branch (103:28): [True: 272, False: 68]
  ------------------
  104|    272|          base64_decode_block(dst, buffer + i * 64);
  105|    272|          dst += 48;
  106|    272|        }
  107|     68|        if (dst >= end_of_safe_64byte_zone) {
  ------------------
  |  Branch (107:13): [True: 0, False: 68]
  ------------------
  108|      0|          base64_decode_block_safe(dst, buffer + (block_size - 2) * 64);
  109|     68|        } else {
  110|     68|          base64_decode_block(dst, buffer + (block_size - 2) * 64);
  111|     68|        }
  112|     68|        dst += 48;
  113|     68|        std::memcpy(buffer, buffer + (block_size - 1) * 64,
  114|     68|                    64); // 64 might be too much
  115|     68|        bufferptr -= (block_size - 1) * 64;
  116|     68|      }
  117|  3.71k|    }
  118|    809|  }
  119|       |
  120|  1.30k|  char *buffer_start = buffer;
  121|       |  // Optimization note: if this is almost full, then it is worth our
  122|       |  // time, otherwise, we should just decode directly.
  123|  1.30k|  int last_block = (int)((bufferptr - buffer_start) % 64);
  124|  1.30k|  if (last_block != 0 && srcend - src + last_block >= 64) {
  ------------------
  |  Branch (124:7): [True: 238, False: 1.06k]
  |  Branch (124:26): [True: 41, False: 197]
  ------------------
  125|       |
  126|    351|    while ((bufferptr - buffer_start) % 64 != 0 && src < srcend) {
  ------------------
  |  Branch (126:12): [True: 324, False: 27]
  |  Branch (126:52): [True: 314, False: 10]
  ------------------
  127|    314|      uint8_t val = to_base64[uint8_t(*src)];
  128|    314|      *bufferptr = char(val);
  129|    314|      if (!ignore_garbage &&
  ------------------
  |  Branch (129:11): [True: 314, Folded]
  ------------------
  130|    314|          (!scalar::base64::is_eight_byte(*src) || val > 64)) {
  ------------------
  |  Branch (130:12): [True: 0, False: 314]
  |  Branch (130:52): [True: 4, False: 310]
  ------------------
  131|      4|        return {error_code::INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  132|      4|                size_t(dst - dstinit)};
  133|      4|      }
  134|    310|      bufferptr += (val <= 63);
  135|    310|      src++;
  136|    310|    }
  137|     41|  }
  138|       |
  139|  1.45k|  for (; buffer_start + 64 <= bufferptr; buffer_start += 64) {
  ------------------
  |  Branch (139:10): [True: 154, False: 1.29k]
  ------------------
  140|    154|    if (dst >= end_of_safe_64byte_zone) {
  ------------------
  |  Branch (140:9): [True: 21, False: 133]
  ------------------
  141|     21|      base64_decode_block_safe(dst, buffer_start);
  142|    133|    } else {
  143|    133|      base64_decode_block(dst, buffer_start);
  144|    133|    }
  145|    154|    dst += 48;
  146|    154|  }
  147|  1.29k|  if ((bufferptr - buffer_start) % 64 != 0) {
  ------------------
  |  Branch (147:7): [True: 207, False: 1.09k]
  ------------------
  148|  1.84k|    while (buffer_start + 4 < bufferptr) {
  ------------------
  |  Branch (148:12): [True: 1.63k, False: 207]
  ------------------
  149|  1.63k|      uint32_t triple = ((uint32_t(uint8_t(buffer_start[0])) << 3 * 6) +
  150|  1.63k|                         (uint32_t(uint8_t(buffer_start[1])) << 2 * 6) +
  151|  1.63k|                         (uint32_t(uint8_t(buffer_start[2])) << 1 * 6) +
  152|  1.63k|                         (uint32_t(uint8_t(buffer_start[3])) << 0 * 6))
  153|  1.63k|                        << 8;
  154|  1.63k|#if !SIMDUTF_IS_BIG_ENDIAN
  155|  1.63k|      triple = scalar::u32_swap_bytes(triple);
  156|  1.63k|#endif
  157|  1.63k|      std::memcpy(dst, &triple, 3);
  158|       |
  159|  1.63k|      dst += 3;
  160|  1.63k|      buffer_start += 4;
  161|  1.63k|    }
  162|    207|    if (buffer_start + 4 <= bufferptr) {
  ------------------
  |  Branch (162:9): [True: 53, False: 154]
  ------------------
  163|     53|      uint32_t triple = ((uint32_t(uint8_t(buffer_start[0])) << 3 * 6) +
  164|     53|                         (uint32_t(uint8_t(buffer_start[1])) << 2 * 6) +
  165|     53|                         (uint32_t(uint8_t(buffer_start[2])) << 1 * 6) +
  166|     53|                         (uint32_t(uint8_t(buffer_start[3])) << 0 * 6))
  167|     53|                        << 8;
  168|     53|#if !SIMDUTF_IS_BIG_ENDIAN
  169|     53|      triple = scalar::u32_swap_bytes(triple);
  170|     53|#endif
  171|     53|      std::memcpy(dst, &triple, 3);
  172|       |
  173|     53|      dst += 3;
  174|     53|      buffer_start += 4;
  175|     53|    }
  176|       |    // we may have 1, 2 or 3 bytes left and we need to decode them so let us
  177|       |    // backtrack
  178|    207|    int leftover = int(bufferptr - buffer_start);
  179|    524|    while (leftover > 0) {
  ------------------
  |  Branch (179:12): [True: 317, False: 207]
  ------------------
  180|    317|      if (!ignore_garbage) {
  ------------------
  |  Branch (180:11): [True: 317, Folded]
  ------------------
  181|  2.74k|        while (to_base64[uint8_t(*(src - 1))] == 64) {
  ------------------
  |  Branch (181:16): [True: 2.42k, False: 317]
  ------------------
  182|  2.42k|          src--;
  183|  2.42k|        }
  184|    317|      } else {
  185|      0|        while (to_base64[uint8_t(*(src - 1))] >= 64) {
  ------------------
  |  Branch (185:16): [True: 0, False: 0]
  ------------------
  186|      0|          src--;
  187|      0|        }
  188|      0|      }
  189|    317|      src--;
  190|    317|      leftover--;
  191|    317|    }
  192|    207|  }
  193|  1.29k|  if (src < srcend + equalsigns) {
  ------------------
  |  Branch (193:7): [True: 1.17k, False: 119]
  ------------------
  194|  1.17k|    full_result r = scalar::base64::base64_tail_decode(
  195|  1.17k|        dst, src, srcend - src, equalsigns, options, last_chunk_options);
  196|  1.17k|    r = scalar::base64::patch_tail_result(
  197|  1.17k|        r, size_t(src - srcinit), size_t(dst - dstinit), equallocation,
  198|  1.17k|        full_input_length, last_chunk_options);
  199|       |    // When is_partial(last_chunk_options) is true, we must either end with
  200|       |    // the end of the stream (beyond whitespace) or right after a non-ignorable
  201|       |    // character or at the very beginning of the stream.
  202|       |    // See https://tc39.es/proposal-arraybuffer-base64/spec/#sec-frombase64
  203|  1.17k|    if (is_partial(last_chunk_options) && r.error == error_code::SUCCESS &&
  ------------------
  |  Branch (203:9): [True: 0, False: 1.17k]
  |  Branch (203:43): [True: 0, False: 0]
  ------------------
  204|      0|        r.input_count < full_input_length) {
  ------------------
  |  Branch (204:9): [True: 0, False: 0]
  ------------------
  205|       |      // First check if we can extend the input to the end of the stream
  206|      0|      while (r.input_count < full_input_length &&
  ------------------
  |  Branch (206:14): [True: 0, False: 0]
  ------------------
  207|      0|             base64_ignorable(*(srcinit + r.input_count), options)) {
  ------------------
  |  Branch (207:14): [True: 0, False: 0]
  ------------------
  208|      0|        r.input_count++;
  209|      0|      }
  210|       |      // If we are still not at the end of the stream, then we must backtrack
  211|       |      // to the last non-ignorable character.
  212|      0|      if (r.input_count < full_input_length) {
  ------------------
  |  Branch (212:11): [True: 0, False: 0]
  ------------------
  213|      0|        while (r.input_count > 0 &&
  ------------------
  |  Branch (213:16): [True: 0, False: 0]
  ------------------
  214|      0|               base64_ignorable(*(srcinit + r.input_count - 1), options)) {
  ------------------
  |  Branch (214:16): [True: 0, False: 0]
  ------------------
  215|      0|          r.input_count--;
  216|      0|        }
  217|      0|      }
  218|      0|    }
  219|  1.17k|    return r;
  220|  1.17k|  }
  221|    119|  if (!ignore_garbage && equalsigns > 0) {
  ------------------
  |  Branch (221:7): [True: 119, Folded]
  |  Branch (221:26): [True: 0, False: 119]
  ------------------
  222|      0|    if ((size_t(dst - dstinit) % 3 == 0) ||
  ------------------
  |  Branch (222:9): [True: 0, False: 0]
  ------------------
  223|      0|        ((size_t(dst - dstinit) % 3) + 1 + equalsigns != 4)) {
  ------------------
  |  Branch (223:9): [True: 0, False: 0]
  ------------------
  224|      0|      return {INVALID_BASE64_CHARACTER, equallocation, size_t(dst - dstinit),
  225|      0|              true};
  226|      0|    }
  227|      0|  }
  228|    119|  return {SUCCESS, srclen, size_t(dst - dstinit)};
  229|    119|}

simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE13get_remainderEPh:
   57|  27.3k|buf_block_reader<STEP_SIZE>::get_remainder(uint8_t *dst) const {
   58|  27.3k|  if (len == idx) {
  ------------------
  |  Branch (58:7): [True: 23.0k, False: 4.38k]
  ------------------
   59|  23.0k|    return 0;
   60|  23.0k|  } // memcpy(dst, null, 0) will trigger an error with some sanitizers
   61|  4.38k|  std::memset(dst, 0x20,
   62|  4.38k|              STEP_SIZE); // std::memset STEP_SIZE because it is more efficient
   63|       |                          // to write out 8 or 16 bytes at once.
   64|  4.38k|  std::memcpy(dst, buf + idx, len - idx);
   65|  4.38k|  return len - idx;
   66|  27.3k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE13get_remainderEPh:
   57|  27.3k|buf_block_reader<STEP_SIZE>::get_remainder(uint8_t *dst) const {
   58|  27.3k|  if (len == idx) {
  ------------------
  |  Branch (58:7): [True: 24.0k, False: 3.35k]
  ------------------
   59|  24.0k|    return 0;
   60|  24.0k|  } // memcpy(dst, null, 0) will trigger an error with some sanitizers
   61|  3.35k|  std::memset(dst, 0x20,
   62|  3.35k|              STEP_SIZE); // std::memset STEP_SIZE because it is more efficient
   63|       |                          // to write out 8 or 16 bytes at once.
   64|  3.35k|  std::memcpy(dst, buf + idx, len - idx);
   65|  3.35k|  return len - idx;
   66|  27.3k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EEC2EPKhm:
   36|  27.6k|    : buf{_buf}, len{_len}, lenminusstep{len < STEP_SIZE ? 0 : len - STEP_SIZE},
  ------------------
  |  Branch (36:42): [True: 25.6k, False: 1.95k]
  ------------------
   37|  27.6k|      idx{0} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE14has_full_blockEv:
   45|  34.5k|simdutf_really_inline bool buf_block_reader<STEP_SIZE>::has_full_block() const {
   46|  34.5k|  return idx < lenminusstep;
   47|  34.5k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE10full_blockEv:
   51|  7.21k|buf_block_reader<STEP_SIZE>::full_block() const {
   52|  7.21k|  return &buf[idx];
   53|  7.21k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE7advanceEv:
   69|  34.3k|simdutf_really_inline void buf_block_reader<STEP_SIZE>::advance() {
   70|  34.3k|  idx += STEP_SIZE;
   71|  34.3k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EEC2EPKhm:
   36|  27.6k|    : buf{_buf}, len{_len}, lenminusstep{len < STEP_SIZE ? 0 : len - STEP_SIZE},
  ------------------
  |  Branch (36:42): [True: 25.7k, False: 1.87k]
  ------------------
   37|  27.6k|      idx{0} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE14has_full_blockEv:
   45|  37.2k|simdutf_really_inline bool buf_block_reader<STEP_SIZE>::has_full_block() const {
   46|  37.2k|  return idx < lenminusstep;
   47|  37.2k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE10full_blockEv:
   51|  9.90k|buf_block_reader<STEP_SIZE>::full_block() const {
   52|  9.90k|  return &buf[idx];
   53|  9.90k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE7advanceEv:
   69|  37.0k|simdutf_really_inline void buf_block_reader<STEP_SIZE>::advance() {
   70|  37.0k|  idx += STEP_SIZE;
   71|  37.0k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE0EEEmPKDsm:
   10|  10.5k|                                                             size_t size) {
   11|  10.5k|  size_t pos = 0;
   12|       |
   13|  10.5k|  using vector_u16 = simd16<uint16_t>;
   14|  10.5k|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|  10.5k|  const auto one = vector_u16::splat(1);
   17|       |
   18|  10.5k|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|  10.5k|  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|  10.5k|  constexpr size_t max_iterations = 65535 / 2;
   26|  10.5k|  size_t iteration = max_iterations;
   27|       |
   28|  15.9k|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 5.39k, False: 10.5k]
  ------------------
   29|  5.39k|    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|  5.39k|    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|  5.39k|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|  5.39k|    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|  5.39k|    v_count += c0;
   68|  5.39k|    v_count += c1;
   69|  5.39k|    v_count += vector_u16(is_surrogate);
   70|       |
   71|  5.39k|    iteration -= 1;
   72|  5.39k|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 0, False: 5.39k]
  ------------------
   73|      0|      count += v_count.sum();
   74|      0|      v_count = vector_u16::zero();
   75|      0|      iteration = max_iterations;
   76|      0|    }
   77|  5.39k|  }
   78|       |
   79|  10.5k|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 10.5k, False: 0]
  ------------------
   80|  10.5k|    count += v_count.sum();
   81|  10.5k|  }
   82|       |
   83|  10.5k|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|  10.5k|                                                                   size - pos);
   85|  10.5k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE1EEEmPKDsm:
   10|  10.5k|                                                             size_t size) {
   11|  10.5k|  size_t pos = 0;
   12|       |
   13|  10.5k|  using vector_u16 = simd16<uint16_t>;
   14|  10.5k|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|  10.5k|  const auto one = vector_u16::splat(1);
   17|       |
   18|  10.5k|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|  10.5k|  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|  10.5k|  constexpr size_t max_iterations = 65535 / 2;
   26|  10.5k|  size_t iteration = max_iterations;
   27|       |
   28|  16.2k|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 5.77k, False: 10.5k]
  ------------------
   29|  5.77k|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
   30|  5.77k|    if constexpr (!match_system(big_endian)) {
   31|  5.77k|      input = input.swap_bytes();
   32|  5.77k|    }
   33|       |    // 0xd800 .. 0xdbff - low surrogate
   34|       |    // 0xdc00 .. 0xdfff - high surrogate
   35|  5.77k|    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|  5.77k|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|  5.77k|    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|  5.77k|    v_count += c0;
   68|  5.77k|    v_count += c1;
   69|  5.77k|    v_count += vector_u16(is_surrogate);
   70|       |
   71|  5.77k|    iteration -= 1;
   72|  5.77k|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 0, False: 5.77k]
  ------------------
   73|      0|      count += v_count.sum();
   74|      0|      v_count = vector_u16::zero();
   75|      0|      iteration = max_iterations;
   76|      0|    }
   77|  5.77k|  }
   78|       |
   79|  10.5k|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 10.5k, False: 0]
  ------------------
   80|  10.5k|    count += v_count.sum();
   81|  10.5k|  }
   82|       |
   83|  10.5k|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|  10.5k|                                                                   size - pos);
   85|  10.5k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE0EEEmPKDsm:
   10|  10.7k|                                                             size_t size) {
   11|  10.7k|  size_t pos = 0;
   12|       |
   13|  10.7k|  using vector_u16 = simd16<uint16_t>;
   14|  10.7k|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|  10.7k|  const auto one = vector_u16::splat(1);
   17|       |
   18|  10.7k|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|  10.7k|  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|  10.7k|  constexpr size_t max_iterations = 65535 / 2;
   26|  10.7k|  size_t iteration = max_iterations;
   27|       |
   28|  27.2k|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 16.5k, False: 10.7k]
  ------------------
   29|  16.5k|    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|  16.5k|    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|  16.5k|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|  16.5k|    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|  16.5k|    v_count += c0;
   68|  16.5k|    v_count += c1;
   69|  16.5k|    v_count += vector_u16(is_surrogate);
   70|       |
   71|  16.5k|    iteration -= 1;
   72|  16.5k|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 0, False: 16.5k]
  ------------------
   73|      0|      count += v_count.sum();
   74|      0|      v_count = vector_u16::zero();
   75|      0|      iteration = max_iterations;
   76|      0|    }
   77|  16.5k|  }
   78|       |
   79|  10.7k|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 10.7k, False: 0]
  ------------------
   80|  10.7k|    count += v_count.sum();
   81|  10.7k|  }
   82|       |
   83|  10.7k|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|  10.7k|                                                                   size - pos);
   85|  10.7k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1631utf8_length_from_utf16_bytemaskILNS_10endiannessE1EEEmPKDsm:
   10|  10.7k|                                                             size_t size) {
   11|  10.7k|  size_t pos = 0;
   12|       |
   13|  10.7k|  using vector_u16 = simd16<uint16_t>;
   14|  10.7k|  constexpr size_t N = vector_u16::ELEMENTS;
   15|       |
   16|  10.7k|  const auto one = vector_u16::splat(1);
   17|       |
   18|  10.7k|  auto v_count = vector_u16::zero();
   19|       |
   20|       |  // each char16 yields at least one byte
   21|  10.7k|  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|  10.7k|  constexpr size_t max_iterations = 65535 / 2;
   26|  10.7k|  size_t iteration = max_iterations;
   27|       |
   28|  27.5k|  for (; pos < size / N * N; pos += N) {
  ------------------
  |  Branch (28:10): [True: 16.7k, False: 10.7k]
  ------------------
   29|  16.7k|    auto input = vector_u16::load(reinterpret_cast<const uint16_t *>(in + pos));
   30|  16.7k|    if constexpr (!match_system(big_endian)) {
   31|  16.7k|      input = input.swap_bytes();
   32|  16.7k|    }
   33|       |    // 0xd800 .. 0xdbff - low surrogate
   34|       |    // 0xdc00 .. 0xdfff - high surrogate
   35|  16.7k|    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|  16.7k|    const auto c0 = min(input & uint16_t(0xff80), one);
   39|       |
   40|       |    // c1 - chars that yield 3-byte UTF-8 codes (including surrogates)
   41|  16.7k|    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|  16.7k|    v_count += c0;
   68|  16.7k|    v_count += c1;
   69|  16.7k|    v_count += vector_u16(is_surrogate);
   70|       |
   71|  16.7k|    iteration -= 1;
   72|  16.7k|    if (iteration == 0) {
  ------------------
  |  Branch (72:9): [True: 0, False: 16.7k]
  ------------------
   73|      0|      count += v_count.sum();
   74|      0|      v_count = vector_u16::zero();
   75|      0|      iteration = max_iterations;
   76|      0|    }
   77|  16.7k|  }
   78|       |
   79|  10.7k|  if (iteration > 0) {
  ------------------
  |  Branch (79:7): [True: 10.7k, False: 0]
  ------------------
   80|  10.7k|    count += v_count.sum();
   81|  10.7k|  }
   82|       |
   83|  10.7k|  return count + scalar::utf16::utf8_length_from_utf16<big_endian>(in + pos,
   84|  10.7k|                                                                   size - pos);
   85|  10.7k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf3222utf8_length_from_utf32EPKDim:
   11|  4.96k|                                                    size_t length) {
   12|  4.96k|  using vector_u32 = simd32<uint32_t>;
   13|       |
   14|  4.96k|  const char32_t *start = input;
   15|       |
   16|       |  // we add up to three ones in a single iteration (see the vectorized loop in
   17|       |  // section #2 below)
   18|  4.96k|  const size_t max_increment = 3;
   19|       |
   20|  4.96k|  const size_t N = vector_u32::ELEMENTS;
   21|       |
   22|       |#if SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   23|       |  const auto v_0000007f = vector_u32::splat(0x0000007f);
   24|       |  const auto v_000007ff = vector_u32::splat(0x000007ff);
   25|       |  const auto v_0000ffff = vector_u32::splat(0x0000ffff);
   26|       |#else
   27|  4.96k|  const auto v_ffffff80 = vector_u32::splat(0xffffff80);
   28|  4.96k|  const auto v_fffff800 = vector_u32::splat(0xfffff800);
   29|  4.96k|  const auto v_ffff0000 = vector_u32::splat(0xffff0000);
   30|  4.96k|  const auto one = vector_u32::splat(1);
   31|  4.96k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   32|       |
   33|  4.96k|  size_t counter = 0;
   34|       |
   35|       |  // 1. vectorized loop unrolled 4 times
   36|  4.96k|  {
   37|       |    // we use vector of uint32 counters, this is why this limit is used
   38|  4.96k|    const size_t max_iterations =
   39|  4.96k|        std::numeric_limits<uint32_t>::max() / (max_increment * 4);
   40|  4.96k|    size_t blocks = length / (N * 4);
   41|  4.96k|    length -= blocks * (N * 4);
   42|  5.18k|    while (blocks != 0) {
  ------------------
  |  Branch (42:12): [True: 218, False: 4.96k]
  ------------------
   43|    218|      const size_t iterations = min(blocks, max_iterations);
   44|    218|      blocks -= iterations;
   45|       |
   46|    218|      simd32<uint32_t> acc = vector_u32::zero();
   47|  1.76k|      for (size_t i = 0; i < iterations; i++) {
  ------------------
  |  Branch (47:26): [True: 1.54k, False: 218]
  ------------------
   48|  1.54k|        const auto in0 = vector_u32(input + 0 * N);
   49|  1.54k|        const auto in1 = vector_u32(input + 1 * N);
   50|  1.54k|        const auto in2 = vector_u32(input + 2 * N);
   51|  1.54k|        const auto in3 = vector_u32(input + 3 * N);
   52|       |
   53|       |#if SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   54|       |        acc -= as_vector_u32(in0 > v_0000007f);
   55|       |        acc -= as_vector_u32(in1 > v_0000007f);
   56|       |        acc -= as_vector_u32(in2 > v_0000007f);
   57|       |        acc -= as_vector_u32(in3 > v_0000007f);
   58|       |
   59|       |        acc -= as_vector_u32(in0 > v_000007ff);
   60|       |        acc -= as_vector_u32(in1 > v_000007ff);
   61|       |        acc -= as_vector_u32(in2 > v_000007ff);
   62|       |        acc -= as_vector_u32(in3 > v_000007ff);
   63|       |
   64|       |        acc -= as_vector_u32(in0 > v_0000ffff);
   65|       |        acc -= as_vector_u32(in1 > v_0000ffff);
   66|       |        acc -= as_vector_u32(in2 > v_0000ffff);
   67|       |        acc -= as_vector_u32(in3 > v_0000ffff);
   68|       |#else
   69|  1.54k|        acc += min(one, in0 & v_ffffff80);
   70|  1.54k|        acc += min(one, in1 & v_ffffff80);
   71|  1.54k|        acc += min(one, in2 & v_ffffff80);
   72|  1.54k|        acc += min(one, in3 & v_ffffff80);
   73|       |
   74|  1.54k|        acc += min(one, in0 & v_fffff800);
   75|  1.54k|        acc += min(one, in1 & v_fffff800);
   76|  1.54k|        acc += min(one, in2 & v_fffff800);
   77|  1.54k|        acc += min(one, in3 & v_fffff800);
   78|       |
   79|  1.54k|        acc += min(one, in0 & v_ffff0000);
   80|  1.54k|        acc += min(one, in1 & v_ffff0000);
   81|  1.54k|        acc += min(one, in2 & v_ffff0000);
   82|  1.54k|        acc += min(one, in3 & v_ffff0000);
   83|  1.54k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   84|       |
   85|  1.54k|        input += 4 * N;
   86|  1.54k|      }
   87|       |
   88|    218|      counter += acc.sum();
   89|    218|    }
   90|  4.96k|  }
   91|       |
   92|       |  // 2. vectorized loop for tail
   93|  4.96k|  {
   94|  4.96k|    const size_t max_iterations =
   95|  4.96k|        std::numeric_limits<uint32_t>::max() / max_increment;
   96|  4.96k|    size_t blocks = length / N;
   97|  4.96k|    length -= blocks * N;
   98|  5.45k|    while (blocks != 0) {
  ------------------
  |  Branch (98:12): [True: 494, False: 4.96k]
  ------------------
   99|    494|      const size_t iterations = min(blocks, max_iterations);
  100|    494|      blocks -= iterations;
  101|       |
  102|    494|      auto acc = vector_u32::zero();
  103|  1.66k|      for (size_t i = 0; i < iterations; i++) {
  ------------------
  |  Branch (103:26): [True: 1.16k, False: 494]
  ------------------
  104|  1.16k|        const auto in = vector_u32(input);
  105|       |
  106|       |#if SIMDUTF_SIMD_HAS_UNSIGNED_CMP
  107|       |        acc -= as_vector_u32(in > v_0000007f);
  108|       |        acc -= as_vector_u32(in > v_000007ff);
  109|       |        acc -= as_vector_u32(in > v_0000ffff);
  110|       |#else
  111|  1.16k|        acc += min(one, in & v_ffffff80);
  112|  1.16k|        acc += min(one, in & v_fffff800);
  113|  1.16k|        acc += min(one, in & v_ffff0000);
  114|  1.16k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
  115|       |
  116|  1.16k|        input += N;
  117|  1.16k|      }
  118|       |
  119|    494|      counter += acc.sum();
  120|    494|    }
  121|  4.96k|  }
  122|       |
  123|  4.96k|  const size_t consumed = input - start;
  124|  4.96k|  if (consumed != 0) {
  ------------------
  |  Branch (124:7): [True: 555, False: 4.40k]
  ------------------
  125|       |    // We don't count 0th bytes in the vectorized loops above, this
  126|       |    // is why we need to count them in the end.
  127|    555|    counter += consumed;
  128|    555|  }
  129|       |
  130|  4.96k|  return counter + scalar::utf32::utf8_length_from_utf32(input, length);
  131|  4.96k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf323minImEET_S4_S4_:
    8|    712|template <typename T> T min(T a, T b) { return a <= b ? a : b; }
  ------------------
  |  Branch (8:48): [True: 712, False: 0]
  ------------------
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf3222utf8_length_from_utf32EPKDim:
   11|  5.14k|                                                    size_t length) {
   12|  5.14k|  using vector_u32 = simd32<uint32_t>;
   13|       |
   14|  5.14k|  const char32_t *start = input;
   15|       |
   16|       |  // we add up to three ones in a single iteration (see the vectorized loop in
   17|       |  // section #2 below)
   18|  5.14k|  const size_t max_increment = 3;
   19|       |
   20|  5.14k|  const size_t N = vector_u32::ELEMENTS;
   21|       |
   22|       |#if SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   23|       |  const auto v_0000007f = vector_u32::splat(0x0000007f);
   24|       |  const auto v_000007ff = vector_u32::splat(0x000007ff);
   25|       |  const auto v_0000ffff = vector_u32::splat(0x0000ffff);
   26|       |#else
   27|  5.14k|  const auto v_ffffff80 = vector_u32::splat(0xffffff80);
   28|  5.14k|  const auto v_fffff800 = vector_u32::splat(0xfffff800);
   29|  5.14k|  const auto v_ffff0000 = vector_u32::splat(0xffff0000);
   30|  5.14k|  const auto one = vector_u32::splat(1);
   31|  5.14k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   32|       |
   33|  5.14k|  size_t counter = 0;
   34|       |
   35|       |  // 1. vectorized loop unrolled 4 times
   36|  5.14k|  {
   37|       |    // we use vector of uint32 counters, this is why this limit is used
   38|  5.14k|    const size_t max_iterations =
   39|  5.14k|        std::numeric_limits<uint32_t>::max() / (max_increment * 4);
   40|  5.14k|    size_t blocks = length / (N * 4);
   41|  5.14k|    length -= blocks * (N * 4);
   42|  5.64k|    while (blocks != 0) {
  ------------------
  |  Branch (42:12): [True: 505, False: 5.14k]
  ------------------
   43|    505|      const size_t iterations = min(blocks, max_iterations);
   44|    505|      blocks -= iterations;
   45|       |
   46|    505|      simd32<uint32_t> acc = vector_u32::zero();
   47|  5.66k|      for (size_t i = 0; i < iterations; i++) {
  ------------------
  |  Branch (47:26): [True: 5.15k, False: 505]
  ------------------
   48|  5.15k|        const auto in0 = vector_u32(input + 0 * N);
   49|  5.15k|        const auto in1 = vector_u32(input + 1 * N);
   50|  5.15k|        const auto in2 = vector_u32(input + 2 * N);
   51|  5.15k|        const auto in3 = vector_u32(input + 3 * N);
   52|       |
   53|       |#if SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   54|       |        acc -= as_vector_u32(in0 > v_0000007f);
   55|       |        acc -= as_vector_u32(in1 > v_0000007f);
   56|       |        acc -= as_vector_u32(in2 > v_0000007f);
   57|       |        acc -= as_vector_u32(in3 > v_0000007f);
   58|       |
   59|       |        acc -= as_vector_u32(in0 > v_000007ff);
   60|       |        acc -= as_vector_u32(in1 > v_000007ff);
   61|       |        acc -= as_vector_u32(in2 > v_000007ff);
   62|       |        acc -= as_vector_u32(in3 > v_000007ff);
   63|       |
   64|       |        acc -= as_vector_u32(in0 > v_0000ffff);
   65|       |        acc -= as_vector_u32(in1 > v_0000ffff);
   66|       |        acc -= as_vector_u32(in2 > v_0000ffff);
   67|       |        acc -= as_vector_u32(in3 > v_0000ffff);
   68|       |#else
   69|  5.15k|        acc += min(one, in0 & v_ffffff80);
   70|  5.15k|        acc += min(one, in1 & v_ffffff80);
   71|  5.15k|        acc += min(one, in2 & v_ffffff80);
   72|  5.15k|        acc += min(one, in3 & v_ffffff80);
   73|       |
   74|  5.15k|        acc += min(one, in0 & v_fffff800);
   75|  5.15k|        acc += min(one, in1 & v_fffff800);
   76|  5.15k|        acc += min(one, in2 & v_fffff800);
   77|  5.15k|        acc += min(one, in3 & v_fffff800);
   78|       |
   79|  5.15k|        acc += min(one, in0 & v_ffff0000);
   80|  5.15k|        acc += min(one, in1 & v_ffff0000);
   81|  5.15k|        acc += min(one, in2 & v_ffff0000);
   82|  5.15k|        acc += min(one, in3 & v_ffff0000);
   83|  5.15k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   84|       |
   85|  5.15k|        input += 4 * N;
   86|  5.15k|      }
   87|       |
   88|    505|      counter += acc.sum();
   89|    505|    }
   90|  5.14k|  }
   91|       |
   92|       |  // 2. vectorized loop for tail
   93|  5.14k|  {
   94|  5.14k|    const size_t max_iterations =
   95|  5.14k|        std::numeric_limits<uint32_t>::max() / max_increment;
   96|  5.14k|    size_t blocks = length / N;
   97|  5.14k|    length -= blocks * N;
   98|  5.58k|    while (blocks != 0) {
  ------------------
  |  Branch (98:12): [True: 445, False: 5.14k]
  ------------------
   99|    445|      const size_t iterations = min(blocks, max_iterations);
  100|    445|      blocks -= iterations;
  101|       |
  102|    445|      auto acc = vector_u32::zero();
  103|  1.48k|      for (size_t i = 0; i < iterations; i++) {
  ------------------
  |  Branch (103:26): [True: 1.03k, False: 445]
  ------------------
  104|  1.03k|        const auto in = vector_u32(input);
  105|       |
  106|       |#if SIMDUTF_SIMD_HAS_UNSIGNED_CMP
  107|       |        acc -= as_vector_u32(in > v_0000007f);
  108|       |        acc -= as_vector_u32(in > v_000007ff);
  109|       |        acc -= as_vector_u32(in > v_0000ffff);
  110|       |#else
  111|  1.03k|        acc += min(one, in & v_ffffff80);
  112|  1.03k|        acc += min(one, in & v_fffff800);
  113|  1.03k|        acc += min(one, in & v_ffff0000);
  114|  1.03k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
  115|       |
  116|  1.03k|        input += N;
  117|  1.03k|      }
  118|       |
  119|    445|      counter += acc.sum();
  120|    445|    }
  121|  5.14k|  }
  122|       |
  123|  5.14k|  const size_t consumed = input - start;
  124|  5.14k|  if (consumed != 0) {
  ------------------
  |  Branch (124:7): [True: 547, False: 4.59k]
  ------------------
  125|       |    // We don't count 0th bytes in the vectorized loops above, this
  126|       |    // is why we need to count them in the end.
  127|    547|    counter += consumed;
  128|    547|  }
  129|       |
  130|  5.14k|  return counter + scalar::utf32::utf8_length_from_utf32(input, length);
  131|  5.14k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf323minImEET_S4_S4_:
    8|    950|template <typename T> T min(T a, T b) { return a <= b ? a : b; }
  ------------------
  |  Branch (8:48): [True: 950, False: 0]
  ------------------

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14utf826count_code_points_bytemaskEPKcm:
   21|  11.1k|count_code_points_bytemask(const char *in, size_t size) {
   22|  11.1k|  using vector_i8 = simd8<int8_t>;
   23|  11.1k|  using vector_u8 = simd8<uint8_t>;
   24|  11.1k|  using vector_u64 = simd64<uint64_t>;
   25|       |
   26|  11.1k|  constexpr size_t N = vector_i8::SIZE;
   27|  11.1k|  constexpr size_t max_iterations = 255 / 4;
   28|       |
   29|  11.1k|  size_t pos = 0;
   30|  11.1k|  size_t count = 0;
   31|       |
   32|  11.1k|  auto counters = vector_u64::zero();
   33|  11.1k|  auto local = vector_u8::zero();
   34|  11.1k|  size_t iterations = 0;
   35|  12.9k|  for (; pos + 4 * N <= size; pos += 4 * N) {
  ------------------
  |  Branch (35:10): [True: 1.77k, False: 11.1k]
  ------------------
   36|  1.77k|    const auto input0 =
   37|  1.77k|        simd8<int8_t>::load(reinterpret_cast<const int8_t *>(in + pos + 0 * N));
   38|  1.77k|    const auto input1 =
   39|  1.77k|        simd8<int8_t>::load(reinterpret_cast<const int8_t *>(in + pos + 1 * N));
   40|  1.77k|    const auto input2 =
   41|  1.77k|        simd8<int8_t>::load(reinterpret_cast<const int8_t *>(in + pos + 2 * N));
   42|  1.77k|    const auto input3 =
   43|  1.77k|        simd8<int8_t>::load(reinterpret_cast<const int8_t *>(in + pos + 3 * N));
   44|  1.77k|    const auto mask0 = input0 > int8_t(-65);
   45|  1.77k|    const auto mask1 = input1 > int8_t(-65);
   46|  1.77k|    const auto mask2 = input2 > int8_t(-65);
   47|  1.77k|    const auto mask3 = input3 > int8_t(-65);
   48|       |
   49|  1.77k|    local -= vector_u8(mask0);
   50|  1.77k|    local -= vector_u8(mask1);
   51|  1.77k|    local -= vector_u8(mask2);
   52|  1.77k|    local -= vector_u8(mask3);
   53|       |
   54|  1.77k|    iterations += 1;
   55|  1.77k|    if (iterations == max_iterations) {
  ------------------
  |  Branch (55:9): [True: 0, False: 1.77k]
  ------------------
   56|      0|      counters += sum_8bytes(local);
   57|      0|      local = vector_u8::zero();
   58|      0|      iterations = 0;
   59|      0|    }
   60|  1.77k|  }
   61|       |
   62|  11.1k|  if (iterations > 0) {
  ------------------
  |  Branch (62:7): [True: 440, False: 10.6k]
  ------------------
   63|    440|    count += local.sum_bytes();
   64|    440|  }
   65|       |
   66|  11.1k|  count += counters.sum();
   67|       |
   68|  11.1k|  return count + scalar::utf8::count_code_points(in + pos, size - pos);
   69|  11.1k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14utf817count_code_pointsEPKcm:
    8|  5.56k|simdutf_really_inline size_t count_code_points(const char *in, size_t size) {
    9|  5.56k|  size_t pos = 0;
   10|  5.56k|  size_t count = 0;
   11|  7.25k|  for (; pos + 64 <= size; pos += 64) {
  ------------------
  |  Branch (11:10): [True: 1.69k, False: 5.56k]
  ------------------
   12|  1.69k|    simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
   13|  1.69k|    uint64_t utf8_continuation_mask = input.gt(-65);
   14|  1.69k|    count += count_ones(utf8_continuation_mask);
   15|  1.69k|  }
   16|  5.56k|  return count + scalar::utf8::count_code_points(in + pos, size - pos);
   17|  5.56k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14utf826count_code_points_bytemaskEPKcm:
   21|  11.1k|count_code_points_bytemask(const char *in, size_t size) {
   22|  11.1k|  using vector_i8 = simd8<int8_t>;
   23|  11.1k|  using vector_u8 = simd8<uint8_t>;
   24|  11.1k|  using vector_u64 = simd64<uint64_t>;
   25|       |
   26|  11.1k|  constexpr size_t N = vector_i8::SIZE;
   27|  11.1k|  constexpr size_t max_iterations = 255 / 4;
   28|       |
   29|  11.1k|  size_t pos = 0;
   30|  11.1k|  size_t count = 0;
   31|       |
   32|  11.1k|  auto counters = vector_u64::zero();
   33|  11.1k|  auto local = vector_u8::zero();
   34|  11.1k|  size_t iterations = 0;
   35|  16.8k|  for (; pos + 4 * N <= size; pos += 4 * N) {
  ------------------
  |  Branch (35:10): [True: 5.69k, False: 11.1k]
  ------------------
   36|  5.69k|    const auto input0 =
   37|  5.69k|        simd8<int8_t>::load(reinterpret_cast<const int8_t *>(in + pos + 0 * N));
   38|  5.69k|    const auto input1 =
   39|  5.69k|        simd8<int8_t>::load(reinterpret_cast<const int8_t *>(in + pos + 1 * N));
   40|  5.69k|    const auto input2 =
   41|  5.69k|        simd8<int8_t>::load(reinterpret_cast<const int8_t *>(in + pos + 2 * N));
   42|  5.69k|    const auto input3 =
   43|  5.69k|        simd8<int8_t>::load(reinterpret_cast<const int8_t *>(in + pos + 3 * N));
   44|  5.69k|    const auto mask0 = input0 > int8_t(-65);
   45|  5.69k|    const auto mask1 = input1 > int8_t(-65);
   46|  5.69k|    const auto mask2 = input2 > int8_t(-65);
   47|  5.69k|    const auto mask3 = input3 > int8_t(-65);
   48|       |
   49|  5.69k|    local -= vector_u8(mask0);
   50|  5.69k|    local -= vector_u8(mask1);
   51|  5.69k|    local -= vector_u8(mask2);
   52|  5.69k|    local -= vector_u8(mask3);
   53|       |
   54|  5.69k|    iterations += 1;
   55|  5.69k|    if (iterations == max_iterations) {
  ------------------
  |  Branch (55:9): [True: 0, False: 5.69k]
  ------------------
   56|      0|      counters += sum_8bytes(local);
   57|      0|      local = vector_u8::zero();
   58|      0|      iterations = 0;
   59|      0|    }
   60|  5.69k|  }
   61|       |
   62|  11.1k|  if (iterations > 0) {
  ------------------
  |  Branch (62:7): [True: 1.06k, False: 10.0k]
  ------------------
   63|  1.06k|    count += local.sum_bytes();
   64|  1.06k|  }
   65|       |
   66|  11.1k|  count += counters.sum();
   67|       |
   68|  11.1k|  return count + scalar::utf8::count_code_points(in + pos, size - pos);
   69|  11.1k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14utf817count_code_pointsEPKcm:
    8|  5.56k|simdutf_really_inline size_t count_code_points(const char *in, size_t size) {
    9|  5.56k|  size_t pos = 0;
   10|  5.56k|  size_t count = 0;
   11|  8.19k|  for (; pos + 64 <= size; pos += 64) {
  ------------------
  |  Branch (11:10): [True: 2.63k, False: 5.56k]
  ------------------
   12|  2.63k|    simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
   13|  2.63k|    uint64_t utf8_continuation_mask = input.gt(-65);
   14|  2.63k|    count += count_ones(utf8_continuation_mask);
   15|  2.63k|  }
   16|  5.56k|  return count + scalar::utf8::count_code_points(in + pos, size - pos);
   17|  5.56k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14utf831utf16_length_from_utf8_bytemaskEPKcm:
    9|  22.0k|                                                             size_t size) {
   10|  22.0k|  using vector_i8 = simd8<int8_t>;
   11|  22.0k|  using vector_u8 = simd8<uint8_t>;
   12|  22.0k|  using vector_u64 = simd64<uint64_t>;
   13|       |
   14|  22.0k|  constexpr size_t N = vector_i8::SIZE;
   15|  22.0k|  constexpr size_t max_iterations = 255 / 2;
   16|       |
   17|  22.0k|  auto counters = vector_u64::zero();
   18|  22.0k|  auto local = vector_u8::zero();
   19|       |
   20|  22.0k|  size_t iterations = 0;
   21|  22.0k|  size_t pos = 0;
   22|  22.0k|  size_t count = 0;
   23|  33.5k|  for (; pos + N <= size; pos += N) {
  ------------------
  |  Branch (23:10): [True: 11.4k, False: 22.0k]
  ------------------
   24|  11.4k|    const auto input =
   25|  11.4k|        vector_i8::load(reinterpret_cast<const int8_t *>(in + pos));
   26|       |
   27|  11.4k|    const auto continuation = input > int8_t(-65);
   28|  11.4k|    const auto utf_4bytes = vector_u8(input.value) >= uint8_t(240);
   29|       |
   30|  11.4k|    local -= vector_u8(continuation);
   31|  11.4k|    local -= vector_u8(utf_4bytes);
   32|       |
   33|  11.4k|    iterations += 1;
   34|  11.4k|    if (iterations == max_iterations) {
  ------------------
  |  Branch (34:9): [True: 0, False: 11.4k]
  ------------------
   35|      0|      counters += sum_8bytes(local);
   36|      0|      local = vector_u8::zero();
   37|      0|      iterations = 0;
   38|      0|    }
   39|  11.4k|  }
   40|       |
   41|  22.0k|  if (iterations > 0) {
  ------------------
  |  Branch (41:7): [True: 1.73k, False: 20.3k]
  ------------------
   42|  1.73k|    count += local.sum_bytes();
   43|  1.73k|  }
   44|       |
   45|  22.0k|  count += counters.sum();
   46|       |
   47|  22.0k|  return count + scalar::utf8::utf16_length_from_utf8(in + pos, size - pos);
   48|  22.0k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14utf831utf16_length_from_utf8_bytemaskEPKcm:
    9|  22.0k|                                                             size_t size) {
   10|  22.0k|  using vector_i8 = simd8<int8_t>;
   11|  22.0k|  using vector_u8 = simd8<uint8_t>;
   12|  22.0k|  using vector_u64 = simd64<uint64_t>;
   13|       |
   14|  22.0k|  constexpr size_t N = vector_i8::SIZE;
   15|  22.0k|  constexpr size_t max_iterations = 255 / 2;
   16|       |
   17|  22.0k|  auto counters = vector_u64::zero();
   18|  22.0k|  auto local = vector_u8::zero();
   19|       |
   20|  22.0k|  size_t iterations = 0;
   21|  22.0k|  size_t pos = 0;
   22|  22.0k|  size_t count = 0;
   23|  56.7k|  for (; pos + N <= size; pos += N) {
  ------------------
  |  Branch (23:10): [True: 34.7k, False: 22.0k]
  ------------------
   24|  34.7k|    const auto input =
   25|  34.7k|        vector_i8::load(reinterpret_cast<const int8_t *>(in + pos));
   26|       |
   27|  34.7k|    const auto continuation = input > int8_t(-65);
   28|  34.7k|    const auto utf_4bytes = vector_u8(input.value) >= uint8_t(240);
   29|       |
   30|  34.7k|    local -= vector_u8(continuation);
   31|  34.7k|    local -= vector_u8(utf_4bytes);
   32|       |
   33|  34.7k|    iterations += 1;
   34|  34.7k|    if (iterations == max_iterations) {
  ------------------
  |  Branch (34:9): [True: 0, False: 34.7k]
  ------------------
   35|      0|      counters += sum_8bytes(local);
   36|      0|      local = vector_u8::zero();
   37|      0|      iterations = 0;
   38|      0|    }
   39|  34.7k|  }
   40|       |
   41|  22.0k|  if (iterations > 0) {
  ------------------
  |  Branch (41:7): [True: 1.99k, False: 20.0k]
  ------------------
   42|  1.99k|    count += local.sum_bytes();
   43|  1.99k|  }
   44|       |
   45|  22.0k|  count += counters.sum();
   46|       |
   47|  22.0k|  return count + scalar::utf8::utf16_length_from_utf8(in + pos, size - pos);
   48|  22.0k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoderC2Ev:
  101|  11.1k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoder7convertEPKcmPc:
  115|  11.1k|                                       char *latin1_output) {
  116|  11.1k|    size_t pos = 0;
  117|  11.1k|    char *start{latin1_output};
  118|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  119|       |    // of 8 bytes when calling convert_masked_utf8_to_latin1. If you skip the
  120|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  121|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  122|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  123|       |    // back from the end counting 16 leading bytes, to give us a good margin.
  124|  11.1k|    size_t leading_byte = 0;
  125|  11.1k|    size_t margin = size;
  126|  52.2k|    for (; margin > 0 && leading_byte < 16; margin--) {
  ------------------
  |  Branch (126:12): [True: 42.7k, False: 9.48k]
  |  Branch (126:26): [True: 41.1k, False: 1.63k]
  ------------------
  127|  41.1k|      leading_byte += (int8_t(in[margin - 1]) >
  128|  41.1k|                       -65); // twos complement of -65 is 1011 1111 ...
  129|  41.1k|    }
  130|       |    // If the input is long enough, then we have that margin-1 is the eight last
  131|       |    // leading byte.
  132|  11.1k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  133|  14.9k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (133:12): [True: 3.81k, False: 11.1k]
  ------------------
  134|  3.81k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  135|  3.81k|      if (input.is_ascii()) {
  ------------------
  |  Branch (135:11): [True: 1.66k, False: 2.15k]
  ------------------
  136|  1.66k|        input.store((int8_t *)latin1_output);
  137|  1.66k|        latin1_output += 64;
  138|  1.66k|        pos += 64;
  139|  2.15k|      } else {
  140|       |        // you might think that a for-loop would work, but under Visual Studio,
  141|       |        // it is not good enough.
  142|  2.15k|        static_assert(
  143|  2.15k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  144|  2.15k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  145|  2.15k|            "We support either two or four chunks per 64-byte block.");
  146|  2.15k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  147|  2.15k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  148|  2.15k|          this->check_utf8_bytes(input.chunks[0], zero);
  149|  2.15k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  150|       |        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  151|       |          this->check_utf8_bytes(input.chunks[0], zero);
  152|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  153|       |          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  154|       |          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  155|       |        }
  156|  2.15k|        uint64_t utf8_continuation_mask =
  157|  2.15k|            input.lt(-65 + 1); // -64 is 1100 0000 in twos complement. Note: in
  158|       |                               // this case, we also have ASCII to account for.
  159|  2.15k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (159:13): [True: 8, False: 2.14k]
  ------------------
  160|      8|          return 0; // error
  161|      8|        }
  162|  2.14k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  163|  2.14k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  164|       |        // We process in blocks of up to 12 bytes except possibly
  165|       |        // for fast paths which may process up to 16 bytes. For the
  166|       |        // slow path to work, we should have at least 12 input bytes left.
  167|  2.14k|        size_t max_starting_point = (pos + 64) - 12;
  168|       |        // Next loop is going to run at least five times.
  169|  17.7k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (169:16): [True: 15.5k, False: 2.14k]
  ------------------
  170|       |          // Performance note: our ability to compute 'consumed' and
  171|       |          // then shift and recompute is critical. If there is a
  172|       |          // latency of, say, 4 cycles on getting 'consumed', then
  173|       |          // the inner loop might have a total latency of about 6 cycles.
  174|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  175|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  176|       |          // for this section of the code. Hence, there is a limit
  177|       |          // to how much we can further increase this latency before
  178|       |          // it seriously harms performance.
  179|  15.5k|          size_t consumed = convert_masked_utf8_to_latin1(
  180|  15.5k|              in + pos, utf8_end_of_code_point_mask, latin1_output);
  181|  15.5k|          pos += consumed;
  182|  15.5k|          utf8_end_of_code_point_mask >>= consumed;
  183|  15.5k|        }
  184|       |        // At this point there may remain between 0 and 12 bytes in the
  185|       |        // 64-byte block. These bytes will be processed again. So we have an
  186|       |        // 80% efficiency (in the worst case). In practice we expect an
  187|       |        // 85% to 90% efficiency.
  188|  2.14k|      }
  189|  3.81k|    }
  190|  11.1k|    if (errors()) {
  ------------------
  |  Branch (190:9): [True: 156, False: 10.9k]
  ------------------
  191|    156|      return 0;
  192|    156|    }
  193|  10.9k|    if (pos < size) {
  ------------------
  |  Branch (193:9): [True: 2.46k, False: 8.49k]
  ------------------
  194|  2.46k|      size_t howmany =
  195|  2.46k|          scalar::utf8_to_latin1::convert(in + pos, size - pos, latin1_output);
  196|  2.46k|      if (howmany == 0) {
  ------------------
  |  Branch (196:11): [True: 1.02k, False: 1.44k]
  ------------------
  197|  1.02k|        return 0;
  198|  1.02k|      }
  199|  1.44k|      latin1_output += howmany;
  200|  1.44k|    }
  201|  9.93k|    return latin1_output - start;
  202|  10.9k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  106|  4.30k|                                              const simd8<uint8_t> prev_input) {
  107|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  108|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  109|       |    // small negative numbers)
  110|  4.30k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  111|  4.30k|    this->error |= check_special_cases(input, prev1);
  112|  4.30k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin119check_special_casesENS1_4simd5simd8IhEES5_:
    8|  4.30k|check_special_cases(const simd8<uint8_t> input, const simd8<uint8_t> prev1) {
    9|       |  // For UTF-8 to Latin 1, we can allow any ASCII character, and any
   10|       |  // continuation byte, but the non-ASCII leading bytes must be 0b11000011 or
   11|       |  // 0b11000010 and nothing else.
   12|       |  //
   13|       |  // Bit 0 = Too Short (lead byte/ASCII followed by lead byte/ASCII)
   14|       |  // Bit 1 = Too Long (ASCII followed by continuation)
   15|       |  // Bit 2 = Overlong 3-byte
   16|       |  // Bit 4 = Surrogate
   17|       |  // Bit 5 = Overlong 2-byte
   18|       |  // Bit 7 = Two Continuations
   19|  4.30k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   20|       |                                               // 11______ 11______
   21|  4.30k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   22|  4.30k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   23|  4.30k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   24|  4.30k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   25|  4.30k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   26|  4.30k|  constexpr const uint8_t TOO_LARGE = 1 << 3;  // 11110100 1001____
   27|       |                                               // 11110100 101_____
   28|       |                                               // 11110101 1001____
   29|       |                                               // 11110101 101_____
   30|       |                                               // 1111011_ 1001____
   31|       |                                               // 1111011_ 101_____
   32|       |                                               // 11111___ 1001____
   33|       |                                               // 11111___ 101_____
   34|  4.30k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   35|       |  // 11110101 1000____
   36|       |  // 1111011_ 1000____
   37|       |  // 11111___ 1000____
   38|  4.30k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   39|  4.30k|  constexpr const uint8_t FORBIDDEN = 0xff;
   40|       |
   41|  4.30k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   42|       |      // 0_______ ________ <ASCII in byte 1>
   43|  4.30k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   44|  4.30k|      TOO_LONG,
   45|       |      // 10______ ________ <continuation in byte 1>
   46|  4.30k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   47|       |      // 1100____ ________ <two byte lead in byte 1>
   48|  4.30k|      TOO_SHORT | OVERLONG_2,
   49|       |      // 1101____ ________ <two byte lead in byte 1>
   50|  4.30k|      FORBIDDEN,
   51|       |      // 1110____ ________ <three byte lead in byte 1>
   52|  4.30k|      FORBIDDEN,
   53|       |      // 1111____ ________ <four+ byte lead in byte 1>
   54|  4.30k|      FORBIDDEN);
   55|  4.30k|  constexpr const uint8_t CARRY =
   56|  4.30k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   57|  4.30k|  const simd8<uint8_t> byte_1_low =
   58|  4.30k|      (prev1 & 0x0F)
   59|  4.30k|          .lookup_16<uint8_t>(
   60|       |              // ____0000 ________
   61|  4.30k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   62|       |              // ____0001 ________
   63|  4.30k|              CARRY | OVERLONG_2,
   64|       |              // ____001_ ________
   65|  4.30k|              CARRY, CARRY,
   66|       |
   67|       |              // ____0100 ________
   68|  4.30k|              FORBIDDEN,
   69|       |              // ____0101 ________
   70|  4.30k|              FORBIDDEN,
   71|       |              // ____011_ ________
   72|  4.30k|              FORBIDDEN, FORBIDDEN,
   73|       |
   74|       |              // ____1___ ________
   75|  4.30k|              FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
   76|       |              // ____1101 ________
   77|  4.30k|              FORBIDDEN, FORBIDDEN, FORBIDDEN);
   78|  4.30k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   79|       |      // ________ 0_______ <ASCII in byte 2>
   80|  4.30k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   81|  4.30k|      TOO_SHORT, TOO_SHORT,
   82|       |
   83|       |      // ________ 1000____
   84|  4.30k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   85|  4.30k|          OVERLONG_4,
   86|       |      // ________ 1001____
   87|  4.30k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   88|       |      // ________ 101_____
   89|  4.30k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   90|  4.30k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   91|       |
   92|       |      // ________ 11______
   93|  4.30k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   94|  4.30k|  return (byte_1_high & byte_1_low & byte_2_high);
   95|  4.30k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoder6errorsEv:
  308|  11.1k|  simdutf_really_inline bool errors() const {
  309|  11.1k|    return this->error.any_bits_set_anywhere();
  310|  11.1k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoderC2Ev:
  101|  11.1k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoder7convertEPKcmPc:
  115|  11.1k|                                       char *latin1_output) {
  116|  11.1k|    size_t pos = 0;
  117|  11.1k|    char *start{latin1_output};
  118|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  119|       |    // of 8 bytes when calling convert_masked_utf8_to_latin1. If you skip the
  120|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  121|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  122|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  123|       |    // back from the end counting 16 leading bytes, to give us a good margin.
  124|  11.1k|    size_t leading_byte = 0;
  125|  11.1k|    size_t margin = size;
  126|  41.4k|    for (; margin > 0 && leading_byte < 16; margin--) {
  ------------------
  |  Branch (126:12): [True: 31.7k, False: 9.72k]
  |  Branch (126:26): [True: 30.3k, False: 1.39k]
  ------------------
  127|  30.3k|      leading_byte += (int8_t(in[margin - 1]) >
  128|  30.3k|                       -65); // twos complement of -65 is 1011 1111 ...
  129|  30.3k|    }
  130|       |    // If the input is long enough, then we have that margin-1 is the eight last
  131|       |    // leading byte.
  132|  11.1k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  133|  16.4k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (133:12): [True: 5.32k, False: 11.1k]
  ------------------
  134|  5.32k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  135|  5.32k|      if (input.is_ascii()) {
  ------------------
  |  Branch (135:11): [True: 2.08k, False: 3.24k]
  ------------------
  136|  2.08k|        input.store((int8_t *)latin1_output);
  137|  2.08k|        latin1_output += 64;
  138|  2.08k|        pos += 64;
  139|  3.24k|      } else {
  140|       |        // you might think that a for-loop would work, but under Visual Studio,
  141|       |        // it is not good enough.
  142|  3.24k|        static_assert(
  143|  3.24k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  144|  3.24k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  145|  3.24k|            "We support either two or four chunks per 64-byte block.");
  146|  3.24k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  147|       |        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  148|       |          this->check_utf8_bytes(input.chunks[0], zero);
  149|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  150|  3.24k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  151|  3.24k|          this->check_utf8_bytes(input.chunks[0], zero);
  152|  3.24k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  153|  3.24k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  154|  3.24k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  155|  3.24k|        }
  156|  3.24k|        uint64_t utf8_continuation_mask =
  157|  3.24k|            input.lt(-65 + 1); // -64 is 1100 0000 in twos complement. Note: in
  158|       |                               // this case, we also have ASCII to account for.
  159|  3.24k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (159:13): [True: 9, False: 3.23k]
  ------------------
  160|      9|          return 0; // error
  161|      9|        }
  162|  3.23k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  163|  3.23k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  164|       |        // We process in blocks of up to 12 bytes except possibly
  165|       |        // for fast paths which may process up to 16 bytes. For the
  166|       |        // slow path to work, we should have at least 12 input bytes left.
  167|  3.23k|        size_t max_starting_point = (pos + 64) - 12;
  168|       |        // Next loop is going to run at least five times.
  169|  26.9k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (169:16): [True: 23.7k, False: 3.23k]
  ------------------
  170|       |          // Performance note: our ability to compute 'consumed' and
  171|       |          // then shift and recompute is critical. If there is a
  172|       |          // latency of, say, 4 cycles on getting 'consumed', then
  173|       |          // the inner loop might have a total latency of about 6 cycles.
  174|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  175|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  176|       |          // for this section of the code. Hence, there is a limit
  177|       |          // to how much we can further increase this latency before
  178|       |          // it seriously harms performance.
  179|  23.7k|          size_t consumed = convert_masked_utf8_to_latin1(
  180|  23.7k|              in + pos, utf8_end_of_code_point_mask, latin1_output);
  181|  23.7k|          pos += consumed;
  182|  23.7k|          utf8_end_of_code_point_mask >>= consumed;
  183|  23.7k|        }
  184|       |        // At this point there may remain between 0 and 12 bytes in the
  185|       |        // 64-byte block. These bytes will be processed again. So we have an
  186|       |        // 80% efficiency (in the worst case). In practice we expect an
  187|       |        // 85% to 90% efficiency.
  188|  3.23k|      }
  189|  5.32k|    }
  190|  11.1k|    if (errors()) {
  ------------------
  |  Branch (190:9): [True: 215, False: 10.9k]
  ------------------
  191|    215|      return 0;
  192|    215|    }
  193|  10.9k|    if (pos < size) {
  ------------------
  |  Branch (193:9): [True: 1.72k, False: 9.17k]
  ------------------
  194|  1.72k|      size_t howmany =
  195|  1.72k|          scalar::utf8_to_latin1::convert(in + pos, size - pos, latin1_output);
  196|  1.72k|      if (howmany == 0) {
  ------------------
  |  Branch (196:11): [True: 641, False: 1.08k]
  ------------------
  197|    641|        return 0;
  198|    641|      }
  199|  1.08k|      latin1_output += howmany;
  200|  1.08k|    }
  201|  10.2k|    return latin1_output - start;
  202|  10.9k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  106|  12.9k|                                              const simd8<uint8_t> prev_input) {
  107|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  108|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  109|       |    // small negative numbers)
  110|  12.9k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  111|  12.9k|    this->error |= check_special_cases(input, prev1);
  112|  12.9k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin119check_special_casesENS1_4simd5simd8IhEES5_:
    8|  12.9k|check_special_cases(const simd8<uint8_t> input, const simd8<uint8_t> prev1) {
    9|       |  // For UTF-8 to Latin 1, we can allow any ASCII character, and any
   10|       |  // continuation byte, but the non-ASCII leading bytes must be 0b11000011 or
   11|       |  // 0b11000010 and nothing else.
   12|       |  //
   13|       |  // Bit 0 = Too Short (lead byte/ASCII followed by lead byte/ASCII)
   14|       |  // Bit 1 = Too Long (ASCII followed by continuation)
   15|       |  // Bit 2 = Overlong 3-byte
   16|       |  // Bit 4 = Surrogate
   17|       |  // Bit 5 = Overlong 2-byte
   18|       |  // Bit 7 = Two Continuations
   19|  12.9k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   20|       |                                               // 11______ 11______
   21|  12.9k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   22|  12.9k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   23|  12.9k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   24|  12.9k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   25|  12.9k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   26|  12.9k|  constexpr const uint8_t TOO_LARGE = 1 << 3;  // 11110100 1001____
   27|       |                                               // 11110100 101_____
   28|       |                                               // 11110101 1001____
   29|       |                                               // 11110101 101_____
   30|       |                                               // 1111011_ 1001____
   31|       |                                               // 1111011_ 101_____
   32|       |                                               // 11111___ 1001____
   33|       |                                               // 11111___ 101_____
   34|  12.9k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   35|       |  // 11110101 1000____
   36|       |  // 1111011_ 1000____
   37|       |  // 11111___ 1000____
   38|  12.9k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   39|  12.9k|  constexpr const uint8_t FORBIDDEN = 0xff;
   40|       |
   41|  12.9k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   42|       |      // 0_______ ________ <ASCII in byte 1>
   43|  12.9k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   44|  12.9k|      TOO_LONG,
   45|       |      // 10______ ________ <continuation in byte 1>
   46|  12.9k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   47|       |      // 1100____ ________ <two byte lead in byte 1>
   48|  12.9k|      TOO_SHORT | OVERLONG_2,
   49|       |      // 1101____ ________ <two byte lead in byte 1>
   50|  12.9k|      FORBIDDEN,
   51|       |      // 1110____ ________ <three byte lead in byte 1>
   52|  12.9k|      FORBIDDEN,
   53|       |      // 1111____ ________ <four+ byte lead in byte 1>
   54|  12.9k|      FORBIDDEN);
   55|  12.9k|  constexpr const uint8_t CARRY =
   56|  12.9k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   57|  12.9k|  const simd8<uint8_t> byte_1_low =
   58|  12.9k|      (prev1 & 0x0F)
   59|  12.9k|          .lookup_16<uint8_t>(
   60|       |              // ____0000 ________
   61|  12.9k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   62|       |              // ____0001 ________
   63|  12.9k|              CARRY | OVERLONG_2,
   64|       |              // ____001_ ________
   65|  12.9k|              CARRY, CARRY,
   66|       |
   67|       |              // ____0100 ________
   68|  12.9k|              FORBIDDEN,
   69|       |              // ____0101 ________
   70|  12.9k|              FORBIDDEN,
   71|       |              // ____011_ ________
   72|  12.9k|              FORBIDDEN, FORBIDDEN,
   73|       |
   74|       |              // ____1___ ________
   75|  12.9k|              FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
   76|       |              // ____1101 ________
   77|  12.9k|              FORBIDDEN, FORBIDDEN, FORBIDDEN);
   78|  12.9k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   79|       |      // ________ 0_______ <ASCII in byte 2>
   80|  12.9k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   81|  12.9k|      TOO_SHORT, TOO_SHORT,
   82|       |
   83|       |      // ________ 1000____
   84|  12.9k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   85|  12.9k|          OVERLONG_4,
   86|       |      // ________ 1001____
   87|  12.9k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   88|       |      // ________ 101_____
   89|  12.9k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   90|  12.9k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   91|       |
   92|       |      // ________ 11______
   93|  12.9k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   94|  12.9k|  return (byte_1_high & byte_1_low & byte_2_high);
   95|  12.9k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoder6errorsEv:
  308|  11.1k|  simdutf_really_inline bool errors() const {
  309|  11.1k|    return this->error.any_bits_set_anywhere();
  310|  11.1k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoderC2Ev:
  114|  22.0k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoderC2Ev:
  114|  22.0k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder7convertILNS_10endiannessE0EEEmPKcmPDs:
  130|  11.0k|                                       char16_t *utf16_output) {
  131|  11.0k|    size_t pos = 0;
  132|  11.0k|    char16_t *start{utf16_output};
  133|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  134|       |    // of 8 bytes when calling convert_masked_utf8_to_utf16. If you skip the
  135|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  136|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  137|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  138|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  139|  11.0k|    size_t leading_byte = 0;
  140|  11.0k|    size_t margin = size;
  141|  29.0k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (141:12): [True: 19.1k, False: 9.94k]
  |  Branch (141:26): [True: 18.0k, False: 1.08k]
  ------------------
  142|  18.0k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  143|  18.0k|    }
  144|       |    // If the input is long enough, then we have that margin-1 is the eight last
  145|       |    // leading byte.
  146|  11.0k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  147|  13.5k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (147:12): [True: 2.56k, False: 11.0k]
  ------------------
  148|  2.56k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  149|  2.56k|      if (input.is_ascii()) {
  ------------------
  |  Branch (149:11): [True: 599, False: 1.97k]
  ------------------
  150|    599|        input.store_ascii_as_utf16<endian>(utf16_output);
  151|    599|        utf16_output += 64;
  152|    599|        pos += 64;
  153|  1.97k|      } else {
  154|       |        // you might think that a for-loop would work, but under Visual Studio,
  155|       |        // it is not good enough.
  156|  1.97k|        static_assert(
  157|  1.97k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  158|  1.97k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  159|  1.97k|            "We support either two or four chunks per 64-byte block.");
  160|  1.97k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  161|  1.97k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  162|  1.97k|          this->check_utf8_bytes(input.chunks[0], zero);
  163|  1.97k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  164|       |        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  165|       |          this->check_utf8_bytes(input.chunks[0], zero);
  166|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  167|       |          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  168|       |          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  169|       |        }
  170|  1.97k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  171|  1.97k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (171:13): [True: 9, False: 1.96k]
  ------------------
  172|      9|          return 0; // error
  173|      9|        }
  174|  1.96k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  175|  1.96k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  176|       |        // We process in blocks of up to 12 bytes except possibly
  177|       |        // for fast paths which may process up to 16 bytes. For the
  178|       |        // slow path to work, we should have at least 12 input bytes left.
  179|  1.96k|        size_t max_starting_point = (pos + 64) - 12;
  180|       |        // Next loop is going to run at least five times.
  181|  16.2k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (181:16): [True: 14.3k, False: 1.96k]
  ------------------
  182|       |          // Performance note: our ability to compute 'consumed' and
  183|       |          // then shift and recompute is critical. If there is a
  184|       |          // latency of, say, 4 cycles on getting 'consumed', then
  185|       |          // the inner loop might have a total latency of about 6 cycles.
  186|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  187|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  188|       |          // for this section of the code. Hence, there is a limit
  189|       |          // to how much we can further increase this latency before
  190|       |          // it seriously harms performance.
  191|  14.3k|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  192|  14.3k|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  193|  14.3k|          pos += consumed;
  194|  14.3k|          utf8_end_of_code_point_mask >>= consumed;
  195|  14.3k|        }
  196|       |        // At this point there may remain between 0 and 12 bytes in the
  197|       |        // 64-byte block. These bytes will be processed again. So we have an
  198|       |        // 80% efficiency (in the worst case). In practice we expect an
  199|       |        // 85% to 90% efficiency.
  200|  1.96k|      }
  201|  2.56k|    }
  202|  11.0k|    if (errors()) {
  ------------------
  |  Branch (202:9): [True: 188, False: 10.8k]
  ------------------
  203|    188|      return 0;
  204|    188|    }
  205|  10.8k|    if (pos < size) {
  ------------------
  |  Branch (205:9): [True: 1.52k, False: 9.30k]
  ------------------
  206|  1.52k|      size_t howmany = scalar::utf8_to_utf16::convert<endian>(
  207|  1.52k|          in + pos, size - pos, utf16_output);
  208|  1.52k|      if (howmany == 0) {
  ------------------
  |  Branch (208:11): [True: 403, False: 1.12k]
  ------------------
  209|    403|        return 0;
  210|    403|      }
  211|  1.12k|      utf16_output += howmany;
  212|  1.12k|    }
  213|  10.4k|    return utf16_output - start;
  214|  10.8k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  119|  8.36k|                                              const simd8<uint8_t> prev_input) {
  120|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  121|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  122|       |    // small negative numbers)
  123|  8.36k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  124|  8.36k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  125|  8.36k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  126|  8.36k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1619check_special_casesENS1_4simd5simd8IhEES5_:
    8|  8.36k|check_special_cases(const simd8<uint8_t> input, const simd8<uint8_t> prev1) {
    9|       |  // Bit 0 = Too Short (lead byte/ASCII followed by lead byte/ASCII)
   10|       |  // Bit 1 = Too Long (ASCII followed by continuation)
   11|       |  // Bit 2 = Overlong 3-byte
   12|       |  // Bit 4 = Surrogate
   13|       |  // Bit 5 = Overlong 2-byte
   14|       |  // Bit 7 = Two Continuations
   15|  8.36k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   16|       |                                               // 11______ 11______
   17|  8.36k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   18|  8.36k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   19|  8.36k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   20|  8.36k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   21|  8.36k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   22|  8.36k|  constexpr const uint8_t TOO_LARGE = 1 << 3;  // 11110100 1001____
   23|       |                                               // 11110100 101_____
   24|       |                                               // 11110101 1001____
   25|       |                                               // 11110101 101_____
   26|       |                                               // 1111011_ 1001____
   27|       |                                               // 1111011_ 101_____
   28|       |                                               // 11111___ 1001____
   29|       |                                               // 11111___ 101_____
   30|  8.36k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   31|       |  // 11110101 1000____
   32|       |  // 1111011_ 1000____
   33|       |  // 11111___ 1000____
   34|  8.36k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   35|       |
   36|  8.36k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   37|       |      // 0_______ ________ <ASCII in byte 1>
   38|  8.36k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   39|  8.36k|      TOO_LONG,
   40|       |      // 10______ ________ <continuation in byte 1>
   41|  8.36k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   42|       |      // 1100____ ________ <two byte lead in byte 1>
   43|  8.36k|      TOO_SHORT | OVERLONG_2,
   44|       |      // 1101____ ________ <two byte lead in byte 1>
   45|  8.36k|      TOO_SHORT,
   46|       |      // 1110____ ________ <three byte lead in byte 1>
   47|  8.36k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   48|       |      // 1111____ ________ <four+ byte lead in byte 1>
   49|  8.36k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   50|  8.36k|  constexpr const uint8_t CARRY =
   51|  8.36k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   52|  8.36k|  const simd8<uint8_t> byte_1_low =
   53|  8.36k|      (prev1 & 0x0F)
   54|  8.36k|          .lookup_16<uint8_t>(
   55|       |              // ____0000 ________
   56|  8.36k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   57|       |              // ____0001 ________
   58|  8.36k|              CARRY | OVERLONG_2,
   59|       |              // ____001_ ________
   60|  8.36k|              CARRY, CARRY,
   61|       |
   62|       |              // ____0100 ________
   63|  8.36k|              CARRY | TOO_LARGE,
   64|       |              // ____0101 ________
   65|  8.36k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   66|       |              // ____011_ ________
   67|  8.36k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   68|  8.36k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|       |
   70|       |              // ____1___ ________
   71|  8.36k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   72|  8.36k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  8.36k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  8.36k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  8.36k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|       |              // ____1101 ________
   77|  8.36k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   78|  8.36k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   79|  8.36k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   80|  8.36k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   81|       |      // ________ 0_______ <ASCII in byte 2>
   82|  8.36k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   83|  8.36k|      TOO_SHORT, TOO_SHORT,
   84|       |
   85|       |      // ________ 1000____
   86|  8.36k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   87|  8.36k|          OVERLONG_4,
   88|       |      // ________ 1001____
   89|  8.36k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   90|       |      // ________ 101_____
   91|  8.36k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   92|  8.36k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|       |
   94|       |      // ________ 11______
   95|  8.36k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   96|  8.36k|  return (byte_1_high & byte_1_low & byte_2_high);
   97|  8.36k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1623check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  101|  8.36k|                        const simd8<uint8_t> sc) {
  102|  8.36k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  103|  8.36k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  104|  8.36k|  simd8<uint8_t> must23 =
  105|  8.36k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  106|  8.36k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  107|  8.36k|  return must23_80 ^ sc;
  108|  8.36k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder6errorsEv:
  324|  22.0k|  simdutf_really_inline bool errors() const {
  325|  22.0k|    return this->error.any_bits_set_anywhere();
  326|  22.0k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder7convertILNS_10endiannessE1EEEmPKcmPDs:
  130|  11.0k|                                       char16_t *utf16_output) {
  131|  11.0k|    size_t pos = 0;
  132|  11.0k|    char16_t *start{utf16_output};
  133|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  134|       |    // of 8 bytes when calling convert_masked_utf8_to_utf16. If you skip the
  135|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  136|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  137|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  138|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  139|  11.0k|    size_t leading_byte = 0;
  140|  11.0k|    size_t margin = size;
  141|  29.5k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (141:12): [True: 19.6k, False: 9.93k]
  |  Branch (141:26): [True: 18.5k, False: 1.10k]
  ------------------
  142|  18.5k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  143|  18.5k|    }
  144|       |    // If the input is long enough, then we have that margin-1 is the eight last
  145|       |    // leading byte.
  146|  11.0k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  147|  13.8k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (147:12): [True: 2.81k, False: 11.0k]
  ------------------
  148|  2.81k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  149|  2.81k|      if (input.is_ascii()) {
  ------------------
  |  Branch (149:11): [True: 598, False: 2.21k]
  ------------------
  150|    598|        input.store_ascii_as_utf16<endian>(utf16_output);
  151|    598|        utf16_output += 64;
  152|    598|        pos += 64;
  153|  2.21k|      } else {
  154|       |        // you might think that a for-loop would work, but under Visual Studio,
  155|       |        // it is not good enough.
  156|  2.21k|        static_assert(
  157|  2.21k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  158|  2.21k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  159|  2.21k|            "We support either two or four chunks per 64-byte block.");
  160|  2.21k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  161|  2.21k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  162|  2.21k|          this->check_utf8_bytes(input.chunks[0], zero);
  163|  2.21k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  164|       |        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  165|       |          this->check_utf8_bytes(input.chunks[0], zero);
  166|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  167|       |          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  168|       |          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  169|       |        }
  170|  2.21k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  171|  2.21k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (171:13): [True: 9, False: 2.20k]
  ------------------
  172|      9|          return 0; // error
  173|      9|        }
  174|  2.20k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  175|  2.20k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  176|       |        // We process in blocks of up to 12 bytes except possibly
  177|       |        // for fast paths which may process up to 16 bytes. For the
  178|       |        // slow path to work, we should have at least 12 input bytes left.
  179|  2.20k|        size_t max_starting_point = (pos + 64) - 12;
  180|       |        // Next loop is going to run at least five times.
  181|  17.8k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (181:16): [True: 15.6k, False: 2.20k]
  ------------------
  182|       |          // Performance note: our ability to compute 'consumed' and
  183|       |          // then shift and recompute is critical. If there is a
  184|       |          // latency of, say, 4 cycles on getting 'consumed', then
  185|       |          // the inner loop might have a total latency of about 6 cycles.
  186|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  187|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  188|       |          // for this section of the code. Hence, there is a limit
  189|       |          // to how much we can further increase this latency before
  190|       |          // it seriously harms performance.
  191|  15.6k|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  192|  15.6k|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  193|  15.6k|          pos += consumed;
  194|  15.6k|          utf8_end_of_code_point_mask >>= consumed;
  195|  15.6k|        }
  196|       |        // At this point there may remain between 0 and 12 bytes in the
  197|       |        // 64-byte block. These bytes will be processed again. So we have an
  198|       |        // 80% efficiency (in the worst case). In practice we expect an
  199|       |        // 85% to 90% efficiency.
  200|  2.20k|      }
  201|  2.81k|    }
  202|  11.0k|    if (errors()) {
  ------------------
  |  Branch (202:9): [True: 188, False: 10.8k]
  ------------------
  203|    188|      return 0;
  204|    188|    }
  205|  10.8k|    if (pos < size) {
  ------------------
  |  Branch (205:9): [True: 1.54k, False: 9.30k]
  ------------------
  206|  1.54k|      size_t howmany = scalar::utf8_to_utf16::convert<endian>(
  207|  1.54k|          in + pos, size - pos, utf16_output);
  208|  1.54k|      if (howmany == 0) {
  ------------------
  |  Branch (208:11): [True: 403, False: 1.14k]
  ------------------
  209|    403|        return 0;
  210|    403|      }
  211|  1.14k|      utf16_output += howmany;
  212|  1.14k|    }
  213|  10.4k|    return utf16_output - start;
  214|  10.8k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder7convertILNS_10endiannessE0EEEmPKcmPDs:
  130|  11.0k|                                       char16_t *utf16_output) {
  131|  11.0k|    size_t pos = 0;
  132|  11.0k|    char16_t *start{utf16_output};
  133|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  134|       |    // of 8 bytes when calling convert_masked_utf8_to_utf16. If you skip the
  135|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  136|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  137|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  138|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  139|  11.0k|    size_t leading_byte = 0;
  140|  11.0k|    size_t margin = size;
  141|  24.3k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (141:12): [True: 14.2k, False: 10.0k]
  |  Branch (141:26): [True: 13.3k, False: 998]
  ------------------
  142|  13.3k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  143|  13.3k|    }
  144|       |    // If the input is long enough, then we have that margin-1 is the eight last
  145|       |    // leading byte.
  146|  11.0k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  147|  15.1k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (147:12): [True: 4.10k, False: 11.0k]
  ------------------
  148|  4.10k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  149|  4.10k|      if (input.is_ascii()) {
  ------------------
  |  Branch (149:11): [True: 974, False: 3.12k]
  ------------------
  150|    974|        input.store_ascii_as_utf16<endian>(utf16_output);
  151|    974|        utf16_output += 64;
  152|    974|        pos += 64;
  153|  3.12k|      } else {
  154|       |        // you might think that a for-loop would work, but under Visual Studio,
  155|       |        // it is not good enough.
  156|  3.12k|        static_assert(
  157|  3.12k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  158|  3.12k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  159|  3.12k|            "We support either two or four chunks per 64-byte block.");
  160|  3.12k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  161|       |        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  162|       |          this->check_utf8_bytes(input.chunks[0], zero);
  163|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  164|  3.12k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  165|  3.12k|          this->check_utf8_bytes(input.chunks[0], zero);
  166|  3.12k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  167|  3.12k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  168|  3.12k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  169|  3.12k|        }
  170|  3.12k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  171|  3.12k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (171:13): [True: 10, False: 3.11k]
  ------------------
  172|     10|          return 0; // error
  173|     10|        }
  174|  3.11k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  175|  3.11k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  176|       |        // We process in blocks of up to 12 bytes except possibly
  177|       |        // for fast paths which may process up to 16 bytes. For the
  178|       |        // slow path to work, we should have at least 12 input bytes left.
  179|  3.11k|        size_t max_starting_point = (pos + 64) - 12;
  180|       |        // Next loop is going to run at least five times.
  181|  25.0k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (181:16): [True: 21.9k, False: 3.11k]
  ------------------
  182|       |          // Performance note: our ability to compute 'consumed' and
  183|       |          // then shift and recompute is critical. If there is a
  184|       |          // latency of, say, 4 cycles on getting 'consumed', then
  185|       |          // the inner loop might have a total latency of about 6 cycles.
  186|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  187|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  188|       |          // for this section of the code. Hence, there is a limit
  189|       |          // to how much we can further increase this latency before
  190|       |          // it seriously harms performance.
  191|  21.9k|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  192|  21.9k|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  193|  21.9k|          pos += consumed;
  194|  21.9k|          utf8_end_of_code_point_mask >>= consumed;
  195|  21.9k|        }
  196|       |        // At this point there may remain between 0 and 12 bytes in the
  197|       |        // 64-byte block. These bytes will be processed again. So we have an
  198|       |        // 80% efficiency (in the worst case). In practice we expect an
  199|       |        // 85% to 90% efficiency.
  200|  3.11k|      }
  201|  4.10k|    }
  202|  11.0k|    if (errors()) {
  ------------------
  |  Branch (202:9): [True: 213, False: 10.7k]
  ------------------
  203|    213|      return 0;
  204|    213|    }
  205|  10.7k|    if (pos < size) {
  ------------------
  |  Branch (205:9): [True: 1.18k, False: 9.61k]
  ------------------
  206|  1.18k|      size_t howmany = scalar::utf8_to_utf16::convert<endian>(
  207|  1.18k|          in + pos, size - pos, utf16_output);
  208|  1.18k|      if (howmany == 0) {
  ------------------
  |  Branch (208:11): [True: 197, False: 987]
  ------------------
  209|    197|        return 0;
  210|    197|      }
  211|    987|      utf16_output += howmany;
  212|    987|    }
  213|  10.6k|    return utf16_output - start;
  214|  10.7k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  119|  25.6k|                                              const simd8<uint8_t> prev_input) {
  120|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  121|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  122|       |    // small negative numbers)
  123|  25.6k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  124|  25.6k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  125|  25.6k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  126|  25.6k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1619check_special_casesENS1_4simd5simd8IhEES5_:
    8|  25.6k|check_special_cases(const simd8<uint8_t> input, const simd8<uint8_t> prev1) {
    9|       |  // Bit 0 = Too Short (lead byte/ASCII followed by lead byte/ASCII)
   10|       |  // Bit 1 = Too Long (ASCII followed by continuation)
   11|       |  // Bit 2 = Overlong 3-byte
   12|       |  // Bit 4 = Surrogate
   13|       |  // Bit 5 = Overlong 2-byte
   14|       |  // Bit 7 = Two Continuations
   15|  25.6k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   16|       |                                               // 11______ 11______
   17|  25.6k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   18|  25.6k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   19|  25.6k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   20|  25.6k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   21|  25.6k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   22|  25.6k|  constexpr const uint8_t TOO_LARGE = 1 << 3;  // 11110100 1001____
   23|       |                                               // 11110100 101_____
   24|       |                                               // 11110101 1001____
   25|       |                                               // 11110101 101_____
   26|       |                                               // 1111011_ 1001____
   27|       |                                               // 1111011_ 101_____
   28|       |                                               // 11111___ 1001____
   29|       |                                               // 11111___ 101_____
   30|  25.6k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   31|       |  // 11110101 1000____
   32|       |  // 1111011_ 1000____
   33|       |  // 11111___ 1000____
   34|  25.6k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   35|       |
   36|  25.6k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   37|       |      // 0_______ ________ <ASCII in byte 1>
   38|  25.6k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   39|  25.6k|      TOO_LONG,
   40|       |      // 10______ ________ <continuation in byte 1>
   41|  25.6k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   42|       |      // 1100____ ________ <two byte lead in byte 1>
   43|  25.6k|      TOO_SHORT | OVERLONG_2,
   44|       |      // 1101____ ________ <two byte lead in byte 1>
   45|  25.6k|      TOO_SHORT,
   46|       |      // 1110____ ________ <three byte lead in byte 1>
   47|  25.6k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   48|       |      // 1111____ ________ <four+ byte lead in byte 1>
   49|  25.6k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   50|  25.6k|  constexpr const uint8_t CARRY =
   51|  25.6k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   52|  25.6k|  const simd8<uint8_t> byte_1_low =
   53|  25.6k|      (prev1 & 0x0F)
   54|  25.6k|          .lookup_16<uint8_t>(
   55|       |              // ____0000 ________
   56|  25.6k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   57|       |              // ____0001 ________
   58|  25.6k|              CARRY | OVERLONG_2,
   59|       |              // ____001_ ________
   60|  25.6k|              CARRY, CARRY,
   61|       |
   62|       |              // ____0100 ________
   63|  25.6k|              CARRY | TOO_LARGE,
   64|       |              // ____0101 ________
   65|  25.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   66|       |              // ____011_ ________
   67|  25.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   68|  25.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|       |
   70|       |              // ____1___ ________
   71|  25.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   72|  25.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  25.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  25.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  25.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|       |              // ____1101 ________
   77|  25.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   78|  25.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   79|  25.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   80|  25.6k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   81|       |      // ________ 0_______ <ASCII in byte 2>
   82|  25.6k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   83|  25.6k|      TOO_SHORT, TOO_SHORT,
   84|       |
   85|       |      // ________ 1000____
   86|  25.6k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   87|  25.6k|          OVERLONG_4,
   88|       |      // ________ 1001____
   89|  25.6k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   90|       |      // ________ 101_____
   91|  25.6k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   92|  25.6k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|       |
   94|       |      // ________ 11______
   95|  25.6k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   96|  25.6k|  return (byte_1_high & byte_1_low & byte_2_high);
   97|  25.6k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1623check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  101|  25.6k|                        const simd8<uint8_t> sc) {
  102|  25.6k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  103|  25.6k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  104|  25.6k|  simd8<uint8_t> must23 =
  105|  25.6k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  106|  25.6k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  107|  25.6k|  return must23_80 ^ sc;
  108|  25.6k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder6errorsEv:
  324|  22.0k|  simdutf_really_inline bool errors() const {
  325|  22.0k|    return this->error.any_bits_set_anywhere();
  326|  22.0k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder7convertILNS_10endiannessE1EEEmPKcmPDs:
  130|  11.0k|                                       char16_t *utf16_output) {
  131|  11.0k|    size_t pos = 0;
  132|  11.0k|    char16_t *start{utf16_output};
  133|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  134|       |    // of 8 bytes when calling convert_masked_utf8_to_utf16. If you skip the
  135|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  136|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  137|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  138|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  139|  11.0k|    size_t leading_byte = 0;
  140|  11.0k|    size_t margin = size;
  141|  24.3k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (141:12): [True: 14.3k, False: 10.0k]
  |  Branch (141:26): [True: 13.3k, False: 995]
  ------------------
  142|  13.3k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  143|  13.3k|    }
  144|       |    // If the input is long enough, then we have that margin-1 is the eight last
  145|       |    // leading byte.
  146|  11.0k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  147|  15.2k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (147:12): [True: 4.24k, False: 11.0k]
  ------------------
  148|  4.24k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  149|  4.24k|      if (input.is_ascii()) {
  ------------------
  |  Branch (149:11): [True: 973, False: 3.27k]
  ------------------
  150|    973|        input.store_ascii_as_utf16<endian>(utf16_output);
  151|    973|        utf16_output += 64;
  152|    973|        pos += 64;
  153|  3.27k|      } else {
  154|       |        // you might think that a for-loop would work, but under Visual Studio,
  155|       |        // it is not good enough.
  156|  3.27k|        static_assert(
  157|  3.27k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  158|  3.27k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  159|  3.27k|            "We support either two or four chunks per 64-byte block.");
  160|  3.27k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  161|       |        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  162|       |          this->check_utf8_bytes(input.chunks[0], zero);
  163|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  164|  3.27k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  165|  3.27k|          this->check_utf8_bytes(input.chunks[0], zero);
  166|  3.27k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  167|  3.27k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  168|  3.27k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  169|  3.27k|        }
  170|  3.27k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  171|  3.27k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (171:13): [True: 10, False: 3.26k]
  ------------------
  172|     10|          return 0; // error
  173|     10|        }
  174|  3.26k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  175|  3.26k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  176|       |        // We process in blocks of up to 12 bytes except possibly
  177|       |        // for fast paths which may process up to 16 bytes. For the
  178|       |        // slow path to work, we should have at least 12 input bytes left.
  179|  3.26k|        size_t max_starting_point = (pos + 64) - 12;
  180|       |        // Next loop is going to run at least five times.
  181|  25.8k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (181:16): [True: 22.6k, False: 3.26k]
  ------------------
  182|       |          // Performance note: our ability to compute 'consumed' and
  183|       |          // then shift and recompute is critical. If there is a
  184|       |          // latency of, say, 4 cycles on getting 'consumed', then
  185|       |          // the inner loop might have a total latency of about 6 cycles.
  186|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  187|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  188|       |          // for this section of the code. Hence, there is a limit
  189|       |          // to how much we can further increase this latency before
  190|       |          // it seriously harms performance.
  191|  22.6k|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  192|  22.6k|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  193|  22.6k|          pos += consumed;
  194|  22.6k|          utf8_end_of_code_point_mask >>= consumed;
  195|  22.6k|        }
  196|       |        // At this point there may remain between 0 and 12 bytes in the
  197|       |        // 64-byte block. These bytes will be processed again. So we have an
  198|       |        // 80% efficiency (in the worst case). In practice we expect an
  199|       |        // 85% to 90% efficiency.
  200|  3.26k|      }
  201|  4.24k|    }
  202|  11.0k|    if (errors()) {
  ------------------
  |  Branch (202:9): [True: 213, False: 10.8k]
  ------------------
  203|    213|      return 0;
  204|    213|    }
  205|  10.8k|    if (pos < size) {
  ------------------
  |  Branch (205:9): [True: 1.17k, False: 9.63k]
  ------------------
  206|  1.17k|      size_t howmany = scalar::utf8_to_utf16::convert<endian>(
  207|  1.17k|          in + pos, size - pos, utf16_output);
  208|  1.17k|      if (howmany == 0) {
  ------------------
  |  Branch (208:11): [True: 197, False: 980]
  ------------------
  209|    197|        return 0;
  210|    197|      }
  211|    980|      utf16_output += howmany;
  212|    980|    }
  213|  10.6k|    return utf16_output - start;
  214|  10.8k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoderC2Ev:
  114|  5.56k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoder7convertEPKcmPDi:
  129|  5.56k|                                       char32_t *utf32_output) {
  130|  5.56k|    size_t pos = 0;
  131|  5.56k|    char32_t *start{utf32_output};
  132|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  133|       |    // of 8 words when calling convert_masked_utf8_to_utf32. If you skip the
  134|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  135|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  136|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  137|       |    // back from the end counting 16 leading bytes, to give us a good margin.
  138|  5.56k|    size_t leading_byte = 0;
  139|  5.56k|    size_t margin = size;
  140|  18.9k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (140:12): [True: 14.2k, False: 4.65k]
  |  Branch (140:26): [True: 13.3k, False: 903]
  ------------------
  141|  13.3k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  142|  13.3k|    }
  143|       |    // If the input is long enough, then we have that margin-1 is the fourth
  144|       |    // last leading byte.
  145|  5.56k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  146|  7.22k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (146:12): [True: 1.67k, False: 5.55k]
  ------------------
  147|  1.67k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  148|  1.67k|      if (input.is_ascii()) {
  ------------------
  |  Branch (148:11): [True: 583, False: 1.09k]
  ------------------
  149|    583|        input.store_ascii_as_utf32(utf32_output);
  150|    583|        utf32_output += 64;
  151|    583|        pos += 64;
  152|  1.09k|      } else {
  153|       |        // you might think that a for-loop would work, but under Visual Studio,
  154|       |        // it is not good enough.
  155|  1.09k|        static_assert(
  156|  1.09k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  157|  1.09k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  158|  1.09k|            "We support either two or four chunks per 64-byte block.");
  159|  1.09k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  160|  1.09k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  161|  1.09k|          this->check_utf8_bytes(input.chunks[0], zero);
  162|  1.09k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  163|       |        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  164|       |          this->check_utf8_bytes(input.chunks[0], zero);
  165|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  166|       |          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  167|       |          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  168|       |        }
  169|  1.09k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  170|  1.09k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (170:13): [True: 9, False: 1.08k]
  ------------------
  171|      9|          return 0; // we have an error
  172|      9|        }
  173|  1.08k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  174|  1.08k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  175|       |        // We process in blocks of up to 12 bytes except possibly
  176|       |        // for fast paths which may process up to 16 bytes. For the
  177|       |        // slow path to work, we should have at least 12 input bytes left.
  178|  1.08k|        size_t max_starting_point = (pos + 64) - 12;
  179|       |        // Next loop is going to run at least five times.
  180|  10.8k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (180:16): [True: 9.80k, False: 1.08k]
  ------------------
  181|       |          // Performance note: our ability to compute 'consumed' and
  182|       |          // then shift and recompute is critical. If there is a
  183|       |          // latency of, say, 4 cycles on getting 'consumed', then
  184|       |          // the inner loop might have a total latency of about 6 cycles.
  185|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  186|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  187|       |          // for this section of the code. Hence, there is a limit
  188|       |          // to how much we can further increase this latency before
  189|       |          // it seriously harms performance.
  190|  9.80k|          size_t consumed = convert_masked_utf8_to_utf32(
  191|  9.80k|              in + pos, utf8_end_of_code_point_mask, utf32_output);
  192|  9.80k|          pos += consumed;
  193|  9.80k|          utf8_end_of_code_point_mask >>= consumed;
  194|  9.80k|        }
  195|       |        // At this point there may remain between 0 and 12 bytes in the
  196|       |        // 64-byte block. These bytes will be processed again. So we have an
  197|       |        // 80% efficiency (in the worst case). In practice we expect an
  198|       |        // 85% to 90% efficiency.
  199|  1.08k|      }
  200|  1.67k|    }
  201|  5.55k|    if (errors()) {
  ------------------
  |  Branch (201:9): [True: 188, False: 5.36k]
  ------------------
  202|    188|      return 0;
  203|    188|    }
  204|  5.36k|    if (pos < size) {
  ------------------
  |  Branch (204:9): [True: 1.26k, False: 4.10k]
  ------------------
  205|  1.26k|      size_t howmany =
  206|  1.26k|          scalar::utf8_to_utf32::convert(in + pos, size - pos, utf32_output);
  207|  1.26k|      if (howmany == 0) {
  ------------------
  |  Branch (207:11): [True: 403, False: 861]
  ------------------
  208|    403|        return 0;
  209|    403|      }
  210|    861|      utf32_output += howmany;
  211|    861|    }
  212|  4.96k|    return utf32_output - start;
  213|  5.36k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  119|  2.18k|                                              const simd8<uint8_t> prev_input) {
  120|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  121|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  122|       |    // small negative numbers)
  123|  2.18k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  124|  2.18k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  125|  2.18k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  126|  2.18k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3219check_special_casesENS1_4simd5simd8IhEES5_:
    8|  2.18k|check_special_cases(const simd8<uint8_t> input, const simd8<uint8_t> prev1) {
    9|       |  // Bit 0 = Too Short (lead byte/ASCII followed by lead byte/ASCII)
   10|       |  // Bit 1 = Too Long (ASCII followed by continuation)
   11|       |  // Bit 2 = Overlong 3-byte
   12|       |  // Bit 4 = Surrogate
   13|       |  // Bit 5 = Overlong 2-byte
   14|       |  // Bit 7 = Two Continuations
   15|  2.18k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   16|       |                                               // 11______ 11______
   17|  2.18k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   18|  2.18k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   19|  2.18k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   20|  2.18k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   21|  2.18k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   22|  2.18k|  constexpr const uint8_t TOO_LARGE = 1 << 3;  // 11110100 1001____
   23|       |                                               // 11110100 101_____
   24|       |                                               // 11110101 1001____
   25|       |                                               // 11110101 101_____
   26|       |                                               // 1111011_ 1001____
   27|       |                                               // 1111011_ 101_____
   28|       |                                               // 11111___ 1001____
   29|       |                                               // 11111___ 101_____
   30|  2.18k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   31|       |  // 11110101 1000____
   32|       |  // 1111011_ 1000____
   33|       |  // 11111___ 1000____
   34|  2.18k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   35|       |
   36|  2.18k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   37|       |      // 0_______ ________ <ASCII in byte 1>
   38|  2.18k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   39|  2.18k|      TOO_LONG,
   40|       |      // 10______ ________ <continuation in byte 1>
   41|  2.18k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   42|       |      // 1100____ ________ <two byte lead in byte 1>
   43|  2.18k|      TOO_SHORT | OVERLONG_2,
   44|       |      // 1101____ ________ <two byte lead in byte 1>
   45|  2.18k|      TOO_SHORT,
   46|       |      // 1110____ ________ <three byte lead in byte 1>
   47|  2.18k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   48|       |      // 1111____ ________ <four+ byte lead in byte 1>
   49|  2.18k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   50|  2.18k|  constexpr const uint8_t CARRY =
   51|  2.18k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   52|  2.18k|  const simd8<uint8_t> byte_1_low =
   53|  2.18k|      (prev1 & 0x0F)
   54|  2.18k|          .lookup_16<uint8_t>(
   55|       |              // ____0000 ________
   56|  2.18k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   57|       |              // ____0001 ________
   58|  2.18k|              CARRY | OVERLONG_2,
   59|       |              // ____001_ ________
   60|  2.18k|              CARRY, CARRY,
   61|       |
   62|       |              // ____0100 ________
   63|  2.18k|              CARRY | TOO_LARGE,
   64|       |              // ____0101 ________
   65|  2.18k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   66|       |              // ____011_ ________
   67|  2.18k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   68|  2.18k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|       |
   70|       |              // ____1___ ________
   71|  2.18k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   72|  2.18k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  2.18k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  2.18k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  2.18k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|       |              // ____1101 ________
   77|  2.18k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   78|  2.18k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   79|  2.18k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   80|  2.18k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   81|       |      // ________ 0_______ <ASCII in byte 2>
   82|  2.18k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   83|  2.18k|      TOO_SHORT, TOO_SHORT,
   84|       |
   85|       |      // ________ 1000____
   86|  2.18k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   87|  2.18k|          OVERLONG_4,
   88|       |      // ________ 1001____
   89|  2.18k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   90|       |      // ________ 101_____
   91|  2.18k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   92|  2.18k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|       |
   94|       |      // ________ 11______
   95|  2.18k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   96|  2.18k|  return (byte_1_high & byte_1_low & byte_2_high);
   97|  2.18k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3223check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  101|  2.18k|                        const simd8<uint8_t> sc) {
  102|  2.18k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  103|  2.18k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  104|  2.18k|  simd8<uint8_t> must23 =
  105|  2.18k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  106|  2.18k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  107|  2.18k|  return must23_80 ^ sc;
  108|  2.18k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoder6errorsEv:
  310|  5.55k|  simdutf_really_inline bool errors() const {
  311|  5.55k|    return this->error.any_bits_set_anywhere();
  312|  5.55k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoderC2Ev:
  114|  5.56k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoder7convertEPKcmPDi:
  129|  5.56k|                                       char32_t *utf32_output) {
  130|  5.56k|    size_t pos = 0;
  131|  5.56k|    char32_t *start{utf32_output};
  132|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  133|       |    // of 8 words when calling convert_masked_utf8_to_utf32. If you skip the
  134|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  135|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  136|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  137|       |    // back from the end counting 16 leading bytes, to give us a good margin.
  138|  5.56k|    size_t leading_byte = 0;
  139|  5.56k|    size_t margin = size;
  140|  14.4k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (140:12): [True: 9.71k, False: 4.75k]
  |  Branch (140:26): [True: 8.90k, False: 811]
  ------------------
  141|  8.90k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  142|  8.90k|    }
  143|       |    // If the input is long enough, then we have that margin-1 is the fourth
  144|       |    // last leading byte.
  145|  5.56k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  146|  8.26k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (146:12): [True: 2.71k, False: 5.55k]
  ------------------
  147|  2.71k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  148|  2.71k|      if (input.is_ascii()) {
  ------------------
  |  Branch (148:11): [True: 944, False: 1.76k]
  ------------------
  149|    944|        input.store_ascii_as_utf32(utf32_output);
  150|    944|        utf32_output += 64;
  151|    944|        pos += 64;
  152|  1.76k|      } else {
  153|       |        // you might think that a for-loop would work, but under Visual Studio,
  154|       |        // it is not good enough.
  155|  1.76k|        static_assert(
  156|  1.76k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  157|  1.76k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  158|  1.76k|            "We support either two or four chunks per 64-byte block.");
  159|  1.76k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  160|       |        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  161|       |          this->check_utf8_bytes(input.chunks[0], zero);
  162|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  163|  1.76k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  164|  1.76k|          this->check_utf8_bytes(input.chunks[0], zero);
  165|  1.76k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  166|  1.76k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  167|  1.76k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  168|  1.76k|        }
  169|  1.76k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  170|  1.76k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (170:13): [True: 10, False: 1.75k]
  ------------------
  171|     10|          return 0; // we have an error
  172|     10|        }
  173|  1.75k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  174|  1.75k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  175|       |        // We process in blocks of up to 12 bytes except possibly
  176|       |        // for fast paths which may process up to 16 bytes. For the
  177|       |        // slow path to work, we should have at least 12 input bytes left.
  178|  1.75k|        size_t max_starting_point = (pos + 64) - 12;
  179|       |        // Next loop is going to run at least five times.
  180|  16.6k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (180:16): [True: 14.9k, False: 1.75k]
  ------------------
  181|       |          // Performance note: our ability to compute 'consumed' and
  182|       |          // then shift and recompute is critical. If there is a
  183|       |          // latency of, say, 4 cycles on getting 'consumed', then
  184|       |          // the inner loop might have a total latency of about 6 cycles.
  185|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  186|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  187|       |          // for this section of the code. Hence, there is a limit
  188|       |          // to how much we can further increase this latency before
  189|       |          // it seriously harms performance.
  190|  14.9k|          size_t consumed = convert_masked_utf8_to_utf32(
  191|  14.9k|              in + pos, utf8_end_of_code_point_mask, utf32_output);
  192|  14.9k|          pos += consumed;
  193|  14.9k|          utf8_end_of_code_point_mask >>= consumed;
  194|  14.9k|        }
  195|       |        // At this point there may remain between 0 and 12 bytes in the
  196|       |        // 64-byte block. These bytes will be processed again. So we have an
  197|       |        // 80% efficiency (in the worst case). In practice we expect an
  198|       |        // 85% to 90% efficiency.
  199|  1.75k|      }
  200|  2.71k|    }
  201|  5.55k|    if (errors()) {
  ------------------
  |  Branch (201:9): [True: 213, False: 5.33k]
  ------------------
  202|    213|      return 0;
  203|    213|    }
  204|  5.33k|    if (pos < size) {
  ------------------
  |  Branch (204:9): [True: 940, False: 4.39k]
  ------------------
  205|    940|      size_t howmany =
  206|    940|          scalar::utf8_to_utf32::convert(in + pos, size - pos, utf32_output);
  207|    940|      if (howmany == 0) {
  ------------------
  |  Branch (207:11): [True: 197, False: 743]
  ------------------
  208|    197|        return 0;
  209|    197|      }
  210|    743|      utf32_output += howmany;
  211|    743|    }
  212|  5.14k|    return utf32_output - start;
  213|  5.33k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  119|  7.06k|                                              const simd8<uint8_t> prev_input) {
  120|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  121|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  122|       |    // small negative numbers)
  123|  7.06k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  124|  7.06k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  125|  7.06k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  126|  7.06k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3219check_special_casesENS1_4simd5simd8IhEES5_:
    8|  7.06k|check_special_cases(const simd8<uint8_t> input, const simd8<uint8_t> prev1) {
    9|       |  // Bit 0 = Too Short (lead byte/ASCII followed by lead byte/ASCII)
   10|       |  // Bit 1 = Too Long (ASCII followed by continuation)
   11|       |  // Bit 2 = Overlong 3-byte
   12|       |  // Bit 4 = Surrogate
   13|       |  // Bit 5 = Overlong 2-byte
   14|       |  // Bit 7 = Two Continuations
   15|  7.06k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   16|       |                                               // 11______ 11______
   17|  7.06k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   18|  7.06k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   19|  7.06k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   20|  7.06k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   21|  7.06k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   22|  7.06k|  constexpr const uint8_t TOO_LARGE = 1 << 3;  // 11110100 1001____
   23|       |                                               // 11110100 101_____
   24|       |                                               // 11110101 1001____
   25|       |                                               // 11110101 101_____
   26|       |                                               // 1111011_ 1001____
   27|       |                                               // 1111011_ 101_____
   28|       |                                               // 11111___ 1001____
   29|       |                                               // 11111___ 101_____
   30|  7.06k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   31|       |  // 11110101 1000____
   32|       |  // 1111011_ 1000____
   33|       |  // 11111___ 1000____
   34|  7.06k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   35|       |
   36|  7.06k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   37|       |      // 0_______ ________ <ASCII in byte 1>
   38|  7.06k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   39|  7.06k|      TOO_LONG,
   40|       |      // 10______ ________ <continuation in byte 1>
   41|  7.06k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   42|       |      // 1100____ ________ <two byte lead in byte 1>
   43|  7.06k|      TOO_SHORT | OVERLONG_2,
   44|       |      // 1101____ ________ <two byte lead in byte 1>
   45|  7.06k|      TOO_SHORT,
   46|       |      // 1110____ ________ <three byte lead in byte 1>
   47|  7.06k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   48|       |      // 1111____ ________ <four+ byte lead in byte 1>
   49|  7.06k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   50|  7.06k|  constexpr const uint8_t CARRY =
   51|  7.06k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   52|  7.06k|  const simd8<uint8_t> byte_1_low =
   53|  7.06k|      (prev1 & 0x0F)
   54|  7.06k|          .lookup_16<uint8_t>(
   55|       |              // ____0000 ________
   56|  7.06k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   57|       |              // ____0001 ________
   58|  7.06k|              CARRY | OVERLONG_2,
   59|       |              // ____001_ ________
   60|  7.06k|              CARRY, CARRY,
   61|       |
   62|       |              // ____0100 ________
   63|  7.06k|              CARRY | TOO_LARGE,
   64|       |              // ____0101 ________
   65|  7.06k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   66|       |              // ____011_ ________
   67|  7.06k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   68|  7.06k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|       |
   70|       |              // ____1___ ________
   71|  7.06k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   72|  7.06k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  7.06k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  7.06k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  7.06k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|       |              // ____1101 ________
   77|  7.06k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   78|  7.06k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   79|  7.06k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   80|  7.06k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   81|       |      // ________ 0_______ <ASCII in byte 2>
   82|  7.06k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   83|  7.06k|      TOO_SHORT, TOO_SHORT,
   84|       |
   85|       |      // ________ 1000____
   86|  7.06k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   87|  7.06k|          OVERLONG_4,
   88|       |      // ________ 1001____
   89|  7.06k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   90|       |      // ________ 101_____
   91|  7.06k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   92|  7.06k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|       |
   94|       |      // ________ 11______
   95|  7.06k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   96|  7.06k|  return (byte_1_high & byte_1_low & byte_2_high);
   97|  7.06k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3223check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  101|  7.06k|                        const simd8<uint8_t> sc) {
  102|  7.06k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  103|  7.06k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  104|  7.06k|  simd8<uint8_t> must23 =
  105|  7.06k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  106|  7.06k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  107|  7.06k|  return must23_80 ^ sc;
  108|  7.06k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoder6errorsEv:
  310|  5.55k|  simdutf_really_inline bool errors() const {
  311|  5.55k|    return this->error.any_bits_set_anywhere();
  312|  5.55k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker16check_next_inputERKNS1_4simd8simd8x64IhEE:
  187|  34.5k|  simdutf_really_inline void check_next_input(const simd8x64<uint8_t> &input) {
  188|  34.5k|    if (simdutf_likely(is_ascii(input))) {
  ------------------
  |  |   89|  34.5k|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (89:31): [True: 26.7k, False: 7.82k]
  |  |  ------------------
  ------------------
  189|  26.7k|      this->error |= this->prev_incomplete;
  190|  26.7k|    } else {
  191|       |      // you might think that a for-loop would work, but under Visual Studio, it
  192|       |      // is not good enough.
  193|  7.82k|      static_assert((simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  194|  7.82k|                        (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  195|  7.82k|                    "We support either two or four chunks per 64-byte block.");
  196|  7.82k|      if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  197|  7.82k|        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  198|  7.82k|        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  199|       |      } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  200|       |        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  201|       |        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  202|       |        this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  203|       |        this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  204|       |      }
  205|  7.82k|      this->prev_incomplete =
  206|  7.82k|          is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1]);
  207|  7.82k|      this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1];
  208|  7.82k|    }
  209|  34.5k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  169|  15.6k|                                              const simd8<uint8_t> prev_input) {
  170|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  171|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  172|       |    // small negative numbers)
  173|  15.6k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  174|  15.6k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  175|  15.6k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  176|  15.6k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation19check_special_casesENS1_4simd5simd8IhEES5_:
    9|  15.6k|check_special_cases(const simd8<uint8_t> input, const simd8<uint8_t> prev1) {
   10|       |  // Bit 0 = Too Short (lead byte/ASCII followed by lead byte/ASCII)
   11|       |  // Bit 1 = Too Long (ASCII followed by continuation)
   12|       |  // Bit 2 = Overlong 3-byte
   13|       |  // Bit 4 = Surrogate
   14|       |  // Bit 5 = Overlong 2-byte
   15|       |  // Bit 7 = Two Continuations
   16|  15.6k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   17|       |                                               // 11______ 11______
   18|  15.6k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   19|  15.6k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   20|  15.6k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   21|  15.6k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   22|  15.6k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   23|  15.6k|  constexpr const uint8_t TOO_LARGE = 1 << 3;  // 11110100 1001____
   24|       |                                               // 11110100 101_____
   25|       |                                               // 11110101 1001____
   26|       |                                               // 11110101 101_____
   27|       |                                               // 1111011_ 1001____
   28|       |                                               // 1111011_ 101_____
   29|       |                                               // 11111___ 1001____
   30|       |                                               // 11111___ 101_____
   31|  15.6k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   32|       |  // 11110101 1000____
   33|       |  // 1111011_ 1000____
   34|       |  // 11111___ 1000____
   35|  15.6k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   36|       |
   37|  15.6k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   38|       |      // 0_______ ________ <ASCII in byte 1>
   39|  15.6k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   40|  15.6k|      TOO_LONG,
   41|       |      // 10______ ________ <continuation in byte 1>
   42|  15.6k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   43|       |      // 1100____ ________ <two byte lead in byte 1>
   44|  15.6k|      TOO_SHORT | OVERLONG_2,
   45|       |      // 1101____ ________ <two byte lead in byte 1>
   46|  15.6k|      TOO_SHORT,
   47|       |      // 1110____ ________ <three byte lead in byte 1>
   48|  15.6k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   49|       |      // 1111____ ________ <four+ byte lead in byte 1>
   50|  15.6k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   51|  15.6k|  constexpr const uint8_t CARRY =
   52|  15.6k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   53|  15.6k|  const simd8<uint8_t> byte_1_low =
   54|  15.6k|      (prev1 & 0x0F)
   55|  15.6k|          .lookup_16<uint8_t>(
   56|       |              // ____0000 ________
   57|  15.6k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   58|       |              // ____0001 ________
   59|  15.6k|              CARRY | OVERLONG_2,
   60|       |              // ____001_ ________
   61|  15.6k|              CARRY, CARRY,
   62|       |
   63|       |              // ____0100 ________
   64|  15.6k|              CARRY | TOO_LARGE,
   65|       |              // ____0101 ________
   66|  15.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   67|       |              // ____011_ ________
   68|  15.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|  15.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   70|       |
   71|       |              // ____1___ ________
   72|  15.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  15.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  15.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  15.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|  15.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   77|       |              // ____1101 ________
   78|  15.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   79|  15.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   80|  15.6k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   81|  15.6k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   82|       |      // ________ 0_______ <ASCII in byte 2>
   83|  15.6k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   84|  15.6k|      TOO_SHORT, TOO_SHORT,
   85|       |
   86|       |      // ________ 1000____
   87|  15.6k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   88|  15.6k|          OVERLONG_4,
   89|       |      // ________ 1001____
   90|  15.6k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   91|       |      // ________ 101_____
   92|  15.6k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|  15.6k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   94|       |
   95|       |      // ________ 11______
   96|  15.6k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   97|  15.6k|  return (byte_1_high & byte_1_low & byte_2_high);
   98|  15.6k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation23check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  102|  15.6k|                        const simd8<uint8_t> sc) {
  103|  15.6k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  104|  15.6k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  105|  15.6k|  simd8<uint8_t> must23 =
  106|  15.6k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  107|  15.6k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  108|  15.6k|  return must23_80 ^ sc;
  109|  15.6k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation13is_incompleteENS1_4simd5simd8IhEE:
  115|  7.82k|simdutf_really_inline simd8<uint8_t> is_incomplete(const simd8<uint8_t> input) {
  116|       |  // If the previous input's last 3 bytes match this, they're too short (they
  117|       |  // ended at EOF):
  118|       |  // ... 1111____ 111_____ 11______
  119|  7.82k|  static const uint8_t max_array[32] = {255,
  120|  7.82k|                                        255,
  121|  7.82k|                                        255,
  122|  7.82k|                                        255,
  123|  7.82k|                                        255,
  124|  7.82k|                                        255,
  125|  7.82k|                                        255,
  126|  7.82k|                                        255,
  127|  7.82k|                                        255,
  128|  7.82k|                                        255,
  129|  7.82k|                                        255,
  130|  7.82k|                                        255,
  131|  7.82k|                                        255,
  132|  7.82k|                                        255,
  133|  7.82k|                                        255,
  134|  7.82k|                                        255,
  135|  7.82k|                                        255,
  136|  7.82k|                                        255,
  137|  7.82k|                                        255,
  138|  7.82k|                                        255,
  139|  7.82k|                                        255,
  140|  7.82k|                                        255,
  141|  7.82k|                                        255,
  142|  7.82k|                                        255,
  143|  7.82k|                                        255,
  144|  7.82k|                                        255,
  145|  7.82k|                                        255,
  146|  7.82k|                                        255,
  147|  7.82k|                                        255,
  148|  7.82k|                                        0b11110000u - 1,
  149|  7.82k|                                        0b11100000u - 1,
  150|  7.82k|                                        0b11000000u - 1};
  151|  7.82k|  const simd8<uint8_t> max_value(
  152|  7.82k|      &max_array[sizeof(max_array) - sizeof(simd8<uint8_t>)]);
  153|  7.82k|  return input.gt_bits(max_value);
  154|  7.82k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker9check_eofEv:
  181|  27.3k|  simdutf_really_inline void check_eof() {
  182|       |    // If the previous block had incomplete UTF-8 characters at the end, an
  183|       |    // ASCII block can't possibly finish them.
  184|  27.3k|    this->error |= this->prev_incomplete;
  185|  27.3k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker6errorsEv:
  212|  28.5k|  simdutf_really_inline bool errors() const {
  213|  28.5k|    return this->error.any_bits_set_anywhere();
  214|  28.5k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker16check_next_inputERKNS1_4simd8simd8x64IhEE:
  187|  37.2k|  simdutf_really_inline void check_next_input(const simd8x64<uint8_t> &input) {
  188|  37.2k|    if (simdutf_likely(is_ascii(input))) {
  ------------------
  |  |   89|  37.2k|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (89:31): [True: 28.2k, False: 9.01k]
  |  |  ------------------
  ------------------
  189|  28.2k|      this->error |= this->prev_incomplete;
  190|  28.2k|    } else {
  191|       |      // you might think that a for-loop would work, but under Visual Studio, it
  192|       |      // is not good enough.
  193|  9.01k|      static_assert((simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  194|  9.01k|                        (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  195|  9.01k|                    "We support either two or four chunks per 64-byte block.");
  196|       |      if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  197|       |        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  198|       |        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  199|  9.01k|      } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  200|  9.01k|        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  201|  9.01k|        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  202|  9.01k|        this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  203|  9.01k|        this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  204|  9.01k|      }
  205|  9.01k|      this->prev_incomplete =
  206|  9.01k|          is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1]);
  207|  9.01k|      this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1];
  208|  9.01k|    }
  209|  37.2k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  169|  36.0k|                                              const simd8<uint8_t> prev_input) {
  170|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  171|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  172|       |    // small negative numbers)
  173|  36.0k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  174|  36.0k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  175|  36.0k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  176|  36.0k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation19check_special_casesENS1_4simd5simd8IhEES5_:
    9|  36.0k|check_special_cases(const simd8<uint8_t> input, const simd8<uint8_t> prev1) {
   10|       |  // Bit 0 = Too Short (lead byte/ASCII followed by lead byte/ASCII)
   11|       |  // Bit 1 = Too Long (ASCII followed by continuation)
   12|       |  // Bit 2 = Overlong 3-byte
   13|       |  // Bit 4 = Surrogate
   14|       |  // Bit 5 = Overlong 2-byte
   15|       |  // Bit 7 = Two Continuations
   16|  36.0k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   17|       |                                               // 11______ 11______
   18|  36.0k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   19|  36.0k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   20|  36.0k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   21|  36.0k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   22|  36.0k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   23|  36.0k|  constexpr const uint8_t TOO_LARGE = 1 << 3;  // 11110100 1001____
   24|       |                                               // 11110100 101_____
   25|       |                                               // 11110101 1001____
   26|       |                                               // 11110101 101_____
   27|       |                                               // 1111011_ 1001____
   28|       |                                               // 1111011_ 101_____
   29|       |                                               // 11111___ 1001____
   30|       |                                               // 11111___ 101_____
   31|  36.0k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   32|       |  // 11110101 1000____
   33|       |  // 1111011_ 1000____
   34|       |  // 11111___ 1000____
   35|  36.0k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   36|       |
   37|  36.0k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   38|       |      // 0_______ ________ <ASCII in byte 1>
   39|  36.0k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   40|  36.0k|      TOO_LONG,
   41|       |      // 10______ ________ <continuation in byte 1>
   42|  36.0k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   43|       |      // 1100____ ________ <two byte lead in byte 1>
   44|  36.0k|      TOO_SHORT | OVERLONG_2,
   45|       |      // 1101____ ________ <two byte lead in byte 1>
   46|  36.0k|      TOO_SHORT,
   47|       |      // 1110____ ________ <three byte lead in byte 1>
   48|  36.0k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   49|       |      // 1111____ ________ <four+ byte lead in byte 1>
   50|  36.0k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   51|  36.0k|  constexpr const uint8_t CARRY =
   52|  36.0k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   53|  36.0k|  const simd8<uint8_t> byte_1_low =
   54|  36.0k|      (prev1 & 0x0F)
   55|  36.0k|          .lookup_16<uint8_t>(
   56|       |              // ____0000 ________
   57|  36.0k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   58|       |              // ____0001 ________
   59|  36.0k|              CARRY | OVERLONG_2,
   60|       |              // ____001_ ________
   61|  36.0k|              CARRY, CARRY,
   62|       |
   63|       |              // ____0100 ________
   64|  36.0k|              CARRY | TOO_LARGE,
   65|       |              // ____0101 ________
   66|  36.0k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   67|       |              // ____011_ ________
   68|  36.0k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|  36.0k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   70|       |
   71|       |              // ____1___ ________
   72|  36.0k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  36.0k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  36.0k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  36.0k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|  36.0k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   77|       |              // ____1101 ________
   78|  36.0k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   79|  36.0k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   80|  36.0k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   81|  36.0k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   82|       |      // ________ 0_______ <ASCII in byte 2>
   83|  36.0k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   84|  36.0k|      TOO_SHORT, TOO_SHORT,
   85|       |
   86|       |      // ________ 1000____
   87|  36.0k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   88|  36.0k|          OVERLONG_4,
   89|       |      // ________ 1001____
   90|  36.0k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   91|       |      // ________ 101_____
   92|  36.0k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|  36.0k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   94|       |
   95|       |      // ________ 11______
   96|  36.0k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   97|  36.0k|  return (byte_1_high & byte_1_low & byte_2_high);
   98|  36.0k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation23check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  102|  36.0k|                        const simd8<uint8_t> sc) {
  103|  36.0k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  104|  36.0k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  105|  36.0k|  simd8<uint8_t> must23 =
  106|  36.0k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  107|  36.0k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  108|  36.0k|  return must23_80 ^ sc;
  109|  36.0k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation13is_incompleteENS1_4simd5simd8IhEE:
  115|  9.01k|simdutf_really_inline simd8<uint8_t> is_incomplete(const simd8<uint8_t> input) {
  116|       |  // If the previous input's last 3 bytes match this, they're too short (they
  117|       |  // ended at EOF):
  118|       |  // ... 1111____ 111_____ 11______
  119|  9.01k|  static const uint8_t max_array[32] = {255,
  120|  9.01k|                                        255,
  121|  9.01k|                                        255,
  122|  9.01k|                                        255,
  123|  9.01k|                                        255,
  124|  9.01k|                                        255,
  125|  9.01k|                                        255,
  126|  9.01k|                                        255,
  127|  9.01k|                                        255,
  128|  9.01k|                                        255,
  129|  9.01k|                                        255,
  130|  9.01k|                                        255,
  131|  9.01k|                                        255,
  132|  9.01k|                                        255,
  133|  9.01k|                                        255,
  134|  9.01k|                                        255,
  135|  9.01k|                                        255,
  136|  9.01k|                                        255,
  137|  9.01k|                                        255,
  138|  9.01k|                                        255,
  139|  9.01k|                                        255,
  140|  9.01k|                                        255,
  141|  9.01k|                                        255,
  142|  9.01k|                                        255,
  143|  9.01k|                                        255,
  144|  9.01k|                                        255,
  145|  9.01k|                                        255,
  146|  9.01k|                                        255,
  147|  9.01k|                                        255,
  148|  9.01k|                                        0b11110000u - 1,
  149|  9.01k|                                        0b11100000u - 1,
  150|  9.01k|                                        0b11000000u - 1};
  151|  9.01k|  const simd8<uint8_t> max_value(
  152|  9.01k|      &max_array[sizeof(max_array) - sizeof(simd8<uint8_t>)]);
  153|  9.01k|  return input.gt_bits(max_value);
  154|  9.01k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker9check_eofEv:
  181|  27.3k|  simdutf_really_inline void check_eof() {
  182|       |    // If the previous block had incomplete UTF-8 characters at the end, an
  183|       |    // ASCII block can't possibly finish them.
  184|  27.3k|    this->error |= this->prev_incomplete;
  185|  27.3k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker6errorsEv:
  212|  29.0k|  simdutf_really_inline bool errors() const {
  213|  29.0k|    return this->error.any_bits_set_anywhere();
  214|  29.0k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation21generic_validate_utf8EPKcm:
   27|  22.0k|bool generic_validate_utf8(const char *input, size_t length) {
   28|  22.0k|  return generic_validate_utf8<utf8_checker>(
   29|  22.0k|      reinterpret_cast<const uint8_t *>(input), length);
   30|  22.0k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation21generic_validate_utf8INS2_12utf8_checkerEEEbPKhm:
   10|  22.0k|bool generic_validate_utf8(const uint8_t *input, size_t length) {
   11|  22.0k|  checker c{};
   12|  22.0k|  buf_block_reader<64> reader(input, length);
   13|  28.1k|  while (reader.has_full_block()) {
  ------------------
  |  Branch (13:10): [True: 6.08k, False: 22.0k]
  ------------------
   14|  6.08k|    simd::simd8x64<uint8_t> in(reader.full_block());
   15|  6.08k|    c.check_next_input(in);
   16|  6.08k|    reader.advance();
   17|  6.08k|  }
   18|  22.0k|  uint8_t block[64]{};
   19|  22.0k|  reader.get_remainder(block);
   20|  22.0k|  simd::simd8x64<uint8_t> in(block);
   21|  22.0k|  c.check_next_input(in);
   22|  22.0k|  reader.advance();
   23|  22.0k|  c.check_eof();
   24|  22.0k|  return !c.errors();
   25|  22.0k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation33generic_validate_utf8_with_errorsEPKcm:
   76|  5.56k|result generic_validate_utf8_with_errors(const char *input, size_t length) {
   77|  5.56k|  return generic_validate_utf8_with_errors<utf8_checker>(
   78|  5.56k|      reinterpret_cast<const uint8_t *>(input), length);
   79|  5.56k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation33generic_validate_utf8_with_errorsINS2_12utf8_checkerEEENS_6resultEPKhm:
   36|  5.56k|result generic_validate_utf8_with_errors(const uint8_t *input, size_t length) {
   37|  5.56k|  checker c{};
   38|  5.56k|  buf_block_reader<64> reader(input, length);
   39|  5.56k|  size_t count{0};
   40|  6.43k|  while (reader.has_full_block()) {
  ------------------
  |  Branch (40:10): [True: 1.12k, False: 5.31k]
  ------------------
   41|  1.12k|    simd::simd8x64<uint8_t> in(reader.full_block());
   42|  1.12k|    c.check_next_input(in);
   43|  1.12k|    if (c.errors()) {
  ------------------
  |  Branch (43:9): [True: 250, False: 871]
  ------------------
   44|    250|      if (count != 0) {
  ------------------
  |  Branch (44:11): [True: 13, False: 237]
  ------------------
   45|     13|        count--;
   46|     13|      } // Sometimes the error is only detected in the next chunk
   47|    250|      result res = scalar::utf8::rewind_and_validate_with_errors(
   48|    250|          reinterpret_cast<const char *>(input),
   49|    250|          reinterpret_cast<const char *>(input + count), length - count);
   50|    250|      res.count += count;
   51|    250|      return res;
   52|    250|    }
   53|    871|    reader.advance();
   54|    871|    count += 64;
   55|    871|  }
   56|  5.31k|  uint8_t block[64]{};
   57|  5.31k|  reader.get_remainder(block);
   58|  5.31k|  simd::simd8x64<uint8_t> in(block);
   59|  5.31k|  c.check_next_input(in);
   60|  5.31k|  reader.advance();
   61|  5.31k|  c.check_eof();
   62|  5.31k|  if (c.errors()) {
  ------------------
  |  Branch (62:7): [True: 350, False: 4.96k]
  ------------------
   63|    350|    if (count != 0) {
  ------------------
  |  Branch (63:9): [True: 13, False: 337]
  ------------------
   64|     13|      count--;
   65|     13|    } // Sometimes the error is only detected in the next chunk
   66|    350|    result res = scalar::utf8::rewind_and_validate_with_errors(
   67|    350|        reinterpret_cast<const char *>(input),
   68|    350|        reinterpret_cast<const char *>(input) + count, length - count);
   69|    350|    res.count += count;
   70|    350|    return res;
   71|  4.96k|  } else {
   72|  4.96k|    return result(error_code::SUCCESS, length);
   73|  4.96k|  }
   74|  5.31k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation21generic_validate_utf8EPKcm:
   27|  22.0k|bool generic_validate_utf8(const char *input, size_t length) {
   28|  22.0k|  return generic_validate_utf8<utf8_checker>(
   29|  22.0k|      reinterpret_cast<const uint8_t *>(input), length);
   30|  22.0k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation21generic_validate_utf8INS2_12utf8_checkerEEEbPKhm:
   10|  22.0k|bool generic_validate_utf8(const uint8_t *input, size_t length) {
   11|  22.0k|  checker c{};
   12|  22.0k|  buf_block_reader<64> reader(input, length);
   13|  30.2k|  while (reader.has_full_block()) {
  ------------------
  |  Branch (13:10): [True: 8.19k, False: 22.0k]
  ------------------
   14|  8.19k|    simd::simd8x64<uint8_t> in(reader.full_block());
   15|  8.19k|    c.check_next_input(in);
   16|  8.19k|    reader.advance();
   17|  8.19k|  }
   18|  22.0k|  uint8_t block[64]{};
   19|  22.0k|  reader.get_remainder(block);
   20|  22.0k|  simd::simd8x64<uint8_t> in(block);
   21|  22.0k|  c.check_next_input(in);
   22|  22.0k|  reader.advance();
   23|  22.0k|  c.check_eof();
   24|  22.0k|  return !c.errors();
   25|  22.0k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation33generic_validate_utf8_with_errorsEPKcm:
   76|  5.56k|result generic_validate_utf8_with_errors(const char *input, size_t length) {
   77|  5.56k|  return generic_validate_utf8_with_errors<utf8_checker>(
   78|  5.56k|      reinterpret_cast<const uint8_t *>(input), length);
   79|  5.56k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation33generic_validate_utf8_with_errorsINS2_12utf8_checkerEEENS_6resultEPKhm:
   36|  5.56k|result generic_validate_utf8_with_errors(const uint8_t *input, size_t length) {
   37|  5.56k|  checker c{};
   38|  5.56k|  buf_block_reader<64> reader(input, length);
   39|  5.56k|  size_t count{0};
   40|  7.03k|  while (reader.has_full_block()) {
  ------------------
  |  Branch (40:10): [True: 1.70k, False: 5.32k]
  ------------------
   41|  1.70k|    simd::simd8x64<uint8_t> in(reader.full_block());
   42|  1.70k|    c.check_next_input(in);
   43|  1.70k|    if (c.errors()) {
  ------------------
  |  Branch (43:9): [True: 238, False: 1.46k]
  ------------------
   44|    238|      if (count != 0) {
  ------------------
  |  Branch (44:11): [True: 36, False: 202]
  ------------------
   45|     36|        count--;
   46|     36|      } // Sometimes the error is only detected in the next chunk
   47|    238|      result res = scalar::utf8::rewind_and_validate_with_errors(
   48|    238|          reinterpret_cast<const char *>(input),
   49|    238|          reinterpret_cast<const char *>(input + count), length - count);
   50|    238|      res.count += count;
   51|    238|      return res;
   52|    238|    }
   53|  1.46k|    reader.advance();
   54|  1.46k|    count += 64;
   55|  1.46k|  }
   56|  5.32k|  uint8_t block[64]{};
   57|  5.32k|  reader.get_remainder(block);
   58|  5.32k|  simd::simd8x64<uint8_t> in(block);
   59|  5.32k|  c.check_next_input(in);
   60|  5.32k|  reader.advance();
   61|  5.32k|  c.check_eof();
   62|  5.32k|  if (c.errors()) {
  ------------------
  |  Branch (62:7): [True: 182, False: 5.14k]
  ------------------
   63|    182|    if (count != 0) {
  ------------------
  |  Branch (63:9): [True: 14, False: 168]
  ------------------
   64|     14|      count--;
   65|     14|    } // Sometimes the error is only detected in the next chunk
   66|    182|    result res = scalar::utf8::rewind_and_validate_with_errors(
   67|    182|        reinterpret_cast<const char *>(input),
   68|    182|        reinterpret_cast<const char *>(input) + count, length - count);
   69|    182|    res.count += count;
   70|    182|    return res;
   71|  5.14k|  } else {
   72|  5.14k|    return result(error_code::SUCCESS, length);
   73|  5.14k|  }
   74|  5.32k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1626validate_utf16_with_errorsILNS_10endiannessE0EEEKNS_6resultEPKDsm:
   49|  7.94k|const result validate_utf16_with_errors(const char16_t *input, size_t size) {
   50|  7.94k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   92|  7.94k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (92:33): [True: 5.20k, False: 2.74k]
  |  |  ------------------
  ------------------
   51|  5.20k|    return result(error_code::SUCCESS, 0);
   52|  5.20k|  }
   53|       |
   54|  2.74k|  const char16_t *start = input;
   55|  2.74k|  const char16_t *end = input + size;
   56|       |
   57|  2.74k|  const auto v_d8 = simd8<uint8_t>::splat(0xd8);
   58|  2.74k|  const auto v_f8 = simd8<uint8_t>::splat(0xf8);
   59|  2.74k|  const auto v_fc = simd8<uint8_t>::splat(0xfc);
   60|  2.74k|  const auto v_dc = simd8<uint8_t>::splat(0xdc);
   61|       |
   62|  14.2k|  while (input + simd16<uint16_t>::SIZE * 2 < end) {
  ------------------
  |  Branch (62:10): [True: 11.6k, False: 2.65k]
  ------------------
   63|       |    // 0. Load data: since the validation takes into account only higher
   64|       |    //    byte of each word, we compress the two vectors into one which
   65|       |    //    consists only the higher bytes.
   66|  11.6k|    auto in0 = simd16<uint16_t>(input);
   67|  11.6k|    auto in1 =
   68|  11.6k|        simd16<uint16_t>(input + simd16<uint16_t>::SIZE / sizeof(char16_t));
   69|       |
   70|       |    // Function `utf16_gather_high_bytes` consumes two vectors of UTF-16
   71|       |    // and yields a single vector having only higher bytes of characters.
   72|  11.6k|    const auto in = utf16_gather_high_bytes<big_endian>(in0, in1);
   73|       |
   74|       |    // 1. Check whether we have any 0xD800..DFFF word (0b1101'1xxx'yyyy'yyyy).
   75|  11.6k|    const auto surrogates_wordmask = (in & v_f8) == v_d8;
   76|  11.6k|    const uint16_t surrogates_bitmask =
   77|  11.6k|        static_cast<uint16_t>(surrogates_wordmask.to_bitmask());
   78|  11.6k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (78:9): [True: 10.5k, False: 1.09k]
  ------------------
   79|  10.5k|      input += 16;
   80|  10.5k|    } else {
   81|       |      // 2. We have some surrogates that have to be distinguished:
   82|       |      //    - low  surrogates: 0b1101'10xx'yyyy'yyyy (0xD800..0xDBFF)
   83|       |      //    - high surrogates: 0b1101'11xx'yyyy'yyyy (0xDC00..0xDFFF)
   84|       |      //
   85|       |      //    Fact: high surrogate has 11th bit set (3rd bit in the higher byte)
   86|       |
   87|       |      // V - non-surrogate code units
   88|       |      //     V = not surrogates_wordmask
   89|  1.09k|      const uint16_t V = static_cast<uint16_t>(~surrogates_bitmask);
   90|       |
   91|       |      // H - word-mask for high surrogates: the six highest bits are 0b1101'11
   92|  1.09k|      const auto vH = (in & v_fc) == v_dc;
   93|  1.09k|      const uint16_t H = static_cast<uint16_t>(vH.to_bitmask());
   94|       |
   95|       |      // L - word mask for low surrogates
   96|       |      //     L = not H and surrogates_wordmask
   97|  1.09k|      const uint16_t L = static_cast<uint16_t>(~H & surrogates_bitmask);
   98|       |
   99|  1.09k|      const uint16_t a = static_cast<uint16_t>(
  100|  1.09k|          L & (H >> 1)); // A low surrogate must be followed by high one.
  101|       |                         // (A low surrogate placed in the 7th register's word
  102|       |                         // is an exception we handle.)
  103|  1.09k|      const uint16_t b = static_cast<uint16_t>(
  104|  1.09k|          a << 1); // Just mark that the opinput - startite fact is hold,
  105|       |                   // thanks to that we have only two masks for valid case.
  106|  1.09k|      const uint16_t c = static_cast<uint16_t>(
  107|  1.09k|          V | a | b); // Combine all the masks into the final one.
  108|       |
  109|  1.09k|      if (c == 0xffff) {
  ------------------
  |  Branch (109:11): [True: 679, False: 419]
  ------------------
  110|       |        // The whole input register contains valid UTF-16, i.e.,
  111|       |        // either single code units or proper surrogate pairs.
  112|    679|        input += 16;
  113|    679|      } else if (c == 0x7fff) {
  ------------------
  |  Branch (113:18): [True: 335, False: 84]
  ------------------
  114|       |        // The 15 lower code units of the input register contains valid UTF-16.
  115|       |        // The 15th word may be either a low or high surrogate. It the next
  116|       |        // iteration we 1) check if the low surrogate is followed by a high
  117|       |        // one, 2) reject sole high surrogate.
  118|    335|        input += 15;
  119|    335|      } else {
  120|     84|        return result(error_code::SURROGATE, input - start);
  121|     84|      }
  122|  1.09k|    }
  123|  11.6k|  }
  124|       |
  125|  2.65k|  return result(error_code::SUCCESS, input - start);
  126|  2.74k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1626validate_utf16_with_errorsILNS_10endiannessE1EEEKNS_6resultEPKDsm:
   49|  7.95k|const result validate_utf16_with_errors(const char16_t *input, size_t size) {
   50|  7.95k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   92|  7.95k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (92:33): [True: 5.19k, False: 2.75k]
  |  |  ------------------
  ------------------
   51|  5.19k|    return result(error_code::SUCCESS, 0);
   52|  5.19k|  }
   53|       |
   54|  2.75k|  const char16_t *start = input;
   55|  2.75k|  const char16_t *end = input + size;
   56|       |
   57|  2.75k|  const auto v_d8 = simd8<uint8_t>::splat(0xd8);
   58|  2.75k|  const auto v_f8 = simd8<uint8_t>::splat(0xf8);
   59|  2.75k|  const auto v_fc = simd8<uint8_t>::splat(0xfc);
   60|  2.75k|  const auto v_dc = simd8<uint8_t>::splat(0xdc);
   61|       |
   62|  14.8k|  while (input + simd16<uint16_t>::SIZE * 2 < end) {
  ------------------
  |  Branch (62:10): [True: 12.1k, False: 2.67k]
  ------------------
   63|       |    // 0. Load data: since the validation takes into account only higher
   64|       |    //    byte of each word, we compress the two vectors into one which
   65|       |    //    consists only the higher bytes.
   66|  12.1k|    auto in0 = simd16<uint16_t>(input);
   67|  12.1k|    auto in1 =
   68|  12.1k|        simd16<uint16_t>(input + simd16<uint16_t>::SIZE / sizeof(char16_t));
   69|       |
   70|       |    // Function `utf16_gather_high_bytes` consumes two vectors of UTF-16
   71|       |    // and yields a single vector having only higher bytes of characters.
   72|  12.1k|    const auto in = utf16_gather_high_bytes<big_endian>(in0, in1);
   73|       |
   74|       |    // 1. Check whether we have any 0xD800..DFFF word (0b1101'1xxx'yyyy'yyyy).
   75|  12.1k|    const auto surrogates_wordmask = (in & v_f8) == v_d8;
   76|  12.1k|    const uint16_t surrogates_bitmask =
   77|  12.1k|        static_cast<uint16_t>(surrogates_wordmask.to_bitmask());
   78|  12.1k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (78:9): [True: 11.2k, False: 988]
  ------------------
   79|  11.2k|      input += 16;
   80|  11.2k|    } else {
   81|       |      // 2. We have some surrogates that have to be distinguished:
   82|       |      //    - low  surrogates: 0b1101'10xx'yyyy'yyyy (0xD800..0xDBFF)
   83|       |      //    - high surrogates: 0b1101'11xx'yyyy'yyyy (0xDC00..0xDFFF)
   84|       |      //
   85|       |      //    Fact: high surrogate has 11th bit set (3rd bit in the higher byte)
   86|       |
   87|       |      // V - non-surrogate code units
   88|       |      //     V = not surrogates_wordmask
   89|    988|      const uint16_t V = static_cast<uint16_t>(~surrogates_bitmask);
   90|       |
   91|       |      // H - word-mask for high surrogates: the six highest bits are 0b1101'11
   92|    988|      const auto vH = (in & v_fc) == v_dc;
   93|    988|      const uint16_t H = static_cast<uint16_t>(vH.to_bitmask());
   94|       |
   95|       |      // L - word mask for low surrogates
   96|       |      //     L = not H and surrogates_wordmask
   97|    988|      const uint16_t L = static_cast<uint16_t>(~H & surrogates_bitmask);
   98|       |
   99|    988|      const uint16_t a = static_cast<uint16_t>(
  100|    988|          L & (H >> 1)); // A low surrogate must be followed by high one.
  101|       |                         // (A low surrogate placed in the 7th register's word
  102|       |                         // is an exception we handle.)
  103|    988|      const uint16_t b = static_cast<uint16_t>(
  104|    988|          a << 1); // Just mark that the opinput - startite fact is hold,
  105|       |                   // thanks to that we have only two masks for valid case.
  106|    988|      const uint16_t c = static_cast<uint16_t>(
  107|    988|          V | a | b); // Combine all the masks into the final one.
  108|       |
  109|    988|      if (c == 0xffff) {
  ------------------
  |  Branch (109:11): [True: 553, False: 435]
  ------------------
  110|       |        // The whole input register contains valid UTF-16, i.e.,
  111|       |        // either single code units or proper surrogate pairs.
  112|    553|        input += 16;
  113|    553|      } else if (c == 0x7fff) {
  ------------------
  |  Branch (113:18): [True: 357, False: 78]
  ------------------
  114|       |        // The 15 lower code units of the input register contains valid UTF-16.
  115|       |        // The 15th word may be either a low or high surrogate. It the next
  116|       |        // iteration we 1) check if the low surrogate is followed by a high
  117|       |        // one, 2) reject sole high surrogate.
  118|    357|        input += 15;
  119|    357|      } else {
  120|     78|        return result(error_code::SURROGATE, input - start);
  121|     78|      }
  122|    988|    }
  123|  12.1k|  }
  124|       |
  125|  2.67k|  return result(error_code::SUCCESS, input - start);
  126|  2.75k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1626validate_utf16_with_errorsILNS_10endiannessE0EEEKNS_6resultEPKDsm:
   49|  7.43k|const result validate_utf16_with_errors(const char16_t *input, size_t size) {
   50|  7.43k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   92|  7.43k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (92:33): [True: 5.21k, False: 2.21k]
  |  |  ------------------
  ------------------
   51|  5.21k|    return result(error_code::SUCCESS, 0);
   52|  5.21k|  }
   53|       |
   54|  2.21k|  const char16_t *start = input;
   55|  2.21k|  const char16_t *end = input + size;
   56|       |
   57|  2.21k|  const auto v_d8 = simd8<uint8_t>::splat(0xd8);
   58|  2.21k|  const auto v_f8 = simd8<uint8_t>::splat(0xf8);
   59|  2.21k|  const auto v_fc = simd8<uint8_t>::splat(0xfc);
   60|  2.21k|  const auto v_dc = simd8<uint8_t>::splat(0xdc);
   61|       |
   62|  20.5k|  while (input + simd16<uint16_t>::SIZE * 2 < end) {
  ------------------
  |  Branch (62:10): [True: 18.4k, False: 2.11k]
  ------------------
   63|       |    // 0. Load data: since the validation takes into account only higher
   64|       |    //    byte of each word, we compress the two vectors into one which
   65|       |    //    consists only the higher bytes.
   66|  18.4k|    auto in0 = simd16<uint16_t>(input);
   67|  18.4k|    auto in1 =
   68|  18.4k|        simd16<uint16_t>(input + simd16<uint16_t>::SIZE / sizeof(char16_t));
   69|       |
   70|       |    // Function `utf16_gather_high_bytes` consumes two vectors of UTF-16
   71|       |    // and yields a single vector having only higher bytes of characters.
   72|  18.4k|    const auto in = utf16_gather_high_bytes<big_endian>(in0, in1);
   73|       |
   74|       |    // 1. Check whether we have any 0xD800..DFFF word (0b1101'1xxx'yyyy'yyyy).
   75|  18.4k|    const auto surrogates_wordmask = (in & v_f8) == v_d8;
   76|  18.4k|    const uint16_t surrogates_bitmask =
   77|  18.4k|        static_cast<uint16_t>(surrogates_wordmask.to_bitmask());
   78|  18.4k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (78:9): [True: 17.1k, False: 1.29k]
  ------------------
   79|  17.1k|      input += 16;
   80|  17.1k|    } else {
   81|       |      // 2. We have some surrogates that have to be distinguished:
   82|       |      //    - low  surrogates: 0b1101'10xx'yyyy'yyyy (0xD800..0xDBFF)
   83|       |      //    - high surrogates: 0b1101'11xx'yyyy'yyyy (0xDC00..0xDFFF)
   84|       |      //
   85|       |      //    Fact: high surrogate has 11th bit set (3rd bit in the higher byte)
   86|       |
   87|       |      // V - non-surrogate code units
   88|       |      //     V = not surrogates_wordmask
   89|  1.29k|      const uint16_t V = static_cast<uint16_t>(~surrogates_bitmask);
   90|       |
   91|       |      // H - word-mask for high surrogates: the six highest bits are 0b1101'11
   92|  1.29k|      const auto vH = (in & v_fc) == v_dc;
   93|  1.29k|      const uint16_t H = static_cast<uint16_t>(vH.to_bitmask());
   94|       |
   95|       |      // L - word mask for low surrogates
   96|       |      //     L = not H and surrogates_wordmask
   97|  1.29k|      const uint16_t L = static_cast<uint16_t>(~H & surrogates_bitmask);
   98|       |
   99|  1.29k|      const uint16_t a = static_cast<uint16_t>(
  100|  1.29k|          L & (H >> 1)); // A low surrogate must be followed by high one.
  101|       |                         // (A low surrogate placed in the 7th register's word
  102|       |                         // is an exception we handle.)
  103|  1.29k|      const uint16_t b = static_cast<uint16_t>(
  104|  1.29k|          a << 1); // Just mark that the opinput - startite fact is hold,
  105|       |                   // thanks to that we have only two masks for valid case.
  106|  1.29k|      const uint16_t c = static_cast<uint16_t>(
  107|  1.29k|          V | a | b); // Combine all the masks into the final one.
  108|       |
  109|  1.29k|      if (c == 0xffff) {
  ------------------
  |  Branch (109:11): [True: 845, False: 452]
  ------------------
  110|       |        // The whole input register contains valid UTF-16, i.e.,
  111|       |        // either single code units or proper surrogate pairs.
  112|    845|        input += 16;
  113|    845|      } else if (c == 0x7fff) {
  ------------------
  |  Branch (113:18): [True: 346, False: 106]
  ------------------
  114|       |        // The 15 lower code units of the input register contains valid UTF-16.
  115|       |        // The 15th word may be either a low or high surrogate. It the next
  116|       |        // iteration we 1) check if the low surrogate is followed by a high
  117|       |        // one, 2) reject sole high surrogate.
  118|    346|        input += 15;
  119|    346|      } else {
  120|    106|        return result(error_code::SURROGATE, input - start);
  121|    106|      }
  122|  1.29k|    }
  123|  18.4k|  }
  124|       |
  125|  2.11k|  return result(error_code::SUCCESS, input - start);
  126|  2.21k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1626validate_utf16_with_errorsILNS_10endiannessE1EEEKNS_6resultEPKDsm:
   49|  7.41k|const result validate_utf16_with_errors(const char16_t *input, size_t size) {
   50|  7.41k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   92|  7.41k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (92:33): [True: 5.23k, False: 2.17k]
  |  |  ------------------
  ------------------
   51|  5.23k|    return result(error_code::SUCCESS, 0);
   52|  5.23k|  }
   53|       |
   54|  2.17k|  const char16_t *start = input;
   55|  2.17k|  const char16_t *end = input + size;
   56|       |
   57|  2.17k|  const auto v_d8 = simd8<uint8_t>::splat(0xd8);
   58|  2.17k|  const auto v_f8 = simd8<uint8_t>::splat(0xf8);
   59|  2.17k|  const auto v_fc = simd8<uint8_t>::splat(0xfc);
   60|  2.17k|  const auto v_dc = simd8<uint8_t>::splat(0xdc);
   61|       |
   62|  20.6k|  while (input + simd16<uint16_t>::SIZE * 2 < end) {
  ------------------
  |  Branch (62:10): [True: 18.5k, False: 2.07k]
  ------------------
   63|       |    // 0. Load data: since the validation takes into account only higher
   64|       |    //    byte of each word, we compress the two vectors into one which
   65|       |    //    consists only the higher bytes.
   66|  18.5k|    auto in0 = simd16<uint16_t>(input);
   67|  18.5k|    auto in1 =
   68|  18.5k|        simd16<uint16_t>(input + simd16<uint16_t>::SIZE / sizeof(char16_t));
   69|       |
   70|       |    // Function `utf16_gather_high_bytes` consumes two vectors of UTF-16
   71|       |    // and yields a single vector having only higher bytes of characters.
   72|  18.5k|    const auto in = utf16_gather_high_bytes<big_endian>(in0, in1);
   73|       |
   74|       |    // 1. Check whether we have any 0xD800..DFFF word (0b1101'1xxx'yyyy'yyyy).
   75|  18.5k|    const auto surrogates_wordmask = (in & v_f8) == v_d8;
   76|  18.5k|    const uint16_t surrogates_bitmask =
   77|  18.5k|        static_cast<uint16_t>(surrogates_wordmask.to_bitmask());
   78|  18.5k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (78:9): [True: 17.3k, False: 1.21k]
  ------------------
   79|  17.3k|      input += 16;
   80|  17.3k|    } else {
   81|       |      // 2. We have some surrogates that have to be distinguished:
   82|       |      //    - low  surrogates: 0b1101'10xx'yyyy'yyyy (0xD800..0xDBFF)
   83|       |      //    - high surrogates: 0b1101'11xx'yyyy'yyyy (0xDC00..0xDFFF)
   84|       |      //
   85|       |      //    Fact: high surrogate has 11th bit set (3rd bit in the higher byte)
   86|       |
   87|       |      // V - non-surrogate code units
   88|       |      //     V = not surrogates_wordmask
   89|  1.21k|      const uint16_t V = static_cast<uint16_t>(~surrogates_bitmask);
   90|       |
   91|       |      // H - word-mask for high surrogates: the six highest bits are 0b1101'11
   92|  1.21k|      const auto vH = (in & v_fc) == v_dc;
   93|  1.21k|      const uint16_t H = static_cast<uint16_t>(vH.to_bitmask());
   94|       |
   95|       |      // L - word mask for low surrogates
   96|       |      //     L = not H and surrogates_wordmask
   97|  1.21k|      const uint16_t L = static_cast<uint16_t>(~H & surrogates_bitmask);
   98|       |
   99|  1.21k|      const uint16_t a = static_cast<uint16_t>(
  100|  1.21k|          L & (H >> 1)); // A low surrogate must be followed by high one.
  101|       |                         // (A low surrogate placed in the 7th register's word
  102|       |                         // is an exception we handle.)
  103|  1.21k|      const uint16_t b = static_cast<uint16_t>(
  104|  1.21k|          a << 1); // Just mark that the opinput - startite fact is hold,
  105|       |                   // thanks to that we have only two masks for valid case.
  106|  1.21k|      const uint16_t c = static_cast<uint16_t>(
  107|  1.21k|          V | a | b); // Combine all the masks into the final one.
  108|       |
  109|  1.21k|      if (c == 0xffff) {
  ------------------
  |  Branch (109:11): [True: 761, False: 454]
  ------------------
  110|       |        // The whole input register contains valid UTF-16, i.e.,
  111|       |        // either single code units or proper surrogate pairs.
  112|    761|        input += 16;
  113|    761|      } else if (c == 0x7fff) {
  ------------------
  |  Branch (113:18): [True: 356, False: 98]
  ------------------
  114|       |        // The 15 lower code units of the input register contains valid UTF-16.
  115|       |        // The 15th word may be either a low or high surrogate. It the next
  116|       |        // iteration we 1) check if the low surrogate is followed by a high
  117|       |        // one, 2) reject sole high surrogate.
  118|    356|        input += 15;
  119|    356|      } else {
  120|     98|        return result(error_code::SURROGATE, input - start);
  121|     98|      }
  122|  1.21k|    }
  123|  18.5k|  }
  124|       |
  125|  2.07k|  return result(error_code::SUCCESS, input - start);
  126|  2.17k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf328validateEPKDim:
    6|  10.5k|simdutf_really_inline bool validate(const char32_t *input, size_t size) {
    7|  10.5k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   92|  10.5k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (92:33): [True: 8.49k, False: 2.03k]
  |  |  ------------------
  ------------------
    8|       |    // empty input is valid UTF-32. protect the implementation from
    9|       |    // handling nullptr
   10|  8.49k|    return true;
   11|  8.49k|  }
   12|       |
   13|  2.03k|  const char32_t *end = input + size;
   14|       |
   15|  2.03k|  using vector_u32 = simd32<uint32_t>;
   16|       |
   17|  2.03k|  const auto standardmax = vector_u32::splat(0x10ffff);
   18|  2.03k|  const auto offset = vector_u32::splat(0xffff2000);
   19|  2.03k|  const auto standardoffsetmax = vector_u32::splat(0xfffff7ff);
   20|  2.03k|  auto currentmax = vector_u32::zero();
   21|  2.03k|  auto currentoffsetmax = vector_u32::zero();
   22|       |
   23|  2.03k|  constexpr size_t N = vector_u32::ELEMENTS;
   24|       |
   25|  27.8k|  while (input + N < end) {
  ------------------
  |  Branch (25:10): [True: 25.8k, False: 2.03k]
  ------------------
   26|  25.8k|    auto in = vector_u32(input);
   27|  25.8k|    if constexpr (!match_system(endianness::BIG)) {
   28|  25.8k|      in.swap_bytes();
   29|  25.8k|    }
   30|       |
   31|  25.8k|    currentmax = max(currentmax, in);
   32|  25.8k|    currentoffsetmax = max(currentoffsetmax, in + offset);
   33|  25.8k|    input += N;
   34|  25.8k|  }
   35|       |
   36|  2.03k|  const auto too_large = currentmax > standardmax;
   37|  2.03k|  if (too_large.any()) {
  ------------------
  |  Branch (37:7): [True: 0, False: 2.03k]
  ------------------
   38|      0|    return false;
   39|      0|  }
   40|       |
   41|  2.03k|  const auto surrogate = currentoffsetmax > standardoffsetmax;
   42|  2.03k|  if (surrogate.any()) {
  ------------------
  |  Branch (42:7): [True: 0, False: 2.03k]
  ------------------
   43|      0|    return false;
   44|      0|  }
   45|       |
   46|  2.03k|  return scalar::utf32::validate(input, end - input);
   47|  2.03k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf328validateEPKDim:
    6|  10.7k|simdutf_really_inline bool validate(const char32_t *input, size_t size) {
    7|  10.7k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   92|  10.7k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (92:33): [True: 9.17k, False: 1.52k]
  |  |  ------------------
  ------------------
    8|       |    // empty input is valid UTF-32. protect the implementation from
    9|       |    // handling nullptr
   10|  9.17k|    return true;
   11|  9.17k|  }
   12|       |
   13|  1.52k|  const char32_t *end = input + size;
   14|       |
   15|  1.52k|  using vector_u32 = simd32<uint32_t>;
   16|       |
   17|  1.52k|  const auto standardmax = vector_u32::splat(0x10ffff);
   18|  1.52k|  const auto offset = vector_u32::splat(0xffff2000);
   19|  1.52k|  const auto standardoffsetmax = vector_u32::splat(0xfffff7ff);
   20|  1.52k|  auto currentmax = vector_u32::zero();
   21|  1.52k|  auto currentoffsetmax = vector_u32::zero();
   22|       |
   23|  1.52k|  constexpr size_t N = vector_u32::ELEMENTS;
   24|       |
   25|  64.0k|  while (input + N < end) {
  ------------------
  |  Branch (25:10): [True: 62.5k, False: 1.52k]
  ------------------
   26|  62.5k|    auto in = vector_u32(input);
   27|  62.5k|    if constexpr (!match_system(endianness::BIG)) {
   28|  62.5k|      in.swap_bytes();
   29|  62.5k|    }
   30|       |
   31|  62.5k|    currentmax = max(currentmax, in);
   32|  62.5k|    currentoffsetmax = max(currentoffsetmax, in + offset);
   33|  62.5k|    input += N;
   34|  62.5k|  }
   35|       |
   36|  1.52k|  const auto too_large = currentmax > standardmax;
   37|  1.52k|  if (too_large.any()) {
  ------------------
  |  Branch (37:7): [True: 0, False: 1.52k]
  ------------------
   38|      0|    return false;
   39|      0|  }
   40|       |
   41|  1.52k|  const auto surrogate = currentoffsetmax > standardoffsetmax;
   42|  1.52k|  if (surrogate.any()) {
  ------------------
  |  Branch (42:7): [True: 0, False: 1.52k]
  ------------------
   43|      0|    return false;
   44|      0|  }
   45|       |
   46|  1.52k|  return scalar::utf32::validate(input, end - input);
   47|  1.52k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block64C2EPKc:
  507|  17.2k|  simdutf_really_inline block64(const char *src) {
  508|  17.2k|    chunks[0] = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src));
  509|  17.2k|    chunks[1] = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src + 32));
  510|  17.2k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6414compress_blockEmPc:
  687|  2.32k|  simdutf_really_inline uint64_t compress_block(uint64_t mask, char *output) {
  688|  2.32k|    if (is_power_of_two(mask)) {
  ------------------
  |  Branch (688:9): [True: 675, False: 1.65k]
  ------------------
  689|    675|      return compress_block_single(mask, output);
  690|    675|    }
  691|       |
  692|  1.65k|    uint64_t nmask = ~mask;
  693|  1.65k|    compress(chunks[0], uint32_t(mask), output);
  694|  1.65k|    compress(chunks[1], uint32_t(mask >> 32),
  695|  1.65k|             output + count_ones(nmask & 0xFFFFFFFF));
  696|  1.65k|    return count_ones(nmask);
  697|  2.32k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6421compress_block_singleEmPc:
  700|    675|                                                     char *output) {
  701|    675|    const size_t pos64 = trailing_zeroes(mask);
  702|    675|    const int8_t pos = pos64 & 0xf;
  703|    675|    switch (pos64 >> 4) {
  ------------------
  |  Branch (703:13): [True: 675, False: 0]
  ------------------
  704|    196|    case 0b00: {
  ------------------
  |  Branch (704:5): [True: 196, False: 479]
  ------------------
  705|    196|      const __m128i lane0 = _mm256_extracti128_si256(chunks[0], 0);
  706|    196|      const __m128i lane1 = _mm256_extracti128_si256(chunks[0], 1);
  707|       |
  708|    196|      const __m128i v0 = _mm_set1_epi8(char(pos - 1));
  709|    196|      const __m128i v1 =
  710|    196|          _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  711|    196|      const __m128i v2 = _mm_cmpgt_epi8(v1, v0);
  712|    196|      const __m128i sh = _mm_sub_epi8(v1, v2);
  713|    196|      const __m128i compressed = _mm_shuffle_epi8(lane0, sh);
  714|       |
  715|    196|      _mm_storeu_si128((__m128i *)(output + 0 * 16), compressed);
  716|    196|      _mm_storeu_si128((__m128i *)(output + 1 * 16 - 1), lane1);
  717|    196|      _mm256_storeu_si256((__m256i *)(output + 2 * 16 - 1), chunks[1]);
  718|    196|    } break;
  719|    176|    case 0b01: {
  ------------------
  |  Branch (719:5): [True: 176, False: 499]
  ------------------
  720|    176|      const __m128i lane0 = _mm256_extracti128_si256(chunks[0], 0);
  721|    176|      const __m128i lane1 = _mm256_extracti128_si256(chunks[0], 1);
  722|    176|      _mm_storeu_si128((__m128i *)(output + 0 * 16), lane0);
  723|       |
  724|    176|      const __m128i v0 = _mm_set1_epi8(char(pos - 1));
  725|    176|      const __m128i v1 =
  726|    176|          _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  727|    176|      const __m128i v2 = _mm_cmpgt_epi8(v1, v0);
  728|    176|      const __m128i sh = _mm_sub_epi8(v1, v2);
  729|    176|      const __m128i compressed = _mm_shuffle_epi8(lane1, sh);
  730|       |
  731|    176|      _mm_storeu_si128((__m128i *)(output + 1 * 16), compressed);
  732|    176|      _mm256_storeu_si256((__m256i *)(output + 2 * 16 - 1), chunks[1]);
  733|    176|    } break;
  734|    150|    case 0b10: {
  ------------------
  |  Branch (734:5): [True: 150, False: 525]
  ------------------
  735|    150|      const __m128i lane2 = _mm256_extracti128_si256(chunks[1], 0);
  736|    150|      const __m128i lane3 = _mm256_extracti128_si256(chunks[1], 1);
  737|       |
  738|    150|      _mm256_storeu_si256((__m256i *)(output + 0 * 16), chunks[0]);
  739|       |
  740|    150|      const __m128i v0 = _mm_set1_epi8(char(pos - 1));
  741|    150|      const __m128i v1 =
  742|    150|          _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  743|    150|      const __m128i v2 = _mm_cmpgt_epi8(v1, v0);
  744|    150|      const __m128i sh = _mm_sub_epi8(v1, v2);
  745|    150|      const __m128i compressed = _mm_shuffle_epi8(lane2, sh);
  746|       |
  747|    150|      _mm_storeu_si128((__m128i *)(output + 2 * 16), compressed);
  748|    150|      _mm_storeu_si128((__m128i *)(output + 3 * 16 - 1), lane3);
  749|    150|    } break;
  750|    153|    case 0b11: {
  ------------------
  |  Branch (750:5): [True: 153, False: 522]
  ------------------
  751|    153|      const __m128i lane2 = _mm256_extracti128_si256(chunks[1], 0);
  752|    153|      const __m128i lane3 = _mm256_extracti128_si256(chunks[1], 1);
  753|       |
  754|    153|      _mm256_storeu_si256((__m256i *)(output + 0 * 16), chunks[0]);
  755|    153|      _mm_storeu_si128((__m128i *)(output + 2 * 16), lane2);
  756|       |
  757|    153|      const __m128i v0 = _mm_set1_epi8(char(pos - 1));
  758|    153|      const __m128i v1 =
  759|    153|          _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  760|    153|      const __m128i v2 = _mm_cmpgt_epi8(v1, v0);
  761|    153|      const __m128i sh = _mm_sub_epi8(v1, v2);
  762|    153|      const __m128i compressed = _mm_shuffle_epi8(lane3, sh);
  763|       |
  764|    153|      _mm_storeu_si128((__m128i *)(output + 3 * 16), compressed);
  765|    153|    } break;
  766|    675|    }
  767|       |
  768|    675|    return 63;
  769|    675|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_18compressIvEEvDv4_xjPc:
  455|  3.30k|simdutf_really_inline void compress(__m256i data, uint32_t mask, char *output) {
  456|  3.30k|  if (mask == 0) {
  ------------------
  |  Branch (456:7): [True: 639, False: 2.66k]
  ------------------
  457|    639|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(output), data);
  458|    639|    return;
  459|    639|  }
  460|  2.66k|  compress(_mm256_castsi256_si128(data), uint16_t(mask), output);
  461|       |  compress(_mm256_extracti128_si256(data, 1), uint16_t(mask >> 16),
  462|  2.66k|           output + count_ones(~mask & 0xFFFF));
  463|  2.66k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_18compressEDv2_xtPc:
  418|  5.33k|static inline void compress(__m128i data, uint16_t mask, char *output) {
  419|  5.33k|  if (mask == 0) {
  ------------------
  |  Branch (419:7): [True: 1.36k, False: 3.96k]
  ------------------
  420|  1.36k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(output), data);
  421|  1.36k|    return;
  422|  1.36k|  }
  423|       |  // this particular implementation was inspired by work done by @animetosho
  424|       |  // we do it in two steps, first 8 bytes and then second 8 bytes
  425|  3.96k|  uint8_t mask1 = uint8_t(mask);      // least significant 8 bits
  426|  3.96k|  uint8_t mask2 = uint8_t(mask >> 8); // most significant 8 bits
  427|       |  // next line just loads the 64-bit values thintable_epi8[mask1] and
  428|       |  // thintable_epi8[mask2] into a 128-bit register, using only
  429|       |  // two instructions on most compilers.
  430|       |
  431|  3.96k|  __m128i shufmask = _mm_set_epi64x(tables::base64::thintable_epi8[mask2],
  432|  3.96k|                                    tables::base64::thintable_epi8[mask1]);
  433|       |  // we increment by 0x08 the second half of the mask
  434|  3.96k|  shufmask =
  435|  3.96k|      _mm_add_epi8(shufmask, _mm_set_epi32(0x08080808, 0x08080808, 0, 0));
  436|       |  // this is the version "nearly pruned"
  437|  3.96k|  __m128i pruned = _mm_shuffle_epi8(data, shufmask);
  438|       |  // we still need to put the two halves together.
  439|       |  // we compute the popcount of the first half:
  440|  3.96k|  int pop1 = tables::base64::BitsSetTable256mul2[mask1];
  441|       |  // then load the corresponding mask, what it does is to write
  442|       |  // only the first pop1 bytes from the first 8 bytes, and then
  443|       |  // it fills in with the bytes from the second 8 bytes + some filling
  444|       |  // at the end.
  445|  3.96k|  __m128i compactmask = _mm_loadu_si128(reinterpret_cast<const __m128i *>(
  446|  3.96k|      tables::base64::pshufb_combine_table + pop1 * 8));
  447|  3.96k|  __m128i answer = _mm_shuffle_epi8(pruned, compactmask);
  448|       |
  449|  3.96k|  _mm_storeu_si128(reinterpret_cast<__m128i *>(output), answer);
  450|  3.96k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6410copy_blockEPc:
  532|    326|  simdutf_really_inline void copy_block(char *output) {
  533|    326|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(output), chunks[0]);
  534|    326|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(output + 32), chunks[1]);
  535|    326|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6424base64_decode_block_safeEPc:
  543|    836|  simdutf_really_inline void base64_decode_block_safe(char *out) {
  544|    836|    base64_decode(out, chunks[0]);
  545|    836|    alignas(32) char buffer[32]; // We enforce safety with a buffer.
  546|    836|    base64_decode(buffer, chunks[1]);
  547|    836|    std::memcpy(out + 24, buffer, 24);
  548|    836|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113base64_decodeIvEEvPcDv4_x:
  466|  30.7k|simdutf_really_inline void base64_decode(char *out, __m256i str) {
  467|       |  // credit: aqrit
  468|  30.7k|  const __m256i pack_shuffle =
  469|  30.7k|      _mm256_setr_epi8(2, 1, 0, 6, 5, 4, 10, 9, 8, 14, 13, 12, -1, -1, -1, -1,
  470|  30.7k|                       2, 1, 0, 6, 5, 4, 10, 9, 8, 14, 13, 12, -1, -1, -1, -1);
  471|  30.7k|  const __m256i t0 = _mm256_maddubs_epi16(str, _mm256_set1_epi32(0x01400140));
  472|  30.7k|  const __m256i t1 = _mm256_madd_epi16(t0, _mm256_set1_epi32(0x00011000));
  473|  30.7k|  const __m256i t2 = _mm256_shuffle_epi8(t1, pack_shuffle);
  474|       |
  475|       |  // Store the output:
  476|  30.7k|  _mm_storeu_si128((__m128i *)out, _mm256_castsi256_si128(t2));
  477|       |  _mm_storeu_si128((__m128i *)(out + 12), _mm256_extracti128_si256(t2, 1));
  478|  30.7k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6419base64_decode_blockEPc:
  538|  12.8k|  simdutf_really_inline void base64_decode_block(char *out) {
  539|  12.8k|    base64_decode(out, chunks[0]);
  540|  12.8k|    base64_decode(out + 24, chunks[1]);
  541|  12.8k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_119base64_decode_blockIvEEvPcPKc:
  481|  1.64k|simdutf_really_inline void base64_decode_block(char *out, const char *src) {
  482|  1.64k|  base64_decode(out,
  483|  1.64k|                _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src)));
  484|  1.64k|  base64_decode(out + 24, _mm256_loadu_si256(
  485|  1.64k|                              reinterpret_cast<const __m256i *>(src + 32)));
  486|  1.64k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_124base64_decode_block_safeIvEEvPcPKc:
  490|     50|                                                    const char *src) {
  491|     50|  base64_decode(out,
  492|     50|                _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src)));
  493|     50|  alignas(32) char buffer[32]; // We enforce safety with a buffer.
  494|     50|  base64_decode(
  495|     50|      buffer, _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src + 32)));
  496|     50|  std::memcpy(out + 24, buffer, 24);
  497|     50|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6414to_base64_maskILb0ELb0ELb0EEEmPm:
  551|  17.2k|  simdutf_really_inline uint64_t to_base64_mask(uint64_t *error) {
  552|  17.2k|    uint32_t err0 = 0;
  553|  17.2k|    uint32_t err1 = 0;
  554|  17.2k|    uint64_t m0 = to_base64_mask<base64_url, ignore_garbage, default_or_url>(
  555|  17.2k|        &chunks[0], &err0);
  556|  17.2k|    uint64_t m1 = to_base64_mask<base64_url, ignore_garbage, default_or_url>(
  557|  17.2k|        &chunks[1], &err1);
  558|  17.2k|    if (!ignore_garbage) {
  ------------------
  |  Branch (558:9): [True: 17.2k, Folded]
  ------------------
  559|  17.2k|      *error = err0 | ((uint64_t)err1 << 32);
  560|  17.2k|    }
  561|  17.2k|    return m0 | (m1 << 32);
  562|  17.2k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6414to_base64_maskILb0ELb0ELb0EEEjPDv4_xPj:
  565|  34.4k|  simdutf_really_inline uint32_t to_base64_mask(__m256i *src, uint32_t *error) {
  566|  34.4k|    const __m256i ascii_space_tbl =
  567|  34.4k|        _mm256_setr_epi8(0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9, 0xa,
  568|  34.4k|                         0x0, 0xc, 0xd, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0,
  569|  34.4k|                         0x0, 0x0, 0x0, 0x9, 0xa, 0x0, 0xc, 0xd, 0x0, 0x0);
  570|       |    // credit: aqrit
  571|  34.4k|    __m256i delta_asso;
  572|  34.4k|    if (default_or_url) {
  ------------------
  |  Branch (572:9): [Folded, False: 34.4k]
  ------------------
  573|      0|      delta_asso = _mm256_setr_epi8(
  574|      0|          0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
  575|      0|          0x00, 0x00, 0x11, 0x00, 0x16, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  576|      0|          0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x16);
  577|  34.4k|    } else if (base64_url) {
  ------------------
  |  Branch (577:16): [Folded, False: 34.4k]
  ------------------
  578|      0|      delta_asso = _mm256_setr_epi8(0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0,
  579|      0|                                    0x0, 0x0, 0x0, 0x0, 0xF, 0x0, 0xF, 0x1, 0x1,
  580|      0|                                    0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0,
  581|      0|                                    0x0, 0x0, 0xF, 0x0, 0xF);
  582|  34.4k|    } else {
  583|  34.4k|      delta_asso = _mm256_setr_epi8(
  584|  34.4k|          0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
  585|  34.4k|          0x00, 0x00, 0x0F, 0x00, 0x0F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  586|  34.4k|          0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x0F);
  587|  34.4k|    }
  588|       |
  589|  34.4k|    __m256i delta_values;
  590|  34.4k|    if (default_or_url) {
  ------------------
  |  Branch (590:9): [Folded, False: 34.4k]
  ------------------
  591|      0|      delta_values = _mm256_setr_epi8(
  592|      0|          uint8_t(0xBF), uint8_t(0xE0), uint8_t(0xB9), uint8_t(0x13),
  593|      0|          uint8_t(0x04), uint8_t(0xBF), uint8_t(0xBF), uint8_t(0xB9),
  594|      0|          uint8_t(0xB9), uint8_t(0x00), uint8_t(0xFF), uint8_t(0x11),
  595|      0|          uint8_t(0xFF), uint8_t(0xBF), uint8_t(0x10), uint8_t(0xB9),
  596|      0|          uint8_t(0xBF), uint8_t(0xE0), uint8_t(0xB9), uint8_t(0x13),
  597|      0|          uint8_t(0x04), uint8_t(0xBF), uint8_t(0xBF), uint8_t(0xB9),
  598|      0|          uint8_t(0xB9), uint8_t(0x00), uint8_t(0xFF), uint8_t(0x11),
  599|      0|          uint8_t(0xFF), uint8_t(0xBF), uint8_t(0x10), uint8_t(0xB9));
  600|  34.4k|    } else if (base64_url) {
  ------------------
  |  Branch (600:16): [Folded, False: 34.4k]
  ------------------
  601|      0|      delta_values = _mm256_setr_epi8(
  602|      0|          0x0, 0x0, 0x0, 0x13, 0x4, uint8_t(0xBF), uint8_t(0xBF), uint8_t(0xB9),
  603|      0|          uint8_t(0xB9), 0x0, 0x11, uint8_t(0xC3), uint8_t(0xBF), uint8_t(0xE0),
  604|      0|          uint8_t(0xB9), uint8_t(0xB9), 0x0, 0x0, 0x0, 0x13, 0x4, uint8_t(0xBF),
  605|      0|          uint8_t(0xBF), uint8_t(0xB9), uint8_t(0xB9), 0x0, 0x11, uint8_t(0xC3),
  606|      0|          uint8_t(0xBF), uint8_t(0xE0), uint8_t(0xB9), uint8_t(0xB9));
  607|  34.4k|    } else {
  608|  34.4k|      delta_values = _mm256_setr_epi8(
  609|  34.4k|          int8_t(0x00), int8_t(0x00), int8_t(0x00), int8_t(0x13), int8_t(0x04),
  610|  34.4k|          int8_t(0xBF), int8_t(0xBF), int8_t(0xB9), int8_t(0xB9), int8_t(0x00),
  611|  34.4k|          int8_t(0x10), int8_t(0xC3), int8_t(0xBF), int8_t(0xBF), int8_t(0xB9),
  612|  34.4k|          int8_t(0xB9), int8_t(0x00), int8_t(0x00), int8_t(0x00), int8_t(0x13),
  613|  34.4k|          int8_t(0x04), int8_t(0xBF), int8_t(0xBF), int8_t(0xB9), int8_t(0xB9),
  614|  34.4k|          int8_t(0x00), int8_t(0x10), int8_t(0xC3), int8_t(0xBF), int8_t(0xBF),
  615|  34.4k|          int8_t(0xB9), int8_t(0xB9));
  616|  34.4k|    }
  617|       |
  618|  34.4k|    __m256i check_asso;
  619|  34.4k|    if (default_or_url) {
  ------------------
  |  Branch (619:9): [Folded, False: 34.4k]
  ------------------
  620|      0|      check_asso = _mm256_setr_epi8(
  621|      0|          0x0D, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03,
  622|      0|          0x07, 0x0B, 0x0E, 0x0B, 0x06, 0x0D, 0x01, 0x01, 0x01, 0x01, 0x01,
  623|      0|          0x01, 0x01, 0x01, 0x01, 0x03, 0x07, 0x0B, 0x0E, 0x0B, 0x06);
  624|  34.4k|    } else if (base64_url) {
  ------------------
  |  Branch (624:16): [Folded, False: 34.4k]
  ------------------
  625|      0|      check_asso = _mm256_setr_epi8(0xD, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
  626|      0|                                    0x1, 0x3, 0x7, 0xB, 0xE, 0xB, 0x6, 0xD, 0x1,
  627|      0|                                    0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x3,
  628|      0|                                    0x7, 0xB, 0xE, 0xB, 0x6);
  629|  34.4k|    } else {
  630|  34.4k|      check_asso = _mm256_setr_epi8(
  631|  34.4k|          0x0D, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03,
  632|  34.4k|          0x07, 0x0B, 0x0B, 0x0B, 0x0F, 0x0D, 0x01, 0x01, 0x01, 0x01, 0x01,
  633|  34.4k|          0x01, 0x01, 0x01, 0x01, 0x03, 0x07, 0x0B, 0x0B, 0x0B, 0x0F);
  634|  34.4k|    }
  635|  34.4k|    __m256i check_values;
  636|  34.4k|    if (default_or_url) {
  ------------------
  |  Branch (636:9): [Folded, False: 34.4k]
  ------------------
  637|      0|      check_values = _mm256_setr_epi8(
  638|      0|          uint8_t(0x80), uint8_t(0x80), uint8_t(0x80), uint8_t(0x80),
  639|      0|          uint8_t(0xCF), uint8_t(0xBF), uint8_t(0xD5), uint8_t(0xA6),
  640|      0|          uint8_t(0xB5), uint8_t(0xA1), uint8_t(0x00), uint8_t(0x80),
  641|      0|          uint8_t(0x00), uint8_t(0x80), uint8_t(0x00), uint8_t(0x80),
  642|      0|          uint8_t(0x80), uint8_t(0x80), uint8_t(0x80), uint8_t(0x80),
  643|      0|          uint8_t(0xCF), uint8_t(0xBF), uint8_t(0xD5), uint8_t(0xA6),
  644|      0|          uint8_t(0xB5), uint8_t(0xA1), uint8_t(0x00), uint8_t(0x80),
  645|      0|          uint8_t(0x00), uint8_t(0x80), uint8_t(0x00), uint8_t(0x80));
  646|  34.4k|    } else if (base64_url) {
  ------------------
  |  Branch (646:16): [Folded, False: 34.4k]
  ------------------
  647|      0|      check_values = _mm256_setr_epi8(
  648|      0|          uint8_t(0x80), uint8_t(0x80), uint8_t(0x80), uint8_t(0x80),
  649|      0|          uint8_t(0xCF), uint8_t(0xBF), uint8_t(0xB6), uint8_t(0xA6),
  650|      0|          uint8_t(0xB5), uint8_t(0xA1), 0x0, uint8_t(0x80), 0x0, uint8_t(0x80),
  651|      0|          0x0, uint8_t(0x80), uint8_t(0x80), uint8_t(0x80), uint8_t(0x80),
  652|      0|          uint8_t(0x80), uint8_t(0xCF), uint8_t(0xBF), uint8_t(0xB6),
  653|      0|          uint8_t(0xA6), uint8_t(0xB5), uint8_t(0xA1), 0x0, uint8_t(0x80), 0x0,
  654|      0|          uint8_t(0x80), 0x0, uint8_t(0x80));
  655|  34.4k|    } else {
  656|  34.4k|      check_values = _mm256_setr_epi8(
  657|  34.4k|          int8_t(0x80), int8_t(0x80), int8_t(0x80), int8_t(0x80), int8_t(0xCF),
  658|  34.4k|          int8_t(0xBF), int8_t(0xD5), int8_t(0xA6), int8_t(0xB5), int8_t(0x86),
  659|  34.4k|          int8_t(0xD1), int8_t(0x80), int8_t(0xB1), int8_t(0x80), int8_t(0x91),
  660|  34.4k|          int8_t(0x80), int8_t(0x80), int8_t(0x80), int8_t(0x80), int8_t(0x80),
  661|  34.4k|          int8_t(0xCF), int8_t(0xBF), int8_t(0xD5), int8_t(0xA6), int8_t(0xB5),
  662|  34.4k|          int8_t(0x86), int8_t(0xD1), int8_t(0x80), int8_t(0xB1), int8_t(0x80),
  663|  34.4k|          int8_t(0x91), int8_t(0x80));
  664|  34.4k|    }
  665|  34.4k|    const __m256i shifted = _mm256_srli_epi32(*src, 3);
  666|  34.4k|    __m256i delta_hash =
  667|  34.4k|        _mm256_avg_epu8(_mm256_shuffle_epi8(delta_asso, *src), shifted);
  668|  34.4k|    if (default_or_url) {
  ------------------
  |  Branch (668:9): [Folded, False: 34.4k]
  ------------------
  669|      0|      delta_hash = _mm256_and_si256(delta_hash, _mm256_set1_epi8(0xf));
  670|      0|    }
  671|  34.4k|    const __m256i check_hash =
  672|  34.4k|        _mm256_avg_epu8(_mm256_shuffle_epi8(check_asso, *src), shifted);
  673|  34.4k|    const __m256i out =
  674|  34.4k|        _mm256_adds_epi8(_mm256_shuffle_epi8(delta_values, delta_hash), *src);
  675|  34.4k|    const __m256i chk =
  676|  34.4k|        _mm256_adds_epi8(_mm256_shuffle_epi8(check_values, check_hash), *src);
  677|  34.4k|    const int mask = _mm256_movemask_epi8(chk);
  678|  34.4k|    if (!ignore_garbage && mask) {
  ------------------
  |  Branch (678:9): [True: 34.4k, Folded]
  |  Branch (678:28): [True: 5.05k, False: 29.4k]
  ------------------
  679|  5.05k|      __m256i ascii_space =
  680|  5.05k|          _mm256_cmpeq_epi8(_mm256_shuffle_epi8(ascii_space_tbl, *src), *src);
  681|  5.05k|      *error = (mask ^ _mm256_movemask_epi8(ascii_space));
  682|  5.05k|    }
  683|  34.4k|    *src = out;
  684|  34.4k|    return (uint32_t)mask;
  685|  34.4k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113encode_base64ILb0EEEmPcPKcmNS_14base64_optionsE:
  414|  15.1k|                     base64_options options) {
  415|  15.1k|  return avx2_encode_base64_impl<isbase64url, false>(dst, src, srclen, options);
  416|  15.1k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_123avx2_encode_base64_implILb0ELb0EEEmPcPKcmNS_14base64_optionsEm:
  156|  15.1k|                        size_t line_length = simdutf::default_line_length) {
  157|  15.1k|  size_t offset = 0;
  158|       |
  159|  15.1k|  if (line_length < 4) {
  ------------------
  |  Branch (159:7): [True: 0, False: 15.1k]
  ------------------
  160|      0|    line_length = 4; // We do not support line_length less than 4
  161|      0|  }
  162|       |  // credit: Wojciech Muła
  163|  15.1k|  const uint8_t *input = (const uint8_t *)src;
  164|       |
  165|  15.1k|  uint8_t *out = (uint8_t *)dst;
  166|  15.1k|  const __m256i shuf =
  167|  15.1k|      _mm256_set_epi8(10, 11, 9, 10, 7, 8, 6, 7, 4, 5, 3, 4, 1, 2, 0, 1,
  168|       |
  169|  15.1k|                      10, 11, 9, 10, 7, 8, 6, 7, 4, 5, 3, 4, 1, 2, 0, 1);
  170|  15.1k|  size_t i = 0;
  171|  17.2k|  for (; i + 100 <= srclen; i += 96) {
  ------------------
  |  Branch (171:10): [True: 2.08k, False: 15.1k]
  ------------------
  172|  2.08k|    const __m128i lo0 = _mm_loadu_si128(
  173|  2.08k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 0));
  174|  2.08k|    const __m128i hi0 = _mm_loadu_si128(
  175|  2.08k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 1));
  176|  2.08k|    const __m128i lo1 = _mm_loadu_si128(
  177|  2.08k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 2));
  178|  2.08k|    const __m128i hi1 = _mm_loadu_si128(
  179|  2.08k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 3));
  180|  2.08k|    const __m128i lo2 = _mm_loadu_si128(
  181|  2.08k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 4));
  182|  2.08k|    const __m128i hi2 = _mm_loadu_si128(
  183|  2.08k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 5));
  184|  2.08k|    const __m128i lo3 = _mm_loadu_si128(
  185|  2.08k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 6));
  186|  2.08k|    const __m128i hi3 = _mm_loadu_si128(
  187|  2.08k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 7));
  188|       |
  189|  2.08k|    __m256i in0 = _mm256_shuffle_epi8(_mm256_set_m128i(hi0, lo0), shuf);
  ------------------
  |  |    4|  2.08k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  2.08k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  190|  2.08k|    __m256i in1 = _mm256_shuffle_epi8(_mm256_set_m128i(hi1, lo1), shuf);
  ------------------
  |  |    4|  2.08k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  2.08k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  191|  2.08k|    __m256i in2 = _mm256_shuffle_epi8(_mm256_set_m128i(hi2, lo2), shuf);
  ------------------
  |  |    4|  2.08k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  2.08k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  192|  2.08k|    __m256i in3 = _mm256_shuffle_epi8(_mm256_set_m128i(hi3, lo3), shuf);
  ------------------
  |  |    4|  2.08k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  2.08k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  193|       |
  194|  2.08k|    const __m256i t0_0 = _mm256_and_si256(in0, _mm256_set1_epi32(0x0fc0fc00));
  195|  2.08k|    const __m256i t0_1 = _mm256_and_si256(in1, _mm256_set1_epi32(0x0fc0fc00));
  196|  2.08k|    const __m256i t0_2 = _mm256_and_si256(in2, _mm256_set1_epi32(0x0fc0fc00));
  197|  2.08k|    const __m256i t0_3 = _mm256_and_si256(in3, _mm256_set1_epi32(0x0fc0fc00));
  198|       |
  199|  2.08k|    const __m256i t1_0 =
  200|  2.08k|        _mm256_mulhi_epu16(t0_0, _mm256_set1_epi32(0x04000040));
  201|  2.08k|    const __m256i t1_1 =
  202|  2.08k|        _mm256_mulhi_epu16(t0_1, _mm256_set1_epi32(0x04000040));
  203|  2.08k|    const __m256i t1_2 =
  204|  2.08k|        _mm256_mulhi_epu16(t0_2, _mm256_set1_epi32(0x04000040));
  205|  2.08k|    const __m256i t1_3 =
  206|  2.08k|        _mm256_mulhi_epu16(t0_3, _mm256_set1_epi32(0x04000040));
  207|       |
  208|  2.08k|    const __m256i t2_0 = _mm256_and_si256(in0, _mm256_set1_epi32(0x003f03f0));
  209|  2.08k|    const __m256i t2_1 = _mm256_and_si256(in1, _mm256_set1_epi32(0x003f03f0));
  210|  2.08k|    const __m256i t2_2 = _mm256_and_si256(in2, _mm256_set1_epi32(0x003f03f0));
  211|  2.08k|    const __m256i t2_3 = _mm256_and_si256(in3, _mm256_set1_epi32(0x003f03f0));
  212|       |
  213|  2.08k|    const __m256i t3_0 =
  214|  2.08k|        _mm256_mullo_epi16(t2_0, _mm256_set1_epi32(0x01000010));
  215|  2.08k|    const __m256i t3_1 =
  216|  2.08k|        _mm256_mullo_epi16(t2_1, _mm256_set1_epi32(0x01000010));
  217|  2.08k|    const __m256i t3_2 =
  218|  2.08k|        _mm256_mullo_epi16(t2_2, _mm256_set1_epi32(0x01000010));
  219|  2.08k|    const __m256i t3_3 =
  220|  2.08k|        _mm256_mullo_epi16(t2_3, _mm256_set1_epi32(0x01000010));
  221|       |
  222|  2.08k|    const __m256i input0 = _mm256_or_si256(t1_0, t3_0);
  223|  2.08k|    const __m256i input1 = _mm256_or_si256(t1_1, t3_1);
  224|  2.08k|    const __m256i input2 = _mm256_or_si256(t1_2, t3_2);
  225|  2.08k|    const __m256i input3 = _mm256_or_si256(t1_3, t3_3);
  226|       |
  227|  2.08k|    if (use_lines) {
  ------------------
  |  Branch (227:9): [Folded, False: 2.08k]
  ------------------
  228|      0|      if (line_length >= 32) { // fast path
  ------------------
  |  Branch (228:11): [True: 0, False: 0]
  ------------------
  229|      0|        __m256i result;
  230|      0|        result = lookup_pshufb_improved<isbase64url>(input0);
  231|      0|        if (offset + 32 > line_length) {
  ------------------
  |  Branch (231:13): [True: 0, False: 0]
  ------------------
  232|      0|          size_t location_end = line_length - offset;
  233|      0|          size_t to_move = 32 - location_end;
  234|       |          // We could do this, or extract instead.
  235|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 1), result);
  236|      0|          _mm256_storeu_si256(
  237|      0|              reinterpret_cast<__m256i *>(out),
  238|      0|              insert_line_feed32(result, static_cast<int>(location_end)));
  239|      0|          offset = to_move;
  240|      0|          out += 32 + 1;
  241|      0|        } else {
  242|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), result);
  243|      0|          offset += 32;
  244|      0|          out += 32;
  245|      0|        }
  246|      0|        result = lookup_pshufb_improved<isbase64url>(input1);
  247|       |
  248|      0|        if (offset + 32 > line_length) {
  ------------------
  |  Branch (248:13): [True: 0, False: 0]
  ------------------
  249|      0|          size_t location_end = line_length - offset;
  250|      0|          size_t to_move = 32 - location_end;
  251|       |
  252|       |          // We could do this, or extract instead.
  253|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 1), result);
  254|      0|          _mm256_storeu_si256(
  255|      0|              reinterpret_cast<__m256i *>(out),
  256|      0|              insert_line_feed32(result, static_cast<int>(location_end)));
  257|       |          // see above.
  258|       |          // out[32] = static_cast<uint8_t>(_mm256_extract_epi8(result, 31));
  259|      0|          offset = to_move;
  260|      0|          out += 32 + 1;
  261|      0|        } else {
  262|       |
  263|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), result);
  264|       |
  265|      0|          offset += 32;
  266|      0|          out += 32;
  267|      0|        }
  268|      0|        result = lookup_pshufb_improved<isbase64url>(input2);
  269|       |
  270|      0|        if (offset + 32 > line_length) {
  ------------------
  |  Branch (270:13): [True: 0, False: 0]
  ------------------
  271|      0|          size_t location_end = line_length - offset;
  272|      0|          size_t to_move = 32 - location_end;
  273|       |
  274|       |          // We could do this, or extract instead.
  275|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 1), result);
  276|      0|          _mm256_storeu_si256(
  277|      0|              reinterpret_cast<__m256i *>(out),
  278|      0|              insert_line_feed32(result, static_cast<int>(location_end)));
  279|       |          // see above.
  280|       |          // out[32] = static_cast<uint8_t>(_mm256_extract_epi8(result, 31));
  281|      0|          offset = to_move;
  282|      0|          out += 32 + 1;
  283|      0|        } else {
  284|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), result);
  285|      0|          offset += 32;
  286|      0|          out += 32;
  287|      0|        }
  288|      0|        result = lookup_pshufb_improved<isbase64url>(input3);
  289|       |
  290|      0|        if (offset + 32 > line_length) {
  ------------------
  |  Branch (290:13): [True: 0, False: 0]
  ------------------
  291|      0|          size_t location_end = line_length - offset;
  292|      0|          size_t to_move = 32 - location_end;
  293|       |
  294|       |          // We could do this, or extract instead.
  295|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 1), result);
  296|      0|          _mm256_storeu_si256(
  297|      0|              reinterpret_cast<__m256i *>(out),
  298|      0|              insert_line_feed32(result, static_cast<int>(location_end)));
  299|       |          // see above.
  300|       |          // out[32] = static_cast<uint8_t>(_mm256_extract_epi8(result, 31));
  301|      0|          offset = to_move;
  302|      0|          out += 32 + 1;
  303|      0|        } else {
  304|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), result);
  305|      0|          offset += 32;
  306|      0|          out += 32;
  307|      0|        }
  308|      0|      } else { // slow path
  309|       |        // could be optimized
  310|      0|        uint8_t buffer[128];
  311|      0|        _mm256_storeu_si256(reinterpret_cast<__m256i *>(buffer),
  312|      0|                            lookup_pshufb_improved<isbase64url>(input0));
  313|      0|        _mm256_storeu_si256(reinterpret_cast<__m256i *>(buffer + 32),
  314|      0|                            lookup_pshufb_improved<isbase64url>(input1));
  315|      0|        _mm256_storeu_si256(reinterpret_cast<__m256i *>(buffer + 64),
  316|      0|                            lookup_pshufb_improved<isbase64url>(input2));
  317|      0|        _mm256_storeu_si256(reinterpret_cast<__m256i *>(buffer + 96),
  318|      0|                            lookup_pshufb_improved<isbase64url>(input3));
  319|      0|        size_t out_pos = 0;
  320|      0|        size_t local_offset = offset;
  321|      0|        for (size_t j = 0; j < 128;) {
  ------------------
  |  Branch (321:28): [True: 0, False: 0]
  ------------------
  322|      0|          if (local_offset == line_length) {
  ------------------
  |  Branch (322:15): [True: 0, False: 0]
  ------------------
  323|      0|            out[out_pos++] = '\n';
  324|      0|            local_offset = 0;
  325|      0|          }
  326|      0|          out[out_pos++] = buffer[j++];
  327|      0|          local_offset++;
  328|      0|        }
  329|      0|        offset = local_offset;
  330|      0|        out += out_pos;
  331|      0|      }
  332|  2.08k|    } else {
  333|  2.08k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(out),
  334|  2.08k|                          lookup_pshufb_improved<isbase64url>(input0));
  335|  2.08k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 32),
  336|  2.08k|                          lookup_pshufb_improved<isbase64url>(input1));
  337|  2.08k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 64),
  338|  2.08k|                          lookup_pshufb_improved<isbase64url>(input2));
  339|  2.08k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 96),
  340|  2.08k|                          lookup_pshufb_improved<isbase64url>(input3));
  341|       |
  342|  2.08k|      out += 128;
  343|  2.08k|    }
  344|  2.08k|  }
  345|  16.8k|  for (; i + 28 <= srclen; i += 24) {
  ------------------
  |  Branch (345:10): [True: 1.66k, False: 15.1k]
  ------------------
  346|       |    // lo = [xxxx|DDDC|CCBB|BAAA]
  347|       |    // hi = [xxxx|HHHG|GGFF|FEEE]
  348|  1.66k|    const __m128i lo =
  349|  1.66k|        _mm_loadu_si128(reinterpret_cast<const __m128i *>(input + i));
  350|  1.66k|    const __m128i hi =
  351|  1.66k|        _mm_loadu_si128(reinterpret_cast<const __m128i *>(input + i + 4 * 3));
  352|       |
  353|       |    // bytes from groups A, B and C are needed in separate 32-bit lanes
  354|       |    // in = [0HHH|0GGG|0FFF|0EEE[0DDD|0CCC|0BBB|0AAA]
  355|  1.66k|    __m256i in = _mm256_shuffle_epi8(_mm256_set_m128i(hi, lo), shuf);
  ------------------
  |  |    4|  1.66k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  1.66k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  356|       |
  357|       |    // this part is well commented in encode.sse.cpp
  358|       |
  359|  1.66k|    const __m256i t0 = _mm256_and_si256(in, _mm256_set1_epi32(0x0fc0fc00));
  360|  1.66k|    const __m256i t1 = _mm256_mulhi_epu16(t0, _mm256_set1_epi32(0x04000040));
  361|  1.66k|    const __m256i t2 = _mm256_and_si256(in, _mm256_set1_epi32(0x003f03f0));
  362|  1.66k|    const __m256i t3 = _mm256_mullo_epi16(t2, _mm256_set1_epi32(0x01000010));
  363|  1.66k|    const __m256i indices = _mm256_or_si256(t1, t3);
  364|       |
  365|  1.66k|    if (use_lines) {
  ------------------
  |  Branch (365:9): [Folded, False: 1.66k]
  ------------------
  366|      0|      if (line_length >= 32) { // fast path
  ------------------
  |  Branch (366:11): [True: 0, False: 0]
  ------------------
  367|      0|        _mm256_storeu_si256(reinterpret_cast<__m256i *>(out),
  368|      0|                            lookup_pshufb_improved<isbase64url>(indices));
  369|       |
  370|      0|        if (offset + 32 > line_length) {
  ------------------
  |  Branch (370:13): [True: 0, False: 0]
  ------------------
  371|      0|          size_t location_end = line_length - offset;
  372|      0|          size_t to_move = 32 - location_end;
  373|      0|          std::memmove(out + location_end + 1, out + location_end, to_move);
  374|      0|          out[location_end] = '\n';
  375|      0|          offset = to_move;
  376|      0|          out += 32 + 1;
  377|      0|        } else {
  378|      0|          offset += 32;
  379|      0|          out += 32;
  380|      0|        }
  381|      0|      } else { // slow path
  382|       |        // could be optimized
  383|      0|        alignas(32) uint8_t buffer[32];
  384|      0|        _mm256_storeu_si256(reinterpret_cast<__m256i *>(buffer),
  385|      0|                            lookup_pshufb_improved<isbase64url>(indices));
  386|      0|        std::memcpy(out, buffer, 32);
  387|      0|        size_t out_pos = 0;
  388|      0|        size_t local_offset = offset;
  389|      0|        for (size_t j = 0; j < 32;) {
  ------------------
  |  Branch (389:28): [True: 0, False: 0]
  ------------------
  390|      0|          if (local_offset == line_length) {
  ------------------
  |  Branch (390:15): [True: 0, False: 0]
  ------------------
  391|      0|            out[out_pos++] = '\n';
  392|      0|            local_offset = 0;
  393|      0|          }
  394|      0|          out[out_pos++] = buffer[j++];
  395|      0|          local_offset++;
  396|      0|        }
  397|      0|        offset = local_offset;
  398|      0|        out += out_pos;
  399|      0|      }
  400|  1.66k|    } else {
  401|  1.66k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(out),
  402|  1.66k|                          lookup_pshufb_improved<isbase64url>(indices));
  403|       |
  404|  1.66k|      out += 32;
  405|  1.66k|    }
  406|  1.66k|  }
  407|  15.1k|  return ((char *)out - (char *)dst) +
  408|  15.1k|         scalar::base64::tail_encode_base64_impl<use_lines>(
  409|  15.1k|             (char *)out, src + i, srclen - i, options, line_length, offset);
  410|  15.1k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_122lookup_pshufb_improvedILb0EEEDv4_xS3_:
   30|  10.0k|simdutf_really_inline __m256i lookup_pshufb_improved(const __m256i input) {
   31|       |  // Precomputed shuffle masks for K = 1 to 16
   32|       |  // credit: Wojciech Muła
   33|  10.0k|  __m256i result = _mm256_subs_epu8(input, _mm256_set1_epi8(51));
   34|  10.0k|  const __m256i less = _mm256_cmpgt_epi8(_mm256_set1_epi8(26), input);
   35|  10.0k|  result =
   36|  10.0k|      _mm256_or_si256(result, _mm256_and_si256(less, _mm256_set1_epi8(13)));
   37|  10.0k|  __m256i shift_LUT;
   38|  10.0k|  if (base64_url) {
  ------------------
  |  Branch (38:7): [Folded, False: 10.0k]
  ------------------
   39|      0|    shift_LUT = _mm256_setr_epi8(
   40|      0|        'a' - 26, '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52,
   41|      0|        '0' - 52, '0' - 52, '0' - 52, '0' - 52, '-' - 62, '_' - 63, 'A', 0, 0,
   42|       |
   43|      0|        'a' - 26, '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52,
   44|      0|        '0' - 52, '0' - 52, '0' - 52, '0' - 52, '-' - 62, '_' - 63, 'A', 0, 0);
   45|  10.0k|  } else {
   46|  10.0k|    shift_LUT = _mm256_setr_epi8(
   47|  10.0k|        'a' - 26, '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52,
   48|  10.0k|        '0' - 52, '0' - 52, '0' - 52, '0' - 52, '+' - 62, '/' - 63, 'A', 0, 0,
   49|       |
   50|  10.0k|        'a' - 26, '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52,
   51|  10.0k|        '0' - 52, '0' - 52, '0' - 52, '0' - 52, '+' - 62, '/' - 63, 'A', 0, 0);
   52|  10.0k|  }
   53|       |
   54|  10.0k|  result = _mm256_shuffle_epi8(shift_LUT, result);
   55|  10.0k|  return _mm256_add_epi8(result, input);
   56|  10.0k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128avx2_convert_latin1_to_utf16ILNS_10endiannessE0EEENSt3__14pairIPKcPDsEES7_mS8_:
    4|  5.56k|                             char16_t *utf16_output) {
    5|  5.56k|  size_t rounded_len = len & ~0xF; // Round down to nearest multiple of 16
    6|       |
    7|  5.56k|  size_t i = 0;
    8|  14.9k|  for (; i < rounded_len; i += 16) {
  ------------------
  |  Branch (8:10): [True: 9.36k, False: 5.56k]
  ------------------
    9|       |    // Load 16 bytes from the address (input + i) into a xmm register
   10|  9.36k|    const __m128i latin1 =
   11|  9.36k|        _mm_loadu_si128(reinterpret_cast<const __m128i *>(latin1_input + i));
   12|       |
   13|       |    // Zero extend each byte in `in` to word
   14|  9.36k|    __m256i utf16 = _mm256_cvtepu8_epi16(latin1);
   15|       |
   16|  9.36k|    if (big_endian) {
  ------------------
  |  Branch (16:9): [Folded, False: 9.36k]
  ------------------
   17|      0|      const __m128i swap128 =
   18|      0|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   19|      0|      const __m256i swap = _mm256_set_m128i(swap128, swap128);
  ------------------
  |  |    4|      0|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|      0|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
   20|      0|      utf16 = _mm256_shuffle_epi8(utf16, swap);
   21|      0|    }
   22|       |
   23|       |    // Store the contents of xmm1 into the address pointed by (output + i)
   24|  9.36k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(utf16_output + i), utf16);
   25|  9.36k|  }
   26|       |
   27|  5.56k|  return std::make_pair(latin1_input + rounded_len, utf16_output + rounded_len);
   28|  5.56k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128avx2_convert_latin1_to_utf16ILNS_10endiannessE1EEENSt3__14pairIPKcPDsEES7_mS8_:
    4|  5.56k|                             char16_t *utf16_output) {
    5|  5.56k|  size_t rounded_len = len & ~0xF; // Round down to nearest multiple of 16
    6|       |
    7|  5.56k|  size_t i = 0;
    8|  14.9k|  for (; i < rounded_len; i += 16) {
  ------------------
  |  Branch (8:10): [True: 9.36k, False: 5.56k]
  ------------------
    9|       |    // Load 16 bytes from the address (input + i) into a xmm register
   10|  9.36k|    const __m128i latin1 =
   11|  9.36k|        _mm_loadu_si128(reinterpret_cast<const __m128i *>(latin1_input + i));
   12|       |
   13|       |    // Zero extend each byte in `in` to word
   14|  9.36k|    __m256i utf16 = _mm256_cvtepu8_epi16(latin1);
   15|       |
   16|  9.36k|    if (big_endian) {
  ------------------
  |  Branch (16:9): [True: 9.36k, Folded]
  ------------------
   17|  9.36k|      const __m128i swap128 =
   18|  9.36k|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   19|  9.36k|      const __m256i swap = _mm256_set_m128i(swap128, swap128);
  ------------------
  |  |    4|  9.36k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  9.36k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
   20|  9.36k|      utf16 = _mm256_shuffle_epi8(utf16, swap);
   21|  9.36k|    }
   22|       |
   23|       |    // Store the contents of xmm1 into the address pointed by (output + i)
   24|  9.36k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(utf16_output + i), utf16);
   25|  9.36k|  }
   26|       |
   27|  5.56k|  return std::make_pair(latin1_input + rounded_len, utf16_output + rounded_len);
   28|  5.56k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128avx2_convert_latin1_to_utf32EPKcmPDi:
    3|  5.56k|                             char32_t *utf32_output) {
    4|  5.56k|  size_t rounded_len = ((len | 7) ^ 7); // Round down to nearest multiple of 8
    5|       |
    6|  24.5k|  for (size_t i = 0; i < rounded_len; i += 8) {
  ------------------
  |  Branch (6:22): [True: 18.9k, False: 5.56k]
  ------------------
    7|       |    // Load 8 Latin1 characters into a 64-bit register
    8|  18.9k|    __m128i in = _mm_loadl_epi64((__m128i *)&buf[i]);
    9|       |
   10|       |    // Zero extend each set of 8 Latin1 characters to 8 32-bit integers using
   11|       |    // vpmovzxbd
   12|  18.9k|    __m256i out = _mm256_cvtepu8_epi32(in);
   13|       |
   14|       |    // Store the results back to memory
   15|  18.9k|    _mm256_storeu_si256((__m256i *)&utf32_output[i], out);
   16|  18.9k|  }
   17|       |
   18|       |  // return pointers pointing to where we left off
   19|  5.56k|  return std::make_pair(buf + rounded_len, utf32_output + rounded_len);
   20|  5.56k|}

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128avx2_convert_utf16_to_latin1ILNS_10endiannessE0EEENSt3__14pairIPKDsPcEES7_mS8_:
    4|  5.56k|                             char *latin1_output) {
    5|  5.56k|  const char16_t *end = buf + len;
    6|  10.1k|  while (end - buf >= 32) {
  ------------------
  |  Branch (6:10): [True: 4.56k, False: 5.56k]
  ------------------
    7|       |    // Load 16 UTF-16 characters into 256-bit AVX2 register
    8|  4.56k|    __m256i in0 = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buf));
    9|  4.56k|    __m256i in1 =
   10|  4.56k|        _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buf + 16));
   11|       |
   12|       |    if constexpr (!match_system(big_endian)) {
   13|       |      const __m256i swap = _mm256_setr_epi8(
   14|       |          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   15|       |          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   16|       |      in0 = _mm256_shuffle_epi8(in0, swap);
   17|       |      in1 = _mm256_shuffle_epi8(in1, swap);
   18|       |    }
   19|       |
   20|  4.56k|    __m256i high_byte_mask = _mm256_set1_epi16((int16_t)0xFF00);
   21|  4.56k|    if (_mm256_testz_si256(_mm256_or_si256(in0, in1), high_byte_mask)) {
  ------------------
  |  Branch (21:9): [True: 4.56k, False: 0]
  ------------------
   22|       |      // Pack 16-bit characters into 8-bit and store in latin1_output
   23|  4.56k|      const __m256i packed = _mm256_packus_epi16(in0, in1);
   24|       |
   25|  4.56k|      const __m256i result = _mm256_permute4x64_epi64(packed, 0b11011000);
   26|       |
   27|  4.56k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(latin1_output), result);
   28|       |      // Adjust pointers for the next iteration
   29|  4.56k|      buf += 32;
   30|  4.56k|      latin1_output += 32;
   31|  4.56k|    } else {
   32|      0|      return std::make_pair(nullptr, reinterpret_cast<char *>(latin1_output));
   33|      0|    }
   34|  4.56k|  } // while
   35|  5.56k|  return std::make_pair(buf, latin1_output);
   36|  5.56k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128avx2_convert_utf16_to_latin1ILNS_10endiannessE1EEENSt3__14pairIPKDsPcEES7_mS8_:
    4|  5.56k|                             char *latin1_output) {
    5|  5.56k|  const char16_t *end = buf + len;
    6|  10.1k|  while (end - buf >= 32) {
  ------------------
  |  Branch (6:10): [True: 4.56k, False: 5.56k]
  ------------------
    7|       |    // Load 16 UTF-16 characters into 256-bit AVX2 register
    8|  4.56k|    __m256i in0 = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buf));
    9|  4.56k|    __m256i in1 =
   10|  4.56k|        _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buf + 16));
   11|       |
   12|  4.56k|    if constexpr (!match_system(big_endian)) {
   13|  4.56k|      const __m256i swap = _mm256_setr_epi8(
   14|  4.56k|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   15|  4.56k|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   16|  4.56k|      in0 = _mm256_shuffle_epi8(in0, swap);
   17|  4.56k|      in1 = _mm256_shuffle_epi8(in1, swap);
   18|  4.56k|    }
   19|       |
   20|  4.56k|    __m256i high_byte_mask = _mm256_set1_epi16((int16_t)0xFF00);
   21|  4.56k|    if (_mm256_testz_si256(_mm256_or_si256(in0, in1), high_byte_mask)) {
  ------------------
  |  Branch (21:9): [True: 4.56k, False: 0]
  ------------------
   22|       |      // Pack 16-bit characters into 8-bit and store in latin1_output
   23|  4.56k|      const __m256i packed = _mm256_packus_epi16(in0, in1);
   24|       |
   25|  4.56k|      const __m256i result = _mm256_permute4x64_epi64(packed, 0b11011000);
   26|       |
   27|  4.56k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(latin1_output), result);
   28|       |      // Adjust pointers for the next iteration
   29|  4.56k|      buf += 32;
   30|  4.56k|      latin1_output += 32;
   31|  4.56k|    } else {
   32|      0|      return std::make_pair(nullptr, reinterpret_cast<char *>(latin1_output));
   33|      0|    }
   34|  4.56k|  } // while
   35|  5.56k|  return std::make_pair(buf, latin1_output);
   36|  5.56k|}

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128avx2_convert_utf32_to_latin1EPKDimPc:
    3|  5.56k|                             char *latin1_output) {
    4|  5.56k|  const size_t rounded_len =
    5|  5.56k|      len & ~0x1F; // Round down to nearest multiple of 32
    6|       |
    7|  5.56k|  const __m256i high_bytes_mask = _mm256_set1_epi32(0xFFFFFF00);
    8|       |
    9|  10.1k|  for (size_t i = 0; i < rounded_len; i += 4 * 8) {
  ------------------
  |  Branch (9:22): [True: 4.56k, False: 5.56k]
  ------------------
   10|  4.56k|    __m256i a = _mm256_loadu_si256((__m256i *)(buf + 0 * 8));
   11|  4.56k|    __m256i b = _mm256_loadu_si256((__m256i *)(buf + 1 * 8));
   12|  4.56k|    __m256i c = _mm256_loadu_si256((__m256i *)(buf + 2 * 8));
   13|  4.56k|    __m256i d = _mm256_loadu_si256((__m256i *)(buf + 3 * 8));
   14|       |
   15|  4.56k|    const __m256i check_combined =
   16|  4.56k|        _mm256_or_si256(_mm256_or_si256(a, b), _mm256_or_si256(c, d));
   17|       |
   18|  4.56k|    if (!_mm256_testz_si256(check_combined, high_bytes_mask)) {
  ------------------
  |  Branch (18:9): [True: 0, False: 4.56k]
  ------------------
   19|      0|      return std::make_pair(nullptr, latin1_output);
   20|      0|    }
   21|       |
   22|  4.56k|    b = _mm256_slli_epi32(b, 1 * 8);
   23|  4.56k|    c = _mm256_slli_epi32(c, 2 * 8);
   24|  4.56k|    d = _mm256_slli_epi32(d, 3 * 8);
   25|       |
   26|       |    // clang-format off
   27|       |
   28|       |    // a  = [.. .. .. a7|.. .. .. a6|.. .. .. a5|.. .. .. a4||.. .. .. a3|.. .. .. a2|.. .. .. a1|.. .. .. a0]
   29|       |    // b  = [.. .. b7 ..|.. .. b6 ..|.. .. b5 ..|.. .. b4 ..||.. .. b3 ..|.. .. b2 ..|.. .. b1 ..|.. .. b0 ..]
   30|       |    // c  = [.. c7 .. ..|.. c6 .. ..|.. c5 .. ..|.. c4 .. ..||.. c3 .. ..|.. c2 .. ..|.. c1 .. ..|.. c0 .. ..]
   31|       |    // d  = [d7 .. .. ..|d6 .. .. ..|d5 .. .. ..|d4 .. .. ..||d3 .. .. ..|d2 .. .. ..|d1 .. .. ..|d0 .. .. ..]
   32|       |
   33|       |    // t0 = [d7 c7 b7 a7|d6 c6 b6 a6|d5 c5 b5 a5|d4 c4 b4 a4||d3 c3 b3 a3|d2 c2 b2 a2|d1 c1 b1 a1|d0 c0 b0 a0]
   34|  4.56k|    const __m256i t0 =
   35|  4.56k|        _mm256_or_si256(_mm256_or_si256(a, b), _mm256_or_si256(c, d));
   36|       |
   37|       |    // shuffle bytes within 128-bit lanes
   38|       |    // t1 = [d7 d6 d5 d4|c7 c6 c5 c4|b7 b6 b5 b4|a7 a6 a5 a4||d3 d2 d1 d0|c3 c2 c1 c0|b3 b2 b1 b0|a3 a2 a1 a0]
   39|  4.56k|    const __m256i shuffle_bytes =
   40|  4.56k|        _mm256_setr_epi8(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15,
   41|  4.56k|                         0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15);
   42|       |
   43|  4.56k|    const __m256i t1 = _mm256_shuffle_epi8(t0, shuffle_bytes);
   44|       |
   45|       |    // reshuffle dwords
   46|       |    // t2 = [d7 d6 d5 d4|d3 d2 d1 d0|c7 c6 c5 c4|c3 c2 c1 c0||b7 b6 b5 b4|b3 b2 b1 b0|a7 a6 a5 a4|a3 a2 a1 a0]
   47|  4.56k|    const __m256i shuffle_dwords = _mm256_setr_epi32(0, 4, 1, 5, 2, 6, 3, 7);
   48|  4.56k|    const __m256i t2 = _mm256_permutevar8x32_epi32(t1, shuffle_dwords);
   49|       |// clang format on
   50|       |
   51|  4.56k|    _mm256_storeu_si256((__m256i *)latin1_output, t2);
   52|       |
   53|  4.56k|    latin1_output += 32;
   54|  4.56k|    buf += 32;
   55|  4.56k|  }
   56|       |
   57|  5.56k|  return std::make_pair(buf, latin1_output);
   58|  5.56k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_126avx2_convert_utf32_to_utf8EPKDimPc:
    2|  4.96k|avx2_convert_utf32_to_utf8(const char32_t *buf, size_t len, char *utf8_output) {
    3|  4.96k|  const char32_t *end = buf + len;
    4|  4.96k|  const __m256i v_0000 = _mm256_setzero_si256();
    5|  4.96k|  const __m256i v_ffff0000 = _mm256_set1_epi32((uint32_t)0xffff0000);
    6|  4.96k|  const __m256i v_ff80 = _mm256_set1_epi16((uint16_t)0xff80);
    7|  4.96k|  const __m256i v_f800 = _mm256_set1_epi16((uint16_t)0xf800);
    8|  4.96k|  const __m256i v_c080 = _mm256_set1_epi16((uint16_t)0xc080);
    9|  4.96k|  const __m256i v_7fffffff = _mm256_set1_epi32((uint32_t)0x7fffffff);
   10|  4.96k|  __m256i running_max = _mm256_setzero_si256();
   11|  4.96k|  __m256i forbidden_bytemask = _mm256_setzero_si256();
   12|       |
   13|  4.96k|  const size_t safety_margin =
   14|  4.96k|      12; // to avoid overruns, see issue
   15|       |          // https://github.com/simdutf/simdutf/issues/92
   16|       |
   17|  8.22k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (17:10): [True: 3.26k, False: 4.96k]
  ------------------
   18|  3.26k|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
   19|  3.26k|    __m256i nextin = _mm256_loadu_si256((__m256i *)buf + 1);
   20|  3.26k|    running_max = _mm256_max_epu32(_mm256_max_epu32(in, running_max), nextin);
   21|       |
   22|       |    // Pack 32-bit UTF-32 code units to 16-bit UTF-16 code units with unsigned
   23|       |    // saturation
   24|  3.26k|    __m256i in_16 = _mm256_packus_epi32(_mm256_and_si256(in, v_7fffffff),
   25|  3.26k|                                        _mm256_and_si256(nextin, v_7fffffff));
   26|  3.26k|    in_16 = _mm256_permute4x64_epi64(in_16, 0b11011000);
   27|       |
   28|       |    // Try to apply UTF-16 => UTF-8 routine on 256 bits
   29|       |    // (haswell/avx2_convert_utf16_to_utf8.cpp)
   30|       |
   31|  3.26k|    if (_mm256_testz_si256(in_16, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (31:9): [True: 2.27k, False: 990]
  ------------------
   32|       |      // 1. pack the bytes
   33|  2.27k|      const __m128i utf8_packed = _mm_packus_epi16(
   34|  2.27k|          _mm256_castsi256_si128(in_16), _mm256_extractf128_si256(in_16, 1));
   35|       |      // 2. store (16 bytes)
   36|  2.27k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   37|       |      // 3. adjust pointers
   38|  2.27k|      buf += 16;
   39|  2.27k|      utf8_output += 16;
   40|  2.27k|      continue; // we are done for this round!
   41|  2.27k|    }
   42|       |    // no bits set above 7th bit
   43|    990|    const __m256i one_byte_bytemask =
   44|    990|        _mm256_cmpeq_epi16(_mm256_and_si256(in_16, v_ff80), v_0000);
   45|    990|    const uint32_t one_byte_bitmask =
   46|    990|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
   47|       |
   48|       |    // no bits set above 11th bit
   49|    990|    const __m256i one_or_two_bytes_bytemask =
   50|    990|        _mm256_cmpeq_epi16(_mm256_and_si256(in_16, v_f800), v_0000);
   51|    990|    const uint32_t one_or_two_bytes_bitmask =
   52|    990|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
   53|    990|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (53:9): [True: 123, False: 867]
  ------------------
   54|       |      // 1. prepare 2-byte values
   55|       |      // input 16-bit word : [0000|0aaa|aabb|bbbb] x 8
   56|       |      // expected output   : [110a|aaaa|10bb|bbbb] x 8
   57|    123|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
   58|    123|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
   59|       |
   60|       |      // t0 = [000a|aaaa|bbbb|bb00]
   61|    123|      const __m256i t0 = _mm256_slli_epi16(in_16, 2);
   62|       |      // t1 = [000a|aaaa|0000|0000]
   63|    123|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
   64|       |      // t2 = [0000|0000|00bb|bbbb]
   65|    123|      const __m256i t2 = _mm256_and_si256(in_16, v_003f);
   66|       |      // t3 = [000a|aaaa|00bb|bbbb]
   67|    123|      const __m256i t3 = _mm256_or_si256(t1, t2);
   68|       |      // t4 = [110a|aaaa|10bb|bbbb]
   69|    123|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
   70|       |
   71|       |      // 2. merge ASCII and 2-byte codewords
   72|    123|      const __m256i utf8_unpacked =
   73|    123|          _mm256_blendv_epi8(t4, in_16, one_byte_bytemask);
   74|       |
   75|       |      // 3. prepare bitmask for 8-bit lookup
   76|    123|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
   77|    123|      const uint32_t M1 = M0 >> 7;
   78|    123|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
   79|       |      // 4. pack the bytes
   80|       |
   81|    123|      const uint8_t *row =
   82|    123|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
   83|    123|      const uint8_t *row_2 =
   84|    123|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
   85|    123|                                                                       16)][0];
   86|       |
   87|    123|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
   88|    123|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
   89|       |
   90|    123|      const __m256i utf8_packed = _mm256_shuffle_epi8(
   91|    123|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|    123|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|    123|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
   92|       |      // 5. store bytes
   93|    123|      _mm_storeu_si128((__m128i *)utf8_output,
   94|    123|                       _mm256_castsi256_si128(utf8_packed));
   95|    123|      utf8_output += row[0];
   96|    123|      _mm_storeu_si128((__m128i *)utf8_output,
   97|    123|                       _mm256_extractf128_si256(utf8_packed, 1));
   98|    123|      utf8_output += row_2[0];
   99|       |
  100|       |      // 6. adjust pointers
  101|    123|      buf += 16;
  102|    123|      continue;
  103|    123|    }
  104|       |    // Must check for overflow in packing
  105|    867|    const __m256i saturation_bytemask = _mm256_cmpeq_epi32(
  106|    867|        _mm256_and_si256(_mm256_or_si256(in, nextin), v_ffff0000), v_0000);
  107|    867|    const uint32_t saturation_bitmask =
  108|    867|        static_cast<uint32_t>(_mm256_movemask_epi8(saturation_bytemask));
  109|    867|    if (saturation_bitmask == 0xffffffff) {
  ------------------
  |  Branch (109:9): [True: 107, False: 760]
  ------------------
  110|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  111|    107|      const __m256i v_d800 = _mm256_set1_epi16((uint16_t)0xd800);
  112|    107|      forbidden_bytemask = _mm256_or_si256(
  113|    107|          forbidden_bytemask,
  114|    107|          _mm256_cmpeq_epi16(_mm256_and_si256(in_16, v_f800), v_d800));
  115|       |
  116|    107|      const __m256i dup_even = _mm256_setr_epi16(
  117|    107|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  118|    107|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  119|       |
  120|       |      /* In this branch we handle three cases:
  121|       |        1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  122|       |        single UFT-8 byte
  123|       |        2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              - two
  124|       |        UTF-8 bytes
  125|       |        3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  126|       |        three UTF-8 bytes
  127|       |
  128|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  129|       |        we have room for four bytes. However, we need five distinct bit
  130|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  131|       |
  132|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  133|       |        in register t2.
  134|       |
  135|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  136|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  137|       |        differ by exactly one bit.
  138|       |
  139|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  140|       |        into account the case (i.e, the number of bytes to write).
  141|       |      */
  142|       |      /**
  143|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  144|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  145|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  146|       |       */
  147|    107|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  148|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  149|    107|      const __m256i t0 = _mm256_shuffle_epi8(in_16, dup_even);
  150|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  151|    107|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  147|    107|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  152|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  153|    107|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  147|    107|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  154|       |
  155|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  156|    107|      const __m256i s0 = _mm256_srli_epi16(in_16, 4);
  157|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  158|    107|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  147|    107|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  159|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  160|    107|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  147|    107|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  161|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  162|    107|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  147|    107|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  163|    107|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  164|    107|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  147|    107|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  165|    107|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  166|    107|#undef simdutf_vec
  167|       |
  168|       |      // 4. expand code units 16-bit => 32-bit
  169|    107|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  170|    107|      const __m256i out1 = _mm256_unpackhi_epi16(t2, s4);
  171|       |
  172|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  173|    107|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  174|    107|                            (one_or_two_bytes_bitmask & 0xaaaaaaaa);
  175|       |      // Due to the wider registers, the following path is less likely to be
  176|       |      // useful.
  177|       |      /*if(mask == 0) {
  178|       |        // We only have three-byte code units. Use fast path.
  179|       |        const __m256i shuffle =
  180|       |      _mm256_setr_epi8(2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1,
  181|       |      2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1); const __m256i utf8_0 =
  182|       |      _mm256_shuffle_epi8(out0, shuffle); const __m256i utf8_1 =
  183|       |      _mm256_shuffle_epi8(out1, shuffle);
  184|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_0));
  185|       |        utf8_output += 12;
  186|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_1));
  187|       |        utf8_output += 12;
  188|       |        _mm_storeu_si128((__m128i*)utf8_output,
  189|       |      _mm256_extractf128_si256(utf8_0,1)); utf8_output += 12;
  190|       |        _mm_storeu_si128((__m128i*)utf8_output,
  191|       |      _mm256_extractf128_si256(utf8_1,1)); utf8_output += 12; buf += 16;
  192|       |        continue;
  193|       |      }*/
  194|    107|      const uint8_t mask0 = uint8_t(mask);
  195|    107|      const uint8_t *row0 =
  196|    107|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  197|    107|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  198|    107|      const __m128i utf8_0 =
  199|    107|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  200|       |
  201|    107|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  202|    107|      const uint8_t *row1 =
  203|    107|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  204|    107|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  205|    107|      const __m128i utf8_1 =
  206|    107|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  207|       |
  208|    107|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  209|    107|      const uint8_t *row2 =
  210|    107|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  211|    107|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  212|    107|      const __m128i utf8_2 =
  213|    107|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  214|       |
  215|    107|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  216|    107|      const uint8_t *row3 =
  217|    107|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  218|    107|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  219|    107|      const __m128i utf8_3 =
  220|    107|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  221|       |
  222|    107|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  223|    107|      utf8_output += row0[0];
  224|    107|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  225|    107|      utf8_output += row1[0];
  226|    107|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  227|    107|      utf8_output += row2[0];
  228|    107|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  229|    107|      utf8_output += row3[0];
  230|    107|      buf += 16;
  231|    760|    } else {
  232|       |      // case: at least one 32-bit word is larger than 0xFFFF <=> it will
  233|       |      // produce four UTF-8 bytes. Let us do a scalar fallback. It may seem
  234|       |      // wasteful to use scalar code, but being efficient with SIMD may require
  235|       |      // large, non-trivial tables?
  236|    760|      size_t forward = 15;
  237|    760|      size_t k = 0;
  238|    760|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (238:11): [True: 0, False: 760]
  ------------------
  239|      0|        forward = size_t(end - buf - 1);
  240|      0|      }
  241|  12.1k|      for (; k < forward; k++) {
  ------------------
  |  Branch (241:14): [True: 11.4k, False: 760]
  ------------------
  242|  11.4k|        uint32_t word = buf[k];
  243|  11.4k|        if ((word & 0xFFFFFF80) == 0) { // 1-byte (ASCII)
  ------------------
  |  Branch (243:13): [True: 9.29k, False: 2.10k]
  ------------------
  244|  9.29k|          *utf8_output++ = char(word);
  245|  9.29k|        } else if ((word & 0xFFFFF800) == 0) { // 2-byte
  ------------------
  |  Branch (245:20): [True: 450, False: 1.65k]
  ------------------
  246|    450|          *utf8_output++ = char((word >> 6) | 0b11000000);
  247|    450|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  248|  1.65k|        } else if ((word & 0xFFFF0000) == 0) { // 3-byte
  ------------------
  |  Branch (248:20): [True: 494, False: 1.16k]
  ------------------
  249|    494|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (249:15): [True: 230, False: 264]
  |  Branch (249:33): [True: 0, False: 230]
  ------------------
  250|      0|            return std::make_pair(nullptr, utf8_output);
  251|      0|          }
  252|    494|          *utf8_output++ = char((word >> 12) | 0b11100000);
  253|    494|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  254|    494|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  255|  1.16k|        } else { // 4-byte
  256|  1.16k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (256:15): [True: 0, False: 1.16k]
  ------------------
  257|      0|            return std::make_pair(nullptr, utf8_output);
  258|      0|          }
  259|  1.16k|          *utf8_output++ = char((word >> 18) | 0b11110000);
  260|  1.16k|          *utf8_output++ = char(((word >> 12) & 0b111111) | 0b10000000);
  261|  1.16k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  262|  1.16k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  263|  1.16k|        }
  264|  11.4k|      }
  265|    760|      buf += k;
  266|    760|    }
  267|    867|  } // while
  268|       |
  269|       |  // check for invalid input
  270|  4.96k|  const __m256i v_10ffff = _mm256_set1_epi32((uint32_t)0x10ffff);
  271|  4.96k|  if (static_cast<uint32_t>(_mm256_movemask_epi8(_mm256_cmpeq_epi32(
  ------------------
  |  Branch (271:7): [True: 0, False: 4.96k]
  ------------------
  272|  4.96k|          _mm256_max_epu32(running_max, v_10ffff), v_10ffff))) != 0xffffffff) {
  273|      0|    return std::make_pair(nullptr, utf8_output);
  274|      0|  }
  275|       |
  276|  4.96k|  if (static_cast<uint32_t>(_mm256_movemask_epi8(forbidden_bytemask)) != 0) {
  ------------------
  |  Branch (276:7): [True: 0, False: 4.96k]
  ------------------
  277|      0|    return std::make_pair(nullptr, utf8_output);
  278|      0|  }
  279|       |
  280|  4.96k|  return std::make_pair(buf, utf8_output);
  281|  4.96k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_129convert_masked_utf8_to_latin1EPKcmRPc:
    9|  15.5k|                                     char *&latin1_output) {
   10|       |  // we use an approach where we try to process up to 12 input bytes.
   11|       |  // Why 12 input bytes and not 16? Because we are concerned with the size of
   12|       |  // the lookup tables. Also 12 is nicely divisible by two and three.
   13|       |  //
   14|       |  //
   15|       |  // Optimization note: our main path below is load-latency dependent. Thus it
   16|       |  // is maybe beneficial to have fast paths that depend on branch prediction but
   17|       |  // have less latency. This results in more instructions but, potentially, also
   18|       |  // higher speeds.
   19|       |  //
   20|  15.5k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   21|       |
   22|  15.5k|  const uint16_t input_utf8_end_of_code_point_mask =
   23|  15.5k|      utf8_end_of_code_point_mask &
   24|  15.5k|      0xfff; // we are only processing 12 bytes in case it is not all ASCII
   25|       |
   26|  15.5k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (26:7): [True: 120, False: 15.4k]
  ------------------
   27|       |    // We process the data in chunks of 12 bytes.
   28|    120|    _mm_storeu_si128(reinterpret_cast<__m128i *>(latin1_output), in);
   29|    120|    latin1_output += 12; // We wrote 12 characters.
   30|    120|    return 12;           // We consumed 1 bytes.
   31|    120|  }
   32|       |  /// We do not have a fast path available, so we fallback.
   33|  15.4k|  const uint8_t idx =
   34|  15.4k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   35|  15.4k|  const uint8_t consumed =
   36|  15.4k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   37|       |  // this indicates an invalid input:
   38|  15.4k|  if (idx >= 64) {
  ------------------
  |  Branch (38:7): [True: 5.03k, False: 10.4k]
  ------------------
   39|  5.03k|    return consumed;
   40|  5.03k|  }
   41|       |  // Here we should have (idx < 64), if not, there is a bug in the validation or
   42|       |  // elsewhere. SIX (6) input code-code units this is a relatively easy scenario
   43|       |  // we process SIX (6) input code-code units. The max length in bytes of six
   44|       |  // code code units spanning between 1 and 2 bytes each is 12 bytes. On
   45|       |  // processors where pdep/pext is fast, we might be able to use a small lookup
   46|       |  // table.
   47|  10.4k|  const __m128i sh =
   48|  10.4k|      _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   49|  10.4k|  const __m128i perm = _mm_shuffle_epi8(in, sh);
   50|  10.4k|  const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   51|  10.4k|  const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   52|  10.4k|  __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   53|  10.4k|  const __m128i latin1_packed = _mm_packus_epi16(composed, composed);
   54|       |  // writing 8 bytes even though we only care about the first 6 bytes.
   55|       |  // performance note: it would be faster to use _mm_storeu_si128, we should
   56|       |  // investigate.
   57|  10.4k|  _mm_storel_epi64((__m128i *)latin1_output, latin1_packed);
   58|  10.4k|  latin1_output += 6; // We wrote 6 bytes.
   59|  10.4k|  return consumed;
   60|  15.4k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128convert_masked_utf8_to_utf16ILNS_10endiannessE0EEEmPKcmRPDs:
   10|  14.3k|                                    char16_t *&utf16_output) {
   11|       |  // we use an approach where we try to process up to 12 input bytes.
   12|       |  // Why 12 input bytes and not 16? Because we are concerned with the size of
   13|       |  // the lookup tables. Also 12 is nicely divisible by two and three.
   14|       |  //
   15|       |  //
   16|       |  // Optimization note: our main path below is load-latency dependent. Thus it
   17|       |  // is maybe beneficial to have fast paths that depend on branch prediction but
   18|       |  // have less latency. This results in more instructions but, potentially, also
   19|       |  // higher speeds.
   20|       |  //
   21|       |  // We first try a few fast paths.
   22|  14.3k|  const __m128i swap =
   23|  14.3k|      _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   24|  14.3k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   25|  14.3k|  const uint16_t input_utf8_end_of_code_point_mask =
   26|  14.3k|      utf8_end_of_code_point_mask & 0xfff;
   27|  14.3k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (27:7): [True: 92, False: 14.2k]
  ------------------
   28|       |    // We process the data in chunks of 12 bytes.
   29|     92|    __m256i ascii = _mm256_cvtepu8_epi16(in);
   30|     92|    if (big_endian) {
  ------------------
  |  Branch (30:9): [Folded, False: 92]
  ------------------
   31|      0|      const __m256i swap256 = _mm256_setr_epi8(
   32|      0|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   33|      0|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   34|      0|      ascii = _mm256_shuffle_epi8(ascii, swap256);
   35|      0|    }
   36|     92|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(utf16_output), ascii);
   37|     92|    utf16_output += 12; // We wrote 12 16-bit characters.
   38|     92|    return 12;          // We consumed 12 bytes.
   39|     92|  }
   40|  14.2k|  if (((utf8_end_of_code_point_mask & 0xffff) == 0xaaaa)) {
  ------------------
  |  Branch (40:7): [True: 129, False: 14.1k]
  ------------------
   41|       |    // We want to take 8 2-byte UTF-8 code units and turn them into 8 2-byte
   42|       |    // UTF-16 code units. There is probably a more efficient sequence, but the
   43|       |    // following might do.
   44|    129|    const __m128i sh =
   45|    129|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   46|    129|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   47|    129|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   48|    129|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   49|    129|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   50|    129|    if (big_endian)
  ------------------
  |  Branch (50:9): [Folded, False: 129]
  ------------------
   51|      0|      composed = _mm_shuffle_epi8(composed, swap);
   52|    129|    _mm_storeu_si128((__m128i *)utf16_output, composed);
   53|    129|    utf16_output += 8; // We wrote 16 bytes, 8 code points.
   54|    129|    return 16;
   55|    129|  }
   56|  14.1k|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (56:7): [True: 3.61k, False: 10.4k]
  ------------------
   57|       |    // We want to take 4 3-byte UTF-8 code units and turn them into 4 2-byte
   58|       |    // UTF-16 code units. There is probably a more efficient sequence, but the
   59|       |    // following might do.
   60|  3.61k|    const __m128i sh =
   61|  3.61k|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   62|  3.61k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   63|  3.61k|    const __m128i ascii =
   64|  3.61k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   65|  3.61k|    const __m128i middlebyte =
   66|  3.61k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   67|  3.61k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   68|  3.61k|    const __m128i highbyte =
   69|  3.61k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   70|  3.61k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   71|  3.61k|    const __m128i composed =
   72|  3.61k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   73|  3.61k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
   74|  3.61k|    if (big_endian)
  ------------------
  |  Branch (74:9): [Folded, False: 3.61k]
  ------------------
   75|      0|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
   76|  3.61k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
   77|  3.61k|    utf16_output += 4;
   78|  3.61k|    return 12;
   79|  3.61k|  }
   80|       |
   81|  10.4k|  const uint8_t idx = simdutf::tables::utf8_to_utf16::utf8bigindex
   82|  10.4k|      [input_utf8_end_of_code_point_mask][0];
   83|  10.4k|  const uint8_t consumed = simdutf::tables::utf8_to_utf16::utf8bigindex
   84|  10.4k|      [input_utf8_end_of_code_point_mask][1];
   85|  10.4k|  if (idx < 64) {
  ------------------
  |  Branch (85:7): [True: 3.94k, False: 6.54k]
  ------------------
   86|       |    // SIX (6) input code-code units
   87|       |    // this is a relatively easy scenario
   88|       |    // we process SIX (6) input code-code units. The max length in bytes of six
   89|       |    // code code units spanning between 1 and 2 bytes each is 12 bytes. On
   90|       |    // processors where pdep/pext is fast, we might be able to use a small
   91|       |    // lookup table.
   92|  3.94k|    const __m128i sh = _mm_loadu_si128(
   93|  3.94k|        (const __m128i *)simdutf::tables::utf8_to_utf16::shufutf8[idx]);
   94|  3.94k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   95|  3.94k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   96|  3.94k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   97|  3.94k|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   98|  3.94k|    if (big_endian)
  ------------------
  |  Branch (98:9): [Folded, False: 3.94k]
  ------------------
   99|      0|      composed = _mm_shuffle_epi8(composed, swap);
  100|  3.94k|    _mm_storeu_si128((__m128i *)utf16_output, composed);
  101|  3.94k|    utf16_output += 6; // We wrote 12 bytes, 6 code points. There is a potential
  102|       |                       // overflow of 4 bytes.
  103|  6.54k|  } else if (idx < 145) {
  ------------------
  |  Branch (103:14): [True: 1.64k, False: 4.90k]
  ------------------
  104|       |    // FOUR (4) input code-code units
  105|  1.64k|    const __m128i sh = _mm_loadu_si128(
  106|  1.64k|        (const __m128i *)simdutf::tables::utf8_to_utf16::shufutf8[idx]);
  107|  1.64k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  108|  1.64k|    const __m128i ascii =
  109|  1.64k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
  110|  1.64k|    const __m128i middlebyte =
  111|  1.64k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  112|  1.64k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  113|  1.64k|    const __m128i highbyte =
  114|  1.64k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  115|  1.64k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  116|  1.64k|    const __m128i composed =
  117|  1.64k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  118|  1.64k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
  119|  1.64k|    if (big_endian)
  ------------------
  |  Branch (119:9): [Folded, False: 1.64k]
  ------------------
  120|      0|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
  121|  1.64k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
  122|  1.64k|    utf16_output += 4; // Here we overflow by 8 bytes.
  123|  4.90k|  } else if (idx < 209) {
  ------------------
  |  Branch (123:14): [True: 4.71k, False: 191]
  ------------------
  124|       |    // TWO (2) input code-code units
  125|       |    //////////////
  126|       |    // There might be garbage inputs where a leading byte mascarades as a
  127|       |    // four-byte leading byte (by being followed by 3 continuation byte), but is
  128|       |    // not greater than 0xf0. This could trigger a buffer overflow if we only
  129|       |    // counted leading bytes of the form 0xf0 as generating surrogate pairs,
  130|       |    // without further UTF-8 validation. Thus we must be careful to ensure that
  131|       |    // only leading bytes at least as large as 0xf0 generate surrogate pairs. We
  132|       |    // do as at the cost of an extra mask.
  133|       |    /////////////
  134|  4.71k|    const __m128i sh = _mm_loadu_si128(
  135|  4.71k|        (const __m128i *)simdutf::tables::utf8_to_utf16::shufutf8[idx]);
  136|  4.71k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  137|  4.71k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  138|  4.71k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  139|  4.71k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  140|  4.71k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  141|       |    // correct for spurious high bit
  142|  4.71k|    const __m128i correct =
  143|  4.71k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  144|  4.71k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  145|  4.71k|    const __m128i middlehighbyte_shifted = _mm_srli_epi32(middlehighbyte, 4);
  146|       |    // We deliberately carry the leading four bits in highbyte if they are
  147|       |    // present, we remove them later when computing hightenbits.
  148|  4.71k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0xff000000));
  149|  4.71k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 6);
  150|       |    // When we need to generate a surrogate pair (leading byte > 0xF0), then
  151|       |    // the corresponding 32-bit value in 'composed'  will be greater than
  152|       |    // > (0xff00000>>6) or > 0x3c00000. This can be used later to identify the
  153|       |    // location of the surrogate pairs.
  154|  4.71k|    const __m128i composed =
  155|  4.71k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  156|  4.71k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  157|  4.71k|    const __m128i composedminus =
  158|  4.71k|        _mm_sub_epi32(composed, _mm_set1_epi32(0x10000));
  159|  4.71k|    const __m128i lowtenbits =
  160|  4.71k|        _mm_and_si128(composedminus, _mm_set1_epi32(0x3ff));
  161|       |    // Notice the 0x3ff mask:
  162|  4.71k|    const __m128i hightenbits =
  163|  4.71k|        _mm_and_si128(_mm_srli_epi32(composedminus, 10), _mm_set1_epi32(0x3ff));
  164|  4.71k|    const __m128i lowtenbitsadd =
  165|  4.71k|        _mm_add_epi32(lowtenbits, _mm_set1_epi32(0xDC00));
  166|  4.71k|    const __m128i hightenbitsadd =
  167|  4.71k|        _mm_add_epi32(hightenbits, _mm_set1_epi32(0xD800));
  168|  4.71k|    const __m128i lowtenbitsaddshifted = _mm_slli_epi32(lowtenbitsadd, 16);
  169|  4.71k|    __m128i surrogates = _mm_or_si128(hightenbitsadd, lowtenbitsaddshifted);
  170|  4.71k|    uint32_t basic_buffer[4];
  171|  4.71k|    uint32_t basic_buffer_swap[4];
  172|  4.71k|    if (big_endian) {
  ------------------
  |  Branch (172:9): [Folded, False: 4.71k]
  ------------------
  173|      0|      _mm_storeu_si128((__m128i *)basic_buffer_swap,
  174|      0|                       _mm_shuffle_epi8(composed, swap));
  175|      0|      surrogates = _mm_shuffle_epi8(surrogates, swap);
  176|      0|    }
  177|  4.71k|    _mm_storeu_si128((__m128i *)basic_buffer, composed);
  178|  4.71k|    uint32_t surrogate_buffer[4];
  179|  4.71k|    _mm_storeu_si128((__m128i *)surrogate_buffer, surrogates);
  180|  18.8k|    for (size_t i = 0; i < 3; i++) {
  ------------------
  |  Branch (180:24): [True: 14.1k, False: 4.71k]
  ------------------
  181|  14.1k|      if (basic_buffer[i] > 0x3c00000) {
  ------------------
  |  Branch (181:11): [True: 2.82k, False: 11.3k]
  ------------------
  182|  2.82k|        utf16_output[0] = uint16_t(surrogate_buffer[i] & 0xffff);
  183|  2.82k|        utf16_output[1] = uint16_t(surrogate_buffer[i] >> 16);
  184|  2.82k|        utf16_output += 2;
  185|  11.3k|      } else {
  186|  11.3k|        utf16_output[0] = big_endian ? uint16_t(basic_buffer_swap[i])
  ------------------
  |  Branch (186:27): [Folded, False: 11.3k]
  ------------------
  187|  11.3k|                                     : uint16_t(basic_buffer[i]);
  188|  11.3k|        utf16_output++;
  189|  11.3k|      }
  190|  14.1k|    }
  191|  4.71k|  } else {
  192|       |    // here we know that there is an error but we do not handle errors
  193|    191|  }
  194|  10.4k|  return consumed;
  195|  14.1k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128convert_masked_utf8_to_utf16ILNS_10endiannessE1EEEmPKcmRPDs:
   10|  15.6k|                                    char16_t *&utf16_output) {
   11|       |  // we use an approach where we try to process up to 12 input bytes.
   12|       |  // Why 12 input bytes and not 16? Because we are concerned with the size of
   13|       |  // the lookup tables. Also 12 is nicely divisible by two and three.
   14|       |  //
   15|       |  //
   16|       |  // Optimization note: our main path below is load-latency dependent. Thus it
   17|       |  // is maybe beneficial to have fast paths that depend on branch prediction but
   18|       |  // have less latency. This results in more instructions but, potentially, also
   19|       |  // higher speeds.
   20|       |  //
   21|       |  // We first try a few fast paths.
   22|  15.6k|  const __m128i swap =
   23|  15.6k|      _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   24|  15.6k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   25|  15.6k|  const uint16_t input_utf8_end_of_code_point_mask =
   26|  15.6k|      utf8_end_of_code_point_mask & 0xfff;
   27|  15.6k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (27:7): [True: 95, False: 15.5k]
  ------------------
   28|       |    // We process the data in chunks of 12 bytes.
   29|     95|    __m256i ascii = _mm256_cvtepu8_epi16(in);
   30|     95|    if (big_endian) {
  ------------------
  |  Branch (30:9): [True: 95, Folded]
  ------------------
   31|     95|      const __m256i swap256 = _mm256_setr_epi8(
   32|     95|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   33|     95|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   34|     95|      ascii = _mm256_shuffle_epi8(ascii, swap256);
   35|     95|    }
   36|     95|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(utf16_output), ascii);
   37|     95|    utf16_output += 12; // We wrote 12 16-bit characters.
   38|     95|    return 12;          // We consumed 12 bytes.
   39|     95|  }
   40|  15.5k|  if (((utf8_end_of_code_point_mask & 0xffff) == 0xaaaa)) {
  ------------------
  |  Branch (40:7): [True: 118, False: 15.3k]
  ------------------
   41|       |    // We want to take 8 2-byte UTF-8 code units and turn them into 8 2-byte
   42|       |    // UTF-16 code units. There is probably a more efficient sequence, but the
   43|       |    // following might do.
   44|    118|    const __m128i sh =
   45|    118|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   46|    118|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   47|    118|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   48|    118|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   49|    118|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   50|    118|    if (big_endian)
  ------------------
  |  Branch (50:9): [True: 118, Folded]
  ------------------
   51|    118|      composed = _mm_shuffle_epi8(composed, swap);
   52|    118|    _mm_storeu_si128((__m128i *)utf16_output, composed);
   53|    118|    utf16_output += 8; // We wrote 16 bytes, 8 code points.
   54|    118|    return 16;
   55|    118|  }
   56|  15.3k|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (56:7): [True: 4.63k, False: 10.7k]
  ------------------
   57|       |    // We want to take 4 3-byte UTF-8 code units and turn them into 4 2-byte
   58|       |    // UTF-16 code units. There is probably a more efficient sequence, but the
   59|       |    // following might do.
   60|  4.63k|    const __m128i sh =
   61|  4.63k|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   62|  4.63k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   63|  4.63k|    const __m128i ascii =
   64|  4.63k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   65|  4.63k|    const __m128i middlebyte =
   66|  4.63k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   67|  4.63k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   68|  4.63k|    const __m128i highbyte =
   69|  4.63k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   70|  4.63k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   71|  4.63k|    const __m128i composed =
   72|  4.63k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   73|  4.63k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
   74|  4.63k|    if (big_endian)
  ------------------
  |  Branch (74:9): [True: 4.63k, Folded]
  ------------------
   75|  4.63k|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
   76|  4.63k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
   77|  4.63k|    utf16_output += 4;
   78|  4.63k|    return 12;
   79|  4.63k|  }
   80|       |
   81|  10.7k|  const uint8_t idx = simdutf::tables::utf8_to_utf16::utf8bigindex
   82|  10.7k|      [input_utf8_end_of_code_point_mask][0];
   83|  10.7k|  const uint8_t consumed = simdutf::tables::utf8_to_utf16::utf8bigindex
   84|  10.7k|      [input_utf8_end_of_code_point_mask][1];
   85|  10.7k|  if (idx < 64) {
  ------------------
  |  Branch (85:7): [True: 4.05k, False: 6.70k]
  ------------------
   86|       |    // SIX (6) input code-code units
   87|       |    // this is a relatively easy scenario
   88|       |    // we process SIX (6) input code-code units. The max length in bytes of six
   89|       |    // code code units spanning between 1 and 2 bytes each is 12 bytes. On
   90|       |    // processors where pdep/pext is fast, we might be able to use a small
   91|       |    // lookup table.
   92|  4.05k|    const __m128i sh = _mm_loadu_si128(
   93|  4.05k|        (const __m128i *)simdutf::tables::utf8_to_utf16::shufutf8[idx]);
   94|  4.05k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   95|  4.05k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   96|  4.05k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   97|  4.05k|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   98|  4.05k|    if (big_endian)
  ------------------
  |  Branch (98:9): [True: 4.05k, Folded]
  ------------------
   99|  4.05k|      composed = _mm_shuffle_epi8(composed, swap);
  100|  4.05k|    _mm_storeu_si128((__m128i *)utf16_output, composed);
  101|  4.05k|    utf16_output += 6; // We wrote 12 bytes, 6 code points. There is a potential
  102|       |                       // overflow of 4 bytes.
  103|  6.70k|  } else if (idx < 145) {
  ------------------
  |  Branch (103:14): [True: 1.88k, False: 4.81k]
  ------------------
  104|       |    // FOUR (4) input code-code units
  105|  1.88k|    const __m128i sh = _mm_loadu_si128(
  106|  1.88k|        (const __m128i *)simdutf::tables::utf8_to_utf16::shufutf8[idx]);
  107|  1.88k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  108|  1.88k|    const __m128i ascii =
  109|  1.88k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
  110|  1.88k|    const __m128i middlebyte =
  111|  1.88k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  112|  1.88k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  113|  1.88k|    const __m128i highbyte =
  114|  1.88k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  115|  1.88k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  116|  1.88k|    const __m128i composed =
  117|  1.88k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  118|  1.88k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
  119|  1.88k|    if (big_endian)
  ------------------
  |  Branch (119:9): [True: 1.88k, Folded]
  ------------------
  120|  1.88k|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
  121|  1.88k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
  122|  1.88k|    utf16_output += 4; // Here we overflow by 8 bytes.
  123|  4.81k|  } else if (idx < 209) {
  ------------------
  |  Branch (123:14): [True: 4.62k, False: 191]
  ------------------
  124|       |    // TWO (2) input code-code units
  125|       |    //////////////
  126|       |    // There might be garbage inputs where a leading byte mascarades as a
  127|       |    // four-byte leading byte (by being followed by 3 continuation byte), but is
  128|       |    // not greater than 0xf0. This could trigger a buffer overflow if we only
  129|       |    // counted leading bytes of the form 0xf0 as generating surrogate pairs,
  130|       |    // without further UTF-8 validation. Thus we must be careful to ensure that
  131|       |    // only leading bytes at least as large as 0xf0 generate surrogate pairs. We
  132|       |    // do as at the cost of an extra mask.
  133|       |    /////////////
  134|  4.62k|    const __m128i sh = _mm_loadu_si128(
  135|  4.62k|        (const __m128i *)simdutf::tables::utf8_to_utf16::shufutf8[idx]);
  136|  4.62k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  137|  4.62k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  138|  4.62k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  139|  4.62k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  140|  4.62k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  141|       |    // correct for spurious high bit
  142|  4.62k|    const __m128i correct =
  143|  4.62k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  144|  4.62k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  145|  4.62k|    const __m128i middlehighbyte_shifted = _mm_srli_epi32(middlehighbyte, 4);
  146|       |    // We deliberately carry the leading four bits in highbyte if they are
  147|       |    // present, we remove them later when computing hightenbits.
  148|  4.62k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0xff000000));
  149|  4.62k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 6);
  150|       |    // When we need to generate a surrogate pair (leading byte > 0xF0), then
  151|       |    // the corresponding 32-bit value in 'composed'  will be greater than
  152|       |    // > (0xff00000>>6) or > 0x3c00000. This can be used later to identify the
  153|       |    // location of the surrogate pairs.
  154|  4.62k|    const __m128i composed =
  155|  4.62k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  156|  4.62k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  157|  4.62k|    const __m128i composedminus =
  158|  4.62k|        _mm_sub_epi32(composed, _mm_set1_epi32(0x10000));
  159|  4.62k|    const __m128i lowtenbits =
  160|  4.62k|        _mm_and_si128(composedminus, _mm_set1_epi32(0x3ff));
  161|       |    // Notice the 0x3ff mask:
  162|  4.62k|    const __m128i hightenbits =
  163|  4.62k|        _mm_and_si128(_mm_srli_epi32(composedminus, 10), _mm_set1_epi32(0x3ff));
  164|  4.62k|    const __m128i lowtenbitsadd =
  165|  4.62k|        _mm_add_epi32(lowtenbits, _mm_set1_epi32(0xDC00));
  166|  4.62k|    const __m128i hightenbitsadd =
  167|  4.62k|        _mm_add_epi32(hightenbits, _mm_set1_epi32(0xD800));
  168|  4.62k|    const __m128i lowtenbitsaddshifted = _mm_slli_epi32(lowtenbitsadd, 16);
  169|  4.62k|    __m128i surrogates = _mm_or_si128(hightenbitsadd, lowtenbitsaddshifted);
  170|  4.62k|    uint32_t basic_buffer[4];
  171|  4.62k|    uint32_t basic_buffer_swap[4];
  172|  4.62k|    if (big_endian) {
  ------------------
  |  Branch (172:9): [True: 4.62k, Folded]
  ------------------
  173|  4.62k|      _mm_storeu_si128((__m128i *)basic_buffer_swap,
  174|  4.62k|                       _mm_shuffle_epi8(composed, swap));
  175|  4.62k|      surrogates = _mm_shuffle_epi8(surrogates, swap);
  176|  4.62k|    }
  177|  4.62k|    _mm_storeu_si128((__m128i *)basic_buffer, composed);
  178|  4.62k|    uint32_t surrogate_buffer[4];
  179|  4.62k|    _mm_storeu_si128((__m128i *)surrogate_buffer, surrogates);
  180|  18.5k|    for (size_t i = 0; i < 3; i++) {
  ------------------
  |  Branch (180:24): [True: 13.8k, False: 4.62k]
  ------------------
  181|  13.8k|      if (basic_buffer[i] > 0x3c00000) {
  ------------------
  |  Branch (181:11): [True: 2.77k, False: 11.1k]
  ------------------
  182|  2.77k|        utf16_output[0] = uint16_t(surrogate_buffer[i] & 0xffff);
  183|  2.77k|        utf16_output[1] = uint16_t(surrogate_buffer[i] >> 16);
  184|  2.77k|        utf16_output += 2;
  185|  11.1k|      } else {
  186|  11.1k|        utf16_output[0] = big_endian ? uint16_t(basic_buffer_swap[i])
  ------------------
  |  Branch (186:27): [True: 11.1k, Folded]
  ------------------
  187|  11.1k|                                     : uint16_t(basic_buffer[i]);
  188|  11.1k|        utf16_output++;
  189|  11.1k|      }
  190|  13.8k|    }
  191|  4.62k|  } else {
  192|       |    // here we know that there is an error but we do not handle errors
  193|    191|  }
  194|  10.7k|  return consumed;
  195|  15.3k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128convert_masked_utf8_to_utf32EPKcmRPDi:
    9|  9.80k|                                    char32_t *&utf32_output) {
   10|       |  // we use an approach where we try to process up to 12 input bytes.
   11|       |  // Why 12 input bytes and not 16? Because we are concerned with the size of
   12|       |  // the lookup tables. Also 12 is nicely divisible by two and three.
   13|       |  //
   14|       |  //
   15|       |  // Optimization note: our main path below is load-latency dependent. Thus it
   16|       |  // is maybe beneficial to have fast paths that depend on branch prediction but
   17|       |  // have less latency. This results in more instructions but, potentially, also
   18|       |  // higher speeds.
   19|       |  //
   20|       |  // We first try a few fast paths.
   21|  9.80k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   22|  9.80k|  const uint16_t input_utf8_end_of_code_point_mask =
   23|  9.80k|      utf8_end_of_code_point_mask & 0xfff;
   24|  9.80k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (24:7): [True: 92, False: 9.71k]
  ------------------
   25|       |    // We process the data in chunks of 12 bytes.
   26|     92|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(utf32_output),
   27|     92|                        _mm256_cvtepu8_epi32(in));
   28|     92|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(utf32_output + 8),
   29|     92|                        _mm256_cvtepu8_epi32(_mm_srli_si128(in, 8)));
   30|     92|    utf32_output += 12; // We wrote 12 32-bit characters.
   31|     92|    return 12;          // We consumed 12 bytes.
   32|     92|  }
   33|  9.71k|  if (((utf8_end_of_code_point_mask & 0xffff) == 0xaaaa)) {
  ------------------
  |  Branch (33:7): [True: 103, False: 9.61k]
  ------------------
   34|       |    // We want to take 8 2-byte UTF-8 code units and turn them into 8 4-byte
   35|       |    // UTF-32 code units. There is probably a more efficient sequence, but the
   36|       |    // following might do.
   37|    103|    const __m128i sh =
   38|    103|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   39|    103|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   40|    103|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   41|    103|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   42|    103|    const __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   43|    103|    _mm256_storeu_si256((__m256i *)utf32_output,
   44|    103|                        _mm256_cvtepu16_epi32(composed));
   45|    103|    utf32_output += 8; // We wrote 16 bytes, 8 code points.
   46|    103|    return 16;
   47|    103|  }
   48|  9.61k|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (48:7): [True: 169, False: 9.44k]
  ------------------
   49|       |    // We want to take 4 3-byte UTF-8 code units and turn them into 4 4-byte
   50|       |    // UTF-32 code units. There is probably a more efficient sequence, but the
   51|       |    // following might do.
   52|    169|    const __m128i sh =
   53|    169|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   54|    169|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   55|    169|    const __m128i ascii =
   56|    169|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   57|    169|    const __m128i middlebyte =
   58|    169|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   59|    169|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   60|    169|    const __m128i highbyte =
   61|    169|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   62|    169|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   63|    169|    const __m128i composed =
   64|    169|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   65|    169|    _mm_storeu_si128((__m128i *)utf32_output, composed);
   66|    169|    utf32_output += 4;
   67|    169|    return 12;
   68|    169|  }
   69|       |  /// We do not have a fast path available, so we fallback.
   70|       |
   71|  9.44k|  const uint8_t idx =
   72|  9.44k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   73|  9.44k|  const uint8_t consumed =
   74|  9.44k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   75|  9.44k|  if (idx < 64) {
  ------------------
  |  Branch (75:7): [True: 3.86k, False: 5.57k]
  ------------------
   76|       |    // SIX (6) input code-code units
   77|       |    // this is a relatively easy scenario
   78|       |    // we process SIX (6) input code-code units. The max length in bytes of six
   79|       |    // code code units spanning between 1 and 2 bytes each is 12 bytes. On
   80|       |    // processors where pdep/pext is fast, we might be able to use a small
   81|       |    // lookup table.
   82|  3.86k|    const __m128i sh =
   83|  3.86k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   84|  3.86k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   85|  3.86k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   86|  3.86k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   87|  3.86k|    const __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   88|  3.86k|    _mm256_storeu_si256((__m256i *)utf32_output,
   89|  3.86k|                        _mm256_cvtepu16_epi32(composed));
   90|  3.86k|    utf32_output += 6; // We wrote 24 bytes, 6 code points. There is a potential
   91|       |    // overflow of 32 - 24 = 8 bytes.
   92|  5.57k|  } else if (idx < 145) {
  ------------------
  |  Branch (92:14): [True: 1.17k, False: 4.40k]
  ------------------
   93|       |    // FOUR (4) input code-code units
   94|  1.17k|    const __m128i sh =
   95|  1.17k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   96|  1.17k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   97|  1.17k|    const __m128i ascii =
   98|  1.17k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   99|  1.17k|    const __m128i middlebyte =
  100|  1.17k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  101|  1.17k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  102|  1.17k|    const __m128i highbyte =
  103|  1.17k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  104|  1.17k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  105|  1.17k|    const __m128i composed =
  106|  1.17k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  107|  1.17k|    _mm_storeu_si128((__m128i *)utf32_output, composed);
  108|  1.17k|    utf32_output += 4;
  109|  4.40k|  } else if (idx < 209) {
  ------------------
  |  Branch (109:14): [True: 4.20k, False: 191]
  ------------------
  110|       |    // TWO (2) input code-code units
  111|  4.20k|    const __m128i sh =
  112|  4.20k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  113|  4.20k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  114|  4.20k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  115|  4.20k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  116|  4.20k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  117|  4.20k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  118|       |    // correct for spurious high bit
  119|  4.20k|    const __m128i correct =
  120|  4.20k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  121|  4.20k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  122|  4.20k|    const __m128i middlehighbyte_shifted = _mm_srli_epi32(middlehighbyte, 4);
  123|  4.20k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0x07000000));
  124|  4.20k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 6);
  125|  4.20k|    const __m128i composed =
  126|  4.20k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  127|  4.20k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  128|  4.20k|    _mm_storeu_si128((__m128i *)utf32_output, composed);
  129|  4.20k|    utf32_output +=
  130|  4.20k|        3; // We wrote 3 * 4 bytes, there is a potential overflow of 4 bytes.
  131|  4.20k|  } else {
  132|       |    // here we know that there is an error but we do not handle errors
  133|    191|  }
  134|  9.44k|  return consumed;
  135|  9.61k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1623utf16_gather_high_bytesILNS_10endiannessE0EEENS1_4simd5simd8IhEERKNS5_6simd16ItEESB_:
    3|  11.6k|                                       const simd16<uint16_t> &in1) {
    4|  11.6k|  if (big_endian) {
  ------------------
  |  Branch (4:7): [Folded, False: 11.6k]
  ------------------
    5|       |    // we want lower bytes
    6|      0|    const auto mask = simd16<uint16_t>(0x00ff);
    7|      0|    const auto t0 = in0 & mask;
    8|      0|    const auto t1 = in1 & mask;
    9|       |
   10|      0|    return simd16<uint16_t>::pack(t0, t1);
   11|  11.6k|  } else {
   12|  11.6k|    const auto t0 = in0.shr<8>();
   13|  11.6k|    const auto t1 = in1.shr<8>();
   14|       |
   15|  11.6k|    return simd16<uint16_t>::pack(t0, t1);
   16|  11.6k|  }
   17|  11.6k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1623utf16_gather_high_bytesILNS_10endiannessE1EEENS1_4simd5simd8IhEERKNS5_6simd16ItEESB_:
    3|  12.1k|                                       const simd16<uint16_t> &in1) {
    4|  12.1k|  if (big_endian) {
  ------------------
  |  Branch (4:7): [True: 12.1k, Folded]
  ------------------
    5|       |    // we want lower bytes
    6|  12.1k|    const auto mask = simd16<uint16_t>(0x00ff);
    7|  12.1k|    const auto t0 = in0 & mask;
    8|  12.1k|    const auto t1 = in1 & mask;
    9|       |
   10|  12.1k|    return simd16<uint16_t>::pack(t0, t1);
   11|  12.1k|  } else {
   12|      0|    const auto t0 = in0.shr<8>();
   13|      0|    const auto t1 = in1.shr<8>();
   14|       |
   15|      0|    return simd16<uint16_t>::pack(t0, t1);
   16|      0|  }
   17|  12.1k|}

_ZNK7simdutf7haswell14implementation13validate_utf8EPKcm:
  264|  22.0k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
  265|  22.0k|  return haswell::utf8_validation::generic_validate_utf8(buf, len);
  266|  22.0k|}
_ZNK7simdutf7haswell14implementation25validate_utf8_with_errorsEPKcm:
  271|  5.56k|    const char *buf, size_t len) const noexcept {
  272|  5.56k|  return haswell::utf8_validation::generic_validate_utf8_with_errors(buf, len);
  273|  5.56k|}
_ZNK7simdutf7haswell14implementation16validate_utf16leEPKDsm:
  310|  16.0k|                                 size_t len) const noexcept {
  311|  16.0k|  if (simdutf_unlikely(len == 0)) {
  ------------------
  |  |   92|  16.0k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (92:33): [True: 13.7k, False: 2.38k]
  |  |  ------------------
  ------------------
  312|       |    // empty input is valid UTF-16. protect the implementation from
  313|       |    // handling nullptr
  314|  13.7k|    return true;
  315|  13.7k|  }
  316|  2.38k|  const auto res =
  317|  2.38k|      haswell::utf16::validate_utf16_with_errors<endianness::LITTLE>(buf, len);
  318|  2.38k|  if (res.is_err()) {
  ------------------
  |  Branch (318:7): [True: 42, False: 2.34k]
  ------------------
  319|     42|    return false;
  320|     42|  }
  321|       |
  322|  2.34k|  if (res.count == len) {
  ------------------
  |  Branch (322:7): [True: 0, False: 2.34k]
  ------------------
  323|      0|    return true;
  324|      0|  }
  325|       |
  326|  2.34k|  return scalar::utf16::validate<endianness::LITTLE>(buf + res.count,
  327|  2.34k|                                                     len - res.count);
  328|  2.34k|}
_ZNK7simdutf7haswell14implementation16validate_utf16beEPKDsm:
  334|  16.0k|                                 size_t len) const noexcept {
  335|  16.0k|  if (simdutf_unlikely(len == 0)) {
  ------------------
  |  |   92|  16.0k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (92:33): [True: 13.6k, False: 2.39k]
  |  |  ------------------
  ------------------
  336|       |    // empty input is valid UTF-16. protect the implementation from
  337|       |    // handling nullptr
  338|  13.6k|    return true;
  339|  13.6k|  }
  340|  2.39k|  const auto res =
  341|  2.39k|      haswell::utf16::validate_utf16_with_errors<endianness::BIG>(buf, len);
  342|  2.39k|  if (res.is_err()) {
  ------------------
  |  Branch (342:7): [True: 39, False: 2.35k]
  ------------------
  343|     39|    return false;
  344|     39|  }
  345|       |
  346|  2.35k|  if (res.count == len) {
  ------------------
  |  Branch (346:7): [True: 0, False: 2.35k]
  ------------------
  347|      0|    return true;
  348|      0|  }
  349|       |
  350|  2.35k|  return scalar::utf16::validate<endianness::BIG>(buf + res.count,
  351|  2.35k|                                                  len - res.count);
  352|  2.35k|}
_ZNK7simdutf7haswell14implementation28validate_utf16le_with_errorsEPKDsm:
  355|  5.56k|    const char16_t *buf, size_t len) const noexcept {
  356|       |
  357|  5.56k|  const result res =
  358|  5.56k|      haswell::utf16::validate_utf16_with_errors<endianness::LITTLE>(buf, len);
  359|  5.56k|  if (res.count != len) {
  ------------------
  |  Branch (359:7): [True: 355, False: 5.20k]
  ------------------
  360|    355|    const result scalar_res =
  361|    355|        scalar::utf16::validate_with_errors<endianness::LITTLE>(
  362|    355|            buf + res.count, len - res.count);
  363|    355|    return result(scalar_res.error, res.count + scalar_res.count);
  364|  5.20k|  } else {
  365|  5.20k|    return res;
  366|  5.20k|  }
  367|  5.56k|}
_ZNK7simdutf7haswell14implementation28validate_utf16be_with_errorsEPKDsm:
  370|  5.56k|    const char16_t *buf, size_t len) const noexcept {
  371|  5.56k|  const result res =
  372|  5.56k|      haswell::utf16::validate_utf16_with_errors<endianness::BIG>(buf, len);
  373|  5.56k|  if (res.count != len) {
  ------------------
  |  Branch (373:7): [True: 363, False: 5.19k]
  ------------------
  374|    363|    const result scalar_res =
  375|    363|        scalar::utf16::validate_with_errors<endianness::BIG>(buf + res.count,
  376|    363|                                                             len - res.count);
  377|    363|    return result(scalar_res.error, res.count + scalar_res.count);
  378|  5.19k|  } else {
  379|  5.19k|    return res;
  380|  5.19k|  }
  381|  5.56k|}
_ZNK7simdutf7haswell14implementation14validate_utf32EPKDim:
  396|  10.5k|implementation::validate_utf32(const char32_t *buf, size_t len) const noexcept {
  397|  10.5k|  return utf32::validate(buf, len);
  398|  10.5k|}
_ZNK7simdutf7haswell14implementation22convert_latin1_to_utf8EPKcmPc:
  410|  5.83k|    const char *buf, size_t len, char *utf8_output) const noexcept {
  411|  5.83k|  std::pair<const char *, char *> ret =
  412|  5.83k|      avx2_convert_latin1_to_utf8(buf, len, utf8_output);
  413|  5.83k|  size_t converted_chars = ret.second - utf8_output;
  414|       |
  415|  5.83k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (415:7): [True: 1.44k, False: 4.39k]
  ------------------
  416|  1.44k|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  417|  1.44k|        ret.first, len - (ret.first - buf), ret.second);
  418|  1.44k|    converted_chars += scalar_converted_chars;
  419|  1.44k|  }
  420|       |
  421|  5.83k|  return converted_chars;
  422|  5.83k|}
_ZNK7simdutf7haswell14implementation25convert_latin1_to_utf16leEPKcmPDs:
  427|  5.56k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  428|  5.56k|  std::pair<const char *, char16_t *> ret =
  429|  5.56k|      avx2_convert_latin1_to_utf16<endianness::LITTLE>(buf, len, utf16_output);
  430|  5.56k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (430:7): [True: 0, False: 5.56k]
  ------------------
  431|      0|    return 0;
  432|      0|  }
  433|  5.56k|  size_t converted_chars = ret.second - utf16_output;
  434|  5.56k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (434:7): [True: 808, False: 4.75k]
  ------------------
  435|    808|    const size_t scalar_converted_chars =
  436|    808|        scalar::latin1_to_utf16::convert<endianness::LITTLE>(
  437|    808|            ret.first, len - (ret.first - buf), ret.second);
  438|    808|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (438:9): [True: 0, False: 808]
  ------------------
  439|      0|      return 0;
  440|      0|    }
  441|    808|    converted_chars += scalar_converted_chars;
  442|    808|  }
  443|  5.56k|  return converted_chars;
  444|  5.56k|}
_ZNK7simdutf7haswell14implementation25convert_latin1_to_utf16beEPKcmPDs:
  447|  5.56k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  448|  5.56k|  std::pair<const char *, char16_t *> ret =
  449|  5.56k|      avx2_convert_latin1_to_utf16<endianness::BIG>(buf, len, utf16_output);
  450|  5.56k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (450:7): [True: 0, False: 5.56k]
  ------------------
  451|      0|    return 0;
  452|      0|  }
  453|  5.56k|  size_t converted_chars = ret.second - utf16_output;
  454|  5.56k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (454:7): [True: 808, False: 4.75k]
  ------------------
  455|    808|    const size_t scalar_converted_chars =
  456|    808|        scalar::latin1_to_utf16::convert<endianness::BIG>(
  457|    808|            ret.first, len - (ret.first - buf), ret.second);
  458|    808|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (458:9): [True: 0, False: 808]
  ------------------
  459|      0|      return 0;
  460|      0|    }
  461|    808|    converted_chars += scalar_converted_chars;
  462|    808|  }
  463|  5.56k|  return converted_chars;
  464|  5.56k|}
_ZNK7simdutf7haswell14implementation23convert_latin1_to_utf32EPKcmPDi:
  469|  5.56k|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  470|  5.56k|  std::pair<const char *, char32_t *> ret =
  471|  5.56k|      avx2_convert_latin1_to_utf32(buf, len, utf32_output);
  472|  5.56k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (472:7): [True: 0, False: 5.56k]
  ------------------
  473|      0|    return 0;
  474|      0|  }
  475|  5.56k|  size_t converted_chars = ret.second - utf32_output;
  476|  5.56k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (476:7): [True: 759, False: 4.80k]
  ------------------
  477|    759|    const size_t scalar_converted_chars = scalar::latin1_to_utf32::convert(
  478|    759|        ret.first, len - (ret.first - buf), ret.second);
  479|    759|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (479:9): [True: 0, False: 759]
  ------------------
  480|      0|      return 0;
  481|      0|    }
  482|    759|    converted_chars += scalar_converted_chars;
  483|    759|  }
  484|  5.56k|  return converted_chars;
  485|  5.56k|}
_ZNK7simdutf7haswell14implementation22convert_utf8_to_latin1EPKcmPc:
  490|  11.1k|    const char *buf, size_t len, char *latin1_output) const noexcept {
  491|  11.1k|  utf8_to_latin1::validating_transcoder converter;
  492|  11.1k|  return converter.convert(buf, len, latin1_output);
  493|  11.1k|}
_ZNK7simdutf7haswell14implementation23convert_utf8_to_utf16leEPKcmPDs:
  509|  11.0k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  510|  11.0k|  utf8_to_utf16::validating_transcoder converter;
  511|  11.0k|  return converter.convert<endianness::LITTLE>(buf, len, utf16_output);
  512|  11.0k|}
_ZNK7simdutf7haswell14implementation23convert_utf8_to_utf16beEPKcmPDs:
  515|  11.0k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  516|  11.0k|  utf8_to_utf16::validating_transcoder converter;
  517|  11.0k|  return converter.convert<endianness::BIG>(buf, len, utf16_output);
  518|  11.0k|}
_ZNK7simdutf7haswell14implementation21convert_utf8_to_utf32EPKcmPDi:
  548|  5.56k|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  549|  5.56k|  utf8_to_utf32::validating_transcoder converter;
  550|  5.56k|  return converter.convert(buf, len, utf32_output);
  551|  5.56k|}
_ZNK7simdutf7haswell14implementation25convert_utf16le_to_latin1EPKDsmPc:
  567|  5.56k|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  568|  5.56k|  std::pair<const char16_t *, char *> ret =
  569|  5.56k|      haswell::avx2_convert_utf16_to_latin1<endianness::LITTLE>(buf, len,
  570|  5.56k|                                                                latin1_output);
  571|  5.56k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (571:7): [True: 0, False: 5.56k]
  ------------------
  572|      0|    return 0;
  573|      0|  }
  574|  5.56k|  size_t saved_bytes = ret.second - latin1_output;
  575|  5.56k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (575:7): [True: 828, False: 4.73k]
  ------------------
  576|    828|    const size_t scalar_saved_bytes =
  577|    828|        scalar::utf16_to_latin1::convert<endianness::LITTLE>(
  578|    828|            ret.first, len - (ret.first - buf), ret.second);
  579|    828|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (579:9): [True: 0, False: 828]
  ------------------
  580|      0|      return 0;
  581|      0|    }
  582|    828|    saved_bytes += scalar_saved_bytes;
  583|    828|  }
  584|  5.56k|  return saved_bytes;
  585|  5.56k|}
_ZNK7simdutf7haswell14implementation25convert_utf16be_to_latin1EPKDsmPc:
  588|  5.56k|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  589|  5.56k|  std::pair<const char16_t *, char *> ret =
  590|  5.56k|      haswell::avx2_convert_utf16_to_latin1<endianness::BIG>(buf, len,
  591|  5.56k|                                                             latin1_output);
  592|  5.56k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (592:7): [True: 0, False: 5.56k]
  ------------------
  593|      0|    return 0;
  594|      0|  }
  595|  5.56k|  size_t saved_bytes = ret.second - latin1_output;
  596|  5.56k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (596:7): [True: 828, False: 4.73k]
  ------------------
  597|    828|    const size_t scalar_saved_bytes =
  598|    828|        scalar::utf16_to_latin1::convert<endianness::BIG>(
  599|    828|            ret.first, len - (ret.first - buf), ret.second);
  600|    828|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (600:9): [True: 0, False: 828]
  ------------------
  601|      0|      return 0;
  602|      0|    }
  603|    828|    saved_bytes += scalar_saved_bytes;
  604|    828|  }
  605|  5.56k|  return saved_bytes;
  606|  5.56k|}
_ZNK7simdutf7haswell14implementation23convert_utf16le_to_utf8EPKDsmPc:
  677|  10.5k|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  678|  10.5k|  std::pair<const char16_t *, char *> ret =
  679|  10.5k|      haswell::avx2_convert_utf16_to_utf8<endianness::LITTLE>(buf, len,
  680|  10.5k|                                                              utf8_output);
  681|  10.5k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (681:7): [True: 55, False: 10.4k]
  ------------------
  682|     55|    return 0;
  683|     55|  }
  684|  10.4k|  size_t saved_bytes = ret.second - utf8_output;
  685|  10.4k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (685:7): [True: 1.16k, False: 9.30k]
  ------------------
  686|  1.16k|    const size_t scalar_saved_bytes =
  687|  1.16k|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  688|  1.16k|            ret.first, len - (ret.first - buf), ret.second);
  689|  1.16k|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (689:9): [True: 37, False: 1.12k]
  ------------------
  690|     37|      return 0;
  691|     37|    }
  692|  1.12k|    saved_bytes += scalar_saved_bytes;
  693|  1.12k|  }
  694|  10.4k|  return saved_bytes;
  695|  10.4k|}
_ZNK7simdutf7haswell14implementation23convert_utf16be_to_utf8EPKDsmPc:
  698|  10.5k|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  699|  10.5k|  std::pair<const char16_t *, char *> ret =
  700|  10.5k|      haswell::avx2_convert_utf16_to_utf8<endianness::BIG>(buf, len,
  701|  10.5k|                                                           utf8_output);
  702|  10.5k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (702:7): [True: 52, False: 10.4k]
  ------------------
  703|     52|    return 0;
  704|     52|  }
  705|  10.4k|  size_t saved_bytes = ret.second - utf8_output;
  706|  10.4k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (706:7): [True: 1.17k, False: 9.30k]
  ------------------
  707|  1.17k|    const size_t scalar_saved_bytes =
  708|  1.17k|        scalar::utf16_to_utf8::convert<endianness::BIG>(
  709|  1.17k|            ret.first, len - (ret.first - buf), ret.second);
  710|  1.17k|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (710:9): [True: 32, False: 1.14k]
  ------------------
  711|     32|      return 0;
  712|     32|    }
  713|  1.14k|    saved_bytes += scalar_saved_bytes;
  714|  1.14k|  }
  715|  10.4k|  return saved_bytes;
  716|  10.4k|}
_ZNK7simdutf7haswell14implementation21convert_utf32_to_utf8EPKDimPc:
  787|  4.96k|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  788|  4.96k|  std::pair<const char32_t *, char *> ret =
  789|  4.96k|      avx2_convert_utf32_to_utf8(buf, len, utf8_output);
  790|  4.96k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (790:7): [True: 0, False: 4.96k]
  ------------------
  791|      0|    return 0;
  792|      0|  }
  793|  4.96k|  size_t saved_bytes = ret.second - utf8_output;
  794|  4.96k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (794:7): [True: 861, False: 4.10k]
  ------------------
  795|    861|    const size_t scalar_saved_bytes = scalar::utf32_to_utf8::convert(
  796|    861|        ret.first, len - (ret.first - buf), ret.second);
  797|    861|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (797:9): [True: 0, False: 861]
  ------------------
  798|      0|      return 0;
  799|      0|    }
  800|    861|    saved_bytes += scalar_saved_bytes;
  801|    861|  }
  802|  4.96k|  return saved_bytes;
  803|  4.96k|}
_ZNK7simdutf7haswell14implementation23convert_utf32_to_latin1EPKDimPc:
  808|  5.56k|    const char32_t *buf, size_t len, char *latin1_output) const noexcept {
  809|  5.56k|  std::pair<const char32_t *, char *> ret =
  810|  5.56k|      avx2_convert_utf32_to_latin1(buf, len, latin1_output);
  811|  5.56k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (811:7): [True: 0, False: 5.56k]
  ------------------
  812|      0|    return 0;
  813|      0|  }
  814|  5.56k|  size_t saved_bytes = ret.second - latin1_output;
  815|  5.56k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (815:7): [True: 828, False: 4.73k]
  ------------------
  816|    828|    const size_t scalar_saved_bytes = scalar::utf32_to_latin1::convert(
  817|    828|        ret.first, len - (ret.first - buf), ret.second);
  818|    828|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (818:9): [True: 0, False: 828]
  ------------------
  819|      0|      return 0;
  820|      0|    }
  821|    828|    saved_bytes += scalar_saved_bytes;
  822|    828|  }
  823|  5.56k|  return saved_bytes;
  824|  5.56k|}
_ZNK7simdutf7haswell14implementation10count_utf8EPKcm:
 1115|  11.1k|implementation::count_utf8(const char *in, size_t size) const noexcept {
 1116|  11.1k|  return utf8::count_code_points_bytemask(in, size);
 1117|  11.1k|}
_ZNK7simdutf7haswell14implementation23latin1_length_from_utf8EPKcm:
 1122|  11.1k|    const char *buf, size_t len) const noexcept {
 1123|  11.1k|  return count_utf8(buf, len);
 1124|  11.1k|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16leEPKDsm:
 1129|  10.5k|    const char16_t *input, size_t length) const noexcept {
 1130|  10.5k|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1131|  10.5k|                                                                    length);
 1132|  10.5k|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16beEPKDsm:
 1135|  10.5k|    const char16_t *input, size_t length) const noexcept {
 1136|  10.5k|  return utf16::utf8_length_from_utf16_bytemask<endianness::BIG>(input, length);
 1137|  10.5k|}
_ZNK7simdutf7haswell14implementation22utf16_length_from_utf8EPKcm:
 1154|  22.0k|    const char *input, size_t length) const noexcept {
 1155|  22.0k|  return utf8::utf16_length_from_utf8_bytemask(input, length);
 1156|  22.0k|}
_ZNK7simdutf7haswell14implementation23utf8_length_from_latin1EPKcm:
 1189|  5.83k|    const char *input, size_t len) const noexcept {
 1190|  5.83k|  const uint8_t *data = reinterpret_cast<const uint8_t *>(input);
 1191|  5.83k|  size_t answer = len / sizeof(__m256i) * sizeof(__m256i);
 1192|  5.83k|  size_t i = 0;
 1193|  5.83k|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1193:7): [True: 0, False: 5.83k]
  ------------------
 1194|      0|    __m256i four_64bits = _mm256_setzero_si256();
 1195|      0|    while (i + sizeof(__m256i) <= len) {
  ------------------
  |  Branch (1195:12): [True: 0, False: 0]
  ------------------
 1196|      0|      __m256i runner = _mm256_setzero_si256();
 1197|       |      // We can do up to 255 loops without overflow.
 1198|      0|      size_t iterations = (len - i) / sizeof(__m256i);
 1199|      0|      if (iterations > 255) {
  ------------------
  |  Branch (1199:11): [True: 0, False: 0]
  ------------------
 1200|      0|        iterations = 255;
 1201|      0|      }
 1202|      0|      size_t max_i = i + iterations * sizeof(__m256i) - sizeof(__m256i);
 1203|      0|      for (; i + 4 * sizeof(__m256i) <= max_i; i += 4 * sizeof(__m256i)) {
  ------------------
  |  Branch (1203:14): [True: 0, False: 0]
  ------------------
 1204|      0|        __m256i input1 = _mm256_loadu_si256((const __m256i *)(data + i));
 1205|      0|        __m256i input2 =
 1206|      0|            _mm256_loadu_si256((const __m256i *)(data + i + sizeof(__m256i)));
 1207|      0|        __m256i input3 = _mm256_loadu_si256(
 1208|      0|            (const __m256i *)(data + i + 2 * sizeof(__m256i)));
 1209|      0|        __m256i input4 = _mm256_loadu_si256(
 1210|      0|            (const __m256i *)(data + i + 3 * sizeof(__m256i)));
 1211|      0|        __m256i input12 =
 1212|      0|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input1),
 1213|      0|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input2));
 1214|      0|        __m256i input23 =
 1215|      0|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input3),
 1216|      0|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input4));
 1217|      0|        __m256i input1234 = _mm256_add_epi8(input12, input23);
 1218|      0|        runner = _mm256_sub_epi8(runner, input1234);
 1219|      0|      }
 1220|      0|      for (; i <= max_i; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1220:14): [True: 0, False: 0]
  ------------------
 1221|      0|        __m256i input_256_chunk =
 1222|      0|            _mm256_loadu_si256((const __m256i *)(data + i));
 1223|      0|        runner = _mm256_sub_epi8(
 1224|      0|            runner, _mm256_cmpgt_epi8(_mm256_setzero_si256(), input_256_chunk));
 1225|      0|      }
 1226|      0|      four_64bits = _mm256_add_epi64(
 1227|      0|          four_64bits, _mm256_sad_epu8(runner, _mm256_setzero_si256()));
 1228|      0|    }
 1229|      0|    answer += _mm256_extract_epi64(four_64bits, 0) +
 1230|      0|              _mm256_extract_epi64(four_64bits, 1) +
 1231|      0|              _mm256_extract_epi64(four_64bits, 2) +
 1232|      0|              _mm256_extract_epi64(four_64bits, 3);
 1233|  5.83k|  } else if (answer > 0) {
  ------------------
  |  Branch (1233:14): [True: 865, False: 4.97k]
  ------------------
 1234|  6.51k|    for (; i + sizeof(__m256i) <= len; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1234:12): [True: 5.64k, False: 865]
  ------------------
 1235|  5.64k|      __m256i latin = _mm256_loadu_si256((const __m256i *)(data + i));
 1236|  5.64k|      uint32_t non_ascii = _mm256_movemask_epi8(latin);
 1237|  5.64k|      answer += count_ones(non_ascii);
 1238|  5.64k|    }
 1239|    865|  }
 1240|  5.83k|  return answer + scalar::latin1::utf8_length_from_latin1(
 1241|  5.83k|                      reinterpret_cast<const char *>(data + i), len - i);
 1242|  5.83k|}
_ZNK7simdutf7haswell14implementation22utf8_length_from_utf32EPKDim:
 1247|  4.96k|    const char32_t *input, size_t length) const noexcept {
 1248|  4.96k|  return utf32::utf8_length_from_utf32(input, length);
 1249|  4.96k|}
_ZNK7simdutf7haswell14implementation22utf32_length_from_utf8EPKcm:
 1275|  5.56k|    const char *input, size_t length) const noexcept {
 1276|  5.56k|  return utf8::count_code_points(input, length);
 1277|  5.56k|}
_ZNK7simdutf7haswell14implementation16base64_to_binaryEPKcmPcNS_14base64_optionsENS_27last_chunk_handling_optionsE:
 1283|  15.9k|    last_chunk_handling_options last_chunk_options) const noexcept {
 1284|  15.9k|  if (options & base64_default_or_url) {
  ------------------
  |  Branch (1284:7): [True: 0, False: 15.9k]
  ------------------
 1285|      0|    if (options == base64_options::base64_default_or_url_accept_garbage) {
  ------------------
  |  Branch (1285:9): [True: 0, False: 0]
  ------------------
 1286|      0|      return base64::compress_decode_base64<false, true, true>(
 1287|      0|          output, input, length, options, last_chunk_options);
 1288|      0|    } else {
 1289|      0|      return base64::compress_decode_base64<false, false, true>(
 1290|      0|          output, input, length, options, last_chunk_options);
 1291|      0|    }
 1292|  15.9k|  } else if (options & base64_url) {
  ------------------
  |  Branch (1292:14): [True: 0, False: 15.9k]
  ------------------
 1293|      0|    if (options == base64_options::base64_url_accept_garbage) {
  ------------------
  |  Branch (1293:9): [True: 0, False: 0]
  ------------------
 1294|      0|      return base64::compress_decode_base64<true, true, false>(
 1295|      0|          output, input, length, options, last_chunk_options);
 1296|      0|    } else {
 1297|      0|      return base64::compress_decode_base64<true, false, false>(
 1298|      0|          output, input, length, options, last_chunk_options);
 1299|      0|    }
 1300|  15.9k|  } else {
 1301|  15.9k|    if (options == base64_options::base64_default_accept_garbage) {
  ------------------
  |  Branch (1301:9): [True: 0, False: 15.9k]
  ------------------
 1302|      0|      return base64::compress_decode_base64<false, true, false>(
 1303|      0|          output, input, length, options, last_chunk_options);
 1304|  15.9k|    } else {
 1305|  15.9k|      return base64::compress_decode_base64<false, false, false>(
 1306|  15.9k|          output, input, length, options, last_chunk_options);
 1307|  15.9k|    }
 1308|  15.9k|  }
 1309|  15.9k|}
_ZNK7simdutf7haswell14implementation24base64_to_binary_detailsEPKcmPcNS_14base64_optionsENS_27last_chunk_handling_optionsE:
 1313|  48.5k|    last_chunk_handling_options last_chunk_options) const noexcept {
 1314|  48.5k|  if (options & base64_default_or_url) {
  ------------------
  |  Branch (1314:7): [True: 0, False: 48.5k]
  ------------------
 1315|      0|    if (options == base64_options::base64_default_or_url_accept_garbage) {
  ------------------
  |  Branch (1315:9): [True: 0, False: 0]
  ------------------
 1316|      0|      return base64::compress_decode_base64<false, true, true>(
 1317|      0|          output, input, length, options, last_chunk_options);
 1318|      0|    } else {
 1319|      0|      return base64::compress_decode_base64<false, false, true>(
 1320|      0|          output, input, length, options, last_chunk_options);
 1321|      0|    }
 1322|  48.5k|  } else if (options & base64_url) {
  ------------------
  |  Branch (1322:14): [True: 0, False: 48.5k]
  ------------------
 1323|      0|    if (options == base64_options::base64_url_accept_garbage) {
  ------------------
  |  Branch (1323:9): [True: 0, False: 0]
  ------------------
 1324|      0|      return base64::compress_decode_base64<true, true, false>(
 1325|      0|          output, input, length, options, last_chunk_options);
 1326|      0|    } else {
 1327|      0|      return base64::compress_decode_base64<true, false, false>(
 1328|      0|          output, input, length, options, last_chunk_options);
 1329|      0|    }
 1330|  48.5k|  } else {
 1331|  48.5k|    if (options == base64_options::base64_default_accept_garbage) {
  ------------------
  |  Branch (1331:9): [True: 0, False: 48.5k]
  ------------------
 1332|      0|      return base64::compress_decode_base64<false, true, false>(
 1333|      0|          output, input, length, options, last_chunk_options);
 1334|  48.5k|    } else {
 1335|  48.5k|      return base64::compress_decode_base64<false, false, false>(
 1336|  48.5k|          output, input, length, options, last_chunk_options);
 1337|  48.5k|    }
 1338|  48.5k|  }
 1339|  48.5k|}
_ZNK7simdutf7haswell14implementation16binary_to_base64EPKcmPcNS_14base64_optionsE:
 1403|  15.1k|                                        base64_options options) const noexcept {
 1404|  15.1k|  if (options & base64_url) {
  ------------------
  |  Branch (1404:7): [True: 0, False: 15.1k]
  ------------------
 1405|      0|    return encode_base64<true>(output, input, length, options);
 1406|  15.1k|  } else {
 1407|  15.1k|    return encode_base64<false>(output, input, length, options);
 1408|  15.1k|  }
 1409|  15.1k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_18is_asciiERKNS1_4simd8simd8x64IhEE:
   13|  34.5k|simdutf_really_inline bool is_ascii(const simd8x64<uint8_t> &input) {
   14|  34.5k|  return input.reduce_or().is_ascii();
   15|  34.5k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_124must_be_2_3_continuationENS1_4simd5simd8IhEES4_:
   22|  26.1k|                         const simd8<uint8_t> prev3) {
   23|  26.1k|  simd8<uint8_t> is_third_byte =
   24|  26.1k|      prev2.saturating_sub(0xe0u - 0x80); // Only 111_____ will be > 0x80
   25|  26.1k|  simd8<uint8_t> is_fourth_byte =
   26|  26.1k|      prev3.saturating_sub(0xf0u - 0x80); // Only 1111____ will be > 0x80
   27|  26.1k|  return simd8<bool>(is_third_byte | is_fourth_byte);
   28|  26.1k|}

_ZNK7simdutf14implementation27supported_by_runtime_systemEv:
   65|  22.2k|bool implementation::supported_by_runtime_system() const {
   66|  22.2k|  uint32_t required_instruction_sets = this->required_instruction_sets();
   67|  22.2k|  uint32_t supported_instruction_sets =
   68|  22.2k|      internal::detect_supported_architectures();
   69|  22.2k|  return ((supported_instruction_sets & required_instruction_sets) ==
   70|  22.2k|          required_instruction_sets);
   71|  22.2k|}
_ZNK7simdutf14implementation33maximal_binary_length_from_base64EPKcm:
  118|  80.5k|    const char *input, size_t length) const noexcept {
  119|  80.5k|  return scalar::base64::maximal_binary_length_from_base64(input, length);
  120|  80.5k|}
_ZNK7simdutf14implementation25base64_length_from_binaryEmNS_14base64_optionsE:
  138|  47.1k|    size_t length, base64_options options) const noexcept {
  139|  47.1k|  return scalar::base64::base64_length_from_binary(length, options);
  140|  47.1k|}
_ZNK7simdutf8internal29available_implementation_list5beginEv:
 1504|  5.56k|available_implementation_list::begin() const noexcept {
 1505|  5.56k|  return internal::get_available_implementation_pointers().begin();
 1506|  5.56k|}
_ZNK7simdutf8internal29available_implementation_list3endEv:
 1508|  5.56k|available_implementation_list::end() const noexcept {
 1509|  5.56k|  return internal::get_available_implementation_pointers().end();
 1510|  5.56k|}
_ZNK7simdutf8internal29available_implementation_list21detect_best_supportedEv:
 1512|      1|available_implementation_list::detect_best_supported() const noexcept {
 1513|       |  // They are prelisted in priority order, so we just go down the list
 1514|      1|  uint32_t supported_instruction_sets =
 1515|      1|      internal::detect_supported_architectures();
 1516|      1|  for (const implementation *impl :
  ------------------
  |  Branch (1516:35): [True: 2, False: 0]
  ------------------
 1517|      2|       internal::get_available_implementation_pointers()) {
 1518|      2|    uint32_t required_instruction_sets = impl->required_instruction_sets();
 1519|      2|    if ((supported_instruction_sets & required_instruction_sets) ==
  ------------------
  |  Branch (1519:9): [True: 1, False: 1]
  ------------------
 1520|      2|        required_instruction_sets) {
 1521|      1|      return impl;
 1522|      1|    }
 1523|      2|  }
 1524|      0|  return get_unsupported_singleton(); // this should never happen?
 1525|      1|}
_ZNK7simdutf8internal49detect_best_supported_implementation_on_first_use8set_bestEv:
 1528|      1|detect_best_supported_implementation_on_first_use::set_best() const noexcept {
 1529|      1|  SIMDUTF_PUSH_DISABLE_WARNINGS
 1530|       |  SIMDUTF_DISABLE_DEPRECATED_WARNING // Disable CRT_SECURE warning on MSVC:
 1531|       |                                     // manually verified this is safe
 1532|      1|      char *force_implementation_name = getenv("SIMDUTF_FORCE_IMPLEMENTATION");
 1533|      1|  SIMDUTF_POP_DISABLE_WARNINGS
 1534|       |
 1535|      1|  if (force_implementation_name) {
  ------------------
  |  Branch (1535:7): [True: 0, False: 1]
  ------------------
 1536|      0|    auto force_implementation =
 1537|      0|        get_available_implementations()[force_implementation_name];
 1538|      0|    if (force_implementation) {
  ------------------
  |  Branch (1538:9): [True: 0, False: 0]
  ------------------
 1539|      0|      return get_active_implementation() = force_implementation;
 1540|      0|    } else {
 1541|       |      // Note: abort() and stderr usage within the library is forbidden.
 1542|      0|      return get_active_implementation() = get_unsupported_singleton();
 1543|      0|    }
 1544|      0|  }
 1545|      1|  return get_active_implementation() =
 1546|      1|             get_available_implementations().detect_best_supported();
 1547|      1|}
_ZN7simdutf29get_available_implementationsEv:
 1559|  5.56k|get_available_implementations() {
 1560|  5.56k|#if !SIMDUTF_USE_STATIC_INITIALIZATION
 1561|  5.56k|  static const internal::available_implementation_list
 1562|  5.56k|      available_implementations_instance{};
 1563|  5.56k|#endif
 1564|  5.56k|  return available_implementations_instance;
 1565|  5.56k|}
_ZN7simdutf25get_active_implementationEv:
 1587|  48.5k|get_active_implementation() {
 1588|  48.5k|#if !SIMDUTF_USE_STATIC_INITIALIZATION
 1589|  48.5k|  #if !SIMDUTF_SINGLE_IMPLEMENTATION
 1590|  48.5k|  static const internal::detect_best_supported_implementation_on_first_use
 1591|  48.5k|      detect_best_supported_implementation_on_first_use_singleton;
 1592|  48.5k|  #endif
 1593|  48.5k|  static internal::atomic_ptr<const implementation>
 1594|  48.5k|      active_implementation_instance{
 1595|       |  #if SIMDUTF_SINGLE_IMPLEMENTATION
 1596|       |          internal::get_single_implementation()
 1597|       |  #else
 1598|  48.5k|          &detect_best_supported_implementation_on_first_use_singleton
 1599|  48.5k|  #endif
 1600|  48.5k|      };
 1601|  48.5k|#endif
 1602|  48.5k|  return active_implementation_instance;
 1603|  48.5k|}
_ZN7simdutf21base64_to_binary_safeEPKcmPcRmNS_14base64_optionsENS_27last_chunk_handling_optionsEb:
 2600|  48.5k|                      bool decode_up_to_bad_char) noexcept {
 2601|  48.5k|  return base64_to_binary_safe_impl<char>(input, length, output, outlen,
 2602|  48.5k|                                          options, last_chunk_handling_options,
 2603|  48.5k|                                          decode_up_to_bad_char);
 2604|  48.5k|}
simdutf.cpp:_ZN7simdutf8internalL37get_available_implementation_pointersEv:
  934|  11.1k|get_available_implementation_pointers() {
  935|  11.1k|#if !SIMDUTF_USE_STATIC_INITIALIZATION
  936|  11.1k|  static const std::initializer_list<const implementation *>
  937|  11.1k|      available_implementation_pointers{
  938|  11.1k|  #if SIMDUTF_IMPLEMENTATION_ICELAKE
  939|  11.1k|          get_icelake_singleton(),
  940|  11.1k|  #endif
  941|  11.1k|  #if SIMDUTF_IMPLEMENTATION_HASWELL
  942|  11.1k|          get_haswell_singleton(),
  943|  11.1k|  #endif
  944|  11.1k|  #if SIMDUTF_IMPLEMENTATION_WESTMERE
  945|  11.1k|          get_westmere_singleton(),
  946|  11.1k|  #endif
  947|       |  #if SIMDUTF_IMPLEMENTATION_ARM64
  948|       |          get_arm64_singleton(),
  949|       |  #endif
  950|       |  #if SIMDUTF_IMPLEMENTATION_PPC64
  951|       |          get_ppc64_singleton(),
  952|       |  #endif
  953|       |  #if SIMDUTF_IMPLEMENTATION_RVV
  954|       |          get_rvv_singleton(),
  955|       |  #endif
  956|       |  #if SIMDUTF_IMPLEMENTATION_LASX
  957|       |          get_lasx_singleton(),
  958|       |  #endif
  959|       |  #if SIMDUTF_IMPLEMENTATION_LSX
  960|       |          get_lsx_singleton(),
  961|       |  #endif
  962|  11.1k|  #if SIMDUTF_IMPLEMENTATION_FALLBACK
  963|  11.1k|          get_fallback_singleton(),
  964|  11.1k|  #endif
  965|  11.1k|      };
  966|  11.1k|#endif
  967|  11.1k|  return available_implementation_pointers;
  968|  11.1k|}
simdutf.cpp:_ZN7simdutf8internalL21get_icelake_singletonEv:
  158|      1|static const icelake::implementation *get_icelake_singleton() {
  159|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  160|      1|  static const icelake::implementation icelake_singleton{};
  161|      1|  #endif
  162|      1|  return &icelake_singleton;
  163|      1|}
simdutf.cpp:_ZN7simdutf8internalL21get_haswell_singletonEv:
  169|      1|static const haswell::implementation *get_haswell_singleton() {
  170|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  171|      1|  static const haswell::implementation haswell_singleton{};
  172|      1|  #endif
  173|      1|  return &haswell_singleton;
  174|      1|}
simdutf.cpp:_ZN7simdutf8internalL22get_westmere_singletonEv:
  180|      1|static const westmere::implementation *get_westmere_singleton() {
  181|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  182|      1|  static const westmere::implementation westmere_singleton{};
  183|      1|  #endif
  184|      1|  return &westmere_singleton;
  185|      1|}
simdutf.cpp:_ZN7simdutf8internalL22get_fallback_singletonEv:
  246|      1|static const fallback::implementation *get_fallback_singleton() {
  247|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  248|      1|  static const fallback::implementation fallback_singleton{};
  249|      1|  #endif
  250|      1|  return &fallback_singleton;
  251|      1|}
_ZN7simdutf8internal49detect_best_supported_implementation_on_first_useC2Ev:
  888|      1|      : implementation("best_supported_detector",
  889|      1|                       "Detects the best supported implementation and sets it",
  890|      1|                       0) {}
_ZNK7simdutf8internal49detect_best_supported_implementation_on_first_use24base64_to_binary_detailsEPKcmPcNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  829|      1|          last_chunk_handling_options::loose) const noexcept override {
  830|      1|    return set_best()->base64_to_binary_details(input, length, output, options,
  831|      1|                                                last_chunk_handling_options);
  832|      1|  }

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_110count_onesEm:
   14|  13.3k|simdutf_really_inline long long int count_ones(uint64_t input_num) {
   15|       |  return _popcnt64(input_num);
   16|  13.3k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115trailing_zeroesEm:
   20|  1.56k|simdutf_really_inline int trailing_zeroes(uint64_t input_num) {
   21|       |  #if SIMDUTF_REGULAR_VISUAL_STUDIO
   22|       |  return (int)_tzcnt_u64(input_num);
   23|       |  #else  // SIMDUTF_REGULAR_VISUAL_STUDIO
   24|  1.56k|  return __builtin_ctzll(input_num);
   25|  1.56k|  #endif // SIMDUTF_REGULAR_VISUAL_STUDIO
   26|  1.56k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115is_power_of_twoImEEbT_:
   29|  2.32k|template <typename T> bool is_power_of_two(T x) { return (x & (x - 1)) == 0; }

_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_14simd5simd8IhEC2Ev:
  191|  82.9k|  simdutf_really_inline simd8() : base8_numeric<uint8_t>() {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhEC2Ev:
  124|  82.9k|  simdutf_really_inline base8_numeric() : base8<T>() {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2Ev:
   71|  82.9k|  simdutf_really_inline base8() : base<simd8<T>>() {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2Ev:
   14|  82.9k|  simdutf_really_inline base() : value{__m256i()} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IhE9reduce_orEv:
  294|  34.5k|  simdutf_really_inline simd8<T> reduce_or() const {
  295|  34.5k|    return this->chunks[0] | this->chunks[1];
  296|  34.5k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEorES5_:
   50|   145k|  simdutf_really_inline Child operator|(const Child other) const {
   51|   145k|    return _mm256_or_si256(*this, other);
   52|   145k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2EDv4_x:
  193|  1.27M|      : base8_numeric<uint8_t>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhEC2EDv4_x:
  126|  1.27M|      : base8<T>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2EDv4_x:
   73|  1.27M|  simdutf_really_inline base8(const __m256i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2EDv4_x:
   17|  1.27M|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE8is_asciiEv:
  234|  34.5k|  simdutf_really_inline bool is_ascii() const {
  235|  34.5k|    return _mm256_movemask_epi8(*this) == 0;
  236|  34.5k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEoRES5_:
   59|  84.6k|  simdutf_really_inline Child &operator|=(const Child other) {
   60|  84.6k|    auto this_cast = static_cast<Child *>(this);
   61|  84.6k|    *this_cast = *this_cast | other;
   62|  84.6k|    return *this_cast;
   63|  84.6k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi1EEENS4_IhEES8_:
   83|  30.5k|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   84|       |    return _mm256_alignr_epi8(
   85|  30.5k|        *this, _mm256_permute2x128_si256(prev_chunk, *this, 0x21), 16 - N);
   86|  30.5k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE3shrILi4EEES4_v:
  245|  61.0k|  template <int N> simdutf_really_inline simd8<uint8_t> shr() const {
  246|  61.0k|    return simd8<uint8_t>(_mm256_srli_epi16(*this, N)) & uint8_t(0xFFu >> N);
  247|  61.0k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE9lookup_16IhEENS2_5simd8IT_EES7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_:
  157|  91.5k|            L replace15) const {
  158|  91.5k|    return lookup_16(simd8<L>::repeat_16(
  159|  91.5k|        replace0, replace1, replace2, replace3, replace4, replace5, replace6,
  160|  91.5k|        replace7, replace8, replace9, replace10, replace11, replace12,
  161|  91.5k|        replace13, replace14, replace15));
  162|  91.5k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE9lookup_16IhEENS2_5simd8IT_EES8_:
  148|  91.5k|  simdutf_really_inline simd8<L> lookup_16(simd8<L> lookup_table) const {
  149|  91.5k|    return _mm256_shuffle_epi8(lookup_table, *this);
  150|  91.5k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE9repeat_16Ehhhhhhhhhhhhhhhh:
  118|  91.5k|                                                  T v14, T v15) {
  119|  91.5k|    return simd8<T>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
  120|  91.5k|                    v14, v15, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
  121|  91.5k|                    v12, v13, v14, v15);
  122|  91.5k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2Ehhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh:
  207|  91.5k|      : simd8(_mm256_setr_epi8(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
  208|  91.5k|                               v12, v13, v14, v15, v16, v17, v18, v19, v20, v21,
  209|  91.5k|                               v22, v23, v24, v25, v26, v27, v28, v29, v30,
  210|  91.5k|                               v31)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2Eh:
  195|   227k|  simdutf_really_inline simd8(uint8_t _value) : simd8(splat(_value)) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi2EEENS4_IhEES8_:
   83|  26.1k|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   84|       |    return _mm256_alignr_epi8(
   85|  26.1k|        *this, _mm256_permute2x128_si256(prev_chunk, *this, 0x21), 16 - N);
   86|  26.1k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi3EEENS4_IhEES8_:
   83|  26.1k|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   84|       |    return _mm256_alignr_epi8(
   85|  26.1k|        *this, _mm256_permute2x128_si256(prev_chunk, *this, 0x21), 16 - N);
   86|  26.1k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE14saturating_subES4_:
  214|  60.2k|  saturating_sub(const simd8<uint8_t> other) const {
  215|  60.2k|    return _mm256_subs_epu8(*this, other);
  216|  60.2k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IbEC2EDv4_x:
   95|   100k|  simdutf_really_inline simd8(const __m256i _value) : base8<bool>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IbNS2_5simd8IbEEEC2EDv4_x:
   73|   100k|  simdutf_really_inline base8(const __m256i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEC2EDv4_x:
   17|   100k|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEcvRKDv4_xEv:
   19|  56.2k|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEeoES5_:
   56|  26.1k|  simdutf_really_inline Child operator^(const Child other) const {
   57|  26.1k|    return _mm256_xor_si256(*this, other);
   58|  26.1k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2EPKh:
  197|  7.82k|  simdutf_really_inline simd8(const uint8_t values[32]) : simd8(load(values)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE4loadEPKh:
  111|  77.0k|  static simdutf_really_inline simd8<T> load(const T values[32]) {
  112|  77.0k|    return _mm256_loadu_si256(reinterpret_cast<const __m256i *>(values));
  113|  77.0k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE7gt_bitsES4_:
  225|  7.82k|  gt_bits(const simd8<uint8_t> other) const {
  226|  7.82k|    return this->saturating_sub(other);
  227|  7.82k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEC2EDv4_x:
   17|   311k|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEcvRKDv4_xEv:
   19|   329k|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IbE10to_bitmaskEv:
   99|  44.1k|  simdutf_really_inline uint32_t to_bitmask() const {
  100|  44.1k|    return uint32_t(_mm256_movemask_epi8(value));
  101|  44.1k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE21any_bits_set_anywhereEv:
  241|  67.2k|  simdutf_really_inline bool any_bits_set_anywhere() const {
  242|  67.2k|    return !bits_not_set_anywhere();
  243|  67.2k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE21bits_not_set_anywhereEv:
  237|  67.2k|  simdutf_really_inline bool bits_not_set_anywhere() const {
  238|  67.2k|    return _mm256_testz_si256(*this, *this);
  239|  67.2k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaEC2EPKa:
  274|  12.5k|      : chunks{simd8<T>::load(ptr),
  275|  12.5k|               simd8<T>::load(ptr + sizeof(simd8<T>) / sizeof(T))} {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIaE4loadEPKa:
  111|  43.6k|  static simdutf_really_inline simd8<T> load(const T values[32]) {
  112|  43.6k|    return _mm256_loadu_si256(reinterpret_cast<const __m256i *>(values));
  113|  43.6k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IaEC2EDv4_x:
  169|  82.2k|      : base8_numeric<int8_t>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIaEC2EDv4_x:
  126|  82.2k|      : base8<T>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IaNS2_5simd8IbEEEC2EDv4_x:
   73|  82.2k|  simdutf_really_inline base8(const __m256i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IaEEEC2EDv4_x:
   17|  82.2k|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE8is_asciiEv:
  298|  10.8k|  simdutf_really_inline bool is_ascii() const {
  299|  10.8k|    return this->reduce_or().is_ascii();
  300|  10.8k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE9reduce_orEv:
  294|  10.8k|  simdutf_really_inline simd8<T> reduce_or() const {
  295|  10.8k|    return this->chunks[0] | this->chunks[1];
  296|  10.8k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IaEEEorES5_:
   50|  10.8k|  simdutf_really_inline Child operator|(const Child other) const {
   51|  10.8k|    return _mm256_or_si256(*this, other);
   52|  10.8k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IaEEEcvRKDv4_xEv:
   19|   119k|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IaE8is_asciiEv:
  177|  10.8k|  simdutf_really_inline bool is_ascii() const {
  178|  10.8k|    return _mm256_movemask_epi8(*this) == 0;
  179|  10.8k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE5storeEPa:
  277|  1.66k|  simdutf_really_inline void store(T *ptr) const {
  278|  1.66k|    this->chunks[0].store(ptr + sizeof(simd8<T>) * 0 / sizeof(T));
  279|  1.66k|    this->chunks[1].store(ptr + sizeof(simd8<T>) * 1 / sizeof(T));
  280|  1.66k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIaE5storeEPa:
  129|  3.32k|  simdutf_really_inline void store(T dst[32]) const {
  130|  3.32k|    return _mm256_storeu_si256(reinterpret_cast<__m256i *>(dst), *this);
  131|  3.32k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IaEcvNS3_IhEEEv:
  256|  22.2k|simdutf_really_inline simd8<int8_t>::operator simd8<uint8_t>() const {
  257|  22.2k|  return this->value;
  258|  22.2k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE2ltEa:
  325|  7.42k|  simdutf_really_inline uint64_t lt(const T m) const {
  326|  7.42k|    const simd8<T> mask = simd8<T>::splat(m);
  327|  7.42k|    return simd8x64<bool>(this->chunks[0] < mask, this->chunks[1] < mask)
  328|  7.42k|        .to_bitmask();
  329|  7.42k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIaE5splatEa:
  105|  27.6k|  static simdutf_really_inline simd8<T> splat(T _value) {
  106|  27.6k|    return _mm256_set1_epi8(_value);
  107|  27.6k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IaEltES4_:
  184|  14.8k|  simdutf_really_inline simd8<bool> operator<(const simd8<int8_t> other) const {
  185|  14.8k|    return _mm256_cmpgt_epi8(other, *this);
  186|  14.8k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IbEC2ENS2_5simd8IbEES6_:
  272|  9.11k|      : chunks{chunk0, chunk1} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IbE10to_bitmaskEv:
  282|  9.11k|  simdutf_really_inline uint64_t to_bitmask() const {
  283|  9.11k|    uint64_t r_lo = uint32_t(this->chunks[0].to_bitmask());
  284|  9.11k|    uint64_t r_hi = this->chunks[1].to_bitmask();
  285|  9.11k|    return r_lo | (r_hi << 32);
  286|  9.11k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE20store_ascii_as_utf32EPDi:
  310|    583|  simdutf_really_inline void store_ascii_as_utf32(char32_t *ptr) const {
  311|    583|    this->chunks[0].store_ascii_as_utf32(ptr + sizeof(simd8<T>) * 0);
  312|    583|    this->chunks[1].store_ascii_as_utf32(ptr + sizeof(simd8<T>) * 1);
  313|    583|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IaEEE20store_ascii_as_utf32EPDi:
   36|  1.16k|  simdutf_really_inline void store_ascii_as_utf32(char32_t *ptr) const {
   37|  1.16k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr),
   38|  1.16k|                        _mm256_cvtepu8_epi32(_mm256_castsi256_si128(*this)));
   39|  1.16k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr + 8),
   40|  1.16k|                        _mm256_cvtepu8_epi32(_mm256_castsi256_si128(
   41|  1.16k|                            _mm256_srli_si256(*this, 8))));
   42|  1.16k|    _mm256_storeu_si256(
   43|  1.16k|        reinterpret_cast<__m256i *>(ptr + 16),
   44|  1.16k|        _mm256_cvtepu8_epi32(_mm256_extractf128_si256(*this, 1)));
   45|  1.16k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr + 24),
   46|       |                        _mm256_cvtepu8_epi32(_mm_srli_si128(
   47|  1.16k|                            _mm256_extractf128_si256(*this, 1), 8)));
   48|  1.16k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE4zeroEv:
  108|  33.1k|  static simdutf_really_inline simd8<T> zero() {
  109|  33.1k|    return _mm256_setzero_si256();
  110|  33.1k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IaEgtES4_:
  181|  21.9k|  simdutf_really_inline simd8<bool> operator>(const simd8<int8_t> other) const {
  182|  21.9k|    return _mm256_cmpgt_epi8(*this, other);
  183|  21.9k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IaEC2Ea:
  172|  18.5k|  simdutf_really_inline simd8(int8_t _value) : simd8(splat(_value)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhEmIENS2_5simd8IhEE:
  137|  30.0k|  simdutf_really_inline simd8<T> &operator-=(const simd8<T> other) {
  138|  30.0k|    *this = *this - other;
  139|  30.0k|    return *static_cast<simd8<T> *>(this);
  140|  30.0k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhEmiENS2_5simd8IhEE:
  134|  30.0k|  simdutf_really_inline simd8<T> operator-(const simd8<T> other) const {
  135|  30.0k|    return _mm256_sub_epi8(*this, other);
  136|  30.0k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE9sum_bytesEv:
  249|  2.17k|  simdutf_really_inline uint64_t sum_bytes() const {
  250|  2.17k|    const auto tmp = _mm256_sad_epu8(value, _mm256_setzero_si256());
  251|       |
  252|  2.17k|    return _mm256_extract_epi64(tmp, 0) + _mm256_extract_epi64(tmp, 1) +
  253|  2.17k|           _mm256_extract_epi64(tmp, 2) + _mm256_extract_epi64(tmp, 3);
  254|  2.17k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEgeES4_:
  229|  11.4k|  operator>=(const simd8<uint8_t> other) const {
  230|  11.4k|    return other.min_val(*this) == other;
  231|  11.4k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE7min_valES4_:
  220|  11.4k|  min_val(const simd8<uint8_t> other) const {
  221|  11.4k|    return _mm256_min_epu8(other, *this);
  222|  11.4k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE2gtEa:
  331|  1.69k|  simdutf_really_inline uint64_t gt(const T m) const {
  332|  1.69k|    const simd8<T> mask = simd8<T>::splat(m);
  333|  1.69k|    return simd8x64<bool>(this->chunks[0] > mask, this->chunks[1] > mask)
  334|  1.69k|        .to_bitmask();
  335|  1.69k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEC2EDv4_x:
   17|  11.1k|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEcvRKDv4_xEv:
   19|  11.1k|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE5splatEh:
  105|   249k|  static simdutf_really_inline simd8<T> splat(T _value) {
  106|   249k|    return _mm256_set1_epi8(_value);
  107|   249k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEcvRKDv4_xEv:
   19|  1.71M|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdeqENS2_5simd8IhEES4_:
   76|  37.3k|                                               const simd8<T> rhs) {
   77|  37.3k|    return _mm256_cmpeq_epi8(lhs, rhs);
   78|  37.3k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEanES5_:
   53|   204k|  simdutf_really_inline Child operator&(const Child other) const {
   54|   204k|    return _mm256_and_si256(*this, other);
   55|   204k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IhEC2EPKh:
  274|  34.5k|      : chunks{simd8<T>::load(ptr),
  275|  34.5k|               simd8<T>::load(ptr + sizeof(simd8<T>) / sizeof(T))} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEanES5_:
   53|  57.8k|  simdutf_really_inline Child operator&(const Child other) const {
   54|  57.8k|    return _mm256_and_si256(*this, other);
   55|  57.8k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE20store_ascii_as_utf16ILNS_10endiannessE0EEEvPDs:
  303|    599|  simdutf_really_inline void store_ascii_as_utf16(char16_t *ptr) const {
  304|    599|    this->chunks[0].template store_ascii_as_utf16<endian>(ptr +
  305|    599|                                                          sizeof(simd8<T>) * 0);
  306|    599|    this->chunks[1].template store_ascii_as_utf16<endian>(ptr +
  307|    599|                                                          sizeof(simd8<T>) * 1);
  308|    599|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IaEEE20store_ascii_as_utf16ILNS_10endiannessE0EEEvPDs:
   22|  1.19k|  simdutf_really_inline void store_ascii_as_utf16(char16_t *ptr) const {
   23|  1.19k|    __m256i first = _mm256_cvtepu8_epi16(_mm256_castsi256_si128(*this));
   24|  1.19k|    __m256i second = _mm256_cvtepu8_epi16(_mm256_extractf128_si256(*this, 1));
   25|  1.19k|    if (big_endian) {
  ------------------
  |  Branch (25:9): [Folded, False: 1.19k]
  ------------------
   26|      0|      const __m256i swap = _mm256_setr_epi8(
   27|      0|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   28|      0|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   29|      0|      first = _mm256_shuffle_epi8(first, swap);
   30|      0|      second = _mm256_shuffle_epi8(second, swap);
   31|      0|    }
   32|  1.19k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr), first);
   33|  1.19k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr + 16), second);
   34|  1.19k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE20store_ascii_as_utf16ILNS_10endiannessE1EEEvPDs:
  303|    598|  simdutf_really_inline void store_ascii_as_utf16(char16_t *ptr) const {
  304|    598|    this->chunks[0].template store_ascii_as_utf16<endian>(ptr +
  305|    598|                                                          sizeof(simd8<T>) * 0);
  306|    598|    this->chunks[1].template store_ascii_as_utf16<endian>(ptr +
  307|    598|                                                          sizeof(simd8<T>) * 1);
  308|    598|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IaEEE20store_ascii_as_utf16ILNS_10endiannessE1EEEvPDs:
   22|  1.19k|  simdutf_really_inline void store_ascii_as_utf16(char16_t *ptr) const {
   23|  1.19k|    __m256i first = _mm256_cvtepu8_epi16(_mm256_castsi256_si128(*this));
   24|  1.19k|    __m256i second = _mm256_cvtepu8_epi16(_mm256_extractf128_si256(*this, 1));
   25|  1.19k|    if (big_endian) {
  ------------------
  |  Branch (25:9): [True: 1.19k, Folded]
  ------------------
   26|  1.19k|      const __m256i swap = _mm256_setr_epi8(
   27|  1.19k|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   28|  1.19k|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   29|  1.19k|      first = _mm256_shuffle_epi8(first, swap);
   30|  1.19k|      second = _mm256_shuffle_epi8(second, swap);
   31|  1.19k|    }
   32|  1.19k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr), first);
   33|  1.19k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr + 16), second);
   34|  1.19k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2EDv4_x:
   97|   311k|      : base16_numeric<uint16_t>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEC2EDv4_x:
   73|   311k|      : base16<T>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6base16ItNS2_6simd16IbEEEC2EDv4_x:
   20|   311k|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE4packERKS4_S6_:
  149|  23.8k|                                                   const simd16<uint16_t> &v1) {
  150|       |    // Note: the AVX2 variant of pack operates on 128-bit lanes, thus
  151|       |    //       we have to shuffle lanes in order to produce bytes in the
  152|       |    //       correct order.
  153|       |
  154|       |    // get the 0th lanes
  155|  23.8k|    const __m128i lo_0 = _mm256_extracti128_si256(v0, 0);
  156|  23.8k|    const __m128i lo_1 = _mm256_extracti128_si256(v1, 0);
  157|       |
  158|       |    // get the 1st lanes
  159|  23.8k|    const __m128i hi_0 = _mm256_extracti128_si256(v0, 1);
  160|  23.8k|    const __m128i hi_1 = _mm256_extracti128_si256(v1, 1);
  161|       |
  162|       |    // build new vectors (shuffle lanes)
  163|  23.8k|    const __m256i t0 = _mm256_set_m128i(lo_1, lo_0);
  ------------------
  |  |    4|  23.8k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  23.8k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  164|  23.8k|    const __m256i t1 = _mm256_set_m128i(hi_1, hi_0);
  ------------------
  |  |    4|  23.8k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  23.8k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  165|       |
  166|       |    // pack code units in linear order from v0 and v1
  167|  23.8k|    return _mm256_packus_epi16(t0, t1);
  168|  23.8k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE4loadEPKt:
   66|  58.8k|  static simdutf_really_inline simd16<T> load(const T values[8]) {
   67|  58.8k|    return _mm256_loadu_si256(reinterpret_cast<const __m256i *>(values));
   68|  58.8k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE10swap_bytesEv:
  139|  5.77k|  simdutf_really_inline simd16<uint16_t> swap_bytes() const {
  140|  5.77k|    const __m256i swap = _mm256_setr_epi8(
  141|  5.77k|        1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
  142|  5.77k|        21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
  143|  5.77k|    return _mm256_shuffle_epi8(*this, swap);
  144|  5.77k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE5splatEt:
   58|  77.9k|  static simdutf_really_inline simd16<T> splat(T _value) {
   59|  77.9k|    return _mm256_set1_epi16(_value);
   60|  77.9k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdeqENS2_6simd16ItEES4_:
   26|  11.1k|                                               const simd16<T> rhs) {
   27|  11.1k|    return _mm256_cmpeq_epi16(lhs, rhs);
   28|  11.1k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16IbEC2EDv4_x:
   45|  11.1k|  simdutf_really_inline simd16(const __m256i _value) : base16<bool>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6base16IbNS2_6simd16IbEEEC2EDv4_x:
   20|  11.1k|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE3shrILi8EEES4_v:
  134|  23.2k|  template <int N> simdutf_really_inline simd16<uint16_t> shr() const {
  135|  23.2k|    return simd16<uint16_t>(_mm256_srli_epi16(*this, N));
  136|  23.2k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2EPKDs:
  104|  47.6k|      : simd16(load(reinterpret_cast<const uint16_t *>(values))) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2Et:
  100|  56.8k|  simdutf_really_inline simd16(uint16_t _value) : simd16(splat(_value)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE4zeroEv:
   62|  21.0k|  static simdutf_really_inline simd16<T> zero() {
   63|  21.0k|    return _mm256_setzero_si256();
   64|  21.0k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd3minENS2_6simd16ItEES4_:
  259|  22.3k|simd16<uint16_t> min(const simd16<uint16_t> a, simd16<uint16_t> b) {
  260|  22.3k|  return _mm256_min_epu16(a.value, b.value);
  261|  22.3k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEpLENS2_6simd16ItEE:
   87|  33.5k|  simdutf_really_inline simd16<T> &operator+=(const simd16<T> other) {
   88|  33.5k|    *this = *this + other;
   89|  33.5k|    return *static_cast<simd16<T> *>(this);
   90|  33.5k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEplENS2_6simd16ItEE:
   84|  33.5k|  simdutf_really_inline simd16<T> operator+(const simd16<T> other) const {
   85|  33.5k|    return _mm256_add_epi16(*this, other);
   86|  33.5k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE3sumEv:
  170|  21.0k|  simdutf_really_inline uint64_t sum() const {
  171|  21.0k|    const auto lo_u16 = _mm256_and_si256(value, _mm256_set1_epi32(0x0000ffff));
  172|  21.0k|    const auto hi_u16 = _mm256_srli_epi32(value, 16);
  173|  21.0k|    const auto sum_u32 = _mm256_add_epi32(lo_u16, hi_u16);
  174|       |
  175|  21.0k|    const auto lo_u32 =
  176|  21.0k|        _mm256_and_si256(sum_u32, _mm256_set1_epi64x(0xffffffff));
  177|  21.0k|    const auto hi_u32 = _mm256_srli_epi64(sum_u32, 32);
  178|  21.0k|    const auto sum_u64 = _mm256_add_epi64(lo_u32, hi_u32);
  179|       |
  180|  21.0k|    return uint64_t(_mm256_extract_epi64(sum_u64, 0)) +
  181|  21.0k|           uint64_t(_mm256_extract_epi64(sum_u64, 1)) +
  182|  21.0k|           uint64_t(_mm256_extract_epi64(sum_u64, 2)) +
  183|       |           uint64_t(_mm256_extract_epi64(sum_u64, 3));
  184|  21.0k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd32IjE5splatEj:
   46|  25.9k|  simdutf_really_inline static simd32<uint32_t> splat(uint32_t v) {
   47|  25.9k|    return _mm256_set1_epi32(v);
   48|  25.9k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd32IjEC2EDv4_x:
    9|   178k|  simdutf_really_inline simd32(const __m256i v) : value(v) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd32IjE4zeroEv:
   42|  4.77k|  simdutf_really_inline static simd32<uint32_t> zero() {
   43|  4.77k|    return _mm256_setzero_si256();
   44|  4.77k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd32IjEC2IDiEEPKT_:
   13|  33.1k|      : value(_mm256_loadu_si256(reinterpret_cast<const __m256i *>(ptr))) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd32IjE10swap_bytesEv:
   27|  25.8k|  simdutf_really_inline simd32<uint32_t> swap_bytes() const {
   28|  25.8k|    const __m256i shuffle =
   29|  25.8k|        _mm256_setr_epi8(3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11, 15, 14, 13, 12,
   30|  25.8k|                         3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11, 15, 14, 13, 12);
   31|       |
   32|  25.8k|    return _mm256_shuffle_epi8(value, shuffle);
   33|  25.8k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd3maxENS2_6simd32IjEES4_:
   80|  51.6k|                                           const simd32<uint32_t> b) {
   81|  51.6k|  return _mm256_max_epu32(a.value, b.value);
   82|  51.6k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdplENS2_6simd32IjEES4_:
   90|  25.8k|                                                 const simd32<uint32_t> b) {
   91|  25.8k|  return _mm256_add_epi32(a.value, b.value);
   92|  25.8k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdgtENS2_6simd32IjEES4_:
  109|  4.06k|                                             const simd32<uint32_t> b) {
  110|  4.06k|  return !(b >= a);
  111|  4.06k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdntENS2_6simd32IbEE:
  104|  4.06k|simdutf_really_inline simd32<bool> operator!(const simd32<bool> v) {
  105|  4.06k|  return _mm256_xor_si256(v.value, _mm256_set1_epi8(-1));
  106|  4.06k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd32IbEC2EDv4_x:
   59|  8.12k|  simdutf_really_inline simd32(const __m256i v) : value(v) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdgeENS2_6simd32IjEES4_:
  100|  4.06k|                                              const simd32<uint32_t> b) {
  101|  4.06k|  return _mm256_cmpeq_epi32(_mm256_max_epu32(a.value, b.value), a.value);
  102|  4.06k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd32IbE3anyEv:
   61|  4.06k|  simdutf_really_inline bool any() const {
   62|  4.06k|    return _mm256_movemask_epi8(value) != 0;
   63|  4.06k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdanENS2_6simd32IjEES4_:
   85|  22.0k|                                                 const simd32<uint32_t> a) {
   86|  22.0k|  return _mm256_and_si256(a.value, b.value);
   87|  22.0k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd3minENS2_6simd32IjEES4_:
   75|  22.0k|                                           const simd32<uint32_t> a) {
   76|  22.0k|  return _mm256_min_epu32(a.value, b.value);
   77|  22.0k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd32IjEpLES4_:
   36|  22.0k|  simdutf_really_inline simd32 &operator+=(const simd32 other) {
   37|  22.0k|    value = _mm256_add_epi32(value, other.value);
   38|  22.0k|    return *this;
   39|  22.0k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd32IjE3sumEv:
   15|    712|  simdutf_really_inline uint64_t sum() const {
   16|    712|    const __m256i mask = _mm256_set1_epi64x(0xffffffff);
   17|    712|    const __m256i t0 = _mm256_and_si256(value, mask);
   18|    712|    const __m256i t1 = _mm256_srli_epi64(value, 32);
   19|    712|    const __m256i t2 = _mm256_add_epi64(t0, t1);
   20|       |
   21|    712|    return uint64_t(_mm256_extract_epi64(t2, 0)) +
   22|    712|           uint64_t(_mm256_extract_epi64(t2, 1)) +
   23|    712|           uint64_t(_mm256_extract_epi64(t2, 2)) +
   24|       |           uint64_t(_mm256_extract_epi64(t2, 3));
   25|    712|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd64ImE4zeroEv:
   27|  33.1k|  simdutf_really_inline static simd64<uint64_t> zero() {
   28|  33.1k|    return _mm256_setzero_si256();
   29|  33.1k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd64ImEC2EDv4_x:
    9|  33.1k|  simdutf_really_inline simd64(const __m256i v) : value(v) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd64ImE3sumEv:
   15|  33.1k|  simdutf_really_inline uint64_t sum() const {
   16|  33.1k|    return _mm256_extract_epi64(value, 0) + _mm256_extract_epi64(value, 1) +
   17|  33.1k|           _mm256_extract_epi64(value, 2) + _mm256_extract_epi64(value, 3);
   18|  33.1k|  }

_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|  18.3k|simdutf_really_inline long long int count_ones(uint64_t input_num) {
   15|       |  return _popcnt64(input_num);
   16|  18.3k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115trailing_zeroesEm:
   20|    466|simdutf_really_inline int trailing_zeroes(uint64_t input_num) {
   21|       |  #if SIMDUTF_REGULAR_VISUAL_STUDIO
   22|       |  unsigned long ret;
   23|       |  _BitScanForward64(&ret, input_num);
   24|       |  return (int)ret;
   25|       |  #else  // SIMDUTF_REGULAR_VISUAL_STUDIO
   26|    466|  return __builtin_ctzll(input_num);
   27|    466|  #endif // SIMDUTF_REGULAR_VISUAL_STUDIO
   28|    466|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115is_power_of_twoImEEbT_:
   31|    752|template <typename T> bool is_power_of_two(T x) { return (x & (x - 1)) == 0; }

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

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2Ev:
  183|  82.8k|  simdutf_really_inline simd8() : base8_numeric<uint8_t>() {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhEC2Ev:
  118|  82.8k|  simdutf_really_inline base8_numeric() : base8<T>() {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2Ev:
   68|  82.8k|  simdutf_really_inline base8() : base<simd8<T>>() {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2Ev:
   13|  82.8k|  simdutf_really_inline base() : value{__m128i()} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IhE9reduce_orEv:
  290|  37.2k|  simdutf_really_inline simd8<T> reduce_or() const {
  291|  37.2k|    return (this->chunks[0] | this->chunks[1]) |
  292|  37.2k|           (this->chunks[2] | this->chunks[3]);
  293|  37.2k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEorES5_:
   42|   317k|  simdutf_really_inline Child operator|(const Child other) const {
   43|   317k|    return _mm_or_si128(*this, other);
   44|   317k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2EDv2_x:
  185|  3.10M|      : base8_numeric<uint8_t>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhEC2EDv2_x:
  120|  3.10M|      : base8<T>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2EDv2_x:
   69|  3.10M|  simdutf_really_inline base8(const __m128i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2EDv2_x:
   16|  3.10M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE8is_asciiEv:
  228|  37.2k|  simdutf_really_inline bool is_ascii() const {
  229|  37.2k|    return _mm_movemask_epi8(*this) == 0;
  230|  37.2k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEoRES5_:
   51|   137k|  simdutf_really_inline Child &operator|=(const Child other) {
   52|   137k|    auto this_cast = static_cast<Child *>(this);
   53|   137k|    *this_cast = *this_cast | other;
   54|   137k|    return *this_cast;
   55|   137k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi1EEENS4_IhEES8_:
   79|  81.6k|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   80|       |    return _mm_alignr_epi8(*this, prev_chunk, 16 - N);
   81|  81.6k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE3shrILi4EEES4_v:
  238|   163k|  template <int N> simdutf_really_inline simd8<uint8_t> shr() const {
  239|   163k|    return simd8<uint8_t>(_mm_srli_epi16(*this, N)) & uint8_t(0xFFu >> N);
  240|   163k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE9lookup_16IhEENS2_5simd8IT_EES7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_S7_:
  151|   245k|            L replace15) const {
  152|   245k|    return lookup_16(simd8<L>::repeat_16(
  153|   245k|        replace0, replace1, replace2, replace3, replace4, replace5, replace6,
  154|   245k|        replace7, replace8, replace9, replace10, replace11, replace12,
  155|   245k|        replace13, replace14, replace15));
  156|   245k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE9lookup_16IhEENS2_5simd8IT_EES8_:
  142|   245k|  simdutf_really_inline simd8<L> lookup_16(simd8<L> lookup_table) const {
  143|   245k|    return _mm_shuffle_epi8(lookup_table, *this);
  144|   245k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE9repeat_16Ehhhhhhhhhhhhhhhh:
  113|   245k|                                                  T v14, T v15) {
  114|   245k|    return simd8<T>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
  115|   245k|                    v14, v15);
  116|   245k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2Ehhhhhhhhhhhhhhhh:
  196|   245k|      : simd8(_mm_setr_epi8(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
  197|   245k|                            v12, v13, v14, v15)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2Eh:
  188|   536k|  simdutf_really_inline simd8(uint8_t _value) : simd8(splat(_value)) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi2EEENS4_IhEES8_:
   79|  68.7k|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   80|       |    return _mm_alignr_epi8(*this, prev_chunk, 16 - N);
   81|  68.7k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi3EEENS4_IhEES8_:
   79|  68.7k|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   80|       |    return _mm_alignr_epi8(*this, prev_chunk, 16 - N);
   81|  68.7k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE14saturating_subES4_:
  201|   146k|  saturating_sub(const simd8<uint8_t> other) const {
  202|   146k|    return _mm_subs_epu8(*this, other);
  203|   146k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IbEC2EDv2_x:
   91|   256k|  simdutf_really_inline simd8(const __m128i _value) : base8<bool>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IbNS2_5simd8IbEEEC2EDv2_x:
   69|   256k|  simdutf_really_inline base8(const __m128i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEC2EDv2_x:
   16|   256k|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEcvRKDv2_xEv:
   18|   256k|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEeoES5_:
   48|  68.7k|  simdutf_really_inline Child operator^(const Child other) const {
   49|  68.7k|    return _mm_xor_si128(*this, other);
   50|  68.7k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2EPKh:
  190|  9.01k|  simdutf_really_inline simd8(const uint8_t *values) : simd8(load(values)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE4loadEPKh:
  106|   158k|  static simdutf_really_inline simd8<T> load(const T values[16]) {
  107|   158k|    return _mm_loadu_si128(reinterpret_cast<const __m128i *>(values));
  108|   158k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE7gt_bitsES4_:
  212|  9.01k|  gt_bits(const simd8<uint8_t> other) const {
  213|  9.01k|    return this->saturating_sub(other);
  214|  9.01k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEC2EDv2_x:
   16|   693k|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEcvRKDv2_xEv:
   18|   669k|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IbE10to_bitmaskEv:
   95|  95.6k|  simdutf_really_inline int to_bitmask() const {
   96|  95.6k|    return _mm_movemask_epi8(*this);
   97|  95.6k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE21any_bits_set_anywhereEv:
  235|  67.7k|  simdutf_really_inline bool any_bits_set_anywhere() const {
  236|  67.7k|    return !bits_not_set_anywhere();
  237|  67.7k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE21bits_not_set_anywhereEv:
  232|  67.7k|  simdutf_really_inline bool bits_not_set_anywhere() const {
  233|  67.7k|    return _mm_testz_si128(*this, *this);
  234|  67.7k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaEC2EPKa:
  270|  19.0k|      : chunks{simd8<T>::load(ptr),
  271|  19.0k|               simd8<T>::load(ptr + sizeof(simd8<T>) / sizeof(T)),
  272|  19.0k|               simd8<T>::load(ptr + 2 * sizeof(simd8<T>) / sizeof(T)),
  273|  19.0k|               simd8<T>::load(ptr + 3 * sizeof(simd8<T>) / sizeof(T))} {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIaE4loadEPKa:
  106|   133k|  static simdutf_really_inline simd8<T> load(const T values[16]) {
  107|   133k|    return _mm_loadu_si128(reinterpret_cast<const __m128i *>(values));
  108|   133k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IaEC2EDv2_x:
  163|   254k|      : base8_numeric<int8_t>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIaEC2EDv2_x:
  120|   254k|      : base8<T>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IaNS2_5simd8IbEEEC2EDv2_x:
   69|   254k|  simdutf_really_inline base8(const __m128i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IaEEEC2EDv2_x:
   16|   254k|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE8is_asciiEv:
  295|  16.3k|  simdutf_really_inline bool is_ascii() const {
  296|  16.3k|    return this->reduce_or().is_ascii();
  297|  16.3k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE9reduce_orEv:
  290|  16.3k|  simdutf_really_inline simd8<T> reduce_or() const {
  291|  16.3k|    return (this->chunks[0] | this->chunks[1]) |
  292|  16.3k|           (this->chunks[2] | this->chunks[3]);
  293|  16.3k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IaEEEorES5_:
   42|  49.1k|  simdutf_really_inline Child operator|(const Child other) const {
   43|  49.1k|    return _mm_or_si128(*this, other);
   44|  49.1k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IaEEEcvRKDv2_xEv:
   18|   381k|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IaE8is_asciiEv:
  168|  16.3k|  simdutf_really_inline bool is_ascii() const {
  169|  16.3k|    return _mm_movemask_epi8(*this) == 0;
  170|  16.3k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE5storeEPa:
  275|  2.08k|  simdutf_really_inline void store(T *ptr) const {
  276|  2.08k|    this->chunks[0].store(ptr + sizeof(simd8<T>) * 0 / sizeof(T));
  277|  2.08k|    this->chunks[1].store(ptr + sizeof(simd8<T>) * 1 / sizeof(T));
  278|  2.08k|    this->chunks[2].store(ptr + sizeof(simd8<T>) * 2 / sizeof(T));
  279|  2.08k|    this->chunks[3].store(ptr + sizeof(simd8<T>) * 3 / sizeof(T));
  280|  2.08k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIaE5storeEPa:
  123|  8.33k|  simdutf_really_inline void store(T dst[16]) const {
  124|  8.33k|    return _mm_storeu_si128(reinterpret_cast<__m128i *>(dst), *this);
  125|  8.33k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IaEcvNS3_IhEEEv:
  251|  79.8k|simdutf_really_inline simd8<int8_t>::operator simd8<uint8_t>() const {
  252|  79.8k|  return this->value;
  253|  79.8k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE2ltEa:
  326|  11.4k|  simdutf_really_inline uint64_t lt(const T m) const {
  327|  11.4k|    const simd8<T> mask = simd8<T>::splat(m);
  328|  11.4k|    return simd8x64<bool>(this->chunks[0] < mask, this->chunks[1] < mask,
  329|  11.4k|                          this->chunks[2] < mask, this->chunks[3] < mask)
  330|  11.4k|        .to_bitmask();
  331|  11.4k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIaE5splatEa:
  102|  71.5k|  static simdutf_really_inline simd8<T> splat(T _value) {
  103|  71.5k|    return _mm_set1_epi8(_value);
  104|  71.5k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IaEltES4_:
  176|  45.6k|  simdutf_really_inline simd8<bool> operator<(const simd8<int8_t> other) const {
  177|  45.6k|    return _mm_cmpgt_epi8(other, *this);
  178|  45.6k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IbEC2ENS2_5simd8IbEES6_S6_S6_:
  268|  14.0k|      : chunks{chunk0, chunk1, chunk2, chunk3} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IbE10to_bitmaskEv:
  318|  14.0k|  simdutf_really_inline uint64_t to_bitmask() const {
  319|  14.0k|    uint64_t r0 = uint32_t(this->chunks[0].to_bitmask());
  320|  14.0k|    uint64_t r1 = this->chunks[1].to_bitmask();
  321|  14.0k|    uint64_t r2 = this->chunks[2].to_bitmask();
  322|  14.0k|    uint64_t r3 = this->chunks[3].to_bitmask();
  323|  14.0k|    return r0 | (r1 << 16) | (r2 << 32) | (r3 << 48);
  324|  14.0k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE20store_ascii_as_utf32EPDi:
  311|    944|  simdutf_really_inline void store_ascii_as_utf32(char32_t *ptr) const {
  312|    944|    this->chunks[0].store_ascii_as_utf32(ptr + sizeof(simd8<T>) * 0);
  313|    944|    this->chunks[1].store_ascii_as_utf32(ptr + sizeof(simd8<T>) * 1);
  314|    944|    this->chunks[2].store_ascii_as_utf32(ptr + sizeof(simd8<T>) * 2);
  315|    944|    this->chunks[3].store_ascii_as_utf32(ptr + sizeof(simd8<T>) * 3);
  316|    944|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IaEEE20store_ascii_as_utf32EPDi:
   32|  3.77k|  simdutf_really_inline void store_ascii_as_utf32(char32_t *p) const {
   33|  3.77k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p), _mm_cvtepu8_epi32(*this));
   34|  3.77k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p + 4),
   35|  3.77k|                     _mm_cvtepu8_epi32(_mm_srli_si128(*this, 4)));
   36|  3.77k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p + 8),
   37|  3.77k|                     _mm_cvtepu8_epi32(_mm_srli_si128(*this, 8)));
   38|  3.77k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p + 12),
   39|       |                     _mm_cvtepu8_epi32(_mm_srli_si128(*this, 12)));
   40|  3.77k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE4zeroEv:
  105|  33.1k|  static simdutf_really_inline simd8<T> zero() { return _mm_setzero_si128(); }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IaEgtES4_:
  173|  68.0k|  simdutf_really_inline simd8<bool> operator>(const simd8<int8_t> other) const {
  174|  68.0k|    return _mm_cmpgt_epi8(*this, other);
  175|  68.0k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IaEC2Ea:
  165|  57.4k|  simdutf_really_inline simd8(int8_t _value) : simd8(splat(_value)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhEmIENS2_5simd8IhEE:
  134|  92.2k|  simdutf_really_inline simd8<T> &operator-=(const simd8<T> other) {
  135|  92.2k|    *this = *this - other;
  136|  92.2k|    return *static_cast<simd8<T> *>(this);
  137|  92.2k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhEmiENS2_5simd8IhEE:
  131|  92.2k|  simdutf_really_inline simd8<T> operator-(const simd8<T> other) const {
  132|  92.2k|    return _mm_sub_epi8(*this, other);
  133|  92.2k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE9sum_bytesEv:
  245|  3.05k|  simdutf_really_inline uint64_t sum_bytes() const {
  246|  3.05k|    const auto tmp = _mm_sad_epu8(value, _mm_setzero_si128());
  247|  3.05k|    return _mm_extract_epi64(tmp, 0) + _mm_extract_epi64(tmp, 1);
  248|  3.05k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEgeES4_:
  217|  34.7k|  operator>=(const simd8<uint8_t> other) const {
  218|  34.7k|    return other.min_val(*this) == other;
  219|  34.7k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE7min_valES4_:
  207|  34.7k|  min_val(const simd8<uint8_t> other) const {
  208|  34.7k|    return _mm_min_epu8(*this, other);
  209|  34.7k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE2gtEa:
  333|  2.63k|  simdutf_really_inline uint64_t gt(const T m) const {
  334|  2.63k|    const simd8<T> mask = simd8<T>::splat(m);
  335|  2.63k|    return simd8x64<bool>(this->chunks[0] > mask, this->chunks[1] > mask,
  336|  2.63k|                          this->chunks[2] > mask, this->chunks[3] > mask)
  337|  2.63k|        .to_bitmask();
  338|  2.63k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEC2EDv2_x:
   16|  33.3k|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEcvRKDv2_xEv:
   18|  33.3k|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE5splatEh:
  102|   553k|  static simdutf_really_inline simd8<T> splat(T _value) {
  103|   553k|    return _mm_set1_epi8(_value);
  104|   553k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEcvRKDv2_xEv:
   18|  3.83M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdeqENS2_5simd8IhEES4_:
   72|  74.1k|                                               const simd8<T> rhs) {
   73|  74.1k|    return _mm_cmpeq_epi8(lhs, rhs);
   74|  74.1k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEanES5_:
   45|   516k|  simdutf_really_inline Child operator&(const Child other) const {
   46|   516k|    return _mm_and_si128(*this, other);
   47|   516k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IhEC2EPKh:
  270|  37.2k|      : chunks{simd8<T>::load(ptr),
  271|  37.2k|               simd8<T>::load(ptr + sizeof(simd8<T>) / sizeof(T)),
  272|  37.2k|               simd8<T>::load(ptr + 2 * sizeof(simd8<T>) / sizeof(T)),
  273|  37.2k|               simd8<T>::load(ptr + 3 * sizeof(simd8<T>) / sizeof(T))} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEanES5_:
   45|   137k|  simdutf_really_inline Child operator&(const Child other) const {
   46|   137k|    return _mm_and_si128(*this, other);
   47|   137k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE20store_ascii_as_utf16ILNS_10endiannessE0EEEvPDs:
  300|    974|  simdutf_really_inline void store_ascii_as_utf16(char16_t *ptr) const {
  301|    974|    this->chunks[0].template store_ascii_as_utf16<endian>(ptr +
  302|    974|                                                          sizeof(simd8<T>) * 0);
  303|    974|    this->chunks[1].template store_ascii_as_utf16<endian>(ptr +
  304|    974|                                                          sizeof(simd8<T>) * 1);
  305|    974|    this->chunks[2].template store_ascii_as_utf16<endian>(ptr +
  306|    974|                                                          sizeof(simd8<T>) * 2);
  307|    974|    this->chunks[3].template store_ascii_as_utf16<endian>(ptr +
  308|    974|                                                          sizeof(simd8<T>) * 3);
  309|    974|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IaEEE20store_ascii_as_utf16ILNS_10endiannessE0EEEvPDs:
   20|  3.89k|  simdutf_really_inline void store_ascii_as_utf16(char16_t *p) const {
   21|  3.89k|    __m128i first = _mm_cvtepu8_epi16(*this);
   22|  3.89k|    __m128i second = _mm_cvtepu8_epi16(_mm_srli_si128(*this, 8));
   23|  3.89k|    if (big_endian) {
  ------------------
  |  Branch (23:9): [Folded, False: 3.89k]
  ------------------
   24|      0|      const __m128i swap =
   25|      0|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   26|      0|      first = _mm_shuffle_epi8(first, swap);
   27|      0|      second = _mm_shuffle_epi8(second, swap);
   28|      0|    }
   29|  3.89k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p), first);
   30|  3.89k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p + 8), second);
   31|  3.89k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE20store_ascii_as_utf16ILNS_10endiannessE1EEEvPDs:
  300|    973|  simdutf_really_inline void store_ascii_as_utf16(char16_t *ptr) const {
  301|    973|    this->chunks[0].template store_ascii_as_utf16<endian>(ptr +
  302|    973|                                                          sizeof(simd8<T>) * 0);
  303|    973|    this->chunks[1].template store_ascii_as_utf16<endian>(ptr +
  304|    973|                                                          sizeof(simd8<T>) * 1);
  305|    973|    this->chunks[2].template store_ascii_as_utf16<endian>(ptr +
  306|    973|                                                          sizeof(simd8<T>) * 2);
  307|    973|    this->chunks[3].template store_ascii_as_utf16<endian>(ptr +
  308|    973|                                                          sizeof(simd8<T>) * 3);
  309|    973|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IaEEE20store_ascii_as_utf16ILNS_10endiannessE1EEEvPDs:
   20|  3.89k|  simdutf_really_inline void store_ascii_as_utf16(char16_t *p) const {
   21|  3.89k|    __m128i first = _mm_cvtepu8_epi16(*this);
   22|  3.89k|    __m128i second = _mm_cvtepu8_epi16(_mm_srli_si128(*this, 8));
   23|  3.89k|    if (big_endian) {
  ------------------
  |  Branch (23:9): [True: 3.89k, Folded]
  ------------------
   24|  3.89k|      const __m128i swap =
   25|  3.89k|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   26|  3.89k|      first = _mm_shuffle_epi8(first, swap);
   27|  3.89k|      second = _mm_shuffle_epi8(second, swap);
   28|  3.89k|    }
   29|  3.89k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p), first);
   30|  3.89k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p + 8), second);
   31|  3.89k|  }

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16ItEC2EDv2_x:
   79|   693k|      : base16_numeric<uint16_t>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItEC2EDv2_x:
   54|   693k|      : base16<T>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6base16ItNS2_6simd16IbEEEC2EDv2_x:
    8|   693k|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16ItE4packERKS4_S6_:
  130|  36.9k|                                                   const simd16<uint16_t> &v1) {
  131|  36.9k|    return _mm_packus_epi16(v0, v1);
  132|  36.9k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItE4loadEPKt:
   47|   107k|  static simdutf_really_inline simd16<T> load(const T values[8]) {
   48|   107k|    return _mm_loadu_si128(reinterpret_cast<const __m128i *>(values));
   49|   107k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16ItE10swap_bytesEv:
  121|  16.7k|  simdutf_really_inline simd16<uint16_t> swap_bytes() const {
  122|  16.7k|    const __m128i swap =
  123|  16.7k|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  124|  16.7k|    return _mm_shuffle_epi8(*this, swap);
  125|  16.7k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItE5splatEt:
   41|   173k|  static simdutf_really_inline simd16<T> splat(T _value) {
   42|   173k|    return _mm_set1_epi16(_value);
   43|   173k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdeqENS2_6simd16ItEES4_:
   11|  33.3k|                                               const simd16<T> rhs) {
   12|  33.3k|    return _mm_cmpeq_epi16(lhs, rhs);
   13|  33.3k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16IbEC2EDv2_x:
   28|  33.3k|  simdutf_really_inline simd16(const __m128i _value) : base16<bool>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6base16IbNS2_6simd16IbEEEC2EDv2_x:
    8|  33.3k|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16ItE3shrILi8EEES4_v:
  116|  36.8k|  template <int N> simdutf_really_inline simd16<uint16_t> shr() const {
  117|  36.8k|    return simd16<uint16_t>(_mm_srli_epi16(*this, N));
  118|  36.8k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16ItEC2EPKDs:
   86|  73.9k|      : simd16(load(reinterpret_cast<const uint16_t *>(values))) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16ItEC2Et:
   82|   152k|  simdutf_really_inline simd16(uint16_t _value) : simd16(splat(_value)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItE4zeroEv:
   45|  21.4k|  static simdutf_really_inline simd16<T> zero() { return _mm_setzero_si128(); }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd3minENS2_6simd16ItEES4_:
  240|  66.7k|simd16<uint16_t> min(const simd16<uint16_t> a, simd16<uint16_t> b) {
  241|  66.7k|  return _mm_min_epu16(a.value, b.value);
  242|  66.7k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItEpLENS2_6simd16ItEE:
   68|   100k|  simdutf_really_inline simd16<T> &operator+=(const simd16<T> other) {
   69|   100k|    *this = *this + other;
   70|   100k|    return *static_cast<simd16<T> *>(this);
   71|   100k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItEplENS2_6simd16ItEE:
   65|   100k|  simdutf_really_inline simd16<T> operator+(const simd16<T> other) const {
   66|   100k|    return _mm_add_epi16(*this, other);
   67|   100k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16ItE3sumEv:
  134|  21.4k|  simdutf_really_inline uint64_t sum() const {
  135|  21.4k|    const auto lo_u16 = _mm_and_si128(value, _mm_set1_epi32(0x0000ffff));
  136|  21.4k|    const auto hi_u16 = _mm_srli_epi32(value, 16);
  137|  21.4k|    const auto sum_u32 = _mm_add_epi32(lo_u16, hi_u16);
  138|       |
  139|  21.4k|    const auto lo_u32 = _mm_and_si128(sum_u32, _mm_set1_epi64x(0xffffffff));
  140|  21.4k|    const auto hi_u32 = _mm_srli_epi64(sum_u32, 32);
  141|  21.4k|    const auto sum_u64 = _mm_add_epi64(lo_u32, hi_u32);
  142|       |
  143|  21.4k|    return uint64_t(_mm_extract_epi64(sum_u64, 0)) +
  144|       |           uint64_t(_mm_extract_epi64(sum_u64, 1));
  145|  21.4k|  }

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd32IjE5splatEj:
   56|  25.1k|  simdutf_really_inline static simd32<uint32_t> splat(uint32_t v) {
   57|  25.1k|    return _mm_set1_epi32(v);
   58|  25.1k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd32IjEC2EDv2_x:
    9|   409k|  simdutf_really_inline simd32(const __m128i v) : value(v) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd32IjE4zeroEv:
   52|  4.00k|  simdutf_really_inline static simd32<uint32_t> zero() {
   53|  4.00k|    return _mm_setzero_si128();
   54|  4.00k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd32IjEC2IDiEEPKT_:
   13|  84.2k|      : value(_mm_loadu_si128(reinterpret_cast<const __m128i *>(ptr))) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd32IjE10swap_bytesEv:
   22|  62.5k|  simdutf_really_inline simd32<uint32_t> swap_bytes() const {
   23|  62.5k|    const __m128i shuffle =
   24|  62.5k|        _mm_setr_epi8(3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11, 15, 14, 13, 12);
   25|       |
   26|  62.5k|    return _mm_shuffle_epi8(value, shuffle);
   27|  62.5k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd3maxENS2_6simd32IjEES4_:
   94|   125k|                                           const simd32<uint32_t> b) {
   95|   125k|  return _mm_max_epu32(a.value, b.value);
   96|   125k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdplENS2_6simd32IjEES4_:
  119|  62.5k|                                                 const simd32<uint32_t> b) {
  120|  62.5k|  return _mm_add_epi32(a.value, b.value);
  121|  62.5k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdgtENS2_6simd32IjEES4_:
  143|  3.05k|                                             const simd32<uint32_t> b) {
  144|  3.05k|  return !(b >= a);
  145|  3.05k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdntENS2_6simd32IbEE:
  138|  3.05k|simdutf_really_inline simd32<bool> operator!(const simd32<bool> v) {
  139|  3.05k|  return _mm_xor_si128(v.value, _mm_set1_epi8(-1));
  140|  3.05k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd32IbEC2EDv2_x:
   69|  6.10k|  simdutf_really_inline simd32(const __m128i v) : value(v) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdgeENS2_6simd32IjEES4_:
  134|  3.05k|                                              const simd32<uint32_t> b) {
  135|  3.05k|  return _mm_cmpeq_epi32(_mm_max_epu32(a.value, b.value), a.value);
  136|  3.05k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd32IbE3anyEv:
   71|  3.05k|  simdutf_really_inline bool any() const {
   72|  3.05k|    return _mm_movemask_epi8(value) != 0;
   73|  3.05k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdanENS2_6simd32IjEES4_:
  104|  65.0k|                                                 const simd32<uint32_t> b) {
  105|  65.0k|  return _mm_and_si128(a.value, b.value);
  106|  65.0k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd3minENS2_6simd32IjEES4_:
   89|  65.0k|                                           const simd32<uint32_t> b) {
   90|  65.0k|  return _mm_min_epu32(a.value, b.value);
   91|  65.0k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd32IjEpLES4_:
   46|  65.0k|  simdutf_really_inline simd32 &operator+=(const simd32 other) {
   47|  65.0k|    value = _mm_add_epi32(value, other.value);
   48|  65.0k|    return *this;
   49|  65.0k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd32IjE3sumEv:
   15|    950|  simdutf_really_inline uint64_t sum() const {
   16|    950|    return uint64_t(_mm_extract_epi32(value, 0)) +
   17|    950|           uint64_t(_mm_extract_epi32(value, 1)) +
   18|    950|           uint64_t(_mm_extract_epi32(value, 2)) +
   19|       |           uint64_t(_mm_extract_epi32(value, 3));
   20|    950|  }

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd64ImE4zeroEv:
   26|  33.1k|  simdutf_really_inline static simd64<uint64_t> zero() {
   27|  33.1k|    return _mm_setzero_si128();
   28|  33.1k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd64ImEC2EDv2_x:
    9|  33.1k|  simdutf_really_inline simd64(const __m128i v) : value(v) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd64ImE3sumEv:
   15|  33.1k|  simdutf_really_inline uint64_t sum() const {
   16|  33.1k|    return _mm_extract_epi64(value, 0) + _mm_extract_epi64(value, 1);
   17|  33.1k|  }

_ZNK7simdutf8westmere14implementation13validate_utf8EPKcm:
  297|  22.0k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
  298|  22.0k|  return westmere::utf8_validation::generic_validate_utf8(buf, len);
  299|  22.0k|}
_ZNK7simdutf8westmere14implementation25validate_utf8_with_errorsEPKcm:
  304|  5.56k|    const char *buf, size_t len) const noexcept {
  305|  5.56k|  return westmere::utf8_validation::generic_validate_utf8_with_errors(buf, len);
  306|  5.56k|}
_ZNK7simdutf8westmere14implementation16validate_utf16leEPKDsm:
  343|  16.2k|                                 size_t len) const noexcept {
  344|  16.2k|  if (simdutf_unlikely(len == 0)) {
  ------------------
  |  |   92|  16.2k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (92:33): [True: 14.3k, False: 1.87k]
  |  |  ------------------
  ------------------
  345|       |    // empty input is valid UTF-16. protect the implementation from
  346|       |    // handling nullptr
  347|  14.3k|    return true;
  348|  14.3k|  }
  349|  1.87k|  const auto res =
  350|  1.87k|      westmere::utf16::validate_utf16_with_errors<endianness::LITTLE>(buf, len);
  351|  1.87k|  if (res.is_err()) {
  ------------------
  |  Branch (351:7): [True: 53, False: 1.81k]
  ------------------
  352|     53|    return false;
  353|     53|  }
  354|       |
  355|  1.81k|  if (res.count == len)
  ------------------
  |  Branch (355:7): [True: 0, False: 1.81k]
  ------------------
  356|      0|    return true;
  357|       |
  358|  1.81k|  return scalar::utf16::validate<endianness::LITTLE>(buf + res.count,
  359|  1.81k|                                                     len - res.count);
  360|  1.81k|}
_ZNK7simdutf8westmere14implementation16validate_utf16beEPKDsm:
  366|  16.2k|                                 size_t len) const noexcept {
  367|  16.2k|  if (simdutf_unlikely(len == 0)) {
  ------------------
  |  |   92|  16.2k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (92:33): [True: 14.4k, False: 1.85k]
  |  |  ------------------
  ------------------
  368|       |    // empty input is valid UTF-16. protect the implementation from
  369|       |    // handling nullptr
  370|  14.4k|    return true;
  371|  14.4k|  }
  372|  1.85k|  const auto res =
  373|  1.85k|      westmere::utf16::validate_utf16_with_errors<endianness::BIG>(buf, len);
  374|  1.85k|  if (res.is_err()) {
  ------------------
  |  Branch (374:7): [True: 49, False: 1.80k]
  ------------------
  375|     49|    return false;
  376|     49|  }
  377|       |
  378|  1.80k|  if (res.count == len)
  ------------------
  |  Branch (378:7): [True: 0, False: 1.80k]
  ------------------
  379|      0|    return true;
  380|       |
  381|  1.80k|  return scalar::utf16::validate<endianness::BIG>(buf + res.count,
  382|  1.80k|                                                  len - res.count);
  383|  1.80k|}
_ZNK7simdutf8westmere14implementation28validate_utf16le_with_errorsEPKDsm:
  386|  5.56k|    const char16_t *buf, size_t len) const noexcept {
  387|  5.56k|  const result res =
  388|  5.56k|      westmere::utf16::validate_utf16_with_errors<endianness::LITTLE>(buf, len);
  389|  5.56k|  if (res.count != len) {
  ------------------
  |  Branch (389:7): [True: 347, False: 5.21k]
  ------------------
  390|    347|    const result scalar_res =
  391|    347|        scalar::utf16::validate_with_errors<endianness::LITTLE>(
  392|    347|            buf + res.count, len - res.count);
  393|    347|    return result(scalar_res.error, res.count + scalar_res.count);
  394|  5.21k|  } else {
  395|  5.21k|    return res;
  396|  5.21k|  }
  397|  5.56k|}
_ZNK7simdutf8westmere14implementation28validate_utf16be_with_errorsEPKDsm:
  400|  5.56k|    const char16_t *buf, size_t len) const noexcept {
  401|  5.56k|  const result res =
  402|  5.56k|      westmere::utf16::validate_utf16_with_errors<endianness::BIG>(buf, len);
  403|  5.56k|  if (res.count != len) {
  ------------------
  |  Branch (403:7): [True: 326, False: 5.23k]
  ------------------
  404|    326|    result scalar_res = scalar::utf16::validate_with_errors<endianness::BIG>(
  405|    326|        buf + res.count, len - res.count);
  406|    326|    return result(scalar_res.error, res.count + scalar_res.count);
  407|  5.23k|  } else {
  408|  5.23k|    return res;
  409|  5.23k|  }
  410|  5.56k|}
_ZNK7simdutf8westmere14implementation14validate_utf32EPKDim:
  425|  10.7k|implementation::validate_utf32(const char32_t *buf, size_t len) const noexcept {
  426|  10.7k|  return utf32::validate(buf, len);
  427|  10.7k|}
_ZNK7simdutf8westmere14implementation22convert_latin1_to_utf8EPKcmPc:
  439|  5.86k|    const char *buf, size_t len, char *utf8_output) const noexcept {
  440|       |
  441|  5.86k|  std::pair<const char *, char *> ret =
  442|  5.86k|      sse_convert_latin1_to_utf8(buf, len, utf8_output);
  443|  5.86k|  size_t converted_chars = ret.second - utf8_output;
  444|       |
  445|  5.86k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (445:7): [True: 830, False: 5.03k]
  ------------------
  446|    830|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  447|    830|        ret.first, len - (ret.first - buf), ret.second);
  448|    830|    converted_chars += scalar_converted_chars;
  449|    830|  }
  450|       |
  451|  5.86k|  return converted_chars;
  452|  5.86k|}
_ZNK7simdutf8westmere14implementation25convert_latin1_to_utf16leEPKcmPDs:
  457|  5.56k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  458|  5.56k|  std::pair<const char *, char16_t *> ret =
  459|  5.56k|      sse_convert_latin1_to_utf16<endianness::LITTLE>(buf, len, utf16_output);
  460|  5.56k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (460:7): [True: 0, False: 5.56k]
  ------------------
  461|      0|    return 0;
  462|      0|  }
  463|  5.56k|  size_t converted_chars = ret.second - utf16_output;
  464|  5.56k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (464:7): [True: 458, False: 5.10k]
  ------------------
  465|    458|    const size_t scalar_converted_chars =
  466|    458|        scalar::latin1_to_utf16::convert<endianness::LITTLE>(
  467|    458|            ret.first, len - (ret.first - buf), ret.second);
  468|    458|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (468:9): [True: 0, False: 458]
  ------------------
  469|      0|      return 0;
  470|      0|    }
  471|    458|    converted_chars += scalar_converted_chars;
  472|    458|  }
  473|  5.56k|  return converted_chars;
  474|  5.56k|}
_ZNK7simdutf8westmere14implementation25convert_latin1_to_utf16beEPKcmPDs:
  477|  5.56k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  478|  5.56k|  std::pair<const char *, char16_t *> ret =
  479|  5.56k|      sse_convert_latin1_to_utf16<endianness::BIG>(buf, len, utf16_output);
  480|  5.56k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (480:7): [True: 0, False: 5.56k]
  ------------------
  481|      0|    return 0;
  482|      0|  }
  483|  5.56k|  size_t converted_chars = ret.second - utf16_output;
  484|  5.56k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (484:7): [True: 458, False: 5.10k]
  ------------------
  485|    458|    const size_t scalar_converted_chars =
  486|    458|        scalar::latin1_to_utf16::convert<endianness::BIG>(
  487|    458|            ret.first, len - (ret.first - buf), ret.second);
  488|    458|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (488:9): [True: 0, False: 458]
  ------------------
  489|      0|      return 0;
  490|      0|    }
  491|    458|    converted_chars += scalar_converted_chars;
  492|    458|  }
  493|  5.56k|  return converted_chars;
  494|  5.56k|}
_ZNK7simdutf8westmere14implementation23convert_latin1_to_utf32EPKcmPDi:
  499|  5.56k|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  500|  5.56k|  std::pair<const char *, char32_t *> ret =
  501|  5.56k|      sse_convert_latin1_to_utf32(buf, len, utf32_output);
  502|  5.56k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (502:7): [True: 0, False: 5.56k]
  ------------------
  503|      0|    return 0;
  504|      0|  }
  505|  5.56k|  size_t converted_chars = ret.second - utf32_output;
  506|  5.56k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (506:7): [True: 458, False: 5.10k]
  ------------------
  507|    458|    const size_t scalar_converted_chars = scalar::latin1_to_utf32::convert(
  508|    458|        ret.first, len - (ret.first - buf), ret.second);
  509|    458|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (509:9): [True: 0, False: 458]
  ------------------
  510|      0|      return 0;
  511|      0|    }
  512|    458|    converted_chars += scalar_converted_chars;
  513|    458|  }
  514|  5.56k|  return converted_chars;
  515|  5.56k|}
_ZNK7simdutf8westmere14implementation22convert_utf8_to_latin1EPKcmPc:
  520|  11.1k|    const char *buf, size_t len, char *latin1_output) const noexcept {
  521|  11.1k|  utf8_to_latin1::validating_transcoder converter;
  522|  11.1k|  return converter.convert(buf, len, latin1_output);
  523|  11.1k|}
_ZNK7simdutf8westmere14implementation23convert_utf8_to_utf16leEPKcmPDs:
  539|  11.0k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  540|  11.0k|  utf8_to_utf16::validating_transcoder converter;
  541|  11.0k|  return converter.convert<endianness::LITTLE>(buf, len, utf16_output);
  542|  11.0k|}
_ZNK7simdutf8westmere14implementation23convert_utf8_to_utf16beEPKcmPDs:
  545|  11.0k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  546|  11.0k|  utf8_to_utf16::validating_transcoder converter;
  547|  11.0k|  return converter.convert<endianness::BIG>(buf, len, utf16_output);
  548|  11.0k|}
_ZNK7simdutf8westmere14implementation21convert_utf8_to_utf32EPKcmPDi:
  578|  5.56k|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  579|  5.56k|  utf8_to_utf32::validating_transcoder converter;
  580|  5.56k|  return converter.convert(buf, len, utf32_output);
  581|  5.56k|}
_ZNK7simdutf8westmere14implementation25convert_utf16le_to_latin1EPKDsmPc:
  597|  5.56k|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  598|  5.56k|  std::pair<const char16_t *, char *> ret =
  599|  5.56k|      sse_convert_utf16_to_latin1<endianness::LITTLE>(buf, len, latin1_output);
  600|  5.56k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (600:7): [True: 0, False: 5.56k]
  ------------------
  601|      0|    return 0;
  602|      0|  }
  603|  5.56k|  size_t saved_bytes = ret.second - latin1_output;
  604|       |
  605|  5.56k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (605:7): [True: 428, False: 5.13k]
  ------------------
  606|    428|    const size_t scalar_saved_bytes =
  607|    428|        scalar::utf16_to_latin1::convert<endianness::LITTLE>(
  608|    428|            ret.first, len - (ret.first - buf), ret.second);
  609|    428|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (609:9): [True: 0, False: 428]
  ------------------
  610|      0|      return 0;
  611|      0|    }
  612|    428|    saved_bytes += scalar_saved_bytes;
  613|    428|  }
  614|  5.56k|  return saved_bytes;
  615|  5.56k|}
_ZNK7simdutf8westmere14implementation25convert_utf16be_to_latin1EPKDsmPc:
  618|  5.56k|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  619|  5.56k|  std::pair<const char16_t *, char *> ret =
  620|  5.56k|      sse_convert_utf16_to_latin1<endianness::BIG>(buf, len, latin1_output);
  621|  5.56k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (621:7): [True: 0, False: 5.56k]
  ------------------
  622|      0|    return 0;
  623|      0|  }
  624|  5.56k|  size_t saved_bytes = ret.second - latin1_output;
  625|       |
  626|  5.56k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (626:7): [True: 428, False: 5.13k]
  ------------------
  627|    428|    const size_t scalar_saved_bytes =
  628|    428|        scalar::utf16_to_latin1::convert<endianness::BIG>(
  629|    428|            ret.first, len - (ret.first - buf), ret.second);
  630|    428|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (630:9): [True: 0, False: 428]
  ------------------
  631|      0|      return 0;
  632|      0|    }
  633|    428|    saved_bytes += scalar_saved_bytes;
  634|    428|  }
  635|  5.56k|  return saved_bytes;
  636|  5.56k|}
_ZNK7simdutf8westmere14implementation23convert_utf16le_to_utf8EPKDsmPc:
  707|  10.7k|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  708|  10.7k|  std::pair<const char16_t *, char *> ret =
  709|  10.7k|      sse_convert_utf16_to_utf8<endianness::LITTLE>(buf, len, utf8_output);
  710|  10.7k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (710:7): [True: 59, False: 10.6k]
  ------------------
  711|     59|    return 0;
  712|     59|  }
  713|  10.6k|  size_t saved_bytes = ret.second - utf8_output;
  714|  10.6k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (714:7): [True: 1.03k, False: 9.61k]
  ------------------
  715|  1.03k|    const size_t scalar_saved_bytes =
  716|  1.03k|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  717|  1.03k|            ret.first, len - (ret.first - buf), ret.second);
  718|  1.03k|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (718:9): [True: 44, False: 987]
  ------------------
  719|     44|      return 0;
  720|     44|    }
  721|    987|    saved_bytes += scalar_saved_bytes;
  722|    987|  }
  723|  10.6k|  return saved_bytes;
  724|  10.6k|}
_ZNK7simdutf8westmere14implementation23convert_utf16be_to_utf8EPKDsmPc:
  727|  10.7k|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  728|  10.7k|  std::pair<const char16_t *, char *> ret =
  729|  10.7k|      sse_convert_utf16_to_utf8<endianness::BIG>(buf, len, utf8_output);
  730|  10.7k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (730:7): [True: 56, False: 10.6k]
  ------------------
  731|     56|    return 0;
  732|     56|  }
  733|  10.6k|  size_t saved_bytes = ret.second - utf8_output;
  734|  10.6k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (734:7): [True: 1.01k, False: 9.63k]
  ------------------
  735|  1.01k|    const size_t scalar_saved_bytes =
  736|  1.01k|        scalar::utf16_to_utf8::convert<endianness::BIG>(
  737|  1.01k|            ret.first, len - (ret.first - buf), ret.second);
  738|  1.01k|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (738:9): [True: 33, False: 980]
  ------------------
  739|     33|      return 0;
  740|     33|    }
  741|    980|    saved_bytes += scalar_saved_bytes;
  742|    980|  }
  743|  10.6k|  return saved_bytes;
  744|  10.6k|}
_ZNK7simdutf8westmere14implementation23convert_utf32_to_latin1EPKDimPc:
  815|  5.56k|    const char32_t *buf, size_t len, char *latin1_output) const noexcept {
  816|  5.56k|  std::pair<const char32_t *, char *> ret =
  817|  5.56k|      sse_convert_utf32_to_latin1(buf, len, latin1_output);
  818|  5.56k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (818:7): [True: 0, False: 5.56k]
  ------------------
  819|      0|    return 0;
  820|      0|  }
  821|  5.56k|  size_t saved_bytes = ret.second - latin1_output;
  822|       |  // if (ret.first != buf + len) {
  823|  5.56k|  if (ret.first < buf + len) {
  ------------------
  |  Branch (823:7): [True: 458, False: 5.10k]
  ------------------
  824|    458|    const size_t scalar_saved_bytes = scalar::utf32_to_latin1::convert(
  825|    458|        ret.first, len - (ret.first - buf), ret.second);
  826|    458|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (826:9): [True: 0, False: 458]
  ------------------
  827|      0|      return 0;
  828|      0|    }
  829|    458|    saved_bytes += scalar_saved_bytes;
  830|    458|  }
  831|  5.56k|  return saved_bytes;
  832|  5.56k|}
_ZNK7simdutf8westmere14implementation21convert_utf32_to_utf8EPKDimPc:
  866|  5.14k|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  867|  5.14k|  std::pair<const char32_t *, char *> ret =
  868|  5.14k|      sse_convert_utf32_to_utf8(buf, len, utf8_output);
  869|  5.14k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (869:7): [True: 0, False: 5.14k]
  ------------------
  870|      0|    return 0;
  871|      0|  }
  872|  5.14k|  size_t saved_bytes = ret.second - utf8_output;
  873|  5.14k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (873:7): [True: 743, False: 4.39k]
  ------------------
  874|    743|    const size_t scalar_saved_bytes = scalar::utf32_to_utf8::convert(
  875|    743|        ret.first, len - (ret.first - buf), ret.second);
  876|    743|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (876:9): [True: 0, False: 743]
  ------------------
  877|      0|      return 0;
  878|      0|    }
  879|    743|    saved_bytes += scalar_saved_bytes;
  880|    743|  }
  881|  5.14k|  return saved_bytes;
  882|  5.14k|}
_ZNK7simdutf8westmere14implementation10count_utf8EPKcm:
 1142|  11.1k|implementation::count_utf8(const char *input, size_t length) const noexcept {
 1143|  11.1k|  return utf8::count_code_points_bytemask(input, length);
 1144|  11.1k|}
_ZNK7simdutf8westmere14implementation23latin1_length_from_utf8EPKcm:
 1149|  11.1k|    const char *buf, size_t len) const noexcept {
 1150|  11.1k|  return count_utf8(buf, len);
 1151|  11.1k|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16leEPKDsm:
 1156|  10.7k|    const char16_t *input, size_t length) const noexcept {
 1157|  10.7k|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1158|  10.7k|                                                                    length);
 1159|  10.7k|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16beEPKDsm:
 1162|  10.7k|    const char16_t *input, size_t length) const noexcept {
 1163|  10.7k|  return utf16::utf8_length_from_utf16_bytemask<endianness::BIG>(input, length);
 1164|  10.7k|}
_ZNK7simdutf8westmere14implementation23utf8_length_from_latin1EPKcm:
 1169|  5.86k|    const char *input, size_t len) const noexcept {
 1170|  5.86k|  const uint8_t *str = reinterpret_cast<const uint8_t *>(input);
 1171|  5.86k|  size_t answer = len / sizeof(__m128i) * sizeof(__m128i);
 1172|  5.86k|  size_t i = 0;
 1173|  5.86k|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1173:7): [True: 0, False: 5.86k]
  ------------------
 1174|      0|    __m128i two_64bits = _mm_setzero_si128();
 1175|      0|    while (i + sizeof(__m128i) <= len) {
  ------------------
  |  Branch (1175:12): [True: 0, False: 0]
  ------------------
 1176|      0|      __m128i runner = _mm_setzero_si128();
 1177|      0|      size_t iterations = (len - i) / sizeof(__m128i);
 1178|      0|      if (iterations > 255) {
  ------------------
  |  Branch (1178:11): [True: 0, False: 0]
  ------------------
 1179|      0|        iterations = 255;
 1180|      0|      }
 1181|      0|      size_t max_i = i + iterations * sizeof(__m128i) - sizeof(__m128i);
 1182|      0|      for (; i + 4 * sizeof(__m128i) <= max_i; i += 4 * sizeof(__m128i)) {
  ------------------
  |  Branch (1182:14): [True: 0, False: 0]
  ------------------
 1183|      0|        __m128i input1 = _mm_loadu_si128((const __m128i *)(str + i));
 1184|      0|        __m128i input2 =
 1185|      0|            _mm_loadu_si128((const __m128i *)(str + i + sizeof(__m128i)));
 1186|      0|        __m128i input3 =
 1187|      0|            _mm_loadu_si128((const __m128i *)(str + i + 2 * sizeof(__m128i)));
 1188|      0|        __m128i input4 =
 1189|      0|            _mm_loadu_si128((const __m128i *)(str + i + 3 * sizeof(__m128i)));
 1190|      0|        __m128i input12 =
 1191|      0|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input1),
 1192|      0|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input2));
 1193|      0|        __m128i input34 =
 1194|      0|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input3),
 1195|      0|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input4));
 1196|      0|        __m128i input1234 = _mm_add_epi8(input12, input34);
 1197|      0|        runner = _mm_sub_epi8(runner, input1234);
 1198|      0|      }
 1199|      0|      for (; i <= max_i; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1199:14): [True: 0, False: 0]
  ------------------
 1200|      0|        __m128i more_input = _mm_loadu_si128((const __m128i *)(str + i));
 1201|      0|        runner = _mm_sub_epi8(runner,
 1202|      0|                              _mm_cmpgt_epi8(_mm_setzero_si128(), more_input));
 1203|      0|      }
 1204|      0|      two_64bits =
 1205|      0|          _mm_add_epi64(two_64bits, _mm_sad_epu8(runner, _mm_setzero_si128()));
 1206|      0|    }
 1207|      0|    answer +=
 1208|      0|        _mm_extract_epi64(two_64bits, 0) + _mm_extract_epi64(two_64bits, 1);
 1209|  5.86k|  } else if (answer > 0) { // short string optimization
  ------------------
  |  Branch (1209:14): [True: 821, False: 5.03k]
  ------------------
 1210|  7.48k|    for (; i + 2 * sizeof(__m128i) <= len; i += 2 * sizeof(__m128i)) {
  ------------------
  |  Branch (1210:12): [True: 6.66k, False: 821]
  ------------------
 1211|  6.66k|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1212|  6.66k|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1213|  6.66k|      answer += count_ones(non_ascii);
 1214|  6.66k|      latin = _mm_loadu_si128((const __m128i *)(input + i) + 1);
 1215|  6.66k|      non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1216|  6.66k|      answer += count_ones(non_ascii);
 1217|  6.66k|    }
 1218|  1.05k|    for (; i + sizeof(__m128i) <= len; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1218:12): [True: 230, False: 821]
  ------------------
 1219|    230|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1220|    230|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1221|    230|      answer += count_ones(non_ascii);
 1222|    230|    }
 1223|    821|  }
 1224|  5.86k|  return answer + scalar::latin1::utf8_length_from_latin1(
 1225|  5.86k|                      reinterpret_cast<const char *>(str + i), len - i);
 1226|  5.86k|}
_ZNK7simdutf8westmere14implementation22utf16_length_from_utf8EPKcm:
 1243|  22.0k|    const char *input, size_t length) const noexcept {
 1244|  22.0k|  return utf8::utf16_length_from_utf8_bytemask(input, length);
 1245|  22.0k|}
_ZNK7simdutf8westmere14implementation22utf8_length_from_utf32EPKDim:
 1278|  5.14k|    const char32_t *input, size_t length) const noexcept {
 1279|  5.14k|  return utf32::utf8_length_from_utf32(input, length);
 1280|  5.14k|}
_ZNK7simdutf8westmere14implementation22utf32_length_from_utf8EPKcm:
 1306|  5.56k|    const char *input, size_t length) const noexcept {
 1307|  5.56k|  return utf8::count_code_points(input, length);
 1308|  5.56k|}
_ZNK7simdutf8westmere14implementation16base64_to_binaryEPKcmPcNS_14base64_optionsENS_27last_chunk_handling_optionsE:
 1314|  16.1k|    last_chunk_handling_options last_chunk_options) const noexcept {
 1315|  16.1k|  if (options & base64_default_or_url) {
  ------------------
  |  Branch (1315:7): [True: 0, False: 16.1k]
  ------------------
 1316|      0|    if (options == base64_options::base64_default_or_url_accept_garbage) {
  ------------------
  |  Branch (1316:9): [True: 0, False: 0]
  ------------------
 1317|      0|      return base64::compress_decode_base64<false, true, true>(
 1318|      0|          output, input, length, options, last_chunk_options);
 1319|      0|    } else {
 1320|      0|      return base64::compress_decode_base64<false, false, true>(
 1321|      0|          output, input, length, options, last_chunk_options);
 1322|      0|    }
 1323|  16.1k|  } else if (options & base64_url) {
  ------------------
  |  Branch (1323:14): [True: 0, False: 16.1k]
  ------------------
 1324|      0|    if (options == base64_options::base64_url_accept_garbage) {
  ------------------
  |  Branch (1324:9): [True: 0, False: 0]
  ------------------
 1325|      0|      return base64::compress_decode_base64<true, true, false>(
 1326|      0|          output, input, length, options, last_chunk_options);
 1327|      0|    } else {
 1328|      0|      return base64::compress_decode_base64<true, false, false>(
 1329|      0|          output, input, length, options, last_chunk_options);
 1330|      0|    }
 1331|  16.1k|  } else {
 1332|  16.1k|    if (options == base64_options::base64_default_accept_garbage) {
  ------------------
  |  Branch (1332:9): [True: 0, False: 16.1k]
  ------------------
 1333|      0|      return base64::compress_decode_base64<false, true, false>(
 1334|      0|          output, input, length, options, last_chunk_options);
 1335|  16.1k|    } else {
 1336|  16.1k|      return base64::compress_decode_base64<false, false, false>(
 1337|  16.1k|          output, input, length, options, last_chunk_options);
 1338|  16.1k|    }
 1339|  16.1k|  }
 1340|  16.1k|}
_ZNK7simdutf8westmere14implementation16binary_to_base64EPKcmPcNS_14base64_optionsE:
 1434|  15.6k|                                        base64_options options) const noexcept {
 1435|  15.6k|  if (options & base64_url) {
  ------------------
  |  Branch (1435:7): [True: 0, False: 15.6k]
  ------------------
 1436|      0|    return encode_base64<true>(output, input, length, options);
 1437|  15.6k|  } else {
 1438|  15.6k|    return encode_base64<false>(output, input, length, options);
 1439|  15.6k|  }
 1440|  15.6k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_18is_asciiERKNS1_4simd8simd8x64IhEE:
   13|  37.2k|simdutf_really_inline bool is_ascii(const simd8x64<uint8_t> &input) {
   14|  37.2k|  return input.reduce_or().is_ascii();
   15|  37.2k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_124must_be_2_3_continuationENS1_4simd5simd8IhEES4_:
   22|  68.7k|                         const simd8<uint8_t> prev3) {
   23|  68.7k|  simd8<uint8_t> is_third_byte =
   24|  68.7k|      prev2.saturating_sub(0xe0u - 0x80); // Only 111_____ will be >= 0x80
   25|  68.7k|  simd8<uint8_t> is_fourth_byte =
   26|  68.7k|      prev3.saturating_sub(0xf0u - 0x80); // Only 1111____ will be >= 0x80
   27|  68.7k|  return simd8<bool>(is_third_byte | is_fourth_byte);
   28|  68.7k|}

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

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_17block64C2EPKc:
  413|  3.97k|  simdutf_really_inline block64(const char *src) {
  414|  3.97k|    chunks[0] = _mm_loadu_si128(reinterpret_cast<const __m128i *>(src));
  415|  3.97k|    chunks[1] = _mm_loadu_si128(reinterpret_cast<const __m128i *>(src + 16));
  416|  3.97k|    chunks[2] = _mm_loadu_si128(reinterpret_cast<const __m128i *>(src + 32));
  417|  3.97k|    chunks[3] = _mm_loadu_si128(reinterpret_cast<const __m128i *>(src + 48));
  418|  3.97k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_17block6414compress_blockEmPc:
  454|    752|  simdutf_really_inline uint64_t compress_block(uint64_t mask, char *output) {
  455|    752|    if (is_power_of_two(mask)) {
  ------------------
  |  Branch (455:9): [True: 213, False: 539]
  ------------------
  456|    213|      return compress_block_single(mask, output);
  457|    213|    }
  458|       |
  459|    539|    uint64_t nmask = ~mask;
  460|    539|    compress(chunks[0], uint16_t(mask), output);
  461|    539|    compress(chunks[1], uint16_t(mask >> 16),
  462|    539|             output + count_ones(nmask & 0xFFFF));
  463|    539|    compress(chunks[2], uint16_t(mask >> 32),
  464|    539|             output + count_ones(nmask & 0xFFFFFFFF));
  465|    539|    compress(chunks[3], uint16_t(mask >> 48),
  466|    539|             output + count_ones(nmask & 0xFFFFFFFFFFFFULL));
  467|    539|    return count_ones(nmask);
  468|    752|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_17block6421compress_block_singleEmPc:
  472|    213|                                                     char *output) {
  473|    213|    const size_t pos64 = trailing_zeroes(mask);
  474|    213|    const int8_t pos = pos64 & 0xf;
  475|    213|    switch (pos64 >> 4) {
  ------------------
  |  Branch (475:13): [True: 213, False: 0]
  ------------------
  476|     48|    case 0b00: {
  ------------------
  |  Branch (476:5): [True: 48, False: 165]
  ------------------
  477|     48|      const __m128i v0 = _mm_set1_epi8(char(pos - 1));
  478|     48|      const __m128i v1 =
  479|     48|          _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  480|     48|      const __m128i v2 = _mm_cmpgt_epi8(v1, v0);
  481|     48|      const __m128i sh = _mm_sub_epi8(v1, v2);
  482|     48|      const __m128i compressed = _mm_shuffle_epi8(chunks[0], sh);
  483|       |
  484|     48|      _mm_storeu_si128((__m128i *)(output + 0 * 16), compressed);
  485|     48|      _mm_storeu_si128((__m128i *)(output + 1 * 16 - 1), chunks[1]);
  486|     48|      _mm_storeu_si128((__m128i *)(output + 2 * 16 - 1), chunks[2]);
  487|     48|      _mm_storeu_si128((__m128i *)(output + 3 * 16 - 1), chunks[3]);
  488|     48|    } break;
  489|     66|    case 0b01: {
  ------------------
  |  Branch (489:5): [True: 66, False: 147]
  ------------------
  490|     66|      _mm_storeu_si128((__m128i *)(output + 0 * 16), chunks[0]);
  491|       |
  492|     66|      const __m128i v0 = _mm_set1_epi8(char(pos - 1));
  493|     66|      const __m128i v1 =
  494|     66|          _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  495|     66|      const __m128i v2 = _mm_cmpgt_epi8(v1, v0);
  496|     66|      const __m128i sh = _mm_sub_epi8(v1, v2);
  497|     66|      const __m128i compressed = _mm_shuffle_epi8(chunks[1], sh);
  498|       |
  499|     66|      _mm_storeu_si128((__m128i *)(output + 1 * 16), compressed);
  500|     66|      _mm_storeu_si128((__m128i *)(output + 2 * 16 - 1), chunks[2]);
  501|     66|      _mm_storeu_si128((__m128i *)(output + 3 * 16 - 1), chunks[3]);
  502|     66|    } break;
  503|     50|    case 0b10: {
  ------------------
  |  Branch (503:5): [True: 50, False: 163]
  ------------------
  504|     50|      _mm_storeu_si128((__m128i *)(output + 0 * 16), chunks[0]);
  505|     50|      _mm_storeu_si128((__m128i *)(output + 1 * 16), chunks[1]);
  506|       |
  507|     50|      const __m128i v0 = _mm_set1_epi8(char(pos - 1));
  508|     50|      const __m128i v1 =
  509|     50|          _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  510|     50|      const __m128i v2 = _mm_cmpgt_epi8(v1, v0);
  511|     50|      const __m128i sh = _mm_sub_epi8(v1, v2);
  512|     50|      const __m128i compressed = _mm_shuffle_epi8(chunks[2], sh);
  513|       |
  514|     50|      _mm_storeu_si128((__m128i *)(output + 2 * 16), compressed);
  515|     50|      _mm_storeu_si128((__m128i *)(output + 3 * 16 - 1), chunks[3]);
  516|     50|    } break;
  517|     49|    case 0b11: {
  ------------------
  |  Branch (517:5): [True: 49, False: 164]
  ------------------
  518|     49|      _mm_storeu_si128((__m128i *)(output + 0 * 16), chunks[0]);
  519|     49|      _mm_storeu_si128((__m128i *)(output + 1 * 16), chunks[1]);
  520|     49|      _mm_storeu_si128((__m128i *)(output + 2 * 16), chunks[2]);
  521|       |
  522|     49|      const __m128i v0 = _mm_set1_epi8(char(pos - 1));
  523|     49|      const __m128i v1 =
  524|     49|          _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  525|     49|      const __m128i v2 = _mm_cmpgt_epi8(v1, v0);
  526|     49|      const __m128i sh = _mm_sub_epi8(v1, v2);
  527|     49|      const __m128i compressed = _mm_shuffle_epi8(chunks[3], sh);
  528|       |
  529|     49|      _mm_storeu_si128((__m128i *)(output + 3 * 16), compressed);
  530|     49|    } break;
  531|    213|    }
  532|       |
  533|    213|    return 63;
  534|    213|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_18compressEDv2_xtPc:
  334|  2.15k|                                           char *output) {
  335|  2.15k|  if (mask == 0) {
  ------------------
  |  Branch (335:7): [True: 832, False: 1.32k]
  ------------------
  336|    832|    _mm_storeu_si128(reinterpret_cast<__m128i *>(output), data);
  337|    832|    return;
  338|    832|  }
  339|       |
  340|       |  // this particular implementation was inspired by work done by @animetosho
  341|       |  // we do it in two steps, first 8 bytes and then second 8 bytes
  342|  1.32k|  uint8_t mask1 = uint8_t(mask);      // least significant 8 bits
  343|  1.32k|  uint8_t mask2 = uint8_t(mask >> 8); // most significant 8 bits
  344|       |  // next line just loads the 64-bit values thintable_epi8[mask1] and
  345|       |  // thintable_epi8[mask2] into a 128-bit register, using only
  346|       |  // two instructions on most compilers.
  347|       |
  348|  1.32k|  __m128i shufmask = _mm_set_epi64x(tables::base64::thintable_epi8[mask2],
  349|  1.32k|                                    tables::base64::thintable_epi8[mask1]);
  350|       |  // we increment by 0x08 the second half of the mask
  351|  1.32k|  shufmask =
  352|  1.32k|      _mm_add_epi8(shufmask, _mm_set_epi32(0x08080808, 0x08080808, 0, 0));
  353|       |  // this is the version "nearly pruned"
  354|  1.32k|  __m128i pruned = _mm_shuffle_epi8(data, shufmask);
  355|       |  // we still need to put the two halves together.
  356|       |  // we compute the popcount of the first half:
  357|  1.32k|  int pop1 = tables::base64::BitsSetTable256mul2[mask1];
  358|       |  // then load the corresponding mask, what it does is to write
  359|       |  // only the first pop1 bytes from the first 8 bytes, and then
  360|       |  // it fills in with the bytes from the second 8 bytes + some filling
  361|       |  // at the end.
  362|  1.32k|  __m128i compactmask = _mm_loadu_si128(reinterpret_cast<const __m128i *>(
  363|  1.32k|      tables::base64::pshufb_combine_table + pop1 * 8));
  364|  1.32k|  __m128i answer = _mm_shuffle_epi8(pruned, compactmask);
  365|  1.32k|  _mm_storeu_si128(reinterpret_cast<__m128i *>(output), answer);
  366|  1.32k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_17block6410copy_blockEPc:
  446|     68|  simdutf_really_inline void copy_block(char *output) {
  447|     68|    _mm_storeu_si128(reinterpret_cast<__m128i *>(output), chunks[0]);
  448|     68|    _mm_storeu_si128(reinterpret_cast<__m128i *>(output + 16), chunks[1]);
  449|     68|    _mm_storeu_si128(reinterpret_cast<__m128i *>(output + 32), chunks[2]);
  450|     68|    _mm_storeu_si128(reinterpret_cast<__m128i *>(output + 48), chunks[3]);
  451|     68|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_17block6424base64_decode_block_safeEPc:
  664|    120|  simdutf_really_inline void base64_decode_block_safe(char *out) {
  665|    120|    base64_decode(out, chunks[0]);
  666|    120|    base64_decode(out + 12, chunks[1]);
  667|    120|    base64_decode(out + 24, chunks[2]);
  668|    120|    char buffer[16];
  669|    120|    base64_decode(buffer, chunks[3]);
  670|    120|    std::memcpy(out + 36, buffer, 12);
  671|    120|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113base64_decodeEPcDv2_x:
  368|  13.5k|static simdutf_really_inline void base64_decode(char *out, __m128i str) {
  369|       |  // credit: aqrit
  370|       |
  371|  13.5k|  const __m128i pack_shuffle =
  372|  13.5k|      _mm_setr_epi8(2, 1, 0, 6, 5, 4, 10, 9, 8, 14, 13, 12, -1, -1, -1, -1);
  373|       |
  374|  13.5k|  const __m128i t0 = _mm_maddubs_epi16(str, _mm_set1_epi32(0x01400140));
  375|  13.5k|  const __m128i t1 = _mm_madd_epi16(t0, _mm_set1_epi32(0x00011000));
  376|  13.5k|  const __m128i t2 = _mm_shuffle_epi8(t1, pack_shuffle);
  377|       |  // Store the output:
  378|       |  // this writes 16 bytes, but we only need 12.
  379|  13.5k|  _mm_storeu_si128((__m128i *)out, t2);
  380|  13.5k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_17block6419base64_decode_blockEPc:
  656|  2.77k|  simdutf_really_inline void base64_decode_block(char *out) {
  657|  2.77k|    base64_decode(out, chunks[0]);
  658|  2.77k|    base64_decode(out + 12, chunks[1]);
  659|  2.77k|    base64_decode(out + 24, chunks[2]);
  660|  2.77k|    base64_decode(out + 36, chunks[3]);
  661|  2.77k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_119base64_decode_blockEPcPKc:
  383|    473|static inline void base64_decode_block(char *out, const char *src) {
  384|    473|  base64_decode(out, _mm_loadu_si128(reinterpret_cast<const __m128i *>(src)));
  385|    473|  base64_decode(out + 12,
  386|    473|                _mm_loadu_si128(reinterpret_cast<const __m128i *>(src + 16)));
  387|    473|  base64_decode(out + 24,
  388|    473|                _mm_loadu_si128(reinterpret_cast<const __m128i *>(src + 32)));
  389|    473|  base64_decode(out + 36,
  390|    473|                _mm_loadu_si128(reinterpret_cast<const __m128i *>(src + 48)));
  391|    473|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_124base64_decode_block_safeEPcPKc:
  393|     21|static inline void base64_decode_block_safe(char *out, const char *src) {
  394|     21|  base64_decode(out, _mm_loadu_si128(reinterpret_cast<const __m128i *>(src)));
  395|     21|  base64_decode(out + 12,
  396|     21|                _mm_loadu_si128(reinterpret_cast<const __m128i *>(src + 16)));
  397|     21|  base64_decode(out + 24,
  398|     21|                _mm_loadu_si128(reinterpret_cast<const __m128i *>(src + 32)));
  399|     21|  char buffer[16];
  400|     21|  base64_decode(buffer,
  401|     21|                _mm_loadu_si128(reinterpret_cast<const __m128i *>(src + 48)));
  402|     21|  std::memcpy(out + 36, buffer, 12);
  403|     21|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_17block6414to_base64_maskILb0ELb0ELb0EEEmPm:
  538|  3.97k|  simdutf_really_inline uint64_t to_base64_mask(uint64_t *error) {
  539|  3.97k|    uint32_t err0 = 0;
  540|  3.97k|    uint32_t err1 = 0;
  541|  3.97k|    uint32_t err2 = 0;
  542|  3.97k|    uint32_t err3 = 0;
  543|  3.97k|    uint64_t m0 = to_base64_mask<base64_url, ignore_garbage, default_or_url>(
  544|  3.97k|        &chunks[0], &err0);
  545|  3.97k|    uint64_t m1 = to_base64_mask<base64_url, ignore_garbage, default_or_url>(
  546|  3.97k|        &chunks[1], &err1);
  547|  3.97k|    uint64_t m2 = to_base64_mask<base64_url, ignore_garbage, default_or_url>(
  548|  3.97k|        &chunks[2], &err2);
  549|  3.97k|    uint64_t m3 = to_base64_mask<base64_url, ignore_garbage, default_or_url>(
  550|  3.97k|        &chunks[3], &err3);
  551|  3.97k|    if (!ignore_garbage) {
  ------------------
  |  Branch (551:9): [True: 3.97k, Folded]
  ------------------
  552|  3.97k|      *error = (err0) | ((uint64_t)err1 << 16) | ((uint64_t)err2 << 32) |
  553|  3.97k|               ((uint64_t)err3 << 48);
  554|  3.97k|    }
  555|  3.97k|    return m0 | (m1 << 16) | (m2 << 32) | (m3 << 48);
  556|  3.97k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_17block6414to_base64_maskILb0ELb0ELb0EEEtPDv2_xPj:
  560|  15.8k|  simdutf_really_inline uint16_t to_base64_mask(__m128i *src, uint32_t *error) {
  561|  15.8k|    const __m128i ascii_space_tbl =
  562|  15.8k|        _mm_setr_epi8(0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9, 0xa,
  563|  15.8k|                      0x0, 0xc, 0xd, 0x0, 0x0);
  564|       |    // credit: aqrit
  565|  15.8k|    __m128i delta_asso;
  566|  15.8k|    if (default_or_url) {
  ------------------
  |  Branch (566:9): [Folded, False: 15.8k]
  ------------------
  567|      0|      delta_asso =
  568|      0|          _mm_setr_epi8(0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
  569|      0|                        0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x16);
  570|  15.8k|    } else if (base64_url) {
  ------------------
  |  Branch (570:16): [Folded, False: 15.8k]
  ------------------
  571|      0|      delta_asso = _mm_setr_epi8(0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0,
  572|      0|                                 0x0, 0x0, 0x0, 0x0, 0xF, 0x0, 0xF);
  573|  15.8k|    } else {
  574|  15.8k|      delta_asso =
  575|  15.8k|          _mm_setr_epi8(0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
  576|  15.8k|                        0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x0F);
  577|  15.8k|    }
  578|  15.8k|    __m128i delta_values;
  579|  15.8k|    if (default_or_url) {
  ------------------
  |  Branch (579:9): [Folded, False: 15.8k]
  ------------------
  580|      0|      delta_values = _mm_setr_epi8(
  581|      0|          uint8_t(0xBF), uint8_t(0xE0), uint8_t(0xB9), uint8_t(0x13),
  582|      0|          uint8_t(0x04), uint8_t(0xBF), uint8_t(0xBF), uint8_t(0xB9),
  583|      0|          uint8_t(0xB9), uint8_t(0x00), uint8_t(0xFF), uint8_t(0x11),
  584|      0|          uint8_t(0xFF), uint8_t(0xBF), uint8_t(0x10), uint8_t(0xB9));
  585|       |
  586|  15.8k|    } else if (base64_url) {
  ------------------
  |  Branch (586:16): [Folded, False: 15.8k]
  ------------------
  587|      0|      delta_values = _mm_setr_epi8(0x0, 0x0, 0x0, 0x13, 0x4, uint8_t(0xBF),
  588|      0|                                   uint8_t(0xBF), uint8_t(0xB9), uint8_t(0xB9),
  589|      0|                                   0x0, 0x11, uint8_t(0xC3), uint8_t(0xBF),
  590|      0|                                   uint8_t(0xE0), uint8_t(0xB9), uint8_t(0xB9));
  591|  15.8k|    } else {
  592|  15.8k|      delta_values =
  593|  15.8k|          _mm_setr_epi8(int8_t(0x00), int8_t(0x00), int8_t(0x00), int8_t(0x13),
  594|  15.8k|                        int8_t(0x04), int8_t(0xBF), int8_t(0xBF), int8_t(0xB9),
  595|  15.8k|                        int8_t(0xB9), int8_t(0x00), int8_t(0x10), int8_t(0xC3),
  596|  15.8k|                        int8_t(0xBF), int8_t(0xBF), int8_t(0xB9), int8_t(0xB9));
  597|  15.8k|    }
  598|  15.8k|    __m128i check_asso;
  599|  15.8k|    if (default_or_url) {
  ------------------
  |  Branch (599:9): [Folded, False: 15.8k]
  ------------------
  600|      0|      check_asso =
  601|      0|          _mm_setr_epi8(0x0D, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  602|      0|                        0x01, 0x03, 0x07, 0x0B, 0x0E, 0x0B, 0x06);
  603|  15.8k|    } else if (base64_url) {
  ------------------
  |  Branch (603:16): [Folded, False: 15.8k]
  ------------------
  604|      0|      check_asso = _mm_setr_epi8(0xD, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
  605|      0|                                 0x1, 0x3, 0x7, 0xB, 0xE, 0xB, 0x6);
  606|  15.8k|    } else {
  607|  15.8k|      check_asso =
  608|  15.8k|          _mm_setr_epi8(0x0D, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  609|  15.8k|                        0x01, 0x03, 0x07, 0x0B, 0x0B, 0x0B, 0x0F);
  610|  15.8k|    }
  611|  15.8k|    __m128i check_values;
  612|  15.8k|    if (default_or_url) {
  ------------------
  |  Branch (612:9): [Folded, False: 15.8k]
  ------------------
  613|      0|      check_values = _mm_setr_epi8(
  614|      0|          uint8_t(0x80), uint8_t(0x80), uint8_t(0x80), uint8_t(0x80),
  615|      0|          uint8_t(0xCF), uint8_t(0xBF), uint8_t(0xD5), uint8_t(0xA6),
  616|      0|          uint8_t(0xB5), uint8_t(0xA1), uint8_t(0x00), uint8_t(0x80),
  617|      0|          uint8_t(0x00), uint8_t(0x80), uint8_t(0x00), uint8_t(0x80));
  618|  15.8k|    } else if (base64_url) {
  ------------------
  |  Branch (618:16): [Folded, False: 15.8k]
  ------------------
  619|      0|      check_values = _mm_setr_epi8(uint8_t(0x80), uint8_t(0x80), uint8_t(0x80),
  620|      0|                                   uint8_t(0x80), uint8_t(0xCF), uint8_t(0xBF),
  621|      0|                                   uint8_t(0xB6), uint8_t(0xA6), uint8_t(0xB5),
  622|      0|                                   uint8_t(0xA1), 0x0, uint8_t(0x80), 0x0,
  623|      0|                                   uint8_t(0x80), 0x0, uint8_t(0x80));
  624|  15.8k|    } else {
  625|  15.8k|      check_values =
  626|  15.8k|          _mm_setr_epi8(int8_t(0x80), int8_t(0x80), int8_t(0x80), int8_t(0x80),
  627|  15.8k|                        int8_t(0xCF), int8_t(0xBF), int8_t(0xD5), int8_t(0xA6),
  628|  15.8k|                        int8_t(0xB5), int8_t(0x86), int8_t(0xD1), int8_t(0x80),
  629|  15.8k|                        int8_t(0xB1), int8_t(0x80), int8_t(0x91), int8_t(0x80));
  630|  15.8k|    }
  631|  15.8k|    const __m128i shifted = _mm_srli_epi32(*src, 3);
  632|       |
  633|  15.8k|    __m128i delta_hash =
  634|  15.8k|        _mm_avg_epu8(_mm_shuffle_epi8(delta_asso, *src), shifted);
  635|  15.8k|    if (default_or_url) {
  ------------------
  |  Branch (635:9): [Folded, False: 15.8k]
  ------------------
  636|      0|      delta_hash = _mm_and_si128(delta_hash, _mm_set1_epi8(0xf));
  637|      0|    }
  638|  15.8k|    const __m128i check_hash =
  639|  15.8k|        _mm_avg_epu8(_mm_shuffle_epi8(check_asso, *src), shifted);
  640|       |
  641|  15.8k|    const __m128i out =
  642|  15.8k|        _mm_adds_epi8(_mm_shuffle_epi8(delta_values, delta_hash), *src);
  643|  15.8k|    const __m128i chk =
  644|  15.8k|        _mm_adds_epi8(_mm_shuffle_epi8(check_values, check_hash), *src);
  645|  15.8k|    const int mask = _mm_movemask_epi8(chk);
  646|  15.8k|    if (!ignore_garbage && mask) {
  ------------------
  |  Branch (646:9): [True: 15.8k, Folded]
  |  Branch (646:28): [True: 2.47k, False: 13.4k]
  ------------------
  647|  2.47k|      __m128i ascii_space =
  648|  2.47k|          _mm_cmpeq_epi8(_mm_shuffle_epi8(ascii_space_tbl, *src), *src);
  649|  2.47k|      *error = (mask ^ _mm_movemask_epi8(ascii_space));
  650|  2.47k|    }
  651|  15.8k|    *src = out;
  652|  15.8k|    return (uint16_t)mask;
  653|  15.8k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113encode_base64ILb0EEEmPcPKcmNS_14base64_optionsE:
  327|  15.6k|                     base64_options options) {
  328|  15.6k|  return encode_base64_impl<isbase64url, false>(dst, src, srclen, options);
  329|  15.6k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_118encode_base64_implILb0ELb0EEEmPcPKcmNS_14base64_optionsEm:
   97|  15.6k|                          size_t line_length = simdutf::default_line_length) {
   98|  15.6k|  size_t offset = 0;
   99|  15.6k|  if (line_length < 4) {
  ------------------
  |  Branch (99:7): [True: 0, False: 15.6k]
  ------------------
  100|      0|    line_length = 4; // We do not support line_length less than 4
  101|      0|  }
  102|       |  // credit: Wojciech Muła
  103|       |  // SSE (lookup: pshufb improved unrolled)
  104|  15.6k|  const uint8_t *input = (const uint8_t *)src;
  105|       |
  106|  15.6k|  uint8_t *out = (uint8_t *)dst;
  107|  15.6k|  const __m128i shuf =
  108|  15.6k|      _mm_set_epi8(10, 11, 9, 10, 7, 8, 6, 7, 4, 5, 3, 4, 1, 2, 0, 1);
  109|       |
  110|  15.6k|  size_t i = 0;
  111|  18.7k|  for (; i + 52 <= srclen; i += 48) {
  ------------------
  |  Branch (111:10): [True: 3.13k, False: 15.6k]
  ------------------
  112|  3.13k|    __m128i in0 = _mm_loadu_si128(
  113|  3.13k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 0));
  114|  3.13k|    __m128i in1 = _mm_loadu_si128(
  115|  3.13k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 1));
  116|  3.13k|    __m128i in2 = _mm_loadu_si128(
  117|  3.13k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 2));
  118|  3.13k|    __m128i in3 = _mm_loadu_si128(
  119|  3.13k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 3));
  120|       |
  121|  3.13k|    in0 = _mm_shuffle_epi8(in0, shuf);
  122|  3.13k|    in1 = _mm_shuffle_epi8(in1, shuf);
  123|  3.13k|    in2 = _mm_shuffle_epi8(in2, shuf);
  124|  3.13k|    in3 = _mm_shuffle_epi8(in3, shuf);
  125|       |
  126|  3.13k|    const __m128i t0_0 = _mm_and_si128(in0, _mm_set1_epi32(0x0fc0fc00));
  127|  3.13k|    const __m128i t0_1 = _mm_and_si128(in1, _mm_set1_epi32(0x0fc0fc00));
  128|  3.13k|    const __m128i t0_2 = _mm_and_si128(in2, _mm_set1_epi32(0x0fc0fc00));
  129|  3.13k|    const __m128i t0_3 = _mm_and_si128(in3, _mm_set1_epi32(0x0fc0fc00));
  130|       |
  131|  3.13k|    const __m128i t1_0 = _mm_mulhi_epu16(t0_0, _mm_set1_epi32(0x04000040));
  132|  3.13k|    const __m128i t1_1 = _mm_mulhi_epu16(t0_1, _mm_set1_epi32(0x04000040));
  133|  3.13k|    const __m128i t1_2 = _mm_mulhi_epu16(t0_2, _mm_set1_epi32(0x04000040));
  134|  3.13k|    const __m128i t1_3 = _mm_mulhi_epu16(t0_3, _mm_set1_epi32(0x04000040));
  135|       |
  136|  3.13k|    const __m128i t2_0 = _mm_and_si128(in0, _mm_set1_epi32(0x003f03f0));
  137|  3.13k|    const __m128i t2_1 = _mm_and_si128(in1, _mm_set1_epi32(0x003f03f0));
  138|  3.13k|    const __m128i t2_2 = _mm_and_si128(in2, _mm_set1_epi32(0x003f03f0));
  139|  3.13k|    const __m128i t2_3 = _mm_and_si128(in3, _mm_set1_epi32(0x003f03f0));
  140|       |
  141|  3.13k|    const __m128i t3_0 = _mm_mullo_epi16(t2_0, _mm_set1_epi32(0x01000010));
  142|  3.13k|    const __m128i t3_1 = _mm_mullo_epi16(t2_1, _mm_set1_epi32(0x01000010));
  143|  3.13k|    const __m128i t3_2 = _mm_mullo_epi16(t2_2, _mm_set1_epi32(0x01000010));
  144|  3.13k|    const __m128i t3_3 = _mm_mullo_epi16(t2_3, _mm_set1_epi32(0x01000010));
  145|       |
  146|  3.13k|    const __m128i input0 = _mm_or_si128(t1_0, t3_0);
  147|  3.13k|    const __m128i input1 = _mm_or_si128(t1_1, t3_1);
  148|  3.13k|    const __m128i input2 = _mm_or_si128(t1_2, t3_2);
  149|  3.13k|    const __m128i input3 = _mm_or_si128(t1_3, t3_3);
  150|       |
  151|  3.13k|    const __m128i t0 = lookup_pshufb_improved<isbase64url>(input0);
  152|  3.13k|    const __m128i t1 = lookup_pshufb_improved<isbase64url>(input1);
  153|  3.13k|    const __m128i t2 = lookup_pshufb_improved<isbase64url>(input2);
  154|  3.13k|    const __m128i t3 = lookup_pshufb_improved<isbase64url>(input3);
  155|       |
  156|  3.13k|    if (use_lines) {
  ------------------
  |  Branch (156:9): [Folded, False: 3.13k]
  ------------------
  157|      0|      if (line_length >= 64) { // fast path
  ------------------
  |  Branch (157:11): [True: 0, False: 0]
  ------------------
  158|      0|        if (offset + 64 > line_length) {
  ------------------
  |  Branch (158:13): [True: 0, False: 0]
  ------------------
  159|      0|          size_t location_end = line_length - offset;
  160|      0|          size_t to_move = 64 - location_end;
  161|      0|          if (location_end < 16) {
  ------------------
  |  Branch (161:15): [True: 0, False: 0]
  ------------------
  162|       |            // We can store or extract store. See below.
  163|       |            //_mm_storeu_si128(reinterpret_cast<__m128i *>(out+1), t0);
  164|      0|            _mm_storeu_si128(reinterpret_cast<__m128i *>(out),
  165|      0|                             insert_line_feed16(t0, location_end));
  166|      0|            out[16] = static_cast<uint8_t>(_mm_extract_epi8(t0, 15));
  167|      0|            out += 17;
  168|      0|          } else {
  169|      0|            _mm_storeu_si128(reinterpret_cast<__m128i *>(out), t0);
  170|      0|            out += 16;
  171|      0|          }
  172|      0|          if (location_end >= 16 && location_end < 32) {
  ------------------
  |  Branch (172:15): [True: 0, False: 0]
  |  Branch (172:37): [True: 0, False: 0]
  ------------------
  173|       |            // We can store or extract store. See below.
  174|       |            //_mm_storeu_si128(reinterpret_cast<__m128i *>(out+1), t1);
  175|      0|            _mm_storeu_si128(reinterpret_cast<__m128i *>(out),
  176|      0|                             insert_line_feed16(t1, location_end - 16));
  177|      0|            out[16] = static_cast<uint8_t>(_mm_extract_epi8(t1, 15));
  178|      0|            out += 17;
  179|      0|          } else {
  180|      0|            _mm_storeu_si128(reinterpret_cast<__m128i *>(out), t1);
  181|      0|            out += 16;
  182|      0|          }
  183|      0|          if (location_end >= 32 && location_end < 48) {
  ------------------
  |  Branch (183:15): [True: 0, False: 0]
  |  Branch (183:37): [True: 0, False: 0]
  ------------------
  184|       |            // We can store or extract store. See below.
  185|       |            //_mm_storeu_si128(reinterpret_cast<__m128i *>(out+1), t2);
  186|      0|            _mm_storeu_si128(reinterpret_cast<__m128i *>(out),
  187|      0|                             insert_line_feed16(t2, location_end - 32));
  188|      0|            out[16] = static_cast<uint8_t>(_mm_extract_epi8(t2, 15));
  189|      0|            out += 17;
  190|      0|          } else {
  191|      0|            _mm_storeu_si128(reinterpret_cast<__m128i *>(out), t2);
  192|      0|            out += 16;
  193|      0|          }
  194|      0|          if (location_end >= 48) {
  ------------------
  |  Branch (194:15): [True: 0, False: 0]
  ------------------
  195|       |            // We can store or extract store. See below.
  196|       |            //_mm_storeu_si128(reinterpret_cast<__m128i *>(out+1), t3);
  197|      0|            _mm_storeu_si128(reinterpret_cast<__m128i *>(out),
  198|      0|                             insert_line_feed16(t3, location_end - 48));
  199|      0|            out[16] = static_cast<uint8_t>(_mm_extract_epi8(t3, 15));
  200|      0|            out += 17;
  201|      0|          } else {
  202|      0|            _mm_storeu_si128(reinterpret_cast<__m128i *>(out), t3);
  203|      0|            out += 16;
  204|      0|          }
  205|      0|          offset = to_move;
  206|      0|        } else {
  207|       |
  208|      0|          _mm_storeu_si128(reinterpret_cast<__m128i *>(out), t0);
  209|      0|          _mm_storeu_si128(reinterpret_cast<__m128i *>(out + 16), t1);
  210|      0|          _mm_storeu_si128(reinterpret_cast<__m128i *>(out + 32), t2);
  211|      0|          _mm_storeu_si128(reinterpret_cast<__m128i *>(out + 48), t3);
  212|      0|          offset += 64;
  213|      0|          out += 64;
  214|      0|        }
  215|      0|      } else { // slow path
  216|       |        // could be optimized
  217|      0|        alignas(64) uint8_t buffer[64];
  218|      0|        _mm_storeu_si128(reinterpret_cast<__m128i *>(buffer), t0);
  219|      0|        _mm_storeu_si128(reinterpret_cast<__m128i *>(buffer + 16), t1);
  220|      0|        _mm_storeu_si128(reinterpret_cast<__m128i *>(buffer + 32), t2);
  221|      0|        _mm_storeu_si128(reinterpret_cast<__m128i *>(buffer + 48), t3);
  222|      0|        std::memcpy(out, buffer, 64);
  223|      0|        size_t out_pos = 0;
  224|      0|        size_t local_offset = offset;
  225|      0|        for (size_t j = 0; j < 64;) {
  ------------------
  |  Branch (225:28): [True: 0, False: 0]
  ------------------
  226|      0|          if (local_offset == line_length) {
  ------------------
  |  Branch (226:15): [True: 0, False: 0]
  ------------------
  227|      0|            out[out_pos++] = '\n';
  228|      0|            local_offset = 0;
  229|      0|          }
  230|      0|          out[out_pos++] = buffer[j++];
  231|      0|          local_offset++;
  232|      0|        }
  233|      0|        offset = local_offset;
  234|      0|        out += out_pos;
  235|      0|      }
  236|  3.13k|    } else {
  237|  3.13k|      _mm_storeu_si128(reinterpret_cast<__m128i *>(out), t0);
  238|  3.13k|      _mm_storeu_si128(reinterpret_cast<__m128i *>(out + 16), t1);
  239|  3.13k|      _mm_storeu_si128(reinterpret_cast<__m128i *>(out + 32), t2);
  240|  3.13k|      _mm_storeu_si128(reinterpret_cast<__m128i *>(out + 48), t3);
  241|  3.13k|      out += 64;
  242|  3.13k|    }
  243|  3.13k|  }
  244|  16.7k|  for (; i + 16 <= srclen; i += 12) {
  ------------------
  |  Branch (244:10): [True: 1.09k, False: 15.6k]
  ------------------
  245|       |
  246|  1.09k|    __m128i in = _mm_loadu_si128(reinterpret_cast<const __m128i *>(input + i));
  247|       |
  248|       |    // bytes from groups A, B and C are needed in separate 32-bit lanes
  249|       |    // in = [DDDD|CCCC|BBBB|AAAA]
  250|       |    //
  251|       |    //      an input triplet has layout
  252|       |    //      [????????|ccdddddd|bbbbcccc|aaaaaabb]
  253|       |    //        byte 3   byte 2   byte 1   byte 0    -- byte 3 comes from the next
  254|       |    //        triplet
  255|       |    //
  256|       |    //      shuffling changes the order of bytes: 1, 0, 2, 1
  257|       |    //      [bbbbcccc|ccdddddd|aaaaaabb|bbbbcccc]
  258|       |    //           ^^^^ ^^^^^^^^ ^^^^^^^^ ^^^^
  259|       |    //                  processed bits
  260|  1.09k|    in = _mm_shuffle_epi8(in, shuf);
  261|       |
  262|       |    // unpacking
  263|       |
  264|       |    // t0    = [0000cccc|cc000000|aaaaaa00|00000000]
  265|  1.09k|    const __m128i t0 = _mm_and_si128(in, _mm_set1_epi32(0x0fc0fc00));
  266|       |    // t1    = [00000000|00cccccc|00000000|00aaaaaa]
  267|       |    //          (c * (1 << 10), a * (1 << 6)) >> 16 (note: an unsigned
  268|       |    //          multiplication)
  269|  1.09k|    const __m128i t1 = _mm_mulhi_epu16(t0, _mm_set1_epi32(0x04000040));
  270|       |
  271|       |    // t2    = [00000000|00dddddd|000000bb|bbbb0000]
  272|  1.09k|    const __m128i t2 = _mm_and_si128(in, _mm_set1_epi32(0x003f03f0));
  273|       |    // t3    = [00dddddd|00000000|00bbbbbb|00000000](
  274|       |    //          (d * (1 << 8), b * (1 << 4))
  275|  1.09k|    const __m128i t3 = _mm_mullo_epi16(t2, _mm_set1_epi32(0x01000010));
  276|       |
  277|       |    // res   = [00dddddd|00cccccc|00bbbbbb|00aaaaaa] = t1 | t3
  278|  1.09k|    const __m128i indices = _mm_or_si128(t1, t3);
  279|       |
  280|  1.09k|    const __m128i T0 = lookup_pshufb_improved<isbase64url>(indices);
  281|       |
  282|  1.09k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(out), T0);
  283|       |
  284|  1.09k|    if (use_lines) {
  ------------------
  |  Branch (284:9): [Folded, False: 1.09k]
  ------------------
  285|      0|      if (line_length >= 16) { // fast path
  ------------------
  |  Branch (285:11): [True: 0, False: 0]
  ------------------
  286|      0|        _mm_storeu_si128(reinterpret_cast<__m128i *>(out), T0);
  287|      0|        if (offset + 16 > line_length) {
  ------------------
  |  Branch (287:13): [True: 0, False: 0]
  ------------------
  288|      0|          size_t location_end = line_length - offset;
  289|      0|          size_t to_move = 16 - location_end;
  290|      0|          std::memmove(out + location_end + 1, out + location_end, to_move);
  291|      0|          out[location_end] = '\n';
  292|      0|          offset = to_move;
  293|      0|          out += 16 + 1;
  294|      0|        } else {
  295|      0|          offset += 16;
  296|      0|          out += 16;
  297|      0|        }
  298|      0|      } else { // slow path
  299|       |        // could be optimized
  300|      0|        uint8_t buffer[16];
  301|      0|        _mm_storeu_si128(reinterpret_cast<__m128i *>(buffer), T0);
  302|      0|        size_t out_pos = 0;
  303|      0|        size_t local_offset = offset;
  304|      0|        for (size_t j = 0; j < 16;) {
  ------------------
  |  Branch (304:28): [True: 0, False: 0]
  ------------------
  305|      0|          if (local_offset == line_length) {
  ------------------
  |  Branch (305:15): [True: 0, False: 0]
  ------------------
  306|      0|            out[out_pos++] = '\n';
  307|      0|            local_offset = 0;
  308|      0|          }
  309|      0|          out[out_pos++] = buffer[j++];
  310|      0|          local_offset++;
  311|      0|        }
  312|      0|        offset = local_offset;
  313|      0|        out += out_pos;
  314|      0|      }
  315|  1.09k|    } else {
  316|  1.09k|      _mm_storeu_si128(reinterpret_cast<__m128i *>(out), T0);
  317|  1.09k|      out += 16;
  318|  1.09k|    }
  319|  1.09k|  }
  320|  15.6k|  return ((char *)out - (char *)dst) +
  321|  15.6k|         scalar::base64::tail_encode_base64_impl<use_lines>(
  322|  15.6k|             (char *)out, src + i, srclen - i, options, line_length, offset);
  323|  15.6k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_122lookup_pshufb_improvedILb0EEEDv2_xS3_:
   30|  13.6k|template <bool base64_url> __m128i lookup_pshufb_improved(const __m128i input) {
   31|       |  // credit: Wojciech Muła
   32|       |  // reduce  0..51 -> 0
   33|       |  //        52..61 -> 1 .. 10
   34|       |  //            62 -> 11
   35|       |  //            63 -> 12
   36|  13.6k|  __m128i result = _mm_subs_epu8(input, _mm_set1_epi8(51));
   37|       |
   38|       |  // distinguish between ranges 0..25 and 26..51:
   39|       |  //         0 .. 25 -> remains 0
   40|       |  //        26 .. 51 -> becomes 13
   41|  13.6k|  const __m128i less = _mm_cmpgt_epi8(_mm_set1_epi8(26), input);
   42|  13.6k|  result = _mm_or_si128(result, _mm_and_si128(less, _mm_set1_epi8(13)));
   43|       |
   44|  13.6k|  __m128i shift_LUT;
   45|  13.6k|  if (base64_url) {
  ------------------
  |  Branch (45:7): [Folded, False: 13.6k]
  ------------------
   46|      0|    shift_LUT = _mm_setr_epi8('a' - 26, '0' - 52, '0' - 52, '0' - 52, '0' - 52,
   47|      0|                              '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52,
   48|      0|                              '0' - 52, '-' - 62, '_' - 63, 'A', 0, 0);
   49|  13.6k|  } else {
   50|  13.6k|    shift_LUT = _mm_setr_epi8('a' - 26, '0' - 52, '0' - 52, '0' - 52, '0' - 52,
   51|  13.6k|                              '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52,
   52|  13.6k|                              '0' - 52, '+' - 62, '/' - 63, 'A', 0, 0);
   53|  13.6k|  }
   54|       |
   55|       |  // read shift
   56|  13.6k|  result = _mm_shuffle_epi8(shift_LUT, result);
   57|       |
   58|  13.6k|  return _mm_add_epi8(result, input);
   59|  13.6k|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_127sse_convert_latin1_to_utf16ILNS_10endiannessE0EEENSt3__14pairIPKcPDsEES7_mS8_:
    4|  5.56k|                            char16_t *utf16_output) {
    5|  5.56k|  size_t rounded_len = len & ~0xF; // Round down to nearest multiple of 16
    6|  15.8k|  for (size_t i = 0; i < rounded_len; i += 16) {
  ------------------
  |  Branch (6:22): [True: 10.2k, False: 5.56k]
  ------------------
    7|       |    // Load 16 Latin1 characters into a 128-bit register
    8|  10.2k|    __m128i in =
    9|  10.2k|        _mm_loadu_si128(reinterpret_cast<const __m128i *>(&latin1_input[i]));
   10|  10.2k|    __m128i out1 = big_endian ? _mm_unpacklo_epi8(_mm_setzero_si128(), in)
  ------------------
  |  Branch (10:20): [Folded, False: 10.2k]
  ------------------
   11|  10.2k|                              : _mm_unpacklo_epi8(in, _mm_setzero_si128());
   12|  10.2k|    __m128i out2 = big_endian ? _mm_unpackhi_epi8(_mm_setzero_si128(), in)
  ------------------
  |  Branch (12:20): [Folded, False: 10.2k]
  ------------------
   13|  10.2k|                              : _mm_unpackhi_epi8(in, _mm_setzero_si128());
   14|       |    // Zero extend each Latin1 character to 16-bit integers and store the
   15|       |    // results back to memory
   16|  10.2k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(&utf16_output[i]), out1);
   17|  10.2k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(&utf16_output[i + 8]), out2);
   18|  10.2k|  }
   19|       |  // return pointers pointing to where we left off
   20|  5.56k|  return std::make_pair(latin1_input + rounded_len, utf16_output + rounded_len);
   21|  5.56k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_127sse_convert_latin1_to_utf16ILNS_10endiannessE1EEENSt3__14pairIPKcPDsEES7_mS8_:
    4|  5.56k|                            char16_t *utf16_output) {
    5|  5.56k|  size_t rounded_len = len & ~0xF; // Round down to nearest multiple of 16
    6|  15.8k|  for (size_t i = 0; i < rounded_len; i += 16) {
  ------------------
  |  Branch (6:22): [True: 10.2k, False: 5.56k]
  ------------------
    7|       |    // Load 16 Latin1 characters into a 128-bit register
    8|  10.2k|    __m128i in =
    9|  10.2k|        _mm_loadu_si128(reinterpret_cast<const __m128i *>(&latin1_input[i]));
   10|  10.2k|    __m128i out1 = big_endian ? _mm_unpacklo_epi8(_mm_setzero_si128(), in)
  ------------------
  |  Branch (10:20): [True: 10.2k, Folded]
  ------------------
   11|  10.2k|                              : _mm_unpacklo_epi8(in, _mm_setzero_si128());
   12|  10.2k|    __m128i out2 = big_endian ? _mm_unpackhi_epi8(_mm_setzero_si128(), in)
  ------------------
  |  Branch (12:20): [True: 10.2k, Folded]
  ------------------
   13|  10.2k|                              : _mm_unpackhi_epi8(in, _mm_setzero_si128());
   14|       |    // Zero extend each Latin1 character to 16-bit integers and store the
   15|       |    // results back to memory
   16|  10.2k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(&utf16_output[i]), out1);
   17|  10.2k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(&utf16_output[i + 8]), out2);
   18|  10.2k|  }
   19|       |  // return pointers pointing to where we left off
   20|  5.56k|  return std::make_pair(latin1_input + rounded_len, utf16_output + rounded_len);
   21|  5.56k|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_127sse_convert_latin1_to_utf32EPKcmPDi:
    3|  5.56k|                            char32_t *utf32_output) {
    4|  5.56k|  const char *end = buf + len;
    5|       |
    6|  15.8k|  while (end - buf >= 16) {
  ------------------
  |  Branch (6:10): [True: 10.2k, False: 5.56k]
  ------------------
    7|       |    // Load 16 Latin1 characters (16 bytes) into a 128-bit register
    8|  10.2k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
    9|       |
   10|       |    // Shift input to process next 4 bytes
   11|  10.2k|    __m128i in_shifted1 = _mm_srli_si128(in, 4);
   12|  10.2k|    __m128i in_shifted2 = _mm_srli_si128(in, 8);
   13|  10.2k|    __m128i in_shifted3 = _mm_srli_si128(in, 12);
   14|       |
   15|       |    // expand 8-bit to 32-bit unit
   16|  10.2k|    __m128i out1 = _mm_cvtepu8_epi32(in);
   17|  10.2k|    __m128i out2 = _mm_cvtepu8_epi32(in_shifted1);
   18|  10.2k|    __m128i out3 = _mm_cvtepu8_epi32(in_shifted2);
   19|  10.2k|    __m128i out4 = _mm_cvtepu8_epi32(in_shifted3);
   20|       |
   21|  10.2k|    _mm_storeu_si128((__m128i *)utf32_output, out1);
   22|  10.2k|    _mm_storeu_si128((__m128i *)(utf32_output + 4), out2);
   23|  10.2k|    _mm_storeu_si128((__m128i *)(utf32_output + 8), out3);
   24|  10.2k|    _mm_storeu_si128((__m128i *)(utf32_output + 12), out4);
   25|       |
   26|  10.2k|    utf32_output += 16;
   27|  10.2k|    buf += 16;
   28|  10.2k|  }
   29|       |
   30|  5.56k|  return std::make_pair(buf, utf32_output);
   31|  5.56k|}

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

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_127sse_convert_utf16_to_latin1ILNS_10endiannessE0EEENSt3__14pairIPKDsPcEES7_mS8_:
    4|  5.56k|                            char *latin1_output) {
    5|  5.56k|  const char16_t *end = buf + len;
    6|  26.2k|  while (end - buf >= 8) {
  ------------------
  |  Branch (6:10): [True: 20.7k, False: 5.56k]
  ------------------
    7|       |    // Load 8 UTF-16 characters into 128-bit SSE register
    8|  20.7k|    __m128i in = _mm_loadu_si128(reinterpret_cast<const __m128i *>(buf));
    9|       |
   10|       |    if constexpr (!match_system(big_endian)) {
   11|       |      const __m128i swap =
   12|       |          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   13|       |      in = _mm_shuffle_epi8(in, swap);
   14|       |    }
   15|       |
   16|  20.7k|    __m128i high_byte_mask = _mm_set1_epi16((int16_t)0xFF00);
   17|  20.7k|    if (_mm_testz_si128(in, high_byte_mask)) {
  ------------------
  |  Branch (17:9): [True: 20.7k, False: 0]
  ------------------
   18|       |      // Pack 16-bit characters into 8-bit and store in latin1_output
   19|  20.7k|      __m128i latin1_packed = _mm_packus_epi16(in, in);
   20|  20.7k|      _mm_storel_epi64(reinterpret_cast<__m128i *>(latin1_output),
   21|  20.7k|                       latin1_packed);
   22|       |      // Adjust pointers for next iteration
   23|  20.7k|      buf += 8;
   24|  20.7k|      latin1_output += 8;
   25|  20.7k|    } else {
   26|      0|      return std::make_pair(nullptr, reinterpret_cast<char *>(latin1_output));
   27|      0|    }
   28|  20.7k|  } // while
   29|  5.56k|  return std::make_pair(buf, latin1_output);
   30|  5.56k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_127sse_convert_utf16_to_latin1ILNS_10endiannessE1EEENSt3__14pairIPKDsPcEES7_mS8_:
    4|  5.56k|                            char *latin1_output) {
    5|  5.56k|  const char16_t *end = buf + len;
    6|  26.2k|  while (end - buf >= 8) {
  ------------------
  |  Branch (6:10): [True: 20.7k, False: 5.56k]
  ------------------
    7|       |    // Load 8 UTF-16 characters into 128-bit SSE register
    8|  20.7k|    __m128i in = _mm_loadu_si128(reinterpret_cast<const __m128i *>(buf));
    9|       |
   10|  20.7k|    if constexpr (!match_system(big_endian)) {
   11|  20.7k|      const __m128i swap =
   12|  20.7k|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   13|  20.7k|      in = _mm_shuffle_epi8(in, swap);
   14|  20.7k|    }
   15|       |
   16|  20.7k|    __m128i high_byte_mask = _mm_set1_epi16((int16_t)0xFF00);
   17|  20.7k|    if (_mm_testz_si128(in, high_byte_mask)) {
  ------------------
  |  Branch (17:9): [True: 20.7k, False: 0]
  ------------------
   18|       |      // Pack 16-bit characters into 8-bit and store in latin1_output
   19|  20.7k|      __m128i latin1_packed = _mm_packus_epi16(in, in);
   20|  20.7k|      _mm_storel_epi64(reinterpret_cast<__m128i *>(latin1_output),
   21|  20.7k|                       latin1_packed);
   22|       |      // Adjust pointers for next iteration
   23|  20.7k|      buf += 8;
   24|  20.7k|      latin1_output += 8;
   25|  20.7k|    } else {
   26|      0|      return std::make_pair(nullptr, reinterpret_cast<char *>(latin1_output));
   27|      0|    }
   28|  20.7k|  } // while
   29|  5.56k|  return std::make_pair(buf, latin1_output);
   30|  5.56k|}

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

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_127sse_convert_utf32_to_latin1EPKDimPc:
    3|  5.56k|                            char *latin1_output) {
    4|  5.56k|  const size_t rounded_len = len & ~0xF; // Round down to nearest multiple of 16
    5|       |
    6|  5.56k|  __m128i high_bytes_mask = _mm_set1_epi32(0xFFFFFF00);
    7|  5.56k|  __m128i shufmask =
    8|  5.56k|      _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 12, 8, 4, 0);
    9|       |
   10|  15.8k|  for (size_t i = 0; i < rounded_len; i += 16) {
  ------------------
  |  Branch (10:22): [True: 10.2k, False: 5.56k]
  ------------------
   11|  10.2k|    __m128i in1 = _mm_loadu_si128((__m128i *)buf);
   12|  10.2k|    __m128i in2 = _mm_loadu_si128((__m128i *)(buf + 4));
   13|  10.2k|    __m128i in3 = _mm_loadu_si128((__m128i *)(buf + 8));
   14|  10.2k|    __m128i in4 = _mm_loadu_si128((__m128i *)(buf + 12));
   15|       |
   16|  10.2k|    __m128i check_combined = _mm_or_si128(in1, in2);
   17|  10.2k|    check_combined = _mm_or_si128(check_combined, in3);
   18|  10.2k|    check_combined = _mm_or_si128(check_combined, in4);
   19|       |
   20|  10.2k|    if (!_mm_testz_si128(check_combined, high_bytes_mask)) {
  ------------------
  |  Branch (20:9): [True: 0, False: 10.2k]
  ------------------
   21|      0|      return std::make_pair(nullptr, latin1_output);
   22|      0|    }
   23|  10.2k|    __m128i pack1 = _mm_unpacklo_epi32(_mm_shuffle_epi8(in1, shufmask),
   24|  10.2k|                                       _mm_shuffle_epi8(in2, shufmask));
   25|  10.2k|    __m128i pack2 = _mm_unpacklo_epi32(_mm_shuffle_epi8(in3, shufmask),
   26|  10.2k|                                       _mm_shuffle_epi8(in4, shufmask));
   27|  10.2k|    __m128i pack = _mm_unpacklo_epi64(pack1, pack2);
   28|  10.2k|    _mm_storeu_si128((__m128i *)latin1_output, pack);
   29|  10.2k|    latin1_output += 16;
   30|  10.2k|    buf += 16;
   31|  10.2k|  }
   32|       |
   33|  5.56k|  return std::make_pair(buf, latin1_output);
   34|  5.56k|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_125sse_convert_utf32_to_utf8EPKDimPc:
    2|  5.14k|sse_convert_utf32_to_utf8(const char32_t *buf, size_t len, char *utf8_output) {
    3|  5.14k|  const char32_t *end = buf + len;
    4|       |
    5|  5.14k|  const __m128i v_0000 = _mm_setzero_si128();              //__m128 = 128 bits
    6|  5.14k|  const __m128i v_f800 = _mm_set1_epi16((uint16_t)0xf800); // 1111 1000 0000
    7|       |                                                           // 0000
    8|  5.14k|  const __m128i v_c080 = _mm_set1_epi16((uint16_t)0xc080); // 1100 0000 1000
    9|       |                                                           // 0000
   10|  5.14k|  const __m128i v_ff80 = _mm_set1_epi16((uint16_t)0xff80); // 1111 1111 1000
   11|       |                                                           // 0000
   12|  5.14k|  const __m128i v_ffff0000 = _mm_set1_epi32(
   13|  5.14k|      (uint32_t)0xffff0000); // 1111 1111 1111 1111 0000 0000 0000 0000
   14|  5.14k|  const __m128i v_7fffffff = _mm_set1_epi32(
   15|  5.14k|      (uint32_t)0x7fffffff); // 0111 1111 1111 1111 1111 1111 1111 1111
   16|  5.14k|  __m128i running_max = _mm_setzero_si128();
   17|  5.14k|  __m128i forbidden_bytemask = _mm_setzero_si128();
   18|  5.14k|  const size_t safety_margin =
   19|  5.14k|      12; // to avoid overruns, see issue
   20|       |          // https://github.com/simdutf/simdutf/issues/92
   21|       |
   22|  10.8k|  while (end - buf >=
  ------------------
  |  Branch (22:10): [True: 5.71k, False: 5.14k]
  ------------------
   23|  10.8k|         std::ptrdiff_t(
   24|  10.8k|             16 + safety_margin)) { // buf is a char32_t pointer, each char32_t
   25|       |                                    // has 4 bytes or 32 bits, thus buf + 16 *
   26|       |                                    // char_32t = 512 bits = 64 bytes
   27|       |    // We load two 16 bytes registers for a total of 32 bytes or 16 characters.
   28|  5.71k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
   29|  5.71k|    __m128i nextin = _mm_loadu_si128(
   30|  5.71k|        (__m128i *)buf + 1); // These two values can hold only 8 UTF32 chars
   31|  5.71k|    running_max = _mm_max_epu32(
   32|  5.71k|        _mm_max_epu32(in, running_max), // take element-wise max char32_t from
   33|       |                                        // in and running_max vector
   34|  5.71k|        nextin); // and take element-wise max element from nextin and
   35|       |                 // running_max vector
   36|       |
   37|       |    // Pack 32-bit UTF-32 code units to 16-bit UTF-16 code units with unsigned
   38|       |    // saturation
   39|  5.71k|    __m128i in_16 = _mm_packus_epi32(
   40|  5.71k|        _mm_and_si128(in, v_7fffffff),
   41|  5.71k|        _mm_and_si128(
   42|  5.71k|            nextin,
   43|  5.71k|            v_7fffffff)); // in this context pack the two __m128 into a single
   44|       |    // By ensuring the highest bit is set to 0(&v_7fffffff), we are making sure
   45|       |    // all values are interpreted as non-negative, or specifically, the values
   46|       |    // are within the range of valid Unicode code points. remember : having
   47|       |    // leading byte 0 means a positive number by the two complements system.
   48|       |    // Unicode is well beneath the range where you'll start getting issues so
   49|       |    // that's OK.
   50|       |
   51|       |    // Try to apply UTF-16 => UTF-8 from ./sse_convert_utf16_to_utf8.cpp
   52|       |
   53|       |    // Check for ASCII fast path
   54|       |
   55|       |    // ASCII fast path!!!!
   56|       |    // We eagerly load another 32 bytes, hoping that they will be ASCII too.
   57|       |    // The intuition is that we try to collect 16 ASCII characters which
   58|       |    // requires a total of 64 bytes of input. If we fail, we just pass thirdin
   59|       |    // and fourthin as our new inputs.
   60|  5.71k|    if (_mm_testz_si128(in_16, v_ff80)) { // if the first two blocks are ASCII
  ------------------
  |  Branch (60:9): [True: 3.45k, False: 2.26k]
  ------------------
   61|  3.45k|      __m128i thirdin = _mm_loadu_si128((__m128i *)buf + 2);
   62|  3.45k|      __m128i fourthin = _mm_loadu_si128((__m128i *)buf + 3);
   63|  3.45k|      running_max = _mm_max_epu32(
   64|  3.45k|          _mm_max_epu32(thirdin, running_max),
   65|  3.45k|          fourthin); // take the running max of all 4 vectors thus far
   66|  3.45k|      __m128i nextin_16 = _mm_packus_epi32(
   67|  3.45k|          _mm_and_si128(thirdin, v_7fffffff),
   68|  3.45k|          _mm_and_si128(fourthin,
   69|  3.45k|                        v_7fffffff)); // pack into 1 vector, now you have two
   70|  3.45k|      if (!_mm_testz_si128(
  ------------------
  |  Branch (70:11): [True: 377, False: 3.07k]
  ------------------
   71|  3.45k|              nextin_16,
   72|  3.45k|              v_ff80)) { // checks if the second packed vector is ASCII, if not:
   73|       |        // 1. pack the bytes
   74|       |        // obviously suboptimal.
   75|    377|        const __m128i utf8_packed = _mm_packus_epi16(
   76|    377|            in_16, in_16); // creates two copy of in_16 in 1 vector
   77|       |        // 2. store (16 bytes)
   78|    377|        _mm_storeu_si128((__m128i *)utf8_output,
   79|    377|                         utf8_packed); // put them into the output
   80|       |        // 3. adjust pointers
   81|    377|        buf += 8; // the char32_t buffer pointer goes up 8 char32_t chars* 32
   82|       |                  // bits =  256 bits
   83|    377|        utf8_output +=
   84|    377|            8; // same with output, e.g. lift the first two blocks alone.
   85|       |        // Proceed with next input
   86|    377|        in_16 = nextin_16;
   87|       |        // We need to update in and nextin because they are used later.
   88|    377|        in = thirdin;
   89|    377|        nextin = fourthin;
   90|  3.07k|      } else {
   91|       |        // 1. pack the bytes
   92|  3.07k|        const __m128i utf8_packed = _mm_packus_epi16(in_16, nextin_16);
   93|       |        // 2. store (16 bytes)
   94|  3.07k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   95|       |        // 3. adjust pointers
   96|  3.07k|        buf += 16;
   97|  3.07k|        utf8_output += 16;
   98|  3.07k|        continue; // we are done for this round!
   99|  3.07k|      }
  100|  3.45k|    }
  101|       |
  102|       |    // no bits set above 7th bit -- find out all the ASCII characters
  103|  2.64k|    const __m128i one_byte_bytemask =
  104|  2.64k|        _mm_cmpeq_epi16( // this takes four bytes at a time and compares:
  105|  2.64k|            _mm_and_si128(in_16, v_ff80), // the vector that get only the first
  106|       |                                          // 9 bits of each 16-bit/2-byte units
  107|  2.64k|            v_0000                        //
  108|  2.64k|        ); // they should be all zero if they are ASCII. E.g. ASCII in UTF32 is
  109|       |           // of format 0000 0000 0000 0XXX XXXX
  110|       |    // _mm_cmpeq_epi16 should now return a 1111 1111 1111 1111 for equals, and
  111|       |    // 0000 0000 0000 0000 if not for each 16-bit/2-byte units
  112|  2.64k|    const uint16_t one_byte_bitmask = static_cast<uint16_t>(_mm_movemask_epi8(
  113|  2.64k|        one_byte_bytemask)); // collect the MSB from previous vector and put
  114|       |                             // them into uint16_t mas
  115|       |
  116|       |    // no bits set above 11th bit
  117|  2.64k|    const __m128i one_or_two_bytes_bytemask =
  118|  2.64k|        _mm_cmpeq_epi16(_mm_and_si128(in_16, v_f800), v_0000);
  119|  2.64k|    const uint16_t one_or_two_bytes_bitmask =
  120|  2.64k|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  121|       |
  122|  2.64k|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (122:9): [True: 1.52k, False: 1.11k]
  ------------------
  123|       |      // case: all code units either produce 1 or 2 UTF-8 bytes (at least one
  124|       |      // produces 2 bytes)
  125|       |      // 1. prepare 2-byte values
  126|       |      // input 16-bit word : [0000|0aaa|aabb|bbbb] x 8
  127|       |      // expected output   : [110a|aaaa|10bb|bbbb] x 8
  128|  1.52k|      const __m128i v_1f00 =
  129|  1.52k|          _mm_set1_epi16((int16_t)0x1f00); // 0001 1111 0000 0000
  130|  1.52k|      const __m128i v_003f =
  131|  1.52k|          _mm_set1_epi16((int16_t)0x003f); // 0000 0000 0011 1111
  132|       |
  133|       |      // t0 = [000a|aaaa|bbbb|bb00]
  134|  1.52k|      const __m128i t0 = _mm_slli_epi16(in_16, 2); // shift packed vector by two
  135|       |      // t1 = [000a|aaaa|0000|0000]
  136|  1.52k|      const __m128i t1 = _mm_and_si128(t0, v_1f00); // potential first utf8 byte
  137|       |      // t2 = [0000|0000|00bb|bbbb]
  138|  1.52k|      const __m128i t2 =
  139|  1.52k|          _mm_and_si128(in_16, v_003f); // potential second utf8 byte
  140|       |      // t3 = [000a|aaaa|00bb|bbbb]
  141|  1.52k|      const __m128i t3 =
  142|  1.52k|          _mm_or_si128(t1, t2); // first and second potential utf8 byte together
  143|       |      // t4 = [110a|aaaa|10bb|bbbb]
  144|  1.52k|      const __m128i t4 = _mm_or_si128(
  145|  1.52k|          t3,
  146|  1.52k|          v_c080); // t3 | 1100 0000 1000 0000 = full potential 2-byte utf8 unit
  147|       |
  148|       |      // 2. merge ASCII and 2-byte codewords
  149|  1.52k|      const __m128i utf8_unpacked =
  150|  1.52k|          _mm_blendv_epi8(t4, in_16, one_byte_bytemask);
  151|       |
  152|       |      // 3. prepare bitmask for 8-bit lookup
  153|       |      //    one_byte_bitmask = hhggffeeddccbbaa -- the bits are doubled (h -
  154|       |      //    MSB, a - LSB)
  155|  1.52k|      const uint16_t m0 = one_byte_bitmask & 0x5555; // m0 = 0h0g0f0e0d0c0b0a
  156|  1.52k|      const uint16_t m1 =
  157|  1.52k|          static_cast<uint16_t>(m0 >> 7); // m1 = 00000000h0g0f0e0
  158|  1.52k|      const uint8_t m2 =
  159|  1.52k|          static_cast<uint8_t>((m0 | m1) & 0xff); // m2 =         hdgcfbea
  160|       |      // 4. pack the bytes
  161|  1.52k|      const uint8_t *row =
  162|  1.52k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[m2][0];
  163|  1.52k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  164|  1.52k|      const __m128i utf8_packed = _mm_shuffle_epi8(utf8_unpacked, shuffle);
  165|       |
  166|       |      // 5. store bytes
  167|  1.52k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  168|       |
  169|       |      // 6. adjust pointers
  170|  1.52k|      buf += 8;
  171|  1.52k|      utf8_output += row[0];
  172|  1.52k|      continue;
  173|  1.52k|    }
  174|       |
  175|       |    // Check for overflow in packing
  176|       |
  177|  1.11k|    const __m128i saturation_bytemask = _mm_cmpeq_epi32(
  178|  1.11k|        _mm_and_si128(_mm_or_si128(in, nextin), v_ffff0000), v_0000);
  179|  1.11k|    const uint32_t saturation_bitmask =
  180|  1.11k|        static_cast<uint32_t>(_mm_movemask_epi8(saturation_bytemask));
  181|  1.11k|    if (saturation_bitmask == 0xffff) {
  ------------------
  |  Branch (181:9): [True: 407, False: 711]
  ------------------
  182|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  183|    407|      const __m128i v_d800 = _mm_set1_epi16((uint16_t)0xd800);
  184|    407|      forbidden_bytemask =
  185|    407|          _mm_or_si128(forbidden_bytemask,
  186|    407|                       _mm_cmpeq_epi16(_mm_and_si128(in_16, v_f800), v_d800));
  187|       |
  188|    407|      const __m128i dup_even = _mm_setr_epi16(0x0000, 0x0202, 0x0404, 0x0606,
  189|    407|                                              0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  190|       |
  191|       |      /* In this branch we handle three cases:
  192|       |          1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  193|       |        single UFT-8 byte
  194|       |          2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              -
  195|       |        two UTF-8 bytes
  196|       |          3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  197|       |        three UTF-8 bytes
  198|       |
  199|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  200|       |        we have room for four bytes. However, we need five distinct bit
  201|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  202|       |
  203|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  204|       |        in register t2.
  205|       |
  206|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  207|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  208|       |        differ by exactly one bit.
  209|       |
  210|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  211|       |        into account the case (i.e, the number of bytes to write).
  212|       |      */
  213|       |      /**
  214|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  215|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  216|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  217|       |       */
  218|    407|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  219|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  220|    407|      const __m128i t0 = _mm_shuffle_epi8(in_16, dup_even);
  221|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  222|    407|      const __m128i t1 = _mm_and_si128(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  218|    407|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  223|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  224|    407|      const __m128i t2 = _mm_or_si128(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  218|    407|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  225|       |
  226|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  227|    407|      const __m128i s0 = _mm_srli_epi16(in_16, 4);
  228|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  229|    407|      const __m128i s1 = _mm_and_si128(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  218|    407|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  230|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  231|    407|      const __m128i s2 = _mm_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  218|    407|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  232|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  233|    407|      const __m128i s3 = _mm_or_si128(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  218|    407|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  234|    407|      const __m128i m0 = _mm_andnot_si128(one_or_two_bytes_bytemask,
  235|    407|                                          simdutf_vec(0b0100000000000000));
  ------------------
  |  |  218|    407|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  236|    407|      const __m128i s4 = _mm_xor_si128(s3, m0);
  237|    407|#undef simdutf_vec
  238|       |
  239|       |      // 4. expand code units 16-bit => 32-bit
  240|    407|      const __m128i out0 = _mm_unpacklo_epi16(t2, s4);
  241|    407|      const __m128i out1 = _mm_unpackhi_epi16(t2, s4);
  242|       |
  243|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  244|    407|      const uint16_t mask =
  245|    407|          (one_byte_bitmask & 0x5555) | (one_or_two_bytes_bitmask & 0xaaaa);
  246|    407|      if (mask == 0) {
  ------------------
  |  Branch (246:11): [True: 82, False: 325]
  ------------------
  247|       |        // We only have three-byte code units. Use fast path.
  248|     82|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  249|     82|                                              15, 13, -1, -1, -1, -1);
  250|     82|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  251|     82|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  252|     82|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  253|     82|        utf8_output += 12;
  254|     82|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  255|     82|        utf8_output += 12;
  256|     82|        buf += 8;
  257|     82|        continue;
  258|     82|      }
  259|    325|      const uint8_t mask0 = uint8_t(mask);
  260|       |
  261|    325|      const uint8_t *row0 =
  262|    325|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  263|    325|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  264|    325|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  265|       |
  266|    325|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  267|       |
  268|    325|      const uint8_t *row1 =
  269|    325|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  270|    325|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  271|    325|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  272|       |
  273|    325|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  274|    325|      utf8_output += row0[0];
  275|    325|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  276|    325|      utf8_output += row1[0];
  277|       |
  278|    325|      buf += 8;
  279|    711|    } else {
  280|       |      // case: at least one 32-bit word produce a surrogate pair in UTF-16 <=>
  281|       |      // will produce four UTF-8 bytes Let us do a scalar fallback. It may seem
  282|       |      // wasteful to use scalar code, but being efficient with SIMD in the
  283|       |      // presence of surrogate pairs may require non-trivial tables.
  284|    711|      size_t forward = 15;
  285|    711|      size_t k = 0;
  286|    711|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (286:11): [True: 0, False: 711]
  ------------------
  287|      0|        forward = size_t(end - buf - 1);
  288|      0|      }
  289|  11.3k|      for (; k < forward; k++) {
  ------------------
  |  Branch (289:14): [True: 10.6k, False: 711]
  ------------------
  290|  10.6k|        uint32_t word = buf[k];
  291|  10.6k|        if ((word & 0xFFFFFF80) == 0) {
  ------------------
  |  Branch (291:13): [True: 8.43k, False: 2.22k]
  ------------------
  292|  8.43k|          *utf8_output++ = char(word);
  293|  8.43k|        } else if ((word & 0xFFFFF800) == 0) {
  ------------------
  |  Branch (293:20): [True: 432, False: 1.79k]
  ------------------
  294|    432|          *utf8_output++ = char((word >> 6) | 0b11000000);
  295|    432|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  296|  1.79k|        } else if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (296:20): [True: 646, False: 1.14k]
  ------------------
  297|    646|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (297:15): [True: 235, False: 411]
  |  Branch (297:33): [True: 0, False: 235]
  ------------------
  298|      0|            return std::make_pair(nullptr, utf8_output);
  299|      0|          }
  300|    646|          *utf8_output++ = char((word >> 12) | 0b11100000);
  301|    646|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  302|    646|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  303|  1.14k|        } else {
  304|  1.14k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (304:15): [True: 0, False: 1.14k]
  ------------------
  305|      0|            return std::make_pair(nullptr, utf8_output);
  306|      0|          }
  307|  1.14k|          *utf8_output++ = char((word >> 18) | 0b11110000);
  308|  1.14k|          *utf8_output++ = char(((word >> 12) & 0b111111) | 0b10000000);
  309|  1.14k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  310|  1.14k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  311|  1.14k|        }
  312|  10.6k|      }
  313|    711|      buf += k;
  314|    711|    }
  315|  1.11k|  } // while
  316|       |
  317|       |  // check for invalid input
  318|  5.14k|  const __m128i v_10ffff = _mm_set1_epi32((uint32_t)0x10ffff);
  319|  5.14k|  if (static_cast<uint16_t>(_mm_movemask_epi8(_mm_cmpeq_epi32(
  ------------------
  |  Branch (319:7): [True: 0, False: 5.14k]
  ------------------
  320|  5.14k|          _mm_max_epu32(running_max, v_10ffff), v_10ffff))) != 0xffff) {
  321|      0|    return std::make_pair(nullptr, utf8_output);
  322|      0|  }
  323|       |
  324|  5.14k|  if (static_cast<uint32_t>(_mm_movemask_epi8(forbidden_bytemask)) != 0) {
  ------------------
  |  Branch (324:7): [True: 0, False: 5.14k]
  ------------------
  325|      0|    return std::make_pair(nullptr, utf8_output);
  326|      0|  }
  327|       |
  328|  5.14k|  return std::make_pair(buf, utf8_output);
  329|  5.14k|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_129convert_masked_utf8_to_latin1EPKcmRPc:
    9|  23.7k|                                     char *&latin1_output) {
   10|       |  // we use an approach where we try to process up to 12 input bytes.
   11|       |  // Why 12 input bytes and not 16? Because we are concerned with the size of
   12|       |  // the lookup tables. Also 12 is nicely divisible by two and three.
   13|       |  //
   14|       |  //
   15|       |  // Optimization note: our main path below is load-latency dependent. Thus it
   16|       |  // is maybe beneficial to have fast paths that depend on branch prediction but
   17|       |  // have less latency. This results in more instructions but, potentially, also
   18|       |  // higher speeds.
   19|       |  //
   20|  23.7k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   21|  23.7k|  const uint16_t input_utf8_end_of_code_point_mask =
   22|  23.7k|      utf8_end_of_code_point_mask &
   23|  23.7k|      0xfff; // we are only processing 12 bytes in case it is not all ASCII
   24|  23.7k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (24:7): [True: 141, False: 23.6k]
  ------------------
   25|       |    // We process the data in chunks of 12 bytes.
   26|    141|    _mm_storeu_si128(reinterpret_cast<__m128i *>(latin1_output), in);
   27|    141|    latin1_output += 12; // We wrote 12 characters.
   28|    141|    return 12;           // We consumed 12 bytes.
   29|    141|  }
   30|       |  /// We do not have a fast path available, so we fallback.
   31|  23.6k|  const uint8_t idx =
   32|  23.6k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   33|  23.6k|  const uint8_t consumed =
   34|  23.6k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   35|       |  // this indicates an invalid input:
   36|  23.6k|  if (idx >= 64) {
  ------------------
  |  Branch (36:7): [True: 5.95k, False: 17.6k]
  ------------------
   37|  5.95k|    return consumed;
   38|  5.95k|  }
   39|       |  // Here we should have (idx < 64), if not, there is a bug in the validation or
   40|       |  // elsewhere. SIX (6) input code-code units this is a relatively easy scenario
   41|       |  // we process SIX (6) input code-code units. The max length in bytes of six
   42|       |  // code code units spanning between 1 and 2 bytes each is 12 bytes. On
   43|       |  // processors where pdep/pext is fast, we might be able to use a small lookup
   44|       |  // table.
   45|  17.6k|  const __m128i sh =
   46|  17.6k|      _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   47|  17.6k|  const __m128i perm = _mm_shuffle_epi8(in, sh);
   48|  17.6k|  const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   49|  17.6k|  const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   50|  17.6k|  __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   51|  17.6k|  const __m128i latin1_packed = _mm_packus_epi16(composed, composed);
   52|       |  // writing 8 bytes even though we only care about the first 6 bytes.
   53|       |  // performance note: it would be faster to use _mm_storeu_si128, we should
   54|       |  // investigate.
   55|  17.6k|  _mm_storel_epi64((__m128i *)latin1_output, latin1_packed);
   56|  17.6k|  latin1_output += 6; // We wrote 6 bytes.
   57|  17.6k|  return consumed;
   58|  23.6k|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_128convert_masked_utf8_to_utf16ILNS_10endiannessE0EEEmPKcmRPDs:
   10|  21.9k|                                    char16_t *&utf16_output) {
   11|       |  // we use an approach where we try to process up to 12 input bytes.
   12|       |  // Why 12 input bytes and not 16? Because we are concerned with the size of
   13|       |  // the lookup tables. Also 12 is nicely divisible by two and three.
   14|       |  //
   15|       |  //
   16|       |  // Optimization note: our main path below is load-latency dependent. Thus it
   17|       |  // is maybe beneficial to have fast paths that depend on branch prediction but
   18|       |  // have less latency. This results in more instructions but, potentially, also
   19|       |  // higher speeds.
   20|       |  //
   21|       |  // We first try a few fast paths.
   22|  21.9k|  const __m128i swap =
   23|  21.9k|      _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   24|  21.9k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   25|  21.9k|  const uint16_t input_utf8_end_of_code_point_mask =
   26|  21.9k|      utf8_end_of_code_point_mask & 0xfff;
   27|  21.9k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (27:7): [True: 92, False: 21.8k]
  ------------------
   28|       |    // We process the data in chunks of 12 bytes.
   29|       |    // Note: using 16 bytes is unsafe, see issue_ossfuzz_71218
   30|     92|    __m128i ascii_first = _mm_cvtepu8_epi16(in);
   31|     92|    __m128i ascii_second = _mm_cvtepu8_epi16(_mm_srli_si128(in, 8));
   32|     92|    if (big_endian) {
  ------------------
  |  Branch (32:9): [Folded, False: 92]
  ------------------
   33|      0|      ascii_first = _mm_shuffle_epi8(ascii_first, swap);
   34|      0|      ascii_second = _mm_shuffle_epi8(ascii_second, swap);
   35|      0|    }
   36|     92|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf16_output), ascii_first);
   37|     92|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf16_output + 8),
   38|     92|                     ascii_second);
   39|     92|    utf16_output += 12; // We wrote 12 16-bit characters.
   40|     92|    return 12;          // We consumed 12 bytes.
   41|     92|  }
   42|  21.8k|  if (((utf8_end_of_code_point_mask & 0xFFFF) == 0xaaaa)) {
  ------------------
  |  Branch (42:7): [True: 332, False: 21.5k]
  ------------------
   43|       |    // We want to take 8 2-byte UTF-8 code units and turn them into 8 2-byte
   44|       |    // UTF-16 code units. There is probably a more efficient sequence, but the
   45|       |    // following might do.
   46|    332|    const __m128i sh =
   47|    332|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   48|    332|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   49|    332|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   50|    332|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   51|    332|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   52|    332|    if (big_endian)
  ------------------
  |  Branch (52:9): [Folded, False: 332]
  ------------------
   53|      0|      composed = _mm_shuffle_epi8(composed, swap);
   54|    332|    _mm_storeu_si128((__m128i *)utf16_output, composed);
   55|    332|    utf16_output += 8; // We wrote 16 bytes, 8 code points.
   56|    332|    return 16;
   57|    332|  }
   58|  21.5k|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (58:7): [True: 5.78k, False: 15.7k]
  ------------------
   59|       |    // We want to take 4 3-byte UTF-8 code units and turn them into 4 2-byte
   60|       |    // UTF-16 code units. There is probably a more efficient sequence, but the
   61|       |    // following might do.
   62|  5.78k|    const __m128i sh =
   63|  5.78k|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   64|  5.78k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   65|  5.78k|    const __m128i ascii =
   66|  5.78k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   67|  5.78k|    const __m128i middlebyte =
   68|  5.78k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   69|  5.78k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   70|  5.78k|    const __m128i highbyte =
   71|  5.78k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   72|  5.78k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   73|  5.78k|    const __m128i composed =
   74|  5.78k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   75|  5.78k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
   76|  5.78k|    if (big_endian)
  ------------------
  |  Branch (76:9): [Folded, False: 5.78k]
  ------------------
   77|      0|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
   78|  5.78k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
   79|  5.78k|    utf16_output += 4;
   80|  5.78k|    return 12;
   81|  5.78k|  }
   82|       |  /// We do not have a fast path available, so we fallback.
   83|       |
   84|  15.7k|  const uint8_t idx =
   85|  15.7k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   86|  15.7k|  const uint8_t consumed =
   87|  15.7k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   88|  15.7k|  if (idx < 64) {
  ------------------
  |  Branch (88:7): [True: 8.40k, False: 7.34k]
  ------------------
   89|       |    // SIX (6) input code-code units
   90|       |    // this is a relatively easy scenario
   91|       |    // we process SIX (6) input code-code units. The max length in bytes of six
   92|       |    // code code units spanning between 1 and 2 bytes each is 12 bytes. On
   93|       |    // processors where pdep/pext is fast, we might be able to use a small
   94|       |    // lookup table.
   95|  8.40k|    const __m128i sh =
   96|  8.40k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   97|  8.40k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   98|  8.40k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   99|  8.40k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
  100|  8.40k|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
  101|  8.40k|    if (big_endian)
  ------------------
  |  Branch (101:9): [Folded, False: 8.40k]
  ------------------
  102|      0|      composed = _mm_shuffle_epi8(composed, swap);
  103|  8.40k|    _mm_storeu_si128((__m128i *)utf16_output, composed);
  104|  8.40k|    utf16_output += 6; // We wrote 12 bytes, 6 code points.
  105|  8.40k|  } else if (idx < 145) {
  ------------------
  |  Branch (105:14): [True: 2.22k, False: 5.12k]
  ------------------
  106|       |    // FOUR (4) input code-code units
  107|  2.22k|    const __m128i sh =
  108|  2.22k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  109|  2.22k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  110|  2.22k|    const __m128i ascii =
  111|  2.22k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
  112|  2.22k|    const __m128i middlebyte =
  113|  2.22k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  114|  2.22k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  115|  2.22k|    const __m128i highbyte =
  116|  2.22k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  117|  2.22k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  118|  2.22k|    const __m128i composed =
  119|  2.22k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  120|  2.22k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
  121|  2.22k|    if (big_endian)
  ------------------
  |  Branch (121:9): [Folded, False: 2.22k]
  ------------------
  122|      0|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
  123|  2.22k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
  124|  2.22k|    utf16_output += 4;
  125|  5.12k|  } else if (idx < 209) {
  ------------------
  |  Branch (125:14): [True: 4.89k, False: 222]
  ------------------
  126|       |    // TWO (2) input code-code units
  127|       |    //////////////
  128|       |    // There might be garbage inputs where a leading byte mascarades as a
  129|       |    // four-byte leading byte (by being followed by 3 continuation byte), but is
  130|       |    // not greater than 0xf0. This could trigger a buffer overflow if we only
  131|       |    // counted leading bytes of the form 0xf0 as generating surrogate pairs,
  132|       |    // without further UTF-8 validation. Thus we must be careful to ensure that
  133|       |    // only leading bytes at least as large as 0xf0 generate surrogate pairs. We
  134|       |    // do as at the cost of an extra mask.
  135|       |    /////////////
  136|  4.89k|    const __m128i sh =
  137|  4.89k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  138|  4.89k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  139|  4.89k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  140|  4.89k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  141|  4.89k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  142|  4.89k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  143|       |    // correct for spurious high bit
  144|  4.89k|    const __m128i correct =
  145|  4.89k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  146|  4.89k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  147|  4.89k|    const __m128i middlehighbyte_shifted = _mm_srli_epi32(middlehighbyte, 4);
  148|       |    // We deliberately carry the leading four bits in highbyte if they are
  149|       |    // present, we remove them later when computing hightenbits.
  150|  4.89k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0xff000000));
  151|  4.89k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 6);
  152|       |    // When we need to generate a surrogate pair (leading byte > 0xF0), then
  153|       |    // the corresponding 32-bit value in 'composed'  will be greater than
  154|       |    // > (0xff00000>>6) or > 0x3c00000. This can be used later to identify the
  155|       |    // location of the surrogate pairs.
  156|  4.89k|    const __m128i composed =
  157|  4.89k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  158|  4.89k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  159|  4.89k|    const __m128i composedminus =
  160|  4.89k|        _mm_sub_epi32(composed, _mm_set1_epi32(0x10000));
  161|  4.89k|    const __m128i lowtenbits =
  162|  4.89k|        _mm_and_si128(composedminus, _mm_set1_epi32(0x3ff));
  163|       |    // Notice the 0x3ff mask:
  164|  4.89k|    const __m128i hightenbits =
  165|  4.89k|        _mm_and_si128(_mm_srli_epi32(composedminus, 10), _mm_set1_epi32(0x3ff));
  166|  4.89k|    const __m128i lowtenbitsadd =
  167|  4.89k|        _mm_add_epi32(lowtenbits, _mm_set1_epi32(0xDC00));
  168|  4.89k|    const __m128i hightenbitsadd =
  169|  4.89k|        _mm_add_epi32(hightenbits, _mm_set1_epi32(0xD800));
  170|  4.89k|    const __m128i lowtenbitsaddshifted = _mm_slli_epi32(lowtenbitsadd, 16);
  171|  4.89k|    __m128i surrogates = _mm_or_si128(hightenbitsadd, lowtenbitsaddshifted);
  172|  4.89k|    uint32_t basic_buffer[4];
  173|  4.89k|    uint32_t basic_buffer_swap[4];
  174|  4.89k|    if (big_endian) {
  ------------------
  |  Branch (174:9): [Folded, False: 4.89k]
  ------------------
  175|      0|      _mm_storeu_si128((__m128i *)basic_buffer_swap,
  176|      0|                       _mm_shuffle_epi8(composed, swap));
  177|      0|      surrogates = _mm_shuffle_epi8(surrogates, swap);
  178|      0|    }
  179|  4.89k|    _mm_storeu_si128((__m128i *)basic_buffer, composed);
  180|  4.89k|    uint32_t surrogate_buffer[4];
  181|  4.89k|    _mm_storeu_si128((__m128i *)surrogate_buffer, surrogates);
  182|  19.5k|    for (size_t i = 0; i < 3; i++) {
  ------------------
  |  Branch (182:24): [True: 14.6k, False: 4.89k]
  ------------------
  183|  14.6k|      if (basic_buffer[i] > 0x3c00000) {
  ------------------
  |  Branch (183:11): [True: 3.23k, False: 11.4k]
  ------------------
  184|  3.23k|        utf16_output[0] = uint16_t(surrogate_buffer[i] & 0xffff);
  185|  3.23k|        utf16_output[1] = uint16_t(surrogate_buffer[i] >> 16);
  186|  3.23k|        utf16_output += 2;
  187|  11.4k|      } else {
  188|  11.4k|        utf16_output[0] = big_endian ? uint16_t(basic_buffer_swap[i])
  ------------------
  |  Branch (188:27): [Folded, False: 11.4k]
  ------------------
  189|  11.4k|                                     : uint16_t(basic_buffer[i]);
  190|  11.4k|        utf16_output++;
  191|  11.4k|      }
  192|  14.6k|    }
  193|  4.89k|  } else {
  194|       |    // here we know that there is an error but we do not handle errors
  195|    222|  }
  196|  15.7k|  return consumed;
  197|  21.5k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_128convert_masked_utf8_to_utf16ILNS_10endiannessE1EEEmPKcmRPDs:
   10|  22.6k|                                    char16_t *&utf16_output) {
   11|       |  // we use an approach where we try to process up to 12 input bytes.
   12|       |  // Why 12 input bytes and not 16? Because we are concerned with the size of
   13|       |  // the lookup tables. Also 12 is nicely divisible by two and three.
   14|       |  //
   15|       |  //
   16|       |  // Optimization note: our main path below is load-latency dependent. Thus it
   17|       |  // is maybe beneficial to have fast paths that depend on branch prediction but
   18|       |  // have less latency. This results in more instructions but, potentially, also
   19|       |  // higher speeds.
   20|       |  //
   21|       |  // We first try a few fast paths.
   22|  22.6k|  const __m128i swap =
   23|  22.6k|      _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   24|  22.6k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   25|  22.6k|  const uint16_t input_utf8_end_of_code_point_mask =
   26|  22.6k|      utf8_end_of_code_point_mask & 0xfff;
   27|  22.6k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (27:7): [True: 92, False: 22.5k]
  ------------------
   28|       |    // We process the data in chunks of 12 bytes.
   29|       |    // Note: using 16 bytes is unsafe, see issue_ossfuzz_71218
   30|     92|    __m128i ascii_first = _mm_cvtepu8_epi16(in);
   31|     92|    __m128i ascii_second = _mm_cvtepu8_epi16(_mm_srli_si128(in, 8));
   32|     92|    if (big_endian) {
  ------------------
  |  Branch (32:9): [True: 92, Folded]
  ------------------
   33|     92|      ascii_first = _mm_shuffle_epi8(ascii_first, swap);
   34|     92|      ascii_second = _mm_shuffle_epi8(ascii_second, swap);
   35|     92|    }
   36|     92|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf16_output), ascii_first);
   37|     92|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf16_output + 8),
   38|     92|                     ascii_second);
   39|     92|    utf16_output += 12; // We wrote 12 16-bit characters.
   40|     92|    return 12;          // We consumed 12 bytes.
   41|     92|  }
   42|  22.5k|  if (((utf8_end_of_code_point_mask & 0xFFFF) == 0xaaaa)) {
  ------------------
  |  Branch (42:7): [True: 354, False: 22.1k]
  ------------------
   43|       |    // We want to take 8 2-byte UTF-8 code units and turn them into 8 2-byte
   44|       |    // UTF-16 code units. There is probably a more efficient sequence, but the
   45|       |    // following might do.
   46|    354|    const __m128i sh =
   47|    354|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   48|    354|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   49|    354|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   50|    354|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   51|    354|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   52|    354|    if (big_endian)
  ------------------
  |  Branch (52:9): [True: 354, Folded]
  ------------------
   53|    354|      composed = _mm_shuffle_epi8(composed, swap);
   54|    354|    _mm_storeu_si128((__m128i *)utf16_output, composed);
   55|    354|    utf16_output += 8; // We wrote 16 bytes, 8 code points.
   56|    354|    return 16;
   57|    354|  }
   58|  22.1k|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (58:7): [True: 6.47k, False: 15.6k]
  ------------------
   59|       |    // We want to take 4 3-byte UTF-8 code units and turn them into 4 2-byte
   60|       |    // UTF-16 code units. There is probably a more efficient sequence, but the
   61|       |    // following might do.
   62|  6.47k|    const __m128i sh =
   63|  6.47k|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   64|  6.47k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   65|  6.47k|    const __m128i ascii =
   66|  6.47k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   67|  6.47k|    const __m128i middlebyte =
   68|  6.47k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   69|  6.47k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   70|  6.47k|    const __m128i highbyte =
   71|  6.47k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   72|  6.47k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   73|  6.47k|    const __m128i composed =
   74|  6.47k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   75|  6.47k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
   76|  6.47k|    if (big_endian)
  ------------------
  |  Branch (76:9): [True: 6.47k, Folded]
  ------------------
   77|  6.47k|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
   78|  6.47k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
   79|  6.47k|    utf16_output += 4;
   80|  6.47k|    return 12;
   81|  6.47k|  }
   82|       |  /// We do not have a fast path available, so we fallback.
   83|       |
   84|  15.6k|  const uint8_t idx =
   85|  15.6k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   86|  15.6k|  const uint8_t consumed =
   87|  15.6k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   88|  15.6k|  if (idx < 64) {
  ------------------
  |  Branch (88:7): [True: 8.31k, False: 7.38k]
  ------------------
   89|       |    // SIX (6) input code-code units
   90|       |    // this is a relatively easy scenario
   91|       |    // we process SIX (6) input code-code units. The max length in bytes of six
   92|       |    // code code units spanning between 1 and 2 bytes each is 12 bytes. On
   93|       |    // processors where pdep/pext is fast, we might be able to use a small
   94|       |    // lookup table.
   95|  8.31k|    const __m128i sh =
   96|  8.31k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   97|  8.31k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   98|  8.31k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   99|  8.31k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
  100|  8.31k|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
  101|  8.31k|    if (big_endian)
  ------------------
  |  Branch (101:9): [True: 8.31k, Folded]
  ------------------
  102|  8.31k|      composed = _mm_shuffle_epi8(composed, swap);
  103|  8.31k|    _mm_storeu_si128((__m128i *)utf16_output, composed);
  104|  8.31k|    utf16_output += 6; // We wrote 12 bytes, 6 code points.
  105|  8.31k|  } else if (idx < 145) {
  ------------------
  |  Branch (105:14): [True: 2.27k, False: 5.11k]
  ------------------
  106|       |    // FOUR (4) input code-code units
  107|  2.27k|    const __m128i sh =
  108|  2.27k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  109|  2.27k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  110|  2.27k|    const __m128i ascii =
  111|  2.27k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
  112|  2.27k|    const __m128i middlebyte =
  113|  2.27k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  114|  2.27k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  115|  2.27k|    const __m128i highbyte =
  116|  2.27k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  117|  2.27k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  118|  2.27k|    const __m128i composed =
  119|  2.27k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  120|  2.27k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
  121|  2.27k|    if (big_endian)
  ------------------
  |  Branch (121:9): [True: 2.27k, Folded]
  ------------------
  122|  2.27k|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
  123|  2.27k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
  124|  2.27k|    utf16_output += 4;
  125|  5.11k|  } else if (idx < 209) {
  ------------------
  |  Branch (125:14): [True: 4.89k, False: 222]
  ------------------
  126|       |    // TWO (2) input code-code units
  127|       |    //////////////
  128|       |    // There might be garbage inputs where a leading byte mascarades as a
  129|       |    // four-byte leading byte (by being followed by 3 continuation byte), but is
  130|       |    // not greater than 0xf0. This could trigger a buffer overflow if we only
  131|       |    // counted leading bytes of the form 0xf0 as generating surrogate pairs,
  132|       |    // without further UTF-8 validation. Thus we must be careful to ensure that
  133|       |    // only leading bytes at least as large as 0xf0 generate surrogate pairs. We
  134|       |    // do as at the cost of an extra mask.
  135|       |    /////////////
  136|  4.89k|    const __m128i sh =
  137|  4.89k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  138|  4.89k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  139|  4.89k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  140|  4.89k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  141|  4.89k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  142|  4.89k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  143|       |    // correct for spurious high bit
  144|  4.89k|    const __m128i correct =
  145|  4.89k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  146|  4.89k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  147|  4.89k|    const __m128i middlehighbyte_shifted = _mm_srli_epi32(middlehighbyte, 4);
  148|       |    // We deliberately carry the leading four bits in highbyte if they are
  149|       |    // present, we remove them later when computing hightenbits.
  150|  4.89k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0xff000000));
  151|  4.89k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 6);
  152|       |    // When we need to generate a surrogate pair (leading byte > 0xF0), then
  153|       |    // the corresponding 32-bit value in 'composed'  will be greater than
  154|       |    // > (0xff00000>>6) or > 0x3c00000. This can be used later to identify the
  155|       |    // location of the surrogate pairs.
  156|  4.89k|    const __m128i composed =
  157|  4.89k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  158|  4.89k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  159|  4.89k|    const __m128i composedminus =
  160|  4.89k|        _mm_sub_epi32(composed, _mm_set1_epi32(0x10000));
  161|  4.89k|    const __m128i lowtenbits =
  162|  4.89k|        _mm_and_si128(composedminus, _mm_set1_epi32(0x3ff));
  163|       |    // Notice the 0x3ff mask:
  164|  4.89k|    const __m128i hightenbits =
  165|  4.89k|        _mm_and_si128(_mm_srli_epi32(composedminus, 10), _mm_set1_epi32(0x3ff));
  166|  4.89k|    const __m128i lowtenbitsadd =
  167|  4.89k|        _mm_add_epi32(lowtenbits, _mm_set1_epi32(0xDC00));
  168|  4.89k|    const __m128i hightenbitsadd =
  169|  4.89k|        _mm_add_epi32(hightenbits, _mm_set1_epi32(0xD800));
  170|  4.89k|    const __m128i lowtenbitsaddshifted = _mm_slli_epi32(lowtenbitsadd, 16);
  171|  4.89k|    __m128i surrogates = _mm_or_si128(hightenbitsadd, lowtenbitsaddshifted);
  172|  4.89k|    uint32_t basic_buffer[4];
  173|  4.89k|    uint32_t basic_buffer_swap[4];
  174|  4.89k|    if (big_endian) {
  ------------------
  |  Branch (174:9): [True: 4.89k, Folded]
  ------------------
  175|  4.89k|      _mm_storeu_si128((__m128i *)basic_buffer_swap,
  176|  4.89k|                       _mm_shuffle_epi8(composed, swap));
  177|  4.89k|      surrogates = _mm_shuffle_epi8(surrogates, swap);
  178|  4.89k|    }
  179|  4.89k|    _mm_storeu_si128((__m128i *)basic_buffer, composed);
  180|  4.89k|    uint32_t surrogate_buffer[4];
  181|  4.89k|    _mm_storeu_si128((__m128i *)surrogate_buffer, surrogates);
  182|  19.5k|    for (size_t i = 0; i < 3; i++) {
  ------------------
  |  Branch (182:24): [True: 14.6k, False: 4.89k]
  ------------------
  183|  14.6k|      if (basic_buffer[i] > 0x3c00000) {
  ------------------
  |  Branch (183:11): [True: 3.14k, False: 11.5k]
  ------------------
  184|  3.14k|        utf16_output[0] = uint16_t(surrogate_buffer[i] & 0xffff);
  185|  3.14k|        utf16_output[1] = uint16_t(surrogate_buffer[i] >> 16);
  186|  3.14k|        utf16_output += 2;
  187|  11.5k|      } else {
  188|  11.5k|        utf16_output[0] = big_endian ? uint16_t(basic_buffer_swap[i])
  ------------------
  |  Branch (188:27): [True: 11.5k, Folded]
  ------------------
  189|  11.5k|                                     : uint16_t(basic_buffer[i]);
  190|  11.5k|        utf16_output++;
  191|  11.5k|      }
  192|  14.6k|    }
  193|  4.89k|  } else {
  194|       |    // here we know that there is an error but we do not handle errors
  195|    222|  }
  196|  15.6k|  return consumed;
  197|  22.1k|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_128convert_masked_utf8_to_utf32EPKcmRPDi:
    9|  14.9k|                                    char32_t *&utf32_output) {
   10|       |  // we use an approach where we try to process up to 12 input bytes.
   11|       |  // Why 12 input bytes and not 16? Because we are concerned with the size of
   12|       |  // the lookup tables. Also 12 is nicely divisible by two and three.
   13|       |  //
   14|       |  //
   15|       |  // Optimization note: our main path below is load-latency dependent. Thus it
   16|       |  // is maybe beneficial to have fast paths that depend on branch prediction but
   17|       |  // have less latency. This results in more instructions but, potentially, also
   18|       |  // higher speeds.
   19|       |  //
   20|       |  // We first try a few fast paths.
   21|  14.9k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   22|  14.9k|  const uint16_t input_utf8_end_of_code_point_mask =
   23|  14.9k|      utf8_end_of_code_point_mask & 0xfff;
   24|  14.9k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (24:7): [True: 92, False: 14.8k]
  ------------------
   25|       |    // We process the data in chunks of 12 bytes.
   26|     92|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output),
   27|     92|                     _mm_cvtepu8_epi32(in));
   28|     92|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 4),
   29|     92|                     _mm_cvtepu8_epi32(_mm_srli_si128(in, 4)));
   30|     92|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 8),
   31|     92|                     _mm_cvtepu8_epi32(_mm_srli_si128(in, 8)));
   32|     92|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 12),
   33|     92|                     _mm_cvtepu8_epi32(_mm_srli_si128(in, 12)));
   34|     92|    utf32_output += 12; // We wrote 12 32-bit characters.
   35|     92|    return 12;          // We consumed 12 bytes.
   36|     92|  }
   37|  14.8k|  if (((utf8_end_of_code_point_mask & 0xffff) == 0xaaaa)) {
  ------------------
  |  Branch (37:7): [True: 131, False: 14.7k]
  ------------------
   38|       |    // We want to take 8 2-byte UTF-8 code units and turn them into 8 4-byte
   39|       |    // UTF-32 code units. There is probably a more efficient sequence, but the
   40|       |    // following might do.
   41|    131|    const __m128i sh =
   42|    131|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   43|    131|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   44|    131|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   45|    131|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   46|    131|    const __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   47|    131|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output),
   48|    131|                     _mm_cvtepu16_epi32(composed));
   49|    131|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 4),
   50|    131|                     _mm_cvtepu16_epi32(_mm_srli_si128(composed, 8)));
   51|    131|    utf32_output += 8; // We wrote 32 bytes, 8 code points.
   52|    131|    return 16;
   53|    131|  }
   54|  14.7k|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (54:7): [True: 461, False: 14.2k]
  ------------------
   55|       |    // We want to take 4 3-byte UTF-8 code units and turn them into 4 4-byte
   56|       |    // UTF-32 code units. There is probably a more efficient sequence, but the
   57|       |    // following might do.
   58|    461|    const __m128i sh =
   59|    461|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   60|    461|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   61|    461|    const __m128i ascii =
   62|    461|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   63|    461|    const __m128i middlebyte =
   64|    461|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   65|    461|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   66|    461|    const __m128i highbyte =
   67|    461|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   68|    461|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   69|    461|    const __m128i composed =
   70|    461|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   71|    461|    _mm_storeu_si128((__m128i *)utf32_output, composed);
   72|    461|    utf32_output += 4;
   73|    461|    return 12;
   74|    461|  }
   75|       |  /// We do not have a fast path available, so we fallback.
   76|       |
   77|  14.2k|  const uint8_t idx =
   78|  14.2k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   79|  14.2k|  const uint8_t consumed =
   80|  14.2k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   81|  14.2k|  if (idx < 64) {
  ------------------
  |  Branch (81:7): [True: 8.04k, False: 6.20k]
  ------------------
   82|       |    // SIX (6) input code-code units
   83|       |    // this is a relatively easy scenario
   84|       |    // we process SIX (6) input code-code units. The max length in bytes of six
   85|       |    // code code units spanning between 1 and 2 bytes each is 12 bytes. On
   86|       |    // processors where pdep/pext is fast, we might be able to use a small
   87|       |    // lookup table.
   88|  8.04k|    const __m128i sh =
   89|  8.04k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   90|  8.04k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   91|  8.04k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   92|  8.04k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   93|  8.04k|    const __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   94|  8.04k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output),
   95|  8.04k|                     _mm_cvtepu16_epi32(composed));
   96|  8.04k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 4),
   97|  8.04k|                     _mm_cvtepu16_epi32(_mm_srli_si128(composed, 8)));
   98|  8.04k|    utf32_output += 6; // We wrote 12 bytes, 6 code points.
   99|  8.04k|  } else if (idx < 145) {
  ------------------
  |  Branch (99:14): [True: 1.53k, False: 4.67k]
  ------------------
  100|       |    // FOUR (4) input code-code units
  101|  1.53k|    const __m128i sh =
  102|  1.53k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  103|  1.53k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  104|  1.53k|    const __m128i ascii =
  105|  1.53k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
  106|  1.53k|    const __m128i middlebyte =
  107|  1.53k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  108|  1.53k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  109|  1.53k|    const __m128i highbyte =
  110|  1.53k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  111|  1.53k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  112|  1.53k|    const __m128i composed =
  113|  1.53k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  114|  1.53k|    _mm_storeu_si128((__m128i *)utf32_output, composed);
  115|  1.53k|    utf32_output += 4;
  116|  4.67k|  } else if (idx < 209) {
  ------------------
  |  Branch (116:14): [True: 4.45k, False: 222]
  ------------------
  117|       |    // TWO (2) input code-code units
  118|  4.45k|    const __m128i sh =
  119|  4.45k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  120|  4.45k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  121|  4.45k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  122|  4.45k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  123|  4.45k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  124|  4.45k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  125|       |    // correct for spurious high bit
  126|  4.45k|    const __m128i correct =
  127|  4.45k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  128|  4.45k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  129|  4.45k|    const __m128i middlehighbyte_shifted = _mm_srli_epi32(middlehighbyte, 4);
  130|  4.45k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0x07000000));
  131|  4.45k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 6);
  132|  4.45k|    const __m128i composed =
  133|  4.45k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  134|  4.45k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  135|  4.45k|    _mm_storeu_si128((__m128i *)utf32_output, composed);
  136|  4.45k|    utf32_output += 3;
  137|  4.45k|  } else {
  138|       |    // here we know that there is an error but we do not handle errors
  139|    222|  }
  140|  14.2k|  return consumed;
  141|  14.7k|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_123utf16_gather_high_bytesILNS_10endiannessE0EEENS1_4simd5simd8IhEENS4_6simd16ItEES8_:
    3|  18.4k|                                       const simd16<uint16_t> in1) {
    4|  18.4k|  if (big_endian) {
  ------------------
  |  Branch (4:7): [Folded, False: 18.4k]
  ------------------
    5|       |    // we want lower bytes
    6|      0|    const auto mask = simd16<uint16_t>(0x00ff);
    7|      0|    const auto t0 = in0 & mask;
    8|      0|    const auto t1 = in1 & mask;
    9|       |
   10|      0|    return simd16<uint16_t>::pack(t0, t1);
   11|  18.4k|  } else {
   12|  18.4k|    const auto t0 = in0.shr<8>();
   13|  18.4k|    const auto t1 = in1.shr<8>();
   14|       |
   15|  18.4k|    return simd16<uint16_t>::pack(t0, t1);
   16|  18.4k|  }
   17|  18.4k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_123utf16_gather_high_bytesILNS_10endiannessE1EEENS1_4simd5simd8IhEENS4_6simd16ItEES8_:
    3|  18.5k|                                       const simd16<uint16_t> in1) {
    4|  18.5k|  if (big_endian) {
  ------------------
  |  Branch (4:7): [True: 18.5k, Folded]
  ------------------
    5|       |    // we want lower bytes
    6|  18.5k|    const auto mask = simd16<uint16_t>(0x00ff);
    7|  18.5k|    const auto t0 = in0 & mask;
    8|  18.5k|    const auto t1 = in1 & mask;
    9|       |
   10|  18.5k|    return simd16<uint16_t>::pack(t0, t1);
   11|  18.5k|  } else {
   12|      0|    const auto t0 = in0.shr<8>();
   13|      0|    const auto t1 = in1.shr<8>();
   14|       |
   15|      0|    return simd16<uint16_t>::pack(t0, t1);
   16|      0|  }
   17|  18.5k|}

