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

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

_ZN7simdutf10is_partialENS_27last_chunk_handling_optionsE:
 4136|  19.2k|is_partial(last_chunk_handling_options options) {
 4137|  19.2k|  return (options == stop_before_partial) || (options == only_full_chunks);
  ------------------
  |  Branch (4137:10): [True: 0, False: 19.2k]
  |  Branch (4137:46): [True: 3.55k, False: 15.6k]
  ------------------
 4138|  19.2k|}
_ZNK7simdutf14implementation25required_instruction_setsEv:
 5157|  21.0k|  virtual uint32_t required_instruction_sets() const {
 5158|  21.0k|    return _required_instruction_sets;
 5159|  21.0k|  }
_ZNK7simdutf14implementation24utf16_length_from_latin1Em:
 6347|  31.6k|  utf16_length_from_latin1(size_t length) const noexcept {
 6348|  31.6k|    return length;
 6349|  31.6k|  }
_ZNK7simdutf14implementation24latin1_length_from_utf32Em:
 6535|  15.8k|  latin1_length_from_utf32(size_t length) const noexcept {
 6536|  15.8k|    return length;
 6537|  15.8k|  }
_ZNK7simdutf14implementation24latin1_length_from_utf16Em:
 6572|  31.6k|  latin1_length_from_utf16(size_t length) const noexcept {
 6573|  31.6k|    return length;
 6574|  31.6k|  }
_ZNK7simdutf14implementation24utf32_length_from_latin1Em:
 6605|  15.8k|  utf32_length_from_latin1(size_t length) const noexcept {
 6606|  15.8k|    return length;
 6607|  15.8k|  }
_ZN7simdutf14implementationC2EPKcS2_j:
 7043|      5|      : _name(name), _description(description),
 7044|      5|        _required_instruction_sets(required_instruction_sets) {}
_ZN7simdutf8internal29available_implementation_listC2Ev:
 7075|      1|  simdutf_really_inline available_implementation_list() {}
_ZN7simdutf25base64_length_from_binaryEmNS_14base64_optionsE:
 4447|  46.0k|    size_t length, base64_options options = base64_default) noexcept {
 4448|  46.0k|  return scalar::base64::base64_length_from_binary(length, options);
 4449|  46.0k|}
_ZN7simdutf16base64_ignorableEcNS_14base64_optionsE:
 4862|  4.02k|base64_ignorable(char input, base64_options options = base64_default) noexcept {
 4863|  4.02k|  return scalar::base64::is_ignorable(input, options);
 4864|  4.02k|}
simdutf.cpp:_ZN7simdutf6detail12_GLOBAL__N_13minEmm:
   59|  46.0k|constexpr std::size_t min(std::size_t a, std::size_t b) {
   60|  46.0k|  return a < b ? a : b;
  ------------------
  |  Branch (60:10): [True: 0, False: 46.0k]
  ------------------
   61|  46.0k|}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEaSEPS3_:
 7146|      1|  atomic_ptr &operator=(T *_ptr) {
 7147|      1|    ptr = _ptr;
 7148|      1|    return *this;
 7149|      1|  }
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEcvPS3_Ev:
 7143|      1|  operator T *() { return ptr.load(); }
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEC2EPS3_:
 7123|      1|  atomic_ptr(T *_ptr) : ptr{_ptr} {}
_ZN7simdutf8internal10atomic_ptrIKNS_14implementationEEptEv:
 7145|  46.0k|  T *operator->() { return ptr.load(); }

simdutf.cpp:_ZN7simdutf8internalL30detect_supported_architecturesEv:
  236|  21.0k|static inline uint32_t detect_supported_architectures() {
  237|  21.0k|  uint32_t eax;
  238|  21.0k|  uint32_t ebx = 0;
  239|  21.0k|  uint32_t ecx = 0;
  240|  21.0k|  uint32_t edx = 0;
  241|  21.0k|  uint32_t host_isa = 0x0;
  242|       |
  243|       |  // EBX for EAX=0x1
  244|  21.0k|  eax = 0x1;
  245|  21.0k|  cpuid(&eax, &ebx, &ecx, &edx);
  246|       |
  247|  21.0k|  if (ecx & cpuid_bit::sse42) {
  ------------------
  |  Branch (247:7): [True: 21.0k, False: 0]
  ------------------
  248|  21.0k|    host_isa |= instruction_set::SSE42;
  249|  21.0k|  }
  250|       |
  251|  21.0k|  if (ecx & cpuid_bit::pclmulqdq) {
  ------------------
  |  Branch (251:7): [True: 21.0k, False: 0]
  ------------------
  252|  21.0k|    host_isa |= instruction_set::PCLMULQDQ;
  253|  21.0k|  }
  254|       |
  255|  21.0k|  if ((ecx & cpuid_bit::osxsave) != cpuid_bit::osxsave) {
  ------------------
  |  Branch (255:7): [True: 0, False: 21.0k]
  ------------------
  256|      0|    return host_isa;
  257|      0|  }
  258|       |
  259|       |  // xgetbv for checking if the OS saves registers
  260|  21.0k|  uint64_t xcr0 = xgetbv();
  261|       |
  262|  21.0k|  if ((xcr0 & cpuid_bit::xcr0_bit::avx256_saved) == 0) {
  ------------------
  |  Branch (262:7): [True: 0, False: 21.0k]
  ------------------
  263|      0|    return host_isa;
  264|      0|  }
  265|       |  // ECX for EAX=0x7
  266|  21.0k|  eax = 0x7;
  267|  21.0k|  ecx = 0x0; // Sub-leaf = 0
  268|  21.0k|  cpuid(&eax, &ebx, &ecx, &edx);
  269|  21.0k|  if (ebx & cpuid_bit::ebx::avx2) {
  ------------------
  |  Branch (269:7): [True: 21.0k, False: 0]
  ------------------
  270|  21.0k|    host_isa |= instruction_set::AVX2;
  271|  21.0k|  }
  272|  21.0k|  if (ebx & cpuid_bit::ebx::bmi1) {
  ------------------
  |  Branch (272:7): [True: 21.0k, False: 0]
  ------------------
  273|  21.0k|    host_isa |= instruction_set::BMI1;
  274|  21.0k|  }
  275|  21.0k|  if (ebx & cpuid_bit::ebx::bmi2) {
  ------------------
  |  Branch (275:7): [True: 21.0k, False: 0]
  ------------------
  276|  21.0k|    host_isa |= instruction_set::BMI2;
  277|  21.0k|  }
  278|  21.0k|  if (!((xcr0 & cpuid_bit::xcr0_bit::avx512_saved) ==
  ------------------
  |  Branch (278:7): [True: 21.0k, False: 0]
  ------------------
  279|  21.0k|        cpuid_bit::xcr0_bit::avx512_saved)) {
  280|  21.0k|    return host_isa;
  281|  21.0k|  }
  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|  21.0k|}
simdutf.cpp:_ZN7simdutf8internalL5cpuidEPjS1_S1_S1_:
  202|  42.1k|                         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|  42.1k|  uint32_t a = *eax, b, c = *ecx, d;
  216|  42.1k|  asm volatile("cpuid\n\t" : "+a"(a), "=b"(b), "+c"(c), "=d"(d));
  217|  42.1k|  *eax = a;
  218|  42.1k|  *ebx = b;
  219|  42.1k|  *ecx = c;
  220|  42.1k|  *edx = d;
  221|  42.1k|  #endif
  222|  42.1k|}
simdutf.cpp:_ZN7simdutf8internalL6xgetbvEv:
  224|  21.0k|static inline uint64_t xgetbv() {
  225|       |  #if defined(_MSC_VER)
  226|       |  return _xgetbv(0);
  227|       |  #elif defined(__FILC__)
  228|       |  return zxgetbv();
  229|       |  #else
  230|  21.0k|  uint32_t xcr0_lo, xcr0_hi;
  231|  21.0k|  asm volatile("xgetbv\n\t" : "=a"(xcr0_lo), "=d"(xcr0_hi) : "c"(0));
  232|  21.0k|  return xcr0_lo | ((uint64_t)xcr0_hi << 32);
  233|  21.0k|  #endif
  234|  21.0k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6425base64_length_from_binaryEmNS_14base64_optionsE:
  836|  90.6k|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|  90.6k|  bool use_padding =
  846|  90.6k|      ((options & base64_url) == 0) ^
  847|  90.6k|      ((options & base64_reverse_padding) == base64_reverse_padding);
  848|  90.6k|  if (!use_padding) {
  ------------------
  |  Branch (848:7): [True: 0, False: 90.6k]
  ------------------
  849|      0|    return length / 3 * 4 + ((length % 3) ? (length % 3) + 1 : 0);
  ------------------
  |  Branch (849:30): [True: 0, False: 0]
  ------------------
  850|      0|  }
  851|  90.6k|  return (length + 2) / 3 *
  852|  90.6k|         4; // We use padding to make the length a multiple of 4.
  853|  90.6k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6418tail_encode_base64EPcPKcmNS_14base64_optionsE:
  648|  15.4k|    char *dst, const char *src, size_t srclen, base64_options options) {
  649|  15.4k|  return tail_encode_base64_impl(dst, src, srclen, options);
  650|  15.4k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6423tail_encode_base64_implILb0EEEmPcPKcmNS_14base64_optionsEmm:
  418|  44.6k|    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|  44.6k|  bool use_padding =
  437|  44.6k|      ((options & base64_url) == 0) ^
  438|  44.6k|      ((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|  44.6k|  const char *e0 = (options & base64_url) ? tables::base64::base64_url::e0
  ------------------
  |  Branch (441:20): [True: 0, False: 44.6k]
  ------------------
  442|  44.6k|                                          : tables::base64::base64_default::e0;
  443|  44.6k|  const char *e1 = (options & base64_url) ? tables::base64::base64_url::e1
  ------------------
  |  Branch (443:20): [True: 0, False: 44.6k]
  ------------------
  444|  44.6k|                                          : tables::base64::base64_default::e1;
  445|  44.6k|  const char *e2 = (options & base64_url) ? tables::base64::base64_url::e2
  ------------------
  |  Branch (445:20): [True: 0, False: 44.6k]
  ------------------
  446|  44.6k|                                          : tables::base64::base64_default::e2;
  447|  44.6k|  char *out = dst;
  448|  44.6k|  size_t i = 0;
  449|  44.6k|  uint8_t t1, t2, t3;
  450|  85.4k|  for (; i + 2 < srclen; i += 3) {
  ------------------
  |  Branch (450:10): [True: 40.7k, False: 44.6k]
  ------------------
  451|  40.7k|    t1 = uint8_t(src[i]);
  452|  40.7k|    t2 = uint8_t(src[i + 1]);
  453|  40.7k|    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|  40.7k|    } else {
  493|  40.7k|      *out++ = e0[t1];
  494|  40.7k|      *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  495|  40.7k|      *out++ = e1[((t2 & 0x0F) << 2) | ((t3 >> 6) & 0x03)];
  496|  40.7k|      *out++ = e2[t3];
  497|  40.7k|    }
  498|  40.7k|  }
  499|  44.6k|  switch (srclen - i) {
  500|  42.6k|  case 0:
  ------------------
  |  Branch (500:3): [True: 42.6k, False: 2.03k]
  ------------------
  501|  42.6k|    break;
  502|  1.27k|  case 1:
  ------------------
  |  Branch (502:3): [True: 1.27k, False: 43.3k]
  ------------------
  503|  1.27k|    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.27k|    } else {
  559|  1.27k|      *out++ = e0[t1];
  560|  1.27k|      *out++ = e1[(t1 & 0x03) << 4];
  561|  1.27k|      if (use_padding) {
  ------------------
  |  Branch (561:11): [True: 1.27k, False: 0]
  ------------------
  562|  1.27k|        *out++ = '=';
  563|  1.27k|        *out++ = '=';
  564|  1.27k|      }
  565|  1.27k|    }
  566|  1.27k|    break;
  567|    760|  default: /* case 2 */
  ------------------
  |  Branch (567:3): [True: 760, False: 43.8k]
  ------------------
  568|    760|    t1 = uint8_t(src[i]);
  569|    760|    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|    760|    } else {
  634|    760|      *out++ = e0[t1];
  635|    760|      *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
  636|    760|      *out++ = e2[(t2 & 0x0F) << 2];
  637|    760|      if (use_padding) {
  ------------------
  |  Branch (637:11): [True: 760, False: 0]
  ------------------
  638|    760|        *out++ = '=';
  639|    760|      }
  640|    760|    }
  641|  44.6k|  }
  642|  44.6k|  return (size_t)(out - dst);
  643|  44.6k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6413is_eight_byteIcEEbT_:
   19|   321k|template <class char_type> simdutf_constexpr23 bool is_eight_byte(char_type c) {
   20|   321k|  if constexpr (sizeof(char_type) == 1) {
   21|   321k|    return true;
   22|   321k|  }
   23|      0|  return uint8_t(c) == c;
   24|   321k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6433maximal_binary_length_from_base64IPKcEEmT_m:
  654|  76.2k|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|  76.2k|  size_t padding = 0;
  659|  76.2k|  if (length > 0) {
  ------------------
  |  Branch (659:7): [True: 7.30k, False: 68.9k]
  ------------------
  660|  7.30k|    if (input[length - 1] == '=') {
  ------------------
  |  Branch (660:9): [True: 2.22k, False: 5.08k]
  ------------------
  661|  2.22k|      padding++;
  662|  2.22k|      if (length > 1 && input[length - 2] == '=') {
  ------------------
  |  Branch (662:11): [True: 2.19k, False: 32]
  |  Branch (662:25): [True: 1.32k, False: 864]
  ------------------
  663|  1.32k|        padding++;
  664|  1.32k|      }
  665|  2.22k|    }
  666|  7.30k|  }
  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|  76.2k|  size_t actual_length = length - padding;
  686|  76.2k|  if (actual_length % 4 <= 1) {
  ------------------
  |  Branch (686:7): [True: 73.2k, False: 2.98k]
  ------------------
  687|  73.2k|    return actual_length / 4 * 3;
  688|  73.2k|  }
  689|       |  // if we have a valid input, then the remainder must be 2 or 3 adding one or
  690|       |  // two extra bytes.
  691|  2.98k|  return actual_length / 4 * 3 + (actual_length % 4) - 1;
  692|  76.2k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6412is_ignorableIcEEbT_NS_14base64_optionsE:
   28|  4.02k|                                      simdutf::base64_options options) {
   29|  4.02k|  const uint8_t *to_base64 =
   30|  4.02k|      (options & base64_default_or_url)
  ------------------
  |  Branch (30:7): [True: 0, False: 4.02k]
  ------------------
   31|  4.02k|          ? tables::base64::to_base64_default_or_url_value
   32|  4.02k|          : ((options & base64_url) ? tables::base64::to_base64_url_value
  ------------------
  |  Branch (32:14): [True: 0, False: 4.02k]
  ------------------
   33|  4.02k|                                    : tables::base64::to_base64_value);
   34|  4.02k|  const bool ignore_garbage =
   35|  4.02k|      (options == base64_options::base64_url_accept_garbage) ||
  ------------------
  |  Branch (35:7): [True: 0, False: 4.02k]
  ------------------
   36|  4.02k|      (options == base64_options::base64_default_accept_garbage) ||
  ------------------
  |  Branch (36:7): [True: 0, False: 4.02k]
  ------------------
   37|  4.02k|      (options == base64_options::base64_default_or_url_accept_garbage);
  ------------------
  |  Branch (37:7): [True: 0, False: 4.02k]
  ------------------
   38|  4.02k|  uint8_t code = to_base64[uint8_t(c)];
   39|  4.02k|  if (is_eight_byte(c) && code <= 63) {
  ------------------
  |  Branch (39:7): [True: 4.02k, False: 0]
  |  Branch (39:27): [True: 469, False: 3.55k]
  ------------------
   40|    469|    return false;
   41|    469|  }
   42|  3.55k|  if (is_eight_byte(c) && code == 64) {
  ------------------
  |  Branch (42:7): [True: 3.55k, False: 0]
  |  Branch (42:27): [True: 3.55k, False: 0]
  ------------------
   43|  3.55k|    return true;
   44|  3.55k|  }
   45|      0|  return ignore_garbage;
   46|  3.55k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base648find_endIcEENS2_13reduced_inputEPKT_mNS_14base64_optionsE:
  100|  94.3k|                                           simdutf::base64_options options) {
  101|  94.3k|  const uint8_t *to_base64 =
  102|  94.3k|      (options & base64_default_or_url)
  ------------------
  |  Branch (102:7): [True: 0, False: 94.3k]
  ------------------
  103|  94.3k|          ? tables::base64::to_base64_default_or_url_value
  104|  94.3k|          : ((options & base64_url) ? tables::base64::to_base64_url_value
  ------------------
  |  Branch (104:14): [True: 0, False: 94.3k]
  ------------------
  105|  94.3k|                                    : tables::base64::to_base64_value);
  106|  94.3k|  const bool ignore_garbage =
  107|  94.3k|      (options == base64_options::base64_url_accept_garbage) ||
  ------------------
  |  Branch (107:7): [True: 0, False: 94.3k]
  ------------------
  108|  94.3k|      (options == base64_options::base64_default_accept_garbage) ||
  ------------------
  |  Branch (108:7): [True: 0, False: 94.3k]
  ------------------
  109|  94.3k|      (options == base64_options::base64_default_or_url_accept_garbage);
  ------------------
  |  Branch (109:7): [True: 0, False: 94.3k]
  ------------------
  110|       |
  111|  94.3k|  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|  94.3k|  size_t full_input_length = srclen;
  115|       |  // skip trailing spaces
  116|   103k|  while (!ignore_garbage && srclen > 0 &&
  ------------------
  |  Branch (116:10): [True: 103k, False: 0]
  |  Branch (116:29): [True: 19.3k, False: 83.7k]
  ------------------
  117|  19.3k|         scalar::base64::is_eight_byte(src[srclen - 1]) &&
  ------------------
  |  Branch (117:10): [True: 19.3k, False: 0]
  ------------------
  118|  19.3k|         to_base64[uint8_t(src[srclen - 1])] == 64) {
  ------------------
  |  Branch (118:10): [True: 8.69k, False: 10.6k]
  ------------------
  119|  8.69k|    srclen--;
  120|  8.69k|  }
  121|  94.3k|  size_t equallocation =
  122|  94.3k|      srclen; // location of the first padding character if any
  123|  94.3k|  if (ignore_garbage) {
  ------------------
  |  Branch (123:7): [True: 0, False: 94.3k]
  ------------------
  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|  94.3k|  if (!ignore_garbage && srclen > 0 && src[srclen - 1] == '=') {
  ------------------
  |  Branch (135:7): [True: 94.3k, False: 0]
  |  Branch (135:26): [True: 10.6k, False: 83.7k]
  |  Branch (135:40): [True: 3.58k, False: 7.04k]
  ------------------
  136|       |    // This is the last '=' sign.
  137|  3.58k|    equallocation = srclen - 1;
  138|  3.58k|    srclen--;
  139|  3.58k|    equalsigns = 1;
  140|       |    // skip trailing spaces
  141|  4.02k|    while (srclen > 0 && scalar::base64::is_eight_byte(src[srclen - 1]) &&
  ------------------
  |  Branch (141:12): [True: 3.97k, False: 51]
  |  Branch (141:26): [True: 3.97k, False: 0]
  ------------------
  142|  3.97k|           to_base64[uint8_t(src[srclen - 1])] == 64) {
  ------------------
  |  Branch (142:12): [True: 441, False: 3.53k]
  ------------------
  143|    441|      srclen--;
  144|    441|    }
  145|  3.58k|    if (srclen > 0 && src[srclen - 1] == '=') {
  ------------------
  |  Branch (145:9): [True: 3.53k, False: 51]
  |  Branch (145:23): [True: 2.23k, False: 1.30k]
  ------------------
  146|       |      // This is the second '=' sign.
  147|  2.23k|      equallocation = srclen - 1;
  148|  2.23k|      srclen--;
  149|  2.23k|      equalsigns = 2;
  150|  2.23k|    }
  151|  3.58k|  }
  152|  94.3k|  return {equalsigns, equallocation, srclen, full_input_length};
  153|  94.3k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6423base64_tail_decode_safeIcEENS_11full_resultEPcmPKT_mmNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  385|  2.23k|    base64_options options, last_chunk_handling_options last_chunk_options) {
  386|  2.23k|  return base64_tail_decode_impl<true>(dst, outlen, src, length,
  387|  2.23k|                                       padding_characters, options,
  388|  2.23k|                                       last_chunk_options);
  389|  2.23k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6423base64_tail_decode_implILb1EcEENS_11full_resultEPcmPKT0_mmNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  164|  2.23k|    base64_options options, last_chunk_handling_options last_chunk_options) {
  165|  2.23k|  char *dstend = dst + outlen;
  166|  2.23k|  (void)dstend;
  167|       |  // This looks like 10 branches, but we expect the compiler to resolve this to
  168|       |  // two branches (easily predicted):
  169|  2.23k|  const uint8_t *to_base64 =
  170|  2.23k|      (options & base64_default_or_url)
  ------------------
  |  Branch (170:7): [True: 0, False: 2.23k]
  ------------------
  171|  2.23k|          ? tables::base64::to_base64_default_or_url_value
  172|  2.23k|          : ((options & base64_url) ? tables::base64::to_base64_url_value
  ------------------
  |  Branch (172:14): [True: 0, False: 2.23k]
  ------------------
  173|  2.23k|                                    : tables::base64::to_base64_value);
  174|  2.23k|  const uint32_t *d0 =
  175|  2.23k|      (options & base64_default_or_url)
  ------------------
  |  Branch (175:7): [True: 0, False: 2.23k]
  ------------------
  176|  2.23k|          ? tables::base64::base64_default_or_url::d0
  177|  2.23k|          : ((options & base64_url) ? tables::base64::base64_url::d0
  ------------------
  |  Branch (177:14): [True: 0, False: 2.23k]
  ------------------
  178|  2.23k|                                    : tables::base64::base64_default::d0);
  179|  2.23k|  const uint32_t *d1 =
  180|  2.23k|      (options & base64_default_or_url)
  ------------------
  |  Branch (180:7): [True: 0, False: 2.23k]
  ------------------
  181|  2.23k|          ? tables::base64::base64_default_or_url::d1
  182|  2.23k|          : ((options & base64_url) ? tables::base64::base64_url::d1
  ------------------
  |  Branch (182:14): [True: 0, False: 2.23k]
  ------------------
  183|  2.23k|                                    : tables::base64::base64_default::d1);
  184|  2.23k|  const uint32_t *d2 =
  185|  2.23k|      (options & base64_default_or_url)
  ------------------
  |  Branch (185:7): [True: 0, False: 2.23k]
  ------------------
  186|  2.23k|          ? tables::base64::base64_default_or_url::d2
  187|  2.23k|          : ((options & base64_url) ? tables::base64::base64_url::d2
  ------------------
  |  Branch (187:14): [True: 0, False: 2.23k]
  ------------------
  188|  2.23k|                                    : tables::base64::base64_default::d2);
  189|  2.23k|  const uint32_t *d3 =
  190|  2.23k|      (options & base64_default_or_url)
  ------------------
  |  Branch (190:7): [True: 0, False: 2.23k]
  ------------------
  191|  2.23k|          ? tables::base64::base64_default_or_url::d3
  192|  2.23k|          : ((options & base64_url) ? tables::base64::base64_url::d3
  ------------------
  |  Branch (192:14): [True: 0, False: 2.23k]
  ------------------
  193|  2.23k|                                    : tables::base64::base64_default::d3);
  194|  2.23k|  const bool ignore_garbage =
  195|  2.23k|      (options == base64_options::base64_url_accept_garbage) ||
  ------------------
  |  Branch (195:7): [True: 0, False: 2.23k]
  ------------------
  196|  2.23k|      (options == base64_options::base64_default_accept_garbage) ||
  ------------------
  |  Branch (196:7): [True: 0, False: 2.23k]
  ------------------
  197|  2.23k|      (options == base64_options::base64_default_or_url_accept_garbage);
  ------------------
  |  Branch (197:7): [True: 0, False: 2.23k]
  ------------------
  198|       |
  199|  2.23k|  const char_type *srcend = src + length;
  200|  2.23k|  const char_type *srcinit = src;
  201|  2.23k|  const char *dstinit = dst;
  202|       |
  203|  2.23k|  uint32_t x;
  204|  2.23k|  size_t idx;
  205|  2.23k|  uint8_t buffer[4];
  206|  2.27k|  while (true) {
  ------------------
  |  Branch (206:10): [True: 2.27k, Folded]
  ------------------
  207|  2.34k|    while (srcend - src >= 4 && is_eight_byte(src[0]) &&
  ------------------
  |  Branch (207:12): [True: 249, False: 2.09k]
  |  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: 69, False: 180]
  ------------------
  211|    249|                d2[uint8_t(src[2])] | d3[uint8_t(src[3])]) < 0x01FFFFFF) {
  212|     69|      if (check_capacity && dstend - dst < 3) {
  ------------------
  |  Branch (212:11): [True: 69, Folded]
  |  Branch (212:29): [True: 0, False: 69]
  ------------------
  213|      0|        return {OUTPUT_BUFFER_TOO_SMALL, size_t(src - srcinit),
  214|      0|                size_t(dst - dstinit)};
  215|      0|      }
  216|     69|      *dst++ = static_cast<char>(x & 0xFF);
  217|     69|      *dst++ = static_cast<char>((x >> 8) & 0xFF);
  218|     69|      *dst++ = static_cast<char>((x >> 16) & 0xFF);
  219|     69|      src += 4;
  220|     69|    }
  221|  2.27k|    const char_type *srccur = src;
  222|  2.27k|    idx = 0;
  223|       |    // we need at least four characters.
  224|  2.27k|#ifdef __clang__
  225|       |    // If possible, we read four characters at a time. (It is an optimization.)
  226|  2.27k|    if (ignore_garbage && src + 4 <= srcend) {
  ------------------
  |  Branch (226:9): [True: 0, False: 2.27k]
  |  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.27k|#endif
  248|  12.9k|    while ((idx < 4) && (src < srcend)) {
  ------------------
  |  Branch (248:12): [True: 12.9k, False: 38]
  |  Branch (248:25): [True: 10.8k, False: 2.05k]
  ------------------
  249|  10.8k|      char_type c = *src;
  250|       |
  251|  10.8k|      uint8_t code = to_base64[uint8_t(c)];
  252|  10.8k|      buffer[idx] = uint8_t(code);
  253|  10.8k|      if (is_eight_byte(c) && code <= 63) {
  ------------------
  |  Branch (253:11): [True: 10.8k, False: 0]
  |  Branch (253:31): [True: 4.76k, False: 6.12k]
  ------------------
  254|  4.76k|        idx++;
  255|  6.12k|      } else if (!ignore_garbage &&
  ------------------
  |  Branch (255:18): [True: 6.12k, False: 0]
  ------------------
  256|  6.12k|                 (code > 64 || !scalar::base64::is_eight_byte(c))) {
  ------------------
  |  Branch (256:19): [True: 175, False: 5.94k]
  |  Branch (256:32): [True: 0, False: 5.94k]
  ------------------
  257|    175|        return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  258|    175|                size_t(dst - dstinit)};
  259|  5.94k|      } else {
  260|       |        // We have a space or a newline or garbage. We ignore it.
  261|  5.94k|      }
  262|  10.7k|      src++;
  263|  10.7k|    }
  264|  2.09k|    if (idx != 4) {
  ------------------
  |  Branch (264:9): [True: 2.05k, False: 38]
  ------------------
  265|  2.05k|      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.05k|      if (!ignore_garbage && (idx + padding_characters > 4)) {
  ------------------
  |  Branch (268:11): [True: 2.05k, False: 0]
  |  Branch (268:30): [True: 7, False: 2.05k]
  ------------------
  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.05k|      if (!ignore_garbage &&
  ------------------
  |  Branch (277:11): [True: 2.05k, False: 0]
  ------------------
  278|  2.05k|          last_chunk_options == last_chunk_handling_options::loose &&
  ------------------
  |  Branch (278:11): [True: 2.05k, False: 0]
  ------------------
  279|  2.05k|          (idx >= 2) && padding_characters > 0 &&
  ------------------
  |  Branch (279:11): [True: 1.87k, False: 179]
  |  Branch (279:25): [True: 1.69k, False: 181]
  ------------------
  280|  1.69k|          ((idx + padding_characters) & 3) != 0) {
  ------------------
  |  Branch (280:11): [True: 13, False: 1.67k]
  ------------------
  281|     13|        return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  282|     13|                size_t(dst - dstinit), true};
  283|     13|      } 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.03k|        if (!ignore_garbage &&
  ------------------
  |  Branch (288:13): [True: 2.03k, False: 0]
  ------------------
  289|  2.03k|            last_chunk_options == last_chunk_handling_options::strict &&
  ------------------
  |  Branch (289:13): [True: 0, False: 2.03k]
  ------------------
  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.03k|          if ((last_chunk_options ==
  ------------------
  |  Branch (298:16): [True: 0, False: 2.03k]
  ------------------
  299|  2.03k|                   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.03k|              (last_chunk_options ==
  ------------------
  |  Branch (302:16): [True: 0, False: 2.03k]
  ------------------
  303|  2.03k|                   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.03k|          } else {
  310|  2.03k|            if (idx == 2) {
  ------------------
  |  Branch (310:17): [True: 1.20k, False: 834]
  ------------------
  311|  1.20k|              uint32_t triple = (uint32_t(buffer[0]) << 3 * 6) +
  312|  1.20k|                                (uint32_t(buffer[1]) << 2 * 6);
  313|  1.20k|              if (!ignore_garbage &&
  ------------------
  |  Branch (313:19): [True: 1.20k, False: 0]
  ------------------
  314|  1.20k|                  (last_chunk_options == last_chunk_handling_options::strict) &&
  ------------------
  |  Branch (314:19): [True: 0, False: 1.20k]
  ------------------
  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.20k|              if (check_capacity && dstend - dst < 1) {
  ------------------
  |  Branch (319:19): [True: 1.20k, Folded]
  |  Branch (319:37): [True: 0, False: 1.20k]
  ------------------
  320|      0|                return {OUTPUT_BUFFER_TOO_SMALL, size_t(srccur - srcinit),
  321|      0|                        size_t(dst - dstinit)};
  322|      0|              }
  323|  1.20k|              *dst++ = static_cast<char>((triple >> 16) & 0xFF);
  324|  1.20k|            } else if (idx == 3) {
  ------------------
  |  Branch (324:24): [True: 655, False: 179]
  ------------------
  325|    655|              uint32_t triple = (uint32_t(buffer[0]) << 3 * 6) +
  326|    655|                                (uint32_t(buffer[1]) << 2 * 6) +
  327|    655|                                (uint32_t(buffer[2]) << 1 * 6);
  328|    655|              if (!ignore_garbage &&
  ------------------
  |  Branch (328:19): [True: 655, False: 0]
  ------------------
  329|    655|                  (last_chunk_options == last_chunk_handling_options::strict) &&
  ------------------
  |  Branch (329:19): [True: 0, False: 655]
  ------------------
  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|    655|              if (check_capacity && dstend - dst < 2) {
  ------------------
  |  Branch (334:19): [True: 655, Folded]
  |  Branch (334:37): [True: 0, False: 655]
  ------------------
  335|      0|                return {OUTPUT_BUFFER_TOO_SMALL, size_t(srccur - srcinit),
  336|      0|                        size_t(dst - dstinit)};
  337|      0|              }
  338|    655|              *dst++ = static_cast<char>((triple >> 16) & 0xFF);
  339|    655|              *dst++ = static_cast<char>((triple >> 8) & 0xFF);
  340|    655|            } else if (!ignore_garbage && idx == 1 &&
  ------------------
  |  Branch (340:24): [True: 179, False: 0]
  |  Branch (340:43): [True: 82, False: 97]
  ------------------
  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|     97|            } else if (!ignore_garbage && idx == 0 && padding_characters > 0) {
  ------------------
  |  Branch (346:24): [True: 97, False: 0]
  |  Branch (346:43): [True: 97, False: 0]
  |  Branch (346:55): [True: 7, False: 90]
  ------------------
  347|      7|              return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  348|      7|                      size_t(dst - dstinit), true};
  349|      7|            }
  350|  1.94k|            return {SUCCESS, size_t(src - srcinit), size_t(dst - dstinit)};
  351|  2.03k|          }
  352|  2.05k|    }
  353|     38|    if (check_capacity && dstend - dst < 3) {
  ------------------
  |  Branch (353:9): [True: 38, Folded]
  |  Branch (353:27): [True: 0, False: 38]
  ------------------
  354|      0|      return {OUTPUT_BUFFER_TOO_SMALL, size_t(srccur - srcinit),
  355|      0|              size_t(dst - dstinit)};
  356|      0|    }
  357|     38|    uint32_t triple =
  358|     38|        (uint32_t(buffer[0]) << 3 * 6) + (uint32_t(buffer[1]) << 2 * 6) +
  359|     38|        (uint32_t(buffer[2]) << 1 * 6) + (uint32_t(buffer[3]) << 0 * 6);
  360|     38|    *dst++ = static_cast<char>((triple >> 16) & 0xFF);
  361|     38|    *dst++ = static_cast<char>((triple >> 8) & 0xFF);
  362|     38|    *dst++ = static_cast<char>(triple & 0xFF);
  363|     38|  }
  364|  2.23k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6417patch_tail_resultENS_11full_resultEmmmmNS_27last_chunk_handling_optionsE:
  394|  8.97k|                  last_chunk_handling_options last_chunk_options) {
  395|  8.97k|  r.input_count += previous_input;
  396|  8.97k|  r.output_count += previous_output;
  397|  8.97k|  if (r.padding_error) {
  ------------------
  |  Branch (397:7): [True: 92, False: 8.87k]
  ------------------
  398|     92|    r.input_count = equallocation;
  399|     92|  }
  400|       |
  401|  8.97k|  if (r.error == error_code::SUCCESS) {
  ------------------
  |  Branch (401:7): [True: 7.32k, False: 1.65k]
  ------------------
  402|  7.32k|    if (!is_partial(last_chunk_options)) {
  ------------------
  |  Branch (402:9): [True: 5.69k, False: 1.62k]
  ------------------
  403|       |      // A success when we are not in stop_before_partial mode.
  404|       |      // means that we have consumed the whole input buffer.
  405|  5.69k|      r.input_count = full_input_length;
  406|  5.69k|    } else if (r.output_count % 3 != 0) {
  ------------------
  |  Branch (406:16): [True: 0, False: 1.62k]
  ------------------
  407|      0|      r.input_count = full_input_length;
  408|      0|    }
  409|  7.32k|  }
  410|  8.97k|  return r;
  411|  8.97k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6434base64_to_binary_details_safe_implIcEENS_11full_resultEPKT_mPcmNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  783|  2.28k|    last_chunk_handling_options last_chunk_options) noexcept {
  784|  2.28k|  const bool ignore_garbage =
  785|  2.28k|      (options == base64_options::base64_url_accept_garbage) ||
  ------------------
  |  Branch (785:7): [True: 0, False: 2.28k]
  ------------------
  786|  2.28k|      (options == base64_options::base64_default_accept_garbage) ||
  ------------------
  |  Branch (786:7): [True: 0, False: 2.28k]
  ------------------
  787|  2.28k|      (options == base64_options::base64_default_or_url_accept_garbage);
  ------------------
  |  Branch (787:7): [True: 0, False: 2.28k]
  ------------------
  788|  2.28k|  auto ri = simdutf::scalar::base64::find_end(input, length, options);
  789|  2.28k|  size_t equallocation = ri.equallocation;
  790|  2.28k|  size_t equalsigns = ri.equalsigns;
  791|  2.28k|  length = ri.srclen;
  792|  2.28k|  size_t full_input_length = ri.full_input_length;
  793|  2.28k|  if (length == 0) {
  ------------------
  |  Branch (793:7): [True: 52, False: 2.23k]
  ------------------
  794|     52|    if (!ignore_garbage && equalsigns > 0) {
  ------------------
  |  Branch (794:9): [True: 52, False: 0]
  |  Branch (794:28): [True: 20, False: 32]
  ------------------
  795|     20|      return {INVALID_BASE64_CHARACTER, equallocation, 0};
  796|     20|    }
  797|     32|    return {SUCCESS, full_input_length, 0};
  798|     52|  }
  799|  2.23k|  full_result r = scalar::base64::base64_tail_decode_safe(
  800|  2.23k|      output, outlen, input, length, equalsigns, options, last_chunk_options);
  801|  2.23k|  r = scalar::base64::patch_tail_result(r, 0, 0, equallocation,
  802|  2.23k|                                        full_input_length, last_chunk_options);
  803|  2.23k|  if (!is_partial(last_chunk_options) && r.error == error_code::SUCCESS &&
  ------------------
  |  Branch (803:7): [True: 2.23k, False: 0]
  |  Branch (803:42): [True: 1.94k, False: 284]
  ------------------
  804|  1.94k|      equalsigns > 0 && !ignore_garbage) {
  ------------------
  |  Branch (804:7): [True: 1.67k, False: 271]
  |  Branch (804:25): [True: 1.67k, False: 0]
  ------------------
  805|       |    // additional checks
  806|  1.67k|    if ((r.output_count % 3 == 0) ||
  ------------------
  |  Branch (806:9): [True: 0, False: 1.67k]
  ------------------
  807|  1.67k|        ((r.output_count % 3) + 1 + equalsigns != 4)) {
  ------------------
  |  Branch (807:9): [True: 0, False: 1.67k]
  ------------------
  808|      0|      return {INVALID_BASE64_CHARACTER, equallocation, r.output_count};
  809|      0|    }
  810|  1.67k|  }
  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.23k|  if (is_partial(last_chunk_options) && r.error == error_code::SUCCESS &&
  ------------------
  |  Branch (816:7): [True: 0, False: 2.23k]
  |  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.23k|  return r;
  833|  2.23k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6429base64_to_binary_details_implIcEENS_11full_resultEPKT_mPcNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  727|  15.6k|    last_chunk_handling_options last_chunk_options) noexcept {
  728|  15.6k|  const bool ignore_garbage =
  729|  15.6k|      (options == base64_options::base64_url_accept_garbage) ||
  ------------------
  |  Branch (729:7): [True: 0, False: 15.6k]
  ------------------
  730|  15.6k|      (options == base64_options::base64_default_accept_garbage) ||
  ------------------
  |  Branch (730:7): [True: 0, False: 15.6k]
  ------------------
  731|  15.6k|      (options == base64_options::base64_default_or_url_accept_garbage);
  ------------------
  |  Branch (731:7): [True: 0, False: 15.6k]
  ------------------
  732|  15.6k|  auto ri = simdutf::scalar::base64::find_end(input, length, options);
  733|  15.6k|  size_t equallocation = ri.equallocation;
  734|  15.6k|  size_t equalsigns = ri.equalsigns;
  735|  15.6k|  length = ri.srclen;
  736|  15.6k|  size_t full_input_length = ri.full_input_length;
  737|  15.6k|  if (length == 0) {
  ------------------
  |  Branch (737:7): [True: 15.2k, False: 393]
  ------------------
  738|  15.2k|    if (!ignore_garbage && equalsigns > 0) {
  ------------------
  |  Branch (738:9): [True: 15.2k, False: 0]
  |  Branch (738:28): [True: 5, False: 15.2k]
  ------------------
  739|      5|      return {INVALID_BASE64_CHARACTER, equallocation, 0, true};
  740|      5|    }
  741|  15.2k|    return {SUCCESS, full_input_length, 0};
  742|  15.2k|  }
  743|    393|  full_result r = scalar::base64::base64_tail_decode(
  744|    393|      output, input, length, equalsigns, options, last_chunk_options);
  745|    393|  r = scalar::base64::patch_tail_result(r, 0, 0, equallocation,
  746|    393|                                        full_input_length, last_chunk_options);
  747|    393|  if (!is_partial(last_chunk_options) && r.error == error_code::SUCCESS &&
  ------------------
  |  Branch (747:7): [True: 393, False: 0]
  |  Branch (747:42): [True: 219, False: 174]
  ------------------
  748|    219|      equalsigns > 0 && !ignore_garbage) {
  ------------------
  |  Branch (748:7): [True: 117, False: 102]
  |  Branch (748:25): [True: 117, False: 0]
  ------------------
  749|       |    // additional checks
  750|    117|    if ((r.output_count % 3 == 0) ||
  ------------------
  |  Branch (750:9): [True: 0, False: 117]
  ------------------
  751|    117|        ((r.output_count % 3) + 1 + equalsigns != 4)) {
  ------------------
  |  Branch (751:9): [True: 0, False: 117]
  ------------------
  752|      0|      return {INVALID_BASE64_CHARACTER, equallocation, r.output_count, true};
  753|      0|    }
  754|    117|  }
  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|    393|  if (is_partial(last_chunk_options) && r.error == error_code::SUCCESS &&
  ------------------
  |  Branch (759:7): [True: 0, False: 393]
  |  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|    393|  return r;
  776|    393|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6418base64_tail_decodeIcEENS_11full_resultEPcPKT_mmNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  371|  6.73k|    base64_options options, last_chunk_handling_options last_chunk_options) {
  372|  6.73k|  return base64_tail_decode_impl<false>(dst, 0, src, length, padding_characters,
  373|  6.73k|                                        options, last_chunk_options);
  374|  6.73k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_16base6423base64_tail_decode_implILb0EcEENS_11full_resultEPcmPKT0_mmNS_14base64_optionsENS_27last_chunk_handling_optionsE:
  164|  6.73k|    base64_options options, last_chunk_handling_options last_chunk_options) {
  165|  6.73k|  char *dstend = dst + outlen;
  166|  6.73k|  (void)dstend;
  167|       |  // This looks like 10 branches, but we expect the compiler to resolve this to
  168|       |  // two branches (easily predicted):
  169|  6.73k|  const uint8_t *to_base64 =
  170|  6.73k|      (options & base64_default_or_url)
  ------------------
  |  Branch (170:7): [True: 0, False: 6.73k]
  ------------------
  171|  6.73k|          ? tables::base64::to_base64_default_or_url_value
  172|  6.73k|          : ((options & base64_url) ? tables::base64::to_base64_url_value
  ------------------
  |  Branch (172:14): [True: 0, False: 6.73k]
  ------------------
  173|  6.73k|                                    : tables::base64::to_base64_value);
  174|  6.73k|  const uint32_t *d0 =
  175|  6.73k|      (options & base64_default_or_url)
  ------------------
  |  Branch (175:7): [True: 0, False: 6.73k]
  ------------------
  176|  6.73k|          ? tables::base64::base64_default_or_url::d0
  177|  6.73k|          : ((options & base64_url) ? tables::base64::base64_url::d0
  ------------------
  |  Branch (177:14): [True: 0, False: 6.73k]
  ------------------
  178|  6.73k|                                    : tables::base64::base64_default::d0);
  179|  6.73k|  const uint32_t *d1 =
  180|  6.73k|      (options & base64_default_or_url)
  ------------------
  |  Branch (180:7): [True: 0, False: 6.73k]
  ------------------
  181|  6.73k|          ? tables::base64::base64_default_or_url::d1
  182|  6.73k|          : ((options & base64_url) ? tables::base64::base64_url::d1
  ------------------
  |  Branch (182:14): [True: 0, False: 6.73k]
  ------------------
  183|  6.73k|                                    : tables::base64::base64_default::d1);
  184|  6.73k|  const uint32_t *d2 =
  185|  6.73k|      (options & base64_default_or_url)
  ------------------
  |  Branch (185:7): [True: 0, False: 6.73k]
  ------------------
  186|  6.73k|          ? tables::base64::base64_default_or_url::d2
  187|  6.73k|          : ((options & base64_url) ? tables::base64::base64_url::d2
  ------------------
  |  Branch (187:14): [True: 0, False: 6.73k]
  ------------------
  188|  6.73k|                                    : tables::base64::base64_default::d2);
  189|  6.73k|  const uint32_t *d3 =
  190|  6.73k|      (options & base64_default_or_url)
  ------------------
  |  Branch (190:7): [True: 0, False: 6.73k]
  ------------------
  191|  6.73k|          ? tables::base64::base64_default_or_url::d3
  192|  6.73k|          : ((options & base64_url) ? tables::base64::base64_url::d3
  ------------------
  |  Branch (192:14): [True: 0, False: 6.73k]
  ------------------
  193|  6.73k|                                    : tables::base64::base64_default::d3);
  194|  6.73k|  const bool ignore_garbage =
  195|  6.73k|      (options == base64_options::base64_url_accept_garbage) ||
  ------------------
  |  Branch (195:7): [True: 0, False: 6.73k]
  ------------------
  196|  6.73k|      (options == base64_options::base64_default_accept_garbage) ||
  ------------------
  |  Branch (196:7): [True: 0, False: 6.73k]
  ------------------
  197|  6.73k|      (options == base64_options::base64_default_or_url_accept_garbage);
  ------------------
  |  Branch (197:7): [True: 0, False: 6.73k]
  ------------------
  198|       |
  199|  6.73k|  const char_type *srcend = src + length;
  200|  6.73k|  const char_type *srcinit = src;
  201|  6.73k|  const char *dstinit = dst;
  202|       |
  203|  6.73k|  uint32_t x;
  204|  6.73k|  size_t idx;
  205|  6.73k|  uint8_t buffer[4];
  206|  7.46k|  while (true) {
  ------------------
  |  Branch (206:10): [True: 7.46k, Folded]
  ------------------
  207|  65.6k|    while (srcend - src >= 4 && is_eight_byte(src[0]) &&
  ------------------
  |  Branch (207:12): [True: 60.1k, False: 5.45k]
  |  Branch (207:33): [True: 60.1k, False: 0]
  ------------------
  208|  60.1k|           is_eight_byte(src[1]) && is_eight_byte(src[2]) &&
  ------------------
  |  Branch (208:12): [True: 60.1k, False: 0]
  |  Branch (208:37): [True: 60.1k, False: 0]
  ------------------
  209|  60.1k|           is_eight_byte(src[3]) &&
  ------------------
  |  Branch (209:12): [True: 60.1k, False: 0]
  ------------------
  210|  60.1k|           (x = d0[uint8_t(src[0])] | d1[uint8_t(src[1])] |
  ------------------
  |  Branch (210:12): [True: 58.1k, False: 2.00k]
  ------------------
  211|  60.1k|                d2[uint8_t(src[2])] | d3[uint8_t(src[3])]) < 0x01FFFFFF) {
  212|  58.1k|      if (check_capacity && dstend - dst < 3) {
  ------------------
  |  Branch (212:11): [Folded, False: 58.1k]
  |  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|  58.1k|      *dst++ = static_cast<char>(x & 0xFF);
  217|  58.1k|      *dst++ = static_cast<char>((x >> 8) & 0xFF);
  218|  58.1k|      *dst++ = static_cast<char>((x >> 16) & 0xFF);
  219|  58.1k|      src += 4;
  220|  58.1k|    }
  221|  7.46k|    const char_type *srccur = src;
  222|  7.46k|    idx = 0;
  223|       |    // we need at least four characters.
  224|  7.46k|#ifdef __clang__
  225|       |    // If possible, we read four characters at a time. (It is an optimization.)
  226|  7.46k|    if (ignore_garbage && src + 4 <= srcend) {
  ------------------
  |  Branch (226:9): [True: 0, False: 7.46k]
  |  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.46k|#endif
  248|  26.8k|    while ((idx < 4) && (src < srcend)) {
  ------------------
  |  Branch (248:12): [True: 26.1k, False: 727]
  |  Branch (248:25): [True: 20.4k, False: 5.64k]
  ------------------
  249|  20.4k|      char_type c = *src;
  250|       |
  251|  20.4k|      uint8_t code = to_base64[uint8_t(c)];
  252|  20.4k|      buffer[idx] = uint8_t(code);
  253|  20.4k|      if (is_eight_byte(c) && code <= 63) {
  ------------------
  |  Branch (253:11): [True: 20.4k, False: 0]
  |  Branch (253:31): [True: 9.42k, False: 11.0k]
  ------------------
  254|  9.42k|        idx++;
  255|  11.0k|      } else if (!ignore_garbage &&
  ------------------
  |  Branch (255:18): [True: 11.0k, False: 0]
  ------------------
  256|  11.0k|                 (code > 64 || !scalar::base64::is_eight_byte(c))) {
  ------------------
  |  Branch (256:19): [True: 1.08k, False: 9.96k]
  |  Branch (256:32): [True: 0, False: 9.96k]
  ------------------
  257|  1.08k|        return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  258|  1.08k|                size_t(dst - dstinit)};
  259|  9.96k|      } else {
  260|       |        // We have a space or a newline or garbage. We ignore it.
  261|  9.96k|      }
  262|  19.3k|      src++;
  263|  19.3k|    }
  264|  6.37k|    if (idx != 4) {
  ------------------
  |  Branch (264:9): [True: 5.64k, False: 727]
  ------------------
  265|  5.64k|      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.64k|      if (!ignore_garbage && (idx + padding_characters > 4)) {
  ------------------
  |  Branch (268:11): [True: 5.64k, False: 0]
  |  Branch (268:30): [True: 15, False: 5.63k]
  ------------------
  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.63k|      if (!ignore_garbage &&
  ------------------
  |  Branch (277:11): [True: 5.63k, False: 0]
  ------------------
  278|  5.63k|          last_chunk_options == last_chunk_handling_options::loose &&
  ------------------
  |  Branch (278:11): [True: 4.00k, False: 1.62k]
  ------------------
  279|  4.00k|          (idx >= 2) && padding_characters > 0 &&
  ------------------
  |  Branch (279:11): [True: 2.24k, False: 1.75k]
  |  Branch (279:25): [True: 1.71k, False: 535]
  ------------------
  280|  1.71k|          ((idx + padding_characters) & 3) != 0) {
  ------------------
  |  Branch (280:11): [True: 27, False: 1.68k]
  ------------------
  281|     27|        return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  282|     27|                size_t(dst - dstinit), true};
  283|     27|      } 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.60k|        if (!ignore_garbage &&
  ------------------
  |  Branch (288:13): [True: 5.60k, False: 0]
  ------------------
  289|  5.60k|            last_chunk_options == last_chunk_handling_options::strict &&
  ------------------
  |  Branch (289:13): [True: 0, False: 5.60k]
  ------------------
  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.60k|          if ((last_chunk_options ==
  ------------------
  |  Branch (298:16): [True: 0, False: 5.60k]
  ------------------
  299|  5.60k|                   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.60k|              (last_chunk_options ==
  ------------------
  |  Branch (302:16): [True: 1.62k, False: 3.97k]
  ------------------
  303|  5.60k|                   last_chunk_handling_options::only_full_chunks &&
  304|  1.62k|               (idx >= 2 || padding_characters == 0))) {
  ------------------
  |  Branch (304:17): [True: 197, False: 1.43k]
  |  Branch (304:29): [True: 1.42k, False: 6]
  ------------------
  305|       |            // partial means that we are *not* going to consume the read
  306|       |            // characters. We need to rewind the src pointer.
  307|  1.62k|            src = srccur;
  308|  1.62k|            return {SUCCESS, size_t(src - srcinit), size_t(dst - dstinit)};
  309|  3.98k|          } else {
  310|  3.98k|            if (idx == 2) {
  ------------------
  |  Branch (310:17): [True: 1.35k, False: 2.63k]
  ------------------
  311|  1.35k|              uint32_t triple = (uint32_t(buffer[0]) << 3 * 6) +
  312|  1.35k|                                (uint32_t(buffer[1]) << 2 * 6);
  313|  1.35k|              if (!ignore_garbage &&
  ------------------
  |  Branch (313:19): [True: 1.35k, False: 0]
  ------------------
  314|  1.35k|                  (last_chunk_options == last_chunk_handling_options::strict) &&
  ------------------
  |  Branch (314:19): [True: 0, False: 1.35k]
  ------------------
  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.35k|              if (check_capacity && dstend - dst < 1) {
  ------------------
  |  Branch (319:19): [Folded, False: 1.35k]
  |  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.35k|              *dst++ = static_cast<char>((triple >> 16) & 0xFF);
  324|  2.63k|            } else if (idx == 3) {
  ------------------
  |  Branch (324:24): [True: 865, False: 1.76k]
  ------------------
  325|    865|              uint32_t triple = (uint32_t(buffer[0]) << 3 * 6) +
  326|    865|                                (uint32_t(buffer[1]) << 2 * 6) +
  327|    865|                                (uint32_t(buffer[2]) << 1 * 6);
  328|    865|              if (!ignore_garbage &&
  ------------------
  |  Branch (328:19): [True: 865, False: 0]
  ------------------
  329|    865|                  (last_chunk_options == last_chunk_handling_options::strict) &&
  ------------------
  |  Branch (329:19): [True: 0, False: 865]
  ------------------
  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|    865|              if (check_capacity && dstend - dst < 2) {
  ------------------
  |  Branch (334:19): [Folded, False: 865]
  |  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|    865|              *dst++ = static_cast<char>((triple >> 16) & 0xFF);
  339|    865|              *dst++ = static_cast<char>((triple >> 8) & 0xFF);
  340|  1.76k|            } else if (!ignore_garbage && idx == 1 &&
  ------------------
  |  Branch (340:24): [True: 1.76k, False: 0]
  |  Branch (340:43): [True: 212, False: 1.55k]
  ------------------
  341|    212|                       (!is_partial(last_chunk_options) ||
  ------------------
  |  Branch (341:25): [True: 206, False: 6]
  ------------------
  342|      6|                        (is_partial(last_chunk_options) &&
  ------------------
  |  Branch (342:26): [True: 6, False: 0]
  ------------------
  343|    212|                         padding_characters > 0))) {
  ------------------
  |  Branch (343:26): [True: 6, False: 0]
  ------------------
  344|    212|              return {BASE64_INPUT_REMAINDER, size_t(src - srcinit),
  345|    212|                      size_t(dst - dstinit)};
  346|  1.55k|            } else if (!ignore_garbage && idx == 0 && padding_characters > 0) {
  ------------------
  |  Branch (346:24): [True: 1.55k, False: 0]
  |  Branch (346:43): [True: 1.55k, False: 0]
  |  Branch (346:55): [True: 23, False: 1.53k]
  ------------------
  347|     23|              return {INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  348|     23|                      size_t(dst - dstinit), true};
  349|     23|            }
  350|  3.74k|            return {SUCCESS, size_t(src - srcinit), size_t(dst - dstinit)};
  351|  3.98k|          }
  352|  5.63k|    }
  353|    727|    if (check_capacity && dstend - dst < 3) {
  ------------------
  |  Branch (353:9): [Folded, False: 727]
  |  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|    727|    uint32_t triple =
  358|    727|        (uint32_t(buffer[0]) << 3 * 6) + (uint32_t(buffer[1]) << 2 * 6) +
  359|    727|        (uint32_t(buffer[2]) << 1 * 6) + (uint32_t(buffer[3]) << 0 * 6);
  360|    727|    *dst++ = static_cast<char>((triple >> 16) & 0xFF);
  361|    727|    *dst++ = static_cast<char>((triple >> 8) & 0xFF);
  362|    727|    *dst++ = static_cast<char>(triple & 0xFF);
  363|    727|  }
  364|  6.73k|}

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

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

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

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

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

_ZN7simdutf6scalar5utf168validateILNS_10endiannessE0EEEbPKDsm:
   22|  19.5k|validate(const char16_t *data, size_t len) noexcept {
   23|  19.5k|  uint64_t pos = 0;
   24|   289k|  while (pos < len) {
  ------------------
  |  Branch (24:10): [True: 270k, False: 19.3k]
  ------------------
   25|   270k|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(data[pos]);
   26|   270k|    if ((word & 0xF800) == 0xD800) {
  ------------------
  |  Branch (26:9): [True: 2.83k, False: 267k]
  ------------------
   27|  2.83k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (27:11): [True: 22, False: 2.80k]
  ------------------
   28|     22|        return false;
   29|     22|      }
   30|  2.80k|      char16_t diff = char16_t(word - 0xD800);
   31|  2.80k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (31:11): [True: 61, False: 2.74k]
  ------------------
   32|     61|        return false;
   33|     61|      }
   34|  2.74k|      char16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (34:28): [Folded, False: 2.74k]
  ------------------
   35|  2.74k|                               ? u16_swap_bytes(data[pos + 1])
   36|  2.74k|                               : data[pos + 1];
   37|  2.74k|      char16_t diff2 = char16_t(next_word - 0xDC00);
   38|  2.74k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (38:11): [True: 65, False: 2.68k]
  ------------------
   39|     65|        return false;
   40|     65|      }
   41|  2.68k|      pos += 2;
   42|   267k|    } else {
   43|   267k|      pos++;
   44|   267k|    }
   45|   270k|  }
   46|  19.3k|  return true;
   47|  19.5k|}
_ZN7simdutf6scalar5utf168validateILNS_10endiannessE1EEEbPKDsm:
   22|  19.5k|validate(const char16_t *data, size_t len) noexcept {
   23|  19.5k|  uint64_t pos = 0;
   24|   288k|  while (pos < len) {
  ------------------
  |  Branch (24:10): [True: 269k, False: 19.4k]
  ------------------
   25|   269k|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(data[pos]);
   26|   269k|    if ((word & 0xF800) == 0xD800) {
  ------------------
  |  Branch (26:9): [True: 2.60k, False: 266k]
  ------------------
   27|  2.60k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (27:11): [True: 20, False: 2.58k]
  ------------------
   28|     20|        return false;
   29|     20|      }
   30|  2.58k|      char16_t diff = char16_t(word - 0xD800);
   31|  2.58k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (31:11): [True: 35, False: 2.55k]
  ------------------
   32|     35|        return false;
   33|     35|      }
   34|  2.55k|      char16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (34:28): [True: 2.55k, Folded]
  ------------------
   35|  2.55k|                               ? u16_swap_bytes(data[pos + 1])
   36|  2.55k|                               : data[pos + 1];
   37|  2.55k|      char16_t diff2 = char16_t(next_word - 0xDC00);
   38|  2.55k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (38:11): [True: 76, False: 2.47k]
  ------------------
   39|     76|        return false;
   40|     76|      }
   41|  2.47k|      pos += 2;
   42|   266k|    } else {
   43|   266k|      pos++;
   44|   266k|    }
   45|   269k|  }
   46|  19.4k|  return true;
   47|  19.5k|}
_ZN7simdutf6scalar5utf1620validate_with_errorsILNS_10endiannessE0EEENS_6resultEPKDsm:
   51|  5.94k|validate_with_errors(const char16_t *data, size_t len) noexcept {
   52|  5.94k|  size_t pos = 0;
   53|  51.4k|  while (pos < len) {
  ------------------
  |  Branch (53:10): [True: 45.7k, False: 5.68k]
  ------------------
   54|  45.7k|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(data[pos]);
   55|  45.7k|    if ((word & 0xF800) == 0xD800) {
  ------------------
  |  Branch (55:9): [True: 1.24k, False: 44.5k]
  ------------------
   56|  1.24k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (56:11): [True: 22, False: 1.22k]
  ------------------
   57|     22|        return result(error_code::SURROGATE, pos);
   58|     22|      }
   59|  1.22k|      char16_t diff = char16_t(word - 0xD800);
   60|  1.22k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (60:11): [True: 113, False: 1.10k]
  ------------------
   61|    113|        return result(error_code::SURROGATE, pos);
   62|    113|      }
   63|  1.10k|      char16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (63:28): [Folded, False: 1.10k]
  ------------------
   64|  1.10k|                               ? u16_swap_bytes(data[pos + 1])
   65|  1.10k|                               : data[pos + 1];
   66|  1.10k|      char16_t diff2 = uint16_t(next_word - 0xDC00);
   67|  1.10k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (67:11): [True: 123, False: 985]
  ------------------
   68|    123|        return result(error_code::SURROGATE, pos);
   69|    123|      }
   70|    985|      pos += 2;
   71|  44.5k|    } else {
   72|  44.5k|      pos++;
   73|  44.5k|    }
   74|  45.7k|  }
   75|  5.68k|  return result(error_code::SUCCESS, pos);
   76|  5.94k|}
_ZN7simdutf6scalar5utf1620validate_with_errorsILNS_10endiannessE1EEENS_6resultEPKDsm:
   51|  5.94k|validate_with_errors(const char16_t *data, size_t len) noexcept {
   52|  5.94k|  size_t pos = 0;
   53|  50.5k|  while (pos < len) {
  ------------------
  |  Branch (53:10): [True: 44.8k, False: 5.70k]
  ------------------
   54|  44.8k|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(data[pos]);
   55|  44.8k|    if ((word & 0xF800) == 0xD800) {
  ------------------
  |  Branch (55:9): [True: 1.01k, False: 43.8k]
  ------------------
   56|  1.01k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (56:11): [True: 20, False: 990]
  ------------------
   57|     20|        return result(error_code::SURROGATE, pos);
   58|     20|      }
   59|    990|      char16_t diff = char16_t(word - 0xD800);
   60|    990|      if (diff > 0x3FF) {
  ------------------
  |  Branch (60:11): [True: 75, False: 915]
  ------------------
   61|     75|        return result(error_code::SURROGATE, pos);
   62|     75|      }
   63|    915|      char16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (63:28): [True: 915, Folded]
  ------------------
   64|    915|                               ? u16_swap_bytes(data[pos + 1])
   65|    915|                               : data[pos + 1];
   66|    915|      char16_t diff2 = uint16_t(next_word - 0xDC00);
   67|    915|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (67:11): [True: 141, False: 774]
  ------------------
   68|    141|        return result(error_code::SURROGATE, pos);
   69|    141|      }
   70|    774|      pos += 2;
   71|  43.8k|    } else {
   72|  43.8k|      pos++;
   73|  43.8k|    }
   74|  44.8k|  }
   75|  5.70k|  return result(error_code::SUCCESS, pos);
   76|  5.94k|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE0EEEmPKDsm:
   91|  30.4k|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|  30.4k|  size_t counter{0};
   94|   127k|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 96.8k, False: 30.4k]
  ------------------
   95|  96.8k|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|  96.8k|    counter++; // ASCII
   97|  96.8k|    counter += static_cast<size_t>(
   98|  96.8k|        word >
   99|  96.8k|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|  96.8k|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 40.3k, False: 56.4k]
  |  Branch (100:53): [True: 32.6k, False: 7.71k]
  ------------------
  101|  64.1k|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 4.04k, False: 60.1k]
  ------------------
  102|  96.8k|  }
  103|  30.4k|  return counter;
  104|  30.4k|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE1EEEmPKDsm:
   91|  30.4k|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|  30.4k|  size_t counter{0};
   94|   125k|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 95.0k, False: 30.4k]
  ------------------
   95|  95.0k|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|  95.0k|    counter++; // ASCII
   97|  95.0k|    counter += static_cast<size_t>(
   98|  95.0k|        word >
   99|  95.0k|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|  95.0k|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 39.6k, False: 55.3k]
  |  Branch (100:53): [True: 33.2k, False: 6.41k]
  ------------------
  101|  61.7k|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 3.57k, False: 58.2k]
  ------------------
  102|  95.0k|  }
  103|  30.4k|  return counter;
  104|  30.4k|}

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

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf87convertILNS_10endiannessE0EPKDsPcQsr7simdutf6detailE18indexes_into_utf16IT0_EEEmS8_mT1_:
   17|  12.3k|                                   OutputPtr utf8_output) {
   18|  12.3k|  size_t pos = 0;
   19|  12.3k|  const auto start = utf8_output;
   20|  70.6k|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 58.4k, False: 12.2k]
  ------------------
   21|       |#if SIMDUTF_CPLUSPLUS23
   22|       |    if !consteval
   23|       |#endif
   24|  58.4k|    {
   25|       |      // try to convert the next block of 8 bytes
   26|  58.4k|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (26:11): [True: 54.4k, False: 3.93k]
  ------------------
   27|       |                            // they are ascii
   28|  54.4k|        uint64_t v;
   29|  54.4k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   30|       |        if constexpr (!match_system(big_endian)) {
   31|       |          v = (v >> 8) | (v << (64 - 8));
   32|       |        }
   33|  54.4k|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (33:13): [True: 14.6k, False: 39.8k]
  ------------------
   34|  14.6k|          size_t final_pos = pos + 4;
   35|  73.0k|          while (pos < final_pos) {
  ------------------
  |  Branch (35:18): [True: 58.4k, False: 14.6k]
  ------------------
   36|  58.4k|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (36:30): [Folded, False: 58.4k]
  ------------------
   37|  58.4k|                                 ? char(u16_swap_bytes(data[pos]))
   38|  58.4k|                                 : char(data[pos]);
   39|  58.4k|            pos++;
   40|  58.4k|          }
   41|  14.6k|          continue;
   42|  14.6k|        }
   43|  54.4k|      }
   44|  58.4k|    }
   45|  43.8k|    uint16_t word =
   46|  43.8k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (46:9): [Folded, False: 43.8k]
  ------------------
   47|  43.8k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (47:9): [True: 4.67k, False: 39.1k]
  ------------------
   48|       |      // will generate one UTF-8 bytes
   49|  4.67k|      *utf8_output++ = char(word);
   50|  4.67k|      pos++;
   51|  39.1k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (51:16): [True: 3.24k, False: 35.9k]
  ------------------
   52|       |      // will generate two UTF-8 bytes
   53|       |      // we have 0b110XXXXX 0b10XXXXXX
   54|  3.24k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   55|  3.24k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   56|  3.24k|      pos++;
   57|  35.9k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (57:16): [True: 34.1k, False: 1.80k]
  ------------------
   58|       |      // will generate three UTF-8 bytes
   59|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   60|  34.1k|      *utf8_output++ = char((word >> 12) | 0b11100000);
   61|  34.1k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   62|  34.1k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   63|  34.1k|      pos++;
   64|  34.1k|    } else {
   65|       |      // must be a surrogate pair
   66|  1.80k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (66:11): [True: 22, False: 1.78k]
  ------------------
   67|     22|        return 0;
   68|     22|      }
   69|  1.78k|      uint16_t diff = uint16_t(word - 0xD800);
   70|  1.78k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (70:11): [True: 50, False: 1.73k]
  ------------------
   71|     50|        return 0;
   72|     50|      }
   73|  1.73k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (73:28): [Folded, False: 1.73k]
  ------------------
   74|  1.73k|                               ? u16_swap_bytes(data[pos + 1])
   75|  1.73k|                               : data[pos + 1];
   76|  1.73k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   77|  1.73k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (77:11): [True: 51, False: 1.68k]
  ------------------
   78|     51|        return 0;
   79|     51|      }
   80|  1.68k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   81|       |      // will generate four UTF-8 bytes
   82|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   83|  1.68k|      *utf8_output++ = char((value >> 18) | 0b11110000);
   84|  1.68k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
   85|  1.68k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
   86|  1.68k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
   87|  1.68k|      pos += 2;
   88|  1.68k|    }
   89|  43.8k|  }
   90|  12.2k|  return utf8_output - start;
   91|  12.3k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf87convertILNS_10endiannessE1EPKDsPcQsr7simdutf6detailE18indexes_into_utf16IT0_EEEmS8_mT1_:
   17|  12.3k|                                   OutputPtr utf8_output) {
   18|  12.3k|  size_t pos = 0;
   19|  12.3k|  const auto start = utf8_output;
   20|  69.5k|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 57.3k, False: 12.2k]
  ------------------
   21|       |#if SIMDUTF_CPLUSPLUS23
   22|       |    if !consteval
   23|       |#endif
   24|  57.3k|    {
   25|       |      // try to convert the next block of 8 bytes
   26|  57.3k|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (26:11): [True: 53.4k, False: 3.91k]
  ------------------
   27|       |                            // they are ascii
   28|  53.4k|        uint64_t v;
   29|  53.4k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   30|  53.4k|        if constexpr (!match_system(big_endian)) {
   31|  53.4k|          v = (v >> 8) | (v << (64 - 8));
   32|  53.4k|        }
   33|  53.4k|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (33:13): [True: 14.5k, False: 38.8k]
  ------------------
   34|  14.5k|          size_t final_pos = pos + 4;
   35|  72.6k|          while (pos < final_pos) {
  ------------------
  |  Branch (35:18): [True: 58.1k, False: 14.5k]
  ------------------
   36|  58.1k|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (36:30): [True: 58.1k, Folded]
  ------------------
   37|  58.1k|                                 ? char(u16_swap_bytes(data[pos]))
   38|  58.1k|                                 : char(data[pos]);
   39|  58.1k|            pos++;
   40|  58.1k|          }
   41|  14.5k|          continue;
   42|  14.5k|        }
   43|  53.4k|      }
   44|  57.3k|    }
   45|  42.7k|    uint16_t word =
   46|  42.7k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (46:9): [True: 42.7k, Folded]
  ------------------
   47|  42.7k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (47:9): [True: 4.64k, False: 38.1k]
  ------------------
   48|       |      // will generate one UTF-8 bytes
   49|  4.64k|      *utf8_output++ = char(word);
   50|  4.64k|      pos++;
   51|  38.1k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (51:16): [True: 2.08k, False: 36.0k]
  ------------------
   52|       |      // will generate two UTF-8 bytes
   53|       |      // we have 0b110XXXXX 0b10XXXXXX
   54|  2.08k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   55|  2.08k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   56|  2.08k|      pos++;
   57|  36.0k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (57:16): [True: 34.4k, False: 1.59k]
  ------------------
   58|       |      // will generate three UTF-8 bytes
   59|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   60|  34.4k|      *utf8_output++ = char((word >> 12) | 0b11100000);
   61|  34.4k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   62|  34.4k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   63|  34.4k|      pos++;
   64|  34.4k|    } else {
   65|       |      // must be a surrogate pair
   66|  1.59k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (66:11): [True: 20, False: 1.57k]
  ------------------
   67|     20|        return 0;
   68|     20|      }
   69|  1.57k|      uint16_t diff = uint16_t(word - 0xD800);
   70|  1.57k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (70:11): [True: 27, False: 1.54k]
  ------------------
   71|     27|        return 0;
   72|     27|      }
   73|  1.54k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (73:28): [True: 1.54k, Folded]
  ------------------
   74|  1.54k|                               ? u16_swap_bytes(data[pos + 1])
   75|  1.54k|                               : data[pos + 1];
   76|  1.54k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   77|  1.54k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (77:11): [True: 63, False: 1.48k]
  ------------------
   78|     63|        return 0;
   79|     63|      }
   80|  1.48k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   81|       |      // will generate four UTF-8 bytes
   82|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   83|  1.48k|      *utf8_output++ = char((value >> 18) | 0b11110000);
   84|  1.48k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
   85|  1.48k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
   86|  1.48k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
   87|  1.48k|      pos += 2;
   88|  1.48k|    }
   89|  42.7k|  }
   90|  12.2k|  return utf8_output - start;
   91|  12.3k|}

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

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

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

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf88validateEPKcm:
  113|  20.9k|                                                        size_t len) noexcept {
  114|  20.9k|  return validate(reinterpret_cast<const uint8_t *>(buf), len);
  115|  20.9k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf88validateIPKhEEbT_m:
   14|  20.9k|                                                      size_t len) noexcept {
   15|  20.9k|  static_assert(
   16|  20.9k|      std::is_same<typename std::decay<decltype(*data)>::type, uint8_t>::value,
   17|  20.9k|      "dereferencing the data pointer must result in a uint8_t");
   18|  20.9k|  uint64_t pos = 0;
   19|  20.9k|  uint32_t code_point = 0;
   20|   110k|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 89.9k, False: 20.4k]
  ------------------
   21|  89.9k|    uint64_t next_pos;
   22|       |#if SIMDUTF_CPLUSPLUS23
   23|       |    if !consteval
   24|       |#endif
   25|  89.9k|    { // check if the next 16 bytes are ascii.
   26|  89.9k|      next_pos = pos + 16;
   27|  89.9k|      if (next_pos <= len) { // if it is safe to read 16 more bytes, check
  ------------------
  |  Branch (27:11): [True: 87.6k, False: 2.22k]
  ------------------
   28|       |                             // that they are ascii
   29|  87.6k|        uint64_t v1{};
   30|  87.6k|        std::memcpy(&v1, data + pos, sizeof(uint64_t));
   31|  87.6k|        uint64_t v2{};
   32|  87.6k|        std::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   33|  87.6k|        uint64_t v{v1 | v2};
   34|  87.6k|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (34:13): [True: 5.49k, False: 82.2k]
  ------------------
   35|  5.49k|          pos = next_pos;
   36|  5.49k|          continue;
   37|  5.49k|        }
   38|  87.6k|      }
   39|  89.9k|    }
   40|       |
   41|  84.4k|    unsigned char byte = data[pos];
   42|       |
   43|   110k|    while (byte < 0b10000000) {
  ------------------
  |  Branch (43:12): [True: 26.5k, False: 84.1k]
  ------------------
   44|  26.5k|      if (++pos == len) {
  ------------------
  |  Branch (44:11): [True: 298, False: 26.2k]
  ------------------
   45|    298|        return true;
   46|    298|      }
   47|  26.2k|      byte = data[pos];
   48|  26.2k|    }
   49|       |
   50|  84.1k|    if ((byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (50:9): [True: 32.9k, False: 51.1k]
  ------------------
   51|  32.9k|      next_pos = pos + 2;
   52|  32.9k|      if (next_pos > len) {
  ------------------
  |  Branch (52:11): [True: 10, False: 32.9k]
  ------------------
   53|     10|        return false;
   54|     10|      }
   55|  32.9k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (55:11): [True: 25, False: 32.9k]
  ------------------
   56|     25|        return false;
   57|     25|      }
   58|       |      // range check
   59|  32.9k|      code_point = (byte & 0b00011111) << 6 | (data[pos + 1] & 0b00111111);
   60|  32.9k|      if (code_point < 0x80) {
  ------------------
  |  Branch (60:11): [True: 5, False: 32.9k]
  ------------------
   61|      5|        return false;
   62|      5|      }
   63|  51.1k|    } else if ((byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (63:16): [True: 49.7k, False: 1.41k]
  ------------------
   64|  49.7k|      next_pos = pos + 3;
   65|  49.7k|      if (next_pos > len) {
  ------------------
  |  Branch (65:11): [True: 5, False: 49.7k]
  ------------------
   66|      5|        return false;
   67|      5|      }
   68|  49.7k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (68:11): [True: 10, False: 49.7k]
  ------------------
   69|     10|        return false;
   70|     10|      }
   71|  49.7k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (71:11): [True: 8, False: 49.7k]
  ------------------
   72|      8|        return false;
   73|      8|      }
   74|       |      // range check
   75|  49.7k|      code_point = (byte & 0b00001111) << 12 |
   76|  49.7k|                   (data[pos + 1] & 0b00111111) << 6 |
   77|  49.7k|                   (data[pos + 2] & 0b00111111);
   78|  49.7k|      if ((code_point < 0x800) ||
  ------------------
  |  Branch (78:11): [True: 9, False: 49.7k]
  ------------------
   79|  49.7k|          (0xd7ff < code_point && code_point < 0xe000)) {
  ------------------
  |  Branch (79:12): [True: 4.61k, False: 45.1k]
  |  Branch (79:35): [True: 3, False: 4.61k]
  ------------------
   80|     12|        return false;
   81|     12|      }
   82|  49.7k|    } else if ((byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (82:16): [True: 1.32k, False: 87]
  ------------------
   83|  1.32k|      next_pos = pos + 4;
   84|  1.32k|      if (next_pos > len) {
  ------------------
  |  Branch (84:11): [True: 4, False: 1.32k]
  ------------------
   85|      4|        return false;
   86|      4|      }
   87|  1.32k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (87:11): [True: 8, False: 1.31k]
  ------------------
   88|      8|        return false;
   89|      8|      }
   90|  1.31k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (90:11): [True: 7, False: 1.30k]
  ------------------
   91|      7|        return false;
   92|      7|      }
   93|  1.30k|      if ((data[pos + 3] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (93:11): [True: 8, False: 1.29k]
  ------------------
   94|      8|        return false;
   95|      8|      }
   96|       |      // range check
   97|  1.29k|      code_point =
   98|  1.29k|          (byte & 0b00000111) << 18 | (data[pos + 1] & 0b00111111) << 12 |
   99|  1.29k|          (data[pos + 2] & 0b00111111) << 6 | (data[pos + 3] & 0b00111111);
  100|  1.29k|      if (code_point <= 0xffff || 0x10ffff < code_point) {
  ------------------
  |  Branch (100:11): [True: 7, False: 1.29k]
  |  Branch (100:35): [True: 3, False: 1.28k]
  ------------------
  101|     10|        return false;
  102|     10|      }
  103|  1.29k|    } else {
  104|       |      // we may have a continuation
  105|     87|      return false;
  106|     87|    }
  107|  83.9k|    pos = next_pos;
  108|  83.9k|  }
  109|  20.4k|  return true;
  110|  20.9k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf820validate_with_errorsEPKcm:
  221|  6.19k|validate_with_errors(const char *buf, size_t len) noexcept {
  222|  6.19k|  return validate_with_errors(reinterpret_cast<const uint8_t *>(buf), len);
  223|  6.19k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf820validate_with_errorsIPKhEENS_6resultET_m:
  119|  6.19k|validate_with_errors(BytePtr data, size_t len) noexcept {
  120|  6.19k|  static_assert(
  121|  6.19k|      std::is_same<typename std::decay<decltype(*data)>::type, uint8_t>::value,
  122|  6.19k|      "dereferencing the data pointer must result in a uint8_t");
  123|  6.19k|  size_t pos = 0;
  124|  6.19k|  uint32_t code_point = 0;
  125|  12.6k|  while (pos < len) {
  ------------------
  |  Branch (125:10): [True: 7.69k, False: 4.93k]
  ------------------
  126|       |    // check of the next 16 bytes are ascii.
  127|  7.69k|    size_t next_pos = pos + 16;
  128|  7.69k|    if (next_pos <=
  ------------------
  |  Branch (128:9): [True: 6.64k, False: 1.04k]
  ------------------
  129|  7.69k|        len) { // if it is safe to read 16 more bytes, check that they are ascii
  130|  6.64k|      uint64_t v1;
  131|  6.64k|      std::memcpy(&v1, data + pos, sizeof(uint64_t));
  132|  6.64k|      uint64_t v2;
  133|  6.64k|      std::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
  134|  6.64k|      uint64_t v{v1 | v2};
  135|  6.64k|      if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (135:11): [True: 2.77k, False: 3.87k]
  ------------------
  136|  2.77k|        pos = next_pos;
  137|  2.77k|        continue;
  138|  2.77k|      }
  139|  6.64k|    }
  140|  4.91k|    unsigned char byte = data[pos];
  141|       |
  142|  13.4k|    while (byte < 0b10000000) {
  ------------------
  |  Branch (142:12): [True: 8.70k, False: 4.78k]
  ------------------
  143|  8.70k|      if (++pos == len) {
  ------------------
  |  Branch (143:11): [True: 133, False: 8.57k]
  ------------------
  144|    133|        return result(error_code::SUCCESS, len);
  145|    133|      }
  146|  8.57k|      byte = data[pos];
  147|  8.57k|    }
  148|       |
  149|  4.78k|    if ((byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (149:9): [True: 1.75k, False: 3.02k]
  ------------------
  150|  1.75k|      next_pos = pos + 2;
  151|  1.75k|      if (next_pos > len) {
  ------------------
  |  Branch (151:11): [True: 40, False: 1.71k]
  ------------------
  152|     40|        return result(error_code::TOO_SHORT, pos);
  153|     40|      }
  154|  1.71k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (154:11): [True: 123, False: 1.59k]
  ------------------
  155|    123|        return result(error_code::TOO_SHORT, pos);
  156|    123|      }
  157|       |      // range check
  158|  1.59k|      code_point = (byte & 0b00011111) << 6 | (data[pos + 1] & 0b00111111);
  159|  1.59k|      if (code_point < 0x80) {
  ------------------
  |  Branch (159:11): [True: 19, False: 1.57k]
  ------------------
  160|     19|        return result(error_code::OVERLONG, pos);
  161|     19|      }
  162|  3.02k|    } else if ((byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (162:16): [True: 1.53k, False: 1.49k]
  ------------------
  163|  1.53k|      next_pos = pos + 3;
  164|  1.53k|      if (next_pos > len) {
  ------------------
  |  Branch (164:11): [True: 49, False: 1.48k]
  ------------------
  165|     49|        return result(error_code::TOO_SHORT, pos);
  166|     49|      }
  167|  1.48k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (167:11): [True: 68, False: 1.41k]
  ------------------
  168|     68|        return result(error_code::TOO_SHORT, pos);
  169|     68|      }
  170|  1.41k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (170:11): [True: 42, False: 1.37k]
  ------------------
  171|     42|        return result(error_code::TOO_SHORT, pos);
  172|     42|      }
  173|       |      // range check
  174|  1.37k|      code_point = (byte & 0b00001111) << 12 |
  175|  1.37k|                   (data[pos + 1] & 0b00111111) << 6 |
  176|  1.37k|                   (data[pos + 2] & 0b00111111);
  177|  1.37k|      if (code_point < 0x800) {
  ------------------
  |  Branch (177:11): [True: 21, False: 1.35k]
  ------------------
  178|     21|        return result(error_code::OVERLONG, pos);
  179|     21|      }
  180|  1.35k|      if (0xd7ff < code_point && code_point < 0xe000) {
  ------------------
  |  Branch (180:11): [True: 705, False: 648]
  |  Branch (180:34): [True: 13, False: 692]
  ------------------
  181|     13|        return result(error_code::SURROGATE, pos);
  182|     13|      }
  183|  1.49k|    } else if ((byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (183:16): [True: 982, False: 511]
  ------------------
  184|    982|      next_pos = pos + 4;
  185|    982|      if (next_pos > len) {
  ------------------
  |  Branch (185:11): [True: 30, False: 952]
  ------------------
  186|     30|        return result(error_code::TOO_SHORT, pos);
  187|     30|      }
  188|    952|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (188:11): [True: 64, False: 888]
  ------------------
  189|     64|        return result(error_code::TOO_SHORT, pos);
  190|     64|      }
  191|    888|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (191:11): [True: 50, False: 838]
  ------------------
  192|     50|        return result(error_code::TOO_SHORT, pos);
  193|     50|      }
  194|    838|      if ((data[pos + 3] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (194:11): [True: 51, False: 787]
  ------------------
  195|     51|        return result(error_code::TOO_SHORT, pos);
  196|     51|      }
  197|       |      // range check
  198|    787|      code_point =
  199|    787|          (byte & 0b00000111) << 18 | (data[pos + 1] & 0b00111111) << 12 |
  200|    787|          (data[pos + 2] & 0b00111111) << 6 | (data[pos + 3] & 0b00111111);
  201|    787|      if (code_point <= 0xffff) {
  ------------------
  |  Branch (201:11): [True: 19, False: 768]
  ------------------
  202|     19|        return result(error_code::OVERLONG, pos);
  203|     19|      }
  204|    768|      if (0x10ffff < code_point) {
  ------------------
  |  Branch (204:11): [True: 24, False: 744]
  ------------------
  205|     24|        return result(error_code::TOO_LARGE, pos);
  206|     24|      }
  207|    768|    } else {
  208|       |      // we either have too many continuation bytes or an invalid leading byte
  209|    511|      if ((byte & 0b11000000) == 0b10000000) {
  ------------------
  |  Branch (209:11): [True: 327, False: 184]
  ------------------
  210|    327|        return result(error_code::TOO_LONG, pos);
  211|    327|      } else {
  212|    184|        return result(error_code::HEADER_BITS, pos);
  213|    184|      }
  214|    511|    }
  215|  3.66k|    pos = next_pos;
  216|  3.66k|  }
  217|  4.93k|  return result(error_code::SUCCESS, len);
  218|  6.19k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf831rewind_and_validate_with_errorsEPKcS4_m:
  232|  1.00k|    const char *start, const char *buf, size_t len) noexcept {
  233|       |  // First check that we start with a leading byte
  234|  1.00k|  if ((*start & 0b11000000) == 0b10000000) {
  ------------------
  |  Branch (234:7): [True: 81, False: 925]
  ------------------
  235|     81|    return result(error_code::TOO_LONG, 0);
  236|     81|  }
  237|    925|  size_t extra_len{0};
  238|       |  // A leading byte cannot be further than 4 bytes away
  239|    958|  for (int i = 0; i < 5; i++) {
  ------------------
  |  Branch (239:19): [True: 958, False: 0]
  ------------------
  240|    958|    unsigned char byte = *buf;
  241|    958|    if ((byte & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (241:9): [True: 925, False: 33]
  ------------------
  242|    925|      break;
  243|    925|    } else {
  244|     33|      buf--;
  245|     33|      extra_len++;
  246|     33|    }
  247|    958|  }
  248|       |
  249|    925|  result res = validate_with_errors(buf, len + extra_len);
  250|    925|  res.count -= extra_len; // Might underflow
  251|    925|  return res;
  252|  1.00k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf817count_code_pointsIPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_m:
  258|  47.4k|simdutf_constexpr23 size_t count_code_points(InputPtr data, size_t len) {
  259|  47.4k|  size_t counter{0};
  260|   524k|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (260:22): [True: 477k, False: 47.4k]
  ------------------
  261|       |    // -65 is 0b10111111, anything larger in two-complement's should start a new
  262|       |    // code point.
  263|   477k|    if (int8_t(data[i]) > -65) {
  ------------------
  |  Branch (263:9): [True: 392k, False: 84.5k]
  ------------------
  264|   392k|      counter++;
  265|   392k|    }
  266|   477k|  }
  267|  47.4k|  return counter;
  268|  47.4k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf822utf16_length_from_utf8IPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_m:
  274|  62.7k|simdutf_constexpr23 size_t utf16_length_from_utf8(InputPtr data, size_t len) {
  275|  62.7k|  size_t counter{0};
  276|   462k|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (276:22): [True: 400k, False: 62.7k]
  ------------------
  277|   400k|    if (int8_t(data[i]) > -65) {
  ------------------
  |  Branch (277:9): [True: 266k, False: 133k]
  ------------------
  278|   266k|      counter++;
  279|   266k|    }
  280|   400k|    if (uint8_t(data[i]) >= 240) {
  ------------------
  |  Branch (280:9): [True: 11.7k, False: 388k]
  ------------------
  281|  11.7k|      counter++;
  282|  11.7k|    }
  283|   400k|  }
  284|  62.7k|  return counter;
  285|  62.7k|}

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

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf167convertILNS_10endiannessE0EPKcQsr7simdutf6detailE22indexes_into_byte_likeIT0_EEEmS7_mPDs:
   16|  13.0k|                                   char16_t *utf16_output) {
   17|  13.0k|  size_t pos = 0;
   18|  13.0k|  char16_t *start{utf16_output};
   19|  75.8k|  while (pos < len) {
  ------------------
  |  Branch (19:10): [True: 63.5k, False: 12.2k]
  ------------------
   20|       |#if SIMDUTF_CPLUSPLUS23
   21|       |    if !consteval
   22|       |#endif
   23|       |    // try to convert the next block of 16 ASCII bytes
   24|  63.5k|    {
   25|  63.5k|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (25:11): [True: 49.9k, False: 13.6k]
  ------------------
   26|       |                             // they are ascii
   27|  49.9k|        uint64_t v1;
   28|  49.9k|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   29|  49.9k|        uint64_t v2;
   30|  49.9k|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   31|  49.9k|        uint64_t v{v1 | v2};
   32|  49.9k|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (32:13): [True: 3.94k, False: 45.9k]
  ------------------
   33|  3.94k|          size_t final_pos = pos + 16;
   34|  67.0k|          while (pos < final_pos) {
  ------------------
  |  Branch (34:18): [True: 63.1k, False: 3.94k]
  ------------------
   35|  63.1k|            *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (35:31): [Folded, False: 63.1k]
  ------------------
   36|  63.1k|                                  ? char16_t(u16_swap_bytes(data[pos]))
   37|  63.1k|                                  : char16_t(data[pos]);
   38|  63.1k|            pos++;
   39|  63.1k|          }
   40|  3.94k|          continue;
   41|  3.94k|        }
   42|  49.9k|      }
   43|  63.5k|    }
   44|       |
   45|  59.6k|    uint8_t leading_byte = data[pos]; // leading byte
   46|  59.6k|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (46:9): [True: 21.0k, False: 38.5k]
  ------------------
   47|       |      // converting one ASCII byte !!!
   48|  21.0k|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (48:25): [Folded, False: 21.0k]
  ------------------
   49|  21.0k|                            ? char16_t(u16_swap_bytes(leading_byte))
   50|  21.0k|                            : char16_t(leading_byte);
   51|  21.0k|      pos++;
   52|  38.5k|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (52:16): [True: 4.42k, False: 34.1k]
  ------------------
   53|       |      // We have a two-byte UTF-8, it should become
   54|       |      // a single UTF-16 word.
   55|  4.42k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (55:11): [True: 40, False: 4.38k]
  ------------------
   56|     40|        return 0;
   57|     40|      } // minimal bound checking
   58|  4.38k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (58:11): [True: 81, False: 4.30k]
  ------------------
   59|     81|        return 0;
   60|     81|      }
   61|       |      // range check
   62|  4.30k|      uint32_t code_point =
   63|  4.30k|          (leading_byte & 0b00011111) << 6 | (data[pos + 1] & 0b00111111);
   64|  4.30k|      if (code_point < 0x80) {
  ------------------
  |  Branch (64:11): [True: 18, False: 4.28k]
  ------------------
   65|     18|        return 0;
   66|     18|      }
   67|       |      if constexpr (!match_system(big_endian)) {
   68|       |        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
   69|       |      }
   70|  4.28k|      *utf16_output++ = char16_t(code_point);
   71|  4.28k|      pos += 2;
   72|  34.1k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (72:16): [True: 31.1k, False: 2.98k]
  ------------------
   73|       |      // We have a three-byte UTF-8, it should become
   74|       |      // a single UTF-16 word.
   75|  31.1k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (75:11): [True: 49, False: 31.0k]
  ------------------
   76|     49|        return 0;
   77|     49|      } // minimal bound checking
   78|       |
   79|  31.0k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (79:11): [True: 34, False: 31.0k]
  ------------------
   80|     34|        return 0;
   81|     34|      }
   82|  31.0k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (82:11): [True: 28, False: 31.0k]
  ------------------
   83|     28|        return 0;
   84|     28|      }
   85|       |      // range check
   86|  31.0k|      uint32_t code_point = (leading_byte & 0b00001111) << 12 |
   87|  31.0k|                            (data[pos + 1] & 0b00111111) << 6 |
   88|  31.0k|                            (data[pos + 2] & 0b00111111);
   89|  31.0k|      if (code_point < 0x800 || (0xd7ff < code_point && code_point < 0xe000)) {
  ------------------
  |  Branch (89:11): [True: 20, False: 30.9k]
  |  Branch (89:34): [True: 4.33k, False: 26.6k]
  |  Branch (89:57): [True: 13, False: 4.32k]
  ------------------
   90|     33|        return 0;
   91|     33|      }
   92|       |      if constexpr (!match_system(big_endian)) {
   93|       |        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
   94|       |      }
   95|  30.9k|      *utf16_output++ = char16_t(code_point);
   96|  30.9k|      pos += 3;
   97|  30.9k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (97:16): [True: 2.63k, False: 356]
  ------------------
   98|       |      // we have a 4-byte UTF-8 word.
   99|  2.63k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (99:11): [True: 30, False: 2.60k]
  ------------------
  100|     30|        return 0;
  101|     30|      } // minimal bound checking
  102|  2.60k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (102:11): [True: 34, False: 2.56k]
  ------------------
  103|     34|        return 0;
  104|     34|      }
  105|  2.56k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (105:11): [True: 26, False: 2.54k]
  ------------------
  106|     26|        return 0;
  107|     26|      }
  108|  2.54k|      if ((data[pos + 3] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (108:11): [True: 27, False: 2.51k]
  ------------------
  109|     27|        return 0;
  110|     27|      }
  111|       |
  112|       |      // range check
  113|  2.51k|      uint32_t code_point = (leading_byte & 0b00000111) << 18 |
  114|  2.51k|                            (data[pos + 1] & 0b00111111) << 12 |
  115|  2.51k|                            (data[pos + 2] & 0b00111111) << 6 |
  116|  2.51k|                            (data[pos + 3] & 0b00111111);
  117|  2.51k|      if (code_point <= 0xffff || 0x10ffff < code_point) {
  ------------------
  |  Branch (117:11): [True: 17, False: 2.49k]
  |  Branch (117:35): [True: 21, False: 2.47k]
  ------------------
  118|     38|        return 0;
  119|     38|      }
  120|  2.47k|      code_point -= 0x10000;
  121|  2.47k|      uint16_t high_surrogate = uint16_t(0xD800 + (code_point >> 10));
  122|  2.47k|      uint16_t low_surrogate = uint16_t(0xDC00 + (code_point & 0x3FF));
  123|       |      if constexpr (!match_system(big_endian)) {
  124|       |        high_surrogate = u16_swap_bytes(high_surrogate);
  125|       |        low_surrogate = u16_swap_bytes(low_surrogate);
  126|       |      }
  127|  2.47k|      *utf16_output++ = char16_t(high_surrogate);
  128|  2.47k|      *utf16_output++ = char16_t(low_surrogate);
  129|  2.47k|      pos += 4;
  130|  2.47k|    } else {
  131|    356|      return 0;
  132|    356|    }
  133|  59.6k|  }
  134|  12.2k|  return utf16_output - start;
  135|  13.0k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf167convertILNS_10endiannessE1EPKcQsr7simdutf6detailE22indexes_into_byte_likeIT0_EEEmS7_mPDs:
   16|  13.0k|                                   char16_t *utf16_output) {
   17|  13.0k|  size_t pos = 0;
   18|  13.0k|  char16_t *start{utf16_output};
   19|  74.3k|  while (pos < len) {
  ------------------
  |  Branch (19:10): [True: 62.1k, False: 12.2k]
  ------------------
   20|       |#if SIMDUTF_CPLUSPLUS23
   21|       |    if !consteval
   22|       |#endif
   23|       |    // try to convert the next block of 16 ASCII bytes
   24|  62.1k|    {
   25|  62.1k|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (25:11): [True: 48.5k, False: 13.5k]
  ------------------
   26|       |                             // they are ascii
   27|  48.5k|        uint64_t v1;
   28|  48.5k|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   29|  48.5k|        uint64_t v2;
   30|  48.5k|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   31|  48.5k|        uint64_t v{v1 | v2};
   32|  48.5k|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (32:13): [True: 3.94k, False: 44.5k]
  ------------------
   33|  3.94k|          size_t final_pos = pos + 16;
   34|  67.0k|          while (pos < final_pos) {
  ------------------
  |  Branch (34:18): [True: 63.1k, False: 3.94k]
  ------------------
   35|  63.1k|            *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (35:31): [True: 63.1k, Folded]
  ------------------
   36|  63.1k|                                  ? char16_t(u16_swap_bytes(data[pos]))
   37|  63.1k|                                  : char16_t(data[pos]);
   38|  63.1k|            pos++;
   39|  63.1k|          }
   40|  3.94k|          continue;
   41|  3.94k|        }
   42|  48.5k|      }
   43|  62.1k|    }
   44|       |
   45|  58.1k|    uint8_t leading_byte = data[pos]; // leading byte
   46|  58.1k|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (46:9): [True: 21.0k, False: 37.1k]
  ------------------
   47|       |      // converting one ASCII byte !!!
   48|  21.0k|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (48:25): [True: 21.0k, Folded]
  ------------------
   49|  21.0k|                            ? char16_t(u16_swap_bytes(leading_byte))
   50|  21.0k|                            : char16_t(leading_byte);
   51|  21.0k|      pos++;
   52|  37.1k|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (52:16): [True: 3.33k, False: 33.8k]
  ------------------
   53|       |      // We have a two-byte UTF-8, it should become
   54|       |      // a single UTF-16 word.
   55|  3.33k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (55:11): [True: 40, False: 3.29k]
  ------------------
   56|     40|        return 0;
   57|     40|      } // minimal bound checking
   58|  3.29k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (58:11): [True: 81, False: 3.21k]
  ------------------
   59|     81|        return 0;
   60|     81|      }
   61|       |      // range check
   62|  3.21k|      uint32_t code_point =
   63|  3.21k|          (leading_byte & 0b00011111) << 6 | (data[pos + 1] & 0b00111111);
   64|  3.21k|      if (code_point < 0x80) {
  ------------------
  |  Branch (64:11): [True: 18, False: 3.19k]
  ------------------
   65|     18|        return 0;
   66|     18|      }
   67|  3.19k|      if constexpr (!match_system(big_endian)) {
   68|  3.19k|        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
   69|  3.19k|      }
   70|  3.19k|      *utf16_output++ = char16_t(code_point);
   71|  3.19k|      pos += 2;
   72|  33.8k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (72:16): [True: 31.1k, False: 2.68k]
  ------------------
   73|       |      // We have a three-byte UTF-8, it should become
   74|       |      // a single UTF-16 word.
   75|  31.1k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (75:11): [True: 49, False: 31.0k]
  ------------------
   76|     49|        return 0;
   77|     49|      } // minimal bound checking
   78|       |
   79|  31.0k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (79:11): [True: 34, False: 31.0k]
  ------------------
   80|     34|        return 0;
   81|     34|      }
   82|  31.0k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (82:11): [True: 28, False: 31.0k]
  ------------------
   83|     28|        return 0;
   84|     28|      }
   85|       |      // range check
   86|  31.0k|      uint32_t code_point = (leading_byte & 0b00001111) << 12 |
   87|  31.0k|                            (data[pos + 1] & 0b00111111) << 6 |
   88|  31.0k|                            (data[pos + 2] & 0b00111111);
   89|  31.0k|      if (code_point < 0x800 || (0xd7ff < code_point && code_point < 0xe000)) {
  ------------------
  |  Branch (89:11): [True: 20, False: 31.0k]
  |  Branch (89:34): [True: 4.00k, False: 26.9k]
  |  Branch (89:57): [True: 13, False: 3.99k]
  ------------------
   90|     33|        return 0;
   91|     33|      }
   92|  30.9k|      if constexpr (!match_system(big_endian)) {
   93|  30.9k|        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
   94|  30.9k|      }
   95|  30.9k|      *utf16_output++ = char16_t(code_point);
   96|  30.9k|      pos += 3;
   97|  30.9k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (97:16): [True: 2.32k, False: 356]
  ------------------
   98|       |      // we have a 4-byte UTF-8 word.
   99|  2.32k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (99:11): [True: 30, False: 2.29k]
  ------------------
  100|     30|        return 0;
  101|     30|      } // minimal bound checking
  102|  2.29k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (102:11): [True: 34, False: 2.26k]
  ------------------
  103|     34|        return 0;
  104|     34|      }
  105|  2.26k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (105:11): [True: 26, False: 2.23k]
  ------------------
  106|     26|        return 0;
  107|     26|      }
  108|  2.23k|      if ((data[pos + 3] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (108:11): [True: 27, False: 2.20k]
  ------------------
  109|     27|        return 0;
  110|     27|      }
  111|       |
  112|       |      // range check
  113|  2.20k|      uint32_t code_point = (leading_byte & 0b00000111) << 18 |
  114|  2.20k|                            (data[pos + 1] & 0b00111111) << 12 |
  115|  2.20k|                            (data[pos + 2] & 0b00111111) << 6 |
  116|  2.20k|                            (data[pos + 3] & 0b00111111);
  117|  2.20k|      if (code_point <= 0xffff || 0x10ffff < code_point) {
  ------------------
  |  Branch (117:11): [True: 17, False: 2.19k]
  |  Branch (117:35): [True: 21, False: 2.16k]
  ------------------
  118|     38|        return 0;
  119|     38|      }
  120|  2.16k|      code_point -= 0x10000;
  121|  2.16k|      uint16_t high_surrogate = uint16_t(0xD800 + (code_point >> 10));
  122|  2.16k|      uint16_t low_surrogate = uint16_t(0xDC00 + (code_point & 0x3FF));
  123|  2.16k|      if constexpr (!match_system(big_endian)) {
  124|  2.16k|        high_surrogate = u16_swap_bytes(high_surrogate);
  125|  2.16k|        low_surrogate = u16_swap_bytes(low_surrogate);
  126|  2.16k|      }
  127|  2.16k|      *utf16_output++ = char16_t(high_surrogate);
  128|  2.16k|      *utf16_output++ = char16_t(low_surrogate);
  129|  2.16k|      pos += 4;
  130|  2.16k|    } else {
  131|    356|      return 0;
  132|    356|    }
  133|  58.1k|  }
  134|  12.2k|  return utf16_output - start;
  135|  13.0k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf327convertIPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_mPDi:
   16|  7.35k|                                   char32_t *utf32_output) {
   17|  7.35k|  size_t pos = 0;
   18|  7.35k|  char32_t *start{utf32_output};
   19|  36.6k|  while (pos < len) {
  ------------------
  |  Branch (19:10): [True: 30.0k, False: 6.55k]
  ------------------
   20|       |#if SIMDUTF_CPLUSPLUS23
   21|       |    if !consteval
   22|       |#endif
   23|  30.0k|    {
   24|       |      // try to convert the next block of 16 ASCII bytes
   25|  30.0k|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (25:11): [True: 19.2k, False: 10.8k]
  ------------------
   26|       |                             // they are ascii
   27|  19.2k|        uint64_t v1;
   28|  19.2k|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   29|  19.2k|        uint64_t v2;
   30|  19.2k|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   31|  19.2k|        uint64_t v{v1 | v2};
   32|  19.2k|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (32:13): [True: 3.78k, False: 15.4k]
  ------------------
   33|  3.78k|          size_t final_pos = pos + 16;
   34|  64.2k|          while (pos < final_pos) {
  ------------------
  |  Branch (34:18): [True: 60.4k, False: 3.78k]
  ------------------
   35|  60.4k|            *utf32_output++ = uint8_t(data[pos]);
   36|  60.4k|            pos++;
   37|  60.4k|          }
   38|  3.78k|          continue;
   39|  3.78k|        }
   40|  19.2k|      }
   41|  30.0k|    }
   42|  26.2k|    auto leading_byte = uint8_t(data[pos]); // leading byte
   43|  26.2k|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (43:9): [True: 19.2k, False: 7.04k]
  ------------------
   44|       |      // converting one ASCII byte !!!
   45|  19.2k|      *utf32_output++ = char32_t(leading_byte);
   46|  19.2k|      pos++;
   47|  19.2k|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (47:16): [True: 2.43k, False: 4.60k]
  ------------------
   48|       |      // We have a two-byte UTF-8
   49|  2.43k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (49:11): [True: 40, False: 2.39k]
  ------------------
   50|     40|        return 0;
   51|     40|      } // minimal bound checking
   52|  2.39k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (52:11): [True: 81, False: 2.31k]
  ------------------
   53|     81|        return 0;
   54|     81|      }
   55|       |      // range check
   56|  2.31k|      uint32_t code_point = (leading_byte & 0b00011111) << 6 |
   57|  2.31k|                            (uint8_t(data[pos + 1]) & 0b00111111);
   58|  2.31k|      if (code_point < 0x80) {
  ------------------
  |  Branch (58:11): [True: 18, False: 2.29k]
  ------------------
   59|     18|        return 0;
   60|     18|      }
   61|  2.29k|      *utf32_output++ = char32_t(code_point);
   62|  2.29k|      pos += 2;
   63|  4.60k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (63:16): [True: 2.28k, False: 2.32k]
  ------------------
   64|       |      // We have a three-byte UTF-8
   65|  2.28k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (65:11): [True: 49, False: 2.23k]
  ------------------
   66|     49|        return 0;
   67|     49|      } // minimal bound checking
   68|       |
   69|  2.23k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (69:11): [True: 34, False: 2.19k]
  ------------------
   70|     34|        return 0;
   71|     34|      }
   72|  2.19k|      if ((uint8_t(data[pos + 2]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (72:11): [True: 28, False: 2.17k]
  ------------------
   73|     28|        return 0;
   74|     28|      }
   75|       |      // range check
   76|  2.17k|      uint32_t code_point = (leading_byte & 0b00001111) << 12 |
   77|  2.17k|                            (uint8_t(data[pos + 1]) & 0b00111111) << 6 |
   78|  2.17k|                            (uint8_t(data[pos + 2]) & 0b00111111);
   79|  2.17k|      if (code_point < 0x800 || (0xd7ff < code_point && code_point < 0xe000)) {
  ------------------
  |  Branch (79:11): [True: 20, False: 2.15k]
  |  Branch (79:34): [True: 1.12k, False: 1.02k]
  |  Branch (79:57): [True: 13, False: 1.11k]
  ------------------
   80|     33|        return 0;
   81|     33|      }
   82|  2.13k|      *utf32_output++ = char32_t(code_point);
   83|  2.13k|      pos += 3;
   84|  2.32k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (84:16): [True: 1.96k, False: 356]
  ------------------
   85|       |      // we have a 4-byte UTF-8 word.
   86|  1.96k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (86:11): [True: 30, False: 1.93k]
  ------------------
   87|     30|        return 0;
   88|     30|      } // minimal bound checking
   89|  1.93k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (89:11): [True: 34, False: 1.90k]
  ------------------
   90|     34|        return 0;
   91|     34|      }
   92|  1.90k|      if ((uint8_t(data[pos + 2]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (92:11): [True: 26, False: 1.87k]
  ------------------
   93|     26|        return 0;
   94|     26|      }
   95|  1.87k|      if ((uint8_t(data[pos + 3]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (95:11): [True: 27, False: 1.85k]
  ------------------
   96|     27|        return 0;
   97|     27|      }
   98|       |
   99|       |      // range check
  100|  1.85k|      uint32_t code_point = (leading_byte & 0b00000111) << 18 |
  101|  1.85k|                            (uint8_t(data[pos + 1]) & 0b00111111) << 12 |
  102|  1.85k|                            (uint8_t(data[pos + 2]) & 0b00111111) << 6 |
  103|  1.85k|                            (uint8_t(data[pos + 3]) & 0b00111111);
  104|  1.85k|      if (code_point <= 0xffff || 0x10ffff < code_point) {
  ------------------
  |  Branch (104:11): [True: 17, False: 1.83k]
  |  Branch (104:35): [True: 21, False: 1.81k]
  ------------------
  105|     38|        return 0;
  106|     38|      }
  107|  1.81k|      *utf32_output++ = char32_t(code_point);
  108|  1.81k|      pos += 4;
  109|  1.81k|    } else {
  110|    356|      return 0;
  111|    356|    }
  112|  26.2k|  }
  113|  6.55k|  return utf32_output - start;
  114|  7.35k|}

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_16base6422compress_decode_base64ILb0ELb0ELb0EcEENS_11full_resultEPcPKT2_mNS_14base64_optionsENS_27last_chunk_handling_optionsE:
   45|  61.1k|                       last_chunk_handling_options last_chunk_options) {
   46|  61.1k|  const uint8_t *to_base64 =
   47|  61.1k|      default_or_url ? tables::base64::to_base64_default_or_url_value
  ------------------
  |  Branch (47:7): [Folded, False: 61.1k]
  ------------------
   48|  61.1k|                     : (base64_url ? tables::base64::to_base64_url_value
  ------------------
  |  Branch (48:25): [Folded, False: 61.1k]
  ------------------
   49|  61.1k|                                   : tables::base64::to_base64_value);
   50|  61.1k|  auto ri = simdutf::scalar::base64::find_end(src, srclen, options);
   51|  61.1k|  size_t equallocation = ri.equallocation;
   52|  61.1k|  size_t equalsigns = ri.equalsigns;
   53|  61.1k|  srclen = ri.srclen;
   54|  61.1k|  size_t full_input_length = ri.full_input_length;
   55|  61.1k|  if (srclen == 0) {
  ------------------
  |  Branch (55:7): [True: 54.6k, False: 6.43k]
  ------------------
   56|  54.6k|    if (!ignore_garbage && equalsigns > 0) {
  ------------------
  |  Branch (56:9): [True: 54.6k, Folded]
  |  Branch (56:28): [True: 19, False: 54.6k]
  ------------------
   57|     19|      return {INVALID_BASE64_CHARACTER, equallocation, 0, true};
   58|     19|    }
   59|  54.6k|    return {SUCCESS, full_input_length, 0};
   60|  54.6k|  }
   61|  6.43k|  char *end_of_safe_64byte_zone =
   62|  6.43k|      dst == nullptr
  ------------------
  |  Branch (62:7): [True: 73, False: 6.36k]
  ------------------
   63|  6.43k|          ? nullptr
   64|  6.43k|          : ((srclen + 3) / 4 * 3 >= 63 ? dst + (srclen + 3) / 4 * 3 - 63
  ------------------
  |  Branch (64:14): [True: 2.31k, False: 4.04k]
  ------------------
   65|  6.36k|                                        : dst);
   66|       |
   67|  6.43k|  const chartype *const srcinit = src;
   68|  6.43k|  const char *const dstinit = dst;
   69|  6.43k|  const chartype *const srcend = src + srclen;
   70|       |
   71|  6.43k|  constexpr size_t block_size = 6;
   72|  6.43k|  static_assert(block_size >= 2, "block_size must be at least two");
   73|  6.43k|  char buffer[block_size * 64];
   74|  6.43k|  char *bufferptr = buffer;
   75|  6.43k|  if (srclen >= 64) {
  ------------------
  |  Branch (75:7): [True: 3.19k, False: 3.23k]
  ------------------
   76|  3.19k|    const chartype *const srcend64 = src + srclen - 64;
   77|  18.9k|    while (src <= srcend64) {
  ------------------
  |  Branch (77:12): [True: 16.5k, False: 2.38k]
  ------------------
   78|  16.5k|      block64 b(src);
   79|  16.5k|      src += 64;
   80|  16.5k|      uint64_t error = 0;
   81|  16.5k|      const uint64_t badcharmask =
   82|  16.5k|          b.to_base64_mask<base64_url, ignore_garbage, default_or_url>(&error);
   83|  16.5k|      if (!ignore_garbage && error) {
  ------------------
  |  Branch (83:11): [True: 16.5k, Folded]
  |  Branch (83:30): [True: 810, False: 15.7k]
  ------------------
   84|    810|        src -= 64;
   85|    810|        const size_t error_offset = trailing_zeroes(error);
   86|    810|        return {error_code::INVALID_BASE64_CHARACTER,
   87|    810|                size_t(src - srcinit + error_offset), size_t(dst - dstinit)};
   88|    810|      }
   89|  15.7k|      if (badcharmask != 0) {
  ------------------
  |  Branch (89:11): [True: 2.23k, False: 13.5k]
  ------------------
   90|  2.23k|        bufferptr += b.compress_block(badcharmask, bufferptr);
   91|  13.5k|      } else if (bufferptr != buffer) {
  ------------------
  |  Branch (91:18): [True: 395, False: 13.1k]
  ------------------
   92|    395|        b.copy_block(bufferptr);
   93|    395|        bufferptr += 64;
   94|  13.1k|      } else {
   95|  13.1k|        if (dst >= end_of_safe_64byte_zone) {
  ------------------
  |  Branch (95:13): [True: 812, False: 12.3k]
  ------------------
   96|    812|          b.base64_decode_block_safe(dst);
   97|  12.3k|        } else {
   98|  12.3k|          b.base64_decode_block(dst);
   99|  12.3k|        }
  100|  13.1k|        dst += 48;
  101|  13.1k|      }
  102|  15.7k|      if (bufferptr >= (block_size - 1) * 64 + buffer) {
  ------------------
  |  Branch (102:11): [True: 240, False: 15.5k]
  ------------------
  103|  1.20k|        for (size_t i = 0; i < (block_size - 2); i++) {
  ------------------
  |  Branch (103:28): [True: 960, False: 240]
  ------------------
  104|    960|          base64_decode_block(dst, buffer + i * 64);
  105|    960|          dst += 48;
  106|    960|        }
  107|    240|        if (dst >= end_of_safe_64byte_zone) {
  ------------------
  |  Branch (107:13): [True: 0, False: 240]
  ------------------
  108|      0|          base64_decode_block_safe(dst, buffer + (block_size - 2) * 64);
  109|    240|        } else {
  110|    240|          base64_decode_block(dst, buffer + (block_size - 2) * 64);
  111|    240|        }
  112|    240|        dst += 48;
  113|    240|        std::memcpy(buffer, buffer + (block_size - 1) * 64,
  114|    240|                    64); // 64 might be too much
  115|    240|        bufferptr -= (block_size - 1) * 64;
  116|    240|      }
  117|  15.7k|    }
  118|  3.19k|  }
  119|       |
  120|  5.62k|  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.62k|  int last_block = (int)((bufferptr - buffer_start) % 64);
  124|  5.62k|  if (last_block != 0 && srcend - src + last_block >= 64) {
  ------------------
  |  Branch (124:7): [True: 668, False: 4.95k]
  |  Branch (124:26): [True: 134, False: 534]
  ------------------
  125|       |
  126|  1.82k|    while ((bufferptr - buffer_start) % 64 != 0 && src < srcend) {
  ------------------
  |  Branch (126:12): [True: 1.72k, False: 100]
  |  Branch (126:52): [True: 1.70k, False: 20]
  ------------------
  127|  1.70k|      uint8_t val = to_base64[uint8_t(*src)];
  128|  1.70k|      *bufferptr = char(val);
  129|  1.70k|      if (!ignore_garbage &&
  ------------------
  |  Branch (129:11): [True: 1.70k, Folded]
  ------------------
  130|  1.70k|          (!scalar::base64::is_eight_byte(*src) || val > 64)) {
  ------------------
  |  Branch (130:12): [True: 0, False: 1.70k]
  |  Branch (130:52): [True: 14, False: 1.68k]
  ------------------
  131|     14|        return {error_code::INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  132|     14|                size_t(dst - dstinit)};
  133|     14|      }
  134|  1.68k|      bufferptr += (val <= 63);
  135|  1.68k|      src++;
  136|  1.68k|    }
  137|    134|  }
  138|       |
  139|  6.14k|  for (; buffer_start + 64 <= bufferptr; buffer_start += 64) {
  ------------------
  |  Branch (139:10): [True: 532, False: 5.60k]
  ------------------
  140|    532|    if (dst >= end_of_safe_64byte_zone) {
  ------------------
  |  Branch (140:9): [True: 50, False: 482]
  ------------------
  141|     50|      base64_decode_block_safe(dst, buffer_start);
  142|    482|    } else {
  143|    482|      base64_decode_block(dst, buffer_start);
  144|    482|    }
  145|    532|    dst += 48;
  146|    532|  }
  147|  5.60k|  if ((bufferptr - buffer_start) % 64 != 0) {
  ------------------
  |  Branch (147:7): [True: 554, False: 5.05k]
  ------------------
  148|  5.29k|    while (buffer_start + 4 < bufferptr) {
  ------------------
  |  Branch (148:12): [True: 4.73k, False: 554]
  ------------------
  149|  4.73k|      uint32_t triple = ((uint32_t(uint8_t(buffer_start[0])) << 3 * 6) +
  150|  4.73k|                         (uint32_t(uint8_t(buffer_start[1])) << 2 * 6) +
  151|  4.73k|                         (uint32_t(uint8_t(buffer_start[2])) << 1 * 6) +
  152|  4.73k|                         (uint32_t(uint8_t(buffer_start[3])) << 0 * 6))
  153|  4.73k|                        << 8;
  154|  4.73k|#if !SIMDUTF_IS_BIG_ENDIAN
  155|  4.73k|      triple = scalar::u32_swap_bytes(triple);
  156|  4.73k|#endif
  157|  4.73k|      std::memcpy(dst, &triple, 3);
  158|       |
  159|  4.73k|      dst += 3;
  160|  4.73k|      buffer_start += 4;
  161|  4.73k|    }
  162|    554|    if (buffer_start + 4 <= bufferptr) {
  ------------------
  |  Branch (162:9): [True: 150, False: 404]
  ------------------
  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|    554|    int leftover = int(bufferptr - buffer_start);
  179|  1.43k|    while (leftover > 0) {
  ------------------
  |  Branch (179:12): [True: 880, False: 554]
  ------------------
  180|    880|      if (!ignore_garbage) {
  ------------------
  |  Branch (180:11): [True: 880, Folded]
  ------------------
  181|  4.51k|        while (to_base64[uint8_t(*(src - 1))] == 64) {
  ------------------
  |  Branch (181:16): [True: 3.63k, False: 880]
  ------------------
  182|  3.63k|          src--;
  183|  3.63k|        }
  184|    880|      } 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|    880|      src--;
  190|    880|      leftover--;
  191|    880|    }
  192|    554|  }
  193|  5.60k|  if (src < srcend + equalsigns) {
  ------------------
  |  Branch (193:7): [True: 5.20k, False: 409]
  ------------------
  194|  5.20k|    full_result r = scalar::base64::base64_tail_decode(
  195|  5.20k|        dst, src, srcend - src, equalsigns, options, last_chunk_options);
  196|  5.20k|    r = scalar::base64::patch_tail_result(
  197|  5.20k|        r, size_t(src - srcinit), size_t(dst - dstinit), equallocation,
  198|  5.20k|        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.20k|    if (is_partial(last_chunk_options) && r.error == error_code::SUCCESS &&
  ------------------
  |  Branch (203:9): [True: 1.91k, False: 3.28k]
  |  Branch (203:43): [True: 1.62k, False: 296]
  ------------------
  204|  1.62k|        r.input_count < full_input_length) {
  ------------------
  |  Branch (204:9): [True: 317, False: 1.30k]
  ------------------
  205|       |      // First check if we can extend the input to the end of the stream
  206|  2.06k|      while (r.input_count < full_input_length &&
  ------------------
  |  Branch (206:14): [True: 2.02k, False: 39]
  ------------------
  207|  2.02k|             base64_ignorable(*(srcinit + r.input_count), options)) {
  ------------------
  |  Branch (207:14): [True: 1.74k, False: 278]
  ------------------
  208|  1.74k|        r.input_count++;
  209|  1.74k|      }
  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: 278, False: 39]
  ------------------
  213|  2.08k|        while (r.input_count > 0 &&
  ------------------
  |  Branch (213:16): [True: 1.99k, False: 87]
  ------------------
  214|  1.99k|               base64_ignorable(*(srcinit + r.input_count - 1), options)) {
  ------------------
  |  Branch (214:16): [True: 1.80k, False: 191]
  ------------------
  215|  1.80k|          r.input_count--;
  216|  1.80k|        }
  217|    278|      }
  218|    317|    }
  219|  5.20k|    return r;
  220|  5.20k|  }
  221|    409|  if (!ignore_garbage && equalsigns > 0) {
  ------------------
  |  Branch (221:7): [True: 409, Folded]
  |  Branch (221:26): [True: 0, False: 409]
  ------------------
  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|    409|  return {SUCCESS, srclen, size_t(dst - dstinit)};
  229|    409|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_16base6422compress_decode_base64ILb0ELb0ELb0EcEENS_11full_resultEPcPKT2_mNS_14base64_optionsENS_27last_chunk_handling_optionsE:
   45|  15.3k|                       last_chunk_handling_options last_chunk_options) {
   46|  15.3k|  const uint8_t *to_base64 =
   47|  15.3k|      default_or_url ? tables::base64::to_base64_default_or_url_value
  ------------------
  |  Branch (47:7): [Folded, False: 15.3k]
  ------------------
   48|  15.3k|                     : (base64_url ? tables::base64::to_base64_url_value
  ------------------
  |  Branch (48:25): [Folded, False: 15.3k]
  ------------------
   49|  15.3k|                                   : tables::base64::to_base64_value);
   50|  15.3k|  auto ri = simdutf::scalar::base64::find_end(src, srclen, options);
   51|  15.3k|  size_t equallocation = ri.equallocation;
   52|  15.3k|  size_t equalsigns = ri.equalsigns;
   53|  15.3k|  srclen = ri.srclen;
   54|  15.3k|  size_t full_input_length = ri.full_input_length;
   55|  15.3k|  if (srclen == 0) {
  ------------------
  |  Branch (55:7): [True: 13.7k, False: 1.51k]
  ------------------
   56|  13.7k|    if (!ignore_garbage && equalsigns > 0) {
  ------------------
  |  Branch (56:9): [True: 13.7k, Folded]
  |  Branch (56:28): [True: 9, False: 13.7k]
  ------------------
   57|      9|      return {INVALID_BASE64_CHARACTER, equallocation, 0, true};
   58|      9|    }
   59|  13.7k|    return {SUCCESS, full_input_length, 0};
   60|  13.7k|  }
   61|  1.51k|  char *end_of_safe_64byte_zone =
   62|  1.51k|      dst == nullptr
  ------------------
  |  Branch (62:7): [True: 30, False: 1.48k]
  ------------------
   63|  1.51k|          ? nullptr
   64|  1.51k|          : ((srclen + 3) / 4 * 3 >= 63 ? dst + (srclen + 3) / 4 * 3 - 63
  ------------------
  |  Branch (64:14): [True: 488, False: 994]
  ------------------
   65|  1.48k|                                        : dst);
   66|       |
   67|  1.51k|  const chartype *const srcinit = src;
   68|  1.51k|  const char *const dstinit = dst;
   69|  1.51k|  const chartype *const srcend = src + srclen;
   70|       |
   71|  1.51k|  constexpr size_t block_size = 6;
   72|  1.51k|  static_assert(block_size >= 2, "block_size must be at least two");
   73|  1.51k|  char buffer[block_size * 64];
   74|  1.51k|  char *bufferptr = buffer;
   75|  1.51k|  if (srclen >= 64) {
  ------------------
  |  Branch (75:7): [True: 786, False: 726]
  ------------------
   76|    786|    const chartype *const srcend64 = src + srclen - 64;
   77|  4.40k|    while (src <= srcend64) {
  ------------------
  |  Branch (77:12): [True: 3.86k, False: 547]
  ------------------
   78|  3.86k|      block64 b(src);
   79|  3.86k|      src += 64;
   80|  3.86k|      uint64_t error = 0;
   81|  3.86k|      const uint64_t badcharmask =
   82|  3.86k|          b.to_base64_mask<base64_url, ignore_garbage, default_or_url>(&error);
   83|  3.86k|      if (!ignore_garbage && error) {
  ------------------
  |  Branch (83:11): [True: 3.86k, Folded]
  |  Branch (83:30): [True: 239, False: 3.62k]
  ------------------
   84|    239|        src -= 64;
   85|    239|        const size_t error_offset = trailing_zeroes(error);
   86|    239|        return {error_code::INVALID_BASE64_CHARACTER,
   87|    239|                size_t(src - srcinit + error_offset), size_t(dst - dstinit)};
   88|    239|      }
   89|  3.62k|      if (badcharmask != 0) {
  ------------------
  |  Branch (89:11): [True: 724, False: 2.89k]
  ------------------
   90|    724|        bufferptr += b.compress_block(badcharmask, bufferptr);
   91|  2.89k|      } else if (bufferptr != buffer) {
  ------------------
  |  Branch (91:18): [True: 94, False: 2.80k]
  ------------------
   92|     94|        b.copy_block(bufferptr);
   93|     94|        bufferptr += 64;
   94|  2.80k|      } else {
   95|  2.80k|        if (dst >= end_of_safe_64byte_zone) {
  ------------------
  |  Branch (95:13): [True: 131, False: 2.67k]
  ------------------
   96|    131|          b.base64_decode_block_safe(dst);
   97|  2.67k|        } else {
   98|  2.67k|          b.base64_decode_block(dst);
   99|  2.67k|        }
  100|  2.80k|        dst += 48;
  101|  2.80k|      }
  102|  3.62k|      if (bufferptr >= (block_size - 1) * 64 + buffer) {
  ------------------
  |  Branch (102:11): [True: 70, False: 3.55k]
  ------------------
  103|    350|        for (size_t i = 0; i < (block_size - 2); i++) {
  ------------------
  |  Branch (103:28): [True: 280, False: 70]
  ------------------
  104|    280|          base64_decode_block(dst, buffer + i * 64);
  105|    280|          dst += 48;
  106|    280|        }
  107|     70|        if (dst >= end_of_safe_64byte_zone) {
  ------------------
  |  Branch (107:13): [True: 0, False: 70]
  ------------------
  108|      0|          base64_decode_block_safe(dst, buffer + (block_size - 2) * 64);
  109|     70|        } else {
  110|     70|          base64_decode_block(dst, buffer + (block_size - 2) * 64);
  111|     70|        }
  112|     70|        dst += 48;
  113|     70|        std::memcpy(buffer, buffer + (block_size - 1) * 64,
  114|     70|                    64); // 64 might be too much
  115|     70|        bufferptr -= (block_size - 1) * 64;
  116|     70|      }
  117|  3.62k|    }
  118|    786|  }
  119|       |
  120|  1.27k|  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.27k|  int last_block = (int)((bufferptr - buffer_start) % 64);
  124|  1.27k|  if (last_block != 0 && srcend - src + last_block >= 64) {
  ------------------
  |  Branch (124:7): [True: 231, False: 1.04k]
  |  Branch (124:26): [True: 45, False: 186]
  ------------------
  125|       |
  126|    450|    while ((bufferptr - buffer_start) % 64 != 0 && src < srcend) {
  ------------------
  |  Branch (126:12): [True: 420, False: 30]
  |  Branch (126:52): [True: 411, False: 9]
  ------------------
  127|    411|      uint8_t val = to_base64[uint8_t(*src)];
  128|    411|      *bufferptr = char(val);
  129|    411|      if (!ignore_garbage &&
  ------------------
  |  Branch (129:11): [True: 411, Folded]
  ------------------
  130|    411|          (!scalar::base64::is_eight_byte(*src) || val > 64)) {
  ------------------
  |  Branch (130:12): [True: 0, False: 411]
  |  Branch (130:52): [True: 6, False: 405]
  ------------------
  131|      6|        return {error_code::INVALID_BASE64_CHARACTER, size_t(src - srcinit),
  132|      6|                size_t(dst - dstinit)};
  133|      6|      }
  134|    405|      bufferptr += (val <= 63);
  135|    405|      src++;
  136|    405|    }
  137|     45|  }
  138|       |
  139|  1.42k|  for (; buffer_start + 64 <= bufferptr; buffer_start += 64) {
  ------------------
  |  Branch (139:10): [True: 159, False: 1.26k]
  ------------------
  140|    159|    if (dst >= end_of_safe_64byte_zone) {
  ------------------
  |  Branch (140:9): [True: 20, False: 139]
  ------------------
  141|     20|      base64_decode_block_safe(dst, buffer_start);
  142|    139|    } else {
  143|    139|      base64_decode_block(dst, buffer_start);
  144|    139|    }
  145|    159|    dst += 48;
  146|    159|  }
  147|  1.26k|  if ((bufferptr - buffer_start) % 64 != 0) {
  ------------------
  |  Branch (147:7): [True: 195, False: 1.07k]
  ------------------
  148|  1.71k|    while (buffer_start + 4 < bufferptr) {
  ------------------
  |  Branch (148:12): [True: 1.52k, False: 195]
  ------------------
  149|  1.52k|      uint32_t triple = ((uint32_t(uint8_t(buffer_start[0])) << 3 * 6) +
  150|  1.52k|                         (uint32_t(uint8_t(buffer_start[1])) << 2 * 6) +
  151|  1.52k|                         (uint32_t(uint8_t(buffer_start[2])) << 1 * 6) +
  152|  1.52k|                         (uint32_t(uint8_t(buffer_start[3])) << 0 * 6))
  153|  1.52k|                        << 8;
  154|  1.52k|#if !SIMDUTF_IS_BIG_ENDIAN
  155|  1.52k|      triple = scalar::u32_swap_bytes(triple);
  156|  1.52k|#endif
  157|  1.52k|      std::memcpy(dst, &triple, 3);
  158|       |
  159|  1.52k|      dst += 3;
  160|  1.52k|      buffer_start += 4;
  161|  1.52k|    }
  162|    195|    if (buffer_start + 4 <= bufferptr) {
  ------------------
  |  Branch (162:9): [True: 49, False: 146]
  ------------------
  163|     49|      uint32_t triple = ((uint32_t(uint8_t(buffer_start[0])) << 3 * 6) +
  164|     49|                         (uint32_t(uint8_t(buffer_start[1])) << 2 * 6) +
  165|     49|                         (uint32_t(uint8_t(buffer_start[2])) << 1 * 6) +
  166|     49|                         (uint32_t(uint8_t(buffer_start[3])) << 0 * 6))
  167|     49|                        << 8;
  168|     49|#if !SIMDUTF_IS_BIG_ENDIAN
  169|     49|      triple = scalar::u32_swap_bytes(triple);
  170|     49|#endif
  171|     49|      std::memcpy(dst, &triple, 3);
  172|       |
  173|     49|      dst += 3;
  174|     49|      buffer_start += 4;
  175|     49|    }
  176|       |    // we may have 1, 2 or 3 bytes left and we need to decode them so let us
  177|       |    // backtrack
  178|    195|    int leftover = int(bufferptr - buffer_start);
  179|    509|    while (leftover > 0) {
  ------------------
  |  Branch (179:12): [True: 314, False: 195]
  ------------------
  180|    314|      if (!ignore_garbage) {
  ------------------
  |  Branch (180:11): [True: 314, Folded]
  ------------------
  181|  2.16k|        while (to_base64[uint8_t(*(src - 1))] == 64) {
  ------------------
  |  Branch (181:16): [True: 1.85k, False: 314]
  ------------------
  182|  1.85k|          src--;
  183|  1.85k|        }
  184|    314|      } 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|    314|      src--;
  190|    314|      leftover--;
  191|    314|    }
  192|    195|  }
  193|  1.26k|  if (src < srcend + equalsigns) {
  ------------------
  |  Branch (193:7): [True: 1.14k, False: 123]
  ------------------
  194|  1.14k|    full_result r = scalar::base64::base64_tail_decode(
  195|  1.14k|        dst, src, srcend - src, equalsigns, options, last_chunk_options);
  196|  1.14k|    r = scalar::base64::patch_tail_result(
  197|  1.14k|        r, size_t(src - srcinit), size_t(dst - dstinit), equallocation,
  198|  1.14k|        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.14k|    if (is_partial(last_chunk_options) && r.error == error_code::SUCCESS &&
  ------------------
  |  Branch (203:9): [True: 0, False: 1.14k]
  |  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.14k|    return r;
  220|  1.14k|  }
  221|    123|  if (!ignore_garbage && equalsigns > 0) {
  ------------------
  |  Branch (221:7): [True: 123, Folded]
  |  Branch (221:26): [True: 0, False: 123]
  ------------------
  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|    123|  return {SUCCESS, srclen, size_t(dst - dstinit)};
  229|    123|}

simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE13get_remainderEPh:
   57|  25.9k|buf_block_reader<STEP_SIZE>::get_remainder(uint8_t *dst) const {
   58|  25.9k|  if (len == idx) {
  ------------------
  |  Branch (58:7): [True: 21.7k, False: 4.14k]
  ------------------
   59|  21.7k|    return 0;
   60|  21.7k|  } // memcpy(dst, null, 0) will trigger an error with some sanitizers
   61|  4.14k|  std::memset(dst, 0x20,
   62|  4.14k|              STEP_SIZE); // std::memset STEP_SIZE because it is more efficient
   63|       |                          // to write out 8 or 16 bytes at once.
   64|  4.14k|  std::memcpy(dst, buf + idx, len - idx);
   65|  4.14k|  return len - idx;
   66|  25.9k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE13get_remainderEPh:
   57|  25.9k|buf_block_reader<STEP_SIZE>::get_remainder(uint8_t *dst) const {
   58|  25.9k|  if (len == idx) {
  ------------------
  |  Branch (58:7): [True: 22.7k, False: 3.19k]
  ------------------
   59|  22.7k|    return 0;
   60|  22.7k|  } // memcpy(dst, null, 0) will trigger an error with some sanitizers
   61|  3.19k|  std::memset(dst, 0x20,
   62|  3.19k|              STEP_SIZE); // std::memset STEP_SIZE because it is more efficient
   63|       |                          // to write out 8 or 16 bytes at once.
   64|  3.19k|  std::memcpy(dst, buf + idx, len - idx);
   65|  3.19k|  return len - idx;
   66|  25.9k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EEC2EPKhm:
   36|  26.1k|    : buf{_buf}, len{_len}, lenminusstep{len < STEP_SIZE ? 0 : len - STEP_SIZE},
  ------------------
  |  Branch (36:42): [True: 24.2k, False: 1.89k]
  ------------------
   37|  26.1k|      idx{0} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE14has_full_blockEv:
   45|  33.0k|simdutf_really_inline bool buf_block_reader<STEP_SIZE>::has_full_block() const {
   46|  33.0k|  return idx < lenminusstep;
   47|  33.0k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE10full_blockEv:
   51|  7.19k|buf_block_reader<STEP_SIZE>::full_block() const {
   52|  7.19k|  return &buf[idx];
   53|  7.19k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_116buf_block_readerILm64EE7advanceEv:
   69|  32.8k|simdutf_really_inline void buf_block_reader<STEP_SIZE>::advance() {
   70|  32.8k|  idx += STEP_SIZE;
   71|  32.8k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EEC2EPKhm:
   36|  26.1k|    : buf{_buf}, len{_len}, lenminusstep{len < STEP_SIZE ? 0 : len - STEP_SIZE},
  ------------------
  |  Branch (36:42): [True: 24.3k, False: 1.78k]
  ------------------
   37|  26.1k|      idx{0} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE14has_full_blockEv:
   45|  35.4k|simdutf_really_inline bool buf_block_reader<STEP_SIZE>::has_full_block() const {
   46|  35.4k|  return idx < lenminusstep;
   47|  35.4k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE10full_blockEv:
   51|  9.50k|buf_block_reader<STEP_SIZE>::full_block() const {
   52|  9.50k|  return &buf[idx];
   53|  9.50k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_116buf_block_readerILm64EE7advanceEv:
   69|  35.1k|simdutf_really_inline void buf_block_reader<STEP_SIZE>::advance() {
   70|  35.1k|  idx += STEP_SIZE;
   71|  35.1k|}

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf3222utf8_length_from_utf32EPKDim:
   11|  4.66k|                                                    size_t length) {
   12|  4.66k|  using vector_u32 = simd32<uint32_t>;
   13|       |
   14|  4.66k|  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.66k|  const size_t max_increment = 3;
   19|       |
   20|  4.66k|  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.66k|  const auto v_ffffff80 = vector_u32::splat(0xffffff80);
   28|  4.66k|  const auto v_fffff800 = vector_u32::splat(0xfffff800);
   29|  4.66k|  const auto v_ffff0000 = vector_u32::splat(0xffff0000);
   30|  4.66k|  const auto one = vector_u32::splat(1);
   31|  4.66k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   32|       |
   33|  4.66k|  size_t counter = 0;
   34|       |
   35|       |  // 1. vectorized loop unrolled 4 times
   36|  4.66k|  {
   37|       |    // we use vector of uint32 counters, this is why this limit is used
   38|  4.66k|    const size_t max_iterations =
   39|  4.66k|        std::numeric_limits<uint32_t>::max() / (max_increment * 4);
   40|  4.66k|    size_t blocks = length / (N * 4);
   41|  4.66k|    length -= blocks * (N * 4);
   42|  4.89k|    while (blocks != 0) {
  ------------------
  |  Branch (42:12): [True: 227, False: 4.66k]
  ------------------
   43|    227|      const size_t iterations = min(blocks, max_iterations);
   44|    227|      blocks -= iterations;
   45|       |
   46|    227|      simd32<uint32_t> acc = vector_u32::zero();
   47|  1.85k|      for (size_t i = 0; i < iterations; i++) {
  ------------------
  |  Branch (47:26): [True: 1.62k, False: 227]
  ------------------
   48|  1.62k|        const auto in0 = vector_u32(input + 0 * N);
   49|  1.62k|        const auto in1 = vector_u32(input + 1 * N);
   50|  1.62k|        const auto in2 = vector_u32(input + 2 * N);
   51|  1.62k|        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.62k|        acc += min(one, in0 & v_ffffff80);
   70|  1.62k|        acc += min(one, in1 & v_ffffff80);
   71|  1.62k|        acc += min(one, in2 & v_ffffff80);
   72|  1.62k|        acc += min(one, in3 & v_ffffff80);
   73|       |
   74|  1.62k|        acc += min(one, in0 & v_fffff800);
   75|  1.62k|        acc += min(one, in1 & v_fffff800);
   76|  1.62k|        acc += min(one, in2 & v_fffff800);
   77|  1.62k|        acc += min(one, in3 & v_fffff800);
   78|       |
   79|  1.62k|        acc += min(one, in0 & v_ffff0000);
   80|  1.62k|        acc += min(one, in1 & v_ffff0000);
   81|  1.62k|        acc += min(one, in2 & v_ffff0000);
   82|  1.62k|        acc += min(one, in3 & v_ffff0000);
   83|  1.62k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   84|       |
   85|  1.62k|        input += 4 * N;
   86|  1.62k|      }
   87|       |
   88|    227|      counter += acc.sum();
   89|    227|    }
   90|  4.66k|  }
   91|       |
   92|       |  // 2. vectorized loop for tail
   93|  4.66k|  {
   94|  4.66k|    const size_t max_iterations =
   95|  4.66k|        std::numeric_limits<uint32_t>::max() / max_increment;
   96|  4.66k|    size_t blocks = length / N;
   97|  4.66k|    length -= blocks * N;
   98|  5.08k|    while (blocks != 0) {
  ------------------
  |  Branch (98:12): [True: 419, False: 4.66k]
  ------------------
   99|    419|      const size_t iterations = min(blocks, max_iterations);
  100|    419|      blocks -= iterations;
  101|       |
  102|    419|      auto acc = vector_u32::zero();
  103|  1.38k|      for (size_t i = 0; i < iterations; i++) {
  ------------------
  |  Branch (103:26): [True: 966, False: 419]
  ------------------
  104|    966|        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|    966|        acc += min(one, in & v_ffffff80);
  112|    966|        acc += min(one, in & v_fffff800);
  113|    966|        acc += min(one, in & v_ffff0000);
  114|    966|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
  115|       |
  116|    966|        input += N;
  117|    966|      }
  118|       |
  119|    419|      counter += acc.sum();
  120|    419|    }
  121|  4.66k|  }
  122|       |
  123|  4.66k|  const size_t consumed = input - start;
  124|  4.66k|  if (consumed != 0) {
  ------------------
  |  Branch (124:7): [True: 488, False: 4.18k]
  ------------------
  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|    488|    counter += consumed;
  128|    488|  }
  129|       |
  130|  4.66k|  return counter + scalar::utf32::utf8_length_from_utf32(input, length);
  131|  4.66k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf323minImEET_S4_S4_:
    8|    646|template <typename T> T min(T a, T b) { return a <= b ? a : b; }
  ------------------
  |  Branch (8:48): [True: 646, False: 0]
  ------------------
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf3222utf8_length_from_utf32EPKDim:
   11|  4.86k|                                                    size_t length) {
   12|  4.86k|  using vector_u32 = simd32<uint32_t>;
   13|       |
   14|  4.86k|  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.86k|  const size_t max_increment = 3;
   19|       |
   20|  4.86k|  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.86k|  const auto v_ffffff80 = vector_u32::splat(0xffffff80);
   28|  4.86k|  const auto v_fffff800 = vector_u32::splat(0xfffff800);
   29|  4.86k|  const auto v_ffff0000 = vector_u32::splat(0xffff0000);
   30|  4.86k|  const auto one = vector_u32::splat(1);
   31|  4.86k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   32|       |
   33|  4.86k|  size_t counter = 0;
   34|       |
   35|       |  // 1. vectorized loop unrolled 4 times
   36|  4.86k|  {
   37|       |    // we use vector of uint32 counters, this is why this limit is used
   38|  4.86k|    const size_t max_iterations =
   39|  4.86k|        std::numeric_limits<uint32_t>::max() / (max_increment * 4);
   40|  4.86k|    size_t blocks = length / (N * 4);
   41|  4.86k|    length -= blocks * (N * 4);
   42|  5.34k|    while (blocks != 0) {
  ------------------
  |  Branch (42:12): [True: 484, False: 4.86k]
  ------------------
   43|    484|      const size_t iterations = min(blocks, max_iterations);
   44|    484|      blocks -= iterations;
   45|       |
   46|    484|      simd32<uint32_t> acc = vector_u32::zero();
   47|  5.48k|      for (size_t i = 0; i < iterations; i++) {
  ------------------
  |  Branch (47:26): [True: 5.00k, False: 484]
  ------------------
   48|  5.00k|        const auto in0 = vector_u32(input + 0 * N);
   49|  5.00k|        const auto in1 = vector_u32(input + 1 * N);
   50|  5.00k|        const auto in2 = vector_u32(input + 2 * N);
   51|  5.00k|        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.00k|        acc += min(one, in0 & v_ffffff80);
   70|  5.00k|        acc += min(one, in1 & v_ffffff80);
   71|  5.00k|        acc += min(one, in2 & v_ffffff80);
   72|  5.00k|        acc += min(one, in3 & v_ffffff80);
   73|       |
   74|  5.00k|        acc += min(one, in0 & v_fffff800);
   75|  5.00k|        acc += min(one, in1 & v_fffff800);
   76|  5.00k|        acc += min(one, in2 & v_fffff800);
   77|  5.00k|        acc += min(one, in3 & v_fffff800);
   78|       |
   79|  5.00k|        acc += min(one, in0 & v_ffff0000);
   80|  5.00k|        acc += min(one, in1 & v_ffff0000);
   81|  5.00k|        acc += min(one, in2 & v_ffff0000);
   82|  5.00k|        acc += min(one, in3 & v_ffff0000);
   83|  5.00k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   84|       |
   85|  5.00k|        input += 4 * N;
   86|  5.00k|      }
   87|       |
   88|    484|      counter += acc.sum();
   89|    484|    }
   90|  4.86k|  }
   91|       |
   92|       |  // 2. vectorized loop for tail
   93|  4.86k|  {
   94|  4.86k|    const size_t max_iterations =
   95|  4.86k|        std::numeric_limits<uint32_t>::max() / max_increment;
   96|  4.86k|    size_t blocks = length / N;
   97|  4.86k|    length -= blocks * N;
   98|  5.28k|    while (blocks != 0) {
  ------------------
  |  Branch (98:12): [True: 426, False: 4.86k]
  ------------------
   99|    426|      const size_t iterations = min(blocks, max_iterations);
  100|    426|      blocks -= iterations;
  101|       |
  102|    426|      auto acc = vector_u32::zero();
  103|  1.41k|      for (size_t i = 0; i < iterations; i++) {
  ------------------
  |  Branch (103:26): [True: 990, False: 426]
  ------------------
  104|    990|        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|    990|        acc += min(one, in & v_ffffff80);
  112|    990|        acc += min(one, in & v_fffff800);
  113|    990|        acc += min(one, in & v_ffff0000);
  114|    990|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
  115|       |
  116|    990|        input += N;
  117|    990|      }
  118|       |
  119|    426|      counter += acc.sum();
  120|    426|    }
  121|  4.86k|  }
  122|       |
  123|  4.86k|  const size_t consumed = input - start;
  124|  4.86k|  if (consumed != 0) {
  ------------------
  |  Branch (124:7): [True: 524, False: 4.33k]
  ------------------
  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|    524|    counter += consumed;
  128|    524|  }
  129|       |
  130|  4.86k|  return counter + scalar::utf32::utf8_length_from_utf32(input, length);
  131|  4.86k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf323minImEET_S4_S4_:
    8|    910|template <typename T> T min(T a, T b) { return a <= b ? a : b; }
  ------------------
  |  Branch (8:48): [True: 910, False: 0]
  ------------------

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

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoderC2Ev:
  101|  10.5k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoder7convertEPKcmPc:
  115|  10.5k|                                       char *latin1_output) {
  116|  10.5k|    size_t pos = 0;
  117|  10.5k|    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|  10.5k|    size_t leading_byte = 0;
  125|  10.5k|    size_t margin = size;
  126|  49.4k|    for (; margin > 0 && leading_byte < 16; margin--) {
  ------------------
  |  Branch (126:12): [True: 40.3k, False: 9.00k]
  |  Branch (126:26): [True: 38.8k, False: 1.52k]
  ------------------
  127|  38.8k|      leading_byte += (int8_t(in[margin - 1]) >
  128|  38.8k|                       -65); // twos complement of -65 is 1011 1111 ...
  129|  38.8k|    }
  130|       |    // If the input is long enough, then we have that margin-1 is the eight last
  131|       |    // leading byte.
  132|  10.5k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  133|  14.5k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (133:12): [True: 3.96k, False: 10.5k]
  ------------------
  134|  3.96k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  135|  3.96k|      if (input.is_ascii()) {
  ------------------
  |  Branch (135:11): [True: 1.68k, False: 2.28k]
  ------------------
  136|  1.68k|        input.store((int8_t *)latin1_output);
  137|  1.68k|        latin1_output += 64;
  138|  1.68k|        pos += 64;
  139|  2.28k|      } else {
  140|       |        // you might think that a for-loop would work, but under Visual Studio,
  141|       |        // it is not good enough.
  142|  2.28k|        static_assert(
  143|  2.28k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  144|  2.28k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  145|  2.28k|            "We support either two or four chunks per 64-byte block.");
  146|  2.28k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  147|  2.28k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  148|  2.28k|          this->check_utf8_bytes(input.chunks[0], zero);
  149|  2.28k|          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.28k|        uint64_t utf8_continuation_mask =
  157|  2.28k|            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.28k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (159:13): [True: 5, False: 2.27k]
  ------------------
  160|      5|          return 0; // error
  161|      5|        }
  162|  2.27k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  163|  2.27k|        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.27k|        size_t max_starting_point = (pos + 64) - 12;
  168|       |        // Next loop is going to run at least five times.
  169|  18.8k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (169:16): [True: 16.5k, False: 2.27k]
  ------------------
  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|  16.5k|          size_t consumed = convert_masked_utf8_to_latin1(
  180|  16.5k|              in + pos, utf8_end_of_code_point_mask, latin1_output);
  181|  16.5k|          pos += consumed;
  182|  16.5k|          utf8_end_of_code_point_mask >>= consumed;
  183|  16.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.27k|      }
  189|  3.96k|    }
  190|  10.5k|    if (errors()) {
  ------------------
  |  Branch (190:9): [True: 175, False: 10.3k]
  ------------------
  191|    175|      return 0;
  192|    175|    }
  193|  10.3k|    if (pos < size) {
  ------------------
  |  Branch (193:9): [True: 2.30k, False: 8.04k]
  ------------------
  194|  2.30k|      size_t howmany =
  195|  2.30k|          scalar::utf8_to_latin1::convert(in + pos, size - pos, latin1_output);
  196|  2.30k|      if (howmany == 0) {
  ------------------
  |  Branch (196:11): [True: 940, False: 1.36k]
  ------------------
  197|    940|        return 0;
  198|    940|      }
  199|  1.36k|      latin1_output += howmany;
  200|  1.36k|    }
  201|  9.41k|    return latin1_output - start;
  202|  10.3k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  106|  4.56k|                                              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.56k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  111|  4.56k|    this->error |= check_special_cases(input, prev1);
  112|  4.56k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin119check_special_casesENS1_4simd5simd8IhEES5_:
    8|  4.56k|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.56k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   20|       |                                               // 11______ 11______
   21|  4.56k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   22|  4.56k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   23|  4.56k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   24|  4.56k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   25|  4.56k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   26|  4.56k|  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.56k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   35|       |  // 11110101 1000____
   36|       |  // 1111011_ 1000____
   37|       |  // 11111___ 1000____
   38|  4.56k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   39|  4.56k|  constexpr const uint8_t FORBIDDEN = 0xff;
   40|       |
   41|  4.56k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   42|       |      // 0_______ ________ <ASCII in byte 1>
   43|  4.56k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   44|  4.56k|      TOO_LONG,
   45|       |      // 10______ ________ <continuation in byte 1>
   46|  4.56k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   47|       |      // 1100____ ________ <two byte lead in byte 1>
   48|  4.56k|      TOO_SHORT | OVERLONG_2,
   49|       |      // 1101____ ________ <two byte lead in byte 1>
   50|  4.56k|      FORBIDDEN,
   51|       |      // 1110____ ________ <three byte lead in byte 1>
   52|  4.56k|      FORBIDDEN,
   53|       |      // 1111____ ________ <four+ byte lead in byte 1>
   54|  4.56k|      FORBIDDEN);
   55|  4.56k|  constexpr const uint8_t CARRY =
   56|  4.56k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   57|  4.56k|  const simd8<uint8_t> byte_1_low =
   58|  4.56k|      (prev1 & 0x0F)
   59|  4.56k|          .lookup_16<uint8_t>(
   60|       |              // ____0000 ________
   61|  4.56k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   62|       |              // ____0001 ________
   63|  4.56k|              CARRY | OVERLONG_2,
   64|       |              // ____001_ ________
   65|  4.56k|              CARRY, CARRY,
   66|       |
   67|       |              // ____0100 ________
   68|  4.56k|              FORBIDDEN,
   69|       |              // ____0101 ________
   70|  4.56k|              FORBIDDEN,
   71|       |              // ____011_ ________
   72|  4.56k|              FORBIDDEN, FORBIDDEN,
   73|       |
   74|       |              // ____1___ ________
   75|  4.56k|              FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
   76|       |              // ____1101 ________
   77|  4.56k|              FORBIDDEN, FORBIDDEN, FORBIDDEN);
   78|  4.56k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   79|       |      // ________ 0_______ <ASCII in byte 2>
   80|  4.56k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   81|  4.56k|      TOO_SHORT, TOO_SHORT,
   82|       |
   83|       |      // ________ 1000____
   84|  4.56k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   85|  4.56k|          OVERLONG_4,
   86|       |      // ________ 1001____
   87|  4.56k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   88|       |      // ________ 101_____
   89|  4.56k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   90|  4.56k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   91|       |
   92|       |      // ________ 11______
   93|  4.56k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   94|  4.56k|  return (byte_1_high & byte_1_low & byte_2_high);
   95|  4.56k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoder6errorsEv:
  308|  10.5k|  simdutf_really_inline bool errors() const {
  309|  10.5k|    return this->error.any_bits_set_anywhere();
  310|  10.5k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoderC2Ev:
  101|  10.5k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoder7convertEPKcmPc:
  115|  10.5k|                                       char *latin1_output) {
  116|  10.5k|    size_t pos = 0;
  117|  10.5k|    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|  10.5k|    size_t leading_byte = 0;
  125|  10.5k|    size_t margin = size;
  126|  40.5k|    for (; margin > 0 && leading_byte < 16; margin--) {
  ------------------
  |  Branch (126:12): [True: 31.4k, False: 9.19k]
  |  Branch (126:26): [True: 30.0k, False: 1.34k]
  ------------------
  127|  30.0k|      leading_byte += (int8_t(in[margin - 1]) >
  128|  30.0k|                       -65); // twos complement of -65 is 1011 1111 ...
  129|  30.0k|    }
  130|       |    // If the input is long enough, then we have that margin-1 is the eight last
  131|       |    // leading byte.
  132|  10.5k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  133|  15.6k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (133:12): [True: 5.12k, False: 10.5k]
  ------------------
  134|  5.12k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  135|  5.12k|      if (input.is_ascii()) {
  ------------------
  |  Branch (135:11): [True: 2.03k, False: 3.08k]
  ------------------
  136|  2.03k|        input.store((int8_t *)latin1_output);
  137|  2.03k|        latin1_output += 64;
  138|  2.03k|        pos += 64;
  139|  3.08k|      } else {
  140|       |        // you might think that a for-loop would work, but under Visual Studio,
  141|       |        // it is not good enough.
  142|  3.08k|        static_assert(
  143|  3.08k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  144|  3.08k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  145|  3.08k|            "We support either two or four chunks per 64-byte block.");
  146|  3.08k|        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.08k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  151|  3.08k|          this->check_utf8_bytes(input.chunks[0], zero);
  152|  3.08k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  153|  3.08k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  154|  3.08k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  155|  3.08k|        }
  156|  3.08k|        uint64_t utf8_continuation_mask =
  157|  3.08k|            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.08k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (159:13): [True: 11, False: 3.07k]
  ------------------
  160|     11|          return 0; // error
  161|     11|        }
  162|  3.07k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  163|  3.07k|        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.07k|        size_t max_starting_point = (pos + 64) - 12;
  168|       |        // Next loop is going to run at least five times.
  169|  25.6k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (169:16): [True: 22.5k, False: 3.07k]
  ------------------
  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|  22.5k|          size_t consumed = convert_masked_utf8_to_latin1(
  180|  22.5k|              in + pos, utf8_end_of_code_point_mask, latin1_output);
  181|  22.5k|          pos += consumed;
  182|  22.5k|          utf8_end_of_code_point_mask >>= consumed;
  183|  22.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|  3.07k|      }
  189|  5.12k|    }
  190|  10.5k|    if (errors()) {
  ------------------
  |  Branch (190:9): [True: 218, False: 10.3k]
  ------------------
  191|    218|      return 0;
  192|    218|    }
  193|  10.3k|    if (pos < size) {
  ------------------
  |  Branch (193:9): [True: 1.64k, False: 8.66k]
  ------------------
  194|  1.64k|      size_t howmany =
  195|  1.64k|          scalar::utf8_to_latin1::convert(in + pos, size - pos, latin1_output);
  196|  1.64k|      if (howmany == 0) {
  ------------------
  |  Branch (196:11): [True: 588, False: 1.05k]
  ------------------
  197|    588|        return 0;
  198|    588|      }
  199|  1.05k|      latin1_output += howmany;
  200|  1.05k|    }
  201|  9.71k|    return latin1_output - start;
  202|  10.3k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  106|  12.3k|                                              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.3k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  111|  12.3k|    this->error |= check_special_cases(input, prev1);
  112|  12.3k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin119check_special_casesENS1_4simd5simd8IhEES5_:
    8|  12.3k|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.3k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   20|       |                                               // 11______ 11______
   21|  12.3k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   22|  12.3k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   23|  12.3k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   24|  12.3k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   25|  12.3k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   26|  12.3k|  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.3k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   35|       |  // 11110101 1000____
   36|       |  // 1111011_ 1000____
   37|       |  // 11111___ 1000____
   38|  12.3k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   39|  12.3k|  constexpr const uint8_t FORBIDDEN = 0xff;
   40|       |
   41|  12.3k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   42|       |      // 0_______ ________ <ASCII in byte 1>
   43|  12.3k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   44|  12.3k|      TOO_LONG,
   45|       |      // 10______ ________ <continuation in byte 1>
   46|  12.3k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   47|       |      // 1100____ ________ <two byte lead in byte 1>
   48|  12.3k|      TOO_SHORT | OVERLONG_2,
   49|       |      // 1101____ ________ <two byte lead in byte 1>
   50|  12.3k|      FORBIDDEN,
   51|       |      // 1110____ ________ <three byte lead in byte 1>
   52|  12.3k|      FORBIDDEN,
   53|       |      // 1111____ ________ <four+ byte lead in byte 1>
   54|  12.3k|      FORBIDDEN);
   55|  12.3k|  constexpr const uint8_t CARRY =
   56|  12.3k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   57|  12.3k|  const simd8<uint8_t> byte_1_low =
   58|  12.3k|      (prev1 & 0x0F)
   59|  12.3k|          .lookup_16<uint8_t>(
   60|       |              // ____0000 ________
   61|  12.3k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   62|       |              // ____0001 ________
   63|  12.3k|              CARRY | OVERLONG_2,
   64|       |              // ____001_ ________
   65|  12.3k|              CARRY, CARRY,
   66|       |
   67|       |              // ____0100 ________
   68|  12.3k|              FORBIDDEN,
   69|       |              // ____0101 ________
   70|  12.3k|              FORBIDDEN,
   71|       |              // ____011_ ________
   72|  12.3k|              FORBIDDEN, FORBIDDEN,
   73|       |
   74|       |              // ____1___ ________
   75|  12.3k|              FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
   76|       |              // ____1101 ________
   77|  12.3k|              FORBIDDEN, FORBIDDEN, FORBIDDEN);
   78|  12.3k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   79|       |      // ________ 0_______ <ASCII in byte 2>
   80|  12.3k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   81|  12.3k|      TOO_SHORT, TOO_SHORT,
   82|       |
   83|       |      // ________ 1000____
   84|  12.3k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   85|  12.3k|          OVERLONG_4,
   86|       |      // ________ 1001____
   87|  12.3k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   88|       |      // ________ 101_____
   89|  12.3k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   90|  12.3k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   91|       |
   92|       |      // ________ 11______
   93|  12.3k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   94|  12.3k|  return (byte_1_high & byte_1_low & byte_2_high);
   95|  12.3k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoder6errorsEv:
  308|  10.5k|  simdutf_really_inline bool errors() const {
  309|  10.5k|    return this->error.any_bits_set_anywhere();
  310|  10.5k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoderC2Ev:
  114|  20.8k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoderC2Ev:
  114|  20.8k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder7convertILNS_10endiannessE0EEEmPKcmPDs:
  130|  10.4k|                                       char16_t *utf16_output) {
  131|  10.4k|    size_t pos = 0;
  132|  10.4k|    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|  10.4k|    size_t leading_byte = 0;
  140|  10.4k|    size_t margin = size;
  141|  27.3k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (141:12): [True: 17.8k, False: 9.42k]
  |  Branch (141:26): [True: 16.8k, False: 1.01k]
  ------------------
  142|  16.8k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  143|  16.8k|    }
  144|       |    // If the input is long enough, then we have that margin-1 is the eight last
  145|       |    // leading byte.
  146|  10.4k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  147|  13.0k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (147:12): [True: 2.64k, False: 10.4k]
  ------------------
  148|  2.64k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  149|  2.64k|      if (input.is_ascii()) {
  ------------------
  |  Branch (149:11): [True: 578, False: 2.06k]
  ------------------
  150|    578|        input.store_ascii_as_utf16<endian>(utf16_output);
  151|    578|        utf16_output += 64;
  152|    578|        pos += 64;
  153|  2.06k|      } else {
  154|       |        // you might think that a for-loop would work, but under Visual Studio,
  155|       |        // it is not good enough.
  156|  2.06k|        static_assert(
  157|  2.06k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  158|  2.06k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  159|  2.06k|            "We support either two or four chunks per 64-byte block.");
  160|  2.06k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  161|  2.06k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  162|  2.06k|          this->check_utf8_bytes(input.chunks[0], zero);
  163|  2.06k|          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.06k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  171|  2.06k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (171:13): [True: 7, False: 2.06k]
  ------------------
  172|      7|          return 0; // error
  173|      7|        }
  174|  2.06k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  175|  2.06k|        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.06k|        size_t max_starting_point = (pos + 64) - 12;
  180|       |        // Next loop is going to run at least five times.
  181|  17.2k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (181:16): [True: 15.1k, False: 2.06k]
  ------------------
  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.1k|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  192|  15.1k|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  193|  15.1k|          pos += consumed;
  194|  15.1k|          utf8_end_of_code_point_mask >>= consumed;
  195|  15.1k|        }
  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.06k|      }
  201|  2.64k|    }
  202|  10.4k|    if (errors()) {
  ------------------
  |  Branch (202:9): [True: 193, False: 10.2k]
  ------------------
  203|    193|      return 0;
  204|    193|    }
  205|  10.2k|    if (pos < size) {
  ------------------
  |  Branch (205:9): [True: 1.44k, False: 8.79k]
  ------------------
  206|  1.44k|      size_t howmany = scalar::utf8_to_utf16::convert<endian>(
  207|  1.44k|          in + pos, size - pos, utf16_output);
  208|  1.44k|      if (howmany == 0) {
  ------------------
  |  Branch (208:11): [True: 400, False: 1.04k]
  ------------------
  209|    400|        return 0;
  210|    400|      }
  211|  1.04k|      utf16_output += howmany;
  212|  1.04k|    }
  213|  9.83k|    return utf16_output - start;
  214|  10.2k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  119|  8.46k|                                              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.46k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  124|  8.46k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  125|  8.46k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  126|  8.46k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1619check_special_casesENS1_4simd5simd8IhEES5_:
    8|  8.46k|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.46k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   16|       |                                               // 11______ 11______
   17|  8.46k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   18|  8.46k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   19|  8.46k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   20|  8.46k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   21|  8.46k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   22|  8.46k|  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.46k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   31|       |  // 11110101 1000____
   32|       |  // 1111011_ 1000____
   33|       |  // 11111___ 1000____
   34|  8.46k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   35|       |
   36|  8.46k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   37|       |      // 0_______ ________ <ASCII in byte 1>
   38|  8.46k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   39|  8.46k|      TOO_LONG,
   40|       |      // 10______ ________ <continuation in byte 1>
   41|  8.46k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   42|       |      // 1100____ ________ <two byte lead in byte 1>
   43|  8.46k|      TOO_SHORT | OVERLONG_2,
   44|       |      // 1101____ ________ <two byte lead in byte 1>
   45|  8.46k|      TOO_SHORT,
   46|       |      // 1110____ ________ <three byte lead in byte 1>
   47|  8.46k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   48|       |      // 1111____ ________ <four+ byte lead in byte 1>
   49|  8.46k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   50|  8.46k|  constexpr const uint8_t CARRY =
   51|  8.46k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   52|  8.46k|  const simd8<uint8_t> byte_1_low =
   53|  8.46k|      (prev1 & 0x0F)
   54|  8.46k|          .lookup_16<uint8_t>(
   55|       |              // ____0000 ________
   56|  8.46k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   57|       |              // ____0001 ________
   58|  8.46k|              CARRY | OVERLONG_2,
   59|       |              // ____001_ ________
   60|  8.46k|              CARRY, CARRY,
   61|       |
   62|       |              // ____0100 ________
   63|  8.46k|              CARRY | TOO_LARGE,
   64|       |              // ____0101 ________
   65|  8.46k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   66|       |              // ____011_ ________
   67|  8.46k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   68|  8.46k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|       |
   70|       |              // ____1___ ________
   71|  8.46k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   72|  8.46k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  8.46k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  8.46k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  8.46k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|       |              // ____1101 ________
   77|  8.46k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   78|  8.46k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   79|  8.46k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   80|  8.46k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   81|       |      // ________ 0_______ <ASCII in byte 2>
   82|  8.46k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   83|  8.46k|      TOO_SHORT, TOO_SHORT,
   84|       |
   85|       |      // ________ 1000____
   86|  8.46k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   87|  8.46k|          OVERLONG_4,
   88|       |      // ________ 1001____
   89|  8.46k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   90|       |      // ________ 101_____
   91|  8.46k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   92|  8.46k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|       |
   94|       |      // ________ 11______
   95|  8.46k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   96|  8.46k|  return (byte_1_high & byte_1_low & byte_2_high);
   97|  8.46k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1623check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  101|  8.46k|                        const simd8<uint8_t> sc) {
  102|  8.46k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  103|  8.46k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  104|  8.46k|  simd8<uint8_t> must23 =
  105|  8.46k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  106|  8.46k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  107|  8.46k|  return must23_80 ^ sc;
  108|  8.46k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder6errorsEv:
  324|  20.8k|  simdutf_really_inline bool errors() const {
  325|  20.8k|    return this->error.any_bits_set_anywhere();
  326|  20.8k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder7convertILNS_10endiannessE1EEEmPKcmPDs:
  130|  10.4k|                                       char16_t *utf16_output) {
  131|  10.4k|    size_t pos = 0;
  132|  10.4k|    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|  10.4k|    size_t leading_byte = 0;
  140|  10.4k|    size_t margin = size;
  141|  27.6k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (141:12): [True: 18.2k, False: 9.42k]
  |  Branch (141:26): [True: 17.1k, False: 1.02k]
  ------------------
  142|  17.1k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  143|  17.1k|    }
  144|       |    // If the input is long enough, then we have that margin-1 is the eight last
  145|       |    // leading byte.
  146|  10.4k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  147|  13.1k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (147:12): [True: 2.74k, False: 10.4k]
  ------------------
  148|  2.74k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  149|  2.74k|      if (input.is_ascii()) {
  ------------------
  |  Branch (149:11): [True: 584, False: 2.16k]
  ------------------
  150|    584|        input.store_ascii_as_utf16<endian>(utf16_output);
  151|    584|        utf16_output += 64;
  152|    584|        pos += 64;
  153|  2.16k|      } else {
  154|       |        // you might think that a for-loop would work, but under Visual Studio,
  155|       |        // it is not good enough.
  156|  2.16k|        static_assert(
  157|  2.16k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  158|  2.16k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  159|  2.16k|            "We support either two or four chunks per 64-byte block.");
  160|  2.16k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  161|  2.16k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  162|  2.16k|          this->check_utf8_bytes(input.chunks[0], zero);
  163|  2.16k|          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.16k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  171|  2.16k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (171:13): [True: 7, False: 2.15k]
  ------------------
  172|      7|          return 0; // error
  173|      7|        }
  174|  2.15k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  175|  2.15k|        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.15k|        size_t max_starting_point = (pos + 64) - 12;
  180|       |        // Next loop is going to run at least five times.
  181|  17.7k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (181:16): [True: 15.6k, False: 2.15k]
  ------------------
  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.15k|      }
  201|  2.74k|    }
  202|  10.4k|    if (errors()) {
  ------------------
  |  Branch (202:9): [True: 193, False: 10.2k]
  ------------------
  203|    193|      return 0;
  204|    193|    }
  205|  10.2k|    if (pos < size) {
  ------------------
  |  Branch (205:9): [True: 1.45k, False: 8.79k]
  ------------------
  206|  1.45k|      size_t howmany = scalar::utf8_to_utf16::convert<endian>(
  207|  1.45k|          in + pos, size - pos, utf16_output);
  208|  1.45k|      if (howmany == 0) {
  ------------------
  |  Branch (208:11): [True: 400, False: 1.05k]
  ------------------
  209|    400|        return 0;
  210|    400|      }
  211|  1.05k|      utf16_output += howmany;
  212|  1.05k|    }
  213|  9.84k|    return utf16_output - start;
  214|  10.2k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder7convertILNS_10endiannessE0EEEmPKcmPDs:
  130|  10.4k|                                       char16_t *utf16_output) {
  131|  10.4k|    size_t pos = 0;
  132|  10.4k|    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|  10.4k|    size_t leading_byte = 0;
  140|  10.4k|    size_t margin = size;
  141|  23.5k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (141:12): [True: 14.0k, False: 9.47k]
  |  Branch (141:26): [True: 13.1k, False: 950]
  ------------------
  142|  13.1k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  143|  13.1k|    }
  144|       |    // If the input is long enough, then we have that margin-1 is the eight last
  145|       |    // leading byte.
  146|  10.4k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  147|  14.3k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (147:12): [True: 3.89k, False: 10.4k]
  ------------------
  148|  3.89k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  149|  3.89k|      if (input.is_ascii()) {
  ------------------
  |  Branch (149:11): [True: 916, False: 2.97k]
  ------------------
  150|    916|        input.store_ascii_as_utf16<endian>(utf16_output);
  151|    916|        utf16_output += 64;
  152|    916|        pos += 64;
  153|  2.97k|      } else {
  154|       |        // you might think that a for-loop would work, but under Visual Studio,
  155|       |        // it is not good enough.
  156|  2.97k|        static_assert(
  157|  2.97k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  158|  2.97k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  159|  2.97k|            "We support either two or four chunks per 64-byte block.");
  160|  2.97k|        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|  2.97k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  165|  2.97k|          this->check_utf8_bytes(input.chunks[0], zero);
  166|  2.97k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  167|  2.97k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  168|  2.97k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  169|  2.97k|        }
  170|  2.97k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  171|  2.97k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (171:13): [True: 13, False: 2.96k]
  ------------------
  172|     13|          return 0; // error
  173|     13|        }
  174|  2.96k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  175|  2.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|  2.96k|        size_t max_starting_point = (pos + 64) - 12;
  180|       |        // Next loop is going to run at least five times.
  181|  23.8k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (181:16): [True: 20.8k, False: 2.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|  20.8k|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  192|  20.8k|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  193|  20.8k|          pos += consumed;
  194|  20.8k|          utf8_end_of_code_point_mask >>= consumed;
  195|  20.8k|        }
  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.96k|      }
  201|  3.89k|    }
  202|  10.4k|    if (errors()) {
  ------------------
  |  Branch (202:9): [True: 198, False: 10.2k]
  ------------------
  203|    198|      return 0;
  204|    198|    }
  205|  10.2k|    if (pos < size) {
  ------------------
  |  Branch (205:9): [True: 1.11k, False: 9.10k]
  ------------------
  206|  1.11k|      size_t howmany = scalar::utf8_to_utf16::convert<endian>(
  207|  1.11k|          in + pos, size - pos, utf16_output);
  208|  1.11k|      if (howmany == 0) {
  ------------------
  |  Branch (208:11): [True: 195, False: 923]
  ------------------
  209|    195|        return 0;
  210|    195|      }
  211|    923|      utf16_output += howmany;
  212|    923|    }
  213|  10.0k|    return utf16_output - start;
  214|  10.2k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  119|  24.4k|                                              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|  24.4k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  124|  24.4k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  125|  24.4k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  126|  24.4k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1619check_special_casesENS1_4simd5simd8IhEES5_:
    8|  24.4k|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|  24.4k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   16|       |                                               // 11______ 11______
   17|  24.4k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   18|  24.4k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   19|  24.4k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   20|  24.4k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   21|  24.4k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   22|  24.4k|  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|  24.4k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   31|       |  // 11110101 1000____
   32|       |  // 1111011_ 1000____
   33|       |  // 11111___ 1000____
   34|  24.4k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   35|       |
   36|  24.4k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   37|       |      // 0_______ ________ <ASCII in byte 1>
   38|  24.4k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   39|  24.4k|      TOO_LONG,
   40|       |      // 10______ ________ <continuation in byte 1>
   41|  24.4k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   42|       |      // 1100____ ________ <two byte lead in byte 1>
   43|  24.4k|      TOO_SHORT | OVERLONG_2,
   44|       |      // 1101____ ________ <two byte lead in byte 1>
   45|  24.4k|      TOO_SHORT,
   46|       |      // 1110____ ________ <three byte lead in byte 1>
   47|  24.4k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   48|       |      // 1111____ ________ <four+ byte lead in byte 1>
   49|  24.4k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   50|  24.4k|  constexpr const uint8_t CARRY =
   51|  24.4k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   52|  24.4k|  const simd8<uint8_t> byte_1_low =
   53|  24.4k|      (prev1 & 0x0F)
   54|  24.4k|          .lookup_16<uint8_t>(
   55|       |              // ____0000 ________
   56|  24.4k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   57|       |              // ____0001 ________
   58|  24.4k|              CARRY | OVERLONG_2,
   59|       |              // ____001_ ________
   60|  24.4k|              CARRY, CARRY,
   61|       |
   62|       |              // ____0100 ________
   63|  24.4k|              CARRY | TOO_LARGE,
   64|       |              // ____0101 ________
   65|  24.4k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   66|       |              // ____011_ ________
   67|  24.4k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   68|  24.4k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|       |
   70|       |              // ____1___ ________
   71|  24.4k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   72|  24.4k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  24.4k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  24.4k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  24.4k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|       |              // ____1101 ________
   77|  24.4k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   78|  24.4k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   79|  24.4k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   80|  24.4k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   81|       |      // ________ 0_______ <ASCII in byte 2>
   82|  24.4k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   83|  24.4k|      TOO_SHORT, TOO_SHORT,
   84|       |
   85|       |      // ________ 1000____
   86|  24.4k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   87|  24.4k|          OVERLONG_4,
   88|       |      // ________ 1001____
   89|  24.4k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   90|       |      // ________ 101_____
   91|  24.4k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   92|  24.4k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|       |
   94|       |      // ________ 11______
   95|  24.4k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   96|  24.4k|  return (byte_1_high & byte_1_low & byte_2_high);
   97|  24.4k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1623check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  101|  24.4k|                        const simd8<uint8_t> sc) {
  102|  24.4k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  103|  24.4k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  104|  24.4k|  simd8<uint8_t> must23 =
  105|  24.4k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  106|  24.4k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  107|  24.4k|  return must23_80 ^ sc;
  108|  24.4k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder6errorsEv:
  324|  20.8k|  simdutf_really_inline bool errors() const {
  325|  20.8k|    return this->error.any_bits_set_anywhere();
  326|  20.8k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder7convertILNS_10endiannessE1EEEmPKcmPDs:
  130|  10.4k|                                       char16_t *utf16_output) {
  131|  10.4k|    size_t pos = 0;
  132|  10.4k|    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|  10.4k|    size_t leading_byte = 0;
  140|  10.4k|    size_t margin = size;
  141|  23.6k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (141:12): [True: 14.1k, False: 9.48k]
  |  Branch (141:26): [True: 13.2k, False: 952]
  ------------------
  142|  13.2k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  143|  13.2k|    }
  144|       |    // If the input is long enough, then we have that margin-1 is the eight last
  145|       |    // leading byte.
  146|  10.4k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  147|  14.4k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (147:12): [True: 4.05k, False: 10.4k]
  ------------------
  148|  4.05k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  149|  4.05k|      if (input.is_ascii()) {
  ------------------
  |  Branch (149:11): [True: 915, False: 3.13k]
  ------------------
  150|    915|        input.store_ascii_as_utf16<endian>(utf16_output);
  151|    915|        utf16_output += 64;
  152|    915|        pos += 64;
  153|  3.13k|      } else {
  154|       |        // you might think that a for-loop would work, but under Visual Studio,
  155|       |        // it is not good enough.
  156|  3.13k|        static_assert(
  157|  3.13k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  158|  3.13k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  159|  3.13k|            "We support either two or four chunks per 64-byte block.");
  160|  3.13k|        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.13k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  165|  3.13k|          this->check_utf8_bytes(input.chunks[0], zero);
  166|  3.13k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  167|  3.13k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  168|  3.13k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  169|  3.13k|        }
  170|  3.13k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  171|  3.13k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (171:13): [True: 13, False: 3.12k]
  ------------------
  172|     13|          return 0; // error
  173|     13|        }
  174|  3.12k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  175|  3.12k|        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.12k|        size_t max_starting_point = (pos + 64) - 12;
  180|       |        // Next loop is going to run at least five times.
  181|  24.7k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (181:16): [True: 21.6k, False: 3.12k]
  ------------------
  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.6k|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  192|  21.6k|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  193|  21.6k|          pos += consumed;
  194|  21.6k|          utf8_end_of_code_point_mask >>= consumed;
  195|  21.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.12k|      }
  201|  4.05k|    }
  202|  10.4k|    if (errors()) {
  ------------------
  |  Branch (202:9): [True: 198, False: 10.2k]
  ------------------
  203|    198|      return 0;
  204|    198|    }
  205|  10.2k|    if (pos < size) {
  ------------------
  |  Branch (205:9): [True: 1.11k, False: 9.11k]
  ------------------
  206|  1.11k|      size_t howmany = scalar::utf8_to_utf16::convert<endian>(
  207|  1.11k|          in + pos, size - pos, utf16_output);
  208|  1.11k|      if (howmany == 0) {
  ------------------
  |  Branch (208:11): [True: 195, False: 920]
  ------------------
  209|    195|        return 0;
  210|    195|      }
  211|    920|      utf16_output += howmany;
  212|    920|    }
  213|  10.0k|    return utf16_output - start;
  214|  10.2k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoderC2Ev:
  114|  5.26k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoder7convertEPKcmPDi:
  129|  5.26k|                                       char32_t *utf32_output) {
  130|  5.26k|    size_t pos = 0;
  131|  5.26k|    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.26k|    size_t leading_byte = 0;
  139|  5.26k|    size_t margin = size;
  140|  17.6k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (140:12): [True: 13.2k, False: 4.42k]
  |  Branch (140:26): [True: 12.3k, False: 843]
  ------------------
  141|  12.3k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  142|  12.3k|    }
  143|       |    // If the input is long enough, then we have that margin-1 is the fourth
  144|       |    // last leading byte.
  145|  5.26k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  146|  7.03k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (146:12): [True: 1.76k, False: 5.26k]
  ------------------
  147|  1.76k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  148|  1.76k|      if (input.is_ascii()) {
  ------------------
  |  Branch (148:11): [True: 569, False: 1.20k]
  ------------------
  149|    569|        input.store_ascii_as_utf32(utf32_output);
  150|    569|        utf32_output += 64;
  151|    569|        pos += 64;
  152|  1.20k|      } else {
  153|       |        // you might think that a for-loop would work, but under Visual Studio,
  154|       |        // it is not good enough.
  155|  1.20k|        static_assert(
  156|  1.20k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  157|  1.20k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  158|  1.20k|            "We support either two or four chunks per 64-byte block.");
  159|  1.20k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  160|  1.20k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  161|  1.20k|          this->check_utf8_bytes(input.chunks[0], zero);
  162|  1.20k|          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.20k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  170|  1.20k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (170:13): [True: 7, False: 1.19k]
  ------------------
  171|      7|          return 0; // we have an error
  172|      7|        }
  173|  1.19k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  174|  1.19k|        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.19k|        size_t max_starting_point = (pos + 64) - 12;
  179|       |        // Next loop is going to run at least five times.
  180|  11.8k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (180:16): [True: 10.6k, False: 1.19k]
  ------------------
  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|  10.6k|          size_t consumed = convert_masked_utf8_to_utf32(
  191|  10.6k|              in + pos, utf8_end_of_code_point_mask, utf32_output);
  192|  10.6k|          pos += consumed;
  193|  10.6k|          utf8_end_of_code_point_mask >>= consumed;
  194|  10.6k|        }
  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.19k|      }
  200|  1.76k|    }
  201|  5.26k|    if (errors()) {
  ------------------
  |  Branch (201:9): [True: 193, False: 5.06k]
  ------------------
  202|    193|      return 0;
  203|    193|    }
  204|  5.06k|    if (pos < size) {
  ------------------
  |  Branch (204:9): [True: 1.18k, False: 3.88k]
  ------------------
  205|  1.18k|      size_t howmany =
  206|  1.18k|          scalar::utf8_to_utf32::convert(in + pos, size - pos, utf32_output);
  207|  1.18k|      if (howmany == 0) {
  ------------------
  |  Branch (207:11): [True: 400, False: 788]
  ------------------
  208|    400|        return 0;
  209|    400|      }
  210|    788|      utf32_output += howmany;
  211|    788|    }
  212|  4.66k|    return utf32_output - start;
  213|  5.06k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  119|  2.40k|                                              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.40k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  124|  2.40k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  125|  2.40k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  126|  2.40k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3219check_special_casesENS1_4simd5simd8IhEES5_:
    8|  2.40k|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.40k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   16|       |                                               // 11______ 11______
   17|  2.40k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   18|  2.40k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   19|  2.40k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   20|  2.40k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   21|  2.40k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   22|  2.40k|  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.40k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   31|       |  // 11110101 1000____
   32|       |  // 1111011_ 1000____
   33|       |  // 11111___ 1000____
   34|  2.40k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   35|       |
   36|  2.40k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   37|       |      // 0_______ ________ <ASCII in byte 1>
   38|  2.40k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   39|  2.40k|      TOO_LONG,
   40|       |      // 10______ ________ <continuation in byte 1>
   41|  2.40k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   42|       |      // 1100____ ________ <two byte lead in byte 1>
   43|  2.40k|      TOO_SHORT | OVERLONG_2,
   44|       |      // 1101____ ________ <two byte lead in byte 1>
   45|  2.40k|      TOO_SHORT,
   46|       |      // 1110____ ________ <three byte lead in byte 1>
   47|  2.40k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   48|       |      // 1111____ ________ <four+ byte lead in byte 1>
   49|  2.40k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   50|  2.40k|  constexpr const uint8_t CARRY =
   51|  2.40k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   52|  2.40k|  const simd8<uint8_t> byte_1_low =
   53|  2.40k|      (prev1 & 0x0F)
   54|  2.40k|          .lookup_16<uint8_t>(
   55|       |              // ____0000 ________
   56|  2.40k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   57|       |              // ____0001 ________
   58|  2.40k|              CARRY | OVERLONG_2,
   59|       |              // ____001_ ________
   60|  2.40k|              CARRY, CARRY,
   61|       |
   62|       |              // ____0100 ________
   63|  2.40k|              CARRY | TOO_LARGE,
   64|       |              // ____0101 ________
   65|  2.40k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   66|       |              // ____011_ ________
   67|  2.40k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   68|  2.40k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|       |
   70|       |              // ____1___ ________
   71|  2.40k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   72|  2.40k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  2.40k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  2.40k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  2.40k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|       |              // ____1101 ________
   77|  2.40k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   78|  2.40k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   79|  2.40k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   80|  2.40k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   81|       |      // ________ 0_______ <ASCII in byte 2>
   82|  2.40k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   83|  2.40k|      TOO_SHORT, TOO_SHORT,
   84|       |
   85|       |      // ________ 1000____
   86|  2.40k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   87|  2.40k|          OVERLONG_4,
   88|       |      // ________ 1001____
   89|  2.40k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   90|       |      // ________ 101_____
   91|  2.40k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   92|  2.40k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|       |
   94|       |      // ________ 11______
   95|  2.40k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   96|  2.40k|  return (byte_1_high & byte_1_low & byte_2_high);
   97|  2.40k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3223check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  101|  2.40k|                        const simd8<uint8_t> sc) {
  102|  2.40k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  103|  2.40k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  104|  2.40k|  simd8<uint8_t> must23 =
  105|  2.40k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  106|  2.40k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  107|  2.40k|  return must23_80 ^ sc;
  108|  2.40k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoder6errorsEv:
  310|  5.26k|  simdutf_really_inline bool errors() const {
  311|  5.26k|    return this->error.any_bits_set_anywhere();
  312|  5.26k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoderC2Ev:
  114|  5.26k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoder7convertEPKcmPDi:
  129|  5.26k|                                       char32_t *utf32_output) {
  130|  5.26k|    size_t pos = 0;
  131|  5.26k|    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.26k|    size_t leading_byte = 0;
  139|  5.26k|    size_t margin = size;
  140|  14.2k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (140:12): [True: 9.81k, False: 4.48k]
  |  Branch (140:26): [True: 9.03k, False: 779]
  ------------------
  141|  9.03k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  142|  9.03k|    }
  143|       |    // If the input is long enough, then we have that margin-1 is the fourth
  144|       |    // last leading byte.
  145|  5.26k|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  146|  7.83k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (146:12): [True: 2.58k, False: 5.25k]
  ------------------
  147|  2.58k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  148|  2.58k|      if (input.is_ascii()) {
  ------------------
  |  Branch (148:11): [True: 886, False: 1.69k]
  ------------------
  149|    886|        input.store_ascii_as_utf32(utf32_output);
  150|    886|        utf32_output += 64;
  151|    886|        pos += 64;
  152|  1.69k|      } else {
  153|       |        // you might think that a for-loop would work, but under Visual Studio,
  154|       |        // it is not good enough.
  155|  1.69k|        static_assert(
  156|  1.69k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  157|  1.69k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  158|  1.69k|            "We support either two or four chunks per 64-byte block.");
  159|  1.69k|        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.69k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  164|  1.69k|          this->check_utf8_bytes(input.chunks[0], zero);
  165|  1.69k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  166|  1.69k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  167|  1.69k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  168|  1.69k|        }
  169|  1.69k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  170|  1.69k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (170:13): [True: 13, False: 1.68k]
  ------------------
  171|     13|          return 0; // we have an error
  172|     13|        }
  173|  1.68k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  174|  1.68k|        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.68k|        size_t max_starting_point = (pos + 64) - 12;
  179|       |        // Next loop is going to run at least five times.
  180|  16.0k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (180:16): [True: 14.3k, False: 1.68k]
  ------------------
  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.3k|          size_t consumed = convert_masked_utf8_to_utf32(
  191|  14.3k|              in + pos, utf8_end_of_code_point_mask, utf32_output);
  192|  14.3k|          pos += consumed;
  193|  14.3k|          utf8_end_of_code_point_mask >>= consumed;
  194|  14.3k|        }
  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.68k|      }
  200|  2.58k|    }
  201|  5.25k|    if (errors()) {
  ------------------
  |  Branch (201:9): [True: 198, False: 5.05k]
  ------------------
  202|    198|      return 0;
  203|    198|    }
  204|  5.05k|    if (pos < size) {
  ------------------
  |  Branch (204:9): [True: 896, False: 4.16k]
  ------------------
  205|    896|      size_t howmany =
  206|    896|          scalar::utf8_to_utf32::convert(in + pos, size - pos, utf32_output);
  207|    896|      if (howmany == 0) {
  ------------------
  |  Branch (207:11): [True: 195, False: 701]
  ------------------
  208|    195|        return 0;
  209|    195|      }
  210|    701|      utf32_output += howmany;
  211|    701|    }
  212|  4.86k|    return utf32_output - start;
  213|  5.05k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  119|  6.77k|                                              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|  6.77k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  124|  6.77k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  125|  6.77k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  126|  6.77k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3219check_special_casesENS1_4simd5simd8IhEES5_:
    8|  6.77k|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|  6.77k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   16|       |                                               // 11______ 11______
   17|  6.77k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   18|  6.77k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   19|  6.77k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   20|  6.77k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   21|  6.77k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   22|  6.77k|  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|  6.77k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   31|       |  // 11110101 1000____
   32|       |  // 1111011_ 1000____
   33|       |  // 11111___ 1000____
   34|  6.77k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   35|       |
   36|  6.77k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   37|       |      // 0_______ ________ <ASCII in byte 1>
   38|  6.77k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   39|  6.77k|      TOO_LONG,
   40|       |      // 10______ ________ <continuation in byte 1>
   41|  6.77k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   42|       |      // 1100____ ________ <two byte lead in byte 1>
   43|  6.77k|      TOO_SHORT | OVERLONG_2,
   44|       |      // 1101____ ________ <two byte lead in byte 1>
   45|  6.77k|      TOO_SHORT,
   46|       |      // 1110____ ________ <three byte lead in byte 1>
   47|  6.77k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   48|       |      // 1111____ ________ <four+ byte lead in byte 1>
   49|  6.77k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   50|  6.77k|  constexpr const uint8_t CARRY =
   51|  6.77k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   52|  6.77k|  const simd8<uint8_t> byte_1_low =
   53|  6.77k|      (prev1 & 0x0F)
   54|  6.77k|          .lookup_16<uint8_t>(
   55|       |              // ____0000 ________
   56|  6.77k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   57|       |              // ____0001 ________
   58|  6.77k|              CARRY | OVERLONG_2,
   59|       |              // ____001_ ________
   60|  6.77k|              CARRY, CARRY,
   61|       |
   62|       |              // ____0100 ________
   63|  6.77k|              CARRY | TOO_LARGE,
   64|       |              // ____0101 ________
   65|  6.77k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   66|       |              // ____011_ ________
   67|  6.77k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   68|  6.77k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|       |
   70|       |              // ____1___ ________
   71|  6.77k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   72|  6.77k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  6.77k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  6.77k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  6.77k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|       |              // ____1101 ________
   77|  6.77k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   78|  6.77k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   79|  6.77k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   80|  6.77k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   81|       |      // ________ 0_______ <ASCII in byte 2>
   82|  6.77k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   83|  6.77k|      TOO_SHORT, TOO_SHORT,
   84|       |
   85|       |      // ________ 1000____
   86|  6.77k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   87|  6.77k|          OVERLONG_4,
   88|       |      // ________ 1001____
   89|  6.77k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   90|       |      // ________ 101_____
   91|  6.77k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   92|  6.77k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|       |
   94|       |      // ________ 11______
   95|  6.77k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   96|  6.77k|  return (byte_1_high & byte_1_low & byte_2_high);
   97|  6.77k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3223check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  101|  6.77k|                        const simd8<uint8_t> sc) {
  102|  6.77k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  103|  6.77k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  104|  6.77k|  simd8<uint8_t> must23 =
  105|  6.77k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  106|  6.77k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  107|  6.77k|  return must23_80 ^ sc;
  108|  6.77k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoder6errorsEv:
  310|  5.25k|  simdutf_really_inline bool errors() const {
  311|  5.25k|    return this->error.any_bits_set_anywhere();
  312|  5.25k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker16check_next_inputERKNS1_4simd8simd8x64IhEE:
  187|  33.0k|  simdutf_really_inline void check_next_input(const simd8x64<uint8_t> &input) {
  188|  33.0k|    if (simdutf_likely(is_ascii(input))) {
  ------------------
  |  |   90|  33.0k|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 25.4k, False: 7.60k]
  |  |  ------------------
  ------------------
  189|  25.4k|      this->error |= this->prev_incomplete;
  190|  25.4k|    } else {
  191|       |      // you might think that a for-loop would work, but under Visual Studio, it
  192|       |      // is not good enough.
  193|  7.60k|      static_assert((simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  194|  7.60k|                        (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  195|  7.60k|                    "We support either two or four chunks per 64-byte block.");
  196|  7.60k|      if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  197|  7.60k|        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  198|  7.60k|        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.60k|      this->prev_incomplete =
  206|  7.60k|          is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1]);
  207|  7.60k|      this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1];
  208|  7.60k|    }
  209|  33.0k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  169|  15.2k|                                              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.2k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  174|  15.2k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  175|  15.2k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  176|  15.2k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation19check_special_casesENS1_4simd5simd8IhEES5_:
    9|  15.2k|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.2k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   17|       |                                               // 11______ 11______
   18|  15.2k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   19|  15.2k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   20|  15.2k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   21|  15.2k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   22|  15.2k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   23|  15.2k|  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.2k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   32|       |  // 11110101 1000____
   33|       |  // 1111011_ 1000____
   34|       |  // 11111___ 1000____
   35|  15.2k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   36|       |
   37|  15.2k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   38|       |      // 0_______ ________ <ASCII in byte 1>
   39|  15.2k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   40|  15.2k|      TOO_LONG,
   41|       |      // 10______ ________ <continuation in byte 1>
   42|  15.2k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   43|       |      // 1100____ ________ <two byte lead in byte 1>
   44|  15.2k|      TOO_SHORT | OVERLONG_2,
   45|       |      // 1101____ ________ <two byte lead in byte 1>
   46|  15.2k|      TOO_SHORT,
   47|       |      // 1110____ ________ <three byte lead in byte 1>
   48|  15.2k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   49|       |      // 1111____ ________ <four+ byte lead in byte 1>
   50|  15.2k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   51|  15.2k|  constexpr const uint8_t CARRY =
   52|  15.2k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   53|  15.2k|  const simd8<uint8_t> byte_1_low =
   54|  15.2k|      (prev1 & 0x0F)
   55|  15.2k|          .lookup_16<uint8_t>(
   56|       |              // ____0000 ________
   57|  15.2k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   58|       |              // ____0001 ________
   59|  15.2k|              CARRY | OVERLONG_2,
   60|       |              // ____001_ ________
   61|  15.2k|              CARRY, CARRY,
   62|       |
   63|       |              // ____0100 ________
   64|  15.2k|              CARRY | TOO_LARGE,
   65|       |              // ____0101 ________
   66|  15.2k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   67|       |              // ____011_ ________
   68|  15.2k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|  15.2k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   70|       |
   71|       |              // ____1___ ________
   72|  15.2k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  15.2k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  15.2k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  15.2k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|  15.2k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   77|       |              // ____1101 ________
   78|  15.2k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   79|  15.2k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   80|  15.2k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   81|  15.2k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   82|       |      // ________ 0_______ <ASCII in byte 2>
   83|  15.2k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   84|  15.2k|      TOO_SHORT, TOO_SHORT,
   85|       |
   86|       |      // ________ 1000____
   87|  15.2k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   88|  15.2k|          OVERLONG_4,
   89|       |      // ________ 1001____
   90|  15.2k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   91|       |      // ________ 101_____
   92|  15.2k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|  15.2k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   94|       |
   95|       |      // ________ 11______
   96|  15.2k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   97|  15.2k|  return (byte_1_high & byte_1_low & byte_2_high);
   98|  15.2k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation23check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  102|  15.2k|                        const simd8<uint8_t> sc) {
  103|  15.2k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  104|  15.2k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  105|  15.2k|  simd8<uint8_t> must23 =
  106|  15.2k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  107|  15.2k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  108|  15.2k|  return must23_80 ^ sc;
  109|  15.2k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation13is_incompleteENS1_4simd5simd8IhEE:
  115|  7.60k|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.60k|  static const uint8_t max_array[32] = {255,
  120|  7.60k|                                        255,
  121|  7.60k|                                        255,
  122|  7.60k|                                        255,
  123|  7.60k|                                        255,
  124|  7.60k|                                        255,
  125|  7.60k|                                        255,
  126|  7.60k|                                        255,
  127|  7.60k|                                        255,
  128|  7.60k|                                        255,
  129|  7.60k|                                        255,
  130|  7.60k|                                        255,
  131|  7.60k|                                        255,
  132|  7.60k|                                        255,
  133|  7.60k|                                        255,
  134|  7.60k|                                        255,
  135|  7.60k|                                        255,
  136|  7.60k|                                        255,
  137|  7.60k|                                        255,
  138|  7.60k|                                        255,
  139|  7.60k|                                        255,
  140|  7.60k|                                        255,
  141|  7.60k|                                        255,
  142|  7.60k|                                        255,
  143|  7.60k|                                        255,
  144|  7.60k|                                        255,
  145|  7.60k|                                        255,
  146|  7.60k|                                        255,
  147|  7.60k|                                        255,
  148|  7.60k|                                        0b11110000u - 1,
  149|  7.60k|                                        0b11100000u - 1,
  150|  7.60k|                                        0b11000000u - 1};
  151|  7.60k|  const simd8<uint8_t> max_value(
  152|  7.60k|      &max_array[sizeof(max_array) - sizeof(simd8<uint8_t>)]);
  153|  7.60k|  return input.gt_bits(max_value);
  154|  7.60k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker9check_eofEv:
  181|  25.9k|  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|  25.9k|    this->error |= this->prev_incomplete;
  185|  25.9k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker6errorsEv:
  212|  27.0k|  simdutf_really_inline bool errors() const {
  213|  27.0k|    return this->error.any_bits_set_anywhere();
  214|  27.0k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker16check_next_inputERKNS1_4simd8simd8x64IhEE:
  187|  35.4k|  simdutf_really_inline void check_next_input(const simd8x64<uint8_t> &input) {
  188|  35.4k|    if (simdutf_likely(is_ascii(input))) {
  ------------------
  |  |   90|  35.4k|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 26.8k, False: 8.59k]
  |  |  ------------------
  ------------------
  189|  26.8k|      this->error |= this->prev_incomplete;
  190|  26.8k|    } else {
  191|       |      // you might think that a for-loop would work, but under Visual Studio, it
  192|       |      // is not good enough.
  193|  8.59k|      static_assert((simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  194|  8.59k|                        (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  195|  8.59k|                    "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|  8.59k|      } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  200|  8.59k|        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  201|  8.59k|        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  202|  8.59k|        this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  203|  8.59k|        this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  204|  8.59k|      }
  205|  8.59k|      this->prev_incomplete =
  206|  8.59k|          is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1]);
  207|  8.59k|      this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1];
  208|  8.59k|    }
  209|  35.4k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  169|  34.3k|                                              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|  34.3k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  174|  34.3k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  175|  34.3k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  176|  34.3k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation19check_special_casesENS1_4simd5simd8IhEES5_:
    9|  34.3k|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|  34.3k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   17|       |                                               // 11______ 11______
   18|  34.3k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   19|  34.3k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   20|  34.3k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   21|  34.3k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   22|  34.3k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   23|  34.3k|  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|  34.3k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   32|       |  // 11110101 1000____
   33|       |  // 1111011_ 1000____
   34|       |  // 11111___ 1000____
   35|  34.3k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   36|       |
   37|  34.3k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   38|       |      // 0_______ ________ <ASCII in byte 1>
   39|  34.3k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   40|  34.3k|      TOO_LONG,
   41|       |      // 10______ ________ <continuation in byte 1>
   42|  34.3k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   43|       |      // 1100____ ________ <two byte lead in byte 1>
   44|  34.3k|      TOO_SHORT | OVERLONG_2,
   45|       |      // 1101____ ________ <two byte lead in byte 1>
   46|  34.3k|      TOO_SHORT,
   47|       |      // 1110____ ________ <three byte lead in byte 1>
   48|  34.3k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   49|       |      // 1111____ ________ <four+ byte lead in byte 1>
   50|  34.3k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   51|  34.3k|  constexpr const uint8_t CARRY =
   52|  34.3k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   53|  34.3k|  const simd8<uint8_t> byte_1_low =
   54|  34.3k|      (prev1 & 0x0F)
   55|  34.3k|          .lookup_16<uint8_t>(
   56|       |              // ____0000 ________
   57|  34.3k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   58|       |              // ____0001 ________
   59|  34.3k|              CARRY | OVERLONG_2,
   60|       |              // ____001_ ________
   61|  34.3k|              CARRY, CARRY,
   62|       |
   63|       |              // ____0100 ________
   64|  34.3k|              CARRY | TOO_LARGE,
   65|       |              // ____0101 ________
   66|  34.3k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   67|       |              // ____011_ ________
   68|  34.3k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|  34.3k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   70|       |
   71|       |              // ____1___ ________
   72|  34.3k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  34.3k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  34.3k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  34.3k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|  34.3k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   77|       |              // ____1101 ________
   78|  34.3k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   79|  34.3k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   80|  34.3k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   81|  34.3k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   82|       |      // ________ 0_______ <ASCII in byte 2>
   83|  34.3k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   84|  34.3k|      TOO_SHORT, TOO_SHORT,
   85|       |
   86|       |      // ________ 1000____
   87|  34.3k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   88|  34.3k|          OVERLONG_4,
   89|       |      // ________ 1001____
   90|  34.3k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   91|       |      // ________ 101_____
   92|  34.3k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|  34.3k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   94|       |
   95|       |      // ________ 11______
   96|  34.3k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   97|  34.3k|  return (byte_1_high & byte_1_low & byte_2_high);
   98|  34.3k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation23check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  102|  34.3k|                        const simd8<uint8_t> sc) {
  103|  34.3k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  104|  34.3k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  105|  34.3k|  simd8<uint8_t> must23 =
  106|  34.3k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  107|  34.3k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  108|  34.3k|  return must23_80 ^ sc;
  109|  34.3k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation13is_incompleteENS1_4simd5simd8IhEE:
  115|  8.59k|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|  8.59k|  static const uint8_t max_array[32] = {255,
  120|  8.59k|                                        255,
  121|  8.59k|                                        255,
  122|  8.59k|                                        255,
  123|  8.59k|                                        255,
  124|  8.59k|                                        255,
  125|  8.59k|                                        255,
  126|  8.59k|                                        255,
  127|  8.59k|                                        255,
  128|  8.59k|                                        255,
  129|  8.59k|                                        255,
  130|  8.59k|                                        255,
  131|  8.59k|                                        255,
  132|  8.59k|                                        255,
  133|  8.59k|                                        255,
  134|  8.59k|                                        255,
  135|  8.59k|                                        255,
  136|  8.59k|                                        255,
  137|  8.59k|                                        255,
  138|  8.59k|                                        255,
  139|  8.59k|                                        255,
  140|  8.59k|                                        255,
  141|  8.59k|                                        255,
  142|  8.59k|                                        255,
  143|  8.59k|                                        255,
  144|  8.59k|                                        255,
  145|  8.59k|                                        255,
  146|  8.59k|                                        255,
  147|  8.59k|                                        255,
  148|  8.59k|                                        0b11110000u - 1,
  149|  8.59k|                                        0b11100000u - 1,
  150|  8.59k|                                        0b11000000u - 1};
  151|  8.59k|  const simd8<uint8_t> max_value(
  152|  8.59k|      &max_array[sizeof(max_array) - sizeof(simd8<uint8_t>)]);
  153|  8.59k|  return input.gt_bits(max_value);
  154|  8.59k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker9check_eofEv:
  181|  25.9k|  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|  25.9k|    this->error |= this->prev_incomplete;
  185|  25.9k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker6errorsEv:
  212|  27.5k|  simdutf_really_inline bool errors() const {
  213|  27.5k|    return this->error.any_bits_set_anywhere();
  214|  27.5k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation21generic_validate_utf8EPKcm:
   27|  20.8k|bool generic_validate_utf8(const char *input, size_t length) {
   28|  20.8k|  return generic_validate_utf8<utf8_checker>(
   29|  20.8k|      reinterpret_cast<const uint8_t *>(input), length);
   30|  20.8k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation21generic_validate_utf8INS2_12utf8_checkerEEEbPKhm:
   10|  20.8k|bool generic_validate_utf8(const uint8_t *input, size_t length) {
   11|  20.8k|  checker c{};
   12|  20.8k|  buf_block_reader<64> reader(input, length);
   13|  26.9k|  while (reader.has_full_block()) {
  ------------------
  |  Branch (13:10): [True: 6.02k, False: 20.8k]
  ------------------
   14|  6.02k|    simd::simd8x64<uint8_t> in(reader.full_block());
   15|  6.02k|    c.check_next_input(in);
   16|  6.02k|    reader.advance();
   17|  6.02k|  }
   18|  20.8k|  uint8_t block[64]{};
   19|  20.8k|  reader.get_remainder(block);
   20|  20.8k|  simd::simd8x64<uint8_t> in(block);
   21|  20.8k|  c.check_next_input(in);
   22|  20.8k|  reader.advance();
   23|  20.8k|  c.check_eof();
   24|  20.8k|  return !c.errors();
   25|  20.8k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation33generic_validate_utf8_with_errorsEPKcm:
   76|  5.26k|result generic_validate_utf8_with_errors(const char *input, size_t length) {
   77|  5.26k|  return generic_validate_utf8_with_errors<utf8_checker>(
   78|  5.26k|      reinterpret_cast<const uint8_t *>(input), length);
   79|  5.26k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation33generic_validate_utf8_with_errorsINS2_12utf8_checkerEEENS_6resultEPKhm:
   36|  5.26k|result generic_validate_utf8_with_errors(const uint8_t *input, size_t length) {
   37|  5.26k|  checker c{};
   38|  5.26k|  buf_block_reader<64> reader(input, length);
   39|  5.26k|  size_t count{0};
   40|  6.18k|  while (reader.has_full_block()) {
  ------------------
  |  Branch (40:10): [True: 1.17k, False: 5.01k]
  ------------------
   41|  1.17k|    simd::simd8x64<uint8_t> in(reader.full_block());
   42|  1.17k|    c.check_next_input(in);
   43|  1.17k|    if (c.errors()) {
  ------------------
  |  Branch (43:9): [True: 252, False: 920]
  ------------------
   44|    252|      if (count != 0) {
  ------------------
  |  Branch (44:11): [True: 14, False: 238]
  ------------------
   45|     14|        count--;
   46|     14|      } // Sometimes the error is only detected in the next chunk
   47|    252|      result res = scalar::utf8::rewind_and_validate_with_errors(
   48|    252|          reinterpret_cast<const char *>(input),
   49|    252|          reinterpret_cast<const char *>(input + count), length - count);
   50|    252|      res.count += count;
   51|    252|      return res;
   52|    252|    }
   53|    920|    reader.advance();
   54|    920|    count += 64;
   55|    920|  }
   56|  5.01k|  uint8_t block[64]{};
   57|  5.01k|  reader.get_remainder(block);
   58|  5.01k|  simd::simd8x64<uint8_t> in(block);
   59|  5.01k|  c.check_next_input(in);
   60|  5.01k|  reader.advance();
   61|  5.01k|  c.check_eof();
   62|  5.01k|  if (c.errors()) {
  ------------------
  |  Branch (62:7): [True: 348, False: 4.66k]
  ------------------
   63|    348|    if (count != 0) {
  ------------------
  |  Branch (63:9): [True: 15, False: 333]
  ------------------
   64|     15|      count--;
   65|     15|    } // Sometimes the error is only detected in the next chunk
   66|    348|    result res = scalar::utf8::rewind_and_validate_with_errors(
   67|    348|        reinterpret_cast<const char *>(input),
   68|    348|        reinterpret_cast<const char *>(input) + count, length - count);
   69|    348|    res.count += count;
   70|    348|    return res;
   71|  4.66k|  } else {
   72|  4.66k|    return result(error_code::SUCCESS, length);
   73|  4.66k|  }
   74|  5.01k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation21generic_validate_utf8EPKcm:
   27|  20.8k|bool generic_validate_utf8(const char *input, size_t length) {
   28|  20.8k|  return generic_validate_utf8<utf8_checker>(
   29|  20.8k|      reinterpret_cast<const uint8_t *>(input), length);
   30|  20.8k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation21generic_validate_utf8INS2_12utf8_checkerEEEbPKhm:
   10|  20.8k|bool generic_validate_utf8(const uint8_t *input, size_t length) {
   11|  20.8k|  checker c{};
   12|  20.8k|  buf_block_reader<64> reader(input, length);
   13|  28.7k|  while (reader.has_full_block()) {
  ------------------
  |  Branch (13:10): [True: 7.86k, False: 20.8k]
  ------------------
   14|  7.86k|    simd::simd8x64<uint8_t> in(reader.full_block());
   15|  7.86k|    c.check_next_input(in);
   16|  7.86k|    reader.advance();
   17|  7.86k|  }
   18|  20.8k|  uint8_t block[64]{};
   19|  20.8k|  reader.get_remainder(block);
   20|  20.8k|  simd::simd8x64<uint8_t> in(block);
   21|  20.8k|  c.check_next_input(in);
   22|  20.8k|  reader.advance();
   23|  20.8k|  c.check_eof();
   24|  20.8k|  return !c.errors();
   25|  20.8k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation33generic_validate_utf8_with_errorsEPKcm:
   76|  5.26k|result generic_validate_utf8_with_errors(const char *input, size_t length) {
   77|  5.26k|  return generic_validate_utf8_with_errors<utf8_checker>(
   78|  5.26k|      reinterpret_cast<const uint8_t *>(input), length);
   79|  5.26k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation33generic_validate_utf8_with_errorsINS2_12utf8_checkerEEENS_6resultEPKhm:
   36|  5.26k|result generic_validate_utf8_with_errors(const uint8_t *input, size_t length) {
   37|  5.26k|  checker c{};
   38|  5.26k|  buf_block_reader<64> reader(input, length);
   39|  5.26k|  size_t count{0};
   40|  6.68k|  while (reader.has_full_block()) {
  ------------------
  |  Branch (40:10): [True: 1.64k, False: 5.04k]
  ------------------
   41|  1.64k|    simd::simd8x64<uint8_t> in(reader.full_block());
   42|  1.64k|    c.check_next_input(in);
   43|  1.64k|    if (c.errors()) {
  ------------------
  |  Branch (43:9): [True: 226, False: 1.41k]
  ------------------
   44|    226|      if (count != 0) {
  ------------------
  |  Branch (44:11): [True: 34, False: 192]
  ------------------
   45|     34|        count--;
   46|     34|      } // Sometimes the error is only detected in the next chunk
   47|    226|      result res = scalar::utf8::rewind_and_validate_with_errors(
   48|    226|          reinterpret_cast<const char *>(input),
   49|    226|          reinterpret_cast<const char *>(input + count), length - count);
   50|    226|      res.count += count;
   51|    226|      return res;
   52|    226|    }
   53|  1.41k|    reader.advance();
   54|  1.41k|    count += 64;
   55|  1.41k|  }
   56|  5.04k|  uint8_t block[64]{};
   57|  5.04k|  reader.get_remainder(block);
   58|  5.04k|  simd::simd8x64<uint8_t> in(block);
   59|  5.04k|  c.check_next_input(in);
   60|  5.04k|  reader.advance();
   61|  5.04k|  c.check_eof();
   62|  5.04k|  if (c.errors()) {
  ------------------
  |  Branch (62:7): [True: 180, False: 4.86k]
  ------------------
   63|    180|    if (count != 0) {
  ------------------
  |  Branch (63:9): [True: 13, False: 167]
  ------------------
   64|     13|      count--;
   65|     13|    } // Sometimes the error is only detected in the next chunk
   66|    180|    result res = scalar::utf8::rewind_and_validate_with_errors(
   67|    180|        reinterpret_cast<const char *>(input),
   68|    180|        reinterpret_cast<const char *>(input) + count, length - count);
   69|    180|    res.count += count;
   70|    180|    return res;
   71|  4.86k|  } else {
   72|  4.86k|    return result(error_code::SUCCESS, length);
   73|  4.86k|  }
   74|  5.04k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1626validate_utf16_with_errorsILNS_10endiannessE0EEEKNS_6resultEPKDsm:
   49|  7.50k|const result validate_utf16_with_errors(const char16_t *input, size_t size) {
   50|  7.50k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   93|  7.50k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 4.91k, False: 2.58k]
  |  |  ------------------
  ------------------
   51|  4.91k|    return result(error_code::SUCCESS, 0);
   52|  4.91k|  }
   53|       |
   54|  2.58k|  const char16_t *start = input;
   55|  2.58k|  const char16_t *end = input + size;
   56|       |
   57|  2.58k|  const auto v_d8 = simd8<uint8_t>::splat(0xd8);
   58|  2.58k|  const auto v_f8 = simd8<uint8_t>::splat(0xf8);
   59|  2.58k|  const auto v_fc = simd8<uint8_t>::splat(0xfc);
   60|  2.58k|  const auto v_dc = simd8<uint8_t>::splat(0xdc);
   61|       |
   62|  14.3k|  while (input + simd16<uint16_t>::SIZE * 2 < end) {
  ------------------
  |  Branch (62:10): [True: 11.8k, False: 2.49k]
  ------------------
   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.8k|    auto in0 = simd16<uint16_t>(input);
   67|  11.8k|    auto in1 =
   68|  11.8k|        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.8k|    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.8k|    const auto surrogates_wordmask = (in & v_f8) == v_d8;
   76|  11.8k|    const uint16_t surrogates_bitmask =
   77|  11.8k|        static_cast<uint16_t>(surrogates_wordmask.to_bitmask());
   78|  11.8k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (78:9): [True: 10.6k, False: 1.17k]
  ------------------
   79|  10.6k|      input += 16;
   80|  10.6k|    } 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.17k|      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.17k|      const auto vH = (in & v_fc) == v_dc;
   93|  1.17k|      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.17k|      const uint16_t L = static_cast<uint16_t>(~H & surrogates_bitmask);
   98|       |
   99|  1.17k|      const uint16_t a = static_cast<uint16_t>(
  100|  1.17k|          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.17k|      const uint16_t b = static_cast<uint16_t>(
  104|  1.17k|          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.17k|      const uint16_t c = static_cast<uint16_t>(
  107|  1.17k|          V | a | b); // Combine all the masks into the final one.
  108|       |
  109|  1.17k|      if (c == 0xffff) {
  ------------------
  |  Branch (109:11): [True: 782, False: 392]
  ------------------
  110|       |        // The whole input register contains valid UTF-16, i.e.,
  111|       |        // either single code units or proper surrogate pairs.
  112|    782|        input += 16;
  113|    782|      } else if (c == 0x7fff) {
  ------------------
  |  Branch (113:18): [True: 298, False: 94]
  ------------------
  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|    298|        input += 15;
  119|    298|      } else {
  120|     94|        return result(error_code::SURROGATE, input - start);
  121|     94|      }
  122|  1.17k|    }
  123|  11.8k|  }
  124|       |
  125|  2.49k|  return result(error_code::SUCCESS, input - start);
  126|  2.58k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1626validate_utf16_with_errorsILNS_10endiannessE1EEEKNS_6resultEPKDsm:
   49|  7.51k|const result validate_utf16_with_errors(const char16_t *input, size_t size) {
   50|  7.51k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   93|  7.51k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 4.91k, False: 2.59k]
  |  |  ------------------
  ------------------
   51|  4.91k|    return result(error_code::SUCCESS, 0);
   52|  4.91k|  }
   53|       |
   54|  2.59k|  const char16_t *start = input;
   55|  2.59k|  const char16_t *end = input + size;
   56|       |
   57|  2.59k|  const auto v_d8 = simd8<uint8_t>::splat(0xd8);
   58|  2.59k|  const auto v_f8 = simd8<uint8_t>::splat(0xf8);
   59|  2.59k|  const auto v_fc = simd8<uint8_t>::splat(0xfc);
   60|  2.59k|  const auto v_dc = simd8<uint8_t>::splat(0xdc);
   61|       |
   62|  14.6k|  while (input + simd16<uint16_t>::SIZE * 2 < end) {
  ------------------
  |  Branch (62:10): [True: 12.0k, False: 2.51k]
  ------------------
   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.0k|    auto in0 = simd16<uint16_t>(input);
   67|  12.0k|    auto in1 =
   68|  12.0k|        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.0k|    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.0k|    const auto surrogates_wordmask = (in & v_f8) == v_d8;
   76|  12.0k|    const uint16_t surrogates_bitmask =
   77|  12.0k|        static_cast<uint16_t>(surrogates_wordmask.to_bitmask());
   78|  12.0k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (78:9): [True: 11.0k, False: 1.08k]
  ------------------
   79|  11.0k|      input += 16;
   80|  11.0k|    } 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.08k|      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.08k|      const auto vH = (in & v_fc) == v_dc;
   93|  1.08k|      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.08k|      const uint16_t L = static_cast<uint16_t>(~H & surrogates_bitmask);
   98|       |
   99|  1.08k|      const uint16_t a = static_cast<uint16_t>(
  100|  1.08k|          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.08k|      const uint16_t b = static_cast<uint16_t>(
  104|  1.08k|          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.08k|      const uint16_t c = static_cast<uint16_t>(
  107|  1.08k|          V | a | b); // Combine all the masks into the final one.
  108|       |
  109|  1.08k|      if (c == 0xffff) {
  ------------------
  |  Branch (109:11): [True: 666, False: 414]
  ------------------
  110|       |        // The whole input register contains valid UTF-16, i.e.,
  111|       |        // either single code units or proper surrogate pairs.
  112|    666|        input += 16;
  113|    666|      } else if (c == 0x7fff) {
  ------------------
  |  Branch (113:18): [True: 328, False: 86]
  ------------------
  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|    328|        input += 15;
  119|    328|      } else {
  120|     86|        return result(error_code::SURROGATE, input - start);
  121|     86|      }
  122|  1.08k|    }
  123|  12.0k|  }
  124|       |
  125|  2.51k|  return result(error_code::SUCCESS, input - start);
  126|  2.59k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1626validate_utf16_with_errorsILNS_10endiannessE0EEEKNS_6resultEPKDsm:
   49|  7.06k|const result validate_utf16_with_errors(const char16_t *input, size_t size) {
   50|  7.06k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   93|  7.06k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 4.93k, False: 2.12k]
  |  |  ------------------
  ------------------
   51|  4.93k|    return result(error_code::SUCCESS, 0);
   52|  4.93k|  }
   53|       |
   54|  2.12k|  const char16_t *start = input;
   55|  2.12k|  const char16_t *end = input + size;
   56|       |
   57|  2.12k|  const auto v_d8 = simd8<uint8_t>::splat(0xd8);
   58|  2.12k|  const auto v_f8 = simd8<uint8_t>::splat(0xf8);
   59|  2.12k|  const auto v_fc = simd8<uint8_t>::splat(0xfc);
   60|  2.12k|  const auto v_dc = simd8<uint8_t>::splat(0xdc);
   61|       |
   62|  19.6k|  while (input + simd16<uint16_t>::SIZE * 2 < end) {
  ------------------
  |  Branch (62:10): [True: 17.6k, False: 2.00k]
  ------------------
   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|  17.6k|    auto in0 = simd16<uint16_t>(input);
   67|  17.6k|    auto in1 =
   68|  17.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|  17.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|  17.6k|    const auto surrogates_wordmask = (in & v_f8) == v_d8;
   76|  17.6k|    const uint16_t surrogates_bitmask =
   77|  17.6k|        static_cast<uint16_t>(surrogates_wordmask.to_bitmask());
   78|  17.6k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (78:9): [True: 16.4k, False: 1.27k]
  ------------------
   79|  16.4k|      input += 16;
   80|  16.4k|    } 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.27k|      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.27k|      const auto vH = (in & v_fc) == v_dc;
   93|  1.27k|      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.27k|      const uint16_t L = static_cast<uint16_t>(~H & surrogates_bitmask);
   98|       |
   99|  1.27k|      const uint16_t a = static_cast<uint16_t>(
  100|  1.27k|          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.27k|      const uint16_t b = static_cast<uint16_t>(
  104|  1.27k|          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.27k|      const uint16_t c = static_cast<uint16_t>(
  107|  1.27k|          V | a | b); // Combine all the masks into the final one.
  108|       |
  109|  1.27k|      if (c == 0xffff) {
  ------------------
  |  Branch (109:11): [True: 800, False: 472]
  ------------------
  110|       |        // The whole input register contains valid UTF-16, i.e.,
  111|       |        // either single code units or proper surrogate pairs.
  112|    800|        input += 16;
  113|    800|      } else if (c == 0x7fff) {
  ------------------
  |  Branch (113:18): [True: 346, False: 126]
  ------------------
  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|    126|        return result(error_code::SURROGATE, input - start);
  121|    126|      }
  122|  1.27k|    }
  123|  17.6k|  }
  124|       |
  125|  2.00k|  return result(error_code::SUCCESS, input - start);
  126|  2.12k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1626validate_utf16_with_errorsILNS_10endiannessE1EEEKNS_6resultEPKDsm:
   49|  7.05k|const result validate_utf16_with_errors(const char16_t *input, size_t size) {
   50|  7.05k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   93|  7.05k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 4.94k, False: 2.10k]
  |  |  ------------------
  ------------------
   51|  4.94k|    return result(error_code::SUCCESS, 0);
   52|  4.94k|  }
   53|       |
   54|  2.10k|  const char16_t *start = input;
   55|  2.10k|  const char16_t *end = input + size;
   56|       |
   57|  2.10k|  const auto v_d8 = simd8<uint8_t>::splat(0xd8);
   58|  2.10k|  const auto v_f8 = simd8<uint8_t>::splat(0xf8);
   59|  2.10k|  const auto v_fc = simd8<uint8_t>::splat(0xfc);
   60|  2.10k|  const auto v_dc = simd8<uint8_t>::splat(0xdc);
   61|       |
   62|  19.8k|  while (input + simd16<uint16_t>::SIZE * 2 < end) {
  ------------------
  |  Branch (62:10): [True: 17.8k, False: 1.98k]
  ------------------
   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|  17.8k|    auto in0 = simd16<uint16_t>(input);
   67|  17.8k|    auto in1 =
   68|  17.8k|        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|  17.8k|    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|  17.8k|    const auto surrogates_wordmask = (in & v_f8) == v_d8;
   76|  17.8k|    const uint16_t surrogates_bitmask =
   77|  17.8k|        static_cast<uint16_t>(surrogates_wordmask.to_bitmask());
   78|  17.8k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (78:9): [True: 16.6k, False: 1.20k]
  ------------------
   79|  16.6k|      input += 16;
   80|  16.6k|    } 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.20k|      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.20k|      const auto vH = (in & v_fc) == v_dc;
   93|  1.20k|      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.20k|      const uint16_t L = static_cast<uint16_t>(~H & surrogates_bitmask);
   98|       |
   99|  1.20k|      const uint16_t a = static_cast<uint16_t>(
  100|  1.20k|          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.20k|      const uint16_t b = static_cast<uint16_t>(
  104|  1.20k|          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.20k|      const uint16_t c = static_cast<uint16_t>(
  107|  1.20k|          V | a | b); // Combine all the masks into the final one.
  108|       |
  109|  1.20k|      if (c == 0xffff) {
  ------------------
  |  Branch (109:11): [True: 726, False: 480]
  ------------------
  110|       |        // The whole input register contains valid UTF-16, i.e.,
  111|       |        // either single code units or proper surrogate pairs.
  112|    726|        input += 16;
  113|    726|      } else if (c == 0x7fff) {
  ------------------
  |  Branch (113:18): [True: 356, False: 124]
  ------------------
  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|    124|        return result(error_code::SURROGATE, input - start);
  121|    124|      }
  122|  1.20k|    }
  123|  17.8k|  }
  124|       |
  125|  1.98k|  return result(error_code::SUCCESS, input - start);
  126|  2.10k|}

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block64C2EPKc:
  450|  16.5k|  simdutf_really_inline block64(const char *src) {
  451|  16.5k|    chunks[0] = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src));
  452|  16.5k|    chunks[1] = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src + 32));
  453|  16.5k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6414compress_blockEmPc:
  630|  2.23k|  simdutf_really_inline uint64_t compress_block(uint64_t mask, char *output) {
  631|  2.23k|    if (is_power_of_two(mask)) {
  ------------------
  |  Branch (631:9): [True: 849, False: 1.38k]
  ------------------
  632|    849|      return compress_block_single(mask, output);
  633|    849|    }
  634|       |
  635|  1.38k|    uint64_t nmask = ~mask;
  636|  1.38k|    compress(chunks[0], uint32_t(mask), output);
  637|  1.38k|    compress(chunks[1], uint32_t(mask >> 32),
  638|  1.38k|             output + count_ones(nmask & 0xFFFFFFFF));
  639|  1.38k|    return count_ones(nmask);
  640|  2.23k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6421compress_block_singleEmPc:
  643|    849|                                                     char *output) {
  644|    849|    const size_t pos64 = trailing_zeroes(mask);
  645|    849|    const int8_t pos = pos64 & 0xf;
  646|    849|    switch (pos64 >> 4) {
  ------------------
  |  Branch (646:13): [True: 849, False: 0]
  ------------------
  647|    241|    case 0b00: {
  ------------------
  |  Branch (647:5): [True: 241, False: 608]
  ------------------
  648|    241|      const __m128i lane0 = _mm256_extracti128_si256(chunks[0], 0);
  649|    241|      const __m128i lane1 = _mm256_extracti128_si256(chunks[0], 1);
  650|       |
  651|    241|      const __m128i v0 = _mm_set1_epi8(char(pos - 1));
  652|    241|      const __m128i v1 =
  653|    241|          _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  654|    241|      const __m128i v2 = _mm_cmpgt_epi8(v1, v0);
  655|    241|      const __m128i sh = _mm_sub_epi8(v1, v2);
  656|    241|      const __m128i compressed = _mm_shuffle_epi8(lane0, sh);
  657|       |
  658|    241|      _mm_storeu_si128((__m128i *)(output + 0 * 16), compressed);
  659|    241|      _mm_storeu_si128((__m128i *)(output + 1 * 16 - 1), lane1);
  660|    241|      _mm256_storeu_si256((__m256i *)(output + 2 * 16 - 1), chunks[1]);
  661|    241|    } break;
  662|    207|    case 0b01: {
  ------------------
  |  Branch (662:5): [True: 207, False: 642]
  ------------------
  663|    207|      const __m128i lane0 = _mm256_extracti128_si256(chunks[0], 0);
  664|    207|      const __m128i lane1 = _mm256_extracti128_si256(chunks[0], 1);
  665|    207|      _mm_storeu_si128((__m128i *)(output + 0 * 16), lane0);
  666|       |
  667|    207|      const __m128i v0 = _mm_set1_epi8(char(pos - 1));
  668|    207|      const __m128i v1 =
  669|    207|          _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  670|    207|      const __m128i v2 = _mm_cmpgt_epi8(v1, v0);
  671|    207|      const __m128i sh = _mm_sub_epi8(v1, v2);
  672|    207|      const __m128i compressed = _mm_shuffle_epi8(lane1, sh);
  673|       |
  674|    207|      _mm_storeu_si128((__m128i *)(output + 1 * 16), compressed);
  675|    207|      _mm256_storeu_si256((__m256i *)(output + 2 * 16 - 1), chunks[1]);
  676|    207|    } break;
  677|    222|    case 0b10: {
  ------------------
  |  Branch (677:5): [True: 222, False: 627]
  ------------------
  678|    222|      const __m128i lane2 = _mm256_extracti128_si256(chunks[1], 0);
  679|    222|      const __m128i lane3 = _mm256_extracti128_si256(chunks[1], 1);
  680|       |
  681|    222|      _mm256_storeu_si256((__m256i *)(output + 0 * 16), chunks[0]);
  682|       |
  683|    222|      const __m128i v0 = _mm_set1_epi8(char(pos - 1));
  684|    222|      const __m128i v1 =
  685|    222|          _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  686|    222|      const __m128i v2 = _mm_cmpgt_epi8(v1, v0);
  687|    222|      const __m128i sh = _mm_sub_epi8(v1, v2);
  688|    222|      const __m128i compressed = _mm_shuffle_epi8(lane2, sh);
  689|       |
  690|    222|      _mm_storeu_si128((__m128i *)(output + 2 * 16), compressed);
  691|    222|      _mm_storeu_si128((__m128i *)(output + 3 * 16 - 1), lane3);
  692|    222|    } break;
  693|    179|    case 0b11: {
  ------------------
  |  Branch (693:5): [True: 179, False: 670]
  ------------------
  694|    179|      const __m128i lane2 = _mm256_extracti128_si256(chunks[1], 0);
  695|    179|      const __m128i lane3 = _mm256_extracti128_si256(chunks[1], 1);
  696|       |
  697|    179|      _mm256_storeu_si256((__m256i *)(output + 0 * 16), chunks[0]);
  698|    179|      _mm_storeu_si128((__m128i *)(output + 2 * 16), lane2);
  699|       |
  700|    179|      const __m128i v0 = _mm_set1_epi8(char(pos - 1));
  701|    179|      const __m128i v1 =
  702|    179|          _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  703|    179|      const __m128i v2 = _mm_cmpgt_epi8(v1, v0);
  704|    179|      const __m128i sh = _mm_sub_epi8(v1, v2);
  705|    179|      const __m128i compressed = _mm_shuffle_epi8(lane3, sh);
  706|       |
  707|    179|      _mm_storeu_si128((__m128i *)(output + 3 * 16), compressed);
  708|    179|    } break;
  709|    849|    }
  710|       |
  711|    849|    return 63;
  712|    849|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_18compressIvEEvDv4_xjPc:
  398|  2.77k|simdutf_really_inline void compress(__m256i data, uint32_t mask, char *output) {
  399|  2.77k|  if (mask == 0) {
  ------------------
  |  Branch (399:7): [True: 464, False: 2.31k]
  ------------------
  400|    464|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(output), data);
  401|    464|    return;
  402|    464|  }
  403|  2.31k|  compress(_mm256_castsi256_si128(data), uint16_t(mask), output);
  404|       |  compress(_mm256_extracti128_si256(data, 1), uint16_t(mask >> 16),
  405|  2.31k|           output + count_ones(~mask & 0xFFFF));
  406|  2.31k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_18compressEDv2_xtPc:
  361|  4.62k|static inline void compress(__m128i data, uint16_t mask, char *output) {
  362|  4.62k|  if (mask == 0) {
  ------------------
  |  Branch (362:7): [True: 1.09k, False: 3.53k]
  ------------------
  363|  1.09k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(output), data);
  364|  1.09k|    return;
  365|  1.09k|  }
  366|       |  // this particular implementation was inspired by work done by @animetosho
  367|       |  // we do it in two steps, first 8 bytes and then second 8 bytes
  368|  3.53k|  uint8_t mask1 = uint8_t(mask);      // least significant 8 bits
  369|  3.53k|  uint8_t mask2 = uint8_t(mask >> 8); // most significant 8 bits
  370|       |  // next line just loads the 64-bit values thintable_epi8[mask1] and
  371|       |  // thintable_epi8[mask2] into a 128-bit register, using only
  372|       |  // two instructions on most compilers.
  373|       |
  374|  3.53k|  __m128i shufmask = _mm_set_epi64x(tables::base64::thintable_epi8[mask2],
  375|  3.53k|                                    tables::base64::thintable_epi8[mask1]);
  376|       |  // we increment by 0x08 the second half of the mask
  377|  3.53k|  shufmask =
  378|  3.53k|      _mm_add_epi8(shufmask, _mm_set_epi32(0x08080808, 0x08080808, 0, 0));
  379|       |  // this is the version "nearly pruned"
  380|  3.53k|  __m128i pruned = _mm_shuffle_epi8(data, shufmask);
  381|       |  // we still need to put the two halves together.
  382|       |  // we compute the popcount of the first half:
  383|  3.53k|  int pop1 = tables::base64::BitsSetTable256mul2[mask1];
  384|       |  // then load the corresponding mask, what it does is to write
  385|       |  // only the first pop1 bytes from the first 8 bytes, and then
  386|       |  // it fills in with the bytes from the second 8 bytes + some filling
  387|       |  // at the end.
  388|  3.53k|  __m128i compactmask = _mm_loadu_si128(reinterpret_cast<const __m128i *>(
  389|  3.53k|      tables::base64::pshufb_combine_table + pop1 * 8));
  390|  3.53k|  __m128i answer = _mm_shuffle_epi8(pruned, compactmask);
  391|       |
  392|  3.53k|  _mm_storeu_si128(reinterpret_cast<__m128i *>(output), answer);
  393|  3.53k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6410copy_blockEPc:
  475|    395|  simdutf_really_inline void copy_block(char *output) {
  476|    395|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(output), chunks[0]);
  477|    395|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(output + 32), chunks[1]);
  478|    395|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6424base64_decode_block_safeEPc:
  486|    812|  simdutf_really_inline void base64_decode_block_safe(char *out) {
  487|    812|    base64_decode(out, chunks[0]);
  488|    812|    alignas(32) char buffer[32]; // We enforce safety with a buffer.
  489|    812|    base64_decode(buffer, chunks[1]);
  490|    812|    std::memcpy(out + 24, buffer, 24);
  491|    812|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113base64_decodeIvEEvPcDv4_x:
  409|  29.7k|simdutf_really_inline void base64_decode(char *out, __m256i str) {
  410|       |  // credit: aqrit
  411|  29.7k|  const __m256i pack_shuffle =
  412|  29.7k|      _mm256_setr_epi8(2, 1, 0, 6, 5, 4, 10, 9, 8, 14, 13, 12, -1, -1, -1, -1,
  413|  29.7k|                       2, 1, 0, 6, 5, 4, 10, 9, 8, 14, 13, 12, -1, -1, -1, -1);
  414|  29.7k|  const __m256i t0 = _mm256_maddubs_epi16(str, _mm256_set1_epi32(0x01400140));
  415|  29.7k|  const __m256i t1 = _mm256_madd_epi16(t0, _mm256_set1_epi32(0x00011000));
  416|  29.7k|  const __m256i t2 = _mm256_shuffle_epi8(t1, pack_shuffle);
  417|       |
  418|       |  // Store the output:
  419|  29.7k|  _mm_storeu_si128((__m128i *)out, _mm256_castsi256_si128(t2));
  420|       |  _mm_storeu_si128((__m128i *)(out + 12), _mm256_extracti128_si256(t2, 1));
  421|  29.7k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6419base64_decode_blockEPc:
  481|  12.3k|  simdutf_really_inline void base64_decode_block(char *out) {
  482|  12.3k|    base64_decode(out, chunks[0]);
  483|  12.3k|    base64_decode(out + 24, chunks[1]);
  484|  12.3k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_119base64_decode_blockIvEEvPcPKc:
  424|  1.68k|simdutf_really_inline void base64_decode_block(char *out, const char *src) {
  425|  1.68k|  base64_decode(out,
  426|  1.68k|                _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src)));
  427|  1.68k|  base64_decode(out + 24, _mm256_loadu_si256(
  428|  1.68k|                              reinterpret_cast<const __m256i *>(src + 32)));
  429|  1.68k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_124base64_decode_block_safeIvEEvPcPKc:
  433|     50|                                                    const char *src) {
  434|     50|  base64_decode(out,
  435|     50|                _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src)));
  436|     50|  alignas(32) char buffer[32]; // We enforce safety with a buffer.
  437|     50|  base64_decode(
  438|     50|      buffer, _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src + 32)));
  439|     50|  std::memcpy(out + 24, buffer, 24);
  440|     50|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6414to_base64_maskILb0ELb0ELb0EEEmPm:
  494|  16.5k|  simdutf_really_inline uint64_t to_base64_mask(uint64_t *error) {
  495|  16.5k|    uint32_t err0 = 0;
  496|  16.5k|    uint32_t err1 = 0;
  497|  16.5k|    uint64_t m0 = to_base64_mask<base64_url, ignore_garbage, default_or_url>(
  498|  16.5k|        &chunks[0], &err0);
  499|  16.5k|    uint64_t m1 = to_base64_mask<base64_url, ignore_garbage, default_or_url>(
  500|  16.5k|        &chunks[1], &err1);
  501|  16.5k|    if (!ignore_garbage) {
  ------------------
  |  Branch (501:9): [True: 16.5k, Folded]
  ------------------
  502|  16.5k|      *error = err0 | ((uint64_t)err1 << 32);
  503|  16.5k|    }
  504|  16.5k|    return m0 | (m1 << 32);
  505|  16.5k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_17block6414to_base64_maskILb0ELb0ELb0EEEjPDv4_xPj:
  508|  33.1k|  simdutf_really_inline uint32_t to_base64_mask(__m256i *src, uint32_t *error) {
  509|  33.1k|    const __m256i ascii_space_tbl =
  510|  33.1k|        _mm256_setr_epi8(0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9, 0xa,
  511|  33.1k|                         0x0, 0xc, 0xd, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0,
  512|  33.1k|                         0x0, 0x0, 0x0, 0x9, 0xa, 0x0, 0xc, 0xd, 0x0, 0x0);
  513|       |    // credit: aqrit
  514|  33.1k|    __m256i delta_asso;
  515|  33.1k|    if (default_or_url) {
  ------------------
  |  Branch (515:9): [Folded, False: 33.1k]
  ------------------
  516|      0|      delta_asso = _mm256_setr_epi8(
  517|      0|          0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
  518|      0|          0x00, 0x00, 0x11, 0x00, 0x16, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  519|      0|          0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x16);
  520|  33.1k|    } else if (base64_url) {
  ------------------
  |  Branch (520:16): [Folded, False: 33.1k]
  ------------------
  521|      0|      delta_asso = _mm256_setr_epi8(0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0,
  522|      0|                                    0x0, 0x0, 0x0, 0x0, 0xF, 0x0, 0xF, 0x1, 0x1,
  523|      0|                                    0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0,
  524|      0|                                    0x0, 0x0, 0xF, 0x0, 0xF);
  525|  33.1k|    } else {
  526|  33.1k|      delta_asso = _mm256_setr_epi8(
  527|  33.1k|          0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
  528|  33.1k|          0x00, 0x00, 0x0F, 0x00, 0x0F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  529|  33.1k|          0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x0F);
  530|  33.1k|    }
  531|       |
  532|  33.1k|    __m256i delta_values;
  533|  33.1k|    if (default_or_url) {
  ------------------
  |  Branch (533:9): [Folded, False: 33.1k]
  ------------------
  534|      0|      delta_values = _mm256_setr_epi8(
  535|      0|          uint8_t(0xBF), uint8_t(0xE0), uint8_t(0xB9), uint8_t(0x13),
  536|      0|          uint8_t(0x04), uint8_t(0xBF), uint8_t(0xBF), uint8_t(0xB9),
  537|      0|          uint8_t(0xB9), uint8_t(0x00), uint8_t(0xFF), uint8_t(0x11),
  538|      0|          uint8_t(0xFF), uint8_t(0xBF), uint8_t(0x10), uint8_t(0xB9),
  539|      0|          uint8_t(0xBF), uint8_t(0xE0), uint8_t(0xB9), uint8_t(0x13),
  540|      0|          uint8_t(0x04), uint8_t(0xBF), uint8_t(0xBF), uint8_t(0xB9),
  541|      0|          uint8_t(0xB9), uint8_t(0x00), uint8_t(0xFF), uint8_t(0x11),
  542|      0|          uint8_t(0xFF), uint8_t(0xBF), uint8_t(0x10), uint8_t(0xB9));
  543|  33.1k|    } else if (base64_url) {
  ------------------
  |  Branch (543:16): [Folded, False: 33.1k]
  ------------------
  544|      0|      delta_values = _mm256_setr_epi8(
  545|      0|          0x0, 0x0, 0x0, 0x13, 0x4, uint8_t(0xBF), uint8_t(0xBF), uint8_t(0xB9),
  546|      0|          uint8_t(0xB9), 0x0, 0x11, uint8_t(0xC3), uint8_t(0xBF), uint8_t(0xE0),
  547|      0|          uint8_t(0xB9), uint8_t(0xB9), 0x0, 0x0, 0x0, 0x13, 0x4, uint8_t(0xBF),
  548|      0|          uint8_t(0xBF), uint8_t(0xB9), uint8_t(0xB9), 0x0, 0x11, uint8_t(0xC3),
  549|      0|          uint8_t(0xBF), uint8_t(0xE0), uint8_t(0xB9), uint8_t(0xB9));
  550|  33.1k|    } else {
  551|  33.1k|      delta_values = _mm256_setr_epi8(
  552|  33.1k|          int8_t(0x00), int8_t(0x00), int8_t(0x00), int8_t(0x13), int8_t(0x04),
  553|  33.1k|          int8_t(0xBF), int8_t(0xBF), int8_t(0xB9), int8_t(0xB9), int8_t(0x00),
  554|  33.1k|          int8_t(0x10), int8_t(0xC3), int8_t(0xBF), int8_t(0xBF), int8_t(0xB9),
  555|  33.1k|          int8_t(0xB9), int8_t(0x00), int8_t(0x00), int8_t(0x00), int8_t(0x13),
  556|  33.1k|          int8_t(0x04), int8_t(0xBF), int8_t(0xBF), int8_t(0xB9), int8_t(0xB9),
  557|  33.1k|          int8_t(0x00), int8_t(0x10), int8_t(0xC3), int8_t(0xBF), int8_t(0xBF),
  558|  33.1k|          int8_t(0xB9), int8_t(0xB9));
  559|  33.1k|    }
  560|       |
  561|  33.1k|    __m256i check_asso;
  562|  33.1k|    if (default_or_url) {
  ------------------
  |  Branch (562:9): [Folded, False: 33.1k]
  ------------------
  563|      0|      check_asso = _mm256_setr_epi8(
  564|      0|          0x0D, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03,
  565|      0|          0x07, 0x0B, 0x0E, 0x0B, 0x06, 0x0D, 0x01, 0x01, 0x01, 0x01, 0x01,
  566|      0|          0x01, 0x01, 0x01, 0x01, 0x03, 0x07, 0x0B, 0x0E, 0x0B, 0x06);
  567|  33.1k|    } else if (base64_url) {
  ------------------
  |  Branch (567:16): [Folded, False: 33.1k]
  ------------------
  568|      0|      check_asso = _mm256_setr_epi8(0xD, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
  569|      0|                                    0x1, 0x3, 0x7, 0xB, 0xE, 0xB, 0x6, 0xD, 0x1,
  570|      0|                                    0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x3,
  571|      0|                                    0x7, 0xB, 0xE, 0xB, 0x6);
  572|  33.1k|    } else {
  573|  33.1k|      check_asso = _mm256_setr_epi8(
  574|  33.1k|          0x0D, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03,
  575|  33.1k|          0x07, 0x0B, 0x0B, 0x0B, 0x0F, 0x0D, 0x01, 0x01, 0x01, 0x01, 0x01,
  576|  33.1k|          0x01, 0x01, 0x01, 0x01, 0x03, 0x07, 0x0B, 0x0B, 0x0B, 0x0F);
  577|  33.1k|    }
  578|  33.1k|    __m256i check_values;
  579|  33.1k|    if (default_or_url) {
  ------------------
  |  Branch (579:9): [Folded, False: 33.1k]
  ------------------
  580|      0|      check_values = _mm256_setr_epi8(
  581|      0|          uint8_t(0x80), uint8_t(0x80), uint8_t(0x80), uint8_t(0x80),
  582|      0|          uint8_t(0xCF), uint8_t(0xBF), uint8_t(0xD5), uint8_t(0xA6),
  583|      0|          uint8_t(0xB5), uint8_t(0xA1), uint8_t(0x00), uint8_t(0x80),
  584|      0|          uint8_t(0x00), uint8_t(0x80), uint8_t(0x00), uint8_t(0x80),
  585|      0|          uint8_t(0x80), uint8_t(0x80), uint8_t(0x80), uint8_t(0x80),
  586|      0|          uint8_t(0xCF), uint8_t(0xBF), uint8_t(0xD5), uint8_t(0xA6),
  587|      0|          uint8_t(0xB5), uint8_t(0xA1), uint8_t(0x00), uint8_t(0x80),
  588|      0|          uint8_t(0x00), uint8_t(0x80), uint8_t(0x00), uint8_t(0x80));
  589|  33.1k|    } else if (base64_url) {
  ------------------
  |  Branch (589:16): [Folded, False: 33.1k]
  ------------------
  590|      0|      check_values = _mm256_setr_epi8(
  591|      0|          uint8_t(0x80), uint8_t(0x80), uint8_t(0x80), uint8_t(0x80),
  592|      0|          uint8_t(0xCF), uint8_t(0xBF), uint8_t(0xB6), uint8_t(0xA6),
  593|      0|          uint8_t(0xB5), uint8_t(0xA1), 0x0, uint8_t(0x80), 0x0, uint8_t(0x80),
  594|      0|          0x0, uint8_t(0x80), uint8_t(0x80), uint8_t(0x80), uint8_t(0x80),
  595|      0|          uint8_t(0x80), uint8_t(0xCF), uint8_t(0xBF), uint8_t(0xB6),
  596|      0|          uint8_t(0xA6), uint8_t(0xB5), uint8_t(0xA1), 0x0, uint8_t(0x80), 0x0,
  597|      0|          uint8_t(0x80), 0x0, uint8_t(0x80));
  598|  33.1k|    } else {
  599|  33.1k|      check_values = _mm256_setr_epi8(
  600|  33.1k|          int8_t(0x80), int8_t(0x80), int8_t(0x80), int8_t(0x80), int8_t(0xCF),
  601|  33.1k|          int8_t(0xBF), int8_t(0xD5), int8_t(0xA6), int8_t(0xB5), int8_t(0x86),
  602|  33.1k|          int8_t(0xD1), int8_t(0x80), int8_t(0xB1), int8_t(0x80), int8_t(0x91),
  603|  33.1k|          int8_t(0x80), int8_t(0x80), int8_t(0x80), int8_t(0x80), int8_t(0x80),
  604|  33.1k|          int8_t(0xCF), int8_t(0xBF), int8_t(0xD5), int8_t(0xA6), int8_t(0xB5),
  605|  33.1k|          int8_t(0x86), int8_t(0xD1), int8_t(0x80), int8_t(0xB1), int8_t(0x80),
  606|  33.1k|          int8_t(0x91), int8_t(0x80));
  607|  33.1k|    }
  608|  33.1k|    const __m256i shifted = _mm256_srli_epi32(*src, 3);
  609|  33.1k|    __m256i delta_hash =
  610|  33.1k|        _mm256_avg_epu8(_mm256_shuffle_epi8(delta_asso, *src), shifted);
  611|  33.1k|    if (default_or_url) {
  ------------------
  |  Branch (611:9): [Folded, False: 33.1k]
  ------------------
  612|      0|      delta_hash = _mm256_and_si256(delta_hash, _mm256_set1_epi8(0xf));
  613|      0|    }
  614|  33.1k|    const __m256i check_hash =
  615|  33.1k|        _mm256_avg_epu8(_mm256_shuffle_epi8(check_asso, *src), shifted);
  616|  33.1k|    const __m256i out =
  617|  33.1k|        _mm256_adds_epi8(_mm256_shuffle_epi8(delta_values, delta_hash), *src);
  618|  33.1k|    const __m256i chk =
  619|  33.1k|        _mm256_adds_epi8(_mm256_shuffle_epi8(check_values, check_hash), *src);
  620|  33.1k|    const int mask = _mm256_movemask_epi8(chk);
  621|  33.1k|    if (!ignore_garbage && mask) {
  ------------------
  |  Branch (621:9): [True: 33.1k, Folded]
  |  Branch (621:28): [True: 4.71k, False: 28.4k]
  ------------------
  622|  4.71k|      __m256i ascii_space =
  623|  4.71k|          _mm256_cmpeq_epi8(_mm256_shuffle_epi8(ascii_space_tbl, *src), *src);
  624|  4.71k|      *error = (mask ^ _mm256_movemask_epi8(ascii_space));
  625|  4.71k|    }
  626|  33.1k|    *src = out;
  627|  33.1k|    return (uint32_t)mask;
  628|  33.1k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113encode_base64ILb0EEEmPcPKcmNS_14base64_optionsE:
  357|  14.3k|                     base64_options options) {
  358|  14.3k|  return avx2_encode_base64_impl<isbase64url, false>(dst, src, srclen, options);
  359|  14.3k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_123avx2_encode_base64_implILb0ELb0EEEmPcPKcmNS_14base64_optionsEm:
   99|  14.3k|                        size_t line_length = simdutf::default_line_length) {
  100|  14.3k|  size_t offset = 0;
  101|       |
  102|  14.3k|  if (line_length < 4) {
  ------------------
  |  Branch (102:7): [True: 0, False: 14.3k]
  ------------------
  103|      0|    line_length = 4; // We do not support line_length less than 4
  104|      0|  }
  105|       |  // credit: Wojciech Muła
  106|  14.3k|  const uint8_t *input = (const uint8_t *)src;
  107|       |
  108|  14.3k|  uint8_t *out = (uint8_t *)dst;
  109|  14.3k|  const __m256i shuf =
  110|  14.3k|      _mm256_set_epi8(10, 11, 9, 10, 7, 8, 6, 7, 4, 5, 3, 4, 1, 2, 0, 1,
  111|       |
  112|  14.3k|                      10, 11, 9, 10, 7, 8, 6, 7, 4, 5, 3, 4, 1, 2, 0, 1);
  113|  14.3k|  size_t i = 0;
  114|  16.4k|  for (; i + 100 <= srclen; i += 96) {
  ------------------
  |  Branch (114:10): [True: 2.01k, False: 14.3k]
  ------------------
  115|  2.01k|    const __m128i lo0 = _mm_loadu_si128(
  116|  2.01k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 0));
  117|  2.01k|    const __m128i hi0 = _mm_loadu_si128(
  118|  2.01k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 1));
  119|  2.01k|    const __m128i lo1 = _mm_loadu_si128(
  120|  2.01k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 2));
  121|  2.01k|    const __m128i hi1 = _mm_loadu_si128(
  122|  2.01k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 3));
  123|  2.01k|    const __m128i lo2 = _mm_loadu_si128(
  124|  2.01k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 4));
  125|  2.01k|    const __m128i hi2 = _mm_loadu_si128(
  126|  2.01k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 5));
  127|  2.01k|    const __m128i lo3 = _mm_loadu_si128(
  128|  2.01k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 6));
  129|  2.01k|    const __m128i hi3 = _mm_loadu_si128(
  130|  2.01k|        reinterpret_cast<const __m128i *>(input + i + 4 * 3 * 7));
  131|       |
  132|  2.01k|    __m256i in0 = _mm256_shuffle_epi8(_mm256_set_m128i(hi0, lo0), shuf);
  ------------------
  |  |    4|  2.01k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  2.01k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  133|  2.01k|    __m256i in1 = _mm256_shuffle_epi8(_mm256_set_m128i(hi1, lo1), shuf);
  ------------------
  |  |    4|  2.01k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  2.01k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  134|  2.01k|    __m256i in2 = _mm256_shuffle_epi8(_mm256_set_m128i(hi2, lo2), shuf);
  ------------------
  |  |    4|  2.01k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  2.01k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  135|  2.01k|    __m256i in3 = _mm256_shuffle_epi8(_mm256_set_m128i(hi3, lo3), shuf);
  ------------------
  |  |    4|  2.01k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  2.01k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  136|       |
  137|  2.01k|    const __m256i t0_0 = _mm256_and_si256(in0, _mm256_set1_epi32(0x0fc0fc00));
  138|  2.01k|    const __m256i t0_1 = _mm256_and_si256(in1, _mm256_set1_epi32(0x0fc0fc00));
  139|  2.01k|    const __m256i t0_2 = _mm256_and_si256(in2, _mm256_set1_epi32(0x0fc0fc00));
  140|  2.01k|    const __m256i t0_3 = _mm256_and_si256(in3, _mm256_set1_epi32(0x0fc0fc00));
  141|       |
  142|  2.01k|    const __m256i t1_0 =
  143|  2.01k|        _mm256_mulhi_epu16(t0_0, _mm256_set1_epi32(0x04000040));
  144|  2.01k|    const __m256i t1_1 =
  145|  2.01k|        _mm256_mulhi_epu16(t0_1, _mm256_set1_epi32(0x04000040));
  146|  2.01k|    const __m256i t1_2 =
  147|  2.01k|        _mm256_mulhi_epu16(t0_2, _mm256_set1_epi32(0x04000040));
  148|  2.01k|    const __m256i t1_3 =
  149|  2.01k|        _mm256_mulhi_epu16(t0_3, _mm256_set1_epi32(0x04000040));
  150|       |
  151|  2.01k|    const __m256i t2_0 = _mm256_and_si256(in0, _mm256_set1_epi32(0x003f03f0));
  152|  2.01k|    const __m256i t2_1 = _mm256_and_si256(in1, _mm256_set1_epi32(0x003f03f0));
  153|  2.01k|    const __m256i t2_2 = _mm256_and_si256(in2, _mm256_set1_epi32(0x003f03f0));
  154|  2.01k|    const __m256i t2_3 = _mm256_and_si256(in3, _mm256_set1_epi32(0x003f03f0));
  155|       |
  156|  2.01k|    const __m256i t3_0 =
  157|  2.01k|        _mm256_mullo_epi16(t2_0, _mm256_set1_epi32(0x01000010));
  158|  2.01k|    const __m256i t3_1 =
  159|  2.01k|        _mm256_mullo_epi16(t2_1, _mm256_set1_epi32(0x01000010));
  160|  2.01k|    const __m256i t3_2 =
  161|  2.01k|        _mm256_mullo_epi16(t2_2, _mm256_set1_epi32(0x01000010));
  162|  2.01k|    const __m256i t3_3 =
  163|  2.01k|        _mm256_mullo_epi16(t2_3, _mm256_set1_epi32(0x01000010));
  164|       |
  165|  2.01k|    const __m256i input0 = _mm256_or_si256(t1_0, t3_0);
  166|  2.01k|    const __m256i input1 = _mm256_or_si256(t1_1, t3_1);
  167|  2.01k|    const __m256i input2 = _mm256_or_si256(t1_2, t3_2);
  168|  2.01k|    const __m256i input3 = _mm256_or_si256(t1_3, t3_3);
  169|       |
  170|  2.01k|    if (use_lines) {
  ------------------
  |  Branch (170:9): [Folded, False: 2.01k]
  ------------------
  171|      0|      if (line_length >= 32) { // fast path
  ------------------
  |  Branch (171:11): [True: 0, False: 0]
  ------------------
  172|      0|        __m256i result;
  173|      0|        result = lookup_pshufb_improved<isbase64url>(input0);
  174|      0|        if (offset + 32 > line_length) {
  ------------------
  |  Branch (174:13): [True: 0, False: 0]
  ------------------
  175|      0|          size_t location_end = line_length - offset;
  176|      0|          size_t to_move = 32 - location_end;
  177|       |          // We could do this, or extract instead.
  178|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 1), result);
  179|      0|          _mm256_storeu_si256(
  180|      0|              reinterpret_cast<__m256i *>(out),
  181|      0|              insert_line_feed32(result, static_cast<int>(location_end)));
  182|      0|          offset = to_move;
  183|      0|          out += 32 + 1;
  184|      0|        } else {
  185|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), result);
  186|      0|          offset += 32;
  187|      0|          out += 32;
  188|      0|        }
  189|      0|        result = lookup_pshufb_improved<isbase64url>(input1);
  190|       |
  191|      0|        if (offset + 32 > line_length) {
  ------------------
  |  Branch (191:13): [True: 0, False: 0]
  ------------------
  192|      0|          size_t location_end = line_length - offset;
  193|      0|          size_t to_move = 32 - location_end;
  194|       |
  195|       |          // We could do this, or extract instead.
  196|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 1), result);
  197|      0|          _mm256_storeu_si256(
  198|      0|              reinterpret_cast<__m256i *>(out),
  199|      0|              insert_line_feed32(result, static_cast<int>(location_end)));
  200|       |          // see above.
  201|       |          // out[32] = static_cast<uint8_t>(_mm256_extract_epi8(result, 31));
  202|      0|          offset = to_move;
  203|      0|          out += 32 + 1;
  204|      0|        } else {
  205|       |
  206|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), result);
  207|       |
  208|      0|          offset += 32;
  209|      0|          out += 32;
  210|      0|        }
  211|      0|        result = lookup_pshufb_improved<isbase64url>(input2);
  212|       |
  213|      0|        if (offset + 32 > line_length) {
  ------------------
  |  Branch (213:13): [True: 0, False: 0]
  ------------------
  214|      0|          size_t location_end = line_length - offset;
  215|      0|          size_t to_move = 32 - location_end;
  216|       |
  217|       |          // We could do this, or extract instead.
  218|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 1), result);
  219|      0|          _mm256_storeu_si256(
  220|      0|              reinterpret_cast<__m256i *>(out),
  221|      0|              insert_line_feed32(result, static_cast<int>(location_end)));
  222|       |          // see above.
  223|       |          // out[32] = static_cast<uint8_t>(_mm256_extract_epi8(result, 31));
  224|      0|          offset = to_move;
  225|      0|          out += 32 + 1;
  226|      0|        } else {
  227|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), result);
  228|      0|          offset += 32;
  229|      0|          out += 32;
  230|      0|        }
  231|      0|        result = lookup_pshufb_improved<isbase64url>(input3);
  232|       |
  233|      0|        if (offset + 32 > line_length) {
  ------------------
  |  Branch (233:13): [True: 0, False: 0]
  ------------------
  234|      0|          size_t location_end = line_length - offset;
  235|      0|          size_t to_move = 32 - location_end;
  236|       |
  237|       |          // We could do this, or extract instead.
  238|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 1), result);
  239|      0|          _mm256_storeu_si256(
  240|      0|              reinterpret_cast<__m256i *>(out),
  241|      0|              insert_line_feed32(result, static_cast<int>(location_end)));
  242|       |          // see above.
  243|       |          // out[32] = static_cast<uint8_t>(_mm256_extract_epi8(result, 31));
  244|      0|          offset = to_move;
  245|      0|          out += 32 + 1;
  246|      0|        } else {
  247|      0|          _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), result);
  248|      0|          offset += 32;
  249|      0|          out += 32;
  250|      0|        }
  251|      0|      } else { // slow path
  252|       |        // could be optimized
  253|      0|        uint8_t buffer[128];
  254|      0|        _mm256_storeu_si256(reinterpret_cast<__m256i *>(buffer),
  255|      0|                            lookup_pshufb_improved<isbase64url>(input0));
  256|      0|        _mm256_storeu_si256(reinterpret_cast<__m256i *>(buffer + 32),
  257|      0|                            lookup_pshufb_improved<isbase64url>(input1));
  258|      0|        _mm256_storeu_si256(reinterpret_cast<__m256i *>(buffer + 64),
  259|      0|                            lookup_pshufb_improved<isbase64url>(input2));
  260|      0|        _mm256_storeu_si256(reinterpret_cast<__m256i *>(buffer + 96),
  261|      0|                            lookup_pshufb_improved<isbase64url>(input3));
  262|      0|        size_t out_pos = 0;
  263|      0|        size_t local_offset = offset;
  264|      0|        for (size_t j = 0; j < 128;) {
  ------------------
  |  Branch (264:28): [True: 0, False: 0]
  ------------------
  265|      0|          if (local_offset == line_length) {
  ------------------
  |  Branch (265:15): [True: 0, False: 0]
  ------------------
  266|      0|            out[out_pos++] = '\n';
  267|      0|            local_offset = 0;
  268|      0|          }
  269|      0|          out[out_pos++] = buffer[j++];
  270|      0|          local_offset++;
  271|      0|        }
  272|      0|        offset = local_offset;
  273|      0|        out += out_pos;
  274|      0|      }
  275|  2.01k|    } else {
  276|  2.01k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(out),
  277|  2.01k|                          lookup_pshufb_improved<isbase64url>(input0));
  278|  2.01k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 32),
  279|  2.01k|                          lookup_pshufb_improved<isbase64url>(input1));
  280|  2.01k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 64),
  281|  2.01k|                          lookup_pshufb_improved<isbase64url>(input2));
  282|  2.01k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(out + 96),
  283|  2.01k|                          lookup_pshufb_improved<isbase64url>(input3));
  284|       |
  285|  2.01k|      out += 128;
  286|  2.01k|    }
  287|  2.01k|  }
  288|  16.0k|  for (; i + 28 <= srclen; i += 24) {
  ------------------
  |  Branch (288:10): [True: 1.63k, False: 14.3k]
  ------------------
  289|       |    // lo = [xxxx|DDDC|CCBB|BAAA]
  290|       |    // hi = [xxxx|HHHG|GGFF|FEEE]
  291|  1.63k|    const __m128i lo =
  292|  1.63k|        _mm_loadu_si128(reinterpret_cast<const __m128i *>(input + i));
  293|  1.63k|    const __m128i hi =
  294|  1.63k|        _mm_loadu_si128(reinterpret_cast<const __m128i *>(input + i + 4 * 3));
  295|       |
  296|       |    // bytes from groups A, B and C are needed in separate 32-bit lanes
  297|       |    // in = [0HHH|0GGG|0FFF|0EEE[0DDD|0CCC|0BBB|0AAA]
  298|  1.63k|    __m256i in = _mm256_shuffle_epi8(_mm256_set_m128i(hi, lo), shuf);
  ------------------
  |  |    4|  1.63k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  1.63k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  299|       |
  300|       |    // this part is well commented in encode.sse.cpp
  301|       |
  302|  1.63k|    const __m256i t0 = _mm256_and_si256(in, _mm256_set1_epi32(0x0fc0fc00));
  303|  1.63k|    const __m256i t1 = _mm256_mulhi_epu16(t0, _mm256_set1_epi32(0x04000040));
  304|  1.63k|    const __m256i t2 = _mm256_and_si256(in, _mm256_set1_epi32(0x003f03f0));
  305|  1.63k|    const __m256i t3 = _mm256_mullo_epi16(t2, _mm256_set1_epi32(0x01000010));
  306|  1.63k|    const __m256i indices = _mm256_or_si256(t1, t3);
  307|       |
  308|  1.63k|    if (use_lines) {
  ------------------
  |  Branch (308:9): [Folded, False: 1.63k]
  ------------------
  309|      0|      if (line_length >= 32) { // fast path
  ------------------
  |  Branch (309:11): [True: 0, False: 0]
  ------------------
  310|      0|        _mm256_storeu_si256(reinterpret_cast<__m256i *>(out),
  311|      0|                            lookup_pshufb_improved<isbase64url>(indices));
  312|       |
  313|      0|        if (offset + 32 > line_length) {
  ------------------
  |  Branch (313:13): [True: 0, False: 0]
  ------------------
  314|      0|          size_t location_end = line_length - offset;
  315|      0|          size_t to_move = 32 - location_end;
  316|      0|          std::memmove(out + location_end + 1, out + location_end, to_move);
  317|      0|          out[location_end] = '\n';
  318|      0|          offset = to_move;
  319|      0|          out += 32 + 1;
  320|      0|        } else {
  321|      0|          offset += 32;
  322|      0|          out += 32;
  323|      0|        }
  324|      0|      } else { // slow path
  325|       |        // could be optimized
  326|      0|        alignas(32) uint8_t buffer[32];
  327|      0|        _mm256_storeu_si256(reinterpret_cast<__m256i *>(buffer),
  328|      0|                            lookup_pshufb_improved<isbase64url>(indices));
  329|      0|        std::memcpy(out, buffer, 32);
  330|      0|        size_t out_pos = 0;
  331|      0|        size_t local_offset = offset;
  332|      0|        for (size_t j = 0; j < 32;) {
  ------------------
  |  Branch (332:28): [True: 0, False: 0]
  ------------------
  333|      0|          if (local_offset == line_length) {
  ------------------
  |  Branch (333:15): [True: 0, False: 0]
  ------------------
  334|      0|            out[out_pos++] = '\n';
  335|      0|            local_offset = 0;
  336|      0|          }
  337|      0|          out[out_pos++] = buffer[j++];
  338|      0|          local_offset++;
  339|      0|        }
  340|      0|        offset = local_offset;
  341|      0|        out += out_pos;
  342|      0|      }
  343|  1.63k|    } else {
  344|  1.63k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(out),
  345|  1.63k|                          lookup_pshufb_improved<isbase64url>(indices));
  346|       |
  347|  1.63k|      out += 32;
  348|  1.63k|    }
  349|  1.63k|  }
  350|  14.3k|  return ((char *)out - (char *)dst) +
  351|  14.3k|         scalar::base64::tail_encode_base64_impl<use_lines>(
  352|  14.3k|             (char *)out, src + i, srclen - i, options, line_length, offset);
  353|  14.3k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_122lookup_pshufb_improvedILb0EEEDv4_xS3_:
   30|  9.69k|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|  9.69k|  __m256i result = _mm256_subs_epu8(input, _mm256_set1_epi8(51));
   34|  9.69k|  const __m256i less = _mm256_cmpgt_epi8(_mm256_set1_epi8(26), input);
   35|  9.69k|  result =
   36|  9.69k|      _mm256_or_si256(result, _mm256_and_si256(less, _mm256_set1_epi8(13)));
   37|  9.69k|  __m256i shift_LUT;
   38|  9.69k|  if (base64_url) {
  ------------------
  |  Branch (38:7): [Folded, False: 9.69k]
  ------------------
   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|  9.69k|  } else {
   46|  9.69k|    shift_LUT = _mm256_setr_epi8(
   47|  9.69k|        'a' - 26, '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52,
   48|  9.69k|        '0' - 52, '0' - 52, '0' - 52, '0' - 52, '+' - 62, '/' - 63, 'A', 0, 0,
   49|       |
   50|  9.69k|        'a' - 26, '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52, '0' - 52,
   51|  9.69k|        '0' - 52, '0' - 52, '0' - 52, '0' - 52, '+' - 62, '/' - 63, 'A', 0, 0);
   52|  9.69k|  }
   53|       |
   54|  9.69k|  result = _mm256_shuffle_epi8(shift_LUT, result);
   55|  9.69k|  return _mm256_add_epi8(result, input);
   56|  9.69k|}

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128avx2_convert_latin1_to_utf32EPKcmPDi:
    3|  5.26k|                             char32_t *utf32_output) {
    4|  5.26k|  size_t rounded_len = ((len | 7) ^ 7); // Round down to nearest multiple of 8
    5|       |
    6|  24.2k|  for (size_t i = 0; i < rounded_len; i += 8) {
  ------------------
  |  Branch (6:22): [True: 18.9k, False: 5.26k]
  ------------------
    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.26k|  return std::make_pair(buf + rounded_len, utf32_output + rounded_len);
   20|  5.26k|}

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

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

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128avx2_convert_utf32_to_latin1EPKDimPc:
    3|  5.26k|                             char *latin1_output) {
    4|  5.26k|  const size_t rounded_len =
    5|  5.26k|      len & ~0x1F; // Round down to nearest multiple of 32
    6|       |
    7|  5.26k|  const __m256i high_bytes_mask = _mm256_set1_epi32(0xFFFFFF00);
    8|       |
    9|  9.84k|  for (size_t i = 0; i < rounded_len; i += 4 * 8) {
  ------------------
  |  Branch (9:22): [True: 4.58k, False: 5.26k]
  ------------------
   10|  4.58k|    __m256i a = _mm256_loadu_si256((__m256i *)(buf + 0 * 8));
   11|  4.58k|    __m256i b = _mm256_loadu_si256((__m256i *)(buf + 1 * 8));
   12|  4.58k|    __m256i c = _mm256_loadu_si256((__m256i *)(buf + 2 * 8));
   13|  4.58k|    __m256i d = _mm256_loadu_si256((__m256i *)(buf + 3 * 8));
   14|       |
   15|  4.58k|    const __m256i check_combined =
   16|  4.58k|        _mm256_or_si256(_mm256_or_si256(a, b), _mm256_or_si256(c, d));
   17|       |
   18|  4.58k|    if (!_mm256_testz_si256(check_combined, high_bytes_mask)) {
  ------------------
  |  Branch (18:9): [True: 0, False: 4.58k]
  ------------------
   19|      0|      return std::make_pair(nullptr, latin1_output);
   20|      0|    }
   21|       |
   22|  4.58k|    b = _mm256_slli_epi32(b, 1 * 8);
   23|  4.58k|    c = _mm256_slli_epi32(c, 2 * 8);
   24|  4.58k|    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.58k|    const __m256i t0 =
   35|  4.58k|        _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.58k|    const __m256i shuffle_bytes =
   40|  4.58k|        _mm256_setr_epi8(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15,
   41|  4.58k|                         0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15);
   42|       |
   43|  4.58k|    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.58k|    const __m256i shuffle_dwords = _mm256_setr_epi32(0, 4, 1, 5, 2, 6, 3, 7);
   48|  4.58k|    const __m256i t2 = _mm256_permutevar8x32_epi32(t1, shuffle_dwords);
   49|       |// clang format on
   50|       |
   51|  4.58k|    _mm256_storeu_si256((__m256i *)latin1_output, t2);
   52|       |
   53|  4.58k|    latin1_output += 32;
   54|  4.58k|    buf += 32;
   55|  4.58k|  }
   56|       |
   57|  5.26k|  return std::make_pair(buf, latin1_output);
   58|  5.26k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_126avx2_convert_utf32_to_utf8EPKDimPc:
    2|  4.66k|avx2_convert_utf32_to_utf8(const char32_t *buf, size_t len, char *utf8_output) {
    3|  4.66k|  const char32_t *end = buf + len;
    4|  4.66k|  const __m256i v_0000 = _mm256_setzero_si256();
    5|  4.66k|  const __m256i v_ffff0000 = _mm256_set1_epi32((uint32_t)0xffff0000);
    6|  4.66k|  const __m256i v_ff80 = _mm256_set1_epi16((uint16_t)0xff80);
    7|  4.66k|  const __m256i v_f800 = _mm256_set1_epi16((uint16_t)0xf800);
    8|  4.66k|  const __m256i v_c080 = _mm256_set1_epi16((uint16_t)0xc080);
    9|  4.66k|  const __m256i v_7fffffff = _mm256_set1_epi32((uint32_t)0x7fffffff);
   10|  4.66k|  __m256i running_max = _mm256_setzero_si256();
   11|  4.66k|  __m256i forbidden_bytemask = _mm256_setzero_si256();
   12|       |
   13|  4.66k|  const size_t safety_margin =
   14|  4.66k|      12; // to avoid overruns, see issue
   15|       |          // https://github.com/simdutf/simdutf/issues/92
   16|       |
   17|  8.02k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (17:10): [True: 3.35k, False: 4.66k]
  ------------------
   18|  3.35k|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
   19|  3.35k|    __m256i nextin = _mm256_loadu_si256((__m256i *)buf + 1);
   20|  3.35k|    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.35k|    __m256i in_16 = _mm256_packus_epi32(_mm256_and_si256(in, v_7fffffff),
   25|  3.35k|                                        _mm256_and_si256(nextin, v_7fffffff));
   26|  3.35k|    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.35k|    if (_mm256_testz_si256(in_16, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (31:9): [True: 2.26k, False: 1.08k]
  ------------------
   32|       |      // 1. pack the bytes
   33|  2.26k|      const __m128i utf8_packed = _mm_packus_epi16(
   34|  2.26k|          _mm256_castsi256_si128(in_16), _mm256_extractf128_si256(in_16, 1));
   35|       |      // 2. store (16 bytes)
   36|  2.26k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   37|       |      // 3. adjust pointers
   38|  2.26k|      buf += 16;
   39|  2.26k|      utf8_output += 16;
   40|  2.26k|      continue; // we are done for this round!
   41|  2.26k|    }
   42|       |    // no bits set above 7th bit
   43|  1.08k|    const __m256i one_byte_bytemask =
   44|  1.08k|        _mm256_cmpeq_epi16(_mm256_and_si256(in_16, v_ff80), v_0000);
   45|  1.08k|    const uint32_t one_byte_bitmask =
   46|  1.08k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
   47|       |
   48|       |    // no bits set above 11th bit
   49|  1.08k|    const __m256i one_or_two_bytes_bytemask =
   50|  1.08k|        _mm256_cmpeq_epi16(_mm256_and_si256(in_16, v_f800), v_0000);
   51|  1.08k|    const uint32_t one_or_two_bytes_bitmask =
   52|  1.08k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
   53|  1.08k|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (53:9): [True: 153, False: 932]
  ------------------
   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|    153|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
   58|    153|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
   59|       |
   60|       |      // t0 = [000a|aaaa|bbbb|bb00]
   61|    153|      const __m256i t0 = _mm256_slli_epi16(in_16, 2);
   62|       |      // t1 = [000a|aaaa|0000|0000]
   63|    153|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
   64|       |      // t2 = [0000|0000|00bb|bbbb]
   65|    153|      const __m256i t2 = _mm256_and_si256(in_16, v_003f);
   66|       |      // t3 = [000a|aaaa|00bb|bbbb]
   67|    153|      const __m256i t3 = _mm256_or_si256(t1, t2);
   68|       |      // t4 = [110a|aaaa|10bb|bbbb]
   69|    153|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
   70|       |
   71|       |      // 2. merge ASCII and 2-byte codewords
   72|    153|      const __m256i utf8_unpacked =
   73|    153|          _mm256_blendv_epi8(t4, in_16, one_byte_bytemask);
   74|       |
   75|       |      // 3. prepare bitmask for 8-bit lookup
   76|    153|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
   77|    153|      const uint32_t M1 = M0 >> 7;
   78|    153|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
   79|       |      // 4. pack the bytes
   80|       |
   81|    153|      const uint8_t *row =
   82|    153|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
   83|    153|      const uint8_t *row_2 =
   84|    153|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
   85|    153|                                                                       16)][0];
   86|       |
   87|    153|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
   88|    153|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
   89|       |
   90|    153|      const __m256i utf8_packed = _mm256_shuffle_epi8(
   91|    153|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|    153|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|    153|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
   92|       |      // 5. store bytes
   93|    153|      _mm_storeu_si128((__m128i *)utf8_output,
   94|    153|                       _mm256_castsi256_si128(utf8_packed));
   95|    153|      utf8_output += row[0];
   96|    153|      _mm_storeu_si128((__m128i *)utf8_output,
   97|    153|                       _mm256_extractf128_si256(utf8_packed, 1));
   98|    153|      utf8_output += row_2[0];
   99|       |
  100|       |      // 6. adjust pointers
  101|    153|      buf += 16;
  102|    153|      continue;
  103|    153|    }
  104|       |    // Must check for overflow in packing
  105|    932|    const __m256i saturation_bytemask = _mm256_cmpeq_epi32(
  106|    932|        _mm256_and_si256(_mm256_or_si256(in, nextin), v_ffff0000), v_0000);
  107|    932|    const uint32_t saturation_bitmask =
  108|    932|        static_cast<uint32_t>(_mm256_movemask_epi8(saturation_bytemask));
  109|    932|    if (saturation_bitmask == 0xffffffff) {
  ------------------
  |  Branch (109:9): [True: 124, False: 808]
  ------------------
  110|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  111|    124|      const __m256i v_d800 = _mm256_set1_epi16((uint16_t)0xd800);
  112|    124|      forbidden_bytemask = _mm256_or_si256(
  113|    124|          forbidden_bytemask,
  114|    124|          _mm256_cmpeq_epi16(_mm256_and_si256(in_16, v_f800), v_d800));
  115|       |
  116|    124|      const __m256i dup_even = _mm256_setr_epi16(
  117|    124|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  118|    124|          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|    124|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  148|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  149|    124|      const __m256i t0 = _mm256_shuffle_epi8(in_16, dup_even);
  150|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  151|    124|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  147|    124|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  152|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  153|    124|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  147|    124|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  154|       |
  155|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  156|    124|      const __m256i s0 = _mm256_srli_epi16(in_16, 4);
  157|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  158|    124|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  147|    124|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  159|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  160|    124|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  147|    124|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  161|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  162|    124|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  147|    124|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  163|    124|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  164|    124|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  147|    124|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  165|    124|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  166|    124|#undef simdutf_vec
  167|       |
  168|       |      // 4. expand code units 16-bit => 32-bit
  169|    124|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  170|    124|      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|    124|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  174|    124|                            (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|    124|      const uint8_t mask0 = uint8_t(mask);
  195|    124|      const uint8_t *row0 =
  196|    124|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  197|    124|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  198|    124|      const __m128i utf8_0 =
  199|    124|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  200|       |
  201|    124|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  202|    124|      const uint8_t *row1 =
  203|    124|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  204|    124|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  205|    124|      const __m128i utf8_1 =
  206|    124|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  207|       |
  208|    124|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  209|    124|      const uint8_t *row2 =
  210|    124|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  211|    124|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  212|    124|      const __m128i utf8_2 =
  213|    124|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  214|       |
  215|    124|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  216|    124|      const uint8_t *row3 =
  217|    124|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  218|    124|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  219|    124|      const __m128i utf8_3 =
  220|    124|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  221|       |
  222|    124|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  223|    124|      utf8_output += row0[0];
  224|    124|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  225|    124|      utf8_output += row1[0];
  226|    124|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  227|    124|      utf8_output += row2[0];
  228|    124|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  229|    124|      utf8_output += row3[0];
  230|    124|      buf += 16;
  231|    808|    } 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|    808|      size_t forward = 15;
  237|    808|      size_t k = 0;
  238|    808|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (238:11): [True: 0, False: 808]
  ------------------
  239|      0|        forward = size_t(end - buf - 1);
  240|      0|      }
  241|  12.9k|      for (; k < forward; k++) {
  ------------------
  |  Branch (241:14): [True: 12.1k, False: 808]
  ------------------
  242|  12.1k|        uint32_t word = buf[k];
  243|  12.1k|        if ((word & 0xFFFFFF80) == 0) { // 1-byte (ASCII)
  ------------------
  |  Branch (243:13): [True: 9.74k, False: 2.37k]
  ------------------
  244|  9.74k|          *utf8_output++ = char(word);
  245|  9.74k|        } else if ((word & 0xFFFFF800) == 0) { // 2-byte
  ------------------
  |  Branch (245:20): [True: 480, False: 1.89k]
  ------------------
  246|    480|          *utf8_output++ = char((word >> 6) | 0b11000000);
  247|    480|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  248|  1.89k|        } else if ((word & 0xFFFF0000) == 0) { // 3-byte
  ------------------
  |  Branch (248:20): [True: 636, False: 1.25k]
  ------------------
  249|    636|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (249:15): [True: 311, False: 325]
  |  Branch (249:33): [True: 0, False: 311]
  ------------------
  250|      0|            return std::make_pair(nullptr, utf8_output);
  251|      0|          }
  252|    636|          *utf8_output++ = char((word >> 12) | 0b11100000);
  253|    636|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  254|    636|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  255|  1.25k|        } else { // 4-byte
  256|  1.25k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (256:15): [True: 0, False: 1.25k]
  ------------------
  257|      0|            return std::make_pair(nullptr, utf8_output);
  258|      0|          }
  259|  1.25k|          *utf8_output++ = char((word >> 18) | 0b11110000);
  260|  1.25k|          *utf8_output++ = char(((word >> 12) & 0b111111) | 0b10000000);
  261|  1.25k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  262|  1.25k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  263|  1.25k|        }
  264|  12.1k|      }
  265|    808|      buf += k;
  266|    808|    }
  267|    932|  } // while
  268|       |
  269|       |  // check for invalid input
  270|  4.66k|  const __m256i v_10ffff = _mm256_set1_epi32((uint32_t)0x10ffff);
  271|  4.66k|  if (static_cast<uint32_t>(_mm256_movemask_epi8(_mm256_cmpeq_epi32(
  ------------------
  |  Branch (271:7): [True: 0, False: 4.66k]
  ------------------
  272|  4.66k|          _mm256_max_epu32(running_max, v_10ffff), v_10ffff))) != 0xffffffff) {
  273|      0|    return std::make_pair(nullptr, utf8_output);
  274|      0|  }
  275|       |
  276|  4.66k|  if (static_cast<uint32_t>(_mm256_movemask_epi8(forbidden_bytemask)) != 0) {
  ------------------
  |  Branch (276:7): [True: 0, False: 4.66k]
  ------------------
  277|      0|    return std::make_pair(nullptr, utf8_output);
  278|      0|  }
  279|       |
  280|  4.66k|  return std::make_pair(buf, utf8_output);
  281|  4.66k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_129convert_masked_utf8_to_latin1EPKcmRPc:
    9|  16.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|  16.5k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   21|       |
   22|  16.5k|  const uint16_t input_utf8_end_of_code_point_mask =
   23|  16.5k|      utf8_end_of_code_point_mask &
   24|  16.5k|      0xfff; // we are only processing 12 bytes in case it is not all ASCII
   25|       |
   26|  16.5k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (26:7): [True: 124, False: 16.4k]
  ------------------
   27|       |    // We process the data in chunks of 12 bytes.
   28|    124|    _mm_storeu_si128(reinterpret_cast<__m128i *>(latin1_output), in);
   29|    124|    latin1_output += 12; // We wrote 12 characters.
   30|    124|    return 12;           // We consumed 1 bytes.
   31|    124|  }
   32|       |  /// We do not have a fast path available, so we fallback.
   33|  16.4k|  const uint8_t idx =
   34|  16.4k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   35|  16.4k|  const uint8_t consumed =
   36|  16.4k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   37|       |  // this indicates an invalid input:
   38|  16.4k|  if (idx >= 64) {
  ------------------
  |  Branch (38:7): [True: 5.22k, False: 11.1k]
  ------------------
   39|  5.22k|    return consumed;
   40|  5.22k|  }
   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|  11.1k|  const __m128i sh =
   48|  11.1k|      _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   49|  11.1k|  const __m128i perm = _mm_shuffle_epi8(in, sh);
   50|  11.1k|  const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   51|  11.1k|  const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   52|  11.1k|  __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   53|  11.1k|  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|  11.1k|  _mm_storel_epi64((__m128i *)latin1_output, latin1_packed);
   58|  11.1k|  latin1_output += 6; // We wrote 6 bytes.
   59|  11.1k|  return consumed;
   60|  16.4k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128convert_masked_utf8_to_utf16ILNS_10endiannessE0EEEmPKcmRPDs:
   10|  15.1k|                                    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.1k|  const __m128i swap =
   23|  15.1k|      _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   24|  15.1k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   25|  15.1k|  const uint16_t input_utf8_end_of_code_point_mask =
   26|  15.1k|      utf8_end_of_code_point_mask & 0xfff;
   27|  15.1k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (27:7): [True: 95, False: 15.0k]
  ------------------
   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): [Folded, False: 95]
  ------------------
   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|     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.0k|  if (((utf8_end_of_code_point_mask & 0xffff) == 0xaaaa)) {
  ------------------
  |  Branch (40:7): [True: 142, False: 14.9k]
  ------------------
   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|    142|    const __m128i sh =
   45|    142|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   46|    142|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   47|    142|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   48|    142|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   49|    142|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   50|    142|    if (big_endian)
  ------------------
  |  Branch (50:9): [Folded, False: 142]
  ------------------
   51|      0|      composed = _mm_shuffle_epi8(composed, swap);
   52|    142|    _mm_storeu_si128((__m128i *)utf16_output, composed);
   53|    142|    utf16_output += 8; // We wrote 16 bytes, 8 code points.
   54|    142|    return 16;
   55|    142|  }
   56|  14.9k|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (56:7): [True: 3.51k, False: 11.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.51k|    const __m128i sh =
   61|  3.51k|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   62|  3.51k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   63|  3.51k|    const __m128i ascii =
   64|  3.51k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   65|  3.51k|    const __m128i middlebyte =
   66|  3.51k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   67|  3.51k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   68|  3.51k|    const __m128i highbyte =
   69|  3.51k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   70|  3.51k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   71|  3.51k|    const __m128i composed =
   72|  3.51k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   73|  3.51k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
   74|  3.51k|    if (big_endian)
  ------------------
  |  Branch (74:9): [Folded, False: 3.51k]
  ------------------
   75|      0|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
   76|  3.51k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
   77|  3.51k|    utf16_output += 4;
   78|  3.51k|    return 12;
   79|  3.51k|  }
   80|       |
   81|  11.4k|  const uint8_t idx = simdutf::tables::utf8_to_utf16::utf8bigindex
   82|  11.4k|      [input_utf8_end_of_code_point_mask][0];
   83|  11.4k|  const uint8_t consumed = simdutf::tables::utf8_to_utf16::utf8bigindex
   84|  11.4k|      [input_utf8_end_of_code_point_mask][1];
   85|  11.4k|  if (idx < 64) {
  ------------------
  |  Branch (85:7): [True: 4.65k, False: 6.76k]
  ------------------
   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.65k|    const __m128i sh = _mm_loadu_si128(
   93|  4.65k|        (const __m128i *)simdutf::tables::utf8_to_utf16::shufutf8[idx]);
   94|  4.65k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   95|  4.65k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   96|  4.65k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   97|  4.65k|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   98|  4.65k|    if (big_endian)
  ------------------
  |  Branch (98:9): [Folded, False: 4.65k]
  ------------------
   99|      0|      composed = _mm_shuffle_epi8(composed, swap);
  100|  4.65k|    _mm_storeu_si128((__m128i *)utf16_output, composed);
  101|  4.65k|    utf16_output += 6; // We wrote 12 bytes, 6 code points. There is a potential
  102|       |                       // overflow of 4 bytes.
  103|  6.76k|  } else if (idx < 145) {
  ------------------
  |  Branch (103:14): [True: 1.69k, False: 5.06k]
  ------------------
  104|       |    // FOUR (4) input code-code units
  105|  1.69k|    const __m128i sh = _mm_loadu_si128(
  106|  1.69k|        (const __m128i *)simdutf::tables::utf8_to_utf16::shufutf8[idx]);
  107|  1.69k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  108|  1.69k|    const __m128i ascii =
  109|  1.69k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
  110|  1.69k|    const __m128i middlebyte =
  111|  1.69k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  112|  1.69k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  113|  1.69k|    const __m128i highbyte =
  114|  1.69k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  115|  1.69k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  116|  1.69k|    const __m128i composed =
  117|  1.69k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  118|  1.69k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
  119|  1.69k|    if (big_endian)
  ------------------
  |  Branch (119:9): [Folded, False: 1.69k]
  ------------------
  120|      0|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
  121|  1.69k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
  122|  1.69k|    utf16_output += 4; // Here we overflow by 8 bytes.
  123|  5.06k|  } else if (idx < 209) {
  ------------------
  |  Branch (123:14): [True: 4.86k, False: 200]
  ------------------
  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.86k|    const __m128i sh = _mm_loadu_si128(
  135|  4.86k|        (const __m128i *)simdutf::tables::utf8_to_utf16::shufutf8[idx]);
  136|  4.86k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  137|  4.86k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  138|  4.86k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  139|  4.86k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  140|  4.86k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  141|       |    // correct for spurious high bit
  142|  4.86k|    const __m128i correct =
  143|  4.86k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  144|  4.86k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  145|  4.86k|    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.86k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0xff000000));
  149|  4.86k|    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.86k|    const __m128i composed =
  155|  4.86k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  156|  4.86k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  157|  4.86k|    const __m128i composedminus =
  158|  4.86k|        _mm_sub_epi32(composed, _mm_set1_epi32(0x10000));
  159|  4.86k|    const __m128i lowtenbits =
  160|  4.86k|        _mm_and_si128(composedminus, _mm_set1_epi32(0x3ff));
  161|       |    // Notice the 0x3ff mask:
  162|  4.86k|    const __m128i hightenbits =
  163|  4.86k|        _mm_and_si128(_mm_srli_epi32(composedminus, 10), _mm_set1_epi32(0x3ff));
  164|  4.86k|    const __m128i lowtenbitsadd =
  165|  4.86k|        _mm_add_epi32(lowtenbits, _mm_set1_epi32(0xDC00));
  166|  4.86k|    const __m128i hightenbitsadd =
  167|  4.86k|        _mm_add_epi32(hightenbits, _mm_set1_epi32(0xD800));
  168|  4.86k|    const __m128i lowtenbitsaddshifted = _mm_slli_epi32(lowtenbitsadd, 16);
  169|  4.86k|    __m128i surrogates = _mm_or_si128(hightenbitsadd, lowtenbitsaddshifted);
  170|  4.86k|    uint32_t basic_buffer[4];
  171|  4.86k|    uint32_t basic_buffer_swap[4];
  172|  4.86k|    if (big_endian) {
  ------------------
  |  Branch (172:9): [Folded, False: 4.86k]
  ------------------
  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.86k|    _mm_storeu_si128((__m128i *)basic_buffer, composed);
  178|  4.86k|    uint32_t surrogate_buffer[4];
  179|  4.86k|    _mm_storeu_si128((__m128i *)surrogate_buffer, surrogates);
  180|  19.4k|    for (size_t i = 0; i < 3; i++) {
  ------------------
  |  Branch (180:24): [True: 14.6k, False: 4.86k]
  ------------------
  181|  14.6k|      if (basic_buffer[i] > 0x3c00000) {
  ------------------
  |  Branch (181:11): [True: 3.00k, False: 11.5k]
  ------------------
  182|  3.00k|        utf16_output[0] = uint16_t(surrogate_buffer[i] & 0xffff);
  183|  3.00k|        utf16_output[1] = uint16_t(surrogate_buffer[i] >> 16);
  184|  3.00k|        utf16_output += 2;
  185|  11.5k|      } else {
  186|  11.5k|        utf16_output[0] = big_endian ? uint16_t(basic_buffer_swap[i])
  ------------------
  |  Branch (186:27): [Folded, False: 11.5k]
  ------------------
  187|  11.5k|                                     : uint16_t(basic_buffer[i]);
  188|  11.5k|        utf16_output++;
  189|  11.5k|      }
  190|  14.6k|    }
  191|  4.86k|  } else {
  192|       |    // here we know that there is an error but we do not handle errors
  193|    200|  }
  194|  11.4k|  return consumed;
  195|  14.9k|}
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: 96, False: 15.5k]
  ------------------
   28|       |    // We process the data in chunks of 12 bytes.
   29|     96|    __m256i ascii = _mm256_cvtepu8_epi16(in);
   30|     96|    if (big_endian) {
  ------------------
  |  Branch (30:9): [True: 96, Folded]
  ------------------
   31|     96|      const __m256i swap256 = _mm256_setr_epi8(
   32|     96|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   33|     96|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   34|     96|      ascii = _mm256_shuffle_epi8(ascii, swap256);
   35|     96|    }
   36|     96|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(utf16_output), ascii);
   37|     96|    utf16_output += 12; // We wrote 12 16-bit characters.
   38|     96|    return 12;          // We consumed 12 bytes.
   39|     96|  }
   40|  15.5k|  if (((utf8_end_of_code_point_mask & 0xffff) == 0xaaaa)) {
  ------------------
  |  Branch (40:7): [True: 121, 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|    121|    const __m128i sh =
   45|    121|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   46|    121|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   47|    121|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   48|    121|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   49|    121|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   50|    121|    if (big_endian)
  ------------------
  |  Branch (50:9): [True: 121, Folded]
  ------------------
   51|    121|      composed = _mm_shuffle_epi8(composed, swap);
   52|    121|    _mm_storeu_si128((__m128i *)utf16_output, composed);
   53|    121|    utf16_output += 8; // We wrote 16 bytes, 8 code points.
   54|    121|    return 16;
   55|    121|  }
   56|  15.3k|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (56:7): [True: 4.01k, False: 11.3k]
  ------------------
   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.01k|    const __m128i sh =
   61|  4.01k|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   62|  4.01k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   63|  4.01k|    const __m128i ascii =
   64|  4.01k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   65|  4.01k|    const __m128i middlebyte =
   66|  4.01k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   67|  4.01k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   68|  4.01k|    const __m128i highbyte =
   69|  4.01k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   70|  4.01k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   71|  4.01k|    const __m128i composed =
   72|  4.01k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   73|  4.01k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
   74|  4.01k|    if (big_endian)
  ------------------
  |  Branch (74:9): [True: 4.01k, Folded]
  ------------------
   75|  4.01k|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
   76|  4.01k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
   77|  4.01k|    utf16_output += 4;
   78|  4.01k|    return 12;
   79|  4.01k|  }
   80|       |
   81|  11.3k|  const uint8_t idx = simdutf::tables::utf8_to_utf16::utf8bigindex
   82|  11.3k|      [input_utf8_end_of_code_point_mask][0];
   83|  11.3k|  const uint8_t consumed = simdutf::tables::utf8_to_utf16::utf8bigindex
   84|  11.3k|      [input_utf8_end_of_code_point_mask][1];
   85|  11.3k|  if (idx < 64) {
  ------------------
  |  Branch (85:7): [True: 4.66k, False: 6.71k]
  ------------------
   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.66k|    const __m128i sh = _mm_loadu_si128(
   93|  4.66k|        (const __m128i *)simdutf::tables::utf8_to_utf16::shufutf8[idx]);
   94|  4.66k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   95|  4.66k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   96|  4.66k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   97|  4.66k|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   98|  4.66k|    if (big_endian)
  ------------------
  |  Branch (98:9): [True: 4.66k, Folded]
  ------------------
   99|  4.66k|      composed = _mm_shuffle_epi8(composed, swap);
  100|  4.66k|    _mm_storeu_si128((__m128i *)utf16_output, composed);
  101|  4.66k|    utf16_output += 6; // We wrote 12 bytes, 6 code points. There is a potential
  102|       |                       // overflow of 4 bytes.
  103|  6.71k|  } else if (idx < 145) {
  ------------------
  |  Branch (103:14): [True: 1.70k, False: 5.00k]
  ------------------
  104|       |    // FOUR (4) input code-code units
  105|  1.70k|    const __m128i sh = _mm_loadu_si128(
  106|  1.70k|        (const __m128i *)simdutf::tables::utf8_to_utf16::shufutf8[idx]);
  107|  1.70k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  108|  1.70k|    const __m128i ascii =
  109|  1.70k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
  110|  1.70k|    const __m128i middlebyte =
  111|  1.70k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  112|  1.70k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  113|  1.70k|    const __m128i highbyte =
  114|  1.70k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  115|  1.70k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  116|  1.70k|    const __m128i composed =
  117|  1.70k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  118|  1.70k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
  119|  1.70k|    if (big_endian)
  ------------------
  |  Branch (119:9): [True: 1.70k, Folded]
  ------------------
  120|  1.70k|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
  121|  1.70k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
  122|  1.70k|    utf16_output += 4; // Here we overflow by 8 bytes.
  123|  5.00k|  } else if (idx < 209) {
  ------------------
  |  Branch (123:14): [True: 4.80k, False: 200]
  ------------------
  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.80k|    const __m128i sh = _mm_loadu_si128(
  135|  4.80k|        (const __m128i *)simdutf::tables::utf8_to_utf16::shufutf8[idx]);
  136|  4.80k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  137|  4.80k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  138|  4.80k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  139|  4.80k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  140|  4.80k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  141|       |    // correct for spurious high bit
  142|  4.80k|    const __m128i correct =
  143|  4.80k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  144|  4.80k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  145|  4.80k|    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.80k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0xff000000));
  149|  4.80k|    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.80k|    const __m128i composed =
  155|  4.80k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  156|  4.80k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  157|  4.80k|    const __m128i composedminus =
  158|  4.80k|        _mm_sub_epi32(composed, _mm_set1_epi32(0x10000));
  159|  4.80k|    const __m128i lowtenbits =
  160|  4.80k|        _mm_and_si128(composedminus, _mm_set1_epi32(0x3ff));
  161|       |    // Notice the 0x3ff mask:
  162|  4.80k|    const __m128i hightenbits =
  163|  4.80k|        _mm_and_si128(_mm_srli_epi32(composedminus, 10), _mm_set1_epi32(0x3ff));
  164|  4.80k|    const __m128i lowtenbitsadd =
  165|  4.80k|        _mm_add_epi32(lowtenbits, _mm_set1_epi32(0xDC00));
  166|  4.80k|    const __m128i hightenbitsadd =
  167|  4.80k|        _mm_add_epi32(hightenbits, _mm_set1_epi32(0xD800));
  168|  4.80k|    const __m128i lowtenbitsaddshifted = _mm_slli_epi32(lowtenbitsadd, 16);
  169|  4.80k|    __m128i surrogates = _mm_or_si128(hightenbitsadd, lowtenbitsaddshifted);
  170|  4.80k|    uint32_t basic_buffer[4];
  171|  4.80k|    uint32_t basic_buffer_swap[4];
  172|  4.80k|    if (big_endian) {
  ------------------
  |  Branch (172:9): [True: 4.80k, Folded]
  ------------------
  173|  4.80k|      _mm_storeu_si128((__m128i *)basic_buffer_swap,
  174|  4.80k|                       _mm_shuffle_epi8(composed, swap));
  175|  4.80k|      surrogates = _mm_shuffle_epi8(surrogates, swap);
  176|  4.80k|    }
  177|  4.80k|    _mm_storeu_si128((__m128i *)basic_buffer, composed);
  178|  4.80k|    uint32_t surrogate_buffer[4];
  179|  4.80k|    _mm_storeu_si128((__m128i *)surrogate_buffer, surrogates);
  180|  19.2k|    for (size_t i = 0; i < 3; i++) {
  ------------------
  |  Branch (180:24): [True: 14.4k, False: 4.80k]
  ------------------
  181|  14.4k|      if (basic_buffer[i] > 0x3c00000) {
  ------------------
  |  Branch (181:11): [True: 2.97k, False: 11.4k]
  ------------------
  182|  2.97k|        utf16_output[0] = uint16_t(surrogate_buffer[i] & 0xffff);
  183|  2.97k|        utf16_output[1] = uint16_t(surrogate_buffer[i] >> 16);
  184|  2.97k|        utf16_output += 2;
  185|  11.4k|      } else {
  186|  11.4k|        utf16_output[0] = big_endian ? uint16_t(basic_buffer_swap[i])
  ------------------
  |  Branch (186:27): [True: 11.4k, Folded]
  ------------------
  187|  11.4k|                                     : uint16_t(basic_buffer[i]);
  188|  11.4k|        utf16_output++;
  189|  11.4k|      }
  190|  14.4k|    }
  191|  4.80k|  } else {
  192|       |    // here we know that there is an error but we do not handle errors
  193|    200|  }
  194|  11.3k|  return consumed;
  195|  15.3k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128convert_masked_utf8_to_utf32EPKcmRPDi:
    9|  10.6k|                                    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|  10.6k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   22|  10.6k|  const uint16_t input_utf8_end_of_code_point_mask =
   23|  10.6k|      utf8_end_of_code_point_mask & 0xfff;
   24|  10.6k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (24:7): [True: 95, False: 10.5k]
  ------------------
   25|       |    // We process the data in chunks of 12 bytes.
   26|     95|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(utf32_output),
   27|     95|                        _mm256_cvtepu8_epi32(in));
   28|     95|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(utf32_output + 8),
   29|     95|                        _mm256_cvtepu8_epi32(_mm_srli_si128(in, 8)));
   30|     95|    utf32_output += 12; // We wrote 12 32-bit characters.
   31|     95|    return 12;          // We consumed 12 bytes.
   32|     95|  }
   33|  10.5k|  if (((utf8_end_of_code_point_mask & 0xffff) == 0xaaaa)) {
  ------------------
  |  Branch (33:7): [True: 92, False: 10.4k]
  ------------------
   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|     92|    const __m128i sh =
   38|     92|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   39|     92|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   40|     92|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   41|     92|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   42|     92|    const __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   43|     92|    _mm256_storeu_si256((__m256i *)utf32_output,
   44|     92|                        _mm256_cvtepu16_epi32(composed));
   45|     92|    utf32_output += 8; // We wrote 16 bytes, 8 code points.
   46|     92|    return 16;
   47|     92|  }
   48|  10.4k|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (48:7): [True: 203, False: 10.2k]
  ------------------
   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|    203|    const __m128i sh =
   53|    203|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   54|    203|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   55|    203|    const __m128i ascii =
   56|    203|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   57|    203|    const __m128i middlebyte =
   58|    203|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   59|    203|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   60|    203|    const __m128i highbyte =
   61|    203|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   62|    203|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   63|    203|    const __m128i composed =
   64|    203|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   65|    203|    _mm_storeu_si128((__m128i *)utf32_output, composed);
   66|    203|    utf32_output += 4;
   67|    203|    return 12;
   68|    203|  }
   69|       |  /// We do not have a fast path available, so we fallback.
   70|       |
   71|  10.2k|  const uint8_t idx =
   72|  10.2k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   73|  10.2k|  const uint8_t consumed =
   74|  10.2k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   75|  10.2k|  if (idx < 64) {
  ------------------
  |  Branch (75:7): [True: 4.53k, False: 5.75k]
  ------------------
   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|  4.53k|    const __m128i sh =
   83|  4.53k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   84|  4.53k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   85|  4.53k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   86|  4.53k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   87|  4.53k|    const __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   88|  4.53k|    _mm256_storeu_si256((__m256i *)utf32_output,
   89|  4.53k|                        _mm256_cvtepu16_epi32(composed));
   90|  4.53k|    utf32_output += 6; // We wrote 24 bytes, 6 code points. There is a potential
   91|       |    // overflow of 32 - 24 = 8 bytes.
   92|  5.75k|  } else if (idx < 145) {
  ------------------
  |  Branch (92:14): [True: 1.19k, False: 4.56k]
  ------------------
   93|       |    // FOUR (4) input code-code units
   94|  1.19k|    const __m128i sh =
   95|  1.19k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   96|  1.19k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   97|  1.19k|    const __m128i ascii =
   98|  1.19k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   99|  1.19k|    const __m128i middlebyte =
  100|  1.19k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  101|  1.19k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  102|  1.19k|    const __m128i highbyte =
  103|  1.19k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  104|  1.19k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  105|  1.19k|    const __m128i composed =
  106|  1.19k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  107|  1.19k|    _mm_storeu_si128((__m128i *)utf32_output, composed);
  108|  1.19k|    utf32_output += 4;
  109|  4.56k|  } else if (idx < 209) {
  ------------------
  |  Branch (109:14): [True: 4.36k, False: 200]
  ------------------
  110|       |    // TWO (2) input code-code units
  111|  4.36k|    const __m128i sh =
  112|  4.36k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  113|  4.36k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  114|  4.36k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  115|  4.36k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  116|  4.36k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  117|  4.36k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  118|       |    // correct for spurious high bit
  119|  4.36k|    const __m128i correct =
  120|  4.36k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  121|  4.36k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  122|  4.36k|    const __m128i middlehighbyte_shifted = _mm_srli_epi32(middlehighbyte, 4);
  123|  4.36k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0x07000000));
  124|  4.36k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 6);
  125|  4.36k|    const __m128i composed =
  126|  4.36k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  127|  4.36k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  128|  4.36k|    _mm_storeu_si128((__m128i *)utf32_output, composed);
  129|  4.36k|    utf32_output +=
  130|  4.36k|        3; // We wrote 3 * 4 bytes, there is a potential overflow of 4 bytes.
  131|  4.36k|  } else {
  132|       |    // here we know that there is an error but we do not handle errors
  133|    200|  }
  134|  10.2k|  return consumed;
  135|  10.4k|}

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

_ZNK7simdutf7haswell14implementation13validate_utf8EPKcm:
  266|  20.8k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
  267|  20.8k|  return haswell::utf8_validation::generic_validate_utf8(buf, len);
  268|  20.8k|}
_ZNK7simdutf7haswell14implementation25validate_utf8_with_errorsEPKcm:
  273|  5.26k|    const char *buf, size_t len) const noexcept {
  274|  5.26k|  return haswell::utf8_validation::generic_validate_utf8_with_errors(buf, len);
  275|  5.26k|}
_ZNK7simdutf7haswell14implementation16validate_utf16leEPKDsm:
  312|  15.2k|                                 size_t len) const noexcept {
  313|  15.2k|  if (simdutf_unlikely(len == 0)) {
  ------------------
  |  |   93|  15.2k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 12.9k, False: 2.23k]
  |  |  ------------------
  ------------------
  314|       |    // empty input is valid UTF-16. protect the implementation from
  315|       |    // handling nullptr
  316|  12.9k|    return true;
  317|  12.9k|  }
  318|  2.23k|  const auto res =
  319|  2.23k|      haswell::utf16::validate_utf16_with_errors<endianness::LITTLE>(buf, len);
  320|  2.23k|  if (res.is_err()) {
  ------------------
  |  Branch (320:7): [True: 47, False: 2.19k]
  ------------------
  321|     47|    return false;
  322|     47|  }
  323|       |
  324|  2.19k|  if (res.count == len) {
  ------------------
  |  Branch (324:7): [True: 0, False: 2.19k]
  ------------------
  325|      0|    return true;
  326|      0|  }
  327|       |
  328|  2.19k|  return scalar::utf16::validate<endianness::LITTLE>(buf + res.count,
  329|  2.19k|                                                     len - res.count);
  330|  2.19k|}
_ZNK7simdutf7haswell14implementation16validate_utf16beEPKDsm:
  336|  15.2k|                                 size_t len) const noexcept {
  337|  15.2k|  if (simdutf_unlikely(len == 0)) {
  ------------------
  |  |   93|  15.2k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 12.9k, False: 2.24k]
  |  |  ------------------
  ------------------
  338|       |    // empty input is valid UTF-16. protect the implementation from
  339|       |    // handling nullptr
  340|  12.9k|    return true;
  341|  12.9k|  }
  342|  2.24k|  const auto res =
  343|  2.24k|      haswell::utf16::validate_utf16_with_errors<endianness::BIG>(buf, len);
  344|  2.24k|  if (res.is_err()) {
  ------------------
  |  Branch (344:7): [True: 43, False: 2.19k]
  ------------------
  345|     43|    return false;
  346|     43|  }
  347|       |
  348|  2.19k|  if (res.count == len) {
  ------------------
  |  Branch (348:7): [True: 0, False: 2.19k]
  ------------------
  349|      0|    return true;
  350|      0|  }
  351|       |
  352|  2.19k|  return scalar::utf16::validate<endianness::BIG>(buf + res.count,
  353|  2.19k|                                                  len - res.count);
  354|  2.19k|}
_ZNK7simdutf7haswell14implementation28validate_utf16le_with_errorsEPKDsm:
  357|  5.26k|    const char16_t *buf, size_t len) const noexcept {
  358|       |
  359|  5.26k|  const result res =
  360|  5.26k|      haswell::utf16::validate_utf16_with_errors<endianness::LITTLE>(buf, len);
  361|  5.26k|  if (res.count != len) {
  ------------------
  |  Branch (361:7): [True: 349, False: 4.91k]
  ------------------
  362|    349|    const result scalar_res =
  363|    349|        scalar::utf16::validate_with_errors<endianness::LITTLE>(
  364|    349|            buf + res.count, len - res.count);
  365|    349|    return result(scalar_res.error, res.count + scalar_res.count);
  366|  4.91k|  } else {
  367|  4.91k|    return res;
  368|  4.91k|  }
  369|  5.26k|}
_ZNK7simdutf7haswell14implementation28validate_utf16be_with_errorsEPKDsm:
  372|  5.26k|    const char16_t *buf, size_t len) const noexcept {
  373|  5.26k|  const result res =
  374|  5.26k|      haswell::utf16::validate_utf16_with_errors<endianness::BIG>(buf, len);
  375|  5.26k|  if (res.count != len) {
  ------------------
  |  Branch (375:7): [True: 354, False: 4.91k]
  ------------------
  376|    354|    const result scalar_res =
  377|    354|        scalar::utf16::validate_with_errors<endianness::BIG>(buf + res.count,
  378|    354|                                                             len - res.count);
  379|    354|    return result(scalar_res.error, res.count + scalar_res.count);
  380|  4.91k|  } else {
  381|  4.91k|    return res;
  382|  4.91k|  }
  383|  5.26k|}
_ZNK7simdutf7haswell14implementation14validate_utf32EPKDim:
  398|  9.93k|implementation::validate_utf32(const char32_t *buf, size_t len) const noexcept {
  399|  9.93k|  return utf32::validate(buf, len);
  400|  9.93k|}
_ZNK7simdutf7haswell14implementation22convert_latin1_to_utf8EPKcmPc:
  412|  5.53k|    const char *buf, size_t len, char *utf8_output) const noexcept {
  413|  5.53k|  std::pair<const char *, char *> ret =
  414|  5.53k|      avx2_convert_latin1_to_utf8(buf, len, utf8_output);
  415|  5.53k|  size_t converted_chars = ret.second - utf8_output;
  416|       |
  417|  5.53k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (417:7): [True: 1.36k, False: 4.16k]
  ------------------
  418|  1.36k|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  419|  1.36k|        ret.first, len - (ret.first - buf), ret.second);
  420|  1.36k|    converted_chars += scalar_converted_chars;
  421|  1.36k|  }
  422|       |
  423|  5.53k|  return converted_chars;
  424|  5.53k|}
_ZNK7simdutf7haswell14implementation25convert_latin1_to_utf16leEPKcmPDs:
  429|  5.26k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  430|  5.26k|  std::pair<const char *, char16_t *> ret =
  431|  5.26k|      avx2_convert_latin1_to_utf16<endianness::LITTLE>(buf, len, utf16_output);
  432|  5.26k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (432:7): [True: 0, False: 5.26k]
  ------------------
  433|      0|    return 0;
  434|      0|  }
  435|  5.26k|  size_t converted_chars = ret.second - utf16_output;
  436|  5.26k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (436:7): [True: 787, False: 4.48k]
  ------------------
  437|    787|    const size_t scalar_converted_chars =
  438|    787|        scalar::latin1_to_utf16::convert<endianness::LITTLE>(
  439|    787|            ret.first, len - (ret.first - buf), ret.second);
  440|    787|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (440:9): [True: 0, False: 787]
  ------------------
  441|      0|      return 0;
  442|      0|    }
  443|    787|    converted_chars += scalar_converted_chars;
  444|    787|  }
  445|  5.26k|  return converted_chars;
  446|  5.26k|}
_ZNK7simdutf7haswell14implementation25convert_latin1_to_utf16beEPKcmPDs:
  449|  5.26k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  450|  5.26k|  std::pair<const char *, char16_t *> ret =
  451|  5.26k|      avx2_convert_latin1_to_utf16<endianness::BIG>(buf, len, utf16_output);
  452|  5.26k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (452:7): [True: 0, False: 5.26k]
  ------------------
  453|      0|    return 0;
  454|      0|  }
  455|  5.26k|  size_t converted_chars = ret.second - utf16_output;
  456|  5.26k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (456:7): [True: 787, False: 4.48k]
  ------------------
  457|    787|    const size_t scalar_converted_chars =
  458|    787|        scalar::latin1_to_utf16::convert<endianness::BIG>(
  459|    787|            ret.first, len - (ret.first - buf), ret.second);
  460|    787|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (460:9): [True: 0, False: 787]
  ------------------
  461|      0|      return 0;
  462|      0|    }
  463|    787|    converted_chars += scalar_converted_chars;
  464|    787|  }
  465|  5.26k|  return converted_chars;
  466|  5.26k|}
_ZNK7simdutf7haswell14implementation23convert_latin1_to_utf32EPKcmPDi:
  471|  5.26k|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  472|  5.26k|  std::pair<const char *, char32_t *> ret =
  473|  5.26k|      avx2_convert_latin1_to_utf32(buf, len, utf32_output);
  474|  5.26k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (474:7): [True: 0, False: 5.26k]
  ------------------
  475|      0|    return 0;
  476|      0|  }
  477|  5.26k|  size_t converted_chars = ret.second - utf32_output;
  478|  5.26k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (478:7): [True: 746, False: 4.52k]
  ------------------
  479|    746|    const size_t scalar_converted_chars = scalar::latin1_to_utf32::convert(
  480|    746|        ret.first, len - (ret.first - buf), ret.second);
  481|    746|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (481:9): [True: 0, False: 746]
  ------------------
  482|      0|      return 0;
  483|      0|    }
  484|    746|    converted_chars += scalar_converted_chars;
  485|    746|  }
  486|  5.26k|  return converted_chars;
  487|  5.26k|}
_ZNK7simdutf7haswell14implementation22convert_utf8_to_latin1EPKcmPc:
  492|  10.5k|    const char *buf, size_t len, char *latin1_output) const noexcept {
  493|  10.5k|  utf8_to_latin1::validating_transcoder converter;
  494|  10.5k|  return converter.convert(buf, len, latin1_output);
  495|  10.5k|}
_ZNK7simdutf7haswell14implementation23convert_utf8_to_utf16leEPKcmPDs:
  511|  10.4k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  512|  10.4k|  utf8_to_utf16::validating_transcoder converter;
  513|  10.4k|  return converter.convert<endianness::LITTLE>(buf, len, utf16_output);
  514|  10.4k|}
_ZNK7simdutf7haswell14implementation23convert_utf8_to_utf16beEPKcmPDs:
  517|  10.4k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  518|  10.4k|  utf8_to_utf16::validating_transcoder converter;
  519|  10.4k|  return converter.convert<endianness::BIG>(buf, len, utf16_output);
  520|  10.4k|}
_ZNK7simdutf7haswell14implementation21convert_utf8_to_utf32EPKcmPDi:
  550|  5.26k|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  551|  5.26k|  utf8_to_utf32::validating_transcoder converter;
  552|  5.26k|  return converter.convert(buf, len, utf32_output);
  553|  5.26k|}
_ZNK7simdutf7haswell14implementation25convert_utf16le_to_latin1EPKDsmPc:
  569|  5.26k|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  570|  5.26k|  std::pair<const char16_t *, char *> ret =
  571|  5.26k|      haswell::avx2_convert_utf16_to_latin1<endianness::LITTLE>(buf, len,
  572|  5.26k|                                                                latin1_output);
  573|  5.26k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (573:7): [True: 0, False: 5.26k]
  ------------------
  574|      0|    return 0;
  575|      0|  }
  576|  5.26k|  size_t saved_bytes = ret.second - latin1_output;
  577|  5.26k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (577:7): [True: 807, False: 4.46k]
  ------------------
  578|    807|    const size_t scalar_saved_bytes =
  579|    807|        scalar::utf16_to_latin1::convert<endianness::LITTLE>(
  580|    807|            ret.first, len - (ret.first - buf), ret.second);
  581|    807|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (581:9): [True: 0, False: 807]
  ------------------
  582|      0|      return 0;
  583|      0|    }
  584|    807|    saved_bytes += scalar_saved_bytes;
  585|    807|  }
  586|  5.26k|  return saved_bytes;
  587|  5.26k|}
_ZNK7simdutf7haswell14implementation25convert_utf16be_to_latin1EPKDsmPc:
  590|  5.26k|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  591|  5.26k|  std::pair<const char16_t *, char *> ret =
  592|  5.26k|      haswell::avx2_convert_utf16_to_latin1<endianness::BIG>(buf, len,
  593|  5.26k|                                                             latin1_output);
  594|  5.26k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (594:7): [True: 0, False: 5.26k]
  ------------------
  595|      0|    return 0;
  596|      0|  }
  597|  5.26k|  size_t saved_bytes = ret.second - latin1_output;
  598|  5.26k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (598:7): [True: 807, False: 4.46k]
  ------------------
  599|    807|    const size_t scalar_saved_bytes =
  600|    807|        scalar::utf16_to_latin1::convert<endianness::BIG>(
  601|    807|            ret.first, len - (ret.first - buf), ret.second);
  602|    807|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (602:9): [True: 0, False: 807]
  ------------------
  603|      0|      return 0;
  604|      0|    }
  605|    807|    saved_bytes += scalar_saved_bytes;
  606|    807|  }
  607|  5.26k|  return saved_bytes;
  608|  5.26k|}
_ZNK7simdutf7haswell14implementation23convert_utf16le_to_utf8EPKDsmPc:
  679|  9.93k|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  680|  9.93k|  std::pair<const char16_t *, char *> ret =
  681|  9.93k|      haswell::avx2_convert_utf16_to_utf8<endianness::LITTLE>(buf, len,
  682|  9.93k|                                                              utf8_output);
  683|  9.93k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (683:7): [True: 65, False: 9.87k]
  ------------------
  684|     65|    return 0;
  685|     65|  }
  686|  9.87k|  size_t saved_bytes = ret.second - utf8_output;
  687|  9.87k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (687:7): [True: 1.07k, False: 8.79k]
  ------------------
  688|  1.07k|    const size_t scalar_saved_bytes =
  689|  1.07k|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  690|  1.07k|            ret.first, len - (ret.first - buf), ret.second);
  691|  1.07k|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (691:9): [True: 32, False: 1.04k]
  ------------------
  692|     32|      return 0;
  693|     32|    }
  694|  1.04k|    saved_bytes += scalar_saved_bytes;
  695|  1.04k|  }
  696|  9.83k|  return saved_bytes;
  697|  9.87k|}
_ZNK7simdutf7haswell14implementation23convert_utf16be_to_utf8EPKDsmPc:
  700|  9.93k|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  701|  9.93k|  std::pair<const char16_t *, char *> ret =
  702|  9.93k|      haswell::avx2_convert_utf16_to_utf8<endianness::BIG>(buf, len,
  703|  9.93k|                                                           utf8_output);
  704|  9.93k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (704:7): [True: 57, False: 9.87k]
  ------------------
  705|     57|    return 0;
  706|     57|  }
  707|  9.87k|  size_t saved_bytes = ret.second - utf8_output;
  708|  9.87k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (708:7): [True: 1.08k, False: 8.79k]
  ------------------
  709|  1.08k|    const size_t scalar_saved_bytes =
  710|  1.08k|        scalar::utf16_to_utf8::convert<endianness::BIG>(
  711|  1.08k|            ret.first, len - (ret.first - buf), ret.second);
  712|  1.08k|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (712:9): [True: 30, False: 1.05k]
  ------------------
  713|     30|      return 0;
  714|     30|    }
  715|  1.05k|    saved_bytes += scalar_saved_bytes;
  716|  1.05k|  }
  717|  9.84k|  return saved_bytes;
  718|  9.87k|}
_ZNK7simdutf7haswell14implementation21convert_utf32_to_utf8EPKDimPc:
  789|  4.66k|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  790|  4.66k|  std::pair<const char32_t *, char *> ret =
  791|  4.66k|      avx2_convert_utf32_to_utf8(buf, len, utf8_output);
  792|  4.66k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (792:7): [True: 0, False: 4.66k]
  ------------------
  793|      0|    return 0;
  794|      0|  }
  795|  4.66k|  size_t saved_bytes = ret.second - utf8_output;
  796|  4.66k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (796:7): [True: 788, False: 3.88k]
  ------------------
  797|    788|    const size_t scalar_saved_bytes = scalar::utf32_to_utf8::convert(
  798|    788|        ret.first, len - (ret.first - buf), ret.second);
  799|    788|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (799:9): [True: 0, False: 788]
  ------------------
  800|      0|      return 0;
  801|      0|    }
  802|    788|    saved_bytes += scalar_saved_bytes;
  803|    788|  }
  804|  4.66k|  return saved_bytes;
  805|  4.66k|}
_ZNK7simdutf7haswell14implementation23convert_utf32_to_latin1EPKDimPc:
  810|  5.26k|    const char32_t *buf, size_t len, char *latin1_output) const noexcept {
  811|  5.26k|  std::pair<const char32_t *, char *> ret =
  812|  5.26k|      avx2_convert_utf32_to_latin1(buf, len, latin1_output);
  813|  5.26k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (813:7): [True: 0, False: 5.26k]
  ------------------
  814|      0|    return 0;
  815|      0|  }
  816|  5.26k|  size_t saved_bytes = ret.second - latin1_output;
  817|  5.26k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (817:7): [True: 807, False: 4.46k]
  ------------------
  818|    807|    const size_t scalar_saved_bytes = scalar::utf32_to_latin1::convert(
  819|    807|        ret.first, len - (ret.first - buf), ret.second);
  820|    807|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (820:9): [True: 0, False: 807]
  ------------------
  821|      0|      return 0;
  822|      0|    }
  823|    807|    saved_bytes += scalar_saved_bytes;
  824|    807|  }
  825|  5.26k|  return saved_bytes;
  826|  5.26k|}
_ZNK7simdutf7haswell14implementation10count_utf8EPKcm:
 1117|  10.5k|implementation::count_utf8(const char *in, size_t size) const noexcept {
 1118|  10.5k|  return utf8::count_code_points_bytemask(in, size);
 1119|  10.5k|}
_ZNK7simdutf7haswell14implementation23latin1_length_from_utf8EPKcm:
 1124|  10.5k|    const char *buf, size_t len) const noexcept {
 1125|  10.5k|  return count_utf8(buf, len);
 1126|  10.5k|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16leEPKDsm:
 1131|  9.93k|    const char16_t *input, size_t length) const noexcept {
 1132|  9.93k|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1133|  9.93k|                                                                    length);
 1134|  9.93k|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16beEPKDsm:
 1137|  9.93k|    const char16_t *input, size_t length) const noexcept {
 1138|  9.93k|  return utf16::utf8_length_from_utf16_bytemask<endianness::BIG>(input, length);
 1139|  9.93k|}
_ZNK7simdutf7haswell14implementation22utf16_length_from_utf8EPKcm:
 1156|  20.8k|    const char *input, size_t length) const noexcept {
 1157|  20.8k|  return utf8::utf16_length_from_utf8_bytemask(input, length);
 1158|  20.8k|}
_ZNK7simdutf7haswell14implementation23utf8_length_from_latin1EPKcm:
 1203|  5.53k|    const char *input, size_t len) const noexcept {
 1204|  5.53k|  const uint8_t *data = reinterpret_cast<const uint8_t *>(input);
 1205|  5.53k|  size_t answer = len / sizeof(__m256i) * sizeof(__m256i);
 1206|  5.53k|  size_t i = 0;
 1207|  5.53k|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1207:7): [True: 0, False: 5.53k]
  ------------------
 1208|      0|    __m256i four_64bits = _mm256_setzero_si256();
 1209|      0|    while (i + sizeof(__m256i) <= len) {
  ------------------
  |  Branch (1209:12): [True: 0, False: 0]
  ------------------
 1210|      0|      __m256i runner = _mm256_setzero_si256();
 1211|       |      // We can do up to 255 loops without overflow.
 1212|      0|      size_t iterations = (len - i) / sizeof(__m256i);
 1213|      0|      if (iterations > 255) {
  ------------------
  |  Branch (1213:11): [True: 0, False: 0]
  ------------------
 1214|      0|        iterations = 255;
 1215|      0|      }
 1216|      0|      size_t max_i = i + iterations * sizeof(__m256i) - sizeof(__m256i);
 1217|      0|      for (; i + 4 * sizeof(__m256i) <= max_i; i += 4 * sizeof(__m256i)) {
  ------------------
  |  Branch (1217:14): [True: 0, False: 0]
  ------------------
 1218|      0|        __m256i input1 = _mm256_loadu_si256((const __m256i *)(data + i));
 1219|      0|        __m256i input2 =
 1220|      0|            _mm256_loadu_si256((const __m256i *)(data + i + sizeof(__m256i)));
 1221|      0|        __m256i input3 = _mm256_loadu_si256(
 1222|      0|            (const __m256i *)(data + i + 2 * sizeof(__m256i)));
 1223|      0|        __m256i input4 = _mm256_loadu_si256(
 1224|      0|            (const __m256i *)(data + i + 3 * sizeof(__m256i)));
 1225|      0|        __m256i input12 =
 1226|      0|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input1),
 1227|      0|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input2));
 1228|      0|        __m256i input23 =
 1229|      0|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input3),
 1230|      0|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input4));
 1231|      0|        __m256i input1234 = _mm256_add_epi8(input12, input23);
 1232|      0|        runner = _mm256_sub_epi8(runner, input1234);
 1233|      0|      }
 1234|      0|      for (; i <= max_i; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1234:14): [True: 0, False: 0]
  ------------------
 1235|      0|        __m256i input_256_chunk =
 1236|      0|            _mm256_loadu_si256((const __m256i *)(data + i));
 1237|      0|        runner = _mm256_sub_epi8(
 1238|      0|            runner, _mm256_cmpgt_epi8(_mm256_setzero_si256(), input_256_chunk));
 1239|      0|      }
 1240|      0|      four_64bits = _mm256_add_epi64(
 1241|      0|          four_64bits, _mm256_sad_epu8(runner, _mm256_setzero_si256()));
 1242|      0|    }
 1243|      0|    answer += _mm256_extract_epi64(four_64bits, 0) +
 1244|      0|              _mm256_extract_epi64(four_64bits, 1) +
 1245|      0|              _mm256_extract_epi64(four_64bits, 2) +
 1246|      0|              _mm256_extract_epi64(four_64bits, 3);
 1247|  5.53k|  } else if (answer > 0) {
  ------------------
  |  Branch (1247:14): [True: 804, False: 4.73k]
  ------------------
 1248|  6.39k|    for (; i + sizeof(__m256i) <= len; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1248:12): [True: 5.58k, False: 804]
  ------------------
 1249|  5.58k|      __m256i latin = _mm256_loadu_si256((const __m256i *)(data + i));
 1250|  5.58k|      uint32_t non_ascii = _mm256_movemask_epi8(latin);
 1251|  5.58k|      answer += count_ones(non_ascii);
 1252|  5.58k|    }
 1253|    804|  }
 1254|  5.53k|  return answer + scalar::latin1::utf8_length_from_latin1(
 1255|  5.53k|                      reinterpret_cast<const char *>(data + i), len - i);
 1256|  5.53k|}
_ZNK7simdutf7haswell14implementation22utf8_length_from_utf32EPKDim:
 1261|  4.66k|    const char32_t *input, size_t length) const noexcept {
 1262|  4.66k|  return utf32::utf8_length_from_utf32(input, length);
 1263|  4.66k|}
_ZNK7simdutf7haswell14implementation22utf32_length_from_utf8EPKcm:
 1289|  5.26k|    const char *input, size_t length) const noexcept {
 1290|  5.26k|  return utf8::count_code_points(input, length);
 1291|  5.26k|}
_ZNK7simdutf7haswell14implementation16base64_to_binaryEPKcmPcNS_14base64_optionsENS_27last_chunk_handling_optionsE:
 1297|  15.0k|    last_chunk_handling_options last_chunk_options) const noexcept {
 1298|  15.0k|  if (options & base64_default_or_url) {
  ------------------
  |  Branch (1298:7): [True: 0, False: 15.0k]
  ------------------
 1299|      0|    if (options == base64_options::base64_default_or_url_accept_garbage) {
  ------------------
  |  Branch (1299:9): [True: 0, False: 0]
  ------------------
 1300|      0|      return base64::compress_decode_base64<false, true, true>(
 1301|      0|          output, input, length, options, last_chunk_options);
 1302|      0|    } else {
 1303|      0|      return base64::compress_decode_base64<false, false, true>(
 1304|      0|          output, input, length, options, last_chunk_options);
 1305|      0|    }
 1306|  15.0k|  } else if (options & base64_url) {
  ------------------
  |  Branch (1306:14): [True: 0, False: 15.0k]
  ------------------
 1307|      0|    if (options == base64_options::base64_url_accept_garbage) {
  ------------------
  |  Branch (1307:9): [True: 0, False: 0]
  ------------------
 1308|      0|      return base64::compress_decode_base64<true, true, false>(
 1309|      0|          output, input, length, options, last_chunk_options);
 1310|      0|    } else {
 1311|      0|      return base64::compress_decode_base64<true, false, false>(
 1312|      0|          output, input, length, options, last_chunk_options);
 1313|      0|    }
 1314|  15.0k|  } else {
 1315|  15.0k|    if (options == base64_options::base64_default_accept_garbage) {
  ------------------
  |  Branch (1315:9): [True: 0, False: 15.0k]
  ------------------
 1316|      0|      return base64::compress_decode_base64<false, true, false>(
 1317|      0|          output, input, length, options, last_chunk_options);
 1318|  15.0k|    } else {
 1319|  15.0k|      return base64::compress_decode_base64<false, false, false>(
 1320|  15.0k|          output, input, length, options, last_chunk_options);
 1321|  15.0k|    }
 1322|  15.0k|  }
 1323|  15.0k|}
_ZNK7simdutf7haswell14implementation24base64_to_binary_detailsEPKcmPcNS_14base64_optionsENS_27last_chunk_handling_optionsE:
 1327|  46.0k|    last_chunk_handling_options last_chunk_options) const noexcept {
 1328|  46.0k|  if (options & base64_default_or_url) {
  ------------------
  |  Branch (1328:7): [True: 0, False: 46.0k]
  ------------------
 1329|      0|    if (options == base64_options::base64_default_or_url_accept_garbage) {
  ------------------
  |  Branch (1329:9): [True: 0, False: 0]
  ------------------
 1330|      0|      return base64::compress_decode_base64<false, true, true>(
 1331|      0|          output, input, length, options, last_chunk_options);
 1332|      0|    } else {
 1333|      0|      return base64::compress_decode_base64<false, false, true>(
 1334|      0|          output, input, length, options, last_chunk_options);
 1335|      0|    }
 1336|  46.0k|  } else if (options & base64_url) {
  ------------------
  |  Branch (1336:14): [True: 0, False: 46.0k]
  ------------------
 1337|      0|    if (options == base64_options::base64_url_accept_garbage) {
  ------------------
  |  Branch (1337:9): [True: 0, False: 0]
  ------------------
 1338|      0|      return base64::compress_decode_base64<true, true, false>(
 1339|      0|          output, input, length, options, last_chunk_options);
 1340|      0|    } else {
 1341|      0|      return base64::compress_decode_base64<true, false, false>(
 1342|      0|          output, input, length, options, last_chunk_options);
 1343|      0|    }
 1344|  46.0k|  } else {
 1345|  46.0k|    if (options == base64_options::base64_default_accept_garbage) {
  ------------------
  |  Branch (1345:9): [True: 0, False: 46.0k]
  ------------------
 1346|      0|      return base64::compress_decode_base64<false, true, false>(
 1347|      0|          output, input, length, options, last_chunk_options);
 1348|  46.0k|    } else {
 1349|  46.0k|      return base64::compress_decode_base64<false, false, false>(
 1350|  46.0k|          output, input, length, options, last_chunk_options);
 1351|  46.0k|    }
 1352|  46.0k|  }
 1353|  46.0k|}
_ZNK7simdutf7haswell14implementation16binary_to_base64EPKcmPcNS_14base64_optionsE:
 1417|  14.3k|                                        base64_options options) const noexcept {
 1418|  14.3k|  if (options & base64_url) {
  ------------------
  |  Branch (1418:7): [True: 0, False: 14.3k]
  ------------------
 1419|      0|    return encode_base64<true>(output, input, length, options);
 1420|  14.3k|  } else {
 1421|  14.3k|    return encode_base64<false>(output, input, length, options);
 1422|  14.3k|  }
 1423|  14.3k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_18is_asciiERKNS1_4simd8simd8x64IhEE:
   13|  33.0k|simdutf_really_inline bool is_ascii(const simd8x64<uint8_t> &input) {
   14|  33.0k|  return input.reduce_or().is_ascii();
   15|  33.0k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_124must_be_2_3_continuationENS1_4simd5simd8IhEES4_:
   22|  26.0k|                         const simd8<uint8_t> prev3) {
   23|  26.0k|  simd8<uint8_t> is_third_byte =
   24|  26.0k|      prev2.saturating_sub(0xe0u - 0x80); // Only 111_____ will be > 0x80
   25|  26.0k|  simd8<uint8_t> is_fourth_byte =
   26|  26.0k|      prev3.saturating_sub(0xf0u - 0x80); // Only 1111____ will be > 0x80
   27|  26.0k|  return simd8<bool>(is_third_byte | is_fourth_byte);
   28|  26.0k|}

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

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_110count_onesEm:
   14|  12.4k|simdutf_really_inline long long int count_ones(uint64_t input_num) {
   15|       |  return _popcnt64(input_num);
   16|  12.4k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115trailing_zeroesEm:
   20|  1.65k|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.65k|  return __builtin_ctzll(input_num);
   25|  1.65k|  #endif // SIMDUTF_REGULAR_VISUAL_STUDIO
   26|  1.65k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115is_power_of_twoImEEbT_:
   29|  2.23k|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|  78.4k|  simdutf_really_inline simd8() : base8_numeric<uint8_t>() {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhEC2Ev:
  124|  78.4k|  simdutf_really_inline base8_numeric() : base8<T>() {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2Ev:
   71|  78.4k|  simdutf_really_inline base8() : base<simd8<T>>() {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2Ev:
   14|  78.4k|  simdutf_really_inline base() : value{__m256i()} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IhE9reduce_orEv:
  294|  33.0k|  simdutf_really_inline simd8<T> reduce_or() const {
  295|  33.0k|    return this->chunks[0] | this->chunks[1];
  296|  33.0k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEorES5_:
   50|   141k|  simdutf_really_inline Child operator|(const Child other) const {
   51|   141k|    return _mm256_or_si256(*this, other);
   52|   141k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2EDv4_x:
  193|  1.26M|      : base8_numeric<uint8_t>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhEC2EDv4_x:
  126|  1.26M|      : base8<T>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2EDv4_x:
   73|  1.26M|  simdutf_really_inline base8(const __m256i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2EDv4_x:
   17|  1.26M|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE8is_asciiEv:
  234|  33.0k|  simdutf_really_inline bool is_ascii() const {
  235|  33.0k|    return _mm256_movemask_epi8(*this) == 0;
  236|  33.0k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEoRES5_:
   59|  82.0k|  simdutf_really_inline Child &operator|=(const Child other) {
   60|  82.0k|    auto this_cast = static_cast<Child *>(this);
   61|  82.0k|    *this_cast = *this_cast | other;
   62|  82.0k|    return *this_cast;
   63|  82.0k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi1EEENS4_IhEES8_:
   83|  30.6k|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   84|       |    return _mm256_alignr_epi8(
   85|  30.6k|        *this, _mm256_permute2x128_si256(prev_chunk, *this, 0x21), 16 - N);
   86|  30.6k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE3shrILi4EEES4_v:
  245|  61.2k|  template <int N> simdutf_really_inline simd8<uint8_t> shr() const {
  246|  61.2k|    return simd8<uint8_t>(_mm256_srli_epi16(*this, N)) & uint8_t(0xFFu >> N);
  247|  61.2k|  }
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.8k|            L replace15) const {
  158|  91.8k|    return lookup_16(simd8<L>::repeat_16(
  159|  91.8k|        replace0, replace1, replace2, replace3, replace4, replace5, replace6,
  160|  91.8k|        replace7, replace8, replace9, replace10, replace11, replace12,
  161|  91.8k|        replace13, replace14, replace15));
  162|  91.8k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE9lookup_16IhEENS2_5simd8IT_EES8_:
  148|  91.8k|  simdutf_really_inline simd8<L> lookup_16(simd8<L> lookup_table) const {
  149|  91.8k|    return _mm256_shuffle_epi8(lookup_table, *this);
  150|  91.8k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE9repeat_16Ehhhhhhhhhhhhhhhh:
  118|  91.8k|                                                  T v14, T v15) {
  119|  91.8k|    return simd8<T>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
  120|  91.8k|                    v14, v15, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
  121|  91.8k|                    v12, v13, v14, v15);
  122|  91.8k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2Ehhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh:
  207|  91.8k|      : simd8(_mm256_setr_epi8(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
  208|  91.8k|                               v12, v13, v14, v15, v16, v17, v18, v19, v20, v21,
  209|  91.8k|                               v22, v23, v24, v25, v26, v27, v28, v29, v30,
  210|  91.8k|                               v31)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2Eh:
  195|   225k|  simdutf_really_inline simd8(uint8_t _value) : simd8(splat(_value)) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi2EEENS4_IhEES8_:
   83|  26.0k|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   84|       |    return _mm256_alignr_epi8(
   85|  26.0k|        *this, _mm256_permute2x128_si256(prev_chunk, *this, 0x21), 16 - N);
   86|  26.0k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi3EEENS4_IhEES8_:
   83|  26.0k|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   84|       |    return _mm256_alignr_epi8(
   85|  26.0k|        *this, _mm256_permute2x128_si256(prev_chunk, *this, 0x21), 16 - N);
   86|  26.0k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE14saturating_subES4_:
  214|  59.7k|  saturating_sub(const simd8<uint8_t> other) const {
  215|  59.7k|    return _mm256_subs_epu8(*this, other);
  216|  59.7k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IbEC2EDv4_x:
   95|   101k|  simdutf_really_inline simd8(const __m256i _value) : base8<bool>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IbNS2_5simd8IbEEEC2EDv4_x:
   73|   101k|  simdutf_really_inline base8(const __m256i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEC2EDv4_x:
   17|   101k|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEcvRKDv4_xEv:
   19|  56.0k|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEeoES5_:
   56|  26.0k|  simdutf_really_inline Child operator^(const Child other) const {
   57|  26.0k|    return _mm256_xor_si256(*this, other);
   58|  26.0k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEC2EPKh:
  197|  7.60k|  simdutf_really_inline simd8(const uint8_t values[32]) : simd8(load(values)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE4loadEPKh:
  111|  73.7k|  static simdutf_really_inline simd8<T> load(const T values[32]) {
  112|  73.7k|    return _mm256_loadu_si256(reinterpret_cast<const __m256i *>(values));
  113|  73.7k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE7gt_bitsES4_:
  225|  7.60k|  gt_bits(const simd8<uint8_t> other) const {
  226|  7.60k|    return this->saturating_sub(other);
  227|  7.60k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEC2EDv4_x:
   17|   306k|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEcvRKDv4_xEv:
   19|   327k|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IbE10to_bitmaskEv:
   99|  45.1k|  simdutf_really_inline uint32_t to_bitmask() const {
  100|  45.1k|    return uint32_t(_mm256_movemask_epi8(value));
  101|  45.1k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE21any_bits_set_anywhereEv:
  241|  63.7k|  simdutf_really_inline bool any_bits_set_anywhere() const {
  242|  63.7k|    return !bits_not_set_anywhere();
  243|  63.7k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE21bits_not_set_anywhereEv:
  237|  63.7k|  simdutf_really_inline bool bits_not_set_anywhere() const {
  238|  63.7k|    return _mm256_testz_si256(*this, *this);
  239|  63.7k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaEC2EPKa:
  274|  12.8k|      : chunks{simd8<T>::load(ptr),
  275|  12.8k|               simd8<T>::load(ptr + sizeof(simd8<T>) / sizeof(T))} {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIaE4loadEPKa:
  111|  44.4k|  static simdutf_really_inline simd8<T> load(const T values[32]) {
  112|  44.4k|    return _mm256_loadu_si256(reinterpret_cast<const __m256i *>(values));
  113|  44.4k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IaEC2EDv4_x:
  169|  83.7k|      : base8_numeric<int8_t>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIaEC2EDv4_x:
  126|  83.7k|      : base8<T>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5base8IaNS2_5simd8IbEEEC2EDv4_x:
   73|  83.7k|  simdutf_really_inline base8(const __m256i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IaEEEC2EDv4_x:
   17|  83.7k|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE8is_asciiEv:
  298|  11.1k|  simdutf_really_inline bool is_ascii() const {
  299|  11.1k|    return this->reduce_or().is_ascii();
  300|  11.1k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE9reduce_orEv:
  294|  11.1k|  simdutf_really_inline simd8<T> reduce_or() const {
  295|  11.1k|    return this->chunks[0] | this->chunks[1];
  296|  11.1k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IaEEEorES5_:
   50|  11.1k|  simdutf_really_inline Child operator|(const Child other) const {
   51|  11.1k|    return _mm256_or_si256(*this, other);
   52|  11.1k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IaEEEcvRKDv4_xEv:
   19|   121k|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IaE8is_asciiEv:
  177|  11.1k|  simdutf_really_inline bool is_ascii() const {
  178|  11.1k|    return _mm256_movemask_epi8(*this) == 0;
  179|  11.1k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE5storeEPa:
  277|  1.68k|  simdutf_really_inline void store(T *ptr) const {
  278|  1.68k|    this->chunks[0].store(ptr + sizeof(simd8<T>) * 0 / sizeof(T));
  279|  1.68k|    this->chunks[1].store(ptr + sizeof(simd8<T>) * 1 / sizeof(T));
  280|  1.68k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIaE5storeEPa:
  129|  3.37k|  simdutf_really_inline void store(T dst[32]) const {
  130|  3.37k|    return _mm256_storeu_si256(reinterpret_cast<__m256i *>(dst), *this);
  131|  3.37k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IaEcvNS3_IhEEEv:
  256|  23.1k|simdutf_really_inline simd8<int8_t>::operator simd8<uint8_t>() const {
  257|  23.1k|  return this->value;
  258|  23.1k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE2ltEa:
  325|  7.71k|  simdutf_really_inline uint64_t lt(const T m) const {
  326|  7.71k|    const simd8<T> mask = simd8<T>::splat(m);
  327|  7.71k|    return simd8x64<bool>(this->chunks[0] < mask, this->chunks[1] < mask)
  328|  7.71k|        .to_bitmask();
  329|  7.71k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIaE5splatEa:
  105|  28.1k|  static simdutf_really_inline simd8<T> splat(T _value) {
  106|  28.1k|    return _mm256_set1_epi8(_value);
  107|  28.1k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IaEltES4_:
  184|  15.4k|  simdutf_really_inline simd8<bool> operator<(const simd8<int8_t> other) const {
  185|  15.4k|    return _mm256_cmpgt_epi8(other, *this);
  186|  15.4k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IbEC2ENS2_5simd8IbEES6_:
  272|  9.47k|      : chunks{chunk0, chunk1} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IbE10to_bitmaskEv:
  282|  9.47k|  simdutf_really_inline uint64_t to_bitmask() const {
  283|  9.47k|    uint64_t r_lo = uint32_t(this->chunks[0].to_bitmask());
  284|  9.47k|    uint64_t r_hi = this->chunks[1].to_bitmask();
  285|  9.47k|    return r_lo | (r_hi << 32);
  286|  9.47k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE20store_ascii_as_utf32EPDi:
  310|    569|  simdutf_really_inline void store_ascii_as_utf32(char32_t *ptr) const {
  311|    569|    this->chunks[0].store_ascii_as_utf32(ptr + sizeof(simd8<T>) * 0);
  312|    569|    this->chunks[1].store_ascii_as_utf32(ptr + sizeof(simd8<T>) * 1);
  313|    569|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IaEEE20store_ascii_as_utf32EPDi:
   36|  1.13k|  simdutf_really_inline void store_ascii_as_utf32(char32_t *ptr) const {
   37|  1.13k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr),
   38|  1.13k|                        _mm256_cvtepu8_epi32(_mm256_castsi256_si128(*this)));
   39|  1.13k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr + 8),
   40|  1.13k|                        _mm256_cvtepu8_epi32(_mm256_castsi256_si128(
   41|  1.13k|                            _mm256_srli_si256(*this, 8))));
   42|  1.13k|    _mm256_storeu_si256(
   43|  1.13k|        reinterpret_cast<__m256i *>(ptr + 16),
   44|  1.13k|        _mm256_cvtepu8_epi32(_mm256_extractf128_si256(*this, 1)));
   45|  1.13k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr + 24),
   46|       |                        _mm256_cvtepu8_epi32(_mm_srli_si128(
   47|  1.13k|                            _mm256_extractf128_si256(*this, 1), 8)));
   48|  1.13k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE4zeroEv:
  108|  31.4k|  static simdutf_really_inline simd8<T> zero() {
  109|  31.4k|    return _mm256_setzero_si256();
  110|  31.4k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IaEgtES4_:
  181|  22.2k|  simdutf_really_inline simd8<bool> operator>(const simd8<int8_t> other) const {
  182|  22.2k|    return _mm256_cmpgt_epi8(*this, other);
  183|  22.2k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd5simd8IaEC2Ea:
  172|  18.7k|  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.07k|  simdutf_really_inline uint64_t sum_bytes() const {
  250|  2.07k|    const auto tmp = _mm256_sad_epu8(value, _mm256_setzero_si256());
  251|       |
  252|  2.07k|    return _mm256_extract_epi64(tmp, 0) + _mm256_extract_epi64(tmp, 1) +
  253|  2.07k|           _mm256_extract_epi64(tmp, 2) + _mm256_extract_epi64(tmp, 3);
  254|  2.07k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhEgeES4_:
  229|  11.3k|  operator>=(const simd8<uint8_t> other) const {
  230|  11.3k|    return other.min_val(*this) == other;
  231|  11.3k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd5simd8IhE7min_valES4_:
  220|  11.3k|  min_val(const simd8<uint8_t> other) const {
  221|  11.3k|    return _mm256_min_epu8(other, *this);
  222|  11.3k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE2gtEa:
  331|  1.76k|  simdutf_really_inline uint64_t gt(const T m) const {
  332|  1.76k|    const simd8<T> mask = simd8<T>::splat(m);
  333|  1.76k|    return simd8x64<bool>(this->chunks[0] > mask, this->chunks[1] > mask)
  334|  1.76k|        .to_bitmask();
  335|  1.76k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEC2EDv4_x:
   17|  10.9k|  simdutf_really_inline base(const __m256i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEcvRKDv4_xEv:
   19|  10.9k|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd13base8_numericIhE5splatEh:
  105|   246k|  static simdutf_really_inline simd8<T> splat(T _value) {
  106|   246k|    return _mm256_set1_epi8(_value);
  107|   246k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEcvRKDv4_xEv:
   19|  1.70M|  simdutf_really_inline operator const __m256i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdeqENS2_5simd8IhEES4_:
   76|  37.5k|                                               const simd8<T> rhs) {
   77|  37.5k|    return _mm256_cmpeq_epi8(lhs, rhs);
   78|  37.5k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEanES5_:
   53|   205k|  simdutf_really_inline Child operator&(const Child other) const {
   54|   205k|    return _mm256_and_si256(*this, other);
   55|   205k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IhEC2EPKh:
  274|  33.0k|      : chunks{simd8<T>::load(ptr),
  275|  33.0k|               simd8<T>::load(ptr + sizeof(simd8<T>) / sizeof(T))} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEanES5_:
   53|  57.1k|  simdutf_really_inline Child operator&(const Child other) const {
   54|  57.1k|    return _mm256_and_si256(*this, other);
   55|  57.1k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE20store_ascii_as_utf16ILNS_10endiannessE0EEEvPDs:
  303|    578|  simdutf_really_inline void store_ascii_as_utf16(char16_t *ptr) const {
  304|    578|    this->chunks[0].template store_ascii_as_utf16<endian>(ptr +
  305|    578|                                                          sizeof(simd8<T>) * 0);
  306|    578|    this->chunks[1].template store_ascii_as_utf16<endian>(ptr +
  307|    578|                                                          sizeof(simd8<T>) * 1);
  308|    578|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IaEEE20store_ascii_as_utf16ILNS_10endiannessE0EEEvPDs:
   22|  1.15k|  simdutf_really_inline void store_ascii_as_utf16(char16_t *ptr) const {
   23|  1.15k|    __m256i first = _mm256_cvtepu8_epi16(_mm256_castsi256_si128(*this));
   24|  1.15k|    __m256i second = _mm256_cvtepu8_epi16(_mm256_extractf128_si256(*this, 1));
   25|  1.15k|    if (big_endian) {
  ------------------
  |  Branch (25:9): [Folded, False: 1.15k]
  ------------------
   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.15k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr), first);
   33|  1.15k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr + 16), second);
   34|  1.15k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd8simd8x64IaE20store_ascii_as_utf16ILNS_10endiannessE1EEEvPDs:
  303|    584|  simdutf_really_inline void store_ascii_as_utf16(char16_t *ptr) const {
  304|    584|    this->chunks[0].template store_ascii_as_utf16<endian>(ptr +
  305|    584|                                                          sizeof(simd8<T>) * 0);
  306|    584|    this->chunks[1].template store_ascii_as_utf16<endian>(ptr +
  307|    584|                                                          sizeof(simd8<T>) * 1);
  308|    584|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd4baseINS2_5simd8IaEEE20store_ascii_as_utf16ILNS_10endiannessE1EEEvPDs:
   22|  1.16k|  simdutf_really_inline void store_ascii_as_utf16(char16_t *ptr) const {
   23|  1.16k|    __m256i first = _mm256_cvtepu8_epi16(_mm256_castsi256_si128(*this));
   24|  1.16k|    __m256i second = _mm256_cvtepu8_epi16(_mm256_extractf128_si256(*this, 1));
   25|  1.16k|    if (big_endian) {
  ------------------
  |  Branch (25:9): [True: 1.16k, Folded]
  ------------------
   26|  1.16k|      const __m256i swap = _mm256_setr_epi8(
   27|  1.16k|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   28|  1.16k|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   29|  1.16k|      first = _mm256_shuffle_epi8(first, swap);
   30|  1.16k|      second = _mm256_shuffle_epi8(second, swap);
   31|  1.16k|    }
   32|  1.16k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr), first);
   33|  1.16k|    _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr + 16), second);
   34|  1.16k|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2EDv4_x:
   97|   306k|      : base16_numeric<uint16_t>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEC2EDv4_x:
   73|   306k|      : base16<T>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6base16ItNS2_6simd16IbEEEC2EDv4_x:
   20|   306k|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE4packERKS4_S6_:
  149|  23.9k|                                                   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.9k|    const __m128i lo_0 = _mm256_extracti128_si256(v0, 0);
  156|  23.9k|    const __m128i lo_1 = _mm256_extracti128_si256(v1, 0);
  157|       |
  158|       |    // get the 1st lanes
  159|  23.9k|    const __m128i hi_0 = _mm256_extracti128_si256(v0, 1);
  160|  23.9k|    const __m128i hi_1 = _mm256_extracti128_si256(v1, 1);
  161|       |
  162|       |    // build new vectors (shuffle lanes)
  163|  23.9k|    const __m256i t0 = _mm256_set_m128i(lo_1, lo_0);
  ------------------
  |  |    4|  23.9k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  23.9k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  164|  23.9k|    const __m256i t1 = _mm256_set_m128i(hi_1, hi_0);
  ------------------
  |  |    4|  23.9k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  23.9k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  165|       |
  166|       |    // pack code units in linear order from v0 and v1
  167|  23.9k|    return _mm256_packus_epi16(t0, t1);
  168|  23.9k|  }
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.56k|  simdutf_really_inline simd16<uint16_t> swap_bytes() const {
  140|  5.56k|    const __m256i swap = _mm256_setr_epi8(
  141|  5.56k|        1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
  142|  5.56k|        21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
  143|  5.56k|    return _mm256_shuffle_epi8(*this, swap);
  144|  5.56k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE5splatEt:
   58|  75.8k|  static simdutf_really_inline simd16<T> splat(T _value) {
   59|  75.8k|    return _mm256_set1_epi16(_value);
   60|  75.8k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdeqENS2_6simd16ItEES4_:
   26|  10.9k|                                               const simd16<T> rhs) {
   27|  10.9k|    return _mm256_cmpeq_epi16(lhs, rhs);
   28|  10.9k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16IbEC2EDv4_x:
   45|  10.9k|  simdutf_really_inline simd16(const __m256i _value) : base16<bool>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6base16IbNS2_6simd16IbEEEC2EDv4_x:
   20|  10.9k|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE3shrILi8EEES4_v:
  134|  23.7k|  template <int N> simdutf_really_inline simd16<uint16_t> shr() const {
  135|  23.7k|    return simd16<uint16_t>(_mm256_srli_epi16(*this, N));
  136|  23.7k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2EPKDs:
  104|  47.9k|      : simd16(load(reinterpret_cast<const uint16_t *>(values))) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2Et:
  100|  55.9k|  simdutf_really_inline simd16(uint16_t _value) : simd16(splat(_value)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE4zeroEv:
   62|  19.8k|  static simdutf_really_inline simd16<T> zero() {
   63|  19.8k|    return _mm256_setzero_si256();
   64|  19.8k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd3minENS2_6simd16ItEES4_:
  259|  21.9k|simd16<uint16_t> min(const simd16<uint16_t> a, simd16<uint16_t> b) {
  260|  21.9k|  return _mm256_min_epu16(a.value, b.value);
  261|  21.9k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEpLENS2_6simd16ItEE:
   87|  32.9k|  simdutf_really_inline simd16<T> &operator+=(const simd16<T> other) {
   88|  32.9k|    *this = *this + other;
   89|  32.9k|    return *static_cast<simd16<T> *>(this);
   90|  32.9k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEplENS2_6simd16ItEE:
   84|  32.9k|  simdutf_really_inline simd16<T> operator+(const simd16<T> other) const {
   85|  32.9k|    return _mm256_add_epi16(*this, other);
   86|  32.9k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE3sumEv:
  170|  19.8k|  simdutf_really_inline uint64_t sum() const {
  171|  19.8k|    const auto lo_u16 = _mm256_and_si256(value, _mm256_set1_epi32(0x0000ffff));
  172|  19.8k|    const auto hi_u16 = _mm256_srli_epi32(value, 16);
  173|  19.8k|    const auto sum_u32 = _mm256_add_epi32(lo_u16, hi_u16);
  174|       |
  175|  19.8k|    const auto lo_u32 =
  176|  19.8k|        _mm256_and_si256(sum_u32, _mm256_set1_epi64x(0xffffffff));
  177|  19.8k|    const auto hi_u32 = _mm256_srli_epi64(sum_u32, 32);
  178|  19.8k|    const auto sum_u64 = _mm256_add_epi64(lo_u32, hi_u32);
  179|       |
  180|  19.8k|    return uint64_t(_mm256_extract_epi64(sum_u64, 0)) +
  181|  19.8k|           uint64_t(_mm256_extract_epi64(sum_u64, 1)) +
  182|  19.8k|           uint64_t(_mm256_extract_epi64(sum_u64, 2)) +
  183|       |           uint64_t(_mm256_extract_epi64(sum_u64, 3));
  184|  19.8k|  }

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

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

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

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

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

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

_ZNK7simdutf8westmere14implementation13validate_utf8EPKcm:
  299|  20.8k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
  300|  20.8k|  return westmere::utf8_validation::generic_validate_utf8(buf, len);
  301|  20.8k|}
_ZNK7simdutf8westmere14implementation25validate_utf8_with_errorsEPKcm:
  306|  5.26k|    const char *buf, size_t len) const noexcept {
  307|  5.26k|  return westmere::utf8_validation::generic_validate_utf8_with_errors(buf, len);
  308|  5.26k|}
_ZNK7simdutf8westmere14implementation16validate_utf16leEPKDsm:
  345|  15.3k|                                 size_t len) const noexcept {
  346|  15.3k|  if (simdutf_unlikely(len == 0)) {
  ------------------
  |  |   93|  15.3k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 13.5k, False: 1.79k]
  |  |  ------------------
  ------------------
  347|       |    // empty input is valid UTF-16. protect the implementation from
  348|       |    // handling nullptr
  349|  13.5k|    return true;
  350|  13.5k|  }
  351|  1.79k|  const auto res =
  352|  1.79k|      westmere::utf16::validate_utf16_with_errors<endianness::LITTLE>(buf, len);
  353|  1.79k|  if (res.is_err()) {
  ------------------
  |  Branch (353:7): [True: 63, False: 1.73k]
  ------------------
  354|     63|    return false;
  355|     63|  }
  356|       |
  357|  1.73k|  if (res.count == len)
  ------------------
  |  Branch (357:7): [True: 0, False: 1.73k]
  ------------------
  358|      0|    return true;
  359|       |
  360|  1.73k|  return scalar::utf16::validate<endianness::LITTLE>(buf + res.count,
  361|  1.73k|                                                     len - res.count);
  362|  1.73k|}
_ZNK7simdutf8westmere14implementation16validate_utf16beEPKDsm:
  368|  15.3k|                                 size_t len) const noexcept {
  369|  15.3k|  if (simdutf_unlikely(len == 0)) {
  ------------------
  |  |   93|  15.3k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 13.6k, False: 1.78k]
  |  |  ------------------
  ------------------
  370|       |    // empty input is valid UTF-16. protect the implementation from
  371|       |    // handling nullptr
  372|  13.6k|    return true;
  373|  13.6k|  }
  374|  1.78k|  const auto res =
  375|  1.78k|      westmere::utf16::validate_utf16_with_errors<endianness::BIG>(buf, len);
  376|  1.78k|  if (res.is_err()) {
  ------------------
  |  Branch (376:7): [True: 62, False: 1.72k]
  ------------------
  377|     62|    return false;
  378|     62|  }
  379|       |
  380|  1.72k|  if (res.count == len)
  ------------------
  |  Branch (380:7): [True: 0, False: 1.72k]
  ------------------
  381|      0|    return true;
  382|       |
  383|  1.72k|  return scalar::utf16::validate<endianness::BIG>(buf + res.count,
  384|  1.72k|                                                  len - res.count);
  385|  1.72k|}
_ZNK7simdutf8westmere14implementation28validate_utf16le_with_errorsEPKDsm:
  388|  5.26k|    const char16_t *buf, size_t len) const noexcept {
  389|  5.26k|  const result res =
  390|  5.26k|      westmere::utf16::validate_utf16_with_errors<endianness::LITTLE>(buf, len);
  391|  5.26k|  if (res.count != len) {
  ------------------
  |  Branch (391:7): [True: 329, False: 4.93k]
  ------------------
  392|    329|    const result scalar_res =
  393|    329|        scalar::utf16::validate_with_errors<endianness::LITTLE>(
  394|    329|            buf + res.count, len - res.count);
  395|    329|    return result(scalar_res.error, res.count + scalar_res.count);
  396|  4.93k|  } else {
  397|  4.93k|    return res;
  398|  4.93k|  }
  399|  5.26k|}
_ZNK7simdutf8westmere14implementation28validate_utf16be_with_errorsEPKDsm:
  402|  5.26k|    const char16_t *buf, size_t len) const noexcept {
  403|  5.26k|  const result res =
  404|  5.26k|      westmere::utf16::validate_utf16_with_errors<endianness::BIG>(buf, len);
  405|  5.26k|  if (res.count != len) {
  ------------------
  |  Branch (405:7): [True: 319, False: 4.94k]
  ------------------
  406|    319|    result scalar_res = scalar::utf16::validate_with_errors<endianness::BIG>(
  407|    319|        buf + res.count, len - res.count);
  408|    319|    return result(scalar_res.error, res.count + scalar_res.count);
  409|  4.94k|  } else {
  410|  4.94k|    return res;
  411|  4.94k|  }
  412|  5.26k|}
_ZNK7simdutf8westmere14implementation14validate_utf32EPKDim:
  427|  10.1k|implementation::validate_utf32(const char32_t *buf, size_t len) const noexcept {
  428|  10.1k|  return utf32::validate(buf, len);
  429|  10.1k|}
_ZNK7simdutf8westmere14implementation22convert_latin1_to_utf8EPKcmPc:
  441|  5.55k|    const char *buf, size_t len, char *utf8_output) const noexcept {
  442|       |
  443|  5.55k|  std::pair<const char *, char *> ret =
  444|  5.55k|      sse_convert_latin1_to_utf8(buf, len, utf8_output);
  445|  5.55k|  size_t converted_chars = ret.second - utf8_output;
  446|       |
  447|  5.55k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (447:7): [True: 812, False: 4.74k]
  ------------------
  448|    812|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  449|    812|        ret.first, len - (ret.first - buf), ret.second);
  450|    812|    converted_chars += scalar_converted_chars;
  451|    812|  }
  452|       |
  453|  5.55k|  return converted_chars;
  454|  5.55k|}
_ZNK7simdutf8westmere14implementation25convert_latin1_to_utf16leEPKcmPDs:
  459|  5.26k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  460|  5.26k|  std::pair<const char *, char16_t *> ret =
  461|  5.26k|      sse_convert_latin1_to_utf16<endianness::LITTLE>(buf, len, utf16_output);
  462|  5.26k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (462:7): [True: 0, False: 5.26k]
  ------------------
  463|      0|    return 0;
  464|      0|  }
  465|  5.26k|  size_t converted_chars = ret.second - utf16_output;
  466|  5.26k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (466:7): [True: 460, False: 4.80k]
  ------------------
  467|    460|    const size_t scalar_converted_chars =
  468|    460|        scalar::latin1_to_utf16::convert<endianness::LITTLE>(
  469|    460|            ret.first, len - (ret.first - buf), ret.second);
  470|    460|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (470:9): [True: 0, False: 460]
  ------------------
  471|      0|      return 0;
  472|      0|    }
  473|    460|    converted_chars += scalar_converted_chars;
  474|    460|  }
  475|  5.26k|  return converted_chars;
  476|  5.26k|}
_ZNK7simdutf8westmere14implementation25convert_latin1_to_utf16beEPKcmPDs:
  479|  5.26k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  480|  5.26k|  std::pair<const char *, char16_t *> ret =
  481|  5.26k|      sse_convert_latin1_to_utf16<endianness::BIG>(buf, len, utf16_output);
  482|  5.26k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (482:7): [True: 0, False: 5.26k]
  ------------------
  483|      0|    return 0;
  484|      0|  }
  485|  5.26k|  size_t converted_chars = ret.second - utf16_output;
  486|  5.26k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (486:7): [True: 460, False: 4.80k]
  ------------------
  487|    460|    const size_t scalar_converted_chars =
  488|    460|        scalar::latin1_to_utf16::convert<endianness::BIG>(
  489|    460|            ret.first, len - (ret.first - buf), ret.second);
  490|    460|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (490:9): [True: 0, False: 460]
  ------------------
  491|      0|      return 0;
  492|      0|    }
  493|    460|    converted_chars += scalar_converted_chars;
  494|    460|  }
  495|  5.26k|  return converted_chars;
  496|  5.26k|}
_ZNK7simdutf8westmere14implementation23convert_latin1_to_utf32EPKcmPDi:
  501|  5.26k|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  502|  5.26k|  std::pair<const char *, char32_t *> ret =
  503|  5.26k|      sse_convert_latin1_to_utf32(buf, len, utf32_output);
  504|  5.26k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (504:7): [True: 0, False: 5.26k]
  ------------------
  505|      0|    return 0;
  506|      0|  }
  507|  5.26k|  size_t converted_chars = ret.second - utf32_output;
  508|  5.26k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (508:7): [True: 460, False: 4.80k]
  ------------------
  509|    460|    const size_t scalar_converted_chars = scalar::latin1_to_utf32::convert(
  510|    460|        ret.first, len - (ret.first - buf), ret.second);
  511|    460|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (511:9): [True: 0, False: 460]
  ------------------
  512|      0|      return 0;
  513|      0|    }
  514|    460|    converted_chars += scalar_converted_chars;
  515|    460|  }
  516|  5.26k|  return converted_chars;
  517|  5.26k|}
_ZNK7simdutf8westmere14implementation22convert_utf8_to_latin1EPKcmPc:
  522|  10.5k|    const char *buf, size_t len, char *latin1_output) const noexcept {
  523|  10.5k|  utf8_to_latin1::validating_transcoder converter;
  524|  10.5k|  return converter.convert(buf, len, latin1_output);
  525|  10.5k|}
_ZNK7simdutf8westmere14implementation23convert_utf8_to_utf16leEPKcmPDs:
  541|  10.4k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  542|  10.4k|  utf8_to_utf16::validating_transcoder converter;
  543|  10.4k|  return converter.convert<endianness::LITTLE>(buf, len, utf16_output);
  544|  10.4k|}
_ZNK7simdutf8westmere14implementation23convert_utf8_to_utf16beEPKcmPDs:
  547|  10.4k|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  548|  10.4k|  utf8_to_utf16::validating_transcoder converter;
  549|  10.4k|  return converter.convert<endianness::BIG>(buf, len, utf16_output);
  550|  10.4k|}
_ZNK7simdutf8westmere14implementation21convert_utf8_to_utf32EPKcmPDi:
  580|  5.26k|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  581|  5.26k|  utf8_to_utf32::validating_transcoder converter;
  582|  5.26k|  return converter.convert(buf, len, utf32_output);
  583|  5.26k|}
_ZNK7simdutf8westmere14implementation25convert_utf16le_to_latin1EPKDsmPc:
  599|  5.26k|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  600|  5.26k|  std::pair<const char16_t *, char *> ret =
  601|  5.26k|      sse_convert_utf16_to_latin1<endianness::LITTLE>(buf, len, latin1_output);
  602|  5.26k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (602:7): [True: 0, False: 5.26k]
  ------------------
  603|      0|    return 0;
  604|      0|  }
  605|  5.26k|  size_t saved_bytes = ret.second - latin1_output;
  606|       |
  607|  5.26k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (607:7): [True: 430, False: 4.83k]
  ------------------
  608|    430|    const size_t scalar_saved_bytes =
  609|    430|        scalar::utf16_to_latin1::convert<endianness::LITTLE>(
  610|    430|            ret.first, len - (ret.first - buf), ret.second);
  611|    430|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (611:9): [True: 0, False: 430]
  ------------------
  612|      0|      return 0;
  613|      0|    }
  614|    430|    saved_bytes += scalar_saved_bytes;
  615|    430|  }
  616|  5.26k|  return saved_bytes;
  617|  5.26k|}
_ZNK7simdutf8westmere14implementation25convert_utf16be_to_latin1EPKDsmPc:
  620|  5.26k|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  621|  5.26k|  std::pair<const char16_t *, char *> ret =
  622|  5.26k|      sse_convert_utf16_to_latin1<endianness::BIG>(buf, len, latin1_output);
  623|  5.26k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (623:7): [True: 0, False: 5.26k]
  ------------------
  624|      0|    return 0;
  625|      0|  }
  626|  5.26k|  size_t saved_bytes = ret.second - latin1_output;
  627|       |
  628|  5.26k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (628:7): [True: 430, False: 4.83k]
  ------------------
  629|    430|    const size_t scalar_saved_bytes =
  630|    430|        scalar::utf16_to_latin1::convert<endianness::BIG>(
  631|    430|            ret.first, len - (ret.first - buf), ret.second);
  632|    430|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (632:9): [True: 0, False: 430]
  ------------------
  633|      0|      return 0;
  634|      0|    }
  635|    430|    saved_bytes += scalar_saved_bytes;
  636|    430|  }
  637|  5.26k|  return saved_bytes;
  638|  5.26k|}
_ZNK7simdutf8westmere14implementation23convert_utf16le_to_utf8EPKDsmPc:
  709|  10.1k|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  710|  10.1k|  std::pair<const char16_t *, char *> ret =
  711|  10.1k|      sse_convert_utf16_to_utf8<endianness::LITTLE>(buf, len, utf8_output);
  712|  10.1k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (712:7): [True: 70, False: 10.0k]
  ------------------
  713|     70|    return 0;
  714|     70|  }
  715|  10.0k|  size_t saved_bytes = ret.second - utf8_output;
  716|  10.0k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (716:7): [True: 960, False: 9.10k]
  ------------------
  717|    960|    const size_t scalar_saved_bytes =
  718|    960|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  719|    960|            ret.first, len - (ret.first - buf), ret.second);
  720|    960|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (720:9): [True: 37, False: 923]
  ------------------
  721|     37|      return 0;
  722|     37|    }
  723|    923|    saved_bytes += scalar_saved_bytes;
  724|    923|  }
  725|  10.0k|  return saved_bytes;
  726|  10.0k|}
_ZNK7simdutf8westmere14implementation23convert_utf16be_to_utf8EPKDsmPc:
  729|  10.1k|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  730|  10.1k|  std::pair<const char16_t *, char *> ret =
  731|  10.1k|      sse_convert_utf16_to_utf8<endianness::BIG>(buf, len, utf8_output);
  732|  10.1k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (732:7): [True: 69, False: 10.0k]
  ------------------
  733|     69|    return 0;
  734|     69|  }
  735|  10.0k|  size_t saved_bytes = ret.second - utf8_output;
  736|  10.0k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (736:7): [True: 951, False: 9.11k]
  ------------------
  737|    951|    const size_t scalar_saved_bytes =
  738|    951|        scalar::utf16_to_utf8::convert<endianness::BIG>(
  739|    951|            ret.first, len - (ret.first - buf), ret.second);
  740|    951|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (740:9): [True: 31, False: 920]
  ------------------
  741|     31|      return 0;
  742|     31|    }
  743|    920|    saved_bytes += scalar_saved_bytes;
  744|    920|  }
  745|  10.0k|  return saved_bytes;
  746|  10.0k|}
_ZNK7simdutf8westmere14implementation23convert_utf32_to_latin1EPKDimPc:
  817|  5.26k|    const char32_t *buf, size_t len, char *latin1_output) const noexcept {
  818|  5.26k|  std::pair<const char32_t *, char *> ret =
  819|  5.26k|      sse_convert_utf32_to_latin1(buf, len, latin1_output);
  820|  5.26k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (820:7): [True: 0, False: 5.26k]
  ------------------
  821|      0|    return 0;
  822|      0|  }
  823|  5.26k|  size_t saved_bytes = ret.second - latin1_output;
  824|       |  // if (ret.first != buf + len) {
  825|  5.26k|  if (ret.first < buf + len) {
  ------------------
  |  Branch (825:7): [True: 460, False: 4.80k]
  ------------------
  826|    460|    const size_t scalar_saved_bytes = scalar::utf32_to_latin1::convert(
  827|    460|        ret.first, len - (ret.first - buf), ret.second);
  828|    460|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (828:9): [True: 0, False: 460]
  ------------------
  829|      0|      return 0;
  830|      0|    }
  831|    460|    saved_bytes += scalar_saved_bytes;
  832|    460|  }
  833|  5.26k|  return saved_bytes;
  834|  5.26k|}
_ZNK7simdutf8westmere14implementation21convert_utf32_to_utf8EPKDimPc:
  868|  4.86k|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  869|  4.86k|  std::pair<const char32_t *, char *> ret =
  870|  4.86k|      sse_convert_utf32_to_utf8(buf, len, utf8_output);
  871|  4.86k|  if (ret.first == nullptr) {
  ------------------
  |  Branch (871:7): [True: 0, False: 4.86k]
  ------------------
  872|      0|    return 0;
  873|      0|  }
  874|  4.86k|  size_t saved_bytes = ret.second - utf8_output;
  875|  4.86k|  if (ret.first != buf + len) {
  ------------------
  |  Branch (875:7): [True: 701, False: 4.16k]
  ------------------
  876|    701|    const size_t scalar_saved_bytes = scalar::utf32_to_utf8::convert(
  877|    701|        ret.first, len - (ret.first - buf), ret.second);
  878|    701|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (878:9): [True: 0, False: 701]
  ------------------
  879|      0|      return 0;
  880|      0|    }
  881|    701|    saved_bytes += scalar_saved_bytes;
  882|    701|  }
  883|  4.86k|  return saved_bytes;
  884|  4.86k|}
_ZNK7simdutf8westmere14implementation10count_utf8EPKcm:
 1144|  10.5k|implementation::count_utf8(const char *input, size_t length) const noexcept {
 1145|  10.5k|  return utf8::count_code_points_bytemask(input, length);
 1146|  10.5k|}
_ZNK7simdutf8westmere14implementation23latin1_length_from_utf8EPKcm:
 1151|  10.5k|    const char *buf, size_t len) const noexcept {
 1152|  10.5k|  return count_utf8(buf, len);
 1153|  10.5k|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16leEPKDsm:
 1158|  10.1k|    const char16_t *input, size_t length) const noexcept {
 1159|  10.1k|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1160|  10.1k|                                                                    length);
 1161|  10.1k|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16beEPKDsm:
 1164|  10.1k|    const char16_t *input, size_t length) const noexcept {
 1165|  10.1k|  return utf16::utf8_length_from_utf16_bytemask<endianness::BIG>(input, length);
 1166|  10.1k|}
_ZNK7simdutf8westmere14implementation23utf8_length_from_latin1EPKcm:
 1171|  5.55k|    const char *input, size_t len) const noexcept {
 1172|  5.55k|  const uint8_t *str = reinterpret_cast<const uint8_t *>(input);
 1173|  5.55k|  size_t answer = len / sizeof(__m128i) * sizeof(__m128i);
 1174|  5.55k|  size_t i = 0;
 1175|  5.55k|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1175:7): [True: 0, False: 5.55k]
  ------------------
 1176|      0|    __m128i two_64bits = _mm_setzero_si128();
 1177|      0|    while (i + sizeof(__m128i) <= len) {
  ------------------
  |  Branch (1177:12): [True: 0, False: 0]
  ------------------
 1178|      0|      __m128i runner = _mm_setzero_si128();
 1179|      0|      size_t iterations = (len - i) / sizeof(__m128i);
 1180|      0|      if (iterations > 255) {
  ------------------
  |  Branch (1180:11): [True: 0, False: 0]
  ------------------
 1181|      0|        iterations = 255;
 1182|      0|      }
 1183|      0|      size_t max_i = i + iterations * sizeof(__m128i) - sizeof(__m128i);
 1184|      0|      for (; i + 4 * sizeof(__m128i) <= max_i; i += 4 * sizeof(__m128i)) {
  ------------------
  |  Branch (1184:14): [True: 0, False: 0]
  ------------------
 1185|      0|        __m128i input1 = _mm_loadu_si128((const __m128i *)(str + i));
 1186|      0|        __m128i input2 =
 1187|      0|            _mm_loadu_si128((const __m128i *)(str + i + sizeof(__m128i)));
 1188|      0|        __m128i input3 =
 1189|      0|            _mm_loadu_si128((const __m128i *)(str + i + 2 * sizeof(__m128i)));
 1190|      0|        __m128i input4 =
 1191|      0|            _mm_loadu_si128((const __m128i *)(str + i + 3 * sizeof(__m128i)));
 1192|      0|        __m128i input12 =
 1193|      0|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input1),
 1194|      0|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input2));
 1195|      0|        __m128i input34 =
 1196|      0|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input3),
 1197|      0|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input4));
 1198|      0|        __m128i input1234 = _mm_add_epi8(input12, input34);
 1199|      0|        runner = _mm_sub_epi8(runner, input1234);
 1200|      0|      }
 1201|      0|      for (; i <= max_i; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1201:14): [True: 0, False: 0]
  ------------------
 1202|      0|        __m128i more_input = _mm_loadu_si128((const __m128i *)(str + i));
 1203|      0|        runner = _mm_sub_epi8(runner,
 1204|      0|                              _mm_cmpgt_epi8(_mm_setzero_si128(), more_input));
 1205|      0|      }
 1206|      0|      two_64bits =
 1207|      0|          _mm_add_epi64(two_64bits, _mm_sad_epu8(runner, _mm_setzero_si128()));
 1208|      0|    }
 1209|      0|    answer +=
 1210|      0|        _mm_extract_epi64(two_64bits, 0) + _mm_extract_epi64(two_64bits, 1);
 1211|  5.55k|  } else if (answer > 0) { // short string optimization
  ------------------
  |  Branch (1211:14): [True: 792, False: 4.76k]
  ------------------
 1212|  7.13k|    for (; i + 2 * sizeof(__m128i) <= len; i += 2 * sizeof(__m128i)) {
  ------------------
  |  Branch (1212:12): [True: 6.34k, False: 792]
  ------------------
 1213|  6.34k|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1214|  6.34k|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1215|  6.34k|      answer += count_ones(non_ascii);
 1216|  6.34k|      latin = _mm_loadu_si128((const __m128i *)(input + i) + 1);
 1217|  6.34k|      non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1218|  6.34k|      answer += count_ones(non_ascii);
 1219|  6.34k|    }
 1220|  1.01k|    for (; i + sizeof(__m128i) <= len; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1220:12): [True: 221, False: 792]
  ------------------
 1221|    221|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1222|    221|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1223|    221|      answer += count_ones(non_ascii);
 1224|    221|    }
 1225|    792|  }
 1226|  5.55k|  return answer + scalar::latin1::utf8_length_from_latin1(
 1227|  5.55k|                      reinterpret_cast<const char *>(str + i), len - i);
 1228|  5.55k|}
_ZNK7simdutf8westmere14implementation22utf16_length_from_utf8EPKcm:
 1245|  20.8k|    const char *input, size_t length) const noexcept {
 1246|  20.8k|  return utf8::utf16_length_from_utf8_bytemask(input, length);
 1247|  20.8k|}
_ZNK7simdutf8westmere14implementation22utf8_length_from_utf32EPKDim:
 1292|  4.86k|    const char32_t *input, size_t length) const noexcept {
 1293|  4.86k|  return utf32::utf8_length_from_utf32(input, length);
 1294|  4.86k|}
_ZNK7simdutf8westmere14implementation22utf32_length_from_utf8EPKcm:
 1320|  5.26k|    const char *input, size_t length) const noexcept {
 1321|  5.26k|  return utf8::count_code_points(input, length);
 1322|  5.26k|}
_ZNK7simdutf8westmere14implementation16base64_to_binaryEPKcmPcNS_14base64_optionsENS_27last_chunk_handling_optionsE:
 1328|  15.3k|    last_chunk_handling_options last_chunk_options) const noexcept {
 1329|  15.3k|  if (options & base64_default_or_url) {
  ------------------
  |  Branch (1329:7): [True: 0, False: 15.3k]
  ------------------
 1330|      0|    if (options == base64_options::base64_default_or_url_accept_garbage) {
  ------------------
  |  Branch (1330:9): [True: 0, False: 0]
  ------------------
 1331|      0|      return base64::compress_decode_base64<false, true, true>(
 1332|      0|          output, input, length, options, last_chunk_options);
 1333|      0|    } else {
 1334|      0|      return base64::compress_decode_base64<false, false, true>(
 1335|      0|          output, input, length, options, last_chunk_options);
 1336|      0|    }
 1337|  15.3k|  } else if (options & base64_url) {
  ------------------
  |  Branch (1337:14): [True: 0, False: 15.3k]
  ------------------
 1338|      0|    if (options == base64_options::base64_url_accept_garbage) {
  ------------------
  |  Branch (1338:9): [True: 0, False: 0]
  ------------------
 1339|      0|      return base64::compress_decode_base64<true, true, false>(
 1340|      0|          output, input, length, options, last_chunk_options);
 1341|      0|    } else {
 1342|      0|      return base64::compress_decode_base64<true, false, false>(
 1343|      0|          output, input, length, options, last_chunk_options);
 1344|      0|    }
 1345|  15.3k|  } else {
 1346|  15.3k|    if (options == base64_options::base64_default_accept_garbage) {
  ------------------
  |  Branch (1346:9): [True: 0, False: 15.3k]
  ------------------
 1347|      0|      return base64::compress_decode_base64<false, true, false>(
 1348|      0|          output, input, length, options, last_chunk_options);
 1349|  15.3k|    } else {
 1350|  15.3k|      return base64::compress_decode_base64<false, false, false>(
 1351|  15.3k|          output, input, length, options, last_chunk_options);
 1352|  15.3k|    }
 1353|  15.3k|  }
 1354|  15.3k|}
_ZNK7simdutf8westmere14implementation16binary_to_base64EPKcmPcNS_14base64_optionsE:
 1448|  14.8k|                                        base64_options options) const noexcept {
 1449|  14.8k|  if (options & base64_url) {
  ------------------
  |  Branch (1449:7): [True: 0, False: 14.8k]
  ------------------
 1450|      0|    return encode_base64<true>(output, input, length, options);
 1451|  14.8k|  } else {
 1452|  14.8k|    return encode_base64<false>(output, input, length, options);
 1453|  14.8k|  }
 1454|  14.8k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_18is_asciiERKNS1_4simd8simd8x64IhEE:
   13|  35.4k|simdutf_really_inline bool is_ascii(const simd8x64<uint8_t> &input) {
   14|  35.4k|  return input.reduce_or().is_ascii();
   15|  35.4k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_124must_be_2_3_continuationENS1_4simd5simd8IhEES4_:
   22|  65.6k|                         const simd8<uint8_t> prev3) {
   23|  65.6k|  simd8<uint8_t> is_third_byte =
   24|  65.6k|      prev2.saturating_sub(0xe0u - 0x80); // Only 111_____ will be >= 0x80
   25|  65.6k|  simd8<uint8_t> is_fourth_byte =
   26|  65.6k|      prev3.saturating_sub(0xf0u - 0x80); // Only 1111____ will be >= 0x80
   27|  65.6k|  return simd8<bool>(is_third_byte | is_fourth_byte);
   28|  65.6k|}

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

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

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

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

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

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

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

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

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_125sse_convert_utf32_to_utf8EPKDimPc:
    2|  4.86k|sse_convert_utf32_to_utf8(const char32_t *buf, size_t len, char *utf8_output) {
    3|  4.86k|  const char32_t *end = buf + len;
    4|       |
    5|  4.86k|  const __m128i v_0000 = _mm_setzero_si128();              //__m128 = 128 bits
    6|  4.86k|  const __m128i v_f800 = _mm_set1_epi16((uint16_t)0xf800); // 1111 1000 0000
    7|       |                                                           // 0000
    8|  4.86k|  const __m128i v_c080 = _mm_set1_epi16((uint16_t)0xc080); // 1100 0000 1000
    9|       |                                                           // 0000
   10|  4.86k|  const __m128i v_ff80 = _mm_set1_epi16((uint16_t)0xff80); // 1111 1111 1000
   11|       |                                                           // 0000
   12|  4.86k|  const __m128i v_ffff0000 = _mm_set1_epi32(
   13|  4.86k|      (uint32_t)0xffff0000); // 1111 1111 1111 1111 0000 0000 0000 0000
   14|  4.86k|  const __m128i v_7fffffff = _mm_set1_epi32(
   15|  4.86k|      (uint32_t)0x7fffffff); // 0111 1111 1111 1111 1111 1111 1111 1111
   16|  4.86k|  __m128i running_max = _mm_setzero_si128();
   17|  4.86k|  __m128i forbidden_bytemask = _mm_setzero_si128();
   18|  4.86k|  const size_t safety_margin =
   19|  4.86k|      12; // to avoid overruns, see issue
   20|       |          // https://github.com/simdutf/simdutf/issues/92
   21|       |
   22|  10.4k|  while (end - buf >=
  ------------------
  |  Branch (22:10): [True: 5.63k, False: 4.86k]
  ------------------
   23|  10.4k|         std::ptrdiff_t(
   24|  10.4k|             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.63k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
   29|  5.63k|    __m128i nextin = _mm_loadu_si128(
   30|  5.63k|        (__m128i *)buf + 1); // These two values can hold only 8 UTF32 chars
   31|  5.63k|    running_max = _mm_max_epu32(
   32|  5.63k|        _mm_max_epu32(in, running_max), // take element-wise max char32_t from
   33|       |                                        // in and running_max vector
   34|  5.63k|        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.63k|    __m128i in_16 = _mm_packus_epi32(
   40|  5.63k|        _mm_and_si128(in, v_7fffffff),
   41|  5.63k|        _mm_and_si128(
   42|  5.63k|            nextin,
   43|  5.63k|            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.63k|    if (_mm_testz_si128(in_16, v_ff80)) { // if the first two blocks are ASCII
  ------------------
  |  Branch (60:9): [True: 3.26k, False: 2.37k]
  ------------------
   61|  3.26k|      __m128i thirdin = _mm_loadu_si128((__m128i *)buf + 2);
   62|  3.26k|      __m128i fourthin = _mm_loadu_si128((__m128i *)buf + 3);
   63|  3.26k|      running_max = _mm_max_epu32(
   64|  3.26k|          _mm_max_epu32(thirdin, running_max),
   65|  3.26k|          fourthin); // take the running max of all 4 vectors thus far
   66|  3.26k|      __m128i nextin_16 = _mm_packus_epi32(
   67|  3.26k|          _mm_and_si128(thirdin, v_7fffffff),
   68|  3.26k|          _mm_and_si128(fourthin,
   69|  3.26k|                        v_7fffffff)); // pack into 1 vector, now you have two
   70|  3.26k|      if (!_mm_testz_si128(
  ------------------
  |  Branch (70:11): [True: 335, False: 2.93k]
  ------------------
   71|  3.26k|              nextin_16,
   72|  3.26k|              v_ff80)) { // checks if the second packed vector is ASCII, if not:
   73|       |        // 1. pack the bytes
   74|       |        // obviously suboptimal.
   75|    335|        const __m128i utf8_packed = _mm_packus_epi16(
   76|    335|            in_16, in_16); // creates two copy of in_16 in 1 vector
   77|       |        // 2. store (16 bytes)
   78|    335|        _mm_storeu_si128((__m128i *)utf8_output,
   79|    335|                         utf8_packed); // put them into the output
   80|       |        // 3. adjust pointers
   81|    335|        buf += 8; // the char32_t buffer pointer goes up 8 char32_t chars* 32
   82|       |                  // bits =  256 bits
   83|    335|        utf8_output +=
   84|    335|            8; // same with output, e.g. lift the first two blocks alone.
   85|       |        // Proceed with next input
   86|    335|        in_16 = nextin_16;
   87|       |        // We need to update in and nextin because they are used later.
   88|    335|        in = thirdin;
   89|    335|        nextin = fourthin;
   90|  2.93k|      } else {
   91|       |        // 1. pack the bytes
   92|  2.93k|        const __m128i utf8_packed = _mm_packus_epi16(in_16, nextin_16);
   93|       |        // 2. store (16 bytes)
   94|  2.93k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   95|       |        // 3. adjust pointers
   96|  2.93k|        buf += 16;
   97|  2.93k|        utf8_output += 16;
   98|  2.93k|        continue; // we are done for this round!
   99|  2.93k|      }
  100|  3.26k|    }
  101|       |
  102|       |    // no bits set above 7th bit -- find out all the ASCII characters
  103|  2.70k|    const __m128i one_byte_bytemask =
  104|  2.70k|        _mm_cmpeq_epi16( // this takes four bytes at a time and compares:
  105|  2.70k|            _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.70k|            v_0000                        //
  108|  2.70k|        ); // 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.70k|    const uint16_t one_byte_bitmask = static_cast<uint16_t>(_mm_movemask_epi8(
  113|  2.70k|        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.70k|    const __m128i one_or_two_bytes_bytemask =
  118|  2.70k|        _mm_cmpeq_epi16(_mm_and_si128(in_16, v_f800), v_0000);
  119|  2.70k|    const uint16_t one_or_two_bytes_bitmask =
  120|  2.70k|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  121|       |
  122|  2.70k|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (122:9): [True: 1.59k, False: 1.10k]
  ------------------
  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.59k|      const __m128i v_1f00 =
  129|  1.59k|          _mm_set1_epi16((int16_t)0x1f00); // 0001 1111 0000 0000
  130|  1.59k|      const __m128i v_003f =
  131|  1.59k|          _mm_set1_epi16((int16_t)0x003f); // 0000 0000 0011 1111
  132|       |
  133|       |      // t0 = [000a|aaaa|bbbb|bb00]
  134|  1.59k|      const __m128i t0 = _mm_slli_epi16(in_16, 2); // shift packed vector by two
  135|       |      // t1 = [000a|aaaa|0000|0000]
  136|  1.59k|      const __m128i t1 = _mm_and_si128(t0, v_1f00); // potential first utf8 byte
  137|       |      // t2 = [0000|0000|00bb|bbbb]
  138|  1.59k|      const __m128i t2 =
  139|  1.59k|          _mm_and_si128(in_16, v_003f); // potential second utf8 byte
  140|       |      // t3 = [000a|aaaa|00bb|bbbb]
  141|  1.59k|      const __m128i t3 =
  142|  1.59k|          _mm_or_si128(t1, t2); // first and second potential utf8 byte together
  143|       |      // t4 = [110a|aaaa|10bb|bbbb]
  144|  1.59k|      const __m128i t4 = _mm_or_si128(
  145|  1.59k|          t3,
  146|  1.59k|          v_c080); // t3 | 1100 0000 1000 0000 = full potential 2-byte utf8 unit
  147|       |
  148|       |      // 2. merge ASCII and 2-byte codewords
  149|  1.59k|      const __m128i utf8_unpacked =
  150|  1.59k|          _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.59k|      const uint16_t m0 = one_byte_bitmask & 0x5555; // m0 = 0h0g0f0e0d0c0b0a
  156|  1.59k|      const uint16_t m1 =
  157|  1.59k|          static_cast<uint16_t>(m0 >> 7); // m1 = 00000000h0g0f0e0
  158|  1.59k|      const uint8_t m2 =
  159|  1.59k|          static_cast<uint8_t>((m0 | m1) & 0xff); // m2 =         hdgcfbea
  160|       |      // 4. pack the bytes
  161|  1.59k|      const uint8_t *row =
  162|  1.59k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[m2][0];
  163|  1.59k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  164|  1.59k|      const __m128i utf8_packed = _mm_shuffle_epi8(utf8_unpacked, shuffle);
  165|       |
  166|       |      // 5. store bytes
  167|  1.59k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  168|       |
  169|       |      // 6. adjust pointers
  170|  1.59k|      buf += 8;
  171|  1.59k|      utf8_output += row[0];
  172|  1.59k|      continue;
  173|  1.59k|    }
  174|       |
  175|       |    // Check for overflow in packing
  176|       |
  177|  1.10k|    const __m128i saturation_bytemask = _mm_cmpeq_epi32(
  178|  1.10k|        _mm_and_si128(_mm_or_si128(in, nextin), v_ffff0000), v_0000);
  179|  1.10k|    const uint32_t saturation_bitmask =
  180|  1.10k|        static_cast<uint32_t>(_mm_movemask_epi8(saturation_bytemask));
  181|  1.10k|    if (saturation_bitmask == 0xffff) {
  ------------------
  |  Branch (181:9): [True: 435, False: 672]
  ------------------
  182|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  183|    435|      const __m128i v_d800 = _mm_set1_epi16((uint16_t)0xd800);
  184|    435|      forbidden_bytemask =
  185|    435|          _mm_or_si128(forbidden_bytemask,
  186|    435|                       _mm_cmpeq_epi16(_mm_and_si128(in_16, v_f800), v_d800));
  187|       |
  188|    435|      const __m128i dup_even = _mm_setr_epi16(0x0000, 0x0202, 0x0404, 0x0606,
  189|    435|                                              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|    435|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  219|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  220|    435|      const __m128i t0 = _mm_shuffle_epi8(in_16, dup_even);
  221|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  222|    435|      const __m128i t1 = _mm_and_si128(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  218|    435|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  223|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  224|    435|      const __m128i t2 = _mm_or_si128(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  218|    435|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  225|       |
  226|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  227|    435|      const __m128i s0 = _mm_srli_epi16(in_16, 4);
  228|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  229|    435|      const __m128i s1 = _mm_and_si128(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  218|    435|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  230|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  231|    435|      const __m128i s2 = _mm_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  218|    435|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  232|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  233|    435|      const __m128i s3 = _mm_or_si128(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  218|    435|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  234|    435|      const __m128i m0 = _mm_andnot_si128(one_or_two_bytes_bytemask,
  235|    435|                                          simdutf_vec(0b0100000000000000));
  ------------------
  |  |  218|    435|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  236|    435|      const __m128i s4 = _mm_xor_si128(s3, m0);
  237|    435|#undef simdutf_vec
  238|       |
  239|       |      // 4. expand code units 16-bit => 32-bit
  240|    435|      const __m128i out0 = _mm_unpacklo_epi16(t2, s4);
  241|    435|      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|    435|      const uint16_t mask =
  245|    435|          (one_byte_bitmask & 0x5555) | (one_or_two_bytes_bitmask & 0xaaaa);
  246|    435|      if (mask == 0) {
  ------------------
  |  Branch (246:11): [True: 74, False: 361]
  ------------------
  247|       |        // We only have three-byte code units. Use fast path.
  248|     74|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  249|     74|                                              15, 13, -1, -1, -1, -1);
  250|     74|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  251|     74|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  252|     74|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  253|     74|        utf8_output += 12;
  254|     74|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  255|     74|        utf8_output += 12;
  256|     74|        buf += 8;
  257|     74|        continue;
  258|     74|      }
  259|    361|      const uint8_t mask0 = uint8_t(mask);
  260|       |
  261|    361|      const uint8_t *row0 =
  262|    361|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  263|    361|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  264|    361|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  265|       |
  266|    361|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  267|       |
  268|    361|      const uint8_t *row1 =
  269|    361|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  270|    361|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  271|    361|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  272|       |
  273|    361|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  274|    361|      utf8_output += row0[0];
  275|    361|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  276|    361|      utf8_output += row1[0];
  277|       |
  278|    361|      buf += 8;
  279|    672|    } 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|    672|      size_t forward = 15;
  285|    672|      size_t k = 0;
  286|    672|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (286:11): [True: 0, False: 672]
  ------------------
  287|      0|        forward = size_t(end - buf - 1);
  288|      0|      }
  289|  10.7k|      for (; k < forward; k++) {
  ------------------
  |  Branch (289:14): [True: 10.0k, False: 672]
  ------------------
  290|  10.0k|        uint32_t word = buf[k];
  291|  10.0k|        if ((word & 0xFFFFFF80) == 0) {
  ------------------
  |  Branch (291:13): [True: 8.01k, False: 2.06k]
  ------------------
  292|  8.01k|          *utf8_output++ = char(word);
  293|  8.01k|        } else if ((word & 0xFFFFF800) == 0) {
  ------------------
  |  Branch (293:20): [True: 474, False: 1.59k]
  ------------------
  294|    474|          *utf8_output++ = char((word >> 6) | 0b11000000);
  295|    474|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  296|  1.59k|        } else if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (296:20): [True: 526, False: 1.06k]
  ------------------
  297|    526|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (297:15): [True: 245, False: 281]
  |  Branch (297:33): [True: 0, False: 245]
  ------------------
  298|      0|            return std::make_pair(nullptr, utf8_output);
  299|      0|          }
  300|    526|          *utf8_output++ = char((word >> 12) | 0b11100000);
  301|    526|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  302|    526|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  303|  1.06k|        } else {
  304|  1.06k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (304:15): [True: 0, False: 1.06k]
  ------------------
  305|      0|            return std::make_pair(nullptr, utf8_output);
  306|      0|          }
  307|  1.06k|          *utf8_output++ = char((word >> 18) | 0b11110000);
  308|  1.06k|          *utf8_output++ = char(((word >> 12) & 0b111111) | 0b10000000);
  309|  1.06k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  310|  1.06k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  311|  1.06k|        }
  312|  10.0k|      }
  313|    672|      buf += k;
  314|    672|    }
  315|  1.10k|  } // while
  316|       |
  317|       |  // check for invalid input
  318|  4.86k|  const __m128i v_10ffff = _mm_set1_epi32((uint32_t)0x10ffff);
  319|  4.86k|  if (static_cast<uint16_t>(_mm_movemask_epi8(_mm_cmpeq_epi32(
  ------------------
  |  Branch (319:7): [True: 0, False: 4.86k]
  ------------------
  320|  4.86k|          _mm_max_epu32(running_max, v_10ffff), v_10ffff))) != 0xffff) {
  321|      0|    return std::make_pair(nullptr, utf8_output);
  322|      0|  }
  323|       |
  324|  4.86k|  if (static_cast<uint32_t>(_mm_movemask_epi8(forbidden_bytemask)) != 0) {
  ------------------
  |  Branch (324:7): [True: 0, False: 4.86k]
  ------------------
  325|      0|    return std::make_pair(nullptr, utf8_output);
  326|      0|  }
  327|       |
  328|  4.86k|  return std::make_pair(buf, utf8_output);
  329|  4.86k|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_129convert_masked_utf8_to_latin1EPKcmRPc:
    9|  22.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|  22.5k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   21|  22.5k|  const uint16_t input_utf8_end_of_code_point_mask =
   22|  22.5k|      utf8_end_of_code_point_mask &
   23|  22.5k|      0xfff; // we are only processing 12 bytes in case it is not all ASCII
   24|  22.5k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (24:7): [True: 128, False: 22.4k]
  ------------------
   25|       |    // We process the data in chunks of 12 bytes.
   26|    128|    _mm_storeu_si128(reinterpret_cast<__m128i *>(latin1_output), in);
   27|    128|    latin1_output += 12; // We wrote 12 characters.
   28|    128|    return 12;           // We consumed 12 bytes.
   29|    128|  }
   30|       |  /// We do not have a fast path available, so we fallback.
   31|  22.4k|  const uint8_t idx =
   32|  22.4k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   33|  22.4k|  const uint8_t consumed =
   34|  22.4k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   35|       |  // this indicates an invalid input:
   36|  22.4k|  if (idx >= 64) {
  ------------------
  |  Branch (36:7): [True: 5.56k, False: 16.8k]
  ------------------
   37|  5.56k|    return consumed;
   38|  5.56k|  }
   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|  16.8k|  const __m128i sh =
   46|  16.8k|      _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   47|  16.8k|  const __m128i perm = _mm_shuffle_epi8(in, sh);
   48|  16.8k|  const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   49|  16.8k|  const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   50|  16.8k|  __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   51|  16.8k|  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|  16.8k|  _mm_storel_epi64((__m128i *)latin1_output, latin1_packed);
   56|  16.8k|  latin1_output += 6; // We wrote 6 bytes.
   57|  16.8k|  return consumed;
   58|  22.4k|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_128convert_masked_utf8_to_utf16ILNS_10endiannessE0EEEmPKcmRPDs:
   10|  20.8k|                                    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|  20.8k|  const __m128i swap =
   23|  20.8k|      _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   24|  20.8k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   25|  20.8k|  const uint16_t input_utf8_end_of_code_point_mask =
   26|  20.8k|      utf8_end_of_code_point_mask & 0xfff;
   27|  20.8k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (27:7): [True: 85, False: 20.7k]
  ------------------
   28|       |    // We process the data in chunks of 12 bytes.
   29|       |    // Note: using 16 bytes is unsafe, see issue_ossfuzz_71218
   30|     85|    __m128i ascii_first = _mm_cvtepu8_epi16(in);
   31|     85|    __m128i ascii_second = _mm_cvtepu8_epi16(_mm_srli_si128(in, 8));
   32|     85|    if (big_endian) {
  ------------------
  |  Branch (32:9): [Folded, False: 85]
  ------------------
   33|      0|      ascii_first = _mm_shuffle_epi8(ascii_first, swap);
   34|      0|      ascii_second = _mm_shuffle_epi8(ascii_second, swap);
   35|      0|    }
   36|     85|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf16_output), ascii_first);
   37|     85|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf16_output + 8),
   38|     85|                     ascii_second);
   39|     85|    utf16_output += 12; // We wrote 12 16-bit characters.
   40|     85|    return 12;          // We consumed 12 bytes.
   41|     85|  }
   42|  20.7k|  if (((utf8_end_of_code_point_mask & 0xFFFF) == 0xaaaa)) {
  ------------------
  |  Branch (42:7): [True: 373, False: 20.3k]
  ------------------
   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|    373|    const __m128i sh =
   47|    373|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   48|    373|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   49|    373|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   50|    373|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   51|    373|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   52|    373|    if (big_endian)
  ------------------
  |  Branch (52:9): [Folded, False: 373]
  ------------------
   53|      0|      composed = _mm_shuffle_epi8(composed, swap);
   54|    373|    _mm_storeu_si128((__m128i *)utf16_output, composed);
   55|    373|    utf16_output += 8; // We wrote 16 bytes, 8 code points.
   56|    373|    return 16;
   57|    373|  }
   58|  20.3k|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (58:7): [True: 5.29k, False: 15.0k]
  ------------------
   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.29k|    const __m128i sh =
   63|  5.29k|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   64|  5.29k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   65|  5.29k|    const __m128i ascii =
   66|  5.29k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   67|  5.29k|    const __m128i middlebyte =
   68|  5.29k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   69|  5.29k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   70|  5.29k|    const __m128i highbyte =
   71|  5.29k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   72|  5.29k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   73|  5.29k|    const __m128i composed =
   74|  5.29k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   75|  5.29k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
   76|  5.29k|    if (big_endian)
  ------------------
  |  Branch (76:9): [Folded, False: 5.29k]
  ------------------
   77|      0|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
   78|  5.29k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
   79|  5.29k|    utf16_output += 4;
   80|  5.29k|    return 12;
   81|  5.29k|  }
   82|       |  /// We do not have a fast path available, so we fallback.
   83|       |
   84|  15.0k|  const uint8_t idx =
   85|  15.0k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   86|  15.0k|  const uint8_t consumed =
   87|  15.0k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   88|  15.0k|  if (idx < 64) {
  ------------------
  |  Branch (88:7): [True: 8.18k, False: 6.91k]
  ------------------
   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.18k|    const __m128i sh =
   96|  8.18k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   97|  8.18k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   98|  8.18k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   99|  8.18k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
  100|  8.18k|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
  101|  8.18k|    if (big_endian)
  ------------------
  |  Branch (101:9): [Folded, False: 8.18k]
  ------------------
  102|      0|      composed = _mm_shuffle_epi8(composed, swap);
  103|  8.18k|    _mm_storeu_si128((__m128i *)utf16_output, composed);
  104|  8.18k|    utf16_output += 6; // We wrote 12 bytes, 6 code points.
  105|  8.18k|  } else if (idx < 145) {
  ------------------
  |  Branch (105:14): [True: 1.93k, False: 4.97k]
  ------------------
  106|       |    // FOUR (4) input code-code units
  107|  1.93k|    const __m128i sh =
  108|  1.93k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  109|  1.93k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  110|  1.93k|    const __m128i ascii =
  111|  1.93k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
  112|  1.93k|    const __m128i middlebyte =
  113|  1.93k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  114|  1.93k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  115|  1.93k|    const __m128i highbyte =
  116|  1.93k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  117|  1.93k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  118|  1.93k|    const __m128i composed =
  119|  1.93k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  120|  1.93k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
  121|  1.93k|    if (big_endian)
  ------------------
  |  Branch (121:9): [Folded, False: 1.93k]
  ------------------
  122|      0|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
  123|  1.93k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
  124|  1.93k|    utf16_output += 4;
  125|  4.97k|  } else if (idx < 209) {
  ------------------
  |  Branch (125:14): [True: 4.68k, False: 289]
  ------------------
  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.68k|    const __m128i sh =
  137|  4.68k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  138|  4.68k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  139|  4.68k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  140|  4.68k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  141|  4.68k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  142|  4.68k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  143|       |    // correct for spurious high bit
  144|  4.68k|    const __m128i correct =
  145|  4.68k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  146|  4.68k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  147|  4.68k|    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.68k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0xff000000));
  151|  4.68k|    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.68k|    const __m128i composed =
  157|  4.68k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  158|  4.68k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  159|  4.68k|    const __m128i composedminus =
  160|  4.68k|        _mm_sub_epi32(composed, _mm_set1_epi32(0x10000));
  161|  4.68k|    const __m128i lowtenbits =
  162|  4.68k|        _mm_and_si128(composedminus, _mm_set1_epi32(0x3ff));
  163|       |    // Notice the 0x3ff mask:
  164|  4.68k|    const __m128i hightenbits =
  165|  4.68k|        _mm_and_si128(_mm_srli_epi32(composedminus, 10), _mm_set1_epi32(0x3ff));
  166|  4.68k|    const __m128i lowtenbitsadd =
  167|  4.68k|        _mm_add_epi32(lowtenbits, _mm_set1_epi32(0xDC00));
  168|  4.68k|    const __m128i hightenbitsadd =
  169|  4.68k|        _mm_add_epi32(hightenbits, _mm_set1_epi32(0xD800));
  170|  4.68k|    const __m128i lowtenbitsaddshifted = _mm_slli_epi32(lowtenbitsadd, 16);
  171|  4.68k|    __m128i surrogates = _mm_or_si128(hightenbitsadd, lowtenbitsaddshifted);
  172|  4.68k|    uint32_t basic_buffer[4];
  173|  4.68k|    uint32_t basic_buffer_swap[4];
  174|  4.68k|    if (big_endian) {
  ------------------
  |  Branch (174:9): [Folded, False: 4.68k]
  ------------------
  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.68k|    _mm_storeu_si128((__m128i *)basic_buffer, composed);
  180|  4.68k|    uint32_t surrogate_buffer[4];
  181|  4.68k|    _mm_storeu_si128((__m128i *)surrogate_buffer, surrogates);
  182|  18.7k|    for (size_t i = 0; i < 3; i++) {
  ------------------
  |  Branch (182:24): [True: 14.0k, False: 4.68k]
  ------------------
  183|  14.0k|      if (basic_buffer[i] > 0x3c00000) {
  ------------------
  |  Branch (183:11): [True: 3.08k, False: 10.9k]
  ------------------
  184|  3.08k|        utf16_output[0] = uint16_t(surrogate_buffer[i] & 0xffff);
  185|  3.08k|        utf16_output[1] = uint16_t(surrogate_buffer[i] >> 16);
  186|  3.08k|        utf16_output += 2;
  187|  10.9k|      } else {
  188|  10.9k|        utf16_output[0] = big_endian ? uint16_t(basic_buffer_swap[i])
  ------------------
  |  Branch (188:27): [Folded, False: 10.9k]
  ------------------
  189|  10.9k|                                     : uint16_t(basic_buffer[i]);
  190|  10.9k|        utf16_output++;
  191|  10.9k|      }
  192|  14.0k|    }
  193|  4.68k|  } else {
  194|       |    // here we know that there is an error but we do not handle errors
  195|    289|  }
  196|  15.0k|  return consumed;
  197|  20.3k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_128convert_masked_utf8_to_utf16ILNS_10endiannessE1EEEmPKcmRPDs:
   10|  21.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|  21.6k|  const __m128i swap =
   23|  21.6k|      _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   24|  21.6k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   25|  21.6k|  const uint16_t input_utf8_end_of_code_point_mask =
   26|  21.6k|      utf8_end_of_code_point_mask & 0xfff;
   27|  21.6k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (27:7): [True: 86, False: 21.5k]
  ------------------
   28|       |    // We process the data in chunks of 12 bytes.
   29|       |    // Note: using 16 bytes is unsafe, see issue_ossfuzz_71218
   30|     86|    __m128i ascii_first = _mm_cvtepu8_epi16(in);
   31|     86|    __m128i ascii_second = _mm_cvtepu8_epi16(_mm_srli_si128(in, 8));
   32|     86|    if (big_endian) {
  ------------------
  |  Branch (32:9): [True: 86, Folded]
  ------------------
   33|     86|      ascii_first = _mm_shuffle_epi8(ascii_first, swap);
   34|     86|      ascii_second = _mm_shuffle_epi8(ascii_second, swap);
   35|     86|    }
   36|     86|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf16_output), ascii_first);
   37|     86|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf16_output + 8),
   38|     86|                     ascii_second);
   39|     86|    utf16_output += 12; // We wrote 12 16-bit characters.
   40|     86|    return 12;          // We consumed 12 bytes.
   41|     86|  }
   42|  21.5k|  if (((utf8_end_of_code_point_mask & 0xFFFF) == 0xaaaa)) {
  ------------------
  |  Branch (42:7): [True: 409, False: 21.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|    409|    const __m128i sh =
   47|    409|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   48|    409|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   49|    409|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   50|    409|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   51|    409|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   52|    409|    if (big_endian)
  ------------------
  |  Branch (52:9): [True: 409, Folded]
  ------------------
   53|    409|      composed = _mm_shuffle_epi8(composed, swap);
   54|    409|    _mm_storeu_si128((__m128i *)utf16_output, composed);
   55|    409|    utf16_output += 8; // We wrote 16 bytes, 8 code points.
   56|    409|    return 16;
   57|    409|  }
   58|  21.1k|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (58:7): [True: 5.97k, False: 15.1k]
  ------------------
   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.97k|    const __m128i sh =
   63|  5.97k|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   64|  5.97k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   65|  5.97k|    const __m128i ascii =
   66|  5.97k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   67|  5.97k|    const __m128i middlebyte =
   68|  5.97k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   69|  5.97k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   70|  5.97k|    const __m128i highbyte =
   71|  5.97k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   72|  5.97k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   73|  5.97k|    const __m128i composed =
   74|  5.97k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   75|  5.97k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
   76|  5.97k|    if (big_endian)
  ------------------
  |  Branch (76:9): [True: 5.97k, Folded]
  ------------------
   77|  5.97k|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
   78|  5.97k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
   79|  5.97k|    utf16_output += 4;
   80|  5.97k|    return 12;
   81|  5.97k|  }
   82|       |  /// We do not have a fast path available, so we fallback.
   83|       |
   84|  15.1k|  const uint8_t idx =
   85|  15.1k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   86|  15.1k|  const uint8_t consumed =
   87|  15.1k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   88|  15.1k|  if (idx < 64) {
  ------------------
  |  Branch (88:7): [True: 8.07k, False: 7.08k]
  ------------------
   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.07k|    const __m128i sh =
   96|  8.07k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   97|  8.07k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   98|  8.07k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   99|  8.07k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
  100|  8.07k|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
  101|  8.07k|    if (big_endian)
  ------------------
  |  Branch (101:9): [True: 8.07k, Folded]
  ------------------
  102|  8.07k|      composed = _mm_shuffle_epi8(composed, swap);
  103|  8.07k|    _mm_storeu_si128((__m128i *)utf16_output, composed);
  104|  8.07k|    utf16_output += 6; // We wrote 12 bytes, 6 code points.
  105|  8.07k|  } else if (idx < 145) {
  ------------------
  |  Branch (105:14): [True: 2.13k, False: 4.94k]
  ------------------
  106|       |    // FOUR (4) input code-code units
  107|  2.13k|    const __m128i sh =
  108|  2.13k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  109|  2.13k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  110|  2.13k|    const __m128i ascii =
  111|  2.13k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
  112|  2.13k|    const __m128i middlebyte =
  113|  2.13k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  114|  2.13k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  115|  2.13k|    const __m128i highbyte =
  116|  2.13k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  117|  2.13k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  118|  2.13k|    const __m128i composed =
  119|  2.13k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  120|  2.13k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
  121|  2.13k|    if (big_endian)
  ------------------
  |  Branch (121:9): [True: 2.13k, Folded]
  ------------------
  122|  2.13k|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
  123|  2.13k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
  124|  2.13k|    utf16_output += 4;
  125|  4.94k|  } else if (idx < 209) {
  ------------------
  |  Branch (125:14): [True: 4.66k, False: 289]
  ------------------
  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.66k|    const __m128i sh =
  137|  4.66k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  138|  4.66k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  139|  4.66k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  140|  4.66k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  141|  4.66k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  142|  4.66k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  143|       |    // correct for spurious high bit
  144|  4.66k|    const __m128i correct =
  145|  4.66k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  146|  4.66k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  147|  4.66k|    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.66k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0xff000000));
  151|  4.66k|    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.66k|    const __m128i composed =
  157|  4.66k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  158|  4.66k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  159|  4.66k|    const __m128i composedminus =
  160|  4.66k|        _mm_sub_epi32(composed, _mm_set1_epi32(0x10000));
  161|  4.66k|    const __m128i lowtenbits =
  162|  4.66k|        _mm_and_si128(composedminus, _mm_set1_epi32(0x3ff));
  163|       |    // Notice the 0x3ff mask:
  164|  4.66k|    const __m128i hightenbits =
  165|  4.66k|        _mm_and_si128(_mm_srli_epi32(composedminus, 10), _mm_set1_epi32(0x3ff));
  166|  4.66k|    const __m128i lowtenbitsadd =
  167|  4.66k|        _mm_add_epi32(lowtenbits, _mm_set1_epi32(0xDC00));
  168|  4.66k|    const __m128i hightenbitsadd =
  169|  4.66k|        _mm_add_epi32(hightenbits, _mm_set1_epi32(0xD800));
  170|  4.66k|    const __m128i lowtenbitsaddshifted = _mm_slli_epi32(lowtenbitsadd, 16);
  171|  4.66k|    __m128i surrogates = _mm_or_si128(hightenbitsadd, lowtenbitsaddshifted);
  172|  4.66k|    uint32_t basic_buffer[4];
  173|  4.66k|    uint32_t basic_buffer_swap[4];
  174|  4.66k|    if (big_endian) {
  ------------------
  |  Branch (174:9): [True: 4.66k, Folded]
  ------------------
  175|  4.66k|      _mm_storeu_si128((__m128i *)basic_buffer_swap,
  176|  4.66k|                       _mm_shuffle_epi8(composed, swap));
  177|  4.66k|      surrogates = _mm_shuffle_epi8(surrogates, swap);
  178|  4.66k|    }
  179|  4.66k|    _mm_storeu_si128((__m128i *)basic_buffer, composed);
  180|  4.66k|    uint32_t surrogate_buffer[4];
  181|  4.66k|    _mm_storeu_si128((__m128i *)surrogate_buffer, surrogates);
  182|  18.6k|    for (size_t i = 0; i < 3; i++) {
  ------------------
  |  Branch (182:24): [True: 13.9k, False: 4.66k]
  ------------------
  183|  13.9k|      if (basic_buffer[i] > 0x3c00000) {
  ------------------
  |  Branch (183:11): [True: 3.01k, False: 10.9k]
  ------------------
  184|  3.01k|        utf16_output[0] = uint16_t(surrogate_buffer[i] & 0xffff);
  185|  3.01k|        utf16_output[1] = uint16_t(surrogate_buffer[i] >> 16);
  186|  3.01k|        utf16_output += 2;
  187|  10.9k|      } else {
  188|  10.9k|        utf16_output[0] = big_endian ? uint16_t(basic_buffer_swap[i])
  ------------------
  |  Branch (188:27): [True: 10.9k, Folded]
  ------------------
  189|  10.9k|                                     : uint16_t(basic_buffer[i]);
  190|  10.9k|        utf16_output++;
  191|  10.9k|      }
  192|  13.9k|    }
  193|  4.66k|  } else {
  194|       |    // here we know that there is an error but we do not handle errors
  195|    289|  }
  196|  15.1k|  return consumed;
  197|  21.1k|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_128convert_masked_utf8_to_utf32EPKcmRPDi:
    9|  14.3k|                                    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.3k|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   22|  14.3k|  const uint16_t input_utf8_end_of_code_point_mask =
   23|  14.3k|      utf8_end_of_code_point_mask & 0xfff;
   24|  14.3k|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (24:7): [True: 85, False: 14.2k]
  ------------------
   25|       |    // We process the data in chunks of 12 bytes.
   26|     85|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output),
   27|     85|                     _mm_cvtepu8_epi32(in));
   28|     85|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 4),
   29|     85|                     _mm_cvtepu8_epi32(_mm_srli_si128(in, 4)));
   30|     85|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 8),
   31|     85|                     _mm_cvtepu8_epi32(_mm_srli_si128(in, 8)));
   32|     85|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 12),
   33|     85|                     _mm_cvtepu8_epi32(_mm_srli_si128(in, 12)));
   34|     85|    utf32_output += 12; // We wrote 12 32-bit characters.
   35|     85|    return 12;          // We consumed 12 bytes.
   36|     85|  }
   37|  14.2k|  if (((utf8_end_of_code_point_mask & 0xffff) == 0xaaaa)) {
  ------------------
  |  Branch (37:7): [True: 117, False: 14.1k]
  ------------------
   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|    117|    const __m128i sh =
   42|    117|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   43|    117|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   44|    117|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   45|    117|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   46|    117|    const __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   47|    117|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output),
   48|    117|                     _mm_cvtepu16_epi32(composed));
   49|    117|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 4),
   50|    117|                     _mm_cvtepu16_epi32(_mm_srli_si128(composed, 8)));
   51|    117|    utf32_output += 8; // We wrote 32 bytes, 8 code points.
   52|    117|    return 16;
   53|    117|  }
   54|  14.1k|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (54:7): [True: 272, False: 13.8k]
  ------------------
   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|    272|    const __m128i sh =
   59|    272|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   60|    272|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   61|    272|    const __m128i ascii =
   62|    272|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   63|    272|    const __m128i middlebyte =
   64|    272|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   65|    272|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   66|    272|    const __m128i highbyte =
   67|    272|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   68|    272|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   69|    272|    const __m128i composed =
   70|    272|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   71|    272|    _mm_storeu_si128((__m128i *)utf32_output, composed);
   72|    272|    utf32_output += 4;
   73|    272|    return 12;
   74|    272|  }
   75|       |  /// We do not have a fast path available, so we fallback.
   76|       |
   77|  13.8k|  const uint8_t idx =
   78|  13.8k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   79|  13.8k|  const uint8_t consumed =
   80|  13.8k|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   81|  13.8k|  if (idx < 64) {
  ------------------
  |  Branch (81:7): [True: 7.91k, False: 5.94k]
  ------------------
   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|  7.91k|    const __m128i sh =
   89|  7.91k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   90|  7.91k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   91|  7.91k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   92|  7.91k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   93|  7.91k|    const __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   94|  7.91k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output),
   95|  7.91k|                     _mm_cvtepu16_epi32(composed));
   96|  7.91k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 4),
   97|  7.91k|                     _mm_cvtepu16_epi32(_mm_srli_si128(composed, 8)));
   98|  7.91k|    utf32_output += 6; // We wrote 12 bytes, 6 code points.
   99|  7.91k|  } else if (idx < 145) {
  ------------------
  |  Branch (99:14): [True: 1.43k, False: 4.50k]
  ------------------
  100|       |    // FOUR (4) input code-code units
  101|  1.43k|    const __m128i sh =
  102|  1.43k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  103|  1.43k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  104|  1.43k|    const __m128i ascii =
  105|  1.43k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
  106|  1.43k|    const __m128i middlebyte =
  107|  1.43k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  108|  1.43k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  109|  1.43k|    const __m128i highbyte =
  110|  1.43k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  111|  1.43k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  112|  1.43k|    const __m128i composed =
  113|  1.43k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  114|  1.43k|    _mm_storeu_si128((__m128i *)utf32_output, composed);
  115|  1.43k|    utf32_output += 4;
  116|  4.50k|  } else if (idx < 209) {
  ------------------
  |  Branch (116:14): [True: 4.22k, False: 289]
  ------------------
  117|       |    // TWO (2) input code-code units
  118|  4.22k|    const __m128i sh =
  119|  4.22k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  120|  4.22k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  121|  4.22k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  122|  4.22k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  123|  4.22k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  124|  4.22k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  125|       |    // correct for spurious high bit
  126|  4.22k|    const __m128i correct =
  127|  4.22k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  128|  4.22k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  129|  4.22k|    const __m128i middlehighbyte_shifted = _mm_srli_epi32(middlehighbyte, 4);
  130|  4.22k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0x07000000));
  131|  4.22k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 6);
  132|  4.22k|    const __m128i composed =
  133|  4.22k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  134|  4.22k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  135|  4.22k|    _mm_storeu_si128((__m128i *)utf32_output, composed);
  136|  4.22k|    utf32_output += 3;
  137|  4.22k|  } else {
  138|       |    // here we know that there is an error but we do not handle errors
  139|    289|  }
  140|  13.8k|  return consumed;
  141|  14.1k|}

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

