_Z18populate_functionsv:
  548|      1|const auto populate_functions() {
  549|      1|  using I = simdutf::implementation;
  550|      1|  using FuzzSignature = void (*)(std::span<const char>);
  551|       |
  552|      1|#define ADD(lenfunc, conversionfunc)                                           \
  553|      1|  FuzzSignature {                                                              \
  554|      1|    +[](std::span<const char> chardata) {                                      \
  555|      1|      const auto c =                                                           \
  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  562|      1|      c.fuzz(chardata);                                                        \
  563|      1|    }                                                                          \
  564|      1|  }
  565|       |
  566|      1|  return std::array{
  567|       |      // all these cases require valid input for invoking the convert function
  568|       |
  569|       |      // see #493
  570|       |      // IGNORE(latin1_length_from_utf16, convert_valid_utf16be_to_latin1),
  571|      1|      ADD(utf32_length_from_utf16be, convert_valid_utf16be_to_utf32),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  572|      1|      ADD(utf8_length_from_utf16be, convert_valid_utf16be_to_utf8),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  573|       |
  574|       |      //  see #493
  575|       |      // IGNORE(latin1_length_from_utf16, convert_valid_utf16le_to_latin1),
  576|      1|      ADD(utf32_length_from_utf16le, convert_valid_utf16le_to_utf32),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  577|      1|      ADD(utf8_length_from_utf16le, convert_valid_utf16le_to_utf8),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  578|       |
  579|       |      // see #493
  580|       |      // IGNORE(latin1_length_from_utf32, convert_valid_utf32_to_latin1),
  581|      1|      ADD(utf16_length_from_utf32, convert_valid_utf32_to_utf16be),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  582|      1|      ADD(utf16_length_from_utf32, convert_valid_utf32_to_utf16le),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  583|      1|      ADD(utf8_length_from_utf32, convert_valid_utf32_to_utf8),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  584|       |
  585|       |      // see #493
  586|       |      // IGNORE(latin1_length_from_utf8, convert_valid_utf8_to_latin1),
  587|      1|      ADD(utf16_length_from_utf8, convert_valid_utf8_to_utf16be),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  588|      1|      ADD(utf16_length_from_utf8, convert_valid_utf8_to_utf16le),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  589|      1|      ADD(utf32_length_from_utf8, convert_valid_utf8_to_utf32),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  590|       |
  591|       |      // all these cases operate on arbitrary data
  592|      1|      ADD(latin1_length_from_utf16, convert_utf16be_to_latin1),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  593|      1|      ADD(utf32_length_from_utf16be, convert_utf16be_to_utf32),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  594|      1|      ADD(utf8_length_from_utf16be, convert_utf16be_to_utf8),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  595|       |
  596|      1|      ADD(latin1_length_from_utf16, convert_utf16le_to_latin1),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  597|      1|      ADD(utf32_length_from_utf16le, convert_utf16le_to_utf32),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  598|      1|      ADD(utf8_length_from_utf16le, convert_utf16le_to_utf8),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  599|       |
  600|      1|      ADD(latin1_length_from_utf32, convert_utf32_to_latin1),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  601|      1|      ADD(utf16_length_from_utf32, convert_utf32_to_utf16be),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  602|      1|      ADD(utf16_length_from_utf32, convert_utf32_to_utf16le),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  603|      1|      ADD(utf8_length_from_utf32, convert_utf32_to_utf8),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  604|       |
  605|      1|      ADD(latin1_length_from_utf8, convert_utf8_to_latin1),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  606|      1|      ADD(utf16_length_from_utf8, convert_utf8_to_utf16be),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  607|      1|      ADD(utf16_length_from_utf8, convert_utf8_to_utf16le),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  608|      1|      ADD(utf32_length_from_utf8, convert_utf8_to_utf32),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  609|       |
  610|       |      // all these cases operate on arbitrary data and use the _with_errors
  611|       |      // variant
  612|      1|      ADD(latin1_length_from_utf16, convert_utf16be_to_latin1_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  613|      1|      ADD(utf32_length_from_utf16be, convert_utf16be_to_utf32_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  614|      1|      ADD(utf8_length_from_utf16be, convert_utf16be_to_utf8_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  615|       |
  616|      1|      ADD(latin1_length_from_utf16, convert_utf16le_to_latin1_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  617|      1|      ADD(utf32_length_from_utf16le, convert_utf16le_to_utf32_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  618|      1|      ADD(utf8_length_from_utf16le, convert_utf16le_to_utf8_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  619|       |
  620|      1|      ADD(latin1_length_from_utf32, convert_utf32_to_latin1_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  621|      1|      ADD(utf16_length_from_utf32, convert_utf32_to_utf16be_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  622|      1|      ADD(utf16_length_from_utf32, convert_utf32_to_utf16le_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  623|      1|      ADD(utf8_length_from_utf32, convert_utf32_to_utf8_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  624|       |
  625|      1|      ADD(latin1_length_from_utf8, convert_utf8_to_latin1_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  626|      1|      ADD(utf16_length_from_utf8, convert_utf8_to_utf16be_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  627|      1|      ADD(utf16_length_from_utf8, convert_utf8_to_utf16le_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  628|      1|      ADD(utf32_length_from_utf8, convert_utf8_to_utf32_with_errors),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  629|       |
  630|       |      // these are a bit special since all input is valid
  631|      1|      ADD(utf32_length_from_latin1, convert_latin1_to_utf32),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  632|      1|      ADD(utf16_length_from_latin1, convert_latin1_to_utf16be),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  633|      1|      ADD(utf16_length_from_latin1, convert_latin1_to_utf16le),
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  634|      1|      ADD(utf8_length_from_latin1, convert_latin1_to_utf8)};
  ------------------
  |  |  553|      1|  FuzzSignature {                                                              \
  |  |  554|      1|    +[](std::span<const char> chardata) {                                      \
  |  |  555|      1|      const auto c =                                                           \
  |  |  556|      1|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  |  |  557|      1|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  |  |  558|      1|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  |  |  559|      1|              &I::lenfunc, &I::conversionfunc,                                 \
  |  |  560|      1|              std::string{NAMEOF(&I::lenfunc)},                                \
  |  |  561|      1|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  |  |  562|      1|      c.fuzz(chardata);                                                        \
  |  |  563|      1|    }                                                                          \
  |  |  564|      1|  }
  ------------------
  635|       |
  636|      1|#undef ADD
  637|      1|}
LLVMFuzzerTestOneInput:
  639|  9.95k|extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  640|  9.95k|  static const auto fptrs = populate_functions();
  641|  9.95k|  constexpr std::size_t Ncases = fptrs.size();
  642|       |
  643|       |  // pick one of the function pointers, based on the fuzz data
  644|       |  // the first byte is which action to take. step forward
  645|       |  // several bytes so the input is aligned.
  646|  9.95k|  if (size < 4) {
  ------------------
  |  Branch (646:7): [True: 3, False: 9.94k]
  ------------------
  647|      3|    return 0;
  648|      3|  }
  649|       |
  650|  9.94k|  constexpr auto actionmask = std::bit_ceil(Ncases) - 1;
  651|  9.94k|  const auto action = data[0] & actionmask;
  652|  9.94k|  data += 4;
  653|  9.94k|  size -= 4;
  654|       |
  655|  9.94k|  if (action >= Ncases) {
  ------------------
  |  Branch (655:7): [True: 1, False: 9.94k]
  ------------------
  656|      1|    return 0;
  657|      1|  }
  658|       |
  659|  9.94k|  if constexpr (use_separate_allocation) {
  660|       |    // this is better at exercising null input and catch buffer underflows
  661|  9.94k|    const std::vector<char> separate{data, data + size};
  662|  9.94k|    fptrs[action](std::span(separate));
  663|       |  } else {
  664|       |    std::span<const char> chardata{(const char*)data, size};
  665|       |    fptrs[action](chardata);
  666|       |  }
  667|       |
  668|  9.94k|  return 0;
  669|  9.94k|}
conversion.cpp:_ZZ18populate_functionsvENK3$_0clENSt3__14spanIKcLm18446744073709551615EEE:
  554|     86|    +[](std::span<const char> chardata) {                                      \
  555|     86|      const auto c =                                                           \
  556|     86|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|     86|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|     86|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|     86|              &I::lenfunc, &I::conversionfunc,                                 \
  560|     86|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|     86|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     86|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     86|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     86|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     86|  constexpr auto _size = _name.size();                                \
  |  | 1183|     86|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     86|  return _nameof; }()
  ------------------
  561|     86|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|     86|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     86|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     86|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     86|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     86|  constexpr auto _size = _name.size();                                \
  |  | 1183|     86|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     86|  return _nameof; }()
  ------------------
  562|     86|      c.fuzz(chardata);                                                        \
  563|     86|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    237|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    237|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    237|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    237|    static const bool do_print_testcase =
  181|    237|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    237|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 237]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    237|    do {
  189|       |      // step 0 - is the input valid?
  190|    237|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    237|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 237]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    237|                    From == UtfEncodings::UTF8) {
  198|    237|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 237]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    237|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    237|      const auto [output_length, length_agree] =
  204|    237|          calculate_length(from, inputisvalid);
  205|    237|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 237]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    237|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 118, False: 119]
  |  Branch (208:28): [True: 19, False: 99]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|     19|        return;
  211|     19|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    218|      const auto [written, outputs_agree] =
  215|    218|          do_conversion(from, output_length, inputisvalid);
  216|    218|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 218]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    218|      return;
  221|    218|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    237|  }
_ZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    237|  validation_result verify_valid_input(FromSpan src) const {
  231|    237|    validation_result ret{};
  232|       |
  233|    237|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    237|    const auto implementations = get_supported_implementations();
  235|    237|    std::vector<simdutf::result> results;
  236|    237|    results.reserve(implementations.size());
  237|       |
  238|    711|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 711, False: 237]
  ------------------
  239|    711|      results.push_back(
  240|    711|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|    711|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|    711|      const bool validation2 =
  245|    711|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|    711|                      src.data(), src.size());
  247|    711|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 711]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|    711|    }
  258|       |
  259|    237|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    237|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 237]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    237|    } else {
  273|    237|      ret.implementations_agree = true;
  274|    237|    }
  275|    237|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    237|      return r.error == simdutf::SUCCESS;
  277|    237|    });
  278|    237|    return ret;
  279|    237|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|    474|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|    475|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    475|      return r.error == simdutf::SUCCESS;
  277|    475|    });
_ZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    237|  bool count_the_input(FromSpan src) const {
  290|    237|    const auto implementations = get_supported_implementations();
  291|    237|    std::vector<std::size_t> results;
  292|    237|    results.reserve(implementations.size());
  293|       |
  294|    711|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 711, False: 237]
  ------------------
  295|    711|      std::size_t ret;
  296|    711|      if constexpr (From == UtfEncodings::UTF16BE) {
  297|    711|        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|       |      } else if constexpr (From == UtfEncodings::UTF8) {
  301|       |        ret = impl->count_utf8(src.data(), src.size());
  302|       |      }
  303|    711|      results.push_back(ret);
  304|    711|    }
  305|    237|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    237|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 237]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    237|    return true;
  321|    237|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  305|    474|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    237|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    237|    length_result ret{};
  344|       |
  345|    237|    const auto implementations = get_supported_implementations();
  346|    237|    std::vector<std::size_t> results;
  347|    237|    results.reserve(implementations.size());
  348|       |
  349|    711|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 711, False: 237]
  ------------------
  350|    711|      const auto len = invoke_lengthcalc(impl, src);
  351|    711|      results.push_back(len);
  352|    711|      ret.length.push_back(len);
  353|    711|    }
  354|       |
  355|    237|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    237|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 237]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    237|    } else {
  375|    237|      ret.implementations_agree = true;
  376|    237|    }
  377|    237|    return ret;
  378|    237|  }
_ZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSE_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|    711|                                FromSpan src) const {
  331|    711|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|    711|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    474|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|    218|                                  const bool inputisvalid) const {
  383|    218|    conversion_result ret{};
  384|       |
  385|    218|    const auto implementations = get_supported_implementations();
  386|       |
  387|    218|    std::vector<result<ConversionResult>> results;
  388|    218|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    218|    std::vector<std::vector<ToType>> outputbuffers;
  393|    218|    outputbuffers.reserve(implementations.size());
  394|    872|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 654, False: 218]
  ------------------
  395|    654|      auto impl = implementations[i];
  396|    654|      const ToType canary1{42};
  397|    654|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    654|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    654|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    654|      const auto success = [](const ConversionResult& r) -> bool {
  402|    654|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    654|          return r != 0;
  404|    654|        } else {
  405|    654|          return r.error == simdutf::error_code::SUCCESS;
  406|    654|        }
  407|    654|      }(implret1);
  408|    654|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    654|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    654|        const ToType canary2{25};
  414|    654|        const auto outputbuffer_first_run = outputbuffer;
  415|    654|        std::ranges::fill(outputbuffer, canary2);
  416|    654|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    654|                                          src.size(), outputbuffer.data());
  418|       |
  419|    654|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 654]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    654|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 357, False: 297]
  |  Branch (423:29): [True: 348, False: 9]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    348|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    348|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 348]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    348|        }
  440|    654|      }
  441|    654|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 348, False: 306]
  ------------------
  442|    654|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    218|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 99, False: 119]
  ------------------
  447|    297|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 297, False: 99]
  ------------------
  448|    297|        e.outputhash.clear();
  449|    297|      }
  450|     99|    }
  451|       |
  452|    218|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    218|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 218]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    218|    } else {
  474|    218|      ret.implementations_agree = true;
  475|    218|    }
  476|    218|    return ret;
  477|    218|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|    654|      const auto success = [](const ConversionResult& r) -> bool {
  402|    654|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    654|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|    654|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    436|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK3$_1clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    227|    +[](std::span<const char> chardata) {                                      \
  555|    227|      const auto c =                                                           \
  556|    227|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    227|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    227|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    227|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    227|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    227|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    227|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    227|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    227|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    227|  constexpr auto _size = _name.size();                                \
  |  | 1183|    227|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    227|  return _nameof; }()
  ------------------
  561|    227|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    227|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    227|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    227|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    227|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    227|  constexpr auto _size = _name.size();                                \
  |  | 1183|    227|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    227|  return _nameof; }()
  ------------------
  562|    227|      c.fuzz(chardata);                                                        \
  563|    227|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    424|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    424|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    424|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    424|    static const bool do_print_testcase =
  181|    424|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    424|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 424]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    424|    do {
  189|       |      // step 0 - is the input valid?
  190|    424|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    424|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 424]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    424|                    From == UtfEncodings::UTF8) {
  198|    424|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 424]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    424|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    424|      const auto [output_length, length_agree] =
  204|    424|          calculate_length(from, inputisvalid);
  205|    424|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 424]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    424|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 113, False: 311]
  |  Branch (208:28): [True: 19, False: 94]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|     19|        return;
  211|     19|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    405|      const auto [written, outputs_agree] =
  215|    405|          do_conversion(from, output_length, inputisvalid);
  216|    405|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 405]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    405|      return;
  221|    405|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    424|  }
_ZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    424|  validation_result verify_valid_input(FromSpan src) const {
  231|    424|    validation_result ret{};
  232|       |
  233|    424|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    424|    const auto implementations = get_supported_implementations();
  235|    424|    std::vector<simdutf::result> results;
  236|    424|    results.reserve(implementations.size());
  237|       |
  238|  1.27k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.27k, False: 424]
  ------------------
  239|  1.27k|      results.push_back(
  240|  1.27k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.27k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.27k|      const bool validation2 =
  245|  1.27k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.27k|                      src.data(), src.size());
  247|  1.27k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.27k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.27k|    }
  258|       |
  259|    424|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    424|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 424]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    424|    } else {
  273|    424|      ret.implementations_agree = true;
  274|    424|    }
  275|    424|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    424|      return r.error == simdutf::SUCCESS;
  277|    424|    });
  278|    424|    return ret;
  279|    424|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|    848|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|  1.04k|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|  1.04k|      return r.error == simdutf::SUCCESS;
  277|  1.04k|    });
_ZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    424|  bool count_the_input(FromSpan src) const {
  290|    424|    const auto implementations = get_supported_implementations();
  291|    424|    std::vector<std::size_t> results;
  292|    424|    results.reserve(implementations.size());
  293|       |
  294|  1.27k|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 1.27k, False: 424]
  ------------------
  295|  1.27k|      std::size_t ret;
  296|  1.27k|      if constexpr (From == UtfEncodings::UTF16BE) {
  297|  1.27k|        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|       |      } else if constexpr (From == UtfEncodings::UTF8) {
  301|       |        ret = impl->count_utf8(src.data(), src.size());
  302|       |      }
  303|  1.27k|      results.push_back(ret);
  304|  1.27k|    }
  305|    424|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    424|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 424]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    424|    return true;
  321|    424|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  305|    848|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    424|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    424|    length_result ret{};
  344|       |
  345|    424|    const auto implementations = get_supported_implementations();
  346|    424|    std::vector<std::size_t> results;
  347|    424|    results.reserve(implementations.size());
  348|       |
  349|  1.27k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.27k, False: 424]
  ------------------
  350|  1.27k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.27k|      results.push_back(len);
  352|  1.27k|      ret.length.push_back(len);
  353|  1.27k|    }
  354|       |
  355|    424|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    424|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 424]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    424|    } else {
  375|    424|      ret.implementations_agree = true;
  376|    424|    }
  377|    424|    return ret;
  378|    424|  }
_ZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSE_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.27k|                                FromSpan src) const {
  331|  1.27k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.27k|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    848|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|    405|                                  const bool inputisvalid) const {
  383|    405|    conversion_result ret{};
  384|       |
  385|    405|    const auto implementations = get_supported_implementations();
  386|       |
  387|    405|    std::vector<result<ConversionResult>> results;
  388|    405|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    405|    std::vector<std::vector<ToType>> outputbuffers;
  393|    405|    outputbuffers.reserve(implementations.size());
  394|  1.62k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.21k, False: 405]
  ------------------
  395|  1.21k|      auto impl = implementations[i];
  396|  1.21k|      const ToType canary1{42};
  397|  1.21k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.21k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.21k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.21k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.21k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.21k|          return r != 0;
  404|  1.21k|        } else {
  405|  1.21k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.21k|        }
  407|  1.21k|      }(implret1);
  408|  1.21k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.21k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.21k|        const ToType canary2{25};
  414|  1.21k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.21k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.21k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.21k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.21k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.21k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.21k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 933, False: 282]
  |  Branch (423:29): [True: 921, False: 12]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    921|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    921|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 921]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    921|        }
  440|  1.21k|      }
  441|  1.21k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 921, False: 294]
  ------------------
  442|  1.21k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    405|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 94, False: 311]
  ------------------
  447|    282|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 282, False: 94]
  ------------------
  448|    282|        e.outputhash.clear();
  449|    282|      }
  450|     94|    }
  451|       |
  452|    405|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    405|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 405]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    405|    } else {
  474|    405|      ret.implementations_agree = true;
  475|    405|    }
  476|    405|    return ret;
  477|    405|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|  1.21k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.21k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.21k|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|  1.21k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    810|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK3$_2clENSt3__14spanIKcLm18446744073709551615EEE:
  554|     66|    +[](std::span<const char> chardata) {                                      \
  555|     66|      const auto c =                                                           \
  556|     66|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|     66|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|     66|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|     66|              &I::lenfunc, &I::conversionfunc,                                 \
  560|     66|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|     66|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     66|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     66|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     66|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     66|  constexpr auto _size = _name.size();                                \
  |  | 1183|     66|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     66|  return _nameof; }()
  ------------------
  561|     66|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|     66|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     66|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     66|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     66|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     66|  constexpr auto _size = _name.size();                                \
  |  | 1183|     66|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     66|  return _nameof; }()
  ------------------
  562|     66|      c.fuzz(chardata);                                                        \
  563|     66|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    220|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    220|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    220|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    220|    static const bool do_print_testcase =
  181|    220|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    220|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 220]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    220|    do {
  189|       |      // step 0 - is the input valid?
  190|    220|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    220|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 220]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    220|                    From == UtfEncodings::UTF8) {
  198|    220|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 220]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    220|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    220|      const auto [output_length, length_agree] =
  204|    220|          calculate_length(from, inputisvalid);
  205|    220|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 220]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    220|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 98, False: 122]
  |  Branch (208:28): [True: 7, False: 91]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      7|        return;
  211|      7|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    213|      const auto [written, outputs_agree] =
  215|    213|          do_conversion(from, output_length, inputisvalid);
  216|    213|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 213]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    213|      return;
  221|    213|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    220|  }
_ZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    220|  validation_result verify_valid_input(FromSpan src) const {
  231|    220|    validation_result ret{};
  232|       |
  233|    220|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    220|    const auto implementations = get_supported_implementations();
  235|    220|    std::vector<simdutf::result> results;
  236|    220|    results.reserve(implementations.size());
  237|       |
  238|    660|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 660, False: 220]
  ------------------
  239|    660|      results.push_back(
  240|    660|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|    660|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|    660|      const bool validation2 =
  245|    660|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|    660|                      src.data(), src.size());
  247|    660|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 660]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|    660|    }
  258|       |
  259|    220|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    220|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 220]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    220|    } else {
  273|    220|      ret.implementations_agree = true;
  274|    220|    }
  275|    220|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    220|      return r.error == simdutf::SUCCESS;
  277|    220|    });
  278|    220|    return ret;
  279|    220|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|    440|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|    464|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    464|      return r.error == simdutf::SUCCESS;
  277|    464|    });
_ZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    220|  bool count_the_input(FromSpan src) const {
  290|    220|    const auto implementations = get_supported_implementations();
  291|    220|    std::vector<std::size_t> results;
  292|    220|    results.reserve(implementations.size());
  293|       |
  294|    660|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 660, False: 220]
  ------------------
  295|    660|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|    660|      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|    660|        ret = impl->count_utf16le(src.data(), src.size());
  300|       |      } else if constexpr (From == UtfEncodings::UTF8) {
  301|       |        ret = impl->count_utf8(src.data(), src.size());
  302|       |      }
  303|    660|      results.push_back(ret);
  304|    660|    }
  305|    220|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    220|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 220]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    220|    return true;
  321|    220|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  305|    440|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    220|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    220|    length_result ret{};
  344|       |
  345|    220|    const auto implementations = get_supported_implementations();
  346|    220|    std::vector<std::size_t> results;
  347|    220|    results.reserve(implementations.size());
  348|       |
  349|    660|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 660, False: 220]
  ------------------
  350|    660|      const auto len = invoke_lengthcalc(impl, src);
  351|    660|      results.push_back(len);
  352|    660|      ret.length.push_back(len);
  353|    660|    }
  354|       |
  355|    220|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    220|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 220]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    220|    } else {
  375|    220|      ret.implementations_agree = true;
  376|    220|    }
  377|    220|    return ret;
  378|    220|  }
_ZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSE_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|    660|                                FromSpan src) const {
  331|    660|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|    660|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    440|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|    213|                                  const bool inputisvalid) const {
  383|    213|    conversion_result ret{};
  384|       |
  385|    213|    const auto implementations = get_supported_implementations();
  386|       |
  387|    213|    std::vector<result<ConversionResult>> results;
  388|    213|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    213|    std::vector<std::vector<ToType>> outputbuffers;
  393|    213|    outputbuffers.reserve(implementations.size());
  394|    852|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 639, False: 213]
  ------------------
  395|    639|      auto impl = implementations[i];
  396|    639|      const ToType canary1{42};
  397|    639|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    639|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    639|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    639|      const auto success = [](const ConversionResult& r) -> bool {
  402|    639|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    639|          return r != 0;
  404|    639|        } else {
  405|    639|          return r.error == simdutf::error_code::SUCCESS;
  406|    639|        }
  407|    639|      }(implret1);
  408|    639|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    639|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    639|        const ToType canary2{25};
  414|    639|        const auto outputbuffer_first_run = outputbuffer;
  415|    639|        std::ranges::fill(outputbuffer, canary2);
  416|    639|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    639|                                          src.size(), outputbuffer.data());
  418|       |
  419|    639|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 639]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    639|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 366, False: 273]
  |  Branch (423:29): [True: 354, False: 12]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    354|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    354|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 354]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    354|        }
  440|    639|      }
  441|    639|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 354, False: 285]
  ------------------
  442|    639|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    213|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 91, False: 122]
  ------------------
  447|    273|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 273, False: 91]
  ------------------
  448|    273|        e.outputhash.clear();
  449|    273|      }
  450|     91|    }
  451|       |
  452|    213|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    213|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 213]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    213|    } else {
  474|    213|      ret.implementations_agree = true;
  475|    213|    }
  476|    213|    return ret;
  477|    213|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|    639|      const auto success = [](const ConversionResult& r) -> bool {
  402|    639|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    639|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|    639|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    426|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK3$_3clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    199|    +[](std::span<const char> chardata) {                                      \
  555|    199|      const auto c =                                                           \
  556|    199|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    199|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    199|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    199|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    199|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    199|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    199|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    199|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    199|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    199|  constexpr auto _size = _name.size();                                \
  |  | 1183|    199|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    199|  return _nameof; }()
  ------------------
  561|    199|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    199|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    199|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    199|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    199|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    199|  constexpr auto _size = _name.size();                                \
  |  | 1183|    199|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    199|  return _nameof; }()
  ------------------
  562|    199|      c.fuzz(chardata);                                                        \
  563|    199|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    452|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    452|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    452|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    452|    static const bool do_print_testcase =
  181|    452|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    452|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 452]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    452|    do {
  189|       |      // step 0 - is the input valid?
  190|    452|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    452|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 452]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    452|                    From == UtfEncodings::UTF8) {
  198|    452|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 452]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    452|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    452|      const auto [output_length, length_agree] =
  204|    452|          calculate_length(from, inputisvalid);
  205|    452|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 452]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    452|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 126, False: 326]
  |  Branch (208:28): [True: 13, False: 113]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|     13|        return;
  211|     13|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    439|      const auto [written, outputs_agree] =
  215|    439|          do_conversion(from, output_length, inputisvalid);
  216|    439|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 439]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    439|      return;
  221|    439|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    452|  }
_ZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    452|  validation_result verify_valid_input(FromSpan src) const {
  231|    452|    validation_result ret{};
  232|       |
  233|    452|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    452|    const auto implementations = get_supported_implementations();
  235|    452|    std::vector<simdutf::result> results;
  236|    452|    results.reserve(implementations.size());
  237|       |
  238|  1.35k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.35k, False: 452]
  ------------------
  239|  1.35k|      results.push_back(
  240|  1.35k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.35k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.35k|      const bool validation2 =
  245|  1.35k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.35k|                      src.data(), src.size());
  247|  1.35k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.35k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.35k|    }
  258|       |
  259|    452|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    452|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 452]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    452|    } else {
  273|    452|      ret.implementations_agree = true;
  274|    452|    }
  275|    452|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    452|      return r.error == simdutf::SUCCESS;
  277|    452|    });
  278|    452|    return ret;
  279|    452|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|    904|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|  1.10k|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|  1.10k|      return r.error == simdutf::SUCCESS;
  277|  1.10k|    });
_ZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    452|  bool count_the_input(FromSpan src) const {
  290|    452|    const auto implementations = get_supported_implementations();
  291|    452|    std::vector<std::size_t> results;
  292|    452|    results.reserve(implementations.size());
  293|       |
  294|  1.35k|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 1.35k, False: 452]
  ------------------
  295|  1.35k|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|  1.35k|      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|  1.35k|        ret = impl->count_utf16le(src.data(), src.size());
  300|       |      } else if constexpr (From == UtfEncodings::UTF8) {
  301|       |        ret = impl->count_utf8(src.data(), src.size());
  302|       |      }
  303|  1.35k|      results.push_back(ret);
  304|  1.35k|    }
  305|    452|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    452|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 452]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    452|    return true;
  321|    452|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  305|    904|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    452|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    452|    length_result ret{};
  344|       |
  345|    452|    const auto implementations = get_supported_implementations();
  346|    452|    std::vector<std::size_t> results;
  347|    452|    results.reserve(implementations.size());
  348|       |
  349|  1.35k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.35k, False: 452]
  ------------------
  350|  1.35k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.35k|      results.push_back(len);
  352|  1.35k|      ret.length.push_back(len);
  353|  1.35k|    }
  354|       |
  355|    452|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    452|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 452]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    452|    } else {
  375|    452|      ret.implementations_agree = true;
  376|    452|    }
  377|    452|    return ret;
  378|    452|  }
_ZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSE_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.35k|                                FromSpan src) const {
  331|  1.35k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.35k|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    904|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|    439|                                  const bool inputisvalid) const {
  383|    439|    conversion_result ret{};
  384|       |
  385|    439|    const auto implementations = get_supported_implementations();
  386|       |
  387|    439|    std::vector<result<ConversionResult>> results;
  388|    439|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    439|    std::vector<std::vector<ToType>> outputbuffers;
  393|    439|    outputbuffers.reserve(implementations.size());
  394|  1.75k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.31k, False: 439]
  ------------------
  395|  1.31k|      auto impl = implementations[i];
  396|  1.31k|      const ToType canary1{42};
  397|  1.31k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.31k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.31k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.31k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.31k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.31k|          return r != 0;
  404|  1.31k|        } else {
  405|  1.31k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.31k|        }
  407|  1.31k|      }(implret1);
  408|  1.31k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.31k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.31k|        const ToType canary2{25};
  414|  1.31k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.31k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.31k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.31k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.31k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.31k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.31k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 978, False: 339]
  |  Branch (423:29): [True: 966, False: 12]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    966|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    966|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 966]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    966|        }
  440|  1.31k|      }
  441|  1.31k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 966, False: 351]
  ------------------
  442|  1.31k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    439|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 113, False: 326]
  ------------------
  447|    339|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 339, False: 113]
  ------------------
  448|    339|        e.outputhash.clear();
  449|    339|      }
  450|    113|    }
  451|       |
  452|    439|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    439|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 439]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    439|    } else {
  474|    439|      ret.implementations_agree = true;
  475|    439|    }
  476|    439|    return ret;
  477|    439|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|  1.31k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.31k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.31k|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|  1.31k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    878|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK3$_4clENSt3__14spanIKcLm18446744073709551615EEE:
  554|     73|    +[](std::span<const char> chardata) {                                      \
  555|     73|      const auto c =                                                           \
  556|     73|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|     73|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|     73|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|     73|              &I::lenfunc, &I::conversionfunc,                                 \
  560|     73|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|     73|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     73|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     73|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     73|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     73|  constexpr auto _size = _name.size();                                \
  |  | 1183|     73|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     73|  return _nameof; }()
  ------------------
  561|     73|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|     73|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     73|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     73|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     73|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     73|  constexpr auto _size = _name.size();                                \
  |  | 1183|     73|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     73|  return _nameof; }()
  ------------------
  562|     73|      c.fuzz(chardata);                                                        \
  563|     73|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    331|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    331|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    331|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    331|    static const bool do_print_testcase =
  181|    331|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    331|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 331]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    331|    do {
  189|       |      // step 0 - is the input valid?
  190|    331|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    331|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 331]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|       |                    From == UtfEncodings::UTF8) {
  198|       |        if (!count_the_input(from) && !allow_implementations_to_differ)
  199|       |          break;
  200|       |      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    331|      const auto [output_length, length_agree] =
  204|    331|          calculate_length(from, inputisvalid);
  205|    331|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 331]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    331|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 190, False: 141]
  |  Branch (208:28): [True: 5, False: 185]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      5|        return;
  211|      5|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    326|      const auto [written, outputs_agree] =
  215|    326|          do_conversion(from, output_length, inputisvalid);
  216|    326|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 326]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    326|      return;
  221|    326|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    331|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    331|  validation_result verify_valid_input(FromSpan src) const {
  231|    331|    validation_result ret{};
  232|       |
  233|    331|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    331|    const auto implementations = get_supported_implementations();
  235|    331|    std::vector<simdutf::result> results;
  236|    331|    results.reserve(implementations.size());
  237|       |
  238|    993|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 993, False: 331]
  ------------------
  239|    993|      results.push_back(
  240|    993|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|    993|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|    993|      const bool validation2 =
  245|    993|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|    993|                      src.data(), src.size());
  247|    993|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 993]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|    993|    }
  258|       |
  259|    331|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    331|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 331]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    331|    } else {
  273|    331|      ret.implementations_agree = true;
  274|    331|    }
  275|    331|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    331|      return r.error == simdutf::SUCCESS;
  277|    331|    });
  278|    331|    return ret;
  279|    331|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|    662|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|    613|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    613|      return r.error == simdutf::SUCCESS;
  277|    613|    });
_ZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    331|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    331|    length_result ret{};
  344|       |
  345|    331|    const auto implementations = get_supported_implementations();
  346|    331|    std::vector<std::size_t> results;
  347|    331|    results.reserve(implementations.size());
  348|       |
  349|    993|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 993, False: 331]
  ------------------
  350|    993|      const auto len = invoke_lengthcalc(impl, src);
  351|    993|      results.push_back(len);
  352|    993|      ret.length.push_back(len);
  353|    993|    }
  354|       |
  355|    331|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    331|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 331]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    331|    } else {
  375|    331|      ret.implementations_agree = true;
  376|    331|    }
  377|    331|    return ret;
  378|    331|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSE_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|    993|                                FromSpan src) const {
  331|    993|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|    993|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    662|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|    326|                                  const bool inputisvalid) const {
  383|    326|    conversion_result ret{};
  384|       |
  385|    326|    const auto implementations = get_supported_implementations();
  386|       |
  387|    326|    std::vector<result<ConversionResult>> results;
  388|    326|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    326|    std::vector<std::vector<ToType>> outputbuffers;
  393|    326|    outputbuffers.reserve(implementations.size());
  394|  1.30k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 978, False: 326]
  ------------------
  395|    978|      auto impl = implementations[i];
  396|    978|      const ToType canary1{42};
  397|    978|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    978|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    978|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    978|      const auto success = [](const ConversionResult& r) -> bool {
  402|    978|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    978|          return r != 0;
  404|    978|        } else {
  405|    978|          return r.error == simdutf::error_code::SUCCESS;
  406|    978|        }
  407|    978|      }(implret1);
  408|    978|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    978|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    978|        const ToType canary2{25};
  414|    978|        const auto outputbuffer_first_run = outputbuffer;
  415|    978|        std::ranges::fill(outputbuffer, canary2);
  416|    978|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    978|                                          src.size(), outputbuffer.data());
  418|       |
  419|    978|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 978]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    978|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 423, False: 555]
  |  Branch (423:29): [True: 411, False: 12]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    411|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    411|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 411]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    411|        }
  440|    978|      }
  441|    978|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 411, False: 567]
  ------------------
  442|    978|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    326|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 185, False: 141]
  ------------------
  447|    555|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 555, False: 185]
  ------------------
  448|    555|        e.outputhash.clear();
  449|    555|      }
  450|    185|    }
  451|       |
  452|    326|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    326|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 326]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    326|    } else {
  474|    326|      ret.implementations_agree = true;
  475|    326|    }
  476|    326|    return ret;
  477|    326|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|    978|      const auto success = [](const ConversionResult& r) -> bool {
  402|    978|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    978|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|    978|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    652|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK3$_5clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    150|    +[](std::span<const char> chardata) {                                      \
  555|    150|      const auto c =                                                           \
  556|    150|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    150|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    150|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    150|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    150|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    150|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    150|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    150|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    150|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    150|  constexpr auto _size = _name.size();                                \
  |  | 1183|    150|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    150|  return _nameof; }()
  ------------------
  561|    150|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    150|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    150|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    150|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    150|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    150|  constexpr auto _size = _name.size();                                \
  |  | 1183|    150|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    150|  return _nameof; }()
  ------------------
  562|    150|      c.fuzz(chardata);                                                        \
  563|    150|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    401|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    401|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    401|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    401|    static const bool do_print_testcase =
  181|    401|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    401|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 401]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    401|    do {
  189|       |      // step 0 - is the input valid?
  190|    401|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    401|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 401]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|       |                    From == UtfEncodings::UTF8) {
  198|       |        if (!count_the_input(from) && !allow_implementations_to_differ)
  199|       |          break;
  200|       |      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    401|      const auto [output_length, length_agree] =
  204|    401|          calculate_length(from, inputisvalid);
  205|    401|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 401]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    401|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 187, False: 214]
  |  Branch (208:28): [True: 4, False: 183]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      4|        return;
  211|      4|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    397|      const auto [written, outputs_agree] =
  215|    397|          do_conversion(from, output_length, inputisvalid);
  216|    397|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 397]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    397|      return;
  221|    397|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    401|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    401|  validation_result verify_valid_input(FromSpan src) const {
  231|    401|    validation_result ret{};
  232|       |
  233|    401|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    401|    const auto implementations = get_supported_implementations();
  235|    401|    std::vector<simdutf::result> results;
  236|    401|    results.reserve(implementations.size());
  237|       |
  238|  1.20k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.20k, False: 401]
  ------------------
  239|  1.20k|      results.push_back(
  240|  1.20k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.20k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.20k|      const bool validation2 =
  245|  1.20k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.20k|                      src.data(), src.size());
  247|  1.20k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.20k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.20k|    }
  258|       |
  259|    401|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    401|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 401]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    401|    } else {
  273|    401|      ret.implementations_agree = true;
  274|    401|    }
  275|    401|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    401|      return r.error == simdutf::SUCCESS;
  277|    401|    });
  278|    401|    return ret;
  279|    401|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|    802|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|    829|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    829|      return r.error == simdutf::SUCCESS;
  277|    829|    });
_ZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    401|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    401|    length_result ret{};
  344|       |
  345|    401|    const auto implementations = get_supported_implementations();
  346|    401|    std::vector<std::size_t> results;
  347|    401|    results.reserve(implementations.size());
  348|       |
  349|  1.20k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.20k, False: 401]
  ------------------
  350|  1.20k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.20k|      results.push_back(len);
  352|  1.20k|      ret.length.push_back(len);
  353|  1.20k|    }
  354|       |
  355|    401|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    401|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 401]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    401|    } else {
  375|    401|      ret.implementations_agree = true;
  376|    401|    }
  377|    401|    return ret;
  378|    401|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSE_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.20k|                                FromSpan src) const {
  331|  1.20k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.20k|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    802|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|    397|                                  const bool inputisvalid) const {
  383|    397|    conversion_result ret{};
  384|       |
  385|    397|    const auto implementations = get_supported_implementations();
  386|       |
  387|    397|    std::vector<result<ConversionResult>> results;
  388|    397|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    397|    std::vector<std::vector<ToType>> outputbuffers;
  393|    397|    outputbuffers.reserve(implementations.size());
  394|  1.58k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.19k, False: 397]
  ------------------
  395|  1.19k|      auto impl = implementations[i];
  396|  1.19k|      const ToType canary1{42};
  397|  1.19k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.19k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.19k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.19k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.19k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.19k|          return r != 0;
  404|  1.19k|        } else {
  405|  1.19k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.19k|        }
  407|  1.19k|      }(implret1);
  408|  1.19k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.19k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.19k|        const ToType canary2{25};
  414|  1.19k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.19k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.19k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.19k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.19k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.19k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.19k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 642, False: 549]
  |  Branch (423:29): [True: 627, False: 15]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    627|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    627|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 627]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    627|        }
  440|  1.19k|      }
  441|  1.19k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 627, False: 564]
  ------------------
  442|  1.19k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    397|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 183, False: 214]
  ------------------
  447|    549|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 549, False: 183]
  ------------------
  448|    549|        e.outputhash.clear();
  449|    549|      }
  450|    183|    }
  451|       |
  452|    397|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    397|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 397]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    397|    } else {
  474|    397|      ret.implementations_agree = true;
  475|    397|    }
  476|    397|    return ret;
  477|    397|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|  1.19k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.19k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.19k|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|  1.19k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    794|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK3$_6clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    105|    +[](std::span<const char> chardata) {                                      \
  555|    105|      const auto c =                                                           \
  556|    105|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    105|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    105|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    105|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    105|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    105|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    105|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    105|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    105|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    105|  constexpr auto _size = _name.size();                                \
  |  | 1183|    105|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    105|  return _nameof; }()
  ------------------
  561|    105|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    105|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    105|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    105|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    105|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    105|  constexpr auto _size = _name.size();                                \
  |  | 1183|    105|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    105|  return _nameof; }()
  ------------------
  562|    105|      c.fuzz(chardata);                                                        \
  563|    105|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPcEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    462|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    462|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    462|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    462|    static const bool do_print_testcase =
  181|    462|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    462|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 462]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    462|    do {
  189|       |      // step 0 - is the input valid?
  190|    462|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    462|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 462]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|       |                    From == UtfEncodings::UTF8) {
  198|       |        if (!count_the_input(from) && !allow_implementations_to_differ)
  199|       |          break;
  200|       |      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    462|      const auto [output_length, length_agree] =
  204|    462|          calculate_length(from, inputisvalid);
  205|    462|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 462]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    462|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 296, False: 166]
  |  Branch (208:28): [True: 8, False: 288]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      8|        return;
  211|      8|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    454|      const auto [written, outputs_agree] =
  215|    454|          do_conversion(from, output_length, inputisvalid);
  216|    454|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 454]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    454|      return;
  221|    454|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    462|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    462|  validation_result verify_valid_input(FromSpan src) const {
  231|    462|    validation_result ret{};
  232|       |
  233|    462|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    462|    const auto implementations = get_supported_implementations();
  235|    462|    std::vector<simdutf::result> results;
  236|    462|    results.reserve(implementations.size());
  237|       |
  238|  1.38k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.38k, False: 462]
  ------------------
  239|  1.38k|      results.push_back(
  240|  1.38k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.38k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.38k|      const bool validation2 =
  245|  1.38k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.38k|                      src.data(), src.size());
  247|  1.38k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.38k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.38k|    }
  258|       |
  259|    462|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    462|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 462]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    462|    } else {
  273|    462|      ret.implementations_agree = true;
  274|    462|    }
  275|    462|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    462|      return r.error == simdutf::SUCCESS;
  277|    462|    });
  278|    462|    return ret;
  279|    462|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|    924|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|    794|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    794|      return r.error == simdutf::SUCCESS;
  277|    794|    });
_ZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    462|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    462|    length_result ret{};
  344|       |
  345|    462|    const auto implementations = get_supported_implementations();
  346|    462|    std::vector<std::size_t> results;
  347|    462|    results.reserve(implementations.size());
  348|       |
  349|  1.38k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.38k, False: 462]
  ------------------
  350|  1.38k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.38k|      results.push_back(len);
  352|  1.38k|      ret.length.push_back(len);
  353|  1.38k|    }
  354|       |
  355|    462|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    462|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 462]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    462|    } else {
  375|    462|      ret.implementations_agree = true;
  376|    462|    }
  377|    462|    return ret;
  378|    462|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSE_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.38k|                                FromSpan src) const {
  331|  1.38k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.38k|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    924|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|    454|                                  const bool inputisvalid) const {
  383|    454|    conversion_result ret{};
  384|       |
  385|    454|    const auto implementations = get_supported_implementations();
  386|       |
  387|    454|    std::vector<result<ConversionResult>> results;
  388|    454|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    454|    std::vector<std::vector<ToType>> outputbuffers;
  393|    454|    outputbuffers.reserve(implementations.size());
  394|  1.81k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.36k, False: 454]
  ------------------
  395|  1.36k|      auto impl = implementations[i];
  396|  1.36k|      const ToType canary1{42};
  397|  1.36k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.36k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.36k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.36k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.36k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.36k|          return r != 0;
  404|  1.36k|        } else {
  405|  1.36k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.36k|        }
  407|  1.36k|      }(implret1);
  408|  1.36k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.36k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.36k|        const ToType canary2{25};
  414|  1.36k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.36k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.36k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.36k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.36k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.36k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.36k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 498, False: 864]
  |  Branch (423:29): [True: 486, False: 12]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    486|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    486|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 486]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    486|        }
  440|  1.36k|      }
  441|  1.36k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 486, False: 876]
  ------------------
  442|  1.36k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    454|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 288, False: 166]
  ------------------
  447|    864|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 864, False: 288]
  ------------------
  448|    864|        e.outputhash.clear();
  449|    864|      }
  450|    288|    }
  451|       |
  452|    454|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    454|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 454]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    454|    } else {
  474|    454|      ret.implementations_agree = true;
  475|    454|    }
  476|    454|    return ret;
  477|    454|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|  1.36k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.36k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.36k|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|  1.36k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    908|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK3$_7clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    239|    +[](std::span<const char> chardata) {                                      \
  555|    239|      const auto c =                                                           \
  556|    239|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    239|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    239|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    239|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    239|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    239|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    239|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    239|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    239|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    239|  constexpr auto _size = _name.size();                                \
  |  | 1183|    239|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    239|  return _nameof; }()
  ------------------
  561|    239|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    239|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    239|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    239|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    239|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    239|  constexpr auto _size = _name.size();                                \
  |  | 1183|    239|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    239|  return _nameof; }()
  ------------------
  562|    239|      c.fuzz(chardata);                                                        \
  563|    239|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE4fuzzENSt3__14spanIS3_Lm18446744073709551615EEE:
  175|    726|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    726|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    726|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    726|    static const bool do_print_testcase =
  181|    726|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    726|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 726]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    726|    do {
  189|       |      // step 0 - is the input valid?
  190|    726|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    726|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 726]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    726|                    From == UtfEncodings::UTF8) {
  198|    726|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 726]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    726|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    726|      const auto [output_length, length_agree] =
  204|    726|          calculate_length(from, inputisvalid);
  205|    726|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 726]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    726|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 381, False: 345]
  |  Branch (208:28): [True: 11, False: 370]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|     11|        return;
  211|     11|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    715|      const auto [written, outputs_agree] =
  215|    715|          do_conversion(from, output_length, inputisvalid);
  216|    715|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 715]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    715|      return;
  221|    715|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    726|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    726|  validation_result verify_valid_input(FromSpan src) const {
  231|    726|    validation_result ret{};
  232|       |
  233|    726|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    726|    const auto implementations = get_supported_implementations();
  235|    726|    std::vector<simdutf::result> results;
  236|    726|    results.reserve(implementations.size());
  237|       |
  238|  2.17k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 2.17k, False: 726]
  ------------------
  239|  2.17k|      results.push_back(
  240|  2.17k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  2.17k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  2.17k|      const bool validation2 =
  245|  2.17k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  2.17k|                      src.data(), src.size());
  247|  2.17k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 2.17k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  2.17k|    }
  258|       |
  259|    726|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    726|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 726]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    726|    } else {
  273|    726|      ret.implementations_agree = true;
  274|    726|    }
  275|    726|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    726|      return r.error == simdutf::SUCCESS;
  277|    726|    });
  278|    726|    return ret;
  279|    726|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|  1.45k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|  1.41k|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|  1.41k|      return r.error == simdutf::SUCCESS;
  277|  1.41k|    });
_ZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    726|  bool count_the_input(FromSpan src) const {
  290|    726|    const auto implementations = get_supported_implementations();
  291|    726|    std::vector<std::size_t> results;
  292|    726|    results.reserve(implementations.size());
  293|       |
  294|  2.17k|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 2.17k, False: 726]
  ------------------
  295|  2.17k|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|  2.17k|      } else if constexpr (From == UtfEncodings::UTF8) {
  301|  2.17k|        ret = impl->count_utf8(src.data(), src.size());
  302|  2.17k|      }
  303|  2.17k|      results.push_back(ret);
  304|  2.17k|    }
  305|    726|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    726|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 726]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    726|    return true;
  321|    726|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  305|  1.45k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    726|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    726|    length_result ret{};
  344|       |
  345|    726|    const auto implementations = get_supported_implementations();
  346|    726|    std::vector<std::size_t> results;
  347|    726|    results.reserve(implementations.size());
  348|       |
  349|  2.17k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 2.17k, False: 726]
  ------------------
  350|  2.17k|      const auto len = invoke_lengthcalc(impl, src);
  351|  2.17k|      results.push_back(len);
  352|  2.17k|      ret.length.push_back(len);
  353|  2.17k|    }
  354|       |
  355|    726|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    726|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 726]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    726|    } else {
  375|    726|      ret.implementations_agree = true;
  376|    726|    }
  377|    726|    return ret;
  378|    726|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSE_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  2.17k|                                FromSpan src) const {
  331|  2.17k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  2.17k|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|  1.45k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|    715|                                  const bool inputisvalid) const {
  383|    715|    conversion_result ret{};
  384|       |
  385|    715|    const auto implementations = get_supported_implementations();
  386|       |
  387|    715|    std::vector<result<ConversionResult>> results;
  388|    715|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    715|    std::vector<std::vector<ToType>> outputbuffers;
  393|    715|    outputbuffers.reserve(implementations.size());
  394|  2.86k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 2.14k, False: 715]
  ------------------
  395|  2.14k|      auto impl = implementations[i];
  396|  2.14k|      const ToType canary1{42};
  397|  2.14k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  2.14k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  2.14k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  2.14k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  2.14k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  2.14k|          return r != 0;
  404|  2.14k|        } else {
  405|  2.14k|          return r.error == simdutf::error_code::SUCCESS;
  406|  2.14k|        }
  407|  2.14k|      }(implret1);
  408|  2.14k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  2.14k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  2.14k|        const ToType canary2{25};
  414|  2.14k|        const auto outputbuffer_first_run = outputbuffer;
  415|  2.14k|        std::ranges::fill(outputbuffer, canary2);
  416|  2.14k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  2.14k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  2.14k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 2.14k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  2.14k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 1.03k, False: 1.11k]
  |  Branch (423:29): [True: 1.02k, False: 9]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|  1.02k|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|  1.02k|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 1.02k]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|  1.02k|        }
  440|  2.14k|      }
  441|  2.14k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 1.02k, False: 1.11k]
  ------------------
  442|  2.14k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    715|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 370, False: 345]
  ------------------
  447|  1.11k|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 1.11k, False: 370]
  ------------------
  448|  1.11k|        e.outputhash.clear();
  449|  1.11k|      }
  450|    370|    }
  451|       |
  452|    715|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    715|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 715]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    715|    } else {
  474|    715|      ret.implementations_agree = true;
  475|    715|    }
  476|    715|    return ret;
  477|    715|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|  2.14k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  2.14k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  2.14k|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|  2.14k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|  1.43k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK3$_8clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    181|    +[](std::span<const char> chardata) {                                      \
  555|    181|      const auto c =                                                           \
  556|    181|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    181|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    181|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    181|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    181|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    181|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    181|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    181|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    181|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    181|  constexpr auto _size = _name.size();                                \
  |  | 1183|    181|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    181|  return _nameof; }()
  ------------------
  561|    181|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    181|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    181|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    181|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    181|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    181|  constexpr auto _size = _name.size();                                \
  |  | 1183|    181|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    181|  return _nameof; }()
  ------------------
  562|    181|      c.fuzz(chardata);                                                        \
  563|    181|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE4fuzzENSt3__14spanIS3_Lm18446744073709551615EEE:
  175|    656|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    656|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    656|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    656|    static const bool do_print_testcase =
  181|    656|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    656|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 656]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    656|    do {
  189|       |      // step 0 - is the input valid?
  190|    656|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    656|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 656]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    656|                    From == UtfEncodings::UTF8) {
  198|    656|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 656]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    656|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    656|      const auto [output_length, length_agree] =
  204|    656|          calculate_length(from, inputisvalid);
  205|    656|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 656]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    656|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 357, False: 299]
  |  Branch (208:28): [True: 9, False: 348]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      9|        return;
  211|      9|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    647|      const auto [written, outputs_agree] =
  215|    647|          do_conversion(from, output_length, inputisvalid);
  216|    647|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 647]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    647|      return;
  221|    647|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    656|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    656|  validation_result verify_valid_input(FromSpan src) const {
  231|    656|    validation_result ret{};
  232|       |
  233|    656|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    656|    const auto implementations = get_supported_implementations();
  235|    656|    std::vector<simdutf::result> results;
  236|    656|    results.reserve(implementations.size());
  237|       |
  238|  1.96k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.96k, False: 656]
  ------------------
  239|  1.96k|      results.push_back(
  240|  1.96k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.96k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.96k|      const bool validation2 =
  245|  1.96k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.96k|                      src.data(), src.size());
  247|  1.96k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.96k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.96k|    }
  258|       |
  259|    656|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    656|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 656]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    656|    } else {
  273|    656|      ret.implementations_agree = true;
  274|    656|    }
  275|    656|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    656|      return r.error == simdutf::SUCCESS;
  277|    656|    });
  278|    656|    return ret;
  279|    656|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|  1.31k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|  1.25k|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|  1.25k|      return r.error == simdutf::SUCCESS;
  277|  1.25k|    });
_ZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    656|  bool count_the_input(FromSpan src) const {
  290|    656|    const auto implementations = get_supported_implementations();
  291|    656|    std::vector<std::size_t> results;
  292|    656|    results.reserve(implementations.size());
  293|       |
  294|  1.96k|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 1.96k, False: 656]
  ------------------
  295|  1.96k|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|  1.96k|      } else if constexpr (From == UtfEncodings::UTF8) {
  301|  1.96k|        ret = impl->count_utf8(src.data(), src.size());
  302|  1.96k|      }
  303|  1.96k|      results.push_back(ret);
  304|  1.96k|    }
  305|    656|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    656|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 656]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    656|    return true;
  321|    656|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  305|  1.31k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    656|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    656|    length_result ret{};
  344|       |
  345|    656|    const auto implementations = get_supported_implementations();
  346|    656|    std::vector<std::size_t> results;
  347|    656|    results.reserve(implementations.size());
  348|       |
  349|  1.96k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.96k, False: 656]
  ------------------
  350|  1.96k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.96k|      results.push_back(len);
  352|  1.96k|      ret.length.push_back(len);
  353|  1.96k|    }
  354|       |
  355|    656|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    656|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 656]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    656|    } else {
  375|    656|      ret.implementations_agree = true;
  376|    656|    }
  377|    656|    return ret;
  378|    656|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSE_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.96k|                                FromSpan src) const {
  331|  1.96k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.96k|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|  1.31k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|    647|                                  const bool inputisvalid) const {
  383|    647|    conversion_result ret{};
  384|       |
  385|    647|    const auto implementations = get_supported_implementations();
  386|       |
  387|    647|    std::vector<result<ConversionResult>> results;
  388|    647|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    647|    std::vector<std::vector<ToType>> outputbuffers;
  393|    647|    outputbuffers.reserve(implementations.size());
  394|  2.58k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.94k, False: 647]
  ------------------
  395|  1.94k|      auto impl = implementations[i];
  396|  1.94k|      const ToType canary1{42};
  397|  1.94k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.94k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.94k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.94k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.94k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.94k|          return r != 0;
  404|  1.94k|        } else {
  405|  1.94k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.94k|        }
  407|  1.94k|      }(implret1);
  408|  1.94k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.94k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.94k|        const ToType canary2{25};
  414|  1.94k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.94k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.94k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.94k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.94k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.94k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.94k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 897, False: 1.04k]
  |  Branch (423:29): [True: 888, False: 9]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    888|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    888|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 888]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    888|        }
  440|  1.94k|      }
  441|  1.94k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 888, False: 1.05k]
  ------------------
  442|  1.94k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    647|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 348, False: 299]
  ------------------
  447|  1.04k|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 1.04k, False: 348]
  ------------------
  448|  1.04k|        e.outputhash.clear();
  449|  1.04k|      }
  450|    348|    }
  451|       |
  452|    647|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    647|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 647]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    647|    } else {
  474|    647|      ret.implementations_agree = true;
  475|    647|    }
  476|    647|    return ret;
  477|    647|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|  1.94k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.94k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.94k|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|  1.94k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|  1.29k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK3$_9clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    267|    +[](std::span<const char> chardata) {                                      \
  555|    267|      const auto c =                                                           \
  556|    267|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    267|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    267|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    267|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    267|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    267|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    267|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    267|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    267|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    267|  constexpr auto _size = _name.size();                                \
  |  | 1183|    267|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    267|  return _nameof; }()
  ------------------
  561|    267|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    267|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    267|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    267|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    267|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    267|  constexpr auto _size = _name.size();                                \
  |  | 1183|    267|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    267|  return _nameof; }()
  ------------------
  562|    267|      c.fuzz(chardata);                                                        \
  563|    267|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDiEE4fuzzENSt3__14spanIS3_Lm18446744073709551615EEE:
  175|    742|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    742|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    742|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    742|    static const bool do_print_testcase =
  181|    742|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    742|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 742]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    742|    do {
  189|       |      // step 0 - is the input valid?
  190|    742|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    742|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 742]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    742|                    From == UtfEncodings::UTF8) {
  198|    742|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 742]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    742|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    742|      const auto [output_length, length_agree] =
  204|    742|          calculate_length(from, inputisvalid);
  205|    742|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 742]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    742|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 364, False: 378]
  |  Branch (208:28): [True: 11, False: 353]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|     11|        return;
  211|     11|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    731|      const auto [written, outputs_agree] =
  215|    731|          do_conversion(from, output_length, inputisvalid);
  216|    731|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 731]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    731|      return;
  221|    731|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    742|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    742|  validation_result verify_valid_input(FromSpan src) const {
  231|    742|    validation_result ret{};
  232|       |
  233|    742|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    742|    const auto implementations = get_supported_implementations();
  235|    742|    std::vector<simdutf::result> results;
  236|    742|    results.reserve(implementations.size());
  237|       |
  238|  2.22k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 2.22k, False: 742]
  ------------------
  239|  2.22k|      results.push_back(
  240|  2.22k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  2.22k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  2.22k|      const bool validation2 =
  245|  2.22k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  2.22k|                      src.data(), src.size());
  247|  2.22k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 2.22k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  2.22k|    }
  258|       |
  259|    742|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    742|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 742]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    742|    } else {
  273|    742|      ret.implementations_agree = true;
  274|    742|    }
  275|    742|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    742|      return r.error == simdutf::SUCCESS;
  277|    742|    });
  278|    742|    return ret;
  279|    742|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|  1.48k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|  1.49k|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|  1.49k|      return r.error == simdutf::SUCCESS;
  277|  1.49k|    });
_ZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDiEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    742|  bool count_the_input(FromSpan src) const {
  290|    742|    const auto implementations = get_supported_implementations();
  291|    742|    std::vector<std::size_t> results;
  292|    742|    results.reserve(implementations.size());
  293|       |
  294|  2.22k|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 2.22k, False: 742]
  ------------------
  295|  2.22k|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|  2.22k|      } else if constexpr (From == UtfEncodings::UTF8) {
  301|  2.22k|        ret = impl->count_utf8(src.data(), src.size());
  302|  2.22k|      }
  303|  2.22k|      results.push_back(ret);
  304|  2.22k|    }
  305|    742|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    742|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 742]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    742|    return true;
  321|    742|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDiEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  305|  1.48k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDiEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    742|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    742|    length_result ret{};
  344|       |
  345|    742|    const auto implementations = get_supported_implementations();
  346|    742|    std::vector<std::size_t> results;
  347|    742|    results.reserve(implementations.size());
  348|       |
  349|  2.22k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 2.22k, False: 742]
  ------------------
  350|  2.22k|      const auto len = invoke_lengthcalc(impl, src);
  351|  2.22k|      results.push_back(len);
  352|  2.22k|      ret.length.push_back(len);
  353|  2.22k|    }
  354|       |
  355|    742|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    742|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 742]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    742|    } else {
  375|    742|      ret.implementations_agree = true;
  376|    742|    }
  377|    742|    return ret;
  378|    742|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDiEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSE_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  2.22k|                                FromSpan src) const {
  331|  2.22k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  2.22k|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDiEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|  1.48k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|    731|                                  const bool inputisvalid) const {
  383|    731|    conversion_result ret{};
  384|       |
  385|    731|    const auto implementations = get_supported_implementations();
  386|       |
  387|    731|    std::vector<result<ConversionResult>> results;
  388|    731|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    731|    std::vector<std::vector<ToType>> outputbuffers;
  393|    731|    outputbuffers.reserve(implementations.size());
  394|  2.92k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 2.19k, False: 731]
  ------------------
  395|  2.19k|      auto impl = implementations[i];
  396|  2.19k|      const ToType canary1{42};
  397|  2.19k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  2.19k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  2.19k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  2.19k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  2.19k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  2.19k|          return r != 0;
  404|  2.19k|        } else {
  405|  2.19k|          return r.error == simdutf::error_code::SUCCESS;
  406|  2.19k|        }
  407|  2.19k|      }(implret1);
  408|  2.19k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  2.19k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  2.19k|        const ToType canary2{25};
  414|  2.19k|        const auto outputbuffer_first_run = outputbuffer;
  415|  2.19k|        std::ranges::fill(outputbuffer, canary2);
  416|  2.19k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  2.19k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  2.19k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 2.19k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  2.19k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 1.13k, False: 1.05k]
  |  Branch (423:29): [True: 1.12k, False: 6]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|  1.12k|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|  1.12k|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 1.12k]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|  1.12k|        }
  440|  2.19k|      }
  441|  2.19k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 1.12k, False: 1.06k]
  ------------------
  442|  2.19k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    731|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 353, False: 378]
  ------------------
  447|  1.05k|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 1.05k, False: 353]
  ------------------
  448|  1.05k|        e.outputhash.clear();
  449|  1.05k|      }
  450|    353|    }
  451|       |
  452|    731|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    731|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 731]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    731|    } else {
  474|    731|      ret.implementations_agree = true;
  475|    731|    }
  476|    731|    return ret;
  477|    731|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|  2.19k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  2.19k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  2.19k|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|  2.19k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|  1.46k|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_10clENSt3__14spanIKcLm18446744073709551615EEE:
  554|     58|    +[](std::span<const char> chardata) {                                      \
  555|     58|      const auto c =                                                           \
  556|     58|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|     58|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|     58|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|     58|              &I::lenfunc, &I::conversionfunc,                                 \
  560|     58|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|     58|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     58|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     58|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     58|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     58|  constexpr auto _size = _name.size();                                \
  |  | 1183|     58|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     58|  return _nameof; }()
  ------------------
  561|     58|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|     58|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     58|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     58|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     58|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     58|  constexpr auto _size = _name.size();                                \
  |  | 1183|     58|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     58|  return _nameof; }()
  ------------------
  562|     58|      c.fuzz(chardata);                                                        \
  563|     58|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|     58|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|     58|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|     58|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|     58|    static const bool do_print_testcase =
  181|     58|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|     58|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 58]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|     58|    do {
  189|       |      // step 0 - is the input valid?
  190|     58|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|     58|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 58]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|     58|                    From == UtfEncodings::UTF8) {
  198|     58|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 58]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|     58|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|     58|      const auto [output_length, length_agree] =
  204|     58|          calculate_length(from, inputisvalid);
  205|     58|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 58]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|     58|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 12, False: 46]
  |  Branch (208:28): [True: 0, False: 12]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|     58|      const auto [written, outputs_agree] =
  215|     58|          do_conversion(from, output_length, inputisvalid);
  216|     58|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 58]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|     58|      return;
  221|     58|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|     58|  }
_ZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS5_Lm18446744073709551615EEE:
  230|     58|  validation_result verify_valid_input(FromSpan src) const {
  231|     58|    validation_result ret{};
  232|       |
  233|     58|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|     58|    const auto implementations = get_supported_implementations();
  235|     58|    std::vector<simdutf::result> results;
  236|     58|    results.reserve(implementations.size());
  237|       |
  238|    174|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 174, False: 58]
  ------------------
  239|    174|      results.push_back(
  240|    174|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|    174|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|    174|      const bool validation2 =
  245|    174|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|    174|                      src.data(), src.size());
  247|    174|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 174]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|    174|    }
  258|       |
  259|     58|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|     58|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 58]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|     58|    } else {
  273|     58|      ret.implementations_agree = true;
  274|     58|    }
  275|     58|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|     58|      return r.error == simdutf::SUCCESS;
  277|     58|    });
  278|     58|    return ret;
  279|     58|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS5_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|    116|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS5_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|    150|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    150|      return r.error == simdutf::SUCCESS;
  277|    150|    });
_ZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE15count_the_inputENSt3__14spanIS5_Lm18446744073709551615EEE:
  289|     58|  bool count_the_input(FromSpan src) const {
  290|     58|    const auto implementations = get_supported_implementations();
  291|     58|    std::vector<std::size_t> results;
  292|     58|    results.reserve(implementations.size());
  293|       |
  294|    174|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 174, False: 58]
  ------------------
  295|    174|      std::size_t ret;
  296|    174|      if constexpr (From == UtfEncodings::UTF16BE) {
  297|    174|        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|       |      } else if constexpr (From == UtfEncodings::UTF8) {
  301|       |        ret = impl->count_utf8(src.data(), src.size());
  302|       |      }
  303|    174|      results.push_back(ret);
  304|    174|    }
  305|     58|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|     58|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 58]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|     58|    return true;
  321|     58|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE15count_the_inputENSt3__14spanIS5_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  305|    116|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE16calculate_lengthENSt3__14spanIS5_Lm18446744073709551615EEEb:
  342|     58|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|     58|    length_result ret{};
  344|       |
  345|     58|    const auto implementations = get_supported_implementations();
  346|     58|    std::vector<std::size_t> results;
  347|     58|    results.reserve(implementations.size());
  348|       |
  349|    174|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 174, False: 58]
  ------------------
  350|    174|      const auto len = invoke_lengthcalc(impl, src);
  351|    174|      results.push_back(len);
  352|    174|      ret.length.push_back(len);
  353|    174|    }
  354|       |
  355|     58|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|     58|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 58]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|     58|    } else {
  375|     58|      ret.implementations_agree = true;
  376|     58|    }
  377|     58|    return ret;
  378|     58|  }
_ZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_mEEEmSE_NSt3__14spanIS5_Lm18446744073709551615EEE:
  338|    174|                                FromSpan src) const {
  339|    174|    return std::invoke(lengthcalc, impl, /*src.data(),*/ src.size());
  340|    174|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE16calculate_lengthENSt3__14spanIS5_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    116|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|     58|                                  const bool inputisvalid) const {
  383|     58|    conversion_result ret{};
  384|       |
  385|     58|    const auto implementations = get_supported_implementations();
  386|       |
  387|     58|    std::vector<result<ConversionResult>> results;
  388|     58|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|     58|    std::vector<std::vector<ToType>> outputbuffers;
  393|     58|    outputbuffers.reserve(implementations.size());
  394|    232|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 174, False: 58]
  ------------------
  395|    174|      auto impl = implementations[i];
  396|    174|      const ToType canary1{42};
  397|    174|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    174|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    174|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    174|      const auto success = [](const ConversionResult& r) -> bool {
  402|    174|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    174|          return r != 0;
  404|    174|        } else {
  405|    174|          return r.error == simdutf::error_code::SUCCESS;
  406|    174|        }
  407|    174|      }(implret1);
  408|    174|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    174|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    174|        const ToType canary2{25};
  414|    174|        const auto outputbuffer_first_run = outputbuffer;
  415|    174|        std::ranges::fill(outputbuffer, canary2);
  416|    174|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    174|                                          src.size(), outputbuffer.data());
  418|       |
  419|    174|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 174]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    174|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 138, False: 36]
  |  Branch (423:29): [True: 66, False: 72]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|     66|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|     66|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 66]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|     66|        }
  440|    174|      }
  441|    174|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 66, False: 108]
  ------------------
  442|    174|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|     58|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 12, False: 46]
  ------------------
  447|     36|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 36, False: 12]
  ------------------
  448|     36|        e.outputhash.clear();
  449|     36|      }
  450|     12|    }
  451|       |
  452|     58|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|     58|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 58]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|     58|    } else {
  474|     58|      ret.implementations_agree = true;
  475|     58|    }
  476|     58|    return ret;
  477|     58|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|    174|      const auto success = [](const ConversionResult& r) -> bool {
  402|    174|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    174|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|    174|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    116|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_11clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    151|    +[](std::span<const char> chardata) {                                      \
  555|    151|      const auto c =                                                           \
  556|    151|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    151|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    151|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    151|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    151|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    151|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    151|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    151|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    151|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    151|  constexpr auto _size = _name.size();                                \
  |  | 1183|    151|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    151|  return _nameof; }()
  ------------------
  561|    151|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    151|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    151|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    151|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    151|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    151|  constexpr auto _size = _name.size();                                \
  |  | 1183|    151|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    151|  return _nameof; }()
  ------------------
  562|    151|      c.fuzz(chardata);                                                        \
  563|    151|    }                                                                          \
conversion.cpp:_ZZ18populate_functionsvENK4$_12clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    197|    +[](std::span<const char> chardata) {                                      \
  555|    197|      const auto c =                                                           \
  556|    197|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    197|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    197|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    197|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    197|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    197|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    197|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    197|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    197|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    197|  constexpr auto _size = _name.size();                                \
  |  | 1183|    197|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    197|  return _nameof; }()
  ------------------
  561|    197|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    197|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    197|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    197|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    197|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    197|  constexpr auto _size = _name.size();                                \
  |  | 1183|    197|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    197|  return _nameof; }()
  ------------------
  562|    197|      c.fuzz(chardata);                                                        \
  563|    197|    }                                                                          \
conversion.cpp:_ZZ18populate_functionsvENK4$_13clENSt3__14spanIKcLm18446744073709551615EEE:
  554|     67|    +[](std::span<const char> chardata) {                                      \
  555|     67|      const auto c =                                                           \
  556|     67|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|     67|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|     67|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|     67|              &I::lenfunc, &I::conversionfunc,                                 \
  560|     67|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|     67|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     67|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     67|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     67|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     67|  constexpr auto _size = _name.size();                                \
  |  | 1183|     67|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     67|  return _nameof; }()
  ------------------
  561|     67|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|     67|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     67|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     67|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     67|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     67|  constexpr auto _size = _name.size();                                \
  |  | 1183|     67|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     67|  return _nameof; }()
  ------------------
  562|     67|      c.fuzz(chardata);                                                        \
  563|     67|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|     67|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|     67|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|     67|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|     67|    static const bool do_print_testcase =
  181|     67|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|     67|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 67]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|     67|    do {
  189|       |      // step 0 - is the input valid?
  190|     67|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|     67|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 67]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|     67|                    From == UtfEncodings::UTF8) {
  198|     67|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 67]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|     67|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|     67|      const auto [output_length, length_agree] =
  204|     67|          calculate_length(from, inputisvalid);
  205|     67|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 67]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|     67|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 18, False: 49]
  |  Branch (208:28): [True: 0, False: 18]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|     67|      const auto [written, outputs_agree] =
  215|     67|          do_conversion(from, output_length, inputisvalid);
  216|     67|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 67]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|     67|      return;
  221|     67|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|     67|  }
_ZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS5_Lm18446744073709551615EEE:
  230|     67|  validation_result verify_valid_input(FromSpan src) const {
  231|     67|    validation_result ret{};
  232|       |
  233|     67|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|     67|    const auto implementations = get_supported_implementations();
  235|     67|    std::vector<simdutf::result> results;
  236|     67|    results.reserve(implementations.size());
  237|       |
  238|    201|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 201, False: 67]
  ------------------
  239|    201|      results.push_back(
  240|    201|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|    201|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|    201|      const bool validation2 =
  245|    201|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|    201|                      src.data(), src.size());
  247|    201|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 201]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|    201|    }
  258|       |
  259|     67|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|     67|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 67]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|     67|    } else {
  273|     67|      ret.implementations_agree = true;
  274|     67|    }
  275|     67|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|     67|      return r.error == simdutf::SUCCESS;
  277|     67|    });
  278|     67|    return ret;
  279|     67|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS5_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|    134|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS5_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|    165|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    165|      return r.error == simdutf::SUCCESS;
  277|    165|    });
_ZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE15count_the_inputENSt3__14spanIS5_Lm18446744073709551615EEE:
  289|     67|  bool count_the_input(FromSpan src) const {
  290|     67|    const auto implementations = get_supported_implementations();
  291|     67|    std::vector<std::size_t> results;
  292|     67|    results.reserve(implementations.size());
  293|       |
  294|    201|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 201, False: 67]
  ------------------
  295|    201|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|    201|      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|    201|        ret = impl->count_utf16le(src.data(), src.size());
  300|       |      } else if constexpr (From == UtfEncodings::UTF8) {
  301|       |        ret = impl->count_utf8(src.data(), src.size());
  302|       |      }
  303|    201|      results.push_back(ret);
  304|    201|    }
  305|     67|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|     67|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 67]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|     67|    return true;
  321|     67|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE15count_the_inputENSt3__14spanIS5_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  305|    134|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE16calculate_lengthENSt3__14spanIS5_Lm18446744073709551615EEEb:
  342|     67|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|     67|    length_result ret{};
  344|       |
  345|     67|    const auto implementations = get_supported_implementations();
  346|     67|    std::vector<std::size_t> results;
  347|     67|    results.reserve(implementations.size());
  348|       |
  349|    201|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 201, False: 67]
  ------------------
  350|    201|      const auto len = invoke_lengthcalc(impl, src);
  351|    201|      results.push_back(len);
  352|    201|      ret.length.push_back(len);
  353|    201|    }
  354|       |
  355|     67|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|     67|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 67]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|     67|    } else {
  375|     67|      ret.implementations_agree = true;
  376|     67|    }
  377|     67|    return ret;
  378|     67|  }
_ZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_mEEEmSE_NSt3__14spanIS5_Lm18446744073709551615EEE:
  338|    201|                                FromSpan src) const {
  339|    201|    return std::invoke(lengthcalc, impl, /*src.data(),*/ src.size());
  340|    201|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE16calculate_lengthENSt3__14spanIS5_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    134|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|     67|                                  const bool inputisvalid) const {
  383|     67|    conversion_result ret{};
  384|       |
  385|     67|    const auto implementations = get_supported_implementations();
  386|       |
  387|     67|    std::vector<result<ConversionResult>> results;
  388|     67|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|     67|    std::vector<std::vector<ToType>> outputbuffers;
  393|     67|    outputbuffers.reserve(implementations.size());
  394|    268|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 201, False: 67]
  ------------------
  395|    201|      auto impl = implementations[i];
  396|    201|      const ToType canary1{42};
  397|    201|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    201|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    201|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    201|      const auto success = [](const ConversionResult& r) -> bool {
  402|    201|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    201|          return r != 0;
  404|    201|        } else {
  405|    201|          return r.error == simdutf::error_code::SUCCESS;
  406|    201|        }
  407|    201|      }(implret1);
  408|    201|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    201|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    201|        const ToType canary2{25};
  414|    201|        const auto outputbuffer_first_run = outputbuffer;
  415|    201|        std::ranges::fill(outputbuffer, canary2);
  416|    201|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    201|                                          src.size(), outputbuffer.data());
  418|       |
  419|    201|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 201]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    201|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 147, False: 54]
  |  Branch (423:29): [True: 69, False: 78]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|     69|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|     69|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 69]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|     69|        }
  440|    201|      }
  441|    201|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 69, False: 132]
  ------------------
  442|    201|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|     67|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 18, False: 49]
  ------------------
  447|     54|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 54, False: 18]
  ------------------
  448|     54|        e.outputhash.clear();
  449|     54|      }
  450|     18|    }
  451|       |
  452|     67|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|     67|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 67]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|     67|    } else {
  474|     67|      ret.implementations_agree = true;
  475|     67|    }
  476|     67|    return ret;
  477|     67|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|    201|      const auto success = [](const ConversionResult& r) -> bool {
  402|    201|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    201|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|    201|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDsmPcEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    134|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_14clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    154|    +[](std::span<const char> chardata) {                                      \
  555|    154|      const auto c =                                                           \
  556|    154|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    154|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    154|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    154|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    154|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    154|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    154|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    154|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    154|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    154|  constexpr auto _size = _name.size();                                \
  |  | 1183|    154|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    154|  return _nameof; }()
  ------------------
  561|    154|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    154|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    154|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    154|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    154|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    154|  constexpr auto _size = _name.size();                                \
  |  | 1183|    154|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    154|  return _nameof; }()
  ------------------
  562|    154|      c.fuzz(chardata);                                                        \
  563|    154|    }                                                                          \
conversion.cpp:_ZZ18populate_functionsvENK4$_15clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    253|    +[](std::span<const char> chardata) {                                      \
  555|    253|      const auto c =                                                           \
  556|    253|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    253|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    253|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    253|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    253|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    253|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    253|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    253|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    253|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    253|  constexpr auto _size = _name.size();                                \
  |  | 1183|    253|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    253|  return _nameof; }()
  ------------------
  561|    253|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    253|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    253|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    253|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    253|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    253|  constexpr auto _size = _name.size();                                \
  |  | 1183|    253|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    253|  return _nameof; }()
  ------------------
  562|    253|      c.fuzz(chardata);                                                        \
  563|    253|    }                                                                          \
conversion.cpp:_ZZ18populate_functionsvENK4$_16clENSt3__14spanIKcLm18446744073709551615EEE:
  554|     93|    +[](std::span<const char> chardata) {                                      \
  555|     93|      const auto c =                                                           \
  556|     93|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|     93|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|     93|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|     93|              &I::lenfunc, &I::conversionfunc,                                 \
  560|     93|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|     93|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     93|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     93|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     93|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     93|  constexpr auto _size = _name.size();                                \
  |  | 1183|     93|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     93|  return _nameof; }()
  ------------------
  561|     93|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|     93|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     93|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     93|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     93|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     93|  constexpr auto _size = _name.size();                                \
  |  | 1183|     93|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     93|  return _nameof; }()
  ------------------
  562|     93|      c.fuzz(chardata);                                                        \
  563|     93|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDimPcEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|     93|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|     93|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|     93|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|     93|    static const bool do_print_testcase =
  181|     93|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|     93|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 93]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|     93|    do {
  189|       |      // step 0 - is the input valid?
  190|     93|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|     93|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 93]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|       |                    From == UtfEncodings::UTF8) {
  198|       |        if (!count_the_input(from) && !allow_implementations_to_differ)
  199|       |          break;
  200|       |      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|     93|      const auto [output_length, length_agree] =
  204|     93|          calculate_length(from, inputisvalid);
  205|     93|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 93]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|     93|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 74, False: 19]
  |  Branch (208:28): [True: 0, False: 74]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|     93|      const auto [written, outputs_agree] =
  215|     93|          do_conversion(from, output_length, inputisvalid);
  216|     93|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 93]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|     93|      return;
  221|     93|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|     93|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDimPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS5_Lm18446744073709551615EEE:
  230|     93|  validation_result verify_valid_input(FromSpan src) const {
  231|     93|    validation_result ret{};
  232|       |
  233|     93|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|     93|    const auto implementations = get_supported_implementations();
  235|     93|    std::vector<simdutf::result> results;
  236|     93|    results.reserve(implementations.size());
  237|       |
  238|    279|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 279, False: 93]
  ------------------
  239|    279|      results.push_back(
  240|    279|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|    279|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|    279|      const bool validation2 =
  245|    279|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|    279|                      src.data(), src.size());
  247|    279|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 279]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|    279|    }
  258|       |
  259|     93|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|     93|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 93]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|     93|    } else {
  273|     93|      ret.implementations_agree = true;
  274|     93|    }
  275|     93|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|     93|      return r.error == simdutf::SUCCESS;
  277|     93|    });
  278|     93|    return ret;
  279|     93|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDimPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS5_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|    186|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDimPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS5_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|    131|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    131|      return r.error == simdutf::SUCCESS;
  277|    131|    });
_ZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDimPcEE16calculate_lengthENSt3__14spanIS5_Lm18446744073709551615EEEb:
  342|     93|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|     93|    length_result ret{};
  344|       |
  345|     93|    const auto implementations = get_supported_implementations();
  346|     93|    std::vector<std::size_t> results;
  347|     93|    results.reserve(implementations.size());
  348|       |
  349|    279|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 279, False: 93]
  ------------------
  350|    279|      const auto len = invoke_lengthcalc(impl, src);
  351|    279|      results.push_back(len);
  352|    279|      ret.length.push_back(len);
  353|    279|    }
  354|       |
  355|     93|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|     93|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 93]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|     93|    } else {
  375|     93|      ret.implementations_agree = true;
  376|     93|    }
  377|     93|    return ret;
  378|     93|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDimPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_mEEEmSE_NSt3__14spanIS5_Lm18446744073709551615EEE:
  338|    279|                                FromSpan src) const {
  339|    279|    return std::invoke(lengthcalc, impl, /*src.data(),*/ src.size());
  340|    279|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDimPcEE16calculate_lengthENSt3__14spanIS5_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    186|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDimPcEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|     93|                                  const bool inputisvalid) const {
  383|     93|    conversion_result ret{};
  384|       |
  385|     93|    const auto implementations = get_supported_implementations();
  386|       |
  387|     93|    std::vector<result<ConversionResult>> results;
  388|     93|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|     93|    std::vector<std::vector<ToType>> outputbuffers;
  393|     93|    outputbuffers.reserve(implementations.size());
  394|    372|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 279, False: 93]
  ------------------
  395|    279|      auto impl = implementations[i];
  396|    279|      const ToType canary1{42};
  397|    279|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    279|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    279|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    279|      const auto success = [](const ConversionResult& r) -> bool {
  402|    279|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    279|          return r != 0;
  404|    279|        } else {
  405|    279|          return r.error == simdutf::error_code::SUCCESS;
  406|    279|        }
  407|    279|      }(implret1);
  408|    279|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    279|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    279|        const ToType canary2{25};
  414|    279|        const auto outputbuffer_first_run = outputbuffer;
  415|    279|        std::ranges::fill(outputbuffer, canary2);
  416|    279|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    279|                                          src.size(), outputbuffer.data());
  418|       |
  419|    279|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 279]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    279|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 57, False: 222]
  |  Branch (423:29): [True: 48, False: 9]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|     48|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|     48|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 48]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|     48|        }
  440|    279|      }
  441|    279|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 48, False: 231]
  ------------------
  442|    279|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|     93|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 74, False: 19]
  ------------------
  447|    222|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 222, False: 74]
  ------------------
  448|    222|        e.outputhash.clear();
  449|    222|      }
  450|     74|    }
  451|       |
  452|     93|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|     93|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 93]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|     93|    } else {
  474|     93|      ret.implementations_agree = true;
  475|     93|    }
  476|     93|    return ret;
  477|     93|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDimPcEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|    279|      const auto success = [](const ConversionResult& r) -> bool {
  402|    279|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    279|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|    279|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKDimPcEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    186|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_17clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    258|    +[](std::span<const char> chardata) {                                      \
  555|    258|      const auto c =                                                           \
  556|    258|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    258|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    258|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    258|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    258|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    258|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    258|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    258|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    258|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    258|  constexpr auto _size = _name.size();                                \
  |  | 1183|    258|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    258|  return _nameof; }()
  ------------------
  561|    258|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    258|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    258|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    258|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    258|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    258|  constexpr auto _size = _name.size();                                \
  |  | 1183|    258|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    258|  return _nameof; }()
  ------------------
  562|    258|      c.fuzz(chardata);                                                        \
  563|    258|    }                                                                          \
conversion.cpp:_ZZ18populate_functionsvENK4$_18clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    251|    +[](std::span<const char> chardata) {                                      \
  555|    251|      const auto c =                                                           \
  556|    251|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    251|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    251|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    251|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    251|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    251|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    251|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    251|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    251|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    251|  constexpr auto _size = _name.size();                                \
  |  | 1183|    251|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    251|  return _nameof; }()
  ------------------
  561|    251|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    251|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    251|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    251|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    251|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    251|  constexpr auto _size = _name.size();                                \
  |  | 1183|    251|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    251|  return _nameof; }()
  ------------------
  562|    251|      c.fuzz(chardata);                                                        \
  563|    251|    }                                                                          \
conversion.cpp:_ZZ18populate_functionsvENK4$_19clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    357|    +[](std::span<const char> chardata) {                                      \
  555|    357|      const auto c =                                                           \
  556|    357|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    357|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    357|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    357|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    357|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    357|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    357|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    357|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    357|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    357|  constexpr auto _size = _name.size();                                \
  |  | 1183|    357|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    357|  return _nameof; }()
  ------------------
  561|    357|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    357|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    357|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    357|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    357|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    357|  constexpr auto _size = _name.size();                                \
  |  | 1183|    357|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    357|  return _nameof; }()
  ------------------
  562|    357|      c.fuzz(chardata);                                                        \
  563|    357|    }                                                                          \
conversion.cpp:_ZZ18populate_functionsvENK4$_20clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    358|    +[](std::span<const char> chardata) {                                      \
  555|    358|      const auto c =                                                           \
  556|    358|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    358|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    358|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    358|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    358|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    358|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    358|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    358|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    358|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    358|  constexpr auto _size = _name.size();                                \
  |  | 1183|    358|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    358|  return _nameof; }()
  ------------------
  561|    358|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    358|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    358|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    358|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    358|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    358|  constexpr auto _size = _name.size();                                \
  |  | 1183|    358|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    358|  return _nameof; }()
  ------------------
  562|    358|      c.fuzz(chardata);                                                        \
  563|    358|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE4fuzzENSt3__14spanIS3_Lm18446744073709551615EEE:
  175|    358|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    358|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    358|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    358|    static const bool do_print_testcase =
  181|    358|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    358|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 358]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    358|    do {
  189|       |      // step 0 - is the input valid?
  190|    358|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    358|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 358]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    358|                    From == UtfEncodings::UTF8) {
  198|    358|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 358]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    358|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    358|      const auto [output_length, length_agree] =
  204|    358|          calculate_length(from, inputisvalid);
  205|    358|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 358]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    358|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 250, False: 108]
  |  Branch (208:28): [True: 0, False: 250]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    358|      const auto [written, outputs_agree] =
  215|    358|          do_conversion(from, output_length, inputisvalid);
  216|    358|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 358]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    358|      return;
  221|    358|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    358|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    358|  validation_result verify_valid_input(FromSpan src) const {
  231|    358|    validation_result ret{};
  232|       |
  233|    358|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    358|    const auto implementations = get_supported_implementations();
  235|    358|    std::vector<simdutf::result> results;
  236|    358|    results.reserve(implementations.size());
  237|       |
  238|  1.07k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.07k, False: 358]
  ------------------
  239|  1.07k|      results.push_back(
  240|  1.07k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.07k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.07k|      const bool validation2 =
  245|  1.07k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.07k|                      src.data(), src.size());
  247|  1.07k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.07k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.07k|    }
  258|       |
  259|    358|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    358|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 358]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    358|    } else {
  273|    358|      ret.implementations_agree = true;
  274|    358|    }
  275|    358|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    358|      return r.error == simdutf::SUCCESS;
  277|    358|    });
  278|    358|    return ret;
  279|    358|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clINS1_6resultESO_EEDaSI_SL_:
  259|    716|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKNS1_6resultEE_clESI_:
  275|    574|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    574|      return r.error == simdutf::SUCCESS;
  277|    574|    });
_ZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    358|  bool count_the_input(FromSpan src) const {
  290|    358|    const auto implementations = get_supported_implementations();
  291|    358|    std::vector<std::size_t> results;
  292|    358|    results.reserve(implementations.size());
  293|       |
  294|  1.07k|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 1.07k, False: 358]
  ------------------
  295|  1.07k|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|  1.07k|      } else if constexpr (From == UtfEncodings::UTF8) {
  301|  1.07k|        ret = impl->count_utf8(src.data(), src.size());
  302|  1.07k|      }
  303|  1.07k|      results.push_back(ret);
  304|  1.07k|    }
  305|    358|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    358|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 358]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    358|    return true;
  321|    358|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  305|    716|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    358|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    358|    length_result ret{};
  344|       |
  345|    358|    const auto implementations = get_supported_implementations();
  346|    358|    std::vector<std::size_t> results;
  347|    358|    results.reserve(implementations.size());
  348|       |
  349|  1.07k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.07k, False: 358]
  ------------------
  350|  1.07k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.07k|      results.push_back(len);
  352|  1.07k|      ret.length.push_back(len);
  353|  1.07k|    }
  354|       |
  355|    358|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    358|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 358]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    358|    } else {
  375|    358|      ret.implementations_agree = true;
  376|    358|    }
  377|    358|    return ret;
  378|    358|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSE_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.07k|                                FromSpan src) const {
  331|  1.07k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.07k|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    716|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|    358|                                  const bool inputisvalid) const {
  383|    358|    conversion_result ret{};
  384|       |
  385|    358|    const auto implementations = get_supported_implementations();
  386|       |
  387|    358|    std::vector<result<ConversionResult>> results;
  388|    358|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    358|    std::vector<std::vector<ToType>> outputbuffers;
  393|    358|    outputbuffers.reserve(implementations.size());
  394|  1.43k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.07k, False: 358]
  ------------------
  395|  1.07k|      auto impl = implementations[i];
  396|  1.07k|      const ToType canary1{42};
  397|  1.07k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.07k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.07k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.07k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.07k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.07k|          return r != 0;
  404|  1.07k|        } else {
  405|  1.07k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.07k|        }
  407|  1.07k|      }(implret1);
  408|  1.07k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.07k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.07k|        const ToType canary2{25};
  414|  1.07k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.07k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.07k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.07k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.07k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.07k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.07k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 324, False: 750]
  |  Branch (423:29): [True: 291, False: 33]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    291|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    291|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 291]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    291|        }
  440|  1.07k|      }
  441|  1.07k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 291, False: 783]
  ------------------
  442|  1.07k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    358|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 250, False: 108]
  ------------------
  447|    750|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 750, False: 250]
  ------------------
  448|    750|        e.outputhash.clear();
  449|    750|      }
  450|    250|    }
  451|       |
  452|    358|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    358|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 358]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    358|    } else {
  474|    358|      ret.implementations_agree = true;
  475|    358|    }
  476|    358|    return ret;
  477|    358|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|  1.07k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.07k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.07k|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|  1.07k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    716|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_21clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    487|    +[](std::span<const char> chardata) {                                      \
  555|    487|      const auto c =                                                           \
  556|    487|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    487|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    487|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    487|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    487|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    487|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    487|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    487|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    487|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    487|  constexpr auto _size = _name.size();                                \
  |  | 1183|    487|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    487|  return _nameof; }()
  ------------------
  561|    487|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    487|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    487|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    487|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    487|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    487|  constexpr auto _size = _name.size();                                \
  |  | 1183|    487|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    487|  return _nameof; }()
  ------------------
  562|    487|      c.fuzz(chardata);                                                        \
  563|    487|    }                                                                          \
conversion.cpp:_ZZ18populate_functionsvENK4$_22clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    475|    +[](std::span<const char> chardata) {                                      \
  555|    475|      const auto c =                                                           \
  556|    475|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    475|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    475|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    475|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    475|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    475|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    475|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    475|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    475|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    475|  constexpr auto _size = _name.size();                                \
  |  | 1183|    475|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    475|  return _nameof; }()
  ------------------
  561|    475|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    475|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    475|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    475|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    475|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    475|  constexpr auto _size = _name.size();                                \
  |  | 1183|    475|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    475|  return _nameof; }()
  ------------------
  562|    475|      c.fuzz(chardata);                                                        \
  563|    475|    }                                                                          \
conversion.cpp:_ZZ18populate_functionsvENK4$_23clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    475|    +[](std::span<const char> chardata) {                                      \
  555|    475|      const auto c =                                                           \
  556|    475|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    475|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    475|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    475|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    475|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    475|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    475|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    475|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    475|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    475|  constexpr auto _size = _name.size();                                \
  |  | 1183|    475|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    475|  return _nameof; }()
  ------------------
  561|    475|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    475|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    475|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    475|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    475|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    475|  constexpr auto _size = _name.size();                                \
  |  | 1183|    475|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    475|  return _nameof; }()
  ------------------
  562|    475|      c.fuzz(chardata);                                                        \
  563|    475|    }                                                                          \
conversion.cpp:_ZZ18populate_functionsvENK4$_24clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    124|    +[](std::span<const char> chardata) {                                      \
  555|    124|      const auto c =                                                           \
  556|    124|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    124|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    124|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    124|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    124|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    124|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    124|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    124|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    124|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    124|  constexpr auto _size = _name.size();                                \
  |  | 1183|    124|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    124|  return _nameof; }()
  ------------------
  561|    124|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    124|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    124|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    124|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    124|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    124|  constexpr auto _size = _name.size();                                \
  |  | 1183|    124|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    124|  return _nameof; }()
  ------------------
  562|    124|      c.fuzz(chardata);                                                        \
  563|    124|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    124|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    124|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    124|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    124|    static const bool do_print_testcase =
  181|    124|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    124|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 124]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    124|    do {
  189|       |      // step 0 - is the input valid?
  190|    124|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    124|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 124]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    124|                    From == UtfEncodings::UTF8) {
  198|    124|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 124]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    124|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    124|      const auto [output_length, length_agree] =
  204|    124|          calculate_length(from, inputisvalid);
  205|    124|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 124]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    124|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 18, False: 106]
  |  Branch (208:28): [True: 0, False: 18]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    124|      const auto [written, outputs_agree] =
  215|    124|          do_conversion(from, output_length, inputisvalid);
  216|    124|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 124]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    124|      return;
  221|    124|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    124|  }
_ZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS6_Lm18446744073709551615EEE:
  230|    124|  validation_result verify_valid_input(FromSpan src) const {
  231|    124|    validation_result ret{};
  232|       |
  233|    124|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    124|    const auto implementations = get_supported_implementations();
  235|    124|    std::vector<simdutf::result> results;
  236|    124|    results.reserve(implementations.size());
  237|       |
  238|    372|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 372, False: 124]
  ------------------
  239|    372|      results.push_back(
  240|    372|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|    372|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|    372|      const bool validation2 =
  245|    372|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|    372|                      src.data(), src.size());
  247|    372|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 372]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|    372|    }
  258|       |
  259|    124|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    124|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 124]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    124|    } else {
  273|    124|      ret.implementations_agree = true;
  274|    124|    }
  275|    124|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    124|      return r.error == simdutf::SUCCESS;
  277|    124|    });
  278|    124|    return ret;
  279|    124|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS6_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS5_S5_EEDaSJ_SM_:
  259|    248|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS6_Lm18446744073709551615EEEENKUlRKS5_E_clESI_:
  275|    336|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    336|      return r.error == simdutf::SUCCESS;
  277|    336|    });
_ZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE15count_the_inputENSt3__14spanIS6_Lm18446744073709551615EEE:
  289|    124|  bool count_the_input(FromSpan src) const {
  290|    124|    const auto implementations = get_supported_implementations();
  291|    124|    std::vector<std::size_t> results;
  292|    124|    results.reserve(implementations.size());
  293|       |
  294|    372|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 372, False: 124]
  ------------------
  295|    372|      std::size_t ret;
  296|    372|      if constexpr (From == UtfEncodings::UTF16BE) {
  297|    372|        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|       |      } else if constexpr (From == UtfEncodings::UTF8) {
  301|       |        ret = impl->count_utf8(src.data(), src.size());
  302|       |      }
  303|    372|      results.push_back(ret);
  304|    372|    }
  305|    124|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    124|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 124]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    124|    return true;
  321|    124|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE15count_the_inputENSt3__14spanIS6_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  305|    248|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE16calculate_lengthENSt3__14spanIS6_Lm18446744073709551615EEEb:
  342|    124|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    124|    length_result ret{};
  344|       |
  345|    124|    const auto implementations = get_supported_implementations();
  346|    124|    std::vector<std::size_t> results;
  347|    124|    results.reserve(implementations.size());
  348|       |
  349|    372|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 372, False: 124]
  ------------------
  350|    372|      const auto len = invoke_lengthcalc(impl, src);
  351|    372|      results.push_back(len);
  352|    372|      ret.length.push_back(len);
  353|    372|    }
  354|       |
  355|    124|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    124|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 124]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    124|    } else {
  375|    124|      ret.implementations_agree = true;
  376|    124|    }
  377|    124|    return ret;
  378|    124|  }
_ZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_mEEEmSF_NSt3__14spanIS6_Lm18446744073709551615EEE:
  338|    372|                                FromSpan src) const {
  339|    372|    return std::invoke(lengthcalc, impl, /*src.data(),*/ src.size());
  340|    372|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE16calculate_lengthENSt3__14spanIS6_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    248|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE13do_conversionENSt3__14spanIS6_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    124|                                  const bool inputisvalid) const {
  383|    124|    conversion_result ret{};
  384|       |
  385|    124|    const auto implementations = get_supported_implementations();
  386|       |
  387|    124|    std::vector<result<ConversionResult>> results;
  388|    124|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    124|    std::vector<std::vector<ToType>> outputbuffers;
  393|    124|    outputbuffers.reserve(implementations.size());
  394|    496|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 372, False: 124]
  ------------------
  395|    372|      auto impl = implementations[i];
  396|    372|      const ToType canary1{42};
  397|    372|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    372|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    372|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    372|      const auto success = [](const ConversionResult& r) -> bool {
  402|    372|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    372|          return r != 0;
  404|    372|        } else {
  405|    372|          return r.error == simdutf::error_code::SUCCESS;
  406|    372|        }
  407|    372|      }(implret1);
  408|    372|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    372|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    372|        const ToType canary2{25};
  414|    372|        const auto outputbuffer_first_run = outputbuffer;
  415|    372|        std::ranges::fill(outputbuffer, canary2);
  416|    372|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    372|                                          src.size(), outputbuffer.data());
  418|       |
  419|    372|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 372]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    372|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 318, False: 54]
  |  Branch (423:29): [True: 126, False: 192]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    126|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    126|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 126]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    126|        }
  440|    372|      }
  441|    372|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 126, False: 246]
  ------------------
  442|    372|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    124|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 18, False: 106]
  ------------------
  447|     54|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 54, False: 18]
  ------------------
  448|     54|        e.outputhash.clear();
  449|     54|      }
  450|     18|    }
  451|       |
  452|    124|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    124|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 124]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    124|    } else {
  474|    124|      ret.implementations_agree = true;
  475|    124|    }
  476|    124|    return ret;
  477|    124|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE13do_conversionENSt3__14spanIS6_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS5_E_clESM_:
  401|    372|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|    372|        } else {
  405|    372|          return r.error == simdutf::error_code::SUCCESS;
  406|    372|        }
  407|    372|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings0ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE13do_conversionENSt3__14spanIS6_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS5_ESU_EEDaSN_SQ_:
  452|    248|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_25clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    183|    +[](std::span<const char> chardata) {                                      \
  555|    183|      const auto c =                                                           \
  556|    183|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    183|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    183|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    183|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    183|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    183|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    183|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    183|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    183|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    183|  constexpr auto _size = _name.size();                                \
  |  | 1183|    183|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    183|  return _nameof; }()
  ------------------
  561|    183|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    183|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    183|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    183|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    183|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    183|  constexpr auto _size = _name.size();                                \
  |  | 1183|    183|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    183|  return _nameof; }()
  ------------------
  562|    183|      c.fuzz(chardata);                                                        \
  563|    183|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    183|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    183|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    183|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    183|    static const bool do_print_testcase =
  181|    183|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    183|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 183]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    183|    do {
  189|       |      // step 0 - is the input valid?
  190|    183|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    183|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 183]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    183|                    From == UtfEncodings::UTF8) {
  198|    183|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 183]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    183|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    183|      const auto [output_length, length_agree] =
  204|    183|          calculate_length(from, inputisvalid);
  205|    183|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 183]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    183|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 98, False: 85]
  |  Branch (208:28): [True: 0, False: 98]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    183|      const auto [written, outputs_agree] =
  215|    183|          do_conversion(from, output_length, inputisvalid);
  216|    183|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 183]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    183|      return;
  221|    183|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    183|  }
_ZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    183|  validation_result verify_valid_input(FromSpan src) const {
  231|    183|    validation_result ret{};
  232|       |
  233|    183|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    183|    const auto implementations = get_supported_implementations();
  235|    183|    std::vector<simdutf::result> results;
  236|    183|    results.reserve(implementations.size());
  237|       |
  238|    549|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 549, False: 183]
  ------------------
  239|    549|      results.push_back(
  240|    549|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|    549|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|    549|      const bool validation2 =
  245|    549|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|    549|                      src.data(), src.size());
  247|    549|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 549]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|    549|    }
  258|       |
  259|    183|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    183|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 183]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    183|    } else {
  273|    183|      ret.implementations_agree = true;
  274|    183|    }
  275|    183|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    183|      return r.error == simdutf::SUCCESS;
  277|    183|    });
  278|    183|    return ret;
  279|    183|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS7_S7_EEDaSJ_SM_:
  259|    366|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKS7_E_clESI_:
  275|    353|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    353|      return r.error == simdutf::SUCCESS;
  277|    353|    });
_ZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    183|  bool count_the_input(FromSpan src) const {
  290|    183|    const auto implementations = get_supported_implementations();
  291|    183|    std::vector<std::size_t> results;
  292|    183|    results.reserve(implementations.size());
  293|       |
  294|    549|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 549, False: 183]
  ------------------
  295|    549|      std::size_t ret;
  296|    549|      if constexpr (From == UtfEncodings::UTF16BE) {
  297|    549|        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|       |      } else if constexpr (From == UtfEncodings::UTF8) {
  301|       |        ret = impl->count_utf8(src.data(), src.size());
  302|       |      }
  303|    549|      results.push_back(ret);
  304|    549|    }
  305|    183|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    183|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 183]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    183|    return true;
  321|    183|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  305|    366|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    183|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    183|    length_result ret{};
  344|       |
  345|    183|    const auto implementations = get_supported_implementations();
  346|    183|    std::vector<std::size_t> results;
  347|    183|    results.reserve(implementations.size());
  348|       |
  349|    549|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 549, False: 183]
  ------------------
  350|    549|      const auto len = invoke_lengthcalc(impl, src);
  351|    549|      results.push_back(len);
  352|    549|      ret.length.push_back(len);
  353|    549|    }
  354|       |
  355|    183|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    183|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 183]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    183|    } else {
  375|    183|      ret.implementations_agree = true;
  376|    183|    }
  377|    183|    return ret;
  378|    183|  }
_ZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSF_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|    549|                                FromSpan src) const {
  331|    549|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|    549|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    366|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    183|                                  const bool inputisvalid) const {
  383|    183|    conversion_result ret{};
  384|       |
  385|    183|    const auto implementations = get_supported_implementations();
  386|       |
  387|    183|    std::vector<result<ConversionResult>> results;
  388|    183|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    183|    std::vector<std::vector<ToType>> outputbuffers;
  393|    183|    outputbuffers.reserve(implementations.size());
  394|    732|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 549, False: 183]
  ------------------
  395|    549|      auto impl = implementations[i];
  396|    549|      const ToType canary1{42};
  397|    549|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    549|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    549|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    549|      const auto success = [](const ConversionResult& r) -> bool {
  402|    549|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    549|          return r != 0;
  404|    549|        } else {
  405|    549|          return r.error == simdutf::error_code::SUCCESS;
  406|    549|        }
  407|    549|      }(implret1);
  408|    549|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    549|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    549|        const ToType canary2{25};
  414|    549|        const auto outputbuffer_first_run = outputbuffer;
  415|    549|        std::ranges::fill(outputbuffer, canary2);
  416|    549|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    549|                                          src.size(), outputbuffer.data());
  418|       |
  419|    549|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 549]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    549|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 255, False: 294]
  |  Branch (423:29): [True: 255, False: 0]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    255|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    255|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 255]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    255|        }
  440|    549|      }
  441|    549|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 255, False: 294]
  ------------------
  442|    549|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    183|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 98, False: 85]
  ------------------
  447|    294|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 294, False: 98]
  ------------------
  448|    294|        e.outputhash.clear();
  449|    294|      }
  450|     98|    }
  451|       |
  452|    183|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    183|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 183]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    183|    } else {
  474|    183|      ret.implementations_agree = true;
  475|    183|    }
  476|    183|    return ret;
  477|    183|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS7_E_clESM_:
  401|    549|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|    549|        } else {
  405|    549|          return r.error == simdutf::error_code::SUCCESS;
  406|    549|        }
  407|    549|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings0ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS7_ESU_EEDaSN_SQ_:
  452|    366|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_26clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    308|    +[](std::span<const char> chardata) {                                      \
  555|    308|      const auto c =                                                           \
  556|    308|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    308|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    308|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    308|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    308|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    308|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    308|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    308|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    308|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    308|  constexpr auto _size = _name.size();                                \
  |  | 1183|    308|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    308|  return _nameof; }()
  ------------------
  561|    308|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    308|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    308|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    308|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    308|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    308|  constexpr auto _size = _name.size();                                \
  |  | 1183|    308|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    308|  return _nameof; }()
  ------------------
  562|    308|      c.fuzz(chardata);                                                        \
  563|    308|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    308|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    308|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    308|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    308|    static const bool do_print_testcase =
  181|    308|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    308|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 308]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    308|    do {
  189|       |      // step 0 - is the input valid?
  190|    308|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    308|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 308]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    308|                    From == UtfEncodings::UTF8) {
  198|    308|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 308]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    308|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    308|      const auto [output_length, length_agree] =
  204|    308|          calculate_length(from, inputisvalid);
  205|    308|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 308]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    308|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 122, False: 186]
  |  Branch (208:28): [True: 0, False: 122]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    308|      const auto [written, outputs_agree] =
  215|    308|          do_conversion(from, output_length, inputisvalid);
  216|    308|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 308]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    308|      return;
  221|    308|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    308|  }
_ZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    308|  validation_result verify_valid_input(FromSpan src) const {
  231|    308|    validation_result ret{};
  232|       |
  233|    308|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    308|    const auto implementations = get_supported_implementations();
  235|    308|    std::vector<simdutf::result> results;
  236|    308|    results.reserve(implementations.size());
  237|       |
  238|    924|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 924, False: 308]
  ------------------
  239|    924|      results.push_back(
  240|    924|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|    924|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|    924|      const bool validation2 =
  245|    924|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|    924|                      src.data(), src.size());
  247|    924|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 924]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|    924|    }
  258|       |
  259|    308|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    308|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 308]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    308|    } else {
  273|    308|      ret.implementations_agree = true;
  274|    308|    }
  275|    308|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    308|      return r.error == simdutf::SUCCESS;
  277|    308|    });
  278|    308|    return ret;
  279|    308|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS7_S7_EEDaSJ_SM_:
  259|    616|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKS7_E_clESI_:
  275|    680|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    680|      return r.error == simdutf::SUCCESS;
  277|    680|    });
_ZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    308|  bool count_the_input(FromSpan src) const {
  290|    308|    const auto implementations = get_supported_implementations();
  291|    308|    std::vector<std::size_t> results;
  292|    308|    results.reserve(implementations.size());
  293|       |
  294|    924|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 924, False: 308]
  ------------------
  295|    924|      std::size_t ret;
  296|    924|      if constexpr (From == UtfEncodings::UTF16BE) {
  297|    924|        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|       |      } else if constexpr (From == UtfEncodings::UTF8) {
  301|       |        ret = impl->count_utf8(src.data(), src.size());
  302|       |      }
  303|    924|      results.push_back(ret);
  304|    924|    }
  305|    308|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    308|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 308]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    308|    return true;
  321|    308|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  305|    616|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    308|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    308|    length_result ret{};
  344|       |
  345|    308|    const auto implementations = get_supported_implementations();
  346|    308|    std::vector<std::size_t> results;
  347|    308|    results.reserve(implementations.size());
  348|       |
  349|    924|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 924, False: 308]
  ------------------
  350|    924|      const auto len = invoke_lengthcalc(impl, src);
  351|    924|      results.push_back(len);
  352|    924|      ret.length.push_back(len);
  353|    924|    }
  354|       |
  355|    308|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    308|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 308]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    308|    } else {
  375|    308|      ret.implementations_agree = true;
  376|    308|    }
  377|    308|    return ret;
  378|    308|  }
_ZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSF_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|    924|                                FromSpan src) const {
  331|    924|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|    924|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    616|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    308|                                  const bool inputisvalid) const {
  383|    308|    conversion_result ret{};
  384|       |
  385|    308|    const auto implementations = get_supported_implementations();
  386|       |
  387|    308|    std::vector<result<ConversionResult>> results;
  388|    308|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    308|    std::vector<std::vector<ToType>> outputbuffers;
  393|    308|    outputbuffers.reserve(implementations.size());
  394|  1.23k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 924, False: 308]
  ------------------
  395|    924|      auto impl = implementations[i];
  396|    924|      const ToType canary1{42};
  397|    924|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    924|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    924|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    924|      const auto success = [](const ConversionResult& r) -> bool {
  402|    924|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    924|          return r != 0;
  404|    924|        } else {
  405|    924|          return r.error == simdutf::error_code::SUCCESS;
  406|    924|        }
  407|    924|      }(implret1);
  408|    924|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    924|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    924|        const ToType canary2{25};
  414|    924|        const auto outputbuffer_first_run = outputbuffer;
  415|    924|        std::ranges::fill(outputbuffer, canary2);
  416|    924|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    924|                                          src.size(), outputbuffer.data());
  418|       |
  419|    924|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 924]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    924|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 558, False: 366]
  |  Branch (423:29): [True: 558, False: 0]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    558|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    558|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 558]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    558|        }
  440|    924|      }
  441|    924|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 558, False: 366]
  ------------------
  442|    924|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    308|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 122, False: 186]
  ------------------
  447|    366|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 366, False: 122]
  ------------------
  448|    366|        e.outputhash.clear();
  449|    366|      }
  450|    122|    }
  451|       |
  452|    308|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    308|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 308]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    308|    } else {
  474|    308|      ret.implementations_agree = true;
  475|    308|    }
  476|    308|    return ret;
  477|    308|  }
_ZZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS7_E_clESM_:
  401|    924|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|    924|        } else {
  405|    924|          return r.error == simdutf::error_code::SUCCESS;
  406|    924|        }
  407|    924|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings0ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS7_ESU_EEDaSN_SQ_:
  452|    616|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_27clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    132|    +[](std::span<const char> chardata) {                                      \
  555|    132|      const auto c =                                                           \
  556|    132|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    132|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    132|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    132|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    132|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    132|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    132|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    132|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    132|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    132|  constexpr auto _size = _name.size();                                \
  |  | 1183|    132|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    132|  return _nameof; }()
  ------------------
  561|    132|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    132|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    132|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    132|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    132|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    132|  constexpr auto _size = _name.size();                                \
  |  | 1183|    132|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    132|  return _nameof; }()
  ------------------
  562|    132|      c.fuzz(chardata);                                                        \
  563|    132|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    132|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    132|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    132|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    132|    static const bool do_print_testcase =
  181|    132|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    132|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 132]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    132|    do {
  189|       |      // step 0 - is the input valid?
  190|    132|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    132|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 132]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    132|                    From == UtfEncodings::UTF8) {
  198|    132|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 132]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    132|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    132|      const auto [output_length, length_agree] =
  204|    132|          calculate_length(from, inputisvalid);
  205|    132|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 132]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    132|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 18, False: 114]
  |  Branch (208:28): [True: 0, False: 18]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    132|      const auto [written, outputs_agree] =
  215|    132|          do_conversion(from, output_length, inputisvalid);
  216|    132|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 132]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    132|      return;
  221|    132|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    132|  }
_ZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS6_Lm18446744073709551615EEE:
  230|    132|  validation_result verify_valid_input(FromSpan src) const {
  231|    132|    validation_result ret{};
  232|       |
  233|    132|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    132|    const auto implementations = get_supported_implementations();
  235|    132|    std::vector<simdutf::result> results;
  236|    132|    results.reserve(implementations.size());
  237|       |
  238|    396|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 396, False: 132]
  ------------------
  239|    396|      results.push_back(
  240|    396|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|    396|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|    396|      const bool validation2 =
  245|    396|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|    396|                      src.data(), src.size());
  247|    396|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 396]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|    396|    }
  258|       |
  259|    132|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    132|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 132]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    132|    } else {
  273|    132|      ret.implementations_agree = true;
  274|    132|    }
  275|    132|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    132|      return r.error == simdutf::SUCCESS;
  277|    132|    });
  278|    132|    return ret;
  279|    132|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS6_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS5_S5_EEDaSJ_SM_:
  259|    264|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS6_Lm18446744073709551615EEEENKUlRKS5_E_clESI_:
  275|    360|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    360|      return r.error == simdutf::SUCCESS;
  277|    360|    });
_ZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE15count_the_inputENSt3__14spanIS6_Lm18446744073709551615EEE:
  289|    132|  bool count_the_input(FromSpan src) const {
  290|    132|    const auto implementations = get_supported_implementations();
  291|    132|    std::vector<std::size_t> results;
  292|    132|    results.reserve(implementations.size());
  293|       |
  294|    396|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 396, False: 132]
  ------------------
  295|    396|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|    396|      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|    396|        ret = impl->count_utf16le(src.data(), src.size());
  300|       |      } else if constexpr (From == UtfEncodings::UTF8) {
  301|       |        ret = impl->count_utf8(src.data(), src.size());
  302|       |      }
  303|    396|      results.push_back(ret);
  304|    396|    }
  305|    132|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    132|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 132]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    132|    return true;
  321|    132|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE15count_the_inputENSt3__14spanIS6_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  305|    264|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE16calculate_lengthENSt3__14spanIS6_Lm18446744073709551615EEEb:
  342|    132|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    132|    length_result ret{};
  344|       |
  345|    132|    const auto implementations = get_supported_implementations();
  346|    132|    std::vector<std::size_t> results;
  347|    132|    results.reserve(implementations.size());
  348|       |
  349|    396|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 396, False: 132]
  ------------------
  350|    396|      const auto len = invoke_lengthcalc(impl, src);
  351|    396|      results.push_back(len);
  352|    396|      ret.length.push_back(len);
  353|    396|    }
  354|       |
  355|    132|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    132|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 132]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    132|    } else {
  375|    132|      ret.implementations_agree = true;
  376|    132|    }
  377|    132|    return ret;
  378|    132|  }
_ZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_mEEEmSF_NSt3__14spanIS6_Lm18446744073709551615EEE:
  338|    396|                                FromSpan src) const {
  339|    396|    return std::invoke(lengthcalc, impl, /*src.data(),*/ src.size());
  340|    396|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE16calculate_lengthENSt3__14spanIS6_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    264|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE13do_conversionENSt3__14spanIS6_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    132|                                  const bool inputisvalid) const {
  383|    132|    conversion_result ret{};
  384|       |
  385|    132|    const auto implementations = get_supported_implementations();
  386|       |
  387|    132|    std::vector<result<ConversionResult>> results;
  388|    132|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    132|    std::vector<std::vector<ToType>> outputbuffers;
  393|    132|    outputbuffers.reserve(implementations.size());
  394|    528|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 396, False: 132]
  ------------------
  395|    396|      auto impl = implementations[i];
  396|    396|      const ToType canary1{42};
  397|    396|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    396|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    396|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    396|      const auto success = [](const ConversionResult& r) -> bool {
  402|    396|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    396|          return r != 0;
  404|    396|        } else {
  405|    396|          return r.error == simdutf::error_code::SUCCESS;
  406|    396|        }
  407|    396|      }(implret1);
  408|    396|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    396|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    396|        const ToType canary2{25};
  414|    396|        const auto outputbuffer_first_run = outputbuffer;
  415|    396|        std::ranges::fill(outputbuffer, canary2);
  416|    396|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    396|                                          src.size(), outputbuffer.data());
  418|       |
  419|    396|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 396]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    396|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 342, False: 54]
  |  Branch (423:29): [True: 135, False: 207]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    135|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    135|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 135]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    135|        }
  440|    396|      }
  441|    396|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 135, False: 261]
  ------------------
  442|    396|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    132|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 18, False: 114]
  ------------------
  447|     54|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 54, False: 18]
  ------------------
  448|     54|        e.outputhash.clear();
  449|     54|      }
  450|     18|    }
  451|       |
  452|    132|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    132|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 132]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    132|    } else {
  474|    132|      ret.implementations_agree = true;
  475|    132|    }
  476|    132|    return ret;
  477|    132|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE13do_conversionENSt3__14spanIS6_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS5_E_clESM_:
  401|    396|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|    396|        } else {
  405|    396|          return r.error == simdutf::error_code::SUCCESS;
  406|    396|        }
  407|    396|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings1ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDsmPcEE13do_conversionENSt3__14spanIS6_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS5_ESU_EEDaSN_SQ_:
  452|    264|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_28clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    193|    +[](std::span<const char> chardata) {                                      \
  555|    193|      const auto c =                                                           \
  556|    193|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    193|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    193|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    193|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    193|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    193|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    193|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    193|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    193|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    193|  constexpr auto _size = _name.size();                                \
  |  | 1183|    193|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    193|  return _nameof; }()
  ------------------
  561|    193|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    193|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    193|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    193|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    193|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    193|  constexpr auto _size = _name.size();                                \
  |  | 1183|    193|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    193|  return _nameof; }()
  ------------------
  562|    193|      c.fuzz(chardata);                                                        \
  563|    193|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    193|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    193|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    193|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    193|    static const bool do_print_testcase =
  181|    193|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    193|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 193]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    193|    do {
  189|       |      // step 0 - is the input valid?
  190|    193|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    193|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 193]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    193|                    From == UtfEncodings::UTF8) {
  198|    193|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 193]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    193|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    193|      const auto [output_length, length_agree] =
  204|    193|          calculate_length(from, inputisvalid);
  205|    193|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 193]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    193|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 99, False: 94]
  |  Branch (208:28): [True: 0, False: 99]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    193|      const auto [written, outputs_agree] =
  215|    193|          do_conversion(from, output_length, inputisvalid);
  216|    193|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 193]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    193|      return;
  221|    193|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    193|  }
_ZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    193|  validation_result verify_valid_input(FromSpan src) const {
  231|    193|    validation_result ret{};
  232|       |
  233|    193|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    193|    const auto implementations = get_supported_implementations();
  235|    193|    std::vector<simdutf::result> results;
  236|    193|    results.reserve(implementations.size());
  237|       |
  238|    579|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 579, False: 193]
  ------------------
  239|    579|      results.push_back(
  240|    579|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|    579|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|    579|      const bool validation2 =
  245|    579|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|    579|                      src.data(), src.size());
  247|    579|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 579]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|    579|    }
  258|       |
  259|    193|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    193|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 193]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    193|    } else {
  273|    193|      ret.implementations_agree = true;
  274|    193|    }
  275|    193|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    193|      return r.error == simdutf::SUCCESS;
  277|    193|    });
  278|    193|    return ret;
  279|    193|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS7_S7_EEDaSJ_SM_:
  259|    386|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKS7_E_clESI_:
  275|    381|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    381|      return r.error == simdutf::SUCCESS;
  277|    381|    });
_ZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    193|  bool count_the_input(FromSpan src) const {
  290|    193|    const auto implementations = get_supported_implementations();
  291|    193|    std::vector<std::size_t> results;
  292|    193|    results.reserve(implementations.size());
  293|       |
  294|    579|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 579, False: 193]
  ------------------
  295|    579|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|    579|      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|    579|        ret = impl->count_utf16le(src.data(), src.size());
  300|       |      } else if constexpr (From == UtfEncodings::UTF8) {
  301|       |        ret = impl->count_utf8(src.data(), src.size());
  302|       |      }
  303|    579|      results.push_back(ret);
  304|    579|    }
  305|    193|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    193|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 193]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    193|    return true;
  321|    193|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  305|    386|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    193|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    193|    length_result ret{};
  344|       |
  345|    193|    const auto implementations = get_supported_implementations();
  346|    193|    std::vector<std::size_t> results;
  347|    193|    results.reserve(implementations.size());
  348|       |
  349|    579|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 579, False: 193]
  ------------------
  350|    579|      const auto len = invoke_lengthcalc(impl, src);
  351|    579|      results.push_back(len);
  352|    579|      ret.length.push_back(len);
  353|    579|    }
  354|       |
  355|    193|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    193|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 193]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    193|    } else {
  375|    193|      ret.implementations_agree = true;
  376|    193|    }
  377|    193|    return ret;
  378|    193|  }
_ZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSF_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|    579|                                FromSpan src) const {
  331|    579|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|    579|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    386|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    193|                                  const bool inputisvalid) const {
  383|    193|    conversion_result ret{};
  384|       |
  385|    193|    const auto implementations = get_supported_implementations();
  386|       |
  387|    193|    std::vector<result<ConversionResult>> results;
  388|    193|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    193|    std::vector<std::vector<ToType>> outputbuffers;
  393|    193|    outputbuffers.reserve(implementations.size());
  394|    772|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 579, False: 193]
  ------------------
  395|    579|      auto impl = implementations[i];
  396|    579|      const ToType canary1{42};
  397|    579|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    579|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    579|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    579|      const auto success = [](const ConversionResult& r) -> bool {
  402|    579|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    579|          return r != 0;
  404|    579|        } else {
  405|    579|          return r.error == simdutf::error_code::SUCCESS;
  406|    579|        }
  407|    579|      }(implret1);
  408|    579|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    579|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    579|        const ToType canary2{25};
  414|    579|        const auto outputbuffer_first_run = outputbuffer;
  415|    579|        std::ranges::fill(outputbuffer, canary2);
  416|    579|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    579|                                          src.size(), outputbuffer.data());
  418|       |
  419|    579|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 579]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    579|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 282, False: 297]
  |  Branch (423:29): [True: 282, False: 0]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    282|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    282|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 282]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    282|        }
  440|    579|      }
  441|    579|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 282, False: 297]
  ------------------
  442|    579|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    193|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 99, False: 94]
  ------------------
  447|    297|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 297, False: 99]
  ------------------
  448|    297|        e.outputhash.clear();
  449|    297|      }
  450|     99|    }
  451|       |
  452|    193|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    193|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 193]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    193|    } else {
  474|    193|      ret.implementations_agree = true;
  475|    193|    }
  476|    193|    return ret;
  477|    193|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS7_E_clESM_:
  401|    579|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|    579|        } else {
  405|    579|          return r.error == simdutf::error_code::SUCCESS;
  406|    579|        }
  407|    579|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings1ELS0_3EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS7_ESU_EEDaSN_SQ_:
  452|    386|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_29clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    356|    +[](std::span<const char> chardata) {                                      \
  555|    356|      const auto c =                                                           \
  556|    356|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    356|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    356|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    356|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    356|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    356|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    356|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    356|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    356|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    356|  constexpr auto _size = _name.size();                                \
  |  | 1183|    356|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    356|  return _nameof; }()
  ------------------
  561|    356|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    356|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    356|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    356|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    356|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    356|  constexpr auto _size = _name.size();                                \
  |  | 1183|    356|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    356|  return _nameof; }()
  ------------------
  562|    356|      c.fuzz(chardata);                                                        \
  563|    356|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    356|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    356|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    356|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    356|    static const bool do_print_testcase =
  181|    356|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    356|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 356]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    356|    do {
  189|       |      // step 0 - is the input valid?
  190|    356|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    356|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 356]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    356|                    From == UtfEncodings::UTF8) {
  198|    356|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 356]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    356|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    356|      const auto [output_length, length_agree] =
  204|    356|          calculate_length(from, inputisvalid);
  205|    356|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 356]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    356|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 136, False: 220]
  |  Branch (208:28): [True: 0, False: 136]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    356|      const auto [written, outputs_agree] =
  215|    356|          do_conversion(from, output_length, inputisvalid);
  216|    356|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 356]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    356|      return;
  221|    356|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    356|  }
_ZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    356|  validation_result verify_valid_input(FromSpan src) const {
  231|    356|    validation_result ret{};
  232|       |
  233|    356|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    356|    const auto implementations = get_supported_implementations();
  235|    356|    std::vector<simdutf::result> results;
  236|    356|    results.reserve(implementations.size());
  237|       |
  238|  1.06k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.06k, False: 356]
  ------------------
  239|  1.06k|      results.push_back(
  240|  1.06k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.06k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.06k|      const bool validation2 =
  245|  1.06k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.06k|                      src.data(), src.size());
  247|  1.06k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.06k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.06k|    }
  258|       |
  259|    356|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    356|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 356]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    356|    } else {
  273|    356|      ret.implementations_agree = true;
  274|    356|    }
  275|    356|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    356|      return r.error == simdutf::SUCCESS;
  277|    356|    });
  278|    356|    return ret;
  279|    356|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS7_S7_EEDaSJ_SM_:
  259|    712|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKS7_E_clESI_:
  275|    796|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    796|      return r.error == simdutf::SUCCESS;
  277|    796|    });
_ZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    356|  bool count_the_input(FromSpan src) const {
  290|    356|    const auto implementations = get_supported_implementations();
  291|    356|    std::vector<std::size_t> results;
  292|    356|    results.reserve(implementations.size());
  293|       |
  294|  1.06k|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 1.06k, False: 356]
  ------------------
  295|  1.06k|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|  1.06k|      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|  1.06k|        ret = impl->count_utf16le(src.data(), src.size());
  300|       |      } else if constexpr (From == UtfEncodings::UTF8) {
  301|       |        ret = impl->count_utf8(src.data(), src.size());
  302|       |      }
  303|  1.06k|      results.push_back(ret);
  304|  1.06k|    }
  305|    356|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    356|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 356]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    356|    return true;
  321|    356|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  305|    712|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    356|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    356|    length_result ret{};
  344|       |
  345|    356|    const auto implementations = get_supported_implementations();
  346|    356|    std::vector<std::size_t> results;
  347|    356|    results.reserve(implementations.size());
  348|       |
  349|  1.06k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.06k, False: 356]
  ------------------
  350|  1.06k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.06k|      results.push_back(len);
  352|  1.06k|      ret.length.push_back(len);
  353|  1.06k|    }
  354|       |
  355|    356|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    356|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 356]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    356|    } else {
  375|    356|      ret.implementations_agree = true;
  376|    356|    }
  377|    356|    return ret;
  378|    356|  }
_ZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSF_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.06k|                                FromSpan src) const {
  331|  1.06k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.06k|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    712|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    356|                                  const bool inputisvalid) const {
  383|    356|    conversion_result ret{};
  384|       |
  385|    356|    const auto implementations = get_supported_implementations();
  386|       |
  387|    356|    std::vector<result<ConversionResult>> results;
  388|    356|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    356|    std::vector<std::vector<ToType>> outputbuffers;
  393|    356|    outputbuffers.reserve(implementations.size());
  394|  1.42k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.06k, False: 356]
  ------------------
  395|  1.06k|      auto impl = implementations[i];
  396|  1.06k|      const ToType canary1{42};
  397|  1.06k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.06k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.06k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.06k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.06k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.06k|          return r != 0;
  404|  1.06k|        } else {
  405|  1.06k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.06k|        }
  407|  1.06k|      }(implret1);
  408|  1.06k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.06k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.06k|        const ToType canary2{25};
  414|  1.06k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.06k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.06k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.06k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.06k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.06k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.06k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 660, False: 408]
  |  Branch (423:29): [True: 660, False: 0]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    660|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    660|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 660]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    660|        }
  440|  1.06k|      }
  441|  1.06k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 660, False: 408]
  ------------------
  442|  1.06k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    356|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 136, False: 220]
  ------------------
  447|    408|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 408, False: 136]
  ------------------
  448|    408|        e.outputhash.clear();
  449|    408|      }
  450|    136|    }
  451|       |
  452|    356|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    356|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 356]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    356|    } else {
  474|    356|      ret.implementations_agree = true;
  475|    356|    }
  476|    356|    return ret;
  477|    356|  }
_ZZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS7_E_clESM_:
  401|  1.06k|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|  1.06k|        } else {
  405|  1.06k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.06k|        }
  407|  1.06k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings1ELS0_2EMN7simdutf14implementationEKDoFmPKDsmEMS2_KDoFNS1_6resultES4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS7_ESU_EEDaSN_SQ_:
  452|    712|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_30clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    244|    +[](std::span<const char> chardata) {                                      \
  555|    244|      const auto c =                                                           \
  556|    244|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    244|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    244|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    244|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    244|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    244|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    244|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    244|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    244|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    244|  constexpr auto _size = _name.size();                                \
  |  | 1183|    244|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    244|  return _nameof; }()
  ------------------
  561|    244|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    244|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    244|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    244|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    244|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    244|  constexpr auto _size = _name.size();                                \
  |  | 1183|    244|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    244|  return _nameof; }()
  ------------------
  562|    244|      c.fuzz(chardata);                                                        \
  563|    244|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDimPcEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    244|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    244|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    244|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    244|    static const bool do_print_testcase =
  181|    244|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    244|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 244]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    244|    do {
  189|       |      // step 0 - is the input valid?
  190|    244|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    244|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 244]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|       |                    From == UtfEncodings::UTF8) {
  198|       |        if (!count_the_input(from) && !allow_implementations_to_differ)
  199|       |          break;
  200|       |      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    244|      const auto [output_length, length_agree] =
  204|    244|          calculate_length(from, inputisvalid);
  205|    244|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 244]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    244|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 209, False: 35]
  |  Branch (208:28): [True: 0, False: 209]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    244|      const auto [written, outputs_agree] =
  215|    244|          do_conversion(from, output_length, inputisvalid);
  216|    244|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 244]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    244|      return;
  221|    244|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    244|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDimPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS6_Lm18446744073709551615EEE:
  230|    244|  validation_result verify_valid_input(FromSpan src) const {
  231|    244|    validation_result ret{};
  232|       |
  233|    244|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    244|    const auto implementations = get_supported_implementations();
  235|    244|    std::vector<simdutf::result> results;
  236|    244|    results.reserve(implementations.size());
  237|       |
  238|    732|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 732, False: 244]
  ------------------
  239|    732|      results.push_back(
  240|    732|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|    732|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|    732|      const bool validation2 =
  245|    732|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|    732|                      src.data(), src.size());
  247|    732|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 732]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|    732|    }
  258|       |
  259|    244|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    244|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 244]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    244|    } else {
  273|    244|      ret.implementations_agree = true;
  274|    244|    }
  275|    244|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    244|      return r.error == simdutf::SUCCESS;
  277|    244|    });
  278|    244|    return ret;
  279|    244|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDimPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS6_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS5_S5_EEDaSJ_SM_:
  259|    488|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDimPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS6_Lm18446744073709551615EEEENKUlRKS5_E_clESI_:
  275|    314|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    314|      return r.error == simdutf::SUCCESS;
  277|    314|    });
_ZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDimPcEE16calculate_lengthENSt3__14spanIS6_Lm18446744073709551615EEEb:
  342|    244|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    244|    length_result ret{};
  344|       |
  345|    244|    const auto implementations = get_supported_implementations();
  346|    244|    std::vector<std::size_t> results;
  347|    244|    results.reserve(implementations.size());
  348|       |
  349|    732|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 732, False: 244]
  ------------------
  350|    732|      const auto len = invoke_lengthcalc(impl, src);
  351|    732|      results.push_back(len);
  352|    732|      ret.length.push_back(len);
  353|    732|    }
  354|       |
  355|    244|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    244|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 244]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    244|    } else {
  375|    244|      ret.implementations_agree = true;
  376|    244|    }
  377|    244|    return ret;
  378|    244|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDimPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_mEEEmSF_NSt3__14spanIS6_Lm18446744073709551615EEE:
  338|    732|                                FromSpan src) const {
  339|    732|    return std::invoke(lengthcalc, impl, /*src.data(),*/ src.size());
  340|    732|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDimPcEE16calculate_lengthENSt3__14spanIS6_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    488|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDimPcEE13do_conversionENSt3__14spanIS6_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    244|                                  const bool inputisvalid) const {
  383|    244|    conversion_result ret{};
  384|       |
  385|    244|    const auto implementations = get_supported_implementations();
  386|       |
  387|    244|    std::vector<result<ConversionResult>> results;
  388|    244|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    244|    std::vector<std::vector<ToType>> outputbuffers;
  393|    244|    outputbuffers.reserve(implementations.size());
  394|    976|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 732, False: 244]
  ------------------
  395|    732|      auto impl = implementations[i];
  396|    732|      const ToType canary1{42};
  397|    732|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    732|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    732|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    732|      const auto success = [](const ConversionResult& r) -> bool {
  402|    732|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    732|          return r != 0;
  404|    732|        } else {
  405|    732|          return r.error == simdutf::error_code::SUCCESS;
  406|    732|        }
  407|    732|      }(implret1);
  408|    732|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    732|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    732|        const ToType canary2{25};
  414|    732|        const auto outputbuffer_first_run = outputbuffer;
  415|    732|        std::ranges::fill(outputbuffer, canary2);
  416|    732|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    732|                                          src.size(), outputbuffer.data());
  418|       |
  419|    732|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 732]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    732|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 105, False: 627]
  |  Branch (423:29): [True: 78, False: 27]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|     78|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|     78|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 78]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|     78|        }
  440|    732|      }
  441|    732|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 78, False: 654]
  ------------------
  442|    732|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    244|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 209, False: 35]
  ------------------
  447|    627|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 627, False: 209]
  ------------------
  448|    627|        e.outputhash.clear();
  449|    627|      }
  450|    209|    }
  451|       |
  452|    244|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    244|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 244]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    244|    } else {
  474|    244|      ret.implementations_agree = true;
  475|    244|    }
  476|    244|    return ret;
  477|    244|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDimPcEE13do_conversionENSt3__14spanIS6_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS5_E_clESM_:
  401|    732|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|    732|        } else {
  405|    732|          return r.error == simdutf::error_code::SUCCESS;
  406|    732|        }
  407|    732|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings3ELS0_4EMN7simdutf14implementationEKDoFmmEMS2_KDoFNS1_6resultEPKDimPcEE13do_conversionENSt3__14spanIS6_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS5_ESU_EEDaSN_SQ_:
  452|    488|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_31clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    339|    +[](std::span<const char> chardata) {                                      \
  555|    339|      const auto c =                                                           \
  556|    339|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    339|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    339|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    339|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    339|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    339|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    339|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    339|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    339|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    339|  constexpr auto _size = _name.size();                                \
  |  | 1183|    339|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    339|  return _nameof; }()
  ------------------
  561|    339|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    339|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    339|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    339|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    339|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    339|  constexpr auto _size = _name.size();                                \
  |  | 1183|    339|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    339|  return _nameof; }()
  ------------------
  562|    339|      c.fuzz(chardata);                                                        \
  563|    339|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    339|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    339|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    339|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    339|    static const bool do_print_testcase =
  181|    339|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    339|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 339]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    339|    do {
  189|       |      // step 0 - is the input valid?
  190|    339|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    339|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 339]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|       |                    From == UtfEncodings::UTF8) {
  198|       |        if (!count_the_input(from) && !allow_implementations_to_differ)
  199|       |          break;
  200|       |      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    339|      const auto [output_length, length_agree] =
  204|    339|          calculate_length(from, inputisvalid);
  205|    339|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 339]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    339|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 249, False: 90]
  |  Branch (208:28): [True: 0, False: 249]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    339|      const auto [written, outputs_agree] =
  215|    339|          do_conversion(from, output_length, inputisvalid);
  216|    339|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 339]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    339|      return;
  221|    339|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    339|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    339|  validation_result verify_valid_input(FromSpan src) const {
  231|    339|    validation_result ret{};
  232|       |
  233|    339|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    339|    const auto implementations = get_supported_implementations();
  235|    339|    std::vector<simdutf::result> results;
  236|    339|    results.reserve(implementations.size());
  237|       |
  238|  1.01k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.01k, False: 339]
  ------------------
  239|  1.01k|      results.push_back(
  240|  1.01k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.01k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.01k|      const bool validation2 =
  245|  1.01k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.01k|                      src.data(), src.size());
  247|  1.01k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.01k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.01k|    }
  258|       |
  259|    339|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    339|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 339]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    339|    } else {
  273|    339|      ret.implementations_agree = true;
  274|    339|    }
  275|    339|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    339|      return r.error == simdutf::SUCCESS;
  277|    339|    });
  278|    339|    return ret;
  279|    339|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS7_S7_EEDaSJ_SM_:
  259|    678|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKS7_E_clESI_:
  275|    519|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    519|      return r.error == simdutf::SUCCESS;
  277|    519|    });
_ZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    339|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    339|    length_result ret{};
  344|       |
  345|    339|    const auto implementations = get_supported_implementations();
  346|    339|    std::vector<std::size_t> results;
  347|    339|    results.reserve(implementations.size());
  348|       |
  349|  1.01k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.01k, False: 339]
  ------------------
  350|  1.01k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.01k|      results.push_back(len);
  352|  1.01k|      ret.length.push_back(len);
  353|  1.01k|    }
  354|       |
  355|    339|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    339|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 339]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    339|    } else {
  375|    339|      ret.implementations_agree = true;
  376|    339|    }
  377|    339|    return ret;
  378|    339|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSF_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.01k|                                FromSpan src) const {
  331|  1.01k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.01k|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    678|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    339|                                  const bool inputisvalid) const {
  383|    339|    conversion_result ret{};
  384|       |
  385|    339|    const auto implementations = get_supported_implementations();
  386|       |
  387|    339|    std::vector<result<ConversionResult>> results;
  388|    339|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    339|    std::vector<std::vector<ToType>> outputbuffers;
  393|    339|    outputbuffers.reserve(implementations.size());
  394|  1.35k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.01k, False: 339]
  ------------------
  395|  1.01k|      auto impl = implementations[i];
  396|  1.01k|      const ToType canary1{42};
  397|  1.01k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.01k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.01k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.01k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.01k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.01k|          return r != 0;
  404|  1.01k|        } else {
  405|  1.01k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.01k|        }
  407|  1.01k|      }(implret1);
  408|  1.01k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.01k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.01k|        const ToType canary2{25};
  414|  1.01k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.01k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.01k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.01k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.01k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.01k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.01k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 270, False: 747]
  |  Branch (423:29): [True: 270, False: 0]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    270|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    270|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 270]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    270|        }
  440|  1.01k|      }
  441|  1.01k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 270, False: 747]
  ------------------
  442|  1.01k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    339|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 249, False: 90]
  ------------------
  447|    747|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 747, False: 249]
  ------------------
  448|    747|        e.outputhash.clear();
  449|    747|      }
  450|    249|    }
  451|       |
  452|    339|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    339|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 339]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    339|    } else {
  474|    339|      ret.implementations_agree = true;
  475|    339|    }
  476|    339|    return ret;
  477|    339|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS7_E_clESM_:
  401|  1.01k|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|  1.01k|        } else {
  405|  1.01k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.01k|        }
  407|  1.01k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings3ELS0_0EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS7_ESU_EEDaSN_SQ_:
  452|    678|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_32clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    386|    +[](std::span<const char> chardata) {                                      \
  555|    386|      const auto c =                                                           \
  556|    386|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    386|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    386|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    386|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    386|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    386|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    386|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    386|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    386|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    386|  constexpr auto _size = _name.size();                                \
  |  | 1183|    386|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    386|  return _nameof; }()
  ------------------
  561|    386|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    386|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    386|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    386|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    386|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    386|  constexpr auto _size = _name.size();                                \
  |  | 1183|    386|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    386|  return _nameof; }()
  ------------------
  562|    386|      c.fuzz(chardata);                                                        \
  563|    386|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    386|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    386|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    386|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    386|    static const bool do_print_testcase =
  181|    386|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    386|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 386]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    386|    do {
  189|       |      // step 0 - is the input valid?
  190|    386|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    386|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 386]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|       |                    From == UtfEncodings::UTF8) {
  198|       |        if (!count_the_input(from) && !allow_implementations_to_differ)
  199|       |          break;
  200|       |      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    386|      const auto [output_length, length_agree] =
  204|    386|          calculate_length(from, inputisvalid);
  205|    386|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 386]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    386|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 298, False: 88]
  |  Branch (208:28): [True: 0, False: 298]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    386|      const auto [written, outputs_agree] =
  215|    386|          do_conversion(from, output_length, inputisvalid);
  216|    386|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 386]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    386|      return;
  221|    386|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    386|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    386|  validation_result verify_valid_input(FromSpan src) const {
  231|    386|    validation_result ret{};
  232|       |
  233|    386|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    386|    const auto implementations = get_supported_implementations();
  235|    386|    std::vector<simdutf::result> results;
  236|    386|    results.reserve(implementations.size());
  237|       |
  238|  1.15k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.15k, False: 386]
  ------------------
  239|  1.15k|      results.push_back(
  240|  1.15k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.15k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.15k|      const bool validation2 =
  245|  1.15k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.15k|                      src.data(), src.size());
  247|  1.15k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.15k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.15k|    }
  258|       |
  259|    386|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    386|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 386]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    386|    } else {
  273|    386|      ret.implementations_agree = true;
  274|    386|    }
  275|    386|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    386|      return r.error == simdutf::SUCCESS;
  277|    386|    });
  278|    386|    return ret;
  279|    386|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS7_S7_EEDaSJ_SM_:
  259|    772|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKS7_E_clESI_:
  275|    562|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    562|      return r.error == simdutf::SUCCESS;
  277|    562|    });
_ZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    386|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    386|    length_result ret{};
  344|       |
  345|    386|    const auto implementations = get_supported_implementations();
  346|    386|    std::vector<std::size_t> results;
  347|    386|    results.reserve(implementations.size());
  348|       |
  349|  1.15k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.15k, False: 386]
  ------------------
  350|  1.15k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.15k|      results.push_back(len);
  352|  1.15k|      ret.length.push_back(len);
  353|  1.15k|    }
  354|       |
  355|    386|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    386|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 386]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    386|    } else {
  375|    386|      ret.implementations_agree = true;
  376|    386|    }
  377|    386|    return ret;
  378|    386|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSF_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.15k|                                FromSpan src) const {
  331|  1.15k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.15k|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    772|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    386|                                  const bool inputisvalid) const {
  383|    386|    conversion_result ret{};
  384|       |
  385|    386|    const auto implementations = get_supported_implementations();
  386|       |
  387|    386|    std::vector<result<ConversionResult>> results;
  388|    386|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    386|    std::vector<std::vector<ToType>> outputbuffers;
  393|    386|    outputbuffers.reserve(implementations.size());
  394|  1.54k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.15k, False: 386]
  ------------------
  395|  1.15k|      auto impl = implementations[i];
  396|  1.15k|      const ToType canary1{42};
  397|  1.15k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.15k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.15k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.15k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.15k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.15k|          return r != 0;
  404|  1.15k|        } else {
  405|  1.15k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.15k|        }
  407|  1.15k|      }(implret1);
  408|  1.15k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.15k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.15k|        const ToType canary2{25};
  414|  1.15k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.15k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.15k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.15k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.15k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.15k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.15k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 264, False: 894]
  |  Branch (423:29): [True: 264, False: 0]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    264|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    264|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 264]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    264|        }
  440|  1.15k|      }
  441|  1.15k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 264, False: 894]
  ------------------
  442|  1.15k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    386|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 298, False: 88]
  ------------------
  447|    894|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 894, False: 298]
  ------------------
  448|    894|        e.outputhash.clear();
  449|    894|      }
  450|    298|    }
  451|       |
  452|    386|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    386|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 386]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    386|    } else {
  474|    386|      ret.implementations_agree = true;
  475|    386|    }
  476|    386|    return ret;
  477|    386|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS7_E_clESM_:
  401|  1.15k|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|  1.15k|        } else {
  405|  1.15k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.15k|        }
  407|  1.15k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings3ELS0_1EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS7_ESU_EEDaSN_SQ_:
  452|    772|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_33clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    430|    +[](std::span<const char> chardata) {                                      \
  555|    430|      const auto c =                                                           \
  556|    430|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    430|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    430|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    430|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    430|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    430|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    430|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    430|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    430|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    430|  constexpr auto _size = _name.size();                                \
  |  | 1183|    430|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    430|  return _nameof; }()
  ------------------
  561|    430|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    430|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    430|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    430|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    430|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    430|  constexpr auto _size = _name.size();                                \
  |  | 1183|    430|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    430|  return _nameof; }()
  ------------------
  562|    430|      c.fuzz(chardata);                                                        \
  563|    430|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPcEE4fuzzENSt3__14spanIKcLm18446744073709551615EEE:
  175|    430|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    430|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    430|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    430|    static const bool do_print_testcase =
  181|    430|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    430|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 430]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    430|    do {
  189|       |      // step 0 - is the input valid?
  190|    430|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    430|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 430]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|       |                    From == UtfEncodings::UTF8) {
  198|       |        if (!count_the_input(from) && !allow_implementations_to_differ)
  199|       |          break;
  200|       |      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    430|      const auto [output_length, length_agree] =
  204|    430|          calculate_length(from, inputisvalid);
  205|    430|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 430]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    430|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 327, False: 103]
  |  Branch (208:28): [True: 0, False: 327]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    430|      const auto [written, outputs_agree] =
  215|    430|          do_conversion(from, output_length, inputisvalid);
  216|    430|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 430]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    430|      return;
  221|    430|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    430|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    430|  validation_result verify_valid_input(FromSpan src) const {
  231|    430|    validation_result ret{};
  232|       |
  233|    430|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    430|    const auto implementations = get_supported_implementations();
  235|    430|    std::vector<simdutf::result> results;
  236|    430|    results.reserve(implementations.size());
  237|       |
  238|  1.29k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.29k, False: 430]
  ------------------
  239|  1.29k|      results.push_back(
  240|  1.29k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.29k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.29k|      const bool validation2 =
  245|  1.29k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.29k|                      src.data(), src.size());
  247|  1.29k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.29k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.29k|    }
  258|       |
  259|    430|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    430|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 430]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    430|    } else {
  273|    430|      ret.implementations_agree = true;
  274|    430|    }
  275|    430|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    430|      return r.error == simdutf::SUCCESS;
  277|    430|    });
  278|    430|    return ret;
  279|    430|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS7_S7_EEDaSJ_SM_:
  259|    860|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKS7_E_clESI_:
  275|    636|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    636|      return r.error == simdutf::SUCCESS;
  277|    636|    });
_ZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    430|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    430|    length_result ret{};
  344|       |
  345|    430|    const auto implementations = get_supported_implementations();
  346|    430|    std::vector<std::size_t> results;
  347|    430|    results.reserve(implementations.size());
  348|       |
  349|  1.29k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.29k, False: 430]
  ------------------
  350|  1.29k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.29k|      results.push_back(len);
  352|  1.29k|      ret.length.push_back(len);
  353|  1.29k|    }
  354|       |
  355|    430|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    430|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 430]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    430|    } else {
  375|    430|      ret.implementations_agree = true;
  376|    430|    }
  377|    430|    return ret;
  378|    430|  }
_ZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSF_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.29k|                                FromSpan src) const {
  331|  1.29k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.29k|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    860|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    430|                                  const bool inputisvalid) const {
  383|    430|    conversion_result ret{};
  384|       |
  385|    430|    const auto implementations = get_supported_implementations();
  386|       |
  387|    430|    std::vector<result<ConversionResult>> results;
  388|    430|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    430|    std::vector<std::vector<ToType>> outputbuffers;
  393|    430|    outputbuffers.reserve(implementations.size());
  394|  1.72k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.29k, False: 430]
  ------------------
  395|  1.29k|      auto impl = implementations[i];
  396|  1.29k|      const ToType canary1{42};
  397|  1.29k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.29k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.29k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.29k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.29k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.29k|          return r != 0;
  404|  1.29k|        } else {
  405|  1.29k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.29k|        }
  407|  1.29k|      }(implret1);
  408|  1.29k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.29k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.29k|        const ToType canary2{25};
  414|  1.29k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.29k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.29k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.29k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.29k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.29k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.29k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 309, False: 981]
  |  Branch (423:29): [True: 309, False: 0]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    309|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    309|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 309]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    309|        }
  440|  1.29k|      }
  441|  1.29k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 309, False: 981]
  ------------------
  442|  1.29k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    430|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 327, False: 103]
  ------------------
  447|    981|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 981, False: 327]
  ------------------
  448|    981|        e.outputhash.clear();
  449|    981|      }
  450|    327|    }
  451|       |
  452|    430|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    430|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 430]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    430|    } else {
  474|    430|      ret.implementations_agree = true;
  475|    430|    }
  476|    430|    return ret;
  477|    430|  }
_ZZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS7_E_clESM_:
  401|  1.29k|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|  1.29k|        } else {
  405|  1.29k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.29k|        }
  407|  1.29k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings3ELS0_2EMN7simdutf14implementationEKDoFmPKDimEMS2_KDoFNS1_6resultES4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS7_ESU_EEDaSN_SQ_:
  452|    860|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_34clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    335|    +[](std::span<const char> chardata) {                                      \
  555|    335|      const auto c =                                                           \
  556|    335|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    335|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    335|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    335|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    335|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    335|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    335|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    335|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    335|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    335|  constexpr auto _size = _name.size();                                \
  |  | 1183|    335|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    335|  return _nameof; }()
  ------------------
  561|    335|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    335|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    335|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    335|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    335|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    335|  constexpr auto _size = _name.size();                                \
  |  | 1183|    335|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    335|  return _nameof; }()
  ------------------
  562|    335|      c.fuzz(chardata);                                                        \
  563|    335|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPcEE4fuzzENSt3__14spanIS3_Lm18446744073709551615EEE:
  175|    335|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    335|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    335|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    335|    static const bool do_print_testcase =
  181|    335|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    335|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 335]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    335|    do {
  189|       |      // step 0 - is the input valid?
  190|    335|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    335|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 335]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    335|                    From == UtfEncodings::UTF8) {
  198|    335|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 335]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    335|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    335|      const auto [output_length, length_agree] =
  204|    335|          calculate_length(from, inputisvalid);
  205|    335|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 335]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    335|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 208, False: 127]
  |  Branch (208:28): [True: 0, False: 208]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    335|      const auto [written, outputs_agree] =
  215|    335|          do_conversion(from, output_length, inputisvalid);
  216|    335|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 335]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    335|      return;
  221|    335|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    335|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    335|  validation_result verify_valid_input(FromSpan src) const {
  231|    335|    validation_result ret{};
  232|       |
  233|    335|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    335|    const auto implementations = get_supported_implementations();
  235|    335|    std::vector<simdutf::result> results;
  236|    335|    results.reserve(implementations.size());
  237|       |
  238|  1.00k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.00k, False: 335]
  ------------------
  239|  1.00k|      results.push_back(
  240|  1.00k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.00k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.00k|      const bool validation2 =
  245|  1.00k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.00k|                      src.data(), src.size());
  247|  1.00k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.00k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.00k|    }
  258|       |
  259|    335|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    335|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 335]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    335|    } else {
  273|    335|      ret.implementations_agree = true;
  274|    335|    }
  275|    335|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    335|      return r.error == simdutf::SUCCESS;
  277|    335|    });
  278|    335|    return ret;
  279|    335|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS7_S7_EEDaSJ_SM_:
  259|    670|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPcEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKS7_E_clESI_:
  275|    589|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    589|      return r.error == simdutf::SUCCESS;
  277|    589|    });
_ZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPcEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    335|  bool count_the_input(FromSpan src) const {
  290|    335|    const auto implementations = get_supported_implementations();
  291|    335|    std::vector<std::size_t> results;
  292|    335|    results.reserve(implementations.size());
  293|       |
  294|  1.00k|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 1.00k, False: 335]
  ------------------
  295|  1.00k|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|  1.00k|      } else if constexpr (From == UtfEncodings::UTF8) {
  301|  1.00k|        ret = impl->count_utf8(src.data(), src.size());
  302|  1.00k|      }
  303|  1.00k|      results.push_back(ret);
  304|  1.00k|    }
  305|    335|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    335|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 335]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    335|    return true;
  321|    335|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPcEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  305|    670|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    335|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    335|    length_result ret{};
  344|       |
  345|    335|    const auto implementations = get_supported_implementations();
  346|    335|    std::vector<std::size_t> results;
  347|    335|    results.reserve(implementations.size());
  348|       |
  349|  1.00k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.00k, False: 335]
  ------------------
  350|  1.00k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.00k|      results.push_back(len);
  352|  1.00k|      ret.length.push_back(len);
  353|  1.00k|    }
  354|       |
  355|    335|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    335|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 335]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    335|    } else {
  375|    335|      ret.implementations_agree = true;
  376|    335|    }
  377|    335|    return ret;
  378|    335|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSF_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.00k|                                FromSpan src) const {
  331|  1.00k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.00k|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    670|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    335|                                  const bool inputisvalid) const {
  383|    335|    conversion_result ret{};
  384|       |
  385|    335|    const auto implementations = get_supported_implementations();
  386|       |
  387|    335|    std::vector<result<ConversionResult>> results;
  388|    335|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    335|    std::vector<std::vector<ToType>> outputbuffers;
  393|    335|    outputbuffers.reserve(implementations.size());
  394|  1.34k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.00k, False: 335]
  ------------------
  395|  1.00k|      auto impl = implementations[i];
  396|  1.00k|      const ToType canary1{42};
  397|  1.00k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.00k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.00k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.00k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.00k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.00k|          return r != 0;
  404|  1.00k|        } else {
  405|  1.00k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.00k|        }
  407|  1.00k|      }(implret1);
  408|  1.00k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.00k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.00k|        const ToType canary2{25};
  414|  1.00k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.00k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.00k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.00k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.00k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.00k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.00k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 381, False: 624]
  |  Branch (423:29): [True: 360, False: 21]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    360|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    360|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 360]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    360|        }
  440|  1.00k|      }
  441|  1.00k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 360, False: 645]
  ------------------
  442|  1.00k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    335|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 208, False: 127]
  ------------------
  447|    624|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 624, False: 208]
  ------------------
  448|    624|        e.outputhash.clear();
  449|    624|      }
  450|    208|    }
  451|       |
  452|    335|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    335|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 335]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    335|    } else {
  474|    335|      ret.implementations_agree = true;
  475|    335|    }
  476|    335|    return ret;
  477|    335|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS7_E_clESM_:
  401|  1.00k|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|  1.00k|        } else {
  405|  1.00k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.00k|        }
  407|  1.00k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings2ELS0_4EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS7_ESU_EEDaSN_SQ_:
  452|    670|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_35clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    451|    +[](std::span<const char> chardata) {                                      \
  555|    451|      const auto c =                                                           \
  556|    451|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    451|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    451|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    451|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    451|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    451|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    451|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    451|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    451|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    451|  constexpr auto _size = _name.size();                                \
  |  | 1183|    451|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    451|  return _nameof; }()
  ------------------
  561|    451|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    451|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    451|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    451|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    451|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    451|  constexpr auto _size = _name.size();                                \
  |  | 1183|    451|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    451|  return _nameof; }()
  ------------------
  562|    451|      c.fuzz(chardata);                                                        \
  563|    451|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE4fuzzENSt3__14spanIS3_Lm18446744073709551615EEE:
  175|    451|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    451|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    451|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    451|    static const bool do_print_testcase =
  181|    451|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    451|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 451]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    451|    do {
  189|       |      // step 0 - is the input valid?
  190|    451|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    451|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 451]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    451|                    From == UtfEncodings::UTF8) {
  198|    451|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 451]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    451|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    451|      const auto [output_length, length_agree] =
  204|    451|          calculate_length(from, inputisvalid);
  205|    451|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 451]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    451|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 271, False: 180]
  |  Branch (208:28): [True: 0, False: 271]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    451|      const auto [written, outputs_agree] =
  215|    451|          do_conversion(from, output_length, inputisvalid);
  216|    451|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 451]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    451|      return;
  221|    451|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    451|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    451|  validation_result verify_valid_input(FromSpan src) const {
  231|    451|    validation_result ret{};
  232|       |
  233|    451|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    451|    const auto implementations = get_supported_implementations();
  235|    451|    std::vector<simdutf::result> results;
  236|    451|    results.reserve(implementations.size());
  237|       |
  238|  1.35k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.35k, False: 451]
  ------------------
  239|  1.35k|      results.push_back(
  240|  1.35k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.35k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.35k|      const bool validation2 =
  245|  1.35k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.35k|                      src.data(), src.size());
  247|  1.35k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.35k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.35k|    }
  258|       |
  259|    451|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    451|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 451]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    451|    } else {
  273|    451|      ret.implementations_agree = true;
  274|    451|    }
  275|    451|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    451|      return r.error == simdutf::SUCCESS;
  277|    451|    });
  278|    451|    return ret;
  279|    451|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS7_S7_EEDaSJ_SM_:
  259|    902|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKS7_E_clESI_:
  275|    811|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    811|      return r.error == simdutf::SUCCESS;
  277|    811|    });
_ZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    451|  bool count_the_input(FromSpan src) const {
  290|    451|    const auto implementations = get_supported_implementations();
  291|    451|    std::vector<std::size_t> results;
  292|    451|    results.reserve(implementations.size());
  293|       |
  294|  1.35k|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 1.35k, False: 451]
  ------------------
  295|  1.35k|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|  1.35k|      } else if constexpr (From == UtfEncodings::UTF8) {
  301|  1.35k|        ret = impl->count_utf8(src.data(), src.size());
  302|  1.35k|      }
  303|  1.35k|      results.push_back(ret);
  304|  1.35k|    }
  305|    451|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    451|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 451]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    451|    return true;
  321|    451|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  305|    902|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    451|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    451|    length_result ret{};
  344|       |
  345|    451|    const auto implementations = get_supported_implementations();
  346|    451|    std::vector<std::size_t> results;
  347|    451|    results.reserve(implementations.size());
  348|       |
  349|  1.35k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.35k, False: 451]
  ------------------
  350|  1.35k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.35k|      results.push_back(len);
  352|  1.35k|      ret.length.push_back(len);
  353|  1.35k|    }
  354|       |
  355|    451|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    451|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 451]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    451|    } else {
  375|    451|      ret.implementations_agree = true;
  376|    451|    }
  377|    451|    return ret;
  378|    451|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSF_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.35k|                                FromSpan src) const {
  331|  1.35k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.35k|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    902|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    451|                                  const bool inputisvalid) const {
  383|    451|    conversion_result ret{};
  384|       |
  385|    451|    const auto implementations = get_supported_implementations();
  386|       |
  387|    451|    std::vector<result<ConversionResult>> results;
  388|    451|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    451|    std::vector<std::vector<ToType>> outputbuffers;
  393|    451|    outputbuffers.reserve(implementations.size());
  394|  1.80k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.35k, False: 451]
  ------------------
  395|  1.35k|      auto impl = implementations[i];
  396|  1.35k|      const ToType canary1{42};
  397|  1.35k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.35k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.35k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.35k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.35k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.35k|          return r != 0;
  404|  1.35k|        } else {
  405|  1.35k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.35k|        }
  407|  1.35k|      }(implret1);
  408|  1.35k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.35k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.35k|        const ToType canary2{25};
  414|  1.35k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.35k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.35k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.35k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.35k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.35k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.35k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 540, False: 813]
  |  Branch (423:29): [True: 540, False: 0]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    540|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    540|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 540]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    540|        }
  440|  1.35k|      }
  441|  1.35k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 540, False: 813]
  ------------------
  442|  1.35k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    451|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 271, False: 180]
  ------------------
  447|    813|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 813, False: 271]
  ------------------
  448|    813|        e.outputhash.clear();
  449|    813|      }
  450|    271|    }
  451|       |
  452|    451|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    451|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 451]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    451|    } else {
  474|    451|      ret.implementations_agree = true;
  475|    451|    }
  476|    451|    return ret;
  477|    451|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS7_E_clESM_:
  401|  1.35k|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|  1.35k|        } else {
  405|  1.35k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.35k|        }
  407|  1.35k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings2ELS0_0EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS7_ESU_EEDaSN_SQ_:
  452|    902|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_36clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    391|    +[](std::span<const char> chardata) {                                      \
  555|    391|      const auto c =                                                           \
  556|    391|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    391|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    391|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    391|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    391|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    391|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    391|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    391|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    391|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    391|  constexpr auto _size = _name.size();                                \
  |  | 1183|    391|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    391|  return _nameof; }()
  ------------------
  561|    391|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    391|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    391|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    391|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    391|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    391|  constexpr auto _size = _name.size();                                \
  |  | 1183|    391|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    391|  return _nameof; }()
  ------------------
  562|    391|      c.fuzz(chardata);                                                        \
  563|    391|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE4fuzzENSt3__14spanIS3_Lm18446744073709551615EEE:
  175|    391|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    391|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    391|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    391|    static const bool do_print_testcase =
  181|    391|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    391|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 391]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    391|    do {
  189|       |      // step 0 - is the input valid?
  190|    391|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    391|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 391]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    391|                    From == UtfEncodings::UTF8) {
  198|    391|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 391]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    391|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    391|      const auto [output_length, length_agree] =
  204|    391|          calculate_length(from, inputisvalid);
  205|    391|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 391]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    391|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 273, False: 118]
  |  Branch (208:28): [True: 0, False: 273]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    391|      const auto [written, outputs_agree] =
  215|    391|          do_conversion(from, output_length, inputisvalid);
  216|    391|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 391]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    391|      return;
  221|    391|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    391|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    391|  validation_result verify_valid_input(FromSpan src) const {
  231|    391|    validation_result ret{};
  232|       |
  233|    391|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    391|    const auto implementations = get_supported_implementations();
  235|    391|    std::vector<simdutf::result> results;
  236|    391|    results.reserve(implementations.size());
  237|       |
  238|  1.17k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.17k, False: 391]
  ------------------
  239|  1.17k|      results.push_back(
  240|  1.17k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.17k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.17k|      const bool validation2 =
  245|  1.17k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.17k|                      src.data(), src.size());
  247|  1.17k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.17k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.17k|    }
  258|       |
  259|    391|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    391|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 391]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    391|    } else {
  273|    391|      ret.implementations_agree = true;
  274|    391|    }
  275|    391|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    391|      return r.error == simdutf::SUCCESS;
  277|    391|    });
  278|    391|    return ret;
  279|    391|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS7_S7_EEDaSJ_SM_:
  259|    782|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKS7_E_clESI_:
  275|    627|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    627|      return r.error == simdutf::SUCCESS;
  277|    627|    });
_ZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    391|  bool count_the_input(FromSpan src) const {
  290|    391|    const auto implementations = get_supported_implementations();
  291|    391|    std::vector<std::size_t> results;
  292|    391|    results.reserve(implementations.size());
  293|       |
  294|  1.17k|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 1.17k, False: 391]
  ------------------
  295|  1.17k|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|  1.17k|      } else if constexpr (From == UtfEncodings::UTF8) {
  301|  1.17k|        ret = impl->count_utf8(src.data(), src.size());
  302|  1.17k|      }
  303|  1.17k|      results.push_back(ret);
  304|  1.17k|    }
  305|    391|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    391|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 391]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    391|    return true;
  321|    391|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  305|    782|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    391|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    391|    length_result ret{};
  344|       |
  345|    391|    const auto implementations = get_supported_implementations();
  346|    391|    std::vector<std::size_t> results;
  347|    391|    results.reserve(implementations.size());
  348|       |
  349|  1.17k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.17k, False: 391]
  ------------------
  350|  1.17k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.17k|      results.push_back(len);
  352|  1.17k|      ret.length.push_back(len);
  353|  1.17k|    }
  354|       |
  355|    391|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    391|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 391]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    391|    } else {
  375|    391|      ret.implementations_agree = true;
  376|    391|    }
  377|    391|    return ret;
  378|    391|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSF_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.17k|                                FromSpan src) const {
  331|  1.17k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.17k|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    782|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    391|                                  const bool inputisvalid) const {
  383|    391|    conversion_result ret{};
  384|       |
  385|    391|    const auto implementations = get_supported_implementations();
  386|       |
  387|    391|    std::vector<result<ConversionResult>> results;
  388|    391|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    391|    std::vector<std::vector<ToType>> outputbuffers;
  393|    391|    outputbuffers.reserve(implementations.size());
  394|  1.56k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.17k, False: 391]
  ------------------
  395|  1.17k|      auto impl = implementations[i];
  396|  1.17k|      const ToType canary1{42};
  397|  1.17k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.17k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.17k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.17k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.17k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.17k|          return r != 0;
  404|  1.17k|        } else {
  405|  1.17k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.17k|        }
  407|  1.17k|      }(implret1);
  408|  1.17k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.17k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.17k|        const ToType canary2{25};
  414|  1.17k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.17k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.17k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.17k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.17k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.17k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.17k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 354, False: 819]
  |  Branch (423:29): [True: 354, False: 0]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    354|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    354|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 354]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    354|        }
  440|  1.17k|      }
  441|  1.17k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 354, False: 819]
  ------------------
  442|  1.17k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    391|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 273, False: 118]
  ------------------
  447|    819|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 819, False: 273]
  ------------------
  448|    819|        e.outputhash.clear();
  449|    819|      }
  450|    273|    }
  451|       |
  452|    391|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    391|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 391]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    391|    } else {
  474|    391|      ret.implementations_agree = true;
  475|    391|    }
  476|    391|    return ret;
  477|    391|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS7_E_clESM_:
  401|  1.17k|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|  1.17k|        } else {
  405|  1.17k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.17k|        }
  407|  1.17k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings2ELS0_1EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDsEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS7_ESU_EEDaSN_SQ_:
  452|    782|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_37clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    459|    +[](std::span<const char> chardata) {                                      \
  555|    459|      const auto c =                                                           \
  556|    459|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    459|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    459|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    459|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    459|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    459|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    459|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    459|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    459|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    459|  constexpr auto _size = _name.size();                                \
  |  | 1183|    459|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    459|  return _nameof; }()
  ------------------
  561|    459|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    459|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    459|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    459|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    459|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    459|  constexpr auto _size = _name.size();                                \
  |  | 1183|    459|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    459|  return _nameof; }()
  ------------------
  562|    459|      c.fuzz(chardata);                                                        \
  563|    459|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDiEE4fuzzENSt3__14spanIS3_Lm18446744073709551615EEE:
  175|    459|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    459|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    459|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    459|    static const bool do_print_testcase =
  181|    459|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    459|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 459]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    459|    do {
  189|       |      // step 0 - is the input valid?
  190|    459|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    459|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 459]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|    459|                    From == UtfEncodings::UTF8) {
  198|    459|        if (!count_the_input(from) && !allow_implementations_to_differ)
  ------------------
  |  Branch (198:13): [True: 0, False: 459]
  |  Branch (198:39): [True: 0, Folded]
  ------------------
  199|      0|          break;
  200|    459|      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    459|      const auto [output_length, length_agree] =
  204|    459|          calculate_length(from, inputisvalid);
  205|    459|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 459]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    459|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 297, False: 162]
  |  Branch (208:28): [True: 0, False: 297]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    459|      const auto [written, outputs_agree] =
  215|    459|          do_conversion(from, output_length, inputisvalid);
  216|    459|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 459]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    459|      return;
  221|    459|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    459|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  230|    459|  validation_result verify_valid_input(FromSpan src) const {
  231|    459|    validation_result ret{};
  232|       |
  233|    459|    auto input_validation = ValidationFunctionTrait<From>::ValidationWithErrors;
  234|    459|    const auto implementations = get_supported_implementations();
  235|    459|    std::vector<simdutf::result> results;
  236|    459|    results.reserve(implementations.size());
  237|       |
  238|  1.37k|    for (auto impl : implementations) {
  ------------------
  |  Branch (238:20): [True: 1.37k, False: 459]
  ------------------
  239|  1.37k|      results.push_back(
  240|  1.37k|          std::invoke(input_validation, impl, src.data(), src.size()));
  241|       |
  242|       |      // make sure the validation variant that returns a bool agrees
  243|  1.37k|      const bool validation1 = results.back().error == simdutf::SUCCESS;
  244|  1.37k|      const bool validation2 =
  245|  1.37k|          std::invoke(ValidationFunctionTrait<From>::Validation, impl,
  246|  1.37k|                      src.data(), src.size());
  247|  1.37k|      if (validation1 != validation2) {
  ------------------
  |  Branch (247:11): [True: 0, False: 1.37k]
  ------------------
  248|      0|        std::cerr << "begin errormessage for verify_valid_input()\n";
  249|      0|        std::cerr << ValidationFunctionTrait<From>::ValidationWithErrorsName
  250|      0|                  << " gives " << validation1 << " while "
  251|      0|                  << ValidationFunctionTrait<From>::ValidationName << " gave "
  252|      0|                  << validation2 << " for implementation " << impl->name()
  253|      0|                  << '\n';
  254|      0|        std::cerr << "end errormessage\n";
  255|      0|        std::abort();
  256|      0|      }
  257|  1.37k|    }
  258|       |
  259|    459|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  260|    459|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (260:9): [True: 0, False: 459]
  ------------------
  261|      0|      std::cerr << "begin errormessage for verify_valid_input()\n";
  262|      0|      std::cerr << "in fuzz case for "
  263|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  264|      0|                << " invoked with " << src.size() << " elements:\n";
  265|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (265:31): [True: 0, False: 0]
  ------------------
  266|      0|        std::cerr << "got return " << std::dec << results[i]
  267|      0|                  << " from implementation " << implementations[i]->name()
  268|      0|                  << '\n';
  269|      0|      }
  270|      0|      std::cerr << "end errormessage\n";
  271|      0|      ret.implementations_agree = false;
  272|    459|    } else {
  273|    459|      ret.implementations_agree = true;
  274|    459|    }
  275|    459|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    459|      return r.error == simdutf::SUCCESS;
  277|    459|    });
  278|    459|    return ret;
  279|    459|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clIS7_S7_EEDaSJ_SM_:
  259|    918|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDiEE18verify_valid_inputIvQneT_LS0_4EEENSB_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKS7_E_clESI_:
  275|    783|    ret.valid = std::ranges::all_of(results, [](const simdutf::result& r) {
  276|    783|      return r.error == simdutf::SUCCESS;
  277|    783|    });
_ZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDiEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEE:
  289|    459|  bool count_the_input(FromSpan src) const {
  290|    459|    const auto implementations = get_supported_implementations();
  291|    459|    std::vector<std::size_t> results;
  292|    459|    results.reserve(implementations.size());
  293|       |
  294|  1.37k|    for (auto impl : implementations) {
  ------------------
  |  Branch (294:20): [True: 1.37k, False: 459]
  ------------------
  295|  1.37k|      std::size_t ret;
  296|       |      if constexpr (From == UtfEncodings::UTF16BE) {
  297|       |        ret = impl->count_utf16be(src.data(), src.size());
  298|       |      } else if constexpr (From == UtfEncodings::UTF16LE) {
  299|       |        ret = impl->count_utf16le(src.data(), src.size());
  300|  1.37k|      } else if constexpr (From == UtfEncodings::UTF8) {
  301|  1.37k|        ret = impl->count_utf8(src.data(), src.size());
  302|  1.37k|      }
  303|  1.37k|      results.push_back(ret);
  304|  1.37k|    }
  305|    459|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  306|    459|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (306:9): [True: 0, False: 459]
  ------------------
  307|      0|      std::cerr << "begin errormessage for count_the_input()\n";
  308|      0|      std::cerr << "in fuzz case for "
  309|      0|                << ValidationFunctionTrait<From>::ValidationWithErrorsName
  310|      0|                << " invoked with " << src.size() << " elements:\n";
  311|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (311:31): [True: 0, False: 0]
  ------------------
  312|      0|        std::cerr << "got return " << std::dec << results[i]
  313|      0|                  << " from implementation " << implementations[i]->name()
  314|      0|                  << '\n';
  315|      0|      }
  316|      0|      std::cerr << "end errormessage\n";
  317|      0|      return false;
  318|      0|    }
  319|       |
  320|    459|    return true;
  321|    459|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDiEE15count_the_inputENSt3__14spanIS3_Lm18446744073709551615EEEENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  305|    918|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDiEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    459|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    459|    length_result ret{};
  344|       |
  345|    459|    const auto implementations = get_supported_implementations();
  346|    459|    std::vector<std::size_t> results;
  347|    459|    results.reserve(implementations.size());
  348|       |
  349|  1.37k|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 1.37k, False: 459]
  ------------------
  350|  1.37k|      const auto len = invoke_lengthcalc(impl, src);
  351|  1.37k|      results.push_back(len);
  352|  1.37k|      ret.length.push_back(len);
  353|  1.37k|    }
  354|       |
  355|    459|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    459|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 459]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    459|    } else {
  375|    459|      ret.implementations_agree = true;
  376|    459|    }
  377|    459|    return ret;
  378|    459|  }
_ZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDiEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSF_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|  1.37k|                                FromSpan src) const {
  331|  1.37k|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|  1.37k|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDiEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSH_SK_:
  355|    918|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEb:
  382|    459|                                  const bool inputisvalid) const {
  383|    459|    conversion_result ret{};
  384|       |
  385|    459|    const auto implementations = get_supported_implementations();
  386|       |
  387|    459|    std::vector<result<ConversionResult>> results;
  388|    459|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    459|    std::vector<std::vector<ToType>> outputbuffers;
  393|    459|    outputbuffers.reserve(implementations.size());
  394|  1.83k|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 1.37k, False: 459]
  ------------------
  395|  1.37k|      auto impl = implementations[i];
  396|  1.37k|      const ToType canary1{42};
  397|  1.37k|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|  1.37k|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|  1.37k|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|  1.37k|      const auto success = [](const ConversionResult& r) -> bool {
  402|  1.37k|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|  1.37k|          return r != 0;
  404|  1.37k|        } else {
  405|  1.37k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.37k|        }
  407|  1.37k|      }(implret1);
  408|  1.37k|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|  1.37k|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|  1.37k|        const ToType canary2{25};
  414|  1.37k|        const auto outputbuffer_first_run = outputbuffer;
  415|  1.37k|        std::ranges::fill(outputbuffer, canary2);
  416|  1.37k|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|  1.37k|                                          src.size(), outputbuffer.data());
  418|       |
  419|  1.37k|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 1.37k]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|  1.37k|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 486, False: 891]
  |  Branch (423:29): [True: 486, False: 0]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    486|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    486|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 486]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    486|        }
  440|  1.37k|      }
  441|  1.37k|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 486, False: 891]
  ------------------
  442|  1.37k|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    459|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 297, False: 162]
  ------------------
  447|    891|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 891, False: 297]
  ------------------
  448|    891|        e.outputhash.clear();
  449|    891|      }
  450|    297|    }
  451|       |
  452|    459|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    459|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 459]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    459|    } else {
  474|    459|      ret.implementations_agree = true;
  475|    459|    }
  476|    459|    return ret;
  477|    459|  }
_ZZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKS7_E_clESM_:
  401|  1.37k|      const auto success = [](const ConversionResult& r) -> bool {
  402|       |        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|       |          return r != 0;
  404|  1.37k|        } else {
  405|  1.37k|          return r.error == simdutf::error_code::SUCCESS;
  406|  1.37k|        }
  407|  1.37k|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings2ELS0_3EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFNS1_6resultES4_mPDiEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSC_6vectorImNSC_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultIS7_ESU_EEDaSN_SQ_:
  452|    918|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_38clENSt3__14spanIKcLm18446744073709551615EEE:
  554|     51|    +[](std::span<const char> chardata) {                                      \
  555|     51|      const auto c =                                                           \
  556|     51|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|     51|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|     51|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|     51|              &I::lenfunc, &I::conversionfunc,                                 \
  560|     51|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|     51|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     51|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     51|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     51|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     51|  constexpr auto _size = _name.size();                                \
  |  | 1183|     51|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     51|  return _nameof; }()
  ------------------
  561|     51|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|     51|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     51|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     51|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     51|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     51|  constexpr auto _size = _name.size();                                \
  |  | 1183|     51|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     51|  return _nameof; }()
  ------------------
  562|     51|      c.fuzz(chardata);                                                        \
  563|     51|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings4ELS0_3EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDiEE4fuzzENSt3__14spanIS5_Lm18446744073709551615EEE:
  175|     51|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|     51|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|     51|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|     51|    static const bool do_print_testcase =
  181|     51|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|     51|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 51]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|     51|    do {
  189|       |      // step 0 - is the input valid?
  190|     51|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|     51|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 51]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|       |                    From == UtfEncodings::UTF8) {
  198|       |        if (!count_the_input(from) && !allow_implementations_to_differ)
  199|       |          break;
  200|       |      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|     51|      const auto [output_length, length_agree] =
  204|     51|          calculate_length(from, inputisvalid);
  205|     51|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 51]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|     51|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 0, False: 51]
  |  Branch (208:28): [True: 0, False: 0]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|     51|      const auto [written, outputs_agree] =
  215|     51|          do_conversion(from, output_length, inputisvalid);
  216|     51|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 51]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|     51|      return;
  221|     51|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|     51|  }
_ZNK10ConversionIL12UtfEncodings4ELS0_3EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDiEE18verify_valid_inputIvQeqT_LS0_4EEENSA_17validation_resultENSt3__14spanIS5_Lm18446744073709551615EEE:
  283|     51|  validation_result verify_valid_input(FromSpan) const {
  284|       |    // all latin1 input is valid. there is no simdutf validation function for
  285|       |    // it.
  286|     51|    return validation_result{.valid = true, .implementations_agree = true};
  287|     51|  }
_ZNK10ConversionIL12UtfEncodings4ELS0_3EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDiEE16calculate_lengthENSt3__14spanIS5_Lm18446744073709551615EEEb:
  342|     51|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|     51|    length_result ret{};
  344|       |
  345|     51|    const auto implementations = get_supported_implementations();
  346|     51|    std::vector<std::size_t> results;
  347|     51|    results.reserve(implementations.size());
  348|       |
  349|    153|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 153, False: 51]
  ------------------
  350|    153|      const auto len = invoke_lengthcalc(impl, src);
  351|    153|      results.push_back(len);
  352|    153|      ret.length.push_back(len);
  353|    153|    }
  354|       |
  355|     51|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|     51|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 51]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|     51|    } else {
  375|     51|      ret.implementations_agree = true;
  376|     51|    }
  377|     51|    return ret;
  378|     51|  }
_ZNK10ConversionIL12UtfEncodings4ELS0_3EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDiEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_mEEEmSE_NSt3__14spanIS5_Lm18446744073709551615EEE:
  338|    153|                                FromSpan src) const {
  339|    153|    return std::invoke(lengthcalc, impl, /*src.data(),*/ src.size());
  340|    153|  }
_ZZNK10ConversionIL12UtfEncodings4ELS0_3EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDiEE16calculate_lengthENSt3__14spanIS5_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    102|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings4ELS0_3EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDiEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|     51|                                  const bool inputisvalid) const {
  383|     51|    conversion_result ret{};
  384|       |
  385|     51|    const auto implementations = get_supported_implementations();
  386|       |
  387|     51|    std::vector<result<ConversionResult>> results;
  388|     51|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|     51|    std::vector<std::vector<ToType>> outputbuffers;
  393|     51|    outputbuffers.reserve(implementations.size());
  394|    204|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 153, False: 51]
  ------------------
  395|    153|      auto impl = implementations[i];
  396|    153|      const ToType canary1{42};
  397|    153|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    153|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    153|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    153|      const auto success = [](const ConversionResult& r) -> bool {
  402|    153|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    153|          return r != 0;
  404|    153|        } else {
  405|    153|          return r.error == simdutf::error_code::SUCCESS;
  406|    153|        }
  407|    153|      }(implret1);
  408|    153|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    153|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    153|        const ToType canary2{25};
  414|    153|        const auto outputbuffer_first_run = outputbuffer;
  415|    153|        std::ranges::fill(outputbuffer, canary2);
  416|    153|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    153|                                          src.size(), outputbuffer.data());
  418|       |
  419|    153|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 153]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    153|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 153, False: 0]
  |  Branch (423:29): [True: 147, False: 6]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    147|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    147|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 147]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    147|        }
  440|    153|      }
  441|    153|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 147, False: 6]
  ------------------
  442|    153|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|     51|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 0, False: 51]
  ------------------
  447|      0|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 0, False: 0]
  ------------------
  448|      0|        e.outputhash.clear();
  449|      0|      }
  450|      0|    }
  451|       |
  452|     51|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|     51|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 51]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|     51|    } else {
  474|     51|      ret.implementations_agree = true;
  475|     51|    }
  476|     51|    return ret;
  477|     51|  }
_ZZNK10ConversionIL12UtfEncodings4ELS0_3EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDiEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|    153|      const auto success = [](const ConversionResult& r) -> bool {
  402|    153|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    153|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|    153|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings4ELS0_3EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDiEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    102|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_39clENSt3__14spanIKcLm18446744073709551615EEE:
  554|     54|    +[](std::span<const char> chardata) {                                      \
  555|     54|      const auto c =                                                           \
  556|     54|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|     54|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|     54|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|     54|              &I::lenfunc, &I::conversionfunc,                                 \
  560|     54|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|     54|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     54|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     54|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     54|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     54|  constexpr auto _size = _name.size();                                \
  |  | 1183|     54|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     54|  return _nameof; }()
  ------------------
  561|     54|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|     54|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     54|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     54|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     54|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     54|  constexpr auto _size = _name.size();                                \
  |  | 1183|     54|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     54|  return _nameof; }()
  ------------------
  562|     54|      c.fuzz(chardata);                                                        \
  563|     54|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings4ELS0_0EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE4fuzzENSt3__14spanIS5_Lm18446744073709551615EEE:
  175|     54|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|     54|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|     54|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|     54|    static const bool do_print_testcase =
  181|     54|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|     54|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 54]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|     54|    do {
  189|       |      // step 0 - is the input valid?
  190|     54|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|     54|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 54]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|       |                    From == UtfEncodings::UTF8) {
  198|       |        if (!count_the_input(from) && !allow_implementations_to_differ)
  199|       |          break;
  200|       |      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|     54|      const auto [output_length, length_agree] =
  204|     54|          calculate_length(from, inputisvalid);
  205|     54|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 54]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|     54|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 0, False: 54]
  |  Branch (208:28): [True: 0, False: 0]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|     54|      const auto [written, outputs_agree] =
  215|     54|          do_conversion(from, output_length, inputisvalid);
  216|     54|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 54]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|     54|      return;
  221|     54|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|     54|  }
_ZNK10ConversionIL12UtfEncodings4ELS0_0EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE18verify_valid_inputIvQeqT_LS0_4EEENSA_17validation_resultENSt3__14spanIS5_Lm18446744073709551615EEE:
  283|     54|  validation_result verify_valid_input(FromSpan) const {
  284|       |    // all latin1 input is valid. there is no simdutf validation function for
  285|       |    // it.
  286|     54|    return validation_result{.valid = true, .implementations_agree = true};
  287|     54|  }
_ZNK10ConversionIL12UtfEncodings4ELS0_0EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE16calculate_lengthENSt3__14spanIS5_Lm18446744073709551615EEEb:
  342|     54|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|     54|    length_result ret{};
  344|       |
  345|     54|    const auto implementations = get_supported_implementations();
  346|     54|    std::vector<std::size_t> results;
  347|     54|    results.reserve(implementations.size());
  348|       |
  349|    162|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 162, False: 54]
  ------------------
  350|    162|      const auto len = invoke_lengthcalc(impl, src);
  351|    162|      results.push_back(len);
  352|    162|      ret.length.push_back(len);
  353|    162|    }
  354|       |
  355|     54|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|     54|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 54]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|     54|    } else {
  375|     54|      ret.implementations_agree = true;
  376|     54|    }
  377|     54|    return ret;
  378|     54|  }
_ZNK10ConversionIL12UtfEncodings4ELS0_0EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_mEEEmSE_NSt3__14spanIS5_Lm18446744073709551615EEE:
  338|    162|                                FromSpan src) const {
  339|    162|    return std::invoke(lengthcalc, impl, /*src.data(),*/ src.size());
  340|    162|  }
_ZZNK10ConversionIL12UtfEncodings4ELS0_0EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE16calculate_lengthENSt3__14spanIS5_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    108|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings4ELS0_0EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|     54|                                  const bool inputisvalid) const {
  383|     54|    conversion_result ret{};
  384|       |
  385|     54|    const auto implementations = get_supported_implementations();
  386|       |
  387|     54|    std::vector<result<ConversionResult>> results;
  388|     54|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|     54|    std::vector<std::vector<ToType>> outputbuffers;
  393|     54|    outputbuffers.reserve(implementations.size());
  394|    216|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 162, False: 54]
  ------------------
  395|    162|      auto impl = implementations[i];
  396|    162|      const ToType canary1{42};
  397|    162|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    162|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    162|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    162|      const auto success = [](const ConversionResult& r) -> bool {
  402|    162|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    162|          return r != 0;
  404|    162|        } else {
  405|    162|          return r.error == simdutf::error_code::SUCCESS;
  406|    162|        }
  407|    162|      }(implret1);
  408|    162|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    162|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    162|        const ToType canary2{25};
  414|    162|        const auto outputbuffer_first_run = outputbuffer;
  415|    162|        std::ranges::fill(outputbuffer, canary2);
  416|    162|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    162|                                          src.size(), outputbuffer.data());
  418|       |
  419|    162|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 162]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    162|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 162, False: 0]
  |  Branch (423:29): [True: 156, False: 6]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    156|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    156|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 156]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    156|        }
  440|    162|      }
  441|    162|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 156, False: 6]
  ------------------
  442|    162|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|     54|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 0, False: 54]
  ------------------
  447|      0|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 0, False: 0]
  ------------------
  448|      0|        e.outputhash.clear();
  449|      0|      }
  450|      0|    }
  451|       |
  452|     54|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|     54|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 54]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|     54|    } else {
  474|     54|      ret.implementations_agree = true;
  475|     54|    }
  476|     54|    return ret;
  477|     54|  }
_ZZNK10ConversionIL12UtfEncodings4ELS0_0EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|    162|      const auto success = [](const ConversionResult& r) -> bool {
  402|    162|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    162|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|    162|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings4ELS0_0EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    108|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_40clENSt3__14spanIKcLm18446744073709551615EEE:
  554|     41|    +[](std::span<const char> chardata) {                                      \
  555|     41|      const auto c =                                                           \
  556|     41|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|     41|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|     41|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|     41|              &I::lenfunc, &I::conversionfunc,                                 \
  560|     41|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|     41|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     41|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     41|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     41|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     41|  constexpr auto _size = _name.size();                                \
  |  | 1183|     41|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     41|  return _nameof; }()
  ------------------
  561|     41|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|     41|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|     41|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|     41|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|     41|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|     41|  constexpr auto _size = _name.size();                                \
  |  | 1183|     41|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|     41|  return _nameof; }()
  ------------------
  562|     41|      c.fuzz(chardata);                                                        \
  563|     41|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings4ELS0_1EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE4fuzzENSt3__14spanIS5_Lm18446744073709551615EEE:
  175|     41|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|     41|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|     41|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|     41|    static const bool do_print_testcase =
  181|     41|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|     41|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 41]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|     41|    do {
  189|       |      // step 0 - is the input valid?
  190|     41|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|     41|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 41]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|       |                    From == UtfEncodings::UTF8) {
  198|       |        if (!count_the_input(from) && !allow_implementations_to_differ)
  199|       |          break;
  200|       |      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|     41|      const auto [output_length, length_agree] =
  204|     41|          calculate_length(from, inputisvalid);
  205|     41|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 41]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|     41|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 0, False: 41]
  |  Branch (208:28): [True: 0, False: 0]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|     41|      const auto [written, outputs_agree] =
  215|     41|          do_conversion(from, output_length, inputisvalid);
  216|     41|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 41]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|     41|      return;
  221|     41|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|     41|  }
_ZNK10ConversionIL12UtfEncodings4ELS0_1EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE18verify_valid_inputIvQeqT_LS0_4EEENSA_17validation_resultENSt3__14spanIS5_Lm18446744073709551615EEE:
  283|     41|  validation_result verify_valid_input(FromSpan) const {
  284|       |    // all latin1 input is valid. there is no simdutf validation function for
  285|       |    // it.
  286|     41|    return validation_result{.valid = true, .implementations_agree = true};
  287|     41|  }
_ZNK10ConversionIL12UtfEncodings4ELS0_1EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE16calculate_lengthENSt3__14spanIS5_Lm18446744073709551615EEEb:
  342|     41|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|     41|    length_result ret{};
  344|       |
  345|     41|    const auto implementations = get_supported_implementations();
  346|     41|    std::vector<std::size_t> results;
  347|     41|    results.reserve(implementations.size());
  348|       |
  349|    123|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 123, False: 41]
  ------------------
  350|    123|      const auto len = invoke_lengthcalc(impl, src);
  351|    123|      results.push_back(len);
  352|    123|      ret.length.push_back(len);
  353|    123|    }
  354|       |
  355|     41|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|     41|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 41]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|     41|    } else {
  375|     41|      ret.implementations_agree = true;
  376|     41|    }
  377|     41|    return ret;
  378|     41|  }
_ZNK10ConversionIL12UtfEncodings4ELS0_1EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_mEEEmSE_NSt3__14spanIS5_Lm18446744073709551615EEE:
  338|    123|                                FromSpan src) const {
  339|    123|    return std::invoke(lengthcalc, impl, /*src.data(),*/ src.size());
  340|    123|  }
_ZZNK10ConversionIL12UtfEncodings4ELS0_1EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE16calculate_lengthENSt3__14spanIS5_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|     82|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings4ELS0_1EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|     41|                                  const bool inputisvalid) const {
  383|     41|    conversion_result ret{};
  384|       |
  385|     41|    const auto implementations = get_supported_implementations();
  386|       |
  387|     41|    std::vector<result<ConversionResult>> results;
  388|     41|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|     41|    std::vector<std::vector<ToType>> outputbuffers;
  393|     41|    outputbuffers.reserve(implementations.size());
  394|    164|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 123, False: 41]
  ------------------
  395|    123|      auto impl = implementations[i];
  396|    123|      const ToType canary1{42};
  397|    123|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    123|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    123|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    123|      const auto success = [](const ConversionResult& r) -> bool {
  402|    123|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    123|          return r != 0;
  404|    123|        } else {
  405|    123|          return r.error == simdutf::error_code::SUCCESS;
  406|    123|        }
  407|    123|      }(implret1);
  408|    123|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    123|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    123|        const ToType canary2{25};
  414|    123|        const auto outputbuffer_first_run = outputbuffer;
  415|    123|        std::ranges::fill(outputbuffer, canary2);
  416|    123|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    123|                                          src.size(), outputbuffer.data());
  418|       |
  419|    123|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 123]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    123|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 123, False: 0]
  |  Branch (423:29): [True: 117, False: 6]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    117|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    117|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 117]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    117|        }
  440|    123|      }
  441|    123|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 117, False: 6]
  ------------------
  442|    123|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|     41|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 0, False: 41]
  ------------------
  447|      0|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 0, False: 0]
  ------------------
  448|      0|        e.outputhash.clear();
  449|      0|      }
  450|      0|    }
  451|       |
  452|     41|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|     41|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 41]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|     41|    } else {
  474|     41|      ret.implementations_agree = true;
  475|     41|    }
  476|     41|    return ret;
  477|     41|  }
_ZZNK10ConversionIL12UtfEncodings4ELS0_1EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|    123|      const auto success = [](const ConversionResult& r) -> bool {
  402|    123|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    123|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|    123|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings4ELS0_1EMN7simdutf14implementationEKDoFmmEMS2_KDoFmPKcmPDsEE13do_conversionENSt3__14spanIS5_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|     82|    auto neq = [](const auto& a, const auto& b) { return a != b; };
conversion.cpp:_ZZ18populate_functionsvENK4$_41clENSt3__14spanIKcLm18446744073709551615EEE:
  554|    243|    +[](std::span<const char> chardata) {                                      \
  555|    243|      const auto c =                                                           \
  556|    243|          Conversion<ENCODING_FROM_CONVERSION_NAME(&I::conversionfunc),        \
  557|    243|                     ENCODING_TO_CONVERSION_NAME(&I::conversionfunc),          \
  558|    243|                     decltype(&I::lenfunc), decltype(&I::conversionfunc)>{     \
  559|    243|              &I::lenfunc, &I::conversionfunc,                                 \
  560|    243|              std::string{NAMEOF(&I::lenfunc)},                                \
  ------------------
  |  | 1178|    243|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    243|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    243|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    243|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    243|  constexpr auto _size = _name.size();                                \
  |  | 1183|    243|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    243|  return _nameof; }()
  ------------------
  561|    243|              std::string{NAMEOF(&I::conversionfunc)}};                        \
  ------------------
  |  | 1178|    243|#define NAMEOF(...) []() constexpr noexcept {                         \
  |  | 1179|    243|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
  |  | 1180|    243|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
  |  | 1181|    243|  static_assert(!_name.empty(), "Expression does not have a name.");  \
  |  | 1182|    243|  constexpr auto _size = _name.size();                                \
  |  | 1183|    243|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
  |  | 1184|    243|  return _nameof; }()
  ------------------
  562|    243|      c.fuzz(chardata);                                                        \
  563|    243|    }                                                                          \
_ZNK10ConversionIL12UtfEncodings4ELS0_2EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE4fuzzENSt3__14spanIS3_Lm18446744073709551615EEE:
  175|    243|  void fuzz(std::span<const char> chardata) const {
  176|       |    // assume the input is aligned to FromType
  177|    243|    const FromSpan from{reinterpret_cast<const FromType*>(chardata.data()),
  178|    243|                        chardata.size() / sizeof(FromType)};
  179|       |
  180|    243|    static const bool do_print_testcase =
  181|    243|        std::getenv("PRINT_FUZZ_CASE") != nullptr;
  182|       |
  183|    243|    if (do_print_testcase) {
  ------------------
  |  Branch (183:9): [True: 0, False: 243]
  ------------------
  184|      0|      dump_testcase(from, std::cerr);
  185|      0|      std::exit(EXIT_SUCCESS);
  186|      0|    }
  187|       |
  188|    243|    do {
  189|       |      // step 0 - is the input valid?
  190|    243|      const auto [inputisvalid, valid_input_agree] = verify_valid_input(from);
  191|    243|      if (!valid_input_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (191:11): [True: 0, False: 243]
  |  Branch (191:33): [True: 0, Folded]
  ------------------
  192|      0|        break;
  193|       |
  194|       |      // step 1 - count the input (only makes sense for some of the encodings)
  195|       |      if constexpr (From == UtfEncodings::UTF16BE ||
  196|       |                    From == UtfEncodings::UTF16LE ||
  197|       |                    From == UtfEncodings::UTF8) {
  198|       |        if (!count_the_input(from) && !allow_implementations_to_differ)
  199|       |          break;
  200|       |      }
  201|       |
  202|       |      // step 2 - what is the required size of the output?
  203|    243|      const auto [output_length, length_agree] =
  204|    243|          calculate_length(from, inputisvalid);
  205|    243|      if (!length_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (205:11): [True: 0, False: 243]
  |  Branch (205:28): [True: 0, Folded]
  ------------------
  206|      0|        break;
  207|       |
  208|    243|      if (!inputisvalid && name.find("valid") != std::string::npos) {
  ------------------
  |  Branch (208:11): [True: 0, False: 243]
  |  Branch (208:28): [True: 0, False: 0]
  ------------------
  209|       |        // don't run the conversion step, it requires valid input
  210|      0|        return;
  211|      0|      }
  212|       |
  213|       |      // step 3 - run the conversion
  214|    243|      const auto [written, outputs_agree] =
  215|    243|          do_conversion(from, output_length, inputisvalid);
  216|    243|      if (!outputs_agree && !allow_implementations_to_differ)
  ------------------
  |  Branch (216:11): [True: 0, False: 243]
  |  Branch (216:29): [True: 0, Folded]
  ------------------
  217|      0|        break;
  218|       |
  219|       |      // coming this far means no problems were found
  220|    243|      return;
  221|    243|    } while (0);
  ------------------
  |  Branch (221:14): [Folded, False: 0]
  ------------------
  222|       |    // if we come here, something failed
  223|      0|    std::cerr << "something failed, rerun with PRINT_FUZZ_CASE set to print a "
  224|      0|                 "reproducer to stderr\n";
  225|      0|    std::abort();
  226|    243|  }
_ZNK10ConversionIL12UtfEncodings4ELS0_2EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE18verify_valid_inputIvQeqT_LS0_4EEENSA_17validation_resultENSt3__14spanIS3_Lm18446744073709551615EEE:
  283|    243|  validation_result verify_valid_input(FromSpan) const {
  284|       |    // all latin1 input is valid. there is no simdutf validation function for
  285|       |    // it.
  286|    243|    return validation_result{.valid = true, .implementations_agree = true};
  287|    243|  }
_ZNK10ConversionIL12UtfEncodings4ELS0_2EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEb:
  342|    243|  length_result calculate_length(FromSpan src, const bool inputisvalid) const {
  343|    243|    length_result ret{};
  344|       |
  345|    243|    const auto implementations = get_supported_implementations();
  346|    243|    std::vector<std::size_t> results;
  347|    243|    results.reserve(implementations.size());
  348|       |
  349|    729|    for (auto impl : implementations) {
  ------------------
  |  Branch (349:20): [True: 729, False: 243]
  ------------------
  350|    729|      const auto len = invoke_lengthcalc(impl, src);
  351|    729|      results.push_back(len);
  352|    729|      ret.length.push_back(len);
  353|    729|    }
  354|       |
  355|    243|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  356|    243|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (356:9): [True: 0, False: 243]
  ------------------
  357|      0|      std::cerr << "begin errormessage for calculate_length\n";
  358|      0|      std::cerr << "in fuzz case invoking " << lengthcalcname << " with "
  359|      0|                << src.size() << " elements with valid input=" << inputisvalid
  360|      0|                << ":\n";
  361|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (361:31): [True: 0, False: 0]
  ------------------
  362|      0|        std::cerr << "got return " << std::dec << results[i]
  363|      0|                  << " from implementation " << implementations[i]->name()
  364|      0|                  << '\n';
  365|      0|      }
  366|      0|      std::cerr << "end errormessage\n";
  367|      0|      if (inputisvalid) {
  ------------------
  |  Branch (367:11): [True: 0, False: 0]
  ------------------
  368|      0|        ret.implementations_agree = false;
  369|      0|      } else {
  370|      0|        std::cerr
  371|      0|            << "implementations are allowed to disagree on invalid input\n";
  372|      0|        ret.implementations_agree = true;
  373|      0|      }
  374|    243|    } else {
  375|    243|      ret.implementations_agree = true;
  376|    243|    }
  377|    243|    return ret;
  378|    243|  }
_ZNK10ConversionIL12UtfEncodings4ELS0_2EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE17invoke_lengthcalcIvQsr3stdE14is_invocable_vIT1_PKS2_PKN23ValidationFunctionTraitIXT_EE7RawTypeEmEEEmSE_NSt3__14spanIS3_Lm18446744073709551615EEE:
  330|    729|                                FromSpan src) const {
  331|    729|    return std::invoke(lengthcalc, impl, src.data(), src.size());
  332|    729|  }
_ZZNK10ConversionIL12UtfEncodings4ELS0_2EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE16calculate_lengthENSt3__14spanIS3_Lm18446744073709551615EEEbENKUlRKT_RKT0_E_clImmEEDaSG_SJ_:
  355|    486|    auto neq = [](const auto& a, const auto& b) { return a != b; };
_ZNK10ConversionIL12UtfEncodings4ELS0_2EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEb:
  382|    243|                                  const bool inputisvalid) const {
  383|    243|    conversion_result ret{};
  384|       |
  385|    243|    const auto implementations = get_supported_implementations();
  386|       |
  387|    243|    std::vector<result<ConversionResult>> results;
  388|    243|    results.reserve(implementations.size());
  389|       |
  390|       |    // put the output in a separate allocation to make access violations easier
  391|       |    // to catch
  392|    243|    std::vector<std::vector<ToType>> outputbuffers;
  393|    243|    outputbuffers.reserve(implementations.size());
  394|    972|    for (std::size_t i = 0; i < implementations.size(); ++i) {
  ------------------
  |  Branch (394:29): [True: 729, False: 243]
  ------------------
  395|    729|      auto impl = implementations[i];
  396|    729|      const ToType canary1{42};
  397|    729|      auto& outputbuffer = outputbuffers.emplace_back(outlength.at(i), canary1);
  398|    729|      const auto implret1 = std::invoke(conversion, impl, src.data(),
  399|    729|                                        src.size(), outputbuffer.data());
  400|       |      // was the conversion successful?
  401|    729|      const auto success = [](const ConversionResult& r) -> bool {
  402|    729|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    729|          return r != 0;
  404|    729|        } else {
  405|    729|          return r.error == simdutf::error_code::SUCCESS;
  406|    729|        }
  407|    729|      }(implret1);
  408|    729|      const auto hash1 = FNV1A_hash::as_str(outputbuffer);
  409|    729|      if constexpr (use_canary_in_output) {
  410|       |        // optionally convert again, this time with the buffer filled with
  411|       |        // a different value. if the output differs, it means some of the buffer
  412|       |        // was not written to by the conversion function.
  413|    729|        const ToType canary2{25};
  414|    729|        const auto outputbuffer_first_run = outputbuffer;
  415|    729|        std::ranges::fill(outputbuffer, canary2);
  416|    729|        const auto implret2 = std::invoke(conversion, impl, src.data(),
  417|    729|                                          src.size(), outputbuffer.data());
  418|       |
  419|    729|        if (implret1 != implret2) {
  ------------------
  |  Branch (419:13): [True: 0, False: 729]
  ------------------
  420|      0|          std::cerr << "different return value the second time!\n";
  421|      0|          std::abort();
  422|      0|        }
  423|    729|        if (inputisvalid && success) {
  ------------------
  |  Branch (423:13): [True: 729, False: 0]
  |  Branch (423:29): [True: 723, False: 6]
  ------------------
  424|       |          // only care about the output if the input is valid
  425|    723|          const auto hash2 = FNV1A_hash::as_str(outputbuffer);
  426|    723|          if (hash1 != hash2) {
  ------------------
  |  Branch (426:15): [True: 0, False: 723]
  ------------------
  427|      0|            std::cerr << "different output the second time!\n";
  428|      0|            std::cerr << "implementation " << impl->name() << " " << name
  429|      0|                      << '\n';
  430|      0|            std::cerr << "input is valid=" << inputisvalid << '\n';
  431|      0|            std::cerr << "output length=" << outputbuffer.size() << '\n';
  432|      0|            std::cerr << "conversion was a success? " << success << '\n';
  433|      0|            for (std::size_t j = 0; j < outputbuffer.size(); ++j) {
  ------------------
  |  Branch (433:37): [True: 0, False: 0]
  ------------------
  434|      0|              std::cerr << "output[" << j << "]\t" << +outputbuffer_first_run[j]
  435|      0|                        << '\t' << +outputbuffer[j] << '\n';
  436|      0|            }
  437|      0|            std::abort();
  438|      0|          }
  439|    723|        }
  440|    729|      }
  441|    729|      results.emplace_back(implret1, success ? hash1 : "");
  ------------------
  |  Branch (441:38): [True: 723, False: 6]
  ------------------
  442|    729|    }
  443|       |
  444|       |    // do not require implementations to give the same output if
  445|       |    // the input is not valid.
  446|    243|    if (!inputisvalid) {
  ------------------
  |  Branch (446:9): [True: 0, False: 243]
  ------------------
  447|      0|      for (auto& e : results) {
  ------------------
  |  Branch (447:20): [True: 0, False: 0]
  ------------------
  448|      0|        e.outputhash.clear();
  449|      0|      }
  450|      0|    }
  451|       |
  452|    243|    auto neq = [](const auto& a, const auto& b) { return a != b; };
  453|    243|    if (std::ranges::adjacent_find(results, neq) != results.end()) {
  ------------------
  |  Branch (453:9): [True: 0, False: 243]
  ------------------
  454|      0|      std::cerr << "begin errormessage for do_conversion\n";
  455|      0|      std::cerr << "in fuzz case for " << name << " invoked with " << src.size()
  456|      0|                << " elements:\n";
  457|      0|      std::cerr << "input data is valid ? " << inputisvalid << '\n';
  458|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (458:31): [True: 0, False: 0]
  ------------------
  459|      0|        std::cerr << "got return " << std::dec << results[i]
  460|      0|                  << " from implementation " << implementations[i]->name()
  461|      0|                  << " using outlen=" << outlength.at(i) << '\n';
  462|      0|      }
  463|      0|      for (std::size_t i = 0; i < results.size(); ++i) {
  ------------------
  |  Branch (463:31): [True: 0, False: 0]
  ------------------
  464|      0|        std::cerr << "implementation " << implementations[i]->name()
  465|      0|                  << " out: ";
  466|      0|        for (const auto e : outputbuffers.at(i)) {
  ------------------
  |  Branch (466:27): [True: 0, False: 0]
  ------------------
  467|      0|          std::cerr << +e << ", ";
  468|      0|        }
  469|      0|        std::cerr << '\n';
  470|      0|      }
  471|      0|      std::cerr << "end errormessage\n";
  472|      0|      ret.implementations_agree = false;
  473|    243|    } else {
  474|    243|      ret.implementations_agree = true;
  475|    243|    }
  476|    243|    return ret;
  477|    243|  }
_ZZNK10ConversionIL12UtfEncodings4ELS0_2EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKmE_clESL_:
  401|    729|      const auto success = [](const ConversionResult& r) -> bool {
  402|    729|        if constexpr (std::is_same_v<ConversionResult, std::size_t>) {
  403|    729|          return r != 0;
  404|       |        } else {
  405|       |          return r.error == simdutf::error_code::SUCCESS;
  406|       |        }
  407|    729|      }(implret1);
_ZZNK10ConversionIL12UtfEncodings4ELS0_2EMN7simdutf14implementationEKDoFmPKcmEMS2_KDoFmS4_mPcEE13do_conversionENSt3__14spanIS3_Lm18446744073709551615EEERKNSB_6vectorImNSB_9allocatorImEEEEbENKUlRKT_RKT0_E_clI6resultImEST_EEDaSM_SP_:
  452|    486|    auto neq = [](const auto& a, const auto& b) { return a != b; };

_ZN10FNV1A_hash14fnv1ahash_implENSt3__14spanIKcLm18446744073709551615EEE:
   75|  17.9k|  static constexpr std::uint64_t fnv1ahash_impl(std::span<const char> bytes) {
   76|  17.9k|    auto hash = offset;
   77|       |
   78|   612M|    for (auto byte : bytes) {
  ------------------
  |  Branch (78:20): [True: 612M, False: 17.9k]
  ------------------
   79|   612M|      hash ^= static_cast<unsigned char>(byte);
   80|   612M|      hash *= prime;
   81|   612M|    }
   82|       |
   83|  17.9k|    return hash;
   84|  17.9k|  }
_ZN10FNV1A_hash14fnv1ahash_implIKDsLm18446744073709551615EQaaaa11is_hashableIT_Entsr3stdE9is_same_vIS2_cEntsr3stdE9is_same_vIS2_hEEEmNSt3__14spanIS2_XT0_EEE:
   89|  15.8k|  static constexpr std::uint64_t fnv1ahash_impl(std::span<Basic, N> data) {
   90|  15.8k|    return fnv1ahash_impl({reinterpret_cast<const unsigned char*>(data.data()),
   91|  15.8k|                           data.size_bytes()});
   92|  15.8k|  }
_ZN10FNV1A_hash14fnv1ahash_implENSt3__14spanIKhLm18446744073709551615EEE:
   65|  25.0k|  fnv1ahash_impl(std::span<const unsigned char> bytes) {
   66|  25.0k|    auto hash = offset;
   67|       |
   68|  2.38G|    for (std::uint64_t byte : bytes) {
  ------------------
  |  Branch (68:29): [True: 2.38G, False: 25.0k]
  ------------------
   69|  2.38G|      hash ^= byte;
   70|  2.38G|      hash *= prime;
   71|  2.38G|    }
   72|       |
   73|  25.0k|    return hash;
   74|  25.0k|  }
_Z29get_supported_implementationsv:
   26|  36.2k|get_supported_implementations() {
   27|  36.2k|  static const auto impl = []() -> auto {
   28|  36.2k|    std::vector<const simdutf::implementation*> ret;
   29|  36.2k|    for (auto e : simdutf::get_available_implementations()) {
   30|  36.2k|      std::cerr << "implementation " << e->name() << " is available? "
   31|  36.2k|                << e->supported_by_runtime_system() << '\n';
   32|  36.2k|      if (e->supported_by_runtime_system()) {
   33|  36.2k|        ret.push_back(e);
   34|  36.2k|      }
   35|  36.2k|    }
   36|  36.2k|    return ret;
   37|  36.2k|  }();
   38|  36.2k|  return {impl.data(), impl.size()};
   39|  36.2k|}
_ZZ29get_supported_implementationsvENKUlvE_clEv:
   27|      1|  static const auto impl = []() -> auto {
   28|      1|    std::vector<const simdutf::implementation*> ret;
   29|      4|    for (auto e : simdutf::get_available_implementations()) {
  ------------------
  |  Branch (29:17): [True: 4, False: 1]
  ------------------
   30|      4|      std::cerr << "implementation " << e->name() << " is available? "
   31|      4|                << e->supported_by_runtime_system() << '\n';
   32|      4|      if (e->supported_by_runtime_system()) {
  ------------------
  |  Branch (32:11): [True: 3, False: 1]
  ------------------
   33|      3|        ret.push_back(e);
   34|      3|      }
   35|      4|    }
   36|      1|    return ret;
   37|      1|  }();
_ZneRKN7simdutf6resultES2_:
   42|  32.1k|inline bool operator!=(const simdutf::result& a, const simdutf::result& b) {
   43|  32.1k|  return a.count != b.count || a.error != b.error;
  ------------------
  |  Branch (43:10): [True: 0, False: 32.1k]
  |  Branch (43:32): [True: 0, False: 32.1k]
  ------------------
   44|  32.1k|}
_ZN10FNV1A_hash6as_strIJNSt3__16vectorIDiNS1_9allocatorIDiEEEEEEENS1_12basic_stringIcNS1_11char_traitsIcEENS3_IcEEEEDpRKT_:
  100|  9.14k|  template <typename... Data> static std::string as_str(const Data&... data) {
  101|  9.14k|    static_assert(sizeof...(Data) > 0, "must hash with at least one argument");
  102|  9.14k|    std::uint64_t h;
  103|       |    if constexpr (sizeof...(Data) > 1) {
  104|       |      const std::array hashes{fnv1ahash_impl(data)...};
  105|       |      const auto s = std::span(hashes);
  106|       |      h = fnv1ahash_impl(s);
  107|  9.14k|    } else {
  108|  9.14k|      h = fnv1ahash_impl(data...);
  109|  9.14k|    }
  110|  9.14k|    constexpr std::size_t expected_chars = 16;
  111|  9.14k|    std::string ret(expected_chars, '0');
  112|  9.14k|    auto c = std::to_chars(ret.data(), ret.data() + ret.size(), h, 16);
  113|  9.14k|    assert(c.ec == std::errc{});
  ------------------
  |  Branch (113:5): [True: 9.14k, False: 0]
  ------------------
  114|  9.14k|    auto nwritten = c.ptr - ret.data();
  115|  9.14k|    assert(nwritten <= expected_chars);
  ------------------
  |  Branch (115:5): [True: 9.14k, False: 0]
  ------------------
  116|  9.14k|    std::rotate(ret.data(), c.ptr, ret.data() + expected_chars);
  117|  9.14k|    return ret;
  118|  9.14k|  }
_ZN10FNV1A_hash14fnv1ahash_implIDiQ11is_hashableIT_EEEmRKNSt3__16vectorIS1_NS2_9allocatorIS1_EEEE:
   96|  9.14k|  static constexpr std::uint64_t fnv1ahash_impl(const std::vector<Data>& data) {
   97|  9.14k|    return fnv1ahash_impl(std::span(data));
   98|  9.14k|  }
_ZN10FNV1A_hash14fnv1ahash_implIKDiLm18446744073709551615EQaaaa11is_hashableIT_Entsr3stdE9is_same_vIS2_cEntsr3stdE9is_same_vIS2_hEEEmNSt3__14spanIS2_XT0_EEE:
   89|  9.14k|  static constexpr std::uint64_t fnv1ahash_impl(std::span<Basic, N> data) {
   90|  9.14k|    return fnv1ahash_impl({reinterpret_cast<const unsigned char*>(data.data()),
   91|  9.14k|                           data.size_bytes()});
   92|  9.14k|  }
_ZN10FNV1A_hash6as_strIJNSt3__16vectorIcNS1_9allocatorIcEEEEEEENS1_12basic_stringIcNS1_11char_traitsIcEES4_EEDpRKT_:
  100|  17.9k|  template <typename... Data> static std::string as_str(const Data&... data) {
  101|  17.9k|    static_assert(sizeof...(Data) > 0, "must hash with at least one argument");
  102|  17.9k|    std::uint64_t h;
  103|       |    if constexpr (sizeof...(Data) > 1) {
  104|       |      const std::array hashes{fnv1ahash_impl(data)...};
  105|       |      const auto s = std::span(hashes);
  106|       |      h = fnv1ahash_impl(s);
  107|  17.9k|    } else {
  108|  17.9k|      h = fnv1ahash_impl(data...);
  109|  17.9k|    }
  110|  17.9k|    constexpr std::size_t expected_chars = 16;
  111|  17.9k|    std::string ret(expected_chars, '0');
  112|  17.9k|    auto c = std::to_chars(ret.data(), ret.data() + ret.size(), h, 16);
  113|  17.9k|    assert(c.ec == std::errc{});
  ------------------
  |  Branch (113:5): [True: 17.9k, False: 0]
  ------------------
  114|  17.9k|    auto nwritten = c.ptr - ret.data();
  115|  17.9k|    assert(nwritten <= expected_chars);
  ------------------
  |  Branch (115:5): [True: 17.9k, False: 0]
  ------------------
  116|  17.9k|    std::rotate(ret.data(), c.ptr, ret.data() + expected_chars);
  117|  17.9k|    return ret;
  118|  17.9k|  }
_ZN10FNV1A_hash14fnv1ahash_implIcQ11is_hashableIT_EEEmRKNSt3__16vectorIS1_NS2_9allocatorIS1_EEEE:
   96|  17.9k|  static constexpr std::uint64_t fnv1ahash_impl(const std::vector<Data>& data) {
   97|  17.9k|    return fnv1ahash_impl(std::span(data));
   98|  17.9k|  }
_ZN10FNV1A_hash6as_strIJNSt3__16vectorIDsNS1_9allocatorIDsEEEEEEENS1_12basic_stringIcNS1_11char_traitsIcEENS3_IcEEEEDpRKT_:
  100|  15.8k|  template <typename... Data> static std::string as_str(const Data&... data) {
  101|  15.8k|    static_assert(sizeof...(Data) > 0, "must hash with at least one argument");
  102|  15.8k|    std::uint64_t h;
  103|       |    if constexpr (sizeof...(Data) > 1) {
  104|       |      const std::array hashes{fnv1ahash_impl(data)...};
  105|       |      const auto s = std::span(hashes);
  106|       |      h = fnv1ahash_impl(s);
  107|  15.8k|    } else {
  108|  15.8k|      h = fnv1ahash_impl(data...);
  109|  15.8k|    }
  110|  15.8k|    constexpr std::size_t expected_chars = 16;
  111|  15.8k|    std::string ret(expected_chars, '0');
  112|  15.8k|    auto c = std::to_chars(ret.data(), ret.data() + ret.size(), h, 16);
  113|  15.8k|    assert(c.ec == std::errc{});
  ------------------
  |  Branch (113:5): [True: 15.8k, False: 0]
  ------------------
  114|  15.8k|    auto nwritten = c.ptr - ret.data();
  115|  15.8k|    assert(nwritten <= expected_chars);
  ------------------
  |  Branch (115:5): [True: 15.8k, False: 0]
  ------------------
  116|  15.8k|    std::rotate(ret.data(), c.ptr, ret.data() + expected_chars);
  117|  15.8k|    return ret;
  118|  15.8k|  }
_ZN10FNV1A_hash14fnv1ahash_implIDsQ11is_hashableIT_EEEmRKNSt3__16vectorIS1_NS2_9allocatorIS1_EEEE:
   96|  15.8k|  static constexpr std::uint64_t fnv1ahash_impl(const std::vector<Data>& data) {
   97|  15.8k|    return fnv1ahash_impl(std::span(data));
   98|  15.8k|  }
_ZeqRKN7simdutf6resultES2_:
   45|  8.66k|inline bool operator==(const simdutf::result& a, const simdutf::result& b) {
   46|  8.66k|  return a.count == b.count && a.error == b.error;
  ------------------
  |  Branch (46:10): [True: 8.66k, False: 0]
  |  Branch (46:32): [True: 8.66k, False: 0]
  ------------------
   47|  8.66k|}

_ZNK23ValidationFunctionTraitIL12UtfEncodings0EE24ValidationWithErrorsNameMUlvE_clEv:
 1178|      2|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|      2|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|      2|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|      2|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|      2|  constexpr auto _size = _name.size();                                \
 1183|      2|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|      2|  return _nameof; }()
_ZNK6nameof7cstringILt28EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|      4|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt28EE4dataEv:
  233|      4|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt28EE4sizeEv:
  235|      4|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
_ZNK23ValidationFunctionTraitIL12UtfEncodings1EE24ValidationWithErrorsNameMUlvE_clEv:
 1178|      2|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|      2|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|      2|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|      2|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|      2|  constexpr auto _size = _name.size();                                \
 1183|      2|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|      2|  return _nameof; }()
_ZNK23ValidationFunctionTraitIL12UtfEncodings3EE24ValidationWithErrorsNameMUlvE_clEv:
 1178|      2|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|      2|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|      2|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|      2|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|      2|  constexpr auto _size = _name.size();                                \
 1183|      2|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|      2|  return _nameof; }()
_ZNK6nameof7cstringILt26EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|      2|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt26EE4dataEv:
  233|      2|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt26EE4sizeEv:
  235|      2|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
_ZNK23ValidationFunctionTraitIL12UtfEncodings2EE24ValidationWithErrorsNameMUlvE_clEv:
 1178|      2|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|      2|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|      2|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|      2|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|      2|  constexpr auto _size = _name.size();                                \
 1183|      2|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|      2|  return _nameof; }()
_ZNK6nameof7cstringILt25EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|  1.05k|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt25EE4dataEv:
  233|  1.05k|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt25EE4sizeEv:
  235|  1.05k|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
conversion.cpp:_ZZZ18populate_functionsvENK3$_0clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|     86|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     86|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     86|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     86|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     86|  constexpr auto _size = _name.size();                                \
 1183|     86|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     86|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK3$_0clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|     86|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     86|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     86|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     86|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     86|  constexpr auto _size = _name.size();                                \
 1183|     86|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     86|  return _nameof; }()
_ZNK6nameof7cstringILt30EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|    375|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt30EE4dataEv:
  233|    375|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt30EE4sizeEv:
  235|    375|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
conversion.cpp:_ZZZ18populate_functionsvENK3$_1clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    227|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    227|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    227|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    227|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    227|  constexpr auto _size = _name.size();                                \
 1183|    227|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    227|  return _nameof; }()
_ZNK6nameof7cstringILt24EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|  3.21k|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt24EE4dataEv:
  233|  3.21k|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt24EE4sizeEv:
  235|  3.21k|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
conversion.cpp:_ZZZ18populate_functionsvENK3$_1clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    227|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    227|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    227|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    227|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    227|  constexpr auto _size = _name.size();                                \
 1183|    227|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    227|  return _nameof; }()
_ZNK6nameof7cstringILt29EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|    846|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt29EE4dataEv:
  233|    846|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt29EE4sizeEv:
  235|    846|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
conversion.cpp:_ZZZ18populate_functionsvENK3$_2clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|     66|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     66|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     66|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     66|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     66|  constexpr auto _size = _name.size();                                \
 1183|     66|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     66|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK3$_2clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|     66|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     66|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     66|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     66|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     66|  constexpr auto _size = _name.size();                                \
 1183|     66|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     66|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK3$_3clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    199|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    199|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    199|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    199|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    199|  constexpr auto _size = _name.size();                                \
 1183|    199|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    199|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK3$_3clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    199|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    199|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    199|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    199|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    199|  constexpr auto _size = _name.size();                                \
 1183|    199|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    199|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK3$_4clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|     73|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     73|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     73|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     73|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     73|  constexpr auto _size = _name.size();                                \
 1183|     73|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     73|  return _nameof; }()
_ZNK6nameof7cstringILt23EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|  3.94k|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt23EE4dataEv:
  233|  3.94k|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt23EE4sizeEv:
  235|  3.94k|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
conversion.cpp:_ZZZ18populate_functionsvENK3$_4clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|     73|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     73|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     73|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     73|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     73|  constexpr auto _size = _name.size();                                \
 1183|     73|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     73|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK3$_5clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    150|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    150|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    150|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    150|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    150|  constexpr auto _size = _name.size();                                \
 1183|    150|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    150|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK3$_5clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    150|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    150|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    150|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    150|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    150|  constexpr auto _size = _name.size();                                \
 1183|    150|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    150|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK3$_6clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    105|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    105|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    105|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    105|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    105|  constexpr auto _size = _name.size();                                \
 1183|    105|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    105|  return _nameof; }()
_ZNK6nameof7cstringILt22EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|  4.91k|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt22EE4dataEv:
  233|  4.91k|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt22EE4sizeEv:
  235|  4.91k|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
conversion.cpp:_ZZZ18populate_functionsvENK3$_6clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    105|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    105|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    105|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    105|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    105|  constexpr auto _size = _name.size();                                \
 1183|    105|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    105|  return _nameof; }()
_ZNK6nameof7cstringILt27EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|    372|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt27EE4dataEv:
  233|    372|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt27EE4sizeEv:
  235|    372|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
conversion.cpp:_ZZZ18populate_functionsvENK3$_7clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    239|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    239|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    239|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    239|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    239|  constexpr auto _size = _name.size();                                \
 1183|    239|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    239|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK3$_7clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    239|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    239|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    239|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    239|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    239|  constexpr auto _size = _name.size();                                \
 1183|    239|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    239|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK3$_8clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    181|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    181|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    181|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    181|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    181|  constexpr auto _size = _name.size();                                \
 1183|    181|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    181|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK3$_8clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    181|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    181|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    181|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    181|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    181|  constexpr auto _size = _name.size();                                \
 1183|    181|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    181|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK3$_9clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    267|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    267|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    267|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    267|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    267|  constexpr auto _size = _name.size();                                \
 1183|    267|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    267|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK3$_9clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    267|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    267|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    267|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    267|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    267|  constexpr auto _size = _name.size();                                \
 1183|    267|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    267|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_10clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|     58|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     58|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     58|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     58|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     58|  constexpr auto _size = _name.size();                                \
 1183|     58|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     58|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_10clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|     58|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     58|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     58|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     58|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     58|  constexpr auto _size = _name.size();                                \
 1183|     58|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     58|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_11clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    151|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    151|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    151|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    151|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    151|  constexpr auto _size = _name.size();                                \
 1183|    151|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    151|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_11clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    151|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    151|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    151|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    151|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    151|  constexpr auto _size = _name.size();                                \
 1183|    151|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    151|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_12clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    197|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    197|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    197|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    197|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    197|  constexpr auto _size = _name.size();                                \
 1183|    197|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    197|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_12clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    197|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    197|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    197|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    197|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    197|  constexpr auto _size = _name.size();                                \
 1183|    197|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    197|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_13clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|     67|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     67|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     67|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     67|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     67|  constexpr auto _size = _name.size();                                \
 1183|     67|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     67|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_13clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|     67|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     67|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     67|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     67|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     67|  constexpr auto _size = _name.size();                                \
 1183|     67|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     67|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_14clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    154|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    154|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    154|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    154|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    154|  constexpr auto _size = _name.size();                                \
 1183|    154|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    154|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_14clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    154|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    154|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    154|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    154|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    154|  constexpr auto _size = _name.size();                                \
 1183|    154|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    154|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_15clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    253|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    253|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    253|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    253|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    253|  constexpr auto _size = _name.size();                                \
 1183|    253|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    253|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_15clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    253|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    253|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    253|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    253|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    253|  constexpr auto _size = _name.size();                                \
 1183|    253|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    253|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_16clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|     93|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     93|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     93|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     93|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     93|  constexpr auto _size = _name.size();                                \
 1183|     93|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     93|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_16clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|     93|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     93|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     93|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     93|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     93|  constexpr auto _size = _name.size();                                \
 1183|     93|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     93|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_17clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    258|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    258|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    258|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    258|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    258|  constexpr auto _size = _name.size();                                \
 1183|    258|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    258|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_17clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    258|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    258|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    258|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    258|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    258|  constexpr auto _size = _name.size();                                \
 1183|    258|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    258|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_18clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    251|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    251|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    251|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    251|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    251|  constexpr auto _size = _name.size();                                \
 1183|    251|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    251|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_18clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    251|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    251|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    251|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    251|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    251|  constexpr auto _size = _name.size();                                \
 1183|    251|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    251|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_19clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    357|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    357|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    357|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    357|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    357|  constexpr auto _size = _name.size();                                \
 1183|    357|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    357|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_19clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    357|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    357|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    357|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    357|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    357|  constexpr auto _size = _name.size();                                \
 1183|    357|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    357|  return _nameof; }()
_ZNK6nameof7cstringILt21EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|    832|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt21EE4dataEv:
  233|    832|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt21EE4sizeEv:
  235|    832|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
conversion.cpp:_ZZZ18populate_functionsvENK4$_20clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    358|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    358|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    358|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    358|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    358|  constexpr auto _size = _name.size();                                \
 1183|    358|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    358|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_20clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    358|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    358|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    358|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    358|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    358|  constexpr auto _size = _name.size();                                \
 1183|    358|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    358|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_21clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    487|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    487|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    487|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    487|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    487|  constexpr auto _size = _name.size();                                \
 1183|    487|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    487|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_21clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    487|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    487|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    487|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    487|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    487|  constexpr auto _size = _name.size();                                \
 1183|    487|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    487|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_22clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    475|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    475|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    475|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    475|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    475|  constexpr auto _size = _name.size();                                \
 1183|    475|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    475|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_22clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    475|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    475|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    475|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    475|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    475|  constexpr auto _size = _name.size();                                \
 1183|    475|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    475|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_23clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    475|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    475|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    475|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    475|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    475|  constexpr auto _size = _name.size();                                \
 1183|    475|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    475|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_23clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    475|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    475|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    475|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    475|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    475|  constexpr auto _size = _name.size();                                \
 1183|    475|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    475|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_24clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    124|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    124|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    124|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    124|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    124|  constexpr auto _size = _name.size();                                \
 1183|    124|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    124|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_24clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    124|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    124|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    124|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    124|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    124|  constexpr auto _size = _name.size();                                \
 1183|    124|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    124|  return _nameof; }()
_ZNK6nameof7cstringILt37EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|    256|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt37EE4dataEv:
  233|    256|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt37EE4sizeEv:
  235|    256|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
conversion.cpp:_ZZZ18populate_functionsvENK4$_25clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    183|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    183|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    183|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    183|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    183|  constexpr auto _size = _name.size();                                \
 1183|    183|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    183|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_25clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    183|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    183|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    183|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    183|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    183|  constexpr auto _size = _name.size();                                \
 1183|    183|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    183|  return _nameof; }()
_ZNK6nameof7cstringILt36EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|  1.10k|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt36EE4dataEv:
  233|  1.10k|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt36EE4sizeEv:
  235|  1.10k|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
conversion.cpp:_ZZZ18populate_functionsvENK4$_26clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    308|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    308|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    308|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    308|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    308|  constexpr auto _size = _name.size();                                \
 1183|    308|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    308|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_26clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    308|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    308|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    308|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    308|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    308|  constexpr auto _size = _name.size();                                \
 1183|    308|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    308|  return _nameof; }()
_ZNK6nameof7cstringILt35EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|  1.75k|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt35EE4dataEv:
  233|  1.75k|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt35EE4sizeEv:
  235|  1.75k|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
conversion.cpp:_ZZZ18populate_functionsvENK4$_27clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    132|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    132|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    132|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    132|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    132|  constexpr auto _size = _name.size();                                \
 1183|    132|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    132|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_27clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    132|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    132|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    132|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    132|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    132|  constexpr auto _size = _name.size();                                \
 1183|    132|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    132|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_28clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    193|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    193|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    193|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    193|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    193|  constexpr auto _size = _name.size();                                \
 1183|    193|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    193|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_28clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    193|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    193|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    193|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    193|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    193|  constexpr auto _size = _name.size();                                \
 1183|    193|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    193|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_29clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    356|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    356|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    356|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    356|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    356|  constexpr auto _size = _name.size();                                \
 1183|    356|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    356|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_29clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    356|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    356|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    356|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    356|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    356|  constexpr auto _size = _name.size();                                \
 1183|    356|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    356|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_30clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    244|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    244|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    244|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    244|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    244|  constexpr auto _size = _name.size();                                \
 1183|    244|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    244|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_30clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    244|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    244|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    244|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    244|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    244|  constexpr auto _size = _name.size();                                \
 1183|    244|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    244|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_31clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    339|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    339|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    339|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    339|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    339|  constexpr auto _size = _name.size();                                \
 1183|    339|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    339|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_31clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    339|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    339|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    339|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    339|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    339|  constexpr auto _size = _name.size();                                \
 1183|    339|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    339|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_32clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    386|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    386|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    386|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    386|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    386|  constexpr auto _size = _name.size();                                \
 1183|    386|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    386|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_32clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    386|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    386|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    386|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    386|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    386|  constexpr auto _size = _name.size();                                \
 1183|    386|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    386|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_33clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    430|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    430|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    430|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    430|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    430|  constexpr auto _size = _name.size();                                \
 1183|    430|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    430|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_33clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    430|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    430|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    430|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    430|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    430|  constexpr auto _size = _name.size();                                \
 1183|    430|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    430|  return _nameof; }()
_ZNK6nameof7cstringILt33EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|    889|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt33EE4dataEv:
  233|    889|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt33EE4sizeEv:
  235|    889|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
conversion.cpp:_ZZZ18populate_functionsvENK4$_34clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    335|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    335|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    335|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    335|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    335|  constexpr auto _size = _name.size();                                \
 1183|    335|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    335|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_34clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    335|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    335|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    335|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    335|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    335|  constexpr auto _size = _name.size();                                \
 1183|    335|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    335|  return _nameof; }()
_ZNK6nameof7cstringILt34EEcvNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEEEv:
  269|    335|  [[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
_ZNK6nameof7cstringILt34EE4dataEv:
  233|    335|  [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
_ZNK6nameof7cstringILt34EE4sizeEv:
  235|    335|  [[nodiscard]] constexpr size_type size() const noexcept { return N; }
conversion.cpp:_ZZZ18populate_functionsvENK4$_35clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    451|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    451|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    451|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    451|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    451|  constexpr auto _size = _name.size();                                \
 1183|    451|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    451|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_35clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    451|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    451|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    451|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    451|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    451|  constexpr auto _size = _name.size();                                \
 1183|    451|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    451|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_36clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    391|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    391|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    391|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    391|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    391|  constexpr auto _size = _name.size();                                \
 1183|    391|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    391|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_36clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    391|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    391|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    391|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    391|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    391|  constexpr auto _size = _name.size();                                \
 1183|    391|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    391|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_37clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    459|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    459|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    459|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    459|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    459|  constexpr auto _size = _name.size();                                \
 1183|    459|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    459|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_37clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    459|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    459|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    459|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    459|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    459|  constexpr auto _size = _name.size();                                \
 1183|    459|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    459|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_38clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|     51|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     51|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     51|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     51|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     51|  constexpr auto _size = _name.size();                                \
 1183|     51|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     51|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_38clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|     51|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     51|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     51|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     51|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     51|  constexpr auto _size = _name.size();                                \
 1183|     51|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     51|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_39clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|     54|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     54|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     54|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     54|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     54|  constexpr auto _size = _name.size();                                \
 1183|     54|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     54|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_39clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|     54|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     54|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     54|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     54|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     54|  constexpr auto _size = _name.size();                                \
 1183|     54|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     54|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_40clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|     41|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     41|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     41|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     41|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     41|  constexpr auto _size = _name.size();                                \
 1183|     41|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     41|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_40clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|     41|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|     41|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|     41|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|     41|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|     41|  constexpr auto _size = _name.size();                                \
 1183|     41|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|     41|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_41clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE1_clEv:
 1178|    243|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    243|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    243|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    243|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    243|  constexpr auto _size = _name.size();                                \
 1183|    243|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    243|  return _nameof; }()
conversion.cpp:_ZZZ18populate_functionsvENK4$_41clENSt3__14spanIKcLm18446744073709551615EEEENKUlvE2_clEv:
 1178|    243|#define NAMEOF(...) []() constexpr noexcept {                         \
 1179|    243|  ::std::void_t<decltype(__VA_ARGS__)>();                             \
 1180|    243|  constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
 1181|    243|  static_assert(!_name.empty(), "Expression does not have a name.");  \
 1182|    243|  constexpr auto _size = _name.size();                                \
 1183|    243|  constexpr auto _nameof = ::nameof::cstring<_size>{_name};           \
 1184|    243|  return _nameof; }()

_ZN7simdutf6resultC2ENS_10error_codeEm:
   87|  81.3k|      : error{err}, count{pos} {}
_ZNK7simdutf6result6is_errEv:
   93|  5.44k|  simdutf_really_inline simdutf_constexpr23 bool is_err() const noexcept {
   94|  5.44k|    return error != error_code::SUCCESS;
   95|  5.44k|  }
_ZN7simdutf11full_resultC2ENS_10error_codeEmm:
  111|  6.07k|      : error{err}, input_count{pos_in}, output_count{pos_out} {}
_ZNK7simdutf11full_resultcvNS_6resultEEv:
  117|  3.98k|  simdutf_really_inline simdutf_constexpr23 operator result() const noexcept {
  118|  3.98k|    if (error == error_code::SUCCESS) {
  ------------------
  |  Branch (118:9): [True: 2.43k, False: 1.54k]
  ------------------
  119|  2.43k|      return result{error, output_count};
  120|  2.43k|    } else {
  121|  1.54k|      return result{error, input_count};
  122|  1.54k|    }
  123|  3.98k|  }

_ZNK7simdutf14implementation4nameEv:
 5562|      4|  virtual std::string_view name() const noexcept { return _name; }
_ZNK7simdutf14implementation25required_instruction_setsEv:
 5613|      8|  virtual uint32_t required_instruction_sets() const {
 5614|      8|    return _required_instruction_sets;
 5615|      8|  }
_ZNK7simdutf14implementation24utf16_length_from_latin1Em:
 6818|    285|  utf16_length_from_latin1(size_t length) const noexcept {
 6819|    285|    return length;
 6820|    285|  }
_ZNK7simdutf14implementation24latin1_length_from_utf32Em:
 7006|  1.01k|  latin1_length_from_utf32(size_t length) const noexcept {
 7007|  1.01k|    return length;
 7008|  1.01k|  }
_ZNK7simdutf14implementation24latin1_length_from_utf16Em:
 7043|  1.14k|  latin1_length_from_utf16(size_t length) const noexcept {
 7044|  1.14k|    return length;
 7045|  1.14k|  }
_ZNK7simdutf14implementation24utf32_length_from_latin1Em:
 7076|    153|  utf32_length_from_latin1(size_t length) const noexcept {
 7077|    153|    return length;
 7078|    153|  }
_ZN7simdutf14implementationC2EPKcS2_j:
 7514|      4|      : _name(name), _description(description),
 7515|      4|        _required_instruction_sets(required_instruction_sets) {}
_ZN7simdutf8internal29available_implementation_listC2Ev:
 7546|      1|  simdutf_really_inline available_implementation_list() {}

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

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

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

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

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf87convertEPKcmPc:
   66|  1.36k|                                     char *utf8_output) {
   67|  1.36k|  return convert(reinterpret_cast<const unsigned char *>(buf), len,
   68|  1.36k|                 utf8_output);
   69|  1.36k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf87convertIPKhPcQaasr7simdutf6detailE22indexes_into_byte_likeIT_Esr7simdutf6detailE26index_assignable_from_charIT0_EEEmS7_mS8_:
   17|  1.36k|                                   OutputPtr utf8_output) {
   18|       |  // const unsigned char *data = reinterpret_cast<const unsigned char *>(buf);
   19|  1.36k|  size_t pos = 0;
   20|  1.36k|  size_t utf8_pos = 0;
   21|       |
   22|  6.79M|  while (pos < len) {
  ------------------
  |  Branch (22:10): [True: 6.79M, False: 1.36k]
  ------------------
   23|       |#if SIMDUTF_CPLUSPLUS23
   24|       |    if !consteval
   25|       |#endif
   26|  6.79M|    {
   27|       |      // try to convert the next block of 16 ASCII bytes
   28|  6.79M|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (28:11): [True: 6.78M, False: 11.6k]
  ------------------
   29|       |                             // they are ascii
   30|  6.78M|        uint64_t v1;
   31|  6.78M|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   32|  6.78M|        uint64_t v2;
   33|  6.78M|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   34|  6.78M|        uint64_t v{v1 |
   35|  6.78M|                   v2}; // We are only interested in these bits: 1000 1000 1000
   36|       |                        // 1000, so it makes sense to concatenate everything
   37|  6.78M|        if ((v & 0x8080808080808080) ==
  ------------------
  |  Branch (37:13): [True: 2.34M, False: 4.43M]
  ------------------
   38|  6.78M|            0) { // if NONE of these are set, e.g. all of them are zero, then
   39|       |                 // everything is ASCII
   40|  2.34M|          size_t final_pos = pos + 16;
   41|  39.9M|          while (pos < final_pos) {
  ------------------
  |  Branch (41:18): [True: 37.5M, False: 2.34M]
  ------------------
   42|  37.5M|            utf8_output[utf8_pos++] = char(data[pos]);
   43|  37.5M|            pos++;
   44|  37.5M|          }
   45|  2.34M|          continue;
   46|  2.34M|        }
   47|  6.78M|      } // if (pos + 16 <= len)
   48|  6.79M|    } // !consteval scope
   49|       |
   50|  4.44M|    unsigned char byte = data[pos];
   51|  4.44M|    if ((byte & 0x80) == 0) { // if ASCII
  ------------------
  |  Branch (51:9): [True: 1.84M, False: 2.60M]
  ------------------
   52|       |      // will generate one UTF-8 bytes
   53|  1.84M|      utf8_output[utf8_pos++] = char(byte);
   54|  1.84M|      pos++;
   55|  2.60M|    } else {
   56|       |      // will generate two UTF-8 bytes
   57|  2.60M|      utf8_output[utf8_pos++] = char((byte >> 6) | 0b11000000);
   58|  2.60M|      utf8_output[utf8_pos++] = char((byte & 0b111111) | 0b10000000);
   59|  2.60M|      pos++;
   60|  2.60M|    }
   61|  4.44M|  } // while
   62|  1.36k|  return utf8_pos;
   63|  1.36k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf823utf8_length_from_latin1IPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_m:
  199|    243|utf8_length_from_latin1(InputPtr input, size_t length) noexcept {
  200|    243|  size_t answer = length;
  201|    243|  size_t i = 0;
  202|       |
  203|       |#if SIMDUTF_CPLUSPLUS23
  204|       |  if !consteval
  205|       |#endif
  206|    243|  {
  207|    243|    auto pop = [](uint64_t v) {
  208|    243|      return (size_t)(((v >> 7) & UINT64_C(0x0101010101010101)) *
  209|    243|                          UINT64_C(0x0101010101010101) >>
  210|    243|                      56);
  211|    243|    };
  212|   656k|    for (; i + 32 <= length; i += 32) {
  ------------------
  |  Branch (212:12): [True: 656k, False: 243]
  ------------------
  213|   656k|      uint64_t v;
  214|   656k|      memcpy(&v, input + i, 8);
  215|   656k|      answer += pop(v);
  216|   656k|      memcpy(&v, input + i + 8, sizeof(v));
  217|   656k|      answer += pop(v);
  218|   656k|      memcpy(&v, input + i + 16, sizeof(v));
  219|   656k|      answer += pop(v);
  220|   656k|      memcpy(&v, input + i + 24, sizeof(v));
  221|   656k|      answer += pop(v);
  222|   656k|    }
  223|    458|    for (; i + 8 <= length; i += 8) {
  ------------------
  |  Branch (223:12): [True: 215, False: 243]
  ------------------
  224|    215|      uint64_t v;
  225|    215|      memcpy(&v, input + i, sizeof(v));
  226|    215|      answer += pop(v);
  227|    215|    }
  228|    243|  } // !consteval scope
  229|    653|  for (; i + 1 <= length; i += 1) {
  ------------------
  |  Branch (229:10): [True: 410, False: 243]
  ------------------
  230|    410|    answer += static_cast<uint8_t>(input[i]) >> 7;
  231|    410|  }
  232|    243|  return answer;
  233|    243|}
simdutf.cpp:_ZZN7simdutf6scalar12_GLOBAL__N_114latin1_to_utf823utf8_length_from_latin1IPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_mENKUlmE_clEm:
  207|  2.62M|    auto pop = [](uint64_t v) {
  208|  2.62M|      return (size_t)(((v >> 7) & UINT64_C(0x0101010101010101)) *
  209|       |                          UINT64_C(0x0101010101010101) >>
  210|  2.62M|                      56);
  211|  2.62M|    };

_ZN7simdutf6scalar14u16_swap_bytesEt:
    8|   201M|u16_swap_bytes(const uint16_t word) {
    9|   201M|  return uint16_t((word >> 8) | (word << 8));
   10|   201M|}
_ZN7simdutf6scalar5utf1614swap_if_neededILNS_10endiannessE0EEEtt:
   27|  90.0M|template <endianness big_endian> constexpr uint16_t swap_if_needed(uint16_t c) {
   28|  90.0M|  return !match_system(big_endian) ? scalar::u16_swap_bytes(c) : c;
  ------------------
  |  Branch (28:10): [Folded, False: 90.0M]
  ------------------
   29|  90.0M|}
_ZN7simdutf6scalar5utf1614swap_if_neededILNS_10endiannessE1EEEtt:
   27|  93.0M|template <endianness big_endian> constexpr uint16_t swap_if_needed(uint16_t c) {
   28|  93.0M|  return !match_system(big_endian) ? scalar::u16_swap_bytes(c) : c;
  ------------------
  |  Branch (28:10): [True: 93.0M, Folded]
  ------------------
   29|  93.0M|}

_ZN7simdutf6scalar5utf168validateILNS_10endiannessE0EEEbPKDsm:
   22|  3.97k|validate(const char16_t *data, size_t len) noexcept {
   23|  3.97k|  uint64_t pos = 0;
   24|  20.9M|  while (pos < len) {
  ------------------
  |  Branch (24:10): [True: 20.9M, False: 2.74k]
  ------------------
   25|  20.9M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(data[pos]);
   26|  20.9M|    if ((word & 0xF800) == 0xD800) {
  ------------------
  |  Branch (26:9): [True: 30.9k, False: 20.9M]
  ------------------
   27|  30.9k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (27:11): [True: 252, False: 30.7k]
  ------------------
   28|    252|        return false;
   29|    252|      }
   30|  30.7k|      char16_t diff = char16_t(word - 0xD800);
   31|  30.7k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (31:11): [True: 373, False: 30.3k]
  ------------------
   32|    373|        return false;
   33|    373|      }
   34|  30.3k|      char16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (34:28): [Folded, False: 30.3k]
  ------------------
   35|  30.3k|                               ? u16_swap_bytes(data[pos + 1])
   36|  30.3k|                               : data[pos + 1];
   37|  30.3k|      char16_t diff2 = char16_t(next_word - 0xDC00);
   38|  30.3k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (38:11): [True: 606, False: 29.7k]
  ------------------
   39|    606|        return false;
   40|    606|      }
   41|  29.7k|      pos += 2;
   42|  20.9M|    } else {
   43|  20.9M|      pos++;
   44|  20.9M|    }
   45|  20.9M|  }
   46|  2.74k|  return true;
   47|  3.97k|}
_ZN7simdutf6scalar5utf168validateILNS_10endiannessE1EEEbPKDsm:
   22|  3.76k|validate(const char16_t *data, size_t len) noexcept {
   23|  3.76k|  uint64_t pos = 0;
   24|  21.1M|  while (pos < len) {
  ------------------
  |  Branch (24:10): [True: 21.1M, False: 2.52k]
  ------------------
   25|  21.1M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(data[pos]);
   26|  21.1M|    if ((word & 0xF800) == 0xD800) {
  ------------------
  |  Branch (26:9): [True: 19.7k, False: 21.1M]
  ------------------
   27|  19.7k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (27:11): [True: 252, False: 19.5k]
  ------------------
   28|    252|        return false;
   29|    252|      }
   30|  19.5k|      char16_t diff = char16_t(word - 0xD800);
   31|  19.5k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (31:11): [True: 350, False: 19.1k]
  ------------------
   32|    350|        return false;
   33|    350|      }
   34|  19.1k|      char16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (34:28): [True: 19.1k, Folded]
  ------------------
   35|  19.1k|                               ? u16_swap_bytes(data[pos + 1])
   36|  19.1k|                               : data[pos + 1];
   37|  19.1k|      char16_t diff2 = char16_t(next_word - 0xDC00);
   38|  19.1k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (38:11): [True: 635, False: 18.5k]
  ------------------
   39|    635|        return false;
   40|    635|      }
   41|  18.5k|      pos += 2;
   42|  21.1M|    } else {
   43|  21.1M|      pos++;
   44|  21.1M|    }
   45|  21.1M|  }
   46|  2.52k|  return true;
   47|  3.76k|}
_ZN7simdutf6scalar5utf1620validate_with_errorsILNS_10endiannessE0EEENS_6resultEPKDsm:
   51|  4.22k|validate_with_errors(const char16_t *data, size_t len) noexcept {
   52|  4.22k|  size_t pos = 0;
   53|  20.9M|  while (pos < len) {
  ------------------
  |  Branch (53:10): [True: 20.9M, False: 2.74k]
  ------------------
   54|  20.9M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(data[pos]);
   55|  20.9M|    if ((word & 0xF800) == 0xD800) {
  ------------------
  |  Branch (55:9): [True: 31.2k, False: 20.9M]
  ------------------
   56|  31.2k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (56:11): [True: 252, False: 31.0k]
  ------------------
   57|    252|        return result(error_code::SURROGATE, pos);
   58|    252|      }
   59|  31.0k|      char16_t diff = char16_t(word - 0xD800);
   60|  31.0k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (60:11): [True: 489, False: 30.5k]
  ------------------
   61|    489|        return result(error_code::SURROGATE, pos);
   62|    489|      }
   63|  30.5k|      char16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (63:28): [Folded, False: 30.5k]
  ------------------
   64|  30.5k|                               ? u16_swap_bytes(data[pos + 1])
   65|  30.5k|                               : data[pos + 1];
   66|  30.5k|      char16_t diff2 = uint16_t(next_word - 0xDC00);
   67|  30.5k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (67:11): [True: 744, False: 29.8k]
  ------------------
   68|    744|        return result(error_code::SURROGATE, pos);
   69|    744|      }
   70|  29.8k|      pos += 2;
   71|  20.9M|    } else {
   72|  20.9M|      pos++;
   73|  20.9M|    }
   74|  20.9M|  }
   75|  2.74k|  return result(error_code::SUCCESS, pos);
   76|  4.22k|}
_ZN7simdutf6scalar5utf1620validate_with_errorsILNS_10endiannessE1EEENS_6resultEPKDsm:
   51|  3.97k|validate_with_errors(const char16_t *data, size_t len) noexcept {
   52|  3.97k|  size_t pos = 0;
   53|  21.1M|  while (pos < len) {
  ------------------
  |  Branch (53:10): [True: 21.1M, False: 2.52k]
  ------------------
   54|  21.1M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(data[pos]);
   55|  21.1M|    if ((word & 0xF800) == 0xD800) {
  ------------------
  |  Branch (55:9): [True: 20.0k, False: 21.1M]
  ------------------
   56|  20.0k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (56:11): [True: 252, False: 19.7k]
  ------------------
   57|    252|        return result(error_code::SURROGATE, pos);
   58|    252|      }
   59|  19.7k|      char16_t diff = char16_t(word - 0xD800);
   60|  19.7k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (60:11): [True: 429, False: 19.3k]
  ------------------
   61|    429|        return result(error_code::SURROGATE, pos);
   62|    429|      }
   63|  19.3k|      char16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (63:28): [True: 19.3k, Folded]
  ------------------
   64|  19.3k|                               ? u16_swap_bytes(data[pos + 1])
   65|  19.3k|                               : data[pos + 1];
   66|  19.3k|      char16_t diff2 = uint16_t(next_word - 0xDC00);
   67|  19.3k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (67:11): [True: 762, False: 18.6k]
  ------------------
   68|    762|        return result(error_code::SURROGATE, pos);
   69|    762|      }
   70|  18.6k|      pos += 2;
   71|  21.1M|    } else {
   72|  21.1M|      pos++;
   73|  21.1M|    }
   74|  21.1M|  }
   75|  2.52k|  return result(error_code::SUCCESS, pos);
   76|  3.97k|}
_ZN7simdutf6scalar5utf1617count_code_pointsILNS_10endiannessE0EEEmPKDsm:
   79|  5.08k|simdutf_constexpr23 size_t count_code_points(const char16_t *p, size_t len) {
   80|       |  // We are not BOM aware.
   81|  5.08k|  size_t counter{0};
   82|  26.2M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (82:22): [True: 26.2M, False: 5.08k]
  ------------------
   83|  26.2M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   84|  26.2M|    counter += ((word & 0xFC00) != 0xDC00);
   85|  26.2M|  }
   86|  5.08k|  return counter;
   87|  5.08k|}
_ZN7simdutf6scalar5utf1617count_code_pointsILNS_10endiannessE1EEEmPKDsm:
   79|  4.84k|simdutf_constexpr23 size_t count_code_points(const char16_t *p, size_t len) {
   80|       |  // We are not BOM aware.
   81|  4.84k|  size_t counter{0};
   82|  27.7M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (82:22): [True: 27.7M, False: 4.84k]
  ------------------
   83|  27.7M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   84|  27.7M|    counter += ((word & 0xFC00) != 0xDC00);
   85|  27.7M|  }
   86|  4.84k|  return counter;
   87|  4.84k|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE0EEEmPKDsm:
   91|  2.42k|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|  2.42k|  size_t counter{0};
   94|  15.4M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 15.4M, False: 2.42k]
  ------------------
   95|  15.4M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|  15.4M|    counter++; // ASCII
   97|  15.4M|    counter += static_cast<size_t>(
   98|  15.4M|        word >
   99|  15.4M|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|  15.4M|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 3.34M, False: 12.1M]
  |  Branch (100:53): [True: 3.06M, False: 277k]
  ------------------
  101|  12.3M|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 219k, False: 12.1M]
  ------------------
  102|  15.4M|  }
  103|  2.42k|  return counter;
  104|  2.42k|}
_ZN7simdutf6scalar5utf1622utf8_length_from_utf16ILNS_10endiannessE1EEEmPKDsm:
   91|  2.19k|                                                  size_t len) {
   92|       |  // We are not BOM aware.
   93|  2.19k|  size_t counter{0};
   94|  15.3M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (94:22): [True: 15.3M, False: 2.19k]
  ------------------
   95|  15.3M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
   96|  15.3M|    counter++; // ASCII
   97|  15.3M|    counter += static_cast<size_t>(
   98|  15.3M|        word >
   99|  15.3M|        0x7F); // non-ASCII is at least 2 bytes, surrogates are 2*2 == 4 bytes
  100|  15.3M|    counter += static_cast<size_t>((word > 0x7FF && word <= 0xD7FF) ||
  ------------------
  |  Branch (100:37): [True: 2.74M, False: 12.6M]
  |  Branch (100:53): [True: 2.60M, False: 136k]
  ------------------
  101|  12.7M|                                   (word >= 0xE000)); // three-byte
  ------------------
  |  Branch (101:36): [True: 110k, False: 12.6M]
  ------------------
  102|  15.3M|  }
  103|  2.19k|  return counter;
  104|  2.19k|}
_ZN7simdutf6scalar5utf1623utf32_length_from_utf16ILNS_10endiannessE0EEEmPKDsm:
  108|    413|                                                   size_t len) {
  109|       |  // We are not BOM aware.
  110|    413|  size_t counter{0};
  111|  5.10M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (111:22): [True: 5.10M, False: 413]
  ------------------
  112|  5.10M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
  113|  5.10M|    counter += ((word & 0xFC00) != 0xDC00);
  114|  5.10M|  }
  115|    413|  return counter;
  116|    413|}
_ZN7simdutf6scalar5utf1623utf32_length_from_utf16ILNS_10endiannessE1EEEmPKDsm:
  108|    420|                                                   size_t len) {
  109|       |  // We are not BOM aware.
  110|    420|  size_t counter{0};
  111|  6.81M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (111:22): [True: 6.81M, False: 420]
  ------------------
  112|  6.81M|    char16_t word = scalar::utf16::swap_if_needed<big_endian>(p[i]);
  113|  6.81M|    counter += ((word & 0xFC00) != 0xDC00);
  114|  6.81M|  }
  115|    420|  return counter;
  116|    420|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_115utf16_to_latin17convertILNS_10endiannessE0EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT0_Esr7simdutf6detailE26index_assignable_from_charIT1_EEEmS8_mS9_:
   17|    286|                                   OutputPtr latin_output) {
   18|    286|  if (len == 0) {
  ------------------
  |  Branch (18:7): [True: 6, False: 280]
  ------------------
   19|      6|    return 0;
   20|      6|  }
   21|    280|  size_t pos = 0;
   22|    280|  const auto latin_output_start = latin_output;
   23|    280|  uint16_t word = 0;
   24|    280|  uint16_t too_large = 0;
   25|       |
   26|  3.56M|  while (pos < len) {
  ------------------
  |  Branch (26:10): [True: 3.56M, False: 280]
  ------------------
   27|  3.56M|    word = !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (27:12): [Folded, False: 3.56M]
  ------------------
   28|  3.56M|    too_large |= word;
   29|  3.56M|    *latin_output++ = char(word & 0xFF);
   30|  3.56M|    pos++;
   31|  3.56M|  }
   32|    280|  if ((too_large & 0xFF00) != 0) {
  ------------------
  |  Branch (32:7): [True: 166, False: 114]
  ------------------
   33|    166|    return 0;
   34|    166|  }
   35|       |
   36|    114|  return latin_output - latin_output_start;
   37|    280|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_115utf16_to_latin17convertILNS_10endiannessE1EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT0_Esr7simdutf6detailE26index_assignable_from_charIT1_EEEmS8_mS9_:
   17|    258|                                   OutputPtr latin_output) {
   18|    258|  if (len == 0) {
  ------------------
  |  Branch (18:7): [True: 6, False: 252]
  ------------------
   19|      6|    return 0;
   20|      6|  }
   21|    252|  size_t pos = 0;
   22|    252|  const auto latin_output_start = latin_output;
   23|    252|  uint16_t word = 0;
   24|    252|  uint16_t too_large = 0;
   25|       |
   26|  1.87M|  while (pos < len) {
  ------------------
  |  Branch (26:10): [True: 1.87M, False: 252]
  ------------------
   27|  1.87M|    word = !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (27:12): [True: 1.87M, Folded]
  ------------------
   28|  1.87M|    too_large |= word;
   29|  1.87M|    *latin_output++ = char(word & 0xFF);
   30|  1.87M|    pos++;
   31|  1.87M|  }
   32|    252|  if ((too_large & 0xFF00) != 0) {
  ------------------
  |  Branch (32:7): [True: 148, False: 104]
  ------------------
   33|    148|    return 0;
   34|    148|  }
   35|       |
   36|    104|  return latin_output - latin_output_start;
   37|    252|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_115utf16_to_latin119convert_with_errorsILNS_10endiannessE0EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT0_Esr7simdutf6detailE26index_assignable_from_charIT1_EEENS_6resultES8_mS9_:
   45|    482|                                               OutputPtr latin_output) {
   46|    482|  if (len == 0) {
  ------------------
  |  Branch (46:7): [True: 4, False: 478]
  ------------------
   47|      4|    return result(error_code::SUCCESS, 0);
   48|      4|  }
   49|    478|  size_t pos = 0;
   50|    478|  auto start = latin_output;
   51|    478|  uint16_t word;
   52|       |
   53|   453k|  while (pos < len) {
  ------------------
  |  Branch (53:10): [True: 453k, False: 188]
  ------------------
   54|       |#if SIMDUTF_CPLUSPLUS23
   55|       |    if !consteval
   56|       |#endif
   57|   453k|    {
   58|   453k|      if (pos + 16 <= len) { // if it is safe to read 32 more bytes, check that
  ------------------
  |  Branch (58:11): [True: 451k, False: 1.56k]
  ------------------
   59|       |                             // they are Latin1
   60|   451k|        uint64_t v1, v2, v3, v4;
   61|   451k|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   62|   451k|        ::memcpy(&v2, data + pos + 4, sizeof(uint64_t));
   63|   451k|        ::memcpy(&v3, data + pos + 8, sizeof(uint64_t));
   64|   451k|        ::memcpy(&v4, data + pos + 12, sizeof(uint64_t));
   65|       |
   66|       |        if constexpr (!match_system(big_endian)) {
   67|       |          v1 = (v1 >> 8) | (v1 << (64 - 8));
   68|       |        }
   69|       |        if constexpr (!match_system(big_endian)) {
   70|       |          v2 = (v2 >> 8) | (v2 << (64 - 8));
   71|       |        }
   72|       |        if constexpr (!match_system(big_endian)) {
   73|       |          v3 = (v3 >> 8) | (v3 << (64 - 8));
   74|       |        }
   75|       |        if constexpr (!match_system(big_endian)) {
   76|       |          v4 = (v4 >> 8) | (v4 << (64 - 8));
   77|       |        }
   78|       |
   79|   451k|        if (((v1 | v2 | v3 | v4) & 0xFF00FF00FF00FF00) == 0) {
  ------------------
  |  Branch (79:13): [True: 451k, False: 202]
  ------------------
   80|   451k|          size_t final_pos = pos + 16;
   81|  7.67M|          while (pos < final_pos) {
  ------------------
  |  Branch (81:18): [True: 7.22M, False: 451k]
  ------------------
   82|  7.22M|            *latin_output++ = !match_system(big_endian)
  ------------------
  |  Branch (82:31): [Folded, False: 7.22M]
  ------------------
   83|  7.22M|                                  ? char(u16_swap_bytes(data[pos]))
   84|  7.22M|                                  : char(data[pos]);
   85|  7.22M|            pos++;
   86|  7.22M|          }
   87|   451k|          continue;
   88|   451k|        }
   89|   451k|      }
   90|   453k|    }
   91|       |
   92|  1.76k|    word = !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (92:12): [Folded, False: 1.76k]
  ------------------
   93|  1.76k|    if ((word & 0xFF00) == 0) {
  ------------------
  |  Branch (93:9): [True: 1.47k, False: 290]
  ------------------
   94|  1.47k|      *latin_output++ = char(word & 0xFF);
   95|  1.47k|      pos++;
   96|  1.47k|    } else {
   97|    290|      return result(error_code::TOO_LARGE, pos);
   98|    290|    }
   99|  1.76k|  }
  100|    188|  return result(error_code::SUCCESS, latin_output - start);
  101|    478|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_115utf16_to_latin119convert_with_errorsILNS_10endiannessE1EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT0_Esr7simdutf6detailE26index_assignable_from_charIT1_EEENS_6resultES8_mS9_:
   45|    444|                                               OutputPtr latin_output) {
   46|    444|  if (len == 0) {
  ------------------
  |  Branch (46:7): [True: 4, False: 440]
  ------------------
   47|      4|    return result(error_code::SUCCESS, 0);
   48|      4|  }
   49|    440|  size_t pos = 0;
   50|    440|  auto start = latin_output;
   51|    440|  uint16_t word;
   52|       |
   53|   459k|  while (pos < len) {
  ------------------
  |  Branch (53:10): [True: 458k, False: 192]
  ------------------
   54|       |#if SIMDUTF_CPLUSPLUS23
   55|       |    if !consteval
   56|       |#endif
   57|   458k|    {
   58|   458k|      if (pos + 16 <= len) { // if it is safe to read 32 more bytes, check that
  ------------------
  |  Branch (58:11): [True: 457k, False: 1.40k]
  ------------------
   59|       |                             // they are Latin1
   60|   457k|        uint64_t v1, v2, v3, v4;
   61|   457k|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   62|   457k|        ::memcpy(&v2, data + pos + 4, sizeof(uint64_t));
   63|   457k|        ::memcpy(&v3, data + pos + 8, sizeof(uint64_t));
   64|   457k|        ::memcpy(&v4, data + pos + 12, sizeof(uint64_t));
   65|       |
   66|   457k|        if constexpr (!match_system(big_endian)) {
   67|   457k|          v1 = (v1 >> 8) | (v1 << (64 - 8));
   68|   457k|        }
   69|   457k|        if constexpr (!match_system(big_endian)) {
   70|   457k|          v2 = (v2 >> 8) | (v2 << (64 - 8));
   71|   457k|        }
   72|   457k|        if constexpr (!match_system(big_endian)) {
   73|   457k|          v3 = (v3 >> 8) | (v3 << (64 - 8));
   74|   457k|        }
   75|   457k|        if constexpr (!match_system(big_endian)) {
   76|   457k|          v4 = (v4 >> 8) | (v4 << (64 - 8));
   77|   457k|        }
   78|       |
   79|   457k|        if (((v1 | v2 | v3 | v4) & 0xFF00FF00FF00FF00) == 0) {
  ------------------
  |  Branch (79:13): [True: 457k, False: 408]
  ------------------
   80|   457k|          size_t final_pos = pos + 16;
   81|  7.77M|          while (pos < final_pos) {
  ------------------
  |  Branch (81:18): [True: 7.31M, False: 457k]
  ------------------
   82|  7.31M|            *latin_output++ = !match_system(big_endian)
  ------------------
  |  Branch (82:31): [True: 7.31M, Folded]
  ------------------
   83|  7.31M|                                  ? char(u16_swap_bytes(data[pos]))
   84|  7.31M|                                  : char(data[pos]);
   85|  7.31M|            pos++;
   86|  7.31M|          }
   87|   457k|          continue;
   88|   457k|        }
   89|   457k|      }
   90|   458k|    }
   91|       |
   92|  1.81k|    word = !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (92:12): [True: 1.81k, Folded]
  ------------------
   93|  1.81k|    if ((word & 0xFF00) == 0) {
  ------------------
  |  Branch (93:9): [True: 1.56k, False: 248]
  ------------------
   94|  1.56k|      *latin_output++ = char(word & 0xFF);
   95|  1.56k|      pos++;
   96|  1.56k|    } else {
   97|    248|      return result(error_code::TOO_LARGE, pos);
   98|    248|    }
   99|  1.81k|  }
  100|    192|  return result(error_code::SUCCESS, latin_output - start);
  101|    440|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf16_to_utf327convertILNS_10endiannessE0EEEmPKDsmPDi:
   11|    842|                                   char32_t *utf32_output) {
   12|    842|  size_t pos = 0;
   13|    842|  char32_t *start{utf32_output};
   14|  2.49M|  while (pos < len) {
  ------------------
  |  Branch (14:10): [True: 2.49M, False: 502]
  ------------------
   15|  2.49M|    uint16_t word =
   16|  2.49M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (16:9): [Folded, False: 2.49M]
  ------------------
   17|  2.49M|    if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (17:9): [True: 2.47M, False: 24.1k]
  ------------------
   18|       |      // No surrogate pair, extend 16-bit word to 32-bit word
   19|  2.47M|      *utf32_output++ = char32_t(word);
   20|  2.47M|      pos++;
   21|  2.47M|    } else {
   22|       |      // must be a surrogate pair
   23|  24.1k|      uint16_t diff = uint16_t(word - 0xD800);
   24|  24.1k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (24:11): [True: 106, False: 24.0k]
  ------------------
   25|    106|        return 0;
   26|    106|      }
   27|  24.0k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (27:11): [True: 102, False: 23.9k]
  ------------------
   28|    102|        return 0;
   29|    102|      } // minimal bound checking
   30|  23.9k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (30:28): [Folded, False: 23.9k]
  ------------------
   31|  23.9k|                               ? u16_swap_bytes(data[pos + 1])
   32|  23.9k|                               : data[pos + 1];
   33|  23.9k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   34|  23.9k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (34:11): [True: 132, False: 23.7k]
  ------------------
   35|    132|        return 0;
   36|    132|      }
   37|  23.7k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   38|  23.7k|      *utf32_output++ = char32_t(value);
   39|  23.7k|      pos += 2;
   40|  23.7k|    }
   41|  2.49M|  }
   42|    502|  return utf32_output - start;
   43|    842|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf16_to_utf327convertILNS_10endiannessE1EEEmPKDsmPDi:
   11|    852|                                   char32_t *utf32_output) {
   12|    852|  size_t pos = 0;
   13|    852|  char32_t *start{utf32_output};
   14|   272k|  while (pos < len) {
  ------------------
  |  Branch (14:10): [True: 272k, False: 476]
  ------------------
   15|   272k|    uint16_t word =
   16|   272k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (16:9): [True: 272k, Folded]
  ------------------
   17|   272k|    if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (17:9): [True: 270k, False: 1.85k]
  ------------------
   18|       |      // No surrogate pair, extend 16-bit word to 32-bit word
   19|   270k|      *utf32_output++ = char32_t(word);
   20|   270k|      pos++;
   21|   270k|    } else {
   22|       |      // must be a surrogate pair
   23|  1.85k|      uint16_t diff = uint16_t(word - 0xD800);
   24|  1.85k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (24:11): [True: 90, False: 1.76k]
  ------------------
   25|     90|        return 0;
   26|     90|      }
   27|  1.76k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (27:11): [True: 114, False: 1.65k]
  ------------------
   28|    114|        return 0;
   29|    114|      } // minimal bound checking
   30|  1.65k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (30:28): [True: 1.65k, Folded]
  ------------------
   31|  1.65k|                               ? u16_swap_bytes(data[pos + 1])
   32|  1.65k|                               : data[pos + 1];
   33|  1.65k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   34|  1.65k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (34:11): [True: 172, False: 1.47k]
  ------------------
   35|    172|        return 0;
   36|    172|      }
   37|  1.47k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   38|  1.47k|      *utf32_output++ = char32_t(value);
   39|  1.47k|      pos += 2;
   40|  1.47k|    }
   41|   272k|  }
   42|    476|  return utf32_output - start;
   43|    852|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf16_to_utf3219convert_with_errorsILNS_10endiannessE0EEENS_6resultEPKDsmPDi:
   47|    840|                                               char32_t *utf32_output) {
   48|    840|  size_t pos = 0;
   49|    840|  char32_t *start{utf32_output};
   50|  2.85M|  while (pos < len) {
  ------------------
  |  Branch (50:10): [True: 2.85M, False: 482]
  ------------------
   51|  2.85M|    uint16_t word =
   52|  2.85M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (52:9): [Folded, False: 2.85M]
  ------------------
   53|  2.85M|    if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (53:9): [True: 2.84M, False: 12.8k]
  ------------------
   54|       |      // No surrogate pair, extend 16-bit word to 32-bit word
   55|  2.84M|      *utf32_output++ = char32_t(word);
   56|  2.84M|      pos++;
   57|  2.84M|    } else {
   58|       |      // must be a surrogate pair
   59|  12.8k|      uint16_t diff = uint16_t(word - 0xD800);
   60|  12.8k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (60:11): [True: 90, False: 12.7k]
  ------------------
   61|     90|        return result(error_code::SURROGATE, pos);
   62|     90|      }
   63|  12.7k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (63:11): [True: 114, False: 12.6k]
  ------------------
   64|    114|        return result(error_code::SURROGATE, pos);
   65|    114|      } // minimal bound checking
   66|  12.6k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (66:28): [Folded, False: 12.6k]
  ------------------
   67|  12.6k|                               ? u16_swap_bytes(data[pos + 1])
   68|  12.6k|                               : data[pos + 1];
   69|  12.6k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   70|  12.6k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (70:11): [True: 154, False: 12.5k]
  ------------------
   71|    154|        return result(error_code::SURROGATE, pos);
   72|    154|      }
   73|  12.5k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   74|  12.5k|      *utf32_output++ = char32_t(value);
   75|  12.5k|      pos += 2;
   76|  12.5k|    }
   77|  2.85M|  }
   78|    482|  return result(error_code::SUCCESS, utf32_output - start);
   79|    840|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf16_to_utf3219convert_with_errorsILNS_10endiannessE1EEENS_6resultEPKDsmPDi:
   47|    828|                                               char32_t *utf32_output) {
   48|    828|  size_t pos = 0;
   49|    828|  char32_t *start{utf32_output};
   50|  3.04M|  while (pos < len) {
  ------------------
  |  Branch (50:10): [True: 3.04M, False: 444]
  ------------------
   51|  3.04M|    uint16_t word =
   52|  3.04M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (52:9): [True: 3.04M, Folded]
  ------------------
   53|  3.04M|    if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (53:9): [True: 3.03M, False: 9.04k]
  ------------------
   54|       |      // No surrogate pair, extend 16-bit word to 32-bit word
   55|  3.03M|      *utf32_output++ = char32_t(word);
   56|  3.03M|      pos++;
   57|  3.03M|    } else {
   58|       |      // must be a surrogate pair
   59|  9.04k|      uint16_t diff = uint16_t(word - 0xD800);
   60|  9.04k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (60:11): [True: 98, False: 8.95k]
  ------------------
   61|     98|        return result(error_code::SURROGATE, pos);
   62|     98|      }
   63|  8.95k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (63:11): [True: 102, False: 8.84k]
  ------------------
   64|    102|        return result(error_code::SURROGATE, pos);
   65|    102|      } // minimal bound checking
   66|  8.84k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (66:28): [True: 8.84k, Folded]
  ------------------
   67|  8.84k|                               ? u16_swap_bytes(data[pos + 1])
   68|  8.84k|                               : data[pos + 1];
   69|  8.84k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   70|  8.84k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (70:11): [True: 184, False: 8.66k]
  ------------------
   71|    184|        return result(error_code::SURROGATE, pos);
   72|    184|      }
   73|  8.66k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   74|  8.66k|      *utf32_output++ = char32_t(value);
   75|  8.66k|      pos += 2;
   76|  8.66k|    }
   77|  3.04M|  }
   78|    444|  return result(error_code::SUCCESS, utf32_output - start);
   79|    828|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf16_to_utf3213convert_validILNS_10endiannessE0EEEmPKDsmPDi:
   11|    118|                                         char32_t *utf32_output) {
   12|    118|  size_t pos = 0;
   13|    118|  char32_t *start{utf32_output};
   14|  2.68M|  while (pos < len) {
  ------------------
  |  Branch (14:10): [True: 2.68M, False: 118]
  ------------------
   15|  2.68M|    uint16_t word =
   16|  2.68M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (16:9): [Folded, False: 2.68M]
  ------------------
   17|  2.68M|    if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (17:9): [True: 2.67M, False: 3.69k]
  ------------------
   18|       |      // No surrogate pair, extend 16-bit word to 32-bit word
   19|  2.67M|      *utf32_output++ = char32_t(word);
   20|  2.67M|      pos++;
   21|  2.67M|    } else {
   22|       |      // must be a surrogate pair
   23|  3.69k|      uint16_t diff = uint16_t(word - 0xD800);
   24|  3.69k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (24:11): [True: 0, False: 3.69k]
  ------------------
   25|      0|        return 0;
   26|      0|      } // minimal bound checking
   27|  3.69k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (27:28): [Folded, False: 3.69k]
  ------------------
   28|  3.69k|                               ? u16_swap_bytes(data[pos + 1])
   29|  3.69k|                               : data[pos + 1];
   30|  3.69k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   31|  3.69k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   32|  3.69k|      *utf32_output++ = char32_t(value);
   33|  3.69k|      pos += 2;
   34|  3.69k|    }
   35|  2.68M|  }
   36|    118|  return utf32_output - start;
   37|    118|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf16_to_utf3213convert_validILNS_10endiannessE1EEEmPKDsmPDi:
   11|    134|                                         char32_t *utf32_output) {
   12|    134|  size_t pos = 0;
   13|    134|  char32_t *start{utf32_output};
   14|  3.68M|  while (pos < len) {
  ------------------
  |  Branch (14:10): [True: 3.68M, False: 134]
  ------------------
   15|  3.68M|    uint16_t word =
   16|  3.68M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (16:9): [True: 3.68M, Folded]
  ------------------
   17|  3.68M|    if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (17:9): [True: 3.68M, False: 830]
  ------------------
   18|       |      // No surrogate pair, extend 16-bit word to 32-bit word
   19|  3.68M|      *utf32_output++ = char32_t(word);
   20|  3.68M|      pos++;
   21|  3.68M|    } else {
   22|       |      // must be a surrogate pair
   23|    830|      uint16_t diff = uint16_t(word - 0xD800);
   24|    830|      if (pos + 1 >= len) {
  ------------------
  |  Branch (24:11): [True: 0, False: 830]
  ------------------
   25|      0|        return 0;
   26|      0|      } // minimal bound checking
   27|    830|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (27:28): [True: 830, Folded]
  ------------------
   28|    830|                               ? u16_swap_bytes(data[pos + 1])
   29|    830|                               : data[pos + 1];
   30|    830|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   31|    830|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   32|    830|      *utf32_output++ = char32_t(value);
   33|    830|      pos += 2;
   34|    830|    }
   35|  3.68M|  }
   36|    134|  return utf32_output - start;
   37|    134|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf87convertILNS_10endiannessE0EPKDsPcQsr7simdutf6detailE18indexes_into_utf16IT0_EEEmS8_mT1_:
   17|  1.98k|                                   OutputPtr utf8_output) {
   18|  1.98k|  size_t pos = 0;
   19|  1.98k|  const auto start = utf8_output;
   20|  2.62M|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 2.62M, False: 1.56k]
  ------------------
   21|       |#if SIMDUTF_CPLUSPLUS23
   22|       |    if !consteval
   23|       |#endif
   24|  2.62M|    {
   25|       |      // try to convert the next block of 8 bytes
   26|  2.62M|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (26:11): [True: 2.62M, False: 3.55k]
  ------------------
   27|       |                            // they are ascii
   28|  2.62M|        uint64_t v;
   29|  2.62M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   30|       |        if constexpr (!match_system(big_endian)) {
   31|       |          v = (v >> 8) | (v << (64 - 8));
   32|       |        }
   33|  2.62M|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (33:13): [True: 1.69M, False: 928k]
  ------------------
   34|  1.69M|          size_t final_pos = pos + 4;
   35|  8.47M|          while (pos < final_pos) {
  ------------------
  |  Branch (35:18): [True: 6.78M, False: 1.69M]
  ------------------
   36|  6.78M|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (36:30): [Folded, False: 6.78M]
  ------------------
   37|  6.78M|                                 ? char(u16_swap_bytes(data[pos]))
   38|  6.78M|                                 : char(data[pos]);
   39|  6.78M|            pos++;
   40|  6.78M|          }
   41|  1.69M|          continue;
   42|  1.69M|        }
   43|  2.62M|      }
   44|  2.62M|    }
   45|   932k|    uint16_t word =
   46|   932k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (46:9): [Folded, False: 932k]
  ------------------
   47|   932k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (47:9): [True: 177k, False: 754k]
  ------------------
   48|       |      // will generate one UTF-8 bytes
   49|   177k|      *utf8_output++ = char(word);
   50|   177k|      pos++;
   51|   754k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (51:16): [True: 333k, False: 420k]
  ------------------
   52|       |      // will generate two UTF-8 bytes
   53|       |      // we have 0b110XXXXX 0b10XXXXXX
   54|   333k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   55|   333k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   56|   333k|      pos++;
   57|   420k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (57:16): [True: 413k, False: 6.80k]
  ------------------
   58|       |      // will generate three UTF-8 bytes
   59|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   60|   413k|      *utf8_output++ = char((word >> 12) | 0b11100000);
   61|   413k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   62|   413k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   63|   413k|      pos++;
   64|   413k|    } else {
   65|       |      // must be a surrogate pair
   66|  6.80k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (66:11): [True: 78, False: 6.72k]
  ------------------
   67|     78|        return 0;
   68|     78|      }
   69|  6.72k|      uint16_t diff = uint16_t(word - 0xD800);
   70|  6.72k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (70:11): [True: 122, False: 6.60k]
  ------------------
   71|    122|        return 0;
   72|    122|      }
   73|  6.60k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (73:28): [Folded, False: 6.60k]
  ------------------
   74|  6.60k|                               ? u16_swap_bytes(data[pos + 1])
   75|  6.60k|                               : data[pos + 1];
   76|  6.60k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   77|  6.60k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (77:11): [True: 218, False: 6.38k]
  ------------------
   78|    218|        return 0;
   79|    218|      }
   80|  6.38k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   81|       |      // will generate four UTF-8 bytes
   82|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   83|  6.38k|      *utf8_output++ = char((value >> 18) | 0b11110000);
   84|  6.38k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
   85|  6.38k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
   86|  6.38k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
   87|  6.38k|      pos += 2;
   88|  6.38k|    }
   89|   932k|  }
   90|  1.56k|  return utf8_output - start;
   91|  1.98k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf87convertILNS_10endiannessE1EPKDsPcQsr7simdutf6detailE18indexes_into_utf16IT0_EEEmS8_mT1_:
   17|  1.80k|                                   OutputPtr utf8_output) {
   18|  1.80k|  size_t pos = 0;
   19|  1.80k|  const auto start = utf8_output;
   20|  2.41M|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 2.40M, False: 1.43k]
  ------------------
   21|       |#if SIMDUTF_CPLUSPLUS23
   22|       |    if !consteval
   23|       |#endif
   24|  2.40M|    {
   25|       |      // try to convert the next block of 8 bytes
   26|  2.40M|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (26:11): [True: 2.40M, False: 3.23k]
  ------------------
   27|       |                            // they are ascii
   28|  2.40M|        uint64_t v;
   29|  2.40M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   30|  2.40M|        if constexpr (!match_system(big_endian)) {
   31|  2.40M|          v = (v >> 8) | (v << (64 - 8));
   32|  2.40M|        }
   33|  2.40M|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (33:13): [True: 1.50M, False: 900k]
  ------------------
   34|  1.50M|          size_t final_pos = pos + 4;
   35|  7.52M|          while (pos < final_pos) {
  ------------------
  |  Branch (35:18): [True: 6.02M, False: 1.50M]
  ------------------
   36|  6.02M|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (36:30): [True: 6.02M, Folded]
  ------------------
   37|  6.02M|                                 ? char(u16_swap_bytes(data[pos]))
   38|  6.02M|                                 : char(data[pos]);
   39|  6.02M|            pos++;
   40|  6.02M|          }
   41|  1.50M|          continue;
   42|  1.50M|        }
   43|  2.40M|      }
   44|  2.40M|    }
   45|   904k|    uint16_t word =
   46|   904k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (46:9): [True: 904k, Folded]
  ------------------
   47|   904k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (47:9): [True: 117k, False: 786k]
  ------------------
   48|       |      // will generate one UTF-8 bytes
   49|   117k|      *utf8_output++ = char(word);
   50|   117k|      pos++;
   51|   786k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (51:16): [True: 38.8k, False: 747k]
  ------------------
   52|       |      // will generate two UTF-8 bytes
   53|       |      // we have 0b110XXXXX 0b10XXXXXX
   54|  38.8k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   55|  38.8k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   56|  38.8k|      pos++;
   57|   747k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (57:16): [True: 741k, False: 5.42k]
  ------------------
   58|       |      // will generate three UTF-8 bytes
   59|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   60|   741k|      *utf8_output++ = char((word >> 12) | 0b11100000);
   61|   741k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   62|   741k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   63|   741k|      pos++;
   64|   741k|    } else {
   65|       |      // must be a surrogate pair
   66|  5.42k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (66:11): [True: 66, False: 5.36k]
  ------------------
   67|     66|        return 0;
   68|     66|      }
   69|  5.36k|      uint16_t diff = uint16_t(word - 0xD800);
   70|  5.36k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (70:11): [True: 136, False: 5.22k]
  ------------------
   71|    136|        return 0;
   72|    136|      }
   73|  5.22k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (73:28): [True: 5.22k, Folded]
  ------------------
   74|  5.22k|                               ? u16_swap_bytes(data[pos + 1])
   75|  5.22k|                               : data[pos + 1];
   76|  5.22k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   77|  5.22k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (77:11): [True: 170, False: 5.05k]
  ------------------
   78|    170|        return 0;
   79|    170|      }
   80|  5.05k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   81|       |      // will generate four UTF-8 bytes
   82|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   83|  5.05k|      *utf8_output++ = char((value >> 18) | 0b11110000);
   84|  5.05k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
   85|  5.05k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
   86|  5.05k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
   87|  5.05k|      pos += 2;
   88|  5.05k|    }
   89|   904k|  }
   90|  1.43k|  return utf8_output - start;
   91|  1.80k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf819convert_with_errorsILNS_10endiannessE0ELb0EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT1_Esr7simdutf6detailE26index_assignable_from_charIT2_EEENS_11full_resultES8_mS9_m:
  101|  1.84k|                                                    size_t utf8_len = 0) {
  102|  1.84k|  if (check_output && utf8_len == 0) {
  ------------------
  |  Branch (102:7): [Folded, False: 1.84k]
  |  Branch (102:23): [True: 0, False: 0]
  ------------------
  103|      0|    return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, 0, 0);
  104|      0|  }
  105|       |
  106|  1.84k|  size_t pos = 0;
  107|  1.84k|  auto start = utf8_output;
  108|  1.84k|  auto end = utf8_output + utf8_len;
  109|       |
  110|  5.17M|  while (pos < len) {
  ------------------
  |  Branch (110:10): [True: 5.16M, False: 1.31k]
  ------------------
  111|       |#if SIMDUTF_CPLUSPLUS23
  112|       |    if !consteval
  113|       |#endif
  114|  5.16M|    {
  115|       |      // try to convert the next block of 8 bytes
  116|  5.16M|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (116:11): [True: 5.16M, False: 3.13k]
  ------------------
  117|       |                            // they are ascii
  118|  5.16M|        uint64_t v;
  119|  5.16M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
  120|       |        if constexpr (!match_system(big_endian))
  121|       |          v = (v >> 8) | (v << (64 - 8));
  122|  5.16M|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (122:13): [True: 1.59M, False: 3.57M]
  ------------------
  123|  1.59M|          size_t final_pos = pos + 4;
  124|  7.97M|          while (pos < final_pos) {
  ------------------
  |  Branch (124:18): [True: 6.37M, False: 1.59M]
  ------------------
  125|  6.37M|            if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (125:17): [Folded, False: 6.37M]
  |  Branch (125:33): [True: 0, False: 0]
  ------------------
  126|      0|              return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  127|      0|                                 utf8_output - start);
  128|      0|            }
  129|  6.37M|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (129:30): [Folded, False: 6.37M]
  ------------------
  130|  6.37M|                                 ? char(u16_swap_bytes(data[pos]))
  131|  6.37M|                                 : char(data[pos]);
  132|  6.37M|            pos++;
  133|  6.37M|          }
  134|  1.59M|          continue;
  135|  1.59M|        }
  136|  5.16M|      }
  137|  5.16M|    }
  138|       |
  139|  3.57M|    uint16_t word =
  140|  3.57M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (140:9): [Folded, False: 3.57M]
  ------------------
  141|  3.57M|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (141:9): [True: 323k, False: 3.25M]
  ------------------
  142|       |      // will generate one UTF-8 bytes
  143|   323k|      if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (143:11): [Folded, False: 323k]
  |  Branch (143:27): [True: 0, False: 0]
  ------------------
  144|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  145|      0|                           utf8_output - start);
  146|      0|      }
  147|   323k|      *utf8_output++ = char(word);
  148|   323k|      pos++;
  149|  3.25M|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (149:16): [True: 138k, False: 3.11M]
  ------------------
  150|       |      // will generate two UTF-8 bytes
  151|       |      // we have 0b110XXXXX 0b10XXXXXX
  152|   138k|      if (check_output && size_t(end - utf8_output) < 2) {
  ------------------
  |  Branch (152:11): [Folded, False: 138k]
  |  Branch (152:27): [True: 0, False: 0]
  ------------------
  153|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  154|      0|                           utf8_output - start);
  155|      0|      }
  156|   138k|      *utf8_output++ = char((word >> 6) | 0b11000000);
  157|   138k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  158|   138k|      pos++;
  159|       |
  160|  3.11M|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (160:16): [True: 3.10M, False: 7.03k]
  ------------------
  161|       |      // will generate three UTF-8 bytes
  162|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
  163|  3.10M|      if (check_output && size_t(end - utf8_output) < 3) {
  ------------------
  |  Branch (163:11): [Folded, False: 3.10M]
  |  Branch (163:27): [True: 0, False: 0]
  ------------------
  164|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  165|      0|                           utf8_output - start);
  166|      0|      }
  167|  3.10M|      *utf8_output++ = char((word >> 12) | 0b11100000);
  168|  3.10M|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  169|  3.10M|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  170|  3.10M|      pos++;
  171|  3.10M|    } else {
  172|       |
  173|  7.03k|      if (check_output && size_t(end - utf8_output) < 4) {
  ------------------
  |  Branch (173:11): [Folded, False: 7.03k]
  |  Branch (173:27): [True: 0, False: 0]
  ------------------
  174|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  175|      0|                           utf8_output - start);
  176|      0|      }
  177|       |      // must be a surrogate pair
  178|  7.03k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (178:11): [True: 84, False: 6.95k]
  ------------------
  179|     84|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  180|     84|      }
  181|  6.95k|      uint16_t diff = uint16_t(word - 0xD800);
  182|  6.95k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (182:11): [True: 152, False: 6.79k]
  ------------------
  183|    152|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  184|    152|      }
  185|  6.79k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (185:28): [Folded, False: 6.79k]
  ------------------
  186|  6.79k|                               ? u16_swap_bytes(data[pos + 1])
  187|  6.79k|                               : data[pos + 1];
  188|  6.79k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
  189|  6.79k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (189:11): [True: 298, False: 6.50k]
  ------------------
  190|    298|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  191|    298|      }
  192|  6.50k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
  193|       |      // will generate four UTF-8 bytes
  194|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
  195|  6.50k|      *utf8_output++ = char((value >> 18) | 0b11110000);
  196|  6.50k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  197|  6.50k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  198|  6.50k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
  199|  6.50k|      pos += 2;
  200|  6.50k|    }
  201|  3.57M|  }
  202|  1.31k|  return full_result(error_code::SUCCESS, pos, utf8_output - start);
  203|  1.84k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf819convert_with_errorsILNS_10endiannessE1ELb0EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT1_Esr7simdutf6detailE26index_assignable_from_charIT2_EEENS_11full_resultES8_mS9_m:
  101|  1.56k|                                                    size_t utf8_len = 0) {
  102|  1.56k|  if (check_output && utf8_len == 0) {
  ------------------
  |  Branch (102:7): [Folded, False: 1.56k]
  |  Branch (102:23): [True: 0, False: 0]
  ------------------
  103|      0|    return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, 0, 0);
  104|      0|  }
  105|       |
  106|  1.56k|  size_t pos = 0;
  107|  1.56k|  auto start = utf8_output;
  108|  1.56k|  auto end = utf8_output + utf8_len;
  109|       |
  110|  3.04M|  while (pos < len) {
  ------------------
  |  Branch (110:10): [True: 3.04M, False: 1.10k]
  ------------------
  111|       |#if SIMDUTF_CPLUSPLUS23
  112|       |    if !consteval
  113|       |#endif
  114|  3.04M|    {
  115|       |      // try to convert the next block of 8 bytes
  116|  3.04M|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (116:11): [True: 3.04M, False: 2.56k]
  ------------------
  117|       |                            // they are ascii
  118|  3.04M|        uint64_t v;
  119|  3.04M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
  120|       |        if constexpr (!match_system(big_endian))
  121|  3.04M|          v = (v >> 8) | (v << (64 - 8));
  122|  3.04M|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (122:13): [True: 1.52M, False: 1.51M]
  ------------------
  123|  1.52M|          size_t final_pos = pos + 4;
  124|  7.63M|          while (pos < final_pos) {
  ------------------
  |  Branch (124:18): [True: 6.10M, False: 1.52M]
  ------------------
  125|  6.10M|            if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (125:17): [Folded, False: 6.10M]
  |  Branch (125:33): [True: 0, False: 0]
  ------------------
  126|      0|              return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  127|      0|                                 utf8_output - start);
  128|      0|            }
  129|  6.10M|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (129:30): [True: 6.10M, Folded]
  ------------------
  130|  6.10M|                                 ? char(u16_swap_bytes(data[pos]))
  131|  6.10M|                                 : char(data[pos]);
  132|  6.10M|            pos++;
  133|  6.10M|          }
  134|  1.52M|          continue;
  135|  1.52M|        }
  136|  3.04M|      }
  137|  3.04M|    }
  138|       |
  139|  1.51M|    uint16_t word =
  140|  1.51M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (140:9): [True: 1.51M, Folded]
  ------------------
  141|  1.51M|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (141:9): [True: 294k, False: 1.22M]
  ------------------
  142|       |      // will generate one UTF-8 bytes
  143|   294k|      if (check_output && size_t(end - utf8_output) < 1) {
  ------------------
  |  Branch (143:11): [Folded, False: 294k]
  |  Branch (143:27): [True: 0, False: 0]
  ------------------
  144|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  145|      0|                           utf8_output - start);
  146|      0|      }
  147|   294k|      *utf8_output++ = char(word);
  148|   294k|      pos++;
  149|  1.22M|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (149:16): [True: 122k, False: 1.10M]
  ------------------
  150|       |      // will generate two UTF-8 bytes
  151|       |      // we have 0b110XXXXX 0b10XXXXXX
  152|   122k|      if (check_output && size_t(end - utf8_output) < 2) {
  ------------------
  |  Branch (152:11): [Folded, False: 122k]
  |  Branch (152:27): [True: 0, False: 0]
  ------------------
  153|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  154|      0|                           utf8_output - start);
  155|      0|      }
  156|   122k|      *utf8_output++ = char((word >> 6) | 0b11000000);
  157|   122k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  158|   122k|      pos++;
  159|       |
  160|  1.10M|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (160:16): [True: 1.08M, False: 11.8k]
  ------------------
  161|       |      // will generate three UTF-8 bytes
  162|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
  163|  1.08M|      if (check_output && size_t(end - utf8_output) < 3) {
  ------------------
  |  Branch (163:11): [Folded, False: 1.08M]
  |  Branch (163:27): [True: 0, False: 0]
  ------------------
  164|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  165|      0|                           utf8_output - start);
  166|      0|      }
  167|  1.08M|      *utf8_output++ = char((word >> 12) | 0b11100000);
  168|  1.08M|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  169|  1.08M|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  170|  1.08M|      pos++;
  171|  1.08M|    } else {
  172|       |
  173|  11.8k|      if (check_output && size_t(end - utf8_output) < 4) {
  ------------------
  |  Branch (173:11): [Folded, False: 11.8k]
  |  Branch (173:27): [True: 0, False: 0]
  ------------------
  174|      0|        return full_result(error_code::OUTPUT_BUFFER_TOO_SMALL, pos,
  175|      0|                           utf8_output - start);
  176|      0|      }
  177|       |      // must be a surrogate pair
  178|  11.8k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (178:11): [True: 54, False: 11.8k]
  ------------------
  179|     54|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  180|     54|      }
  181|  11.8k|      uint16_t diff = uint16_t(word - 0xD800);
  182|  11.8k|      if (diff > 0x3FF) {
  ------------------
  |  Branch (182:11): [True: 158, False: 11.6k]
  ------------------
  183|    158|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  184|    158|      }
  185|  11.6k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (185:28): [True: 11.6k, Folded]
  ------------------
  186|  11.6k|                               ? u16_swap_bytes(data[pos + 1])
  187|  11.6k|                               : data[pos + 1];
  188|  11.6k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
  189|  11.6k|      if (diff2 > 0x3FF) {
  ------------------
  |  Branch (189:11): [True: 248, False: 11.4k]
  ------------------
  190|    248|        return full_result(error_code::SURROGATE, pos, utf8_output - start);
  191|    248|      }
  192|  11.4k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
  193|       |      // will generate four UTF-8 bytes
  194|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
  195|  11.4k|      *utf8_output++ = char((value >> 18) | 0b11110000);
  196|  11.4k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  197|  11.4k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  198|  11.4k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
  199|  11.4k|      pos += 2;
  200|  11.4k|    }
  201|  1.51M|  }
  202|  1.10k|  return full_result(error_code::SUCCESS, pos, utf8_output - start);
  203|  1.56k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf813convert_validILNS_10endiannessE0EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT0_Esr7simdutf6detailE26index_assignable_from_charIT1_EEEmS8_mS9_:
   17|    372|                                         OutputPtr utf8_output) {
   18|    372|  size_t pos = 0;
   19|    372|  auto start = utf8_output;
   20|  1.84M|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 1.84M, False: 372]
  ------------------
   21|       |#if SIMDUTF_CPLUSPLUS23
   22|       |    if !consteval
   23|       |#endif
   24|  1.84M|    {
   25|       |      // try to convert the next block of 4 ASCII characters
   26|  1.84M|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (26:11): [True: 1.84M, False: 766]
  ------------------
   27|       |                            // they are ascii
   28|  1.84M|        uint64_t v;
   29|  1.84M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   30|       |        if constexpr (!match_system(big_endian)) {
   31|       |          v = (v >> 8) | (v << (64 - 8));
   32|       |        }
   33|  1.84M|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (33:13): [True: 1.42M, False: 417k]
  ------------------
   34|  1.42M|          size_t final_pos = pos + 4;
   35|  7.11M|          while (pos < final_pos) {
  ------------------
  |  Branch (35:18): [True: 5.69M, False: 1.42M]
  ------------------
   36|  5.69M|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (36:30): [Folded, False: 5.69M]
  ------------------
   37|  5.69M|                                 ? char(u16_swap_bytes(data[pos]))
   38|  5.69M|                                 : char(data[pos]);
   39|  5.69M|            pos++;
   40|  5.69M|          }
   41|  1.42M|          continue;
   42|  1.42M|        }
   43|  1.84M|      }
   44|  1.84M|    }
   45|       |
   46|   418k|    uint16_t word =
   47|   418k|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (47:9): [Folded, False: 418k]
  ------------------
   48|   418k|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (48:9): [True: 174k, False: 243k]
  ------------------
   49|       |      // will generate one UTF-8 bytes
   50|   174k|      *utf8_output++ = char(word);
   51|   174k|      pos++;
   52|   243k|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (52:16): [True: 53.8k, False: 189k]
  ------------------
   53|       |      // will generate two UTF-8 bytes
   54|       |      // we have 0b110XXXXX 0b10XXXXXX
   55|  53.8k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   56|  53.8k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   57|  53.8k|      pos++;
   58|   189k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (58:16): [True: 186k, False: 3.49k]
  ------------------
   59|       |      // will generate three UTF-8 bytes
   60|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   61|   186k|      *utf8_output++ = char((word >> 12) | 0b11100000);
   62|   186k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   63|   186k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   64|   186k|      pos++;
   65|   186k|    } else {
   66|       |      // must be a surrogate pair
   67|  3.49k|      uint16_t diff = uint16_t(word - 0xD800);
   68|  3.49k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (68:11): [True: 0, False: 3.49k]
  ------------------
   69|      0|        return 0;
   70|      0|      } // minimal bound checking
   71|  3.49k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (71:28): [Folded, False: 3.49k]
  ------------------
   72|  3.49k|                               ? u16_swap_bytes(data[pos + 1])
   73|  3.49k|                               : data[pos + 1];
   74|  3.49k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   75|  3.49k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   76|       |      // will generate four UTF-8 bytes
   77|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   78|  3.49k|      *utf8_output++ = char((value >> 18) | 0b11110000);
   79|  3.49k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
   80|  3.49k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
   81|  3.49k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
   82|  3.49k|      pos += 2;
   83|  3.49k|    }
   84|   418k|  }
   85|    372|  return utf8_output - start;
   86|    372|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf16_to_utf813convert_validILNS_10endiannessE1EPKDsPcQaasr7simdutf6detailE18indexes_into_utf16IT0_Esr7simdutf6detailE26index_assignable_from_charIT1_EEEmS8_mS9_:
   17|    416|                                         OutputPtr utf8_output) {
   18|    416|  size_t pos = 0;
   19|    416|  auto start = utf8_output;
   20|  3.79M|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 3.79M, False: 416]
  ------------------
   21|       |#if SIMDUTF_CPLUSPLUS23
   22|       |    if !consteval
   23|       |#endif
   24|  3.79M|    {
   25|       |      // try to convert the next block of 4 ASCII characters
   26|  3.79M|      if (pos + 4 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (26:11): [True: 3.79M, False: 856]
  ------------------
   27|       |                            // they are ascii
   28|  3.79M|        uint64_t v;
   29|  3.79M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   30|  3.79M|        if constexpr (!match_system(big_endian)) {
   31|  3.79M|          v = (v >> 8) | (v << (64 - 8));
   32|  3.79M|        }
   33|  3.79M|        if ((v & 0xFF80FF80FF80FF80) == 0) {
  ------------------
  |  Branch (33:13): [True: 2.32M, False: 1.46M]
  ------------------
   34|  2.32M|          size_t final_pos = pos + 4;
   35|  11.6M|          while (pos < final_pos) {
  ------------------
  |  Branch (35:18): [True: 9.31M, False: 2.32M]
  ------------------
   36|  9.31M|            *utf8_output++ = !match_system(big_endian)
  ------------------
  |  Branch (36:30): [True: 9.31M, Folded]
  ------------------
   37|  9.31M|                                 ? char(u16_swap_bytes(data[pos]))
   38|  9.31M|                                 : char(data[pos]);
   39|  9.31M|            pos++;
   40|  9.31M|          }
   41|  2.32M|          continue;
   42|  2.32M|        }
   43|  3.79M|      }
   44|  3.79M|    }
   45|       |
   46|  1.46M|    uint16_t word =
   47|  1.46M|        !match_system(big_endian) ? u16_swap_bytes(data[pos]) : data[pos];
  ------------------
  |  Branch (47:9): [True: 1.46M, Folded]
  ------------------
   48|  1.46M|    if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (48:9): [True: 383k, False: 1.07M]
  ------------------
   49|       |      // will generate one UTF-8 bytes
   50|   383k|      *utf8_output++ = char(word);
   51|   383k|      pos++;
   52|  1.07M|    } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (52:16): [True: 167k, False: 912k]
  ------------------
   53|       |      // will generate two UTF-8 bytes
   54|       |      // we have 0b110XXXXX 0b10XXXXXX
   55|   167k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   56|   167k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   57|   167k|      pos++;
   58|   912k|    } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (58:16): [True: 905k, False: 6.17k]
  ------------------
   59|       |      // will generate three UTF-8 bytes
   60|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   61|   905k|      *utf8_output++ = char((word >> 12) | 0b11100000);
   62|   905k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   63|   905k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   64|   905k|      pos++;
   65|   905k|    } else {
   66|       |      // must be a surrogate pair
   67|  6.17k|      uint16_t diff = uint16_t(word - 0xD800);
   68|  6.17k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (68:11): [True: 0, False: 6.17k]
  ------------------
   69|      0|        return 0;
   70|      0|      } // minimal bound checking
   71|  6.17k|      uint16_t next_word = !match_system(big_endian)
  ------------------
  |  Branch (71:28): [True: 6.17k, Folded]
  ------------------
   72|  6.17k|                               ? u16_swap_bytes(data[pos + 1])
   73|  6.17k|                               : data[pos + 1];
   74|  6.17k|      uint16_t diff2 = uint16_t(next_word - 0xDC00);
   75|  6.17k|      uint32_t value = (diff << 10) + diff2 + 0x10000;
   76|       |      // will generate four UTF-8 bytes
   77|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   78|  6.17k|      *utf8_output++ = char((value >> 18) | 0b11110000);
   79|  6.17k|      *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
   80|  6.17k|      *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
   81|  6.17k|      *utf8_output++ = char((value & 0b111111) | 0b10000000);
   82|  6.17k|      pos += 2;
   83|  6.17k|    }
   84|  1.46M|  }
   85|    416|  return utf8_output - start;
   86|    416|}

_ZN7simdutf6scalar5utf328validateEPKDim:
   25|  5.77k|                                                        size_t len) noexcept {
   26|  5.77k|  return validate(reinterpret_cast<const uint32_t *>(buf), len);
   27|  5.77k|}
_ZN7simdutf6scalar5utf3220validate_with_errorsEPKDim:
   49|  8.01k|validate_with_errors(const char32_t *buf, size_t len) noexcept {
   50|  8.01k|  return validate_with_errors(reinterpret_cast<const uint32_t *>(buf), len);
   51|  8.01k|}
_ZN7simdutf6scalar5utf3222utf8_length_from_utf32EPKDim:
   54|  2.67k|                                                         size_t len) {
   55|       |  // We are not BOM aware.
   56|  2.67k|  size_t counter{0};
   57|  2.40M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (57:22): [True: 2.40M, False: 2.67k]
  ------------------
   58|       |    // credit: @ttsugriy  for the vectorizable approach
   59|  2.40M|    counter++;                                     // ASCII
   60|  2.40M|    counter += static_cast<size_t>(p[i] > 0x7F);   // two-byte
   61|  2.40M|    counter += static_cast<size_t>(p[i] > 0x7FF);  // three-byte
   62|  2.40M|    counter += static_cast<size_t>(p[i] > 0xFFFF); // four-bytes
   63|  2.40M|  }
   64|  2.67k|  return counter;
   65|  2.67k|}
_ZN7simdutf6scalar5utf3223utf16_length_from_utf32EPKDim:
   68|  4.37k|utf16_length_from_utf32(const char32_t *p, size_t len) {
   69|       |  // We are not BOM aware.
   70|  4.37k|  size_t counter{0};
   71|  3.87M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (71:22): [True: 3.86M, False: 4.37k]
  ------------------
   72|  3.86M|    counter++;                                     // non-surrogate word
   73|  3.86M|    counter += static_cast<size_t>(p[i] > 0xFFFF); // surrogate pair
   74|  3.86M|  }
   75|  4.37k|  return counter;
   76|  4.37k|}
_ZN7simdutf6scalar5utf328validateIPKjQsr7simdutf6detailE19indexes_into_uint32IT_EEEbS5_m:
   13|  5.77k|                                                      size_t len) noexcept {
   14|  5.77k|  uint64_t pos = 0;
   15|   583k|  for (; pos < len; pos++) {
  ------------------
  |  Branch (15:10): [True: 580k, False: 2.52k]
  ------------------
   16|   580k|    uint32_t word = data[pos];
   17|   580k|    if (word > 0x10FFFF || (word >= 0xD800 && word <= 0xDFFF)) {
  ------------------
  |  Branch (17:9): [True: 2.75k, False: 578k]
  |  Branch (17:29): [True: 34.7k, False: 543k]
  |  Branch (17:47): [True: 507, False: 34.2k]
  ------------------
   18|  3.25k|      return false;
   19|  3.25k|    }
   20|   580k|  }
   21|  2.52k|  return true;
   22|  5.77k|}
_ZN7simdutf6scalar5utf3220validate_with_errorsIPKjQsr7simdutf6detailE19indexes_into_uint32IT_EEENS_6resultES5_m:
   34|  8.01k|validate_with_errors(InputPtr data, size_t len) noexcept {
   35|  8.01k|  size_t pos = 0;
   36|   589k|  for (; pos < len; pos++) {
  ------------------
  |  Branch (36:10): [True: 587k, False: 2.52k]
  ------------------
   37|   587k|    uint32_t word = data[pos];
   38|   587k|    if (word > 0x10FFFF) {
  ------------------
  |  Branch (38:9): [True: 4.56k, False: 582k]
  ------------------
   39|  4.56k|      return result(error_code::TOO_LARGE, pos);
   40|  4.56k|    }
   41|   582k|    if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (41:9): [True: 36.3k, False: 546k]
  |  Branch (41:27): [True: 924, False: 35.4k]
  ------------------
   42|    924|      return result(error_code::SURROGATE, pos);
   43|    924|    }
   44|   582k|  }
   45|  2.52k|  return result(error_code::SUCCESS, pos);
   46|  8.01k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_115utf32_to_latin17convertEPKDimPc:
   12|    430|                                          char *latin1_output) {
   13|    430|  char *start = latin1_output;
   14|    430|  uint32_t utf32_char;
   15|    430|  size_t pos = 0;
   16|    430|  uint32_t too_large = 0;
   17|       |
   18|  1.71M|  while (pos < len) {
  ------------------
  |  Branch (18:10): [True: 1.71M, False: 430]
  ------------------
   19|  1.71M|    utf32_char = (uint32_t)data[pos];
   20|  1.71M|    too_large |= utf32_char;
   21|  1.71M|    *latin1_output++ = (char)(utf32_char & 0xFF);
   22|  1.71M|    pos++;
   23|  1.71M|  }
   24|    430|  if ((too_large & 0xFFFFFF00) != 0) {
  ------------------
  |  Branch (24:7): [True: 362, False: 68]
  ------------------
   25|    362|    return 0;
   26|    362|  }
   27|     68|  return latin1_output - start;
   28|    430|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_115utf32_to_latin119convert_with_errorsEPKDimPc:
   32|  1.42k|                                                      char *latin1_output) {
   33|  1.42k|  char *start{latin1_output};
   34|  1.42k|  size_t pos = 0;
   35|   270k|  while (pos < len) {
  ------------------
  |  Branch (35:10): [True: 270k, False: 114]
  ------------------
   36|       |#if SIMDUTF_CPLUSPLUS23
   37|       |    if !consteval
   38|       |#endif
   39|   270k|    {
   40|   270k|      if (pos + 2 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (40:11): [True: 270k, False: 390]
  ------------------
   41|       |                            // they are Latin1
   42|   270k|        uint64_t v;
   43|   270k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   44|   270k|        if ((v & 0xFFFFFF00FFFFFF00) == 0) {
  ------------------
  |  Branch (44:13): [True: 269k, False: 1.18k]
  ------------------
   45|   269k|          *latin1_output++ = char(data[pos]);
   46|   269k|          *latin1_output++ = char(data[pos + 1]);
   47|   269k|          pos += 2;
   48|   269k|          continue;
   49|   269k|        }
   50|   270k|      }
   51|   270k|    }
   52|       |
   53|  1.57k|    uint32_t utf32_char = data[pos];
   54|  1.57k|    if ((utf32_char & 0xFFFFFF00) ==
  ------------------
  |  Branch (54:9): [True: 262, False: 1.30k]
  ------------------
   55|  1.57k|        0) { // Check if the character can be represented in Latin-1
   56|    262|      *latin1_output++ = (char)(utf32_char & 0xFF);
   57|    262|      pos++;
   58|  1.30k|    } else {
   59|  1.30k|      return result(error_code::TOO_LARGE, pos);
   60|  1.30k|    };
   61|    262|  }
   62|    114|  return result(error_code::SUCCESS, latin1_output - start);
   63|  1.42k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf32_to_utf167convertILNS_10endiannessE0EEEmPKDimPDs:
   11|  1.83k|                                   char16_t *utf16_output) {
   12|  1.83k|  size_t pos = 0;
   13|  1.83k|  char16_t *start{utf16_output};
   14|   152k|  while (pos < len) {
  ------------------
  |  Branch (14:10): [True: 151k, False: 972]
  ------------------
   15|   151k|    uint32_t word = data[pos];
   16|   151k|    if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (16:9): [True: 143k, False: 8.41k]
  ------------------
   17|   143k|      if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (17:11): [True: 1.63k, False: 141k]
  |  Branch (17:29): [True: 208, False: 1.42k]
  ------------------
   18|    208|        return 0;
   19|    208|      }
   20|       |      // will not generate a surrogate pair
   21|   142k|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (21:25): [Folded, False: 142k]
  ------------------
   22|   142k|                            ? char16_t(u16_swap_bytes(uint16_t(word)))
   23|   142k|                            : char16_t(word);
   24|   142k|    } else {
   25|       |      // will generate a surrogate pair
   26|  8.41k|      if (word > 0x10FFFF) {
  ------------------
  |  Branch (26:11): [True: 654, False: 7.75k]
  ------------------
   27|    654|        return 0;
   28|    654|      }
   29|  7.75k|      word -= 0x10000;
   30|  7.75k|      uint16_t high_surrogate = uint16_t(0xD800 + (word >> 10));
   31|  7.75k|      uint16_t low_surrogate = uint16_t(0xDC00 + (word & 0x3FF));
   32|       |      if constexpr (!match_system(big_endian)) {
   33|       |        high_surrogate = u16_swap_bytes(high_surrogate);
   34|       |        low_surrogate = u16_swap_bytes(low_surrogate);
   35|       |      }
   36|  7.75k|      *utf16_output++ = char16_t(high_surrogate);
   37|  7.75k|      *utf16_output++ = char16_t(low_surrogate);
   38|  7.75k|    }
   39|   150k|    pos++;
   40|   150k|  }
   41|    972|  return utf16_output - start;
   42|  1.83k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf32_to_utf167convertILNS_10endiannessE1EEEmPKDimPDs:
   11|  1.55k|                                   char16_t *utf16_output) {
   12|  1.55k|  size_t pos = 0;
   13|  1.55k|  char16_t *start{utf16_output};
   14|  50.4k|  while (pos < len) {
  ------------------
  |  Branch (14:10): [True: 49.7k, False: 694]
  ------------------
   15|  49.7k|    uint32_t word = data[pos];
   16|  49.7k|    if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (16:9): [True: 37.3k, False: 12.4k]
  ------------------
   17|  37.3k|      if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (17:11): [True: 1.19k, False: 36.1k]
  |  Branch (17:29): [True: 202, False: 992]
  ------------------
   18|    202|        return 0;
   19|    202|      }
   20|       |      // will not generate a surrogate pair
   21|  37.1k|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (21:25): [True: 37.1k, Folded]
  ------------------
   22|  37.1k|                            ? char16_t(u16_swap_bytes(uint16_t(word)))
   23|  37.1k|                            : char16_t(word);
   24|  37.1k|    } else {
   25|       |      // will generate a surrogate pair
   26|  12.4k|      if (word > 0x10FFFF) {
  ------------------
  |  Branch (26:11): [True: 656, False: 11.7k]
  ------------------
   27|    656|        return 0;
   28|    656|      }
   29|  11.7k|      word -= 0x10000;
   30|  11.7k|      uint16_t high_surrogate = uint16_t(0xD800 + (word >> 10));
   31|  11.7k|      uint16_t low_surrogate = uint16_t(0xDC00 + (word & 0x3FF));
   32|  11.7k|      if constexpr (!match_system(big_endian)) {
   33|  11.7k|        high_surrogate = u16_swap_bytes(high_surrogate);
   34|  11.7k|        low_surrogate = u16_swap_bytes(low_surrogate);
   35|  11.7k|      }
   36|  11.7k|      *utf16_output++ = char16_t(high_surrogate);
   37|  11.7k|      *utf16_output++ = char16_t(low_surrogate);
   38|  11.7k|    }
   39|  48.8k|    pos++;
   40|  48.8k|  }
   41|    694|  return utf16_output - start;
   42|  1.55k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf32_to_utf1619convert_with_errorsILNS_10endiannessE0EEENS_6resultEPKDimPDs:
   46|  2.28k|                                               char16_t *utf16_output) {
   47|  2.28k|  size_t pos = 0;
   48|  2.28k|  char16_t *start{utf16_output};
   49|   100k|  while (pos < len) {
  ------------------
  |  Branch (49:10): [True: 100k, False: 500]
  ------------------
   50|   100k|    uint32_t word = data[pos];
   51|   100k|    if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (51:9): [True: 91.1k, False: 9.21k]
  ------------------
   52|  91.1k|      if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (52:11): [True: 2.00k, False: 89.1k]
  |  Branch (52:29): [True: 390, False: 1.61k]
  ------------------
   53|    390|        return result(error_code::SURROGATE, pos);
   54|    390|      }
   55|       |      // will not generate a surrogate pair
   56|  90.7k|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (56:25): [Folded, False: 90.7k]
  ------------------
   57|  90.7k|                            ? char16_t(u16_swap_bytes(uint16_t(word)))
   58|  90.7k|                            : char16_t(word);
   59|  90.7k|    } else {
   60|       |      // will generate a surrogate pair
   61|  9.21k|      if (word > 0x10FFFF) {
  ------------------
  |  Branch (61:11): [True: 1.39k, False: 7.81k]
  ------------------
   62|  1.39k|        return result(error_code::TOO_LARGE, pos);
   63|  1.39k|      }
   64|  7.81k|      word -= 0x10000;
   65|  7.81k|      uint16_t high_surrogate = uint16_t(0xD800 + (word >> 10));
   66|  7.81k|      uint16_t low_surrogate = uint16_t(0xDC00 + (word & 0x3FF));
   67|       |      if constexpr (!match_system(big_endian)) {
   68|       |        high_surrogate = u16_swap_bytes(high_surrogate);
   69|       |        low_surrogate = u16_swap_bytes(low_surrogate);
   70|       |      }
   71|  7.81k|      *utf16_output++ = char16_t(high_surrogate);
   72|  7.81k|      *utf16_output++ = char16_t(low_surrogate);
   73|  7.81k|    }
   74|  98.5k|    pos++;
   75|  98.5k|  }
   76|    500|  return result(error_code::SUCCESS, utf16_output - start);
   77|  2.28k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf32_to_utf1619convert_with_errorsILNS_10endiannessE1EEENS_6resultEPKDimPDs:
   46|  2.01k|                                               char16_t *utf16_output) {
   47|  2.01k|  size_t pos = 0;
   48|  2.01k|  char16_t *start{utf16_output};
   49|   161k|  while (pos < len) {
  ------------------
  |  Branch (49:10): [True: 160k, False: 516]
  ------------------
   50|   160k|    uint32_t word = data[pos];
   51|   160k|    if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (51:9): [True: 156k, False: 4.44k]
  ------------------
   52|   156k|      if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (52:11): [True: 1.47k, False: 154k]
  |  Branch (52:29): [True: 228, False: 1.25k]
  ------------------
   53|    228|        return result(error_code::SURROGATE, pos);
   54|    228|      }
   55|       |      // will not generate a surrogate pair
   56|   156k|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (56:25): [True: 156k, Folded]
  ------------------
   57|   156k|                            ? char16_t(u16_swap_bytes(uint16_t(word)))
   58|   156k|                            : char16_t(word);
   59|   156k|    } else {
   60|       |      // will generate a surrogate pair
   61|  4.44k|      if (word > 0x10FFFF) {
  ------------------
  |  Branch (61:11): [True: 1.26k, False: 3.17k]
  ------------------
   62|  1.26k|        return result(error_code::TOO_LARGE, pos);
   63|  1.26k|      }
   64|  3.17k|      word -= 0x10000;
   65|  3.17k|      uint16_t high_surrogate = uint16_t(0xD800 + (word >> 10));
   66|  3.17k|      uint16_t low_surrogate = uint16_t(0xDC00 + (word & 0x3FF));
   67|  3.17k|      if constexpr (!match_system(big_endian)) {
   68|  3.17k|        high_surrogate = u16_swap_bytes(high_surrogate);
   69|  3.17k|        low_surrogate = u16_swap_bytes(low_surrogate);
   70|  3.17k|      }
   71|  3.17k|      *utf16_output++ = char16_t(high_surrogate);
   72|  3.17k|      *utf16_output++ = char16_t(low_surrogate);
   73|  3.17k|    }
   74|   159k|    pos++;
   75|   159k|  }
   76|    516|  return result(error_code::SUCCESS, utf16_output - start);
   77|  2.01k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf32_to_utf1613convert_validILNS_10endiannessE0EEEmPKDimPDs:
   11|    292|                                         char16_t *utf16_output) {
   12|    292|  size_t pos = 0;
   13|    292|  char16_t *start{utf16_output};
   14|  8.31k|  while (pos < len) {
  ------------------
  |  Branch (14:10): [True: 8.02k, False: 292]
  ------------------
   15|  8.02k|    uint32_t word = data[pos];
   16|  8.02k|    if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (16:9): [True: 5.15k, False: 2.86k]
  ------------------
   17|       |      // will not generate a surrogate pair
   18|  5.15k|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (18:25): [Folded, False: 5.15k]
  ------------------
   19|  5.15k|                            ? char16_t(u16_swap_bytes(uint16_t(word)))
   20|  5.15k|                            : char16_t(word);
   21|  5.15k|      pos++;
   22|  5.15k|    } else {
   23|       |      // will generate a surrogate pair
   24|  2.86k|      word -= 0x10000;
   25|  2.86k|      uint16_t high_surrogate = uint16_t(0xD800 + (word >> 10));
   26|  2.86k|      uint16_t low_surrogate = uint16_t(0xDC00 + (word & 0x3FF));
   27|       |      if constexpr (!match_system(big_endian)) {
   28|       |        high_surrogate = u16_swap_bytes(high_surrogate);
   29|       |        low_surrogate = u16_swap_bytes(low_surrogate);
   30|       |      }
   31|  2.86k|      *utf16_output++ = char16_t(high_surrogate);
   32|  2.86k|      *utf16_output++ = char16_t(low_surrogate);
   33|  2.86k|      pos++;
   34|  2.86k|    }
   35|  8.02k|  }
   36|    292|  return utf16_output - start;
   37|    292|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf32_to_utf1613convert_validILNS_10endiannessE1EEEmPKDimPDs:
   11|    136|                                         char16_t *utf16_output) {
   12|    136|  size_t pos = 0;
   13|    136|  char16_t *start{utf16_output};
   14|  19.7k|  while (pos < len) {
  ------------------
  |  Branch (14:10): [True: 19.6k, False: 136]
  ------------------
   15|  19.6k|    uint32_t word = data[pos];
   16|  19.6k|    if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (16:9): [True: 10.7k, False: 8.89k]
  ------------------
   17|       |      // will not generate a surrogate pair
   18|  10.7k|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (18:25): [True: 10.7k, Folded]
  ------------------
   19|  10.7k|                            ? char16_t(u16_swap_bytes(uint16_t(word)))
   20|  10.7k|                            : char16_t(word);
   21|  10.7k|      pos++;
   22|  10.7k|    } else {
   23|       |      // will generate a surrogate pair
   24|  8.89k|      word -= 0x10000;
   25|  8.89k|      uint16_t high_surrogate = uint16_t(0xD800 + (word >> 10));
   26|  8.89k|      uint16_t low_surrogate = uint16_t(0xDC00 + (word & 0x3FF));
   27|  8.89k|      if constexpr (!match_system(big_endian)) {
   28|  8.89k|        high_surrogate = u16_swap_bytes(high_surrogate);
   29|  8.89k|        low_surrogate = u16_swap_bytes(low_surrogate);
   30|  8.89k|      }
   31|  8.89k|      *utf16_output++ = char16_t(high_surrogate);
   32|  8.89k|      *utf16_output++ = char16_t(low_surrogate);
   33|  8.89k|      pos++;
   34|  8.89k|    }
   35|  19.6k|  }
   36|    136|  return utf16_output - start;
   37|    136|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf32_to_utf87convertIPKDiPcQaasr7simdutf6detailE18indexes_into_utf32IT_Esr7simdutf6detailE26index_assignable_from_charIT0_EEEmS7_mS8_:
   17|  1.88k|                                   OutputPtr utf8_output) {
   18|  1.88k|  size_t pos = 0;
   19|  1.88k|  auto start = utf8_output;
   20|  56.8k|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 56.0k, False: 786]
  ------------------
   21|       |#if SIMDUTF_CPLUSPLUS23
   22|       |    if !consteval
   23|       |#endif
   24|  56.0k|    { // try to convert the next block of 2 ASCII characters
   25|  56.0k|      if (pos + 2 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (25:11): [True: 55.0k, False: 1.03k]
  ------------------
   26|       |                            // they are ascii
   27|  55.0k|        uint64_t v;
   28|  55.0k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   29|  55.0k|        if ((v & 0xFFFFFF80FFFFFF80) == 0) {
  ------------------
  |  Branch (29:13): [True: 20.2k, False: 34.7k]
  ------------------
   30|  20.2k|          *utf8_output++ = char(data[pos]);
   31|  20.2k|          *utf8_output++ = char(data[pos + 1]);
   32|  20.2k|          pos += 2;
   33|  20.2k|          continue;
   34|  20.2k|        }
   35|  55.0k|      }
   36|  56.0k|    }
   37|       |
   38|  35.8k|    uint32_t word = data[pos];
   39|  35.8k|    if ((word & 0xFFFFFF80) == 0) {
  ------------------
  |  Branch (39:9): [True: 4.60k, False: 31.1k]
  ------------------
   40|       |      // will generate one UTF-8 bytes
   41|  4.60k|      *utf8_output++ = char(word);
   42|  4.60k|      pos++;
   43|  31.1k|    } else if ((word & 0xFFFFF800) == 0) {
  ------------------
  |  Branch (43:16): [True: 16.6k, False: 14.5k]
  ------------------
   44|       |      // will generate two UTF-8 bytes
   45|       |      // we have 0b110XXXXX 0b10XXXXXX
   46|  16.6k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   47|  16.6k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   48|  16.6k|      pos++;
   49|  16.6k|    } else if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (49:16): [True: 10.0k, False: 4.49k]
  ------------------
   50|       |      // will generate three UTF-8 bytes
   51|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   52|  10.0k|      if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (52:11): [True: 7.20k, False: 2.87k]
  |  Branch (52:29): [True: 206, False: 6.99k]
  ------------------
   53|    206|        return 0;
   54|    206|      }
   55|  9.87k|      *utf8_output++ = char((word >> 12) | 0b11100000);
   56|  9.87k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   57|  9.87k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   58|  9.87k|      pos++;
   59|  9.87k|    } else {
   60|       |      // will generate four UTF-8 bytes
   61|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   62|  4.49k|      if (word > 0x10FFFF) {
  ------------------
  |  Branch (62:11): [True: 894, False: 3.60k]
  ------------------
   63|    894|        return 0;
   64|    894|      }
   65|  3.60k|      *utf8_output++ = char((word >> 18) | 0b11110000);
   66|  3.60k|      *utf8_output++ = char(((word >> 12) & 0b111111) | 0b10000000);
   67|  3.60k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   68|  3.60k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   69|  3.60k|      pos++;
   70|  3.60k|    }
   71|  35.8k|  }
   72|    786|  return utf8_output - start;
   73|  1.88k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf32_to_utf819convert_with_errorsIPKDiPcQaasr7simdutf6detailE18indexes_into_utf32IT_Esr7simdutf6detailE26index_assignable_from_charIT0_EEENS_6resultES7_mS8_:
   81|  2.57k|                                               OutputPtr utf8_output) {
   82|  2.57k|  size_t pos = 0;
   83|  2.57k|  auto start = utf8_output;
   84|  31.5k|  while (pos < len) {
  ------------------
  |  Branch (84:10): [True: 30.9k, False: 610]
  ------------------
   85|       |#if SIMDUTF_CPLUSPLUS23
   86|       |    if !consteval
   87|       |#endif
   88|  30.9k|    { // try to convert the next block of 2 ASCII characters
   89|  30.9k|      if (pos + 2 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (89:11): [True: 29.9k, False: 1.04k]
  ------------------
   90|       |                            // they are ascii
   91|  29.9k|        uint64_t v;
   92|  29.9k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   93|  29.9k|        if ((v & 0xFFFFFF80FFFFFF80) == 0) {
  ------------------
  |  Branch (93:13): [True: 8.93k, False: 21.0k]
  ------------------
   94|  8.93k|          *utf8_output++ = char(data[pos]);
   95|  8.93k|          *utf8_output++ = char(data[pos + 1]);
   96|  8.93k|          pos += 2;
   97|  8.93k|          continue;
   98|  8.93k|        }
   99|  29.9k|      }
  100|  30.9k|    }
  101|       |
  102|  22.0k|    uint32_t word = data[pos];
  103|  22.0k|    if ((word & 0xFFFFFF80) == 0) {
  ------------------
  |  Branch (103:9): [True: 2.07k, False: 19.9k]
  ------------------
  104|       |      // will generate one UTF-8 bytes
  105|  2.07k|      *utf8_output++ = char(word);
  106|  2.07k|      pos++;
  107|  19.9k|    } else if ((word & 0xFFFFF800) == 0) {
  ------------------
  |  Branch (107:16): [True: 4.06k, False: 15.9k]
  ------------------
  108|       |      // will generate two UTF-8 bytes
  109|       |      // we have 0b110XXXXX 0b10XXXXXX
  110|  4.06k|      *utf8_output++ = char((word >> 6) | 0b11000000);
  111|  4.06k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  112|  4.06k|      pos++;
  113|  15.9k|    } else if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (113:16): [True: 7.91k, False: 8.00k]
  ------------------
  114|       |      // will generate three UTF-8 bytes
  115|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
  116|  7.91k|      if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (116:11): [True: 5.81k, False: 2.10k]
  |  Branch (116:29): [True: 276, False: 5.53k]
  ------------------
  117|    276|        return result(error_code::SURROGATE, pos);
  118|    276|      }
  119|  7.63k|      *utf8_output++ = char((word >> 12) | 0b11100000);
  120|  7.63k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  121|  7.63k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  122|  7.63k|      pos++;
  123|  8.00k|    } else {
  124|       |      // will generate four UTF-8 bytes
  125|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
  126|  8.00k|      if (word > 0x10FFFF) {
  ------------------
  |  Branch (126:11): [True: 1.68k, False: 6.32k]
  ------------------
  127|  1.68k|        return result(error_code::TOO_LARGE, pos);
  128|  1.68k|      }
  129|  6.32k|      *utf8_output++ = char((word >> 18) | 0b11110000);
  130|  6.32k|      *utf8_output++ = char(((word >> 12) & 0b111111) | 0b10000000);
  131|  6.32k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  132|  6.32k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
  133|  6.32k|      pos++;
  134|  6.32k|    }
  135|  22.0k|  }
  136|    610|  return result(error_code::SUCCESS, utf8_output - start);
  137|  2.57k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf32_to_utf813convert_validIPKDiPcQaasr7simdutf6detailE18indexes_into_utf32IT_Esr7simdutf6detailE26index_assignable_from_charIT0_EEEmS7_mS8_:
   17|    194|                                         OutputPtr utf8_output) {
   18|    194|  size_t pos = 0;
   19|    194|  auto start = utf8_output;
   20|  12.4k|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 12.2k, False: 194]
  ------------------
   21|       |#if SIMDUTF_CPLUSPLUS23
   22|       |    if !consteval
   23|       |#endif
   24|  12.2k|    { // try to convert the next block of 2 ASCII characters
   25|  12.2k|      if (pos + 2 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (25:11): [True: 12.1k, False: 166]
  ------------------
   26|       |                            // they are ascii
   27|  12.1k|        uint64_t v;
   28|  12.1k|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   29|  12.1k|        if ((v & 0xFFFFFF80FFFFFF80) == 0) {
  ------------------
  |  Branch (29:13): [True: 2.08k, False: 10.0k]
  ------------------
   30|  2.08k|          *utf8_output++ = char(data[pos]);
   31|  2.08k|          *utf8_output++ = char(data[pos + 1]);
   32|  2.08k|          pos += 2;
   33|  2.08k|          continue;
   34|  2.08k|        }
   35|  12.1k|      }
   36|  12.2k|    }
   37|       |
   38|  10.2k|    uint32_t word = data[pos];
   39|  10.2k|    if ((word & 0xFFFFFF80) == 0) {
  ------------------
  |  Branch (39:9): [True: 1.04k, False: 9.16k]
  ------------------
   40|       |      // will generate one UTF-8 bytes
   41|  1.04k|      *utf8_output++ = char(word);
   42|  1.04k|      pos++;
   43|  9.16k|    } else if ((word & 0xFFFFF800) == 0) {
  ------------------
  |  Branch (43:16): [True: 4.71k, False: 4.45k]
  ------------------
   44|       |      // will generate two UTF-8 bytes
   45|       |      // we have 0b110XXXXX 0b10XXXXXX
   46|  4.71k|      *utf8_output++ = char((word >> 6) | 0b11000000);
   47|  4.71k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   48|  4.71k|      pos++;
   49|  4.71k|    } else if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (49:16): [True: 1.97k, False: 2.47k]
  ------------------
   50|       |      // will generate three UTF-8 bytes
   51|       |      // we have 0b1110XXXX 0b10XXXXXX 0b10XXXXXX
   52|  1.97k|      *utf8_output++ = char((word >> 12) | 0b11100000);
   53|  1.97k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   54|  1.97k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   55|  1.97k|      pos++;
   56|  2.47k|    } else {
   57|       |      // will generate four UTF-8 bytes
   58|       |      // we have 0b11110XXX 0b10XXXXXX 0b10XXXXXX 0b10XXXXXX
   59|  2.47k|      *utf8_output++ = char((word >> 18) | 0b11110000);
   60|  2.47k|      *utf8_output++ = char(((word >> 12) & 0b111111) | 0b10000000);
   61|  2.47k|      *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
   62|  2.47k|      *utf8_output++ = char((word & 0b111111) | 0b10000000);
   63|  2.47k|      pos++;
   64|  2.47k|    }
   65|  10.2k|  }
   66|    194|  return utf8_output - start;
   67|    194|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf88validateEPKcm:
  113|  4.11k|                                                        size_t len) noexcept {
  114|  4.11k|  return validate(reinterpret_cast<const uint8_t *>(buf), len);
  115|  4.11k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf88validateIPKhEEbT_m:
   14|  4.11k|                                                      size_t len) noexcept {
   15|  4.11k|  static_assert(
   16|  4.11k|      std::is_same<typename std::decay<decltype(*data)>::type, uint8_t>::value,
   17|  4.11k|      "dereferencing the data pointer must result in a uint8_t");
   18|  4.11k|  uint64_t pos = 0;
   19|  4.11k|  uint32_t code_point = 0;
   20|  9.19M|  while (pos < len) {
  ------------------
  |  Branch (20:10): [True: 9.19M, False: 602]
  ------------------
   21|  9.19M|    uint64_t next_pos;
   22|       |#if SIMDUTF_CPLUSPLUS23
   23|       |    if !consteval
   24|       |#endif
   25|  9.19M|    { // check if the next 16 bytes are ascii.
   26|  9.19M|      next_pos = pos + 16;
   27|  9.19M|      if (next_pos <= len) { // if it is safe to read 16 more bytes, check
  ------------------
  |  Branch (27:11): [True: 9.19M, False: 3.38k]
  ------------------
   28|       |                             // that they are ascii
   29|  9.19M|        uint64_t v1{};
   30|  9.19M|        std::memcpy(&v1, data + pos, sizeof(uint64_t));
   31|  9.19M|        uint64_t v2{};
   32|  9.19M|        std::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   33|  9.19M|        uint64_t v{v1 | v2};
   34|  9.19M|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (34:13): [True: 7.99M, False: 1.19M]
  ------------------
   35|  7.99M|          pos = next_pos;
   36|  7.99M|          continue;
   37|  7.99M|        }
   38|  9.19M|      }
   39|  9.19M|    }
   40|       |
   41|  1.19M|    unsigned char byte = data[pos];
   42|       |
   43|  5.95M|    while (byte < 0b10000000) {
  ------------------
  |  Branch (43:12): [True: 4.75M, False: 1.19M]
  ------------------
   44|  4.75M|      if (++pos == len) {
  ------------------
  |  Branch (44:11): [True: 1.11k, False: 4.75M]
  ------------------
   45|  1.11k|        return true;
   46|  1.11k|      }
   47|  4.75M|      byte = data[pos];
   48|  4.75M|    }
   49|       |
   50|  1.19M|    if ((byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (50:9): [True: 716k, False: 482k]
  ------------------
   51|   716k|      next_pos = pos + 2;
   52|   716k|      if (next_pos > len) {
  ------------------
  |  Branch (52:11): [True: 85, False: 715k]
  ------------------
   53|     85|        return false;
   54|     85|      }
   55|   715k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (55:11): [True: 341, False: 715k]
  ------------------
   56|    341|        return false;
   57|    341|      }
   58|       |      // range check
   59|   715k|      code_point = (byte & 0b00011111) << 6 | (data[pos + 1] & 0b00111111);
   60|   715k|      if (code_point < 0x80) {
  ------------------
  |  Branch (60:11): [True: 36, False: 715k]
  ------------------
   61|     36|        return false;
   62|     36|      }
   63|   715k|    } else if ((byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (63:16): [True: 421k, False: 60.9k]
  ------------------
   64|   421k|      next_pos = pos + 3;
   65|   421k|      if (next_pos > len) {
  ------------------
  |  Branch (65:11): [True: 40, False: 421k]
  ------------------
   66|     40|        return false;
   67|     40|      }
   68|   421k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (68:11): [True: 181, False: 421k]
  ------------------
   69|    181|        return false;
   70|    181|      }
   71|   421k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (71:11): [True: 74, False: 420k]
  ------------------
   72|     74|        return false;
   73|     74|      }
   74|       |      // range check
   75|   420k|      code_point = (byte & 0b00001111) << 12 |
   76|   420k|                   (data[pos + 1] & 0b00111111) << 6 |
   77|   420k|                   (data[pos + 2] & 0b00111111);
   78|   420k|      if ((code_point < 0x800) ||
  ------------------
  |  Branch (78:11): [True: 46, False: 420k]
  ------------------
   79|   420k|          (0xd7ff < code_point && code_point < 0xe000)) {
  ------------------
  |  Branch (79:12): [True: 87.9k, False: 332k]
  |  Branch (79:35): [True: 25, False: 87.8k]
  ------------------
   80|     71|        return false;
   81|     71|      }
   82|   420k|    } else if ((byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (82:16): [True: 59.7k, False: 1.18k]
  ------------------
   83|  59.7k|      next_pos = pos + 4;
   84|  59.7k|      if (next_pos > len) {
  ------------------
  |  Branch (84:11): [True: 46, False: 59.7k]
  ------------------
   85|     46|        return false;
   86|     46|      }
   87|  59.7k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (87:11): [True: 153, False: 59.5k]
  ------------------
   88|    153|        return false;
   89|    153|      }
   90|  59.5k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (90:11): [True: 51, False: 59.5k]
  ------------------
   91|     51|        return false;
   92|     51|      }
   93|  59.5k|      if ((data[pos + 3] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (93:11): [True: 43, False: 59.4k]
  ------------------
   94|     43|        return false;
   95|     43|      }
   96|       |      // range check
   97|  59.4k|      code_point =
   98|  59.4k|          (byte & 0b00000111) << 18 | (data[pos + 1] & 0b00111111) << 12 |
   99|  59.4k|          (data[pos + 2] & 0b00111111) << 6 | (data[pos + 3] & 0b00111111);
  100|  59.4k|      if (code_point <= 0xffff || 0x10ffff < code_point) {
  ------------------
  |  Branch (100:11): [True: 43, False: 59.4k]
  |  Branch (100:35): [True: 51, False: 59.3k]
  ------------------
  101|     94|        return false;
  102|     94|      }
  103|  59.4k|    } else {
  104|       |      // we may have a continuation
  105|  1.18k|      return false;
  106|  1.18k|    }
  107|  1.19M|    pos = next_pos;
  108|  1.19M|  }
  109|    602|  return true;
  110|  4.11k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf820validate_with_errorsEPKcm:
  221|  8.64k|validate_with_errors(const char *buf, size_t len) noexcept {
  222|  8.64k|  return validate_with_errors(reinterpret_cast<const uint8_t *>(buf), len);
  223|  8.64k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf820validate_with_errorsIPKhEENS_6resultET_m:
  119|  8.64k|validate_with_errors(BytePtr data, size_t len) noexcept {
  120|  8.64k|  static_assert(
  121|  8.64k|      std::is_same<typename std::decay<decltype(*data)>::type, uint8_t>::value,
  122|  8.64k|      "dereferencing the data pointer must result in a uint8_t");
  123|  8.64k|  size_t pos = 0;
  124|  8.64k|  uint32_t code_point = 0;
  125|  9.20M|  while (pos < len) {
  ------------------
  |  Branch (125:10): [True: 9.20M, False: 602]
  ------------------
  126|       |    // check of the next 16 bytes are ascii.
  127|  9.20M|    size_t next_pos = pos + 16;
  128|  9.20M|    if (next_pos <=
  ------------------
  |  Branch (128:9): [True: 9.20M, False: 5.36k]
  ------------------
  129|  9.20M|        len) { // if it is safe to read 16 more bytes, check that they are ascii
  130|  9.20M|      uint64_t v1;
  131|  9.20M|      std::memcpy(&v1, data + pos, sizeof(uint64_t));
  132|  9.20M|      uint64_t v2;
  133|  9.20M|      std::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
  134|  9.20M|      uint64_t v{v1 | v2};
  135|  9.20M|      if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (135:11): [True: 7.99M, False: 1.20M]
  ------------------
  136|  7.99M|        pos = next_pos;
  137|  7.99M|        continue;
  138|  7.99M|      }
  139|  9.20M|    }
  140|  1.20M|    unsigned char byte = data[pos];
  141|       |
  142|  5.98M|    while (byte < 0b10000000) {
  ------------------
  |  Branch (142:12): [True: 4.78M, False: 1.20M]
  ------------------
  143|  4.78M|      if (++pos == len) {
  ------------------
  |  Branch (143:11): [True: 1.11k, False: 4.77M]
  ------------------
  144|  1.11k|        return result(error_code::SUCCESS, len);
  145|  1.11k|      }
  146|  4.77M|      byte = data[pos];
  147|  4.77M|    }
  148|       |
  149|  1.20M|    if ((byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (149:9): [True: 719k, False: 487k]
  ------------------
  150|   719k|      next_pos = pos + 2;
  151|   719k|      if (next_pos > len) {
  ------------------
  |  Branch (151:11): [True: 255, False: 719k]
  ------------------
  152|    255|        return result(error_code::TOO_SHORT, pos);
  153|    255|      }
  154|   719k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (154:11): [True: 1.02k, False: 718k]
  ------------------
  155|  1.02k|        return result(error_code::TOO_SHORT, pos);
  156|  1.02k|      }
  157|       |      // range check
  158|   718k|      code_point = (byte & 0b00011111) << 6 | (data[pos + 1] & 0b00111111);
  159|   718k|      if (code_point < 0x80) {
  ------------------
  |  Branch (159:11): [True: 108, False: 718k]
  ------------------
  160|    108|        return result(error_code::OVERLONG, pos);
  161|    108|      }
  162|   718k|    } else if ((byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (162:16): [True: 423k, False: 64.2k]
  ------------------
  163|   423k|      next_pos = pos + 3;
  164|   423k|      if (next_pos > len) {
  ------------------
  |  Branch (164:11): [True: 120, False: 423k]
  ------------------
  165|    120|        return result(error_code::TOO_SHORT, pos);
  166|    120|      }
  167|   423k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (167:11): [True: 543, False: 422k]
  ------------------
  168|    543|        return result(error_code::TOO_SHORT, pos);
  169|    543|      }
  170|   422k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (170:11): [True: 222, False: 422k]
  ------------------
  171|    222|        return result(error_code::TOO_SHORT, pos);
  172|    222|      }
  173|       |      // range check
  174|   422k|      code_point = (byte & 0b00001111) << 12 |
  175|   422k|                   (data[pos + 1] & 0b00111111) << 6 |
  176|   422k|                   (data[pos + 2] & 0b00111111);
  177|   422k|      if (code_point < 0x800) {
  ------------------
  |  Branch (177:11): [True: 138, False: 422k]
  ------------------
  178|    138|        return result(error_code::OVERLONG, pos);
  179|    138|      }
  180|   422k|      if (0xd7ff < code_point && code_point < 0xe000) {
  ------------------
  |  Branch (180:11): [True: 88.9k, False: 333k]
  |  Branch (180:34): [True: 75, False: 88.8k]
  ------------------
  181|     75|        return result(error_code::SURROGATE, pos);
  182|     75|      }
  183|   422k|    } else if ((byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (183:16): [True: 61.0k, False: 3.28k]
  ------------------
  184|  61.0k|      next_pos = pos + 4;
  185|  61.0k|      if (next_pos > len) {
  ------------------
  |  Branch (185:11): [True: 138, False: 60.8k]
  ------------------
  186|    138|        return result(error_code::TOO_SHORT, pos);
  187|    138|      }
  188|  60.8k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (188:11): [True: 459, False: 60.4k]
  ------------------
  189|    459|        return result(error_code::TOO_SHORT, pos);
  190|    459|      }
  191|  60.4k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (191:11): [True: 153, False: 60.2k]
  ------------------
  192|    153|        return result(error_code::TOO_SHORT, pos);
  193|    153|      }
  194|  60.2k|      if ((data[pos + 3] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (194:11): [True: 129, False: 60.1k]
  ------------------
  195|    129|        return result(error_code::TOO_SHORT, pos);
  196|    129|      }
  197|       |      // range check
  198|  60.1k|      code_point =
  199|  60.1k|          (byte & 0b00000111) << 18 | (data[pos + 1] & 0b00111111) << 12 |
  200|  60.1k|          (data[pos + 2] & 0b00111111) << 6 | (data[pos + 3] & 0b00111111);
  201|  60.1k|      if (code_point <= 0xffff) {
  ------------------
  |  Branch (201:11): [True: 129, False: 59.9k]
  ------------------
  202|    129|        return result(error_code::OVERLONG, pos);
  203|    129|      }
  204|  59.9k|      if (0x10ffff < code_point) {
  ------------------
  |  Branch (204:11): [True: 153, False: 59.8k]
  ------------------
  205|    153|        return result(error_code::TOO_LARGE, pos);
  206|    153|      }
  207|  59.9k|    } else {
  208|       |      // we either have too many continuation bytes or an invalid leading byte
  209|  3.28k|      if ((byte & 0b11000000) == 0b10000000) {
  ------------------
  |  Branch (209:11): [True: 1.72k, False: 1.56k]
  ------------------
  210|  1.72k|        return result(error_code::TOO_LONG, pos);
  211|  1.72k|      } else {
  212|  1.56k|        return result(error_code::HEADER_BITS, pos);
  213|  1.56k|      }
  214|  3.28k|    }
  215|  1.20M|    pos = next_pos;
  216|  1.20M|  }
  217|    602|  return result(error_code::SUCCESS, len);
  218|  8.64k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf831rewind_and_validate_with_errorsEPKcS4_m:
  232|  4.80k|    const char *start, const char *buf, size_t len) noexcept {
  233|       |  // First check that we start with a leading byte
  234|  4.80k|  if ((*start & 0b11000000) == 0b10000000) {
  ------------------
  |  Branch (234:7): [True: 272, False: 4.53k]
  ------------------
  235|    272|    return result(error_code::TOO_LONG, 0);
  236|    272|  }
  237|  4.53k|  size_t extra_len{0};
  238|       |  // A leading byte cannot be further than 4 bytes away
  239|  4.75k|  for (int i = 0; i < 5; i++) {
  ------------------
  |  Branch (239:19): [True: 4.75k, False: 0]
  ------------------
  240|  4.75k|    unsigned char byte = *buf;
  241|  4.75k|    if ((byte & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (241:9): [True: 4.53k, False: 228]
  ------------------
  242|  4.53k|      break;
  243|  4.53k|    } else {
  244|    228|      buf--;
  245|    228|      extra_len++;
  246|    228|    }
  247|  4.75k|  }
  248|       |
  249|  4.53k|  result res = validate_with_errors(buf, len + extra_len);
  250|  4.53k|  res.count -= extra_len; // Might underflow
  251|  4.53k|  return res;
  252|  4.80k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf817count_code_pointsIPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_m:
  454|  18.0k|simdutf_constexpr23 size_t count_code_points(InputPtr data, size_t len) {
  455|  18.0k|  size_t counter{0};
  456|   292M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (456:22): [True: 292M, False: 18.0k]
  ------------------
  457|       |    // -65 is 0b10111111, anything larger in two-complement's should start a new
  458|       |    // code point.
  459|   292M|    if (int8_t(data[i]) > -65) {
  ------------------
  |  Branch (459:9): [True: 289M, False: 3.78M]
  ------------------
  460|   289M|      counter++;
  461|   289M|    }
  462|   292M|  }
  463|  18.0k|  return counter;
  464|  18.0k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_14utf822utf16_length_from_utf8IPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_m:
  470|  6.67k|simdutf_constexpr23 size_t utf16_length_from_utf8(InputPtr data, size_t len) {
  471|  6.67k|  size_t counter{0};
  472|   101M|  for (size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (472:22): [True: 101M, False: 6.67k]
  ------------------
  473|   101M|    if (int8_t(data[i]) > -65) {
  ------------------
  |  Branch (473:9): [True: 99.9M, False: 1.65M]
  ------------------
  474|  99.9M|      counter++;
  475|  99.9M|    }
  476|   101M|    if (uint8_t(data[i]) >= 240) {
  ------------------
  |  Branch (476:9): [True: 130k, False: 101M]
  ------------------
  477|   130k|      counter++;
  478|   130k|    }
  479|   101M|  }
  480|  6.67k|  return counter;
  481|  6.67k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf8_to_latin130rewind_and_convert_with_errorsEmPKcmPc:
  176|    848|                                             char *latin1_output) {
  177|    848|  size_t extra_len{0};
  178|       |  // We potentially need to go back in time and find a leading byte.
  179|       |  // In theory '3' would be sufficient, but sometimes the error can go back
  180|       |  // quite far.
  181|    848|  size_t how_far_back = prior_bytes;
  182|       |  // size_t how_far_back = 3; // 3 bytes in the past + current position
  183|       |  // if(how_far_back >= prior_bytes) { how_far_back = prior_bytes; }
  184|    848|  bool found_leading_bytes{false};
  185|       |  // important: it is i <= how_far_back and not 'i < how_far_back'.
  186|    912|  for (size_t i = 0; i <= how_far_back; i++) {
  ------------------
  |  Branch (186:22): [True: 868, False: 44]
  ------------------
  187|    868|    unsigned char byte = buf[-static_cast<std::ptrdiff_t>(i)];
  188|    868|    found_leading_bytes = ((byte & 0b11000000) != 0b10000000);
  189|    868|    if (found_leading_bytes) {
  ------------------
  |  Branch (189:9): [True: 804, False: 64]
  ------------------
  190|    804|      if (i > 0 && byte < 128) {
  ------------------
  |  Branch (190:11): [True: 20, False: 784]
  |  Branch (190:20): [True: 20, False: 0]
  ------------------
  191|       |        // If we had to go back and the leading byte is ascii
  192|       |        // then we can stop right away.
  193|     20|        return result(error_code::TOO_LONG, 0 - i + 1);
  194|     20|      }
  195|    784|      buf -= i;
  196|    784|      extra_len = i;
  197|    784|      break;
  198|    804|    }
  199|    868|  }
  200|       |  //
  201|       |  // It is possible for this function to return a negative count in its result.
  202|       |  // C++ Standard Section 18.1 defines size_t is in <cstddef> which is described
  203|       |  // in C Standard as <stddef.h>. C Standard Section 4.1.5 defines size_t as an
  204|       |  // unsigned integral type of the result of the sizeof operator
  205|       |  //
  206|       |  // An unsigned type will simply wrap round arithmetically (well defined).
  207|       |  //
  208|    828|  if (!found_leading_bytes) {
  ------------------
  |  Branch (208:7): [True: 44, False: 784]
  ------------------
  209|       |    // If how_far_back == 3, we may have four consecutive continuation bytes!!!
  210|       |    // [....] [continuation] [continuation] [continuation] | [buf is
  211|       |    // continuation] Or we possibly have a stream that does not start with a
  212|       |    // leading byte.
  213|     44|    return result(error_code::TOO_LONG, 0 - how_far_back);
  214|     44|  }
  215|    784|  result res = convert_with_errors(buf, len + extra_len, latin1_output);
  216|    784|  if (res.error) {
  ------------------
  |  Branch (216:7): [True: 576, False: 208]
  ------------------
  217|    576|    res.count -= extra_len;
  218|    576|  }
  219|    784|  return res;
  220|    828|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf8_to_latin119convert_with_errorsIPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEENS_6resultES6_mPc:
   92|  1.79k|                                               char *latin_output) {
   93|  1.79k|  size_t pos = 0;
   94|  1.79k|  char *start{latin_output};
   95|       |
   96|  1.92M|  while (pos < len) {
  ------------------
  |  Branch (96:10): [True: 1.92M, False: 568]
  ------------------
   97|       |#if SIMDUTF_CPLUSPLUS23
   98|       |    if !consteval
   99|       |#endif
  100|  1.92M|    {
  101|       |      // try to convert the next block of 16 ASCII bytes
  102|  1.92M|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (102:11): [True: 1.91M, False: 6.37k]
  ------------------
  103|       |                             // they are ascii
  104|  1.91M|        uint64_t v1;
  105|  1.91M|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
  106|  1.91M|        uint64_t v2;
  107|  1.91M|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
  108|  1.91M|        uint64_t v{v1 | v2}; // We are only interested in these bits: 1000 1000
  109|       |                             // 1000 1000...etc
  110|  1.91M|        if ((v & 0x8080808080808080) ==
  ------------------
  |  Branch (110:13): [True: 1.65M, False: 263k]
  ------------------
  111|  1.91M|            0) { // if NONE of these are set, e.g. all of them are zero, then
  112|       |                 // everything is ASCII
  113|  1.65M|          size_t final_pos = pos + 16;
  114|  28.1M|          while (pos < final_pos) {
  ------------------
  |  Branch (114:18): [True: 26.4M, False: 1.65M]
  ------------------
  115|  26.4M|            *latin_output++ = char(data[pos]);
  116|  26.4M|            pos++;
  117|  26.4M|          }
  118|  1.65M|          continue;
  119|  1.65M|        }
  120|  1.91M|      }
  121|  1.92M|    }
  122|       |    // suppose it is not an all ASCII byte sequence
  123|   270k|    uint8_t leading_byte = data[pos]; // leading byte
  124|   270k|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (124:9): [True: 235k, False: 34.8k]
  ------------------
  125|       |      // converting one ASCII byte !!!
  126|   235k|      *latin_output++ = char(leading_byte);
  127|   235k|      pos++;
  128|   235k|    } else if ((leading_byte & 0b11100000) ==
  ------------------
  |  Branch (128:16): [True: 34.0k, False: 788]
  ------------------
  129|  34.8k|               0b11000000) { // the first three bits indicate:
  130|       |      // We have a two-byte UTF-8
  131|  34.0k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (131:11): [True: 78, False: 33.9k]
  ------------------
  132|     78|        return result(error_code::TOO_SHORT, pos);
  133|     78|      } // minimal bound checking
  134|  33.9k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (134:11): [True: 276, False: 33.6k]
  ------------------
  135|    276|        return result(error_code::TOO_SHORT, pos);
  136|    276|      } // checks if the next byte is a valid continuation byte in UTF-8. A
  137|       |        // valid continuation byte starts with 10.
  138|       |      // range check -
  139|  33.6k|      uint32_t code_point =
  140|  33.6k|          (leading_byte & 0b00011111) << 6 |
  141|  33.6k|          (data[pos + 1] &
  142|  33.6k|           0b00111111); // assembles the Unicode code point from the two bytes.
  143|       |                        // It does this by discarding the leading 110 and 10
  144|       |                        // bits from the two bytes, shifting the remaining bits
  145|       |                        // of the first byte, and then combining the results
  146|       |                        // with a bitwise OR operation.
  147|  33.6k|      if (code_point < 0x80) {
  ------------------
  |  Branch (147:11): [True: 12, False: 33.6k]
  ------------------
  148|     12|        return result(error_code::OVERLONG, pos);
  149|     12|      }
  150|  33.6k|      if (0xFF < code_point) {
  ------------------
  |  Branch (150:11): [True: 72, False: 33.6k]
  ------------------
  151|     72|        return result(error_code::TOO_LARGE, pos);
  152|     72|      } // We only care about the range 129-255 which is Non-ASCII latin1
  153|       |        // characters
  154|  33.6k|      *latin_output++ = char(code_point);
  155|  33.6k|      pos += 2;
  156|  33.6k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (156:16): [True: 120, False: 668]
  ------------------
  157|       |      // We have a three-byte UTF-8
  158|    120|      return result(error_code::TOO_LARGE, pos);
  159|    668|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (159:16): [True: 66, False: 602]
  ------------------
  160|       |      // we have a 4-byte UTF-8 word.
  161|     66|      return result(error_code::TOO_LARGE, pos);
  162|    602|    } else {
  163|       |      // we either have too many continuation bytes or an invalid leading byte
  164|    602|      if ((leading_byte & 0b11000000) == 0b10000000) {
  ------------------
  |  Branch (164:11): [True: 308, False: 294]
  ------------------
  165|    308|        return result(error_code::TOO_LONG, pos);
  166|    308|      }
  167|       |
  168|    294|      return result(error_code::HEADER_BITS, pos);
  169|    602|    }
  170|   270k|  }
  171|    568|  return result(error_code::SUCCESS, latin_output - start);
  172|  1.79k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_114utf8_to_latin17convertIPKcPcQaasr7simdutf6detailE22indexes_into_byte_likeIT_Esr7simdutf6detailE22indexes_into_byte_likeIT0_EEEmS7_mS8_:
   17|  1.46k|                                   OutputPtr latin_output) {
   18|  1.46k|  size_t pos = 0;
   19|  1.46k|  auto start = latin_output;
   20|       |
   21|  1.36M|  while (pos < len) {
  ------------------
  |  Branch (21:10): [True: 1.36M, False: 402]
  ------------------
   22|       |#if SIMDUTF_CPLUSPLUS23
   23|       |    if !consteval
   24|       |#endif
   25|  1.36M|    {
   26|       |      // try to convert the next block of 16 ASCII bytes
   27|  1.36M|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (27:11): [True: 1.36M, False: 3.68k]
  ------------------
   28|       |                             // they are ascii
   29|  1.36M|        uint64_t v1;
   30|  1.36M|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   31|  1.36M|        uint64_t v2;
   32|  1.36M|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   33|  1.36M|        uint64_t v{v1 | v2}; // We are only interested in these bits: 1000 1000
   34|       |                             // 1000 1000 .... etc
   35|  1.36M|        if ((v & 0x8080808080808080) ==
  ------------------
  |  Branch (35:13): [True: 1.26M, False: 102k]
  ------------------
   36|  1.36M|            0) { // if NONE of these are set, e.g. all of them are zero, then
   37|       |                 // everything is ASCII
   38|  1.26M|          size_t final_pos = pos + 16;
   39|  21.4M|          while (pos < final_pos) {
  ------------------
  |  Branch (39:18): [True: 20.1M, False: 1.26M]
  ------------------
   40|  20.1M|            *latin_output++ = char(data[pos]);
   41|  20.1M|            pos++;
   42|  20.1M|          }
   43|  1.26M|          continue;
   44|  1.26M|        }
   45|  1.36M|      }
   46|  1.36M|    }
   47|       |
   48|       |    // suppose it is not an all ASCII byte sequence
   49|   106k|    uint8_t leading_byte = data[pos]; // leading byte
   50|   106k|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (50:9): [True: 92.7k, False: 13.3k]
  ------------------
   51|       |      // converting one ASCII byte !!!
   52|  92.7k|      *latin_output++ = char(leading_byte);
   53|  92.7k|      pos++;
   54|  92.7k|    } else if ((leading_byte & 0b11100000) ==
  ------------------
  |  Branch (54:16): [True: 12.6k, False: 692]
  ------------------
   55|  13.3k|               0b11000000) { // the first three bits indicate:
   56|       |      // We have a two-byte UTF-8
   57|  12.6k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (57:11): [True: 66, False: 12.6k]
  ------------------
   58|     66|        return 0;
   59|     66|      } // minimal bound checking
   60|  12.6k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (60:11): [True: 184, False: 12.4k]
  ------------------
   61|    184|        return 0;
   62|    184|      } // 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|  12.4k|      uint32_t code_point =
   66|  12.4k|          (leading_byte & 0b00011111) << 6 |
   67|  12.4k|          (data[pos + 1] &
   68|  12.4k|           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|  12.4k|      if (code_point < 0x80 || 0xFF < code_point) {
  ------------------
  |  Branch (73:11): [True: 26, False: 12.4k]
  |  Branch (73:32): [True: 90, False: 12.3k]
  ------------------
   74|    116|        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|    116|      }
   78|  12.3k|      *latin_output++ = char(code_point);
   79|  12.3k|      pos += 2;
   80|  12.3k|    } else {
   81|    692|      return 0;
   82|    692|    }
   83|   106k|  }
   84|    402|  return latin_output - start;
   85|  1.46k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf167convertILNS_10endiannessE0EPKcQsr7simdutf6detailE22indexes_into_byte_likeIT0_EEEmS7_mPDs:
   16|  2.04k|                                   char16_t *utf16_output) {
   17|  2.04k|  size_t pos = 0;
   18|  2.04k|  char16_t *start{utf16_output};
   19|  2.85M|  while (pos < len) {
  ------------------
  |  Branch (19:10): [True: 2.85M, False: 622]
  ------------------
   20|       |#if SIMDUTF_CPLUSPLUS23
   21|       |    if !consteval
   22|       |#endif
   23|       |    // try to convert the next block of 16 ASCII bytes
   24|  2.85M|    {
   25|  2.85M|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (25:11): [True: 2.85M, False: 4.29k]
  ------------------
   26|       |                             // they are ascii
   27|  2.85M|        uint64_t v1;
   28|  2.85M|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   29|  2.85M|        uint64_t v2;
   30|  2.85M|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   31|  2.85M|        uint64_t v{v1 | v2};
   32|  2.85M|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (32:13): [True: 1.42M, False: 1.43M]
  ------------------
   33|  1.42M|          size_t final_pos = pos + 16;
   34|  24.1M|          while (pos < final_pos) {
  ------------------
  |  Branch (34:18): [True: 22.7M, False: 1.42M]
  ------------------
   35|  22.7M|            *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (35:31): [Folded, False: 22.7M]
  ------------------
   36|  22.7M|                                  ? char16_t(u16_swap_bytes(data[pos]))
   37|  22.7M|                                  : char16_t(data[pos]);
   38|  22.7M|            pos++;
   39|  22.7M|          }
   40|  1.42M|          continue;
   41|  1.42M|        }
   42|  2.85M|      }
   43|  2.85M|    }
   44|       |
   45|  1.43M|    uint8_t leading_byte = data[pos]; // leading byte
   46|  1.43M|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (46:9): [True: 1.18M, False: 252k]
  ------------------
   47|       |      // converting one ASCII byte !!!
   48|  1.18M|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (48:25): [Folded, False: 1.18M]
  ------------------
   49|  1.18M|                            ? char16_t(u16_swap_bytes(leading_byte))
   50|  1.18M|                            : char16_t(leading_byte);
   51|  1.18M|      pos++;
   52|  1.18M|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (52:16): [True: 146k, False: 105k]
  ------------------
   53|       |      // We have a two-byte UTF-8, it should become
   54|       |      // a single UTF-16 word.
   55|   146k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (55:11): [True: 24, False: 146k]
  ------------------
   56|     24|        return 0;
   57|     24|      } // minimal bound checking
   58|   146k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (58:11): [True: 174, False: 146k]
  ------------------
   59|    174|        return 0;
   60|    174|      }
   61|       |      // range check
   62|   146k|      uint32_t code_point =
   63|   146k|          (leading_byte & 0b00011111) << 6 | (data[pos + 1] & 0b00111111);
   64|   146k|      if (code_point < 0x80) {
  ------------------
  |  Branch (64:11): [True: 28, False: 146k]
  ------------------
   65|     28|        return 0;
   66|     28|      }
   67|       |      if constexpr (!match_system(big_endian)) {
   68|       |        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
   69|       |      }
   70|   146k|      *utf16_output++ = char16_t(code_point);
   71|   146k|      pos += 2;
   72|   146k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (72:16): [True: 95.0k, False: 10.9k]
  ------------------
   73|       |      // We have a three-byte UTF-8, it should become
   74|       |      // a single UTF-16 word.
   75|  95.0k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (75:11): [True: 30, False: 94.9k]
  ------------------
   76|     30|        return 0;
   77|     30|      } // minimal bound checking
   78|       |
   79|  94.9k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (79:11): [True: 84, False: 94.8k]
  ------------------
   80|     84|        return 0;
   81|     84|      }
   82|  94.8k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (82:11): [True: 52, False: 94.8k]
  ------------------
   83|     52|        return 0;
   84|     52|      }
   85|       |      // range check
   86|  94.8k|      uint32_t code_point = (leading_byte & 0b00001111) << 12 |
   87|  94.8k|                            (data[pos + 1] & 0b00111111) << 6 |
   88|  94.8k|                            (data[pos + 2] & 0b00111111);
   89|  94.8k|      if (code_point < 0x800 || (0xd7ff < code_point && code_point < 0xe000)) {
  ------------------
  |  Branch (89:11): [True: 62, False: 94.7k]
  |  Branch (89:34): [True: 1.43k, False: 93.3k]
  |  Branch (89:57): [True: 26, False: 1.40k]
  ------------------
   90|     88|        return 0;
   91|     88|      }
   92|       |      if constexpr (!match_system(big_endian)) {
   93|       |        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
   94|       |      }
   95|  94.7k|      *utf16_output++ = char16_t(code_point);
   96|  94.7k|      pos += 3;
   97|  94.7k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (97:16): [True: 10.3k, False: 684]
  ------------------
   98|       |      // we have a 4-byte UTF-8 word.
   99|  10.3k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (99:11): [True: 30, False: 10.2k]
  ------------------
  100|     30|        return 0;
  101|     30|      } // minimal bound checking
  102|  10.2k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (102:11): [True: 66, False: 10.2k]
  ------------------
  103|     66|        return 0;
  104|     66|      }
  105|  10.2k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (105:11): [True: 42, False: 10.1k]
  ------------------
  106|     42|        return 0;
  107|     42|      }
  108|  10.1k|      if ((data[pos + 3] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (108:11): [True: 48, False: 10.1k]
  ------------------
  109|     48|        return 0;
  110|     48|      }
  111|       |
  112|       |      // range check
  113|  10.1k|      uint32_t code_point = (leading_byte & 0b00000111) << 18 |
  114|  10.1k|                            (data[pos + 1] & 0b00111111) << 12 |
  115|  10.1k|                            (data[pos + 2] & 0b00111111) << 6 |
  116|  10.1k|                            (data[pos + 3] & 0b00111111);
  117|  10.1k|      if (code_point <= 0xffff || 0x10ffff < code_point) {
  ------------------
  |  Branch (117:11): [True: 22, False: 10.0k]
  |  Branch (117:35): [True: 48, False: 10.0k]
  ------------------
  118|     70|        return 0;
  119|     70|      }
  120|  10.0k|      code_point -= 0x10000;
  121|       |      // The mask is a no-op (code_point < 0x100000). It stops clang 18's SLP
  122|       |      // vectorizer on RISC-V V from narrowing code_point to 16 bits before
  123|       |      // the shift, which drops bits 16-19 of the code point.
  124|  10.0k|      uint16_t high_surrogate = uint16_t(0xD800 + ((code_point >> 10) & 0x3FF));
  125|  10.0k|      uint16_t low_surrogate = uint16_t(0xDC00 + (code_point & 0x3FF));
  126|       |      if constexpr (!match_system(big_endian)) {
  127|       |        high_surrogate = u16_swap_bytes(high_surrogate);
  128|       |        low_surrogate = u16_swap_bytes(low_surrogate);
  129|       |      }
  130|  10.0k|      *utf16_output++ = char16_t(high_surrogate);
  131|  10.0k|      *utf16_output++ = char16_t(low_surrogate);
  132|  10.0k|      pos += 4;
  133|  10.0k|    } else {
  134|    684|      return 0;
  135|    684|    }
  136|  1.43M|  }
  137|    622|  return utf16_output - start;
  138|  2.04k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf167convertILNS_10endiannessE1EPKcQsr7simdutf6detailE22indexes_into_byte_likeIT0_EEEmS7_mPDs:
   16|  2.04k|                                   char16_t *utf16_output) {
   17|  2.04k|  size_t pos = 0;
   18|  2.04k|  char16_t *start{utf16_output};
   19|  1.63M|  while (pos < len) {
  ------------------
  |  Branch (19:10): [True: 1.62M, False: 594]
  ------------------
   20|       |#if SIMDUTF_CPLUSPLUS23
   21|       |    if !consteval
   22|       |#endif
   23|       |    // try to convert the next block of 16 ASCII bytes
   24|  1.62M|    {
   25|  1.62M|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (25:11): [True: 1.62M, False: 4.32k]
  ------------------
   26|       |                             // they are ascii
   27|  1.62M|        uint64_t v1;
   28|  1.62M|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   29|  1.62M|        uint64_t v2;
   30|  1.62M|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   31|  1.62M|        uint64_t v{v1 | v2};
   32|  1.62M|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (32:13): [True: 985k, False: 639k]
  ------------------
   33|   985k|          size_t final_pos = pos + 16;
   34|  16.7M|          while (pos < final_pos) {
  ------------------
  |  Branch (34:18): [True: 15.7M, False: 985k]
  ------------------
   35|  15.7M|            *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (35:31): [True: 15.7M, Folded]
  ------------------
   36|  15.7M|                                  ? char16_t(u16_swap_bytes(data[pos]))
   37|  15.7M|                                  : char16_t(data[pos]);
   38|  15.7M|            pos++;
   39|  15.7M|          }
   40|   985k|          continue;
   41|   985k|        }
   42|  1.62M|      }
   43|  1.62M|    }
   44|       |
   45|   644k|    uint8_t leading_byte = data[pos]; // leading byte
   46|   644k|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (46:9): [True: 531k, False: 112k]
  ------------------
   47|       |      // converting one ASCII byte !!!
   48|   531k|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (48:25): [True: 531k, Folded]
  ------------------
   49|   531k|                            ? char16_t(u16_swap_bytes(leading_byte))
   50|   531k|                            : char16_t(leading_byte);
   51|   531k|      pos++;
   52|   531k|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (52:16): [True: 66.4k, False: 46.1k]
  ------------------
   53|       |      // We have a two-byte UTF-8, it should become
   54|       |      // a single UTF-16 word.
   55|  66.4k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (55:11): [True: 60, False: 66.4k]
  ------------------
   56|     60|        return 0;
   57|     60|      } // minimal bound checking
   58|  66.4k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (58:11): [True: 116, False: 66.3k]
  ------------------
   59|    116|        return 0;
   60|    116|      }
   61|       |      // range check
   62|  66.3k|      uint32_t code_point =
   63|  66.3k|          (leading_byte & 0b00011111) << 6 | (data[pos + 1] & 0b00111111);
   64|  66.3k|      if (code_point < 0x80) {
  ------------------
  |  Branch (64:11): [True: 22, False: 66.2k]
  ------------------
   65|     22|        return 0;
   66|     22|      }
   67|  66.2k|      if constexpr (!match_system(big_endian)) {
   68|  66.2k|        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
   69|  66.2k|      }
   70|  66.2k|      *utf16_output++ = char16_t(code_point);
   71|  66.2k|      pos += 2;
   72|  66.2k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (72:16): [True: 41.0k, False: 5.09k]
  ------------------
   73|       |      // We have a three-byte UTF-8, it should become
   74|       |      // a single UTF-16 word.
   75|  41.0k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (75:11): [True: 18, False: 41.0k]
  ------------------
   76|     18|        return 0;
   77|     18|      } // minimal bound checking
   78|       |
   79|  41.0k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (79:11): [True: 122, False: 40.9k]
  ------------------
   80|    122|        return 0;
   81|    122|      }
   82|  40.9k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (82:11): [True: 44, False: 40.8k]
  ------------------
   83|     44|        return 0;
   84|     44|      }
   85|       |      // range check
   86|  40.8k|      uint32_t code_point = (leading_byte & 0b00001111) << 12 |
   87|  40.8k|                            (data[pos + 1] & 0b00111111) << 6 |
   88|  40.8k|                            (data[pos + 2] & 0b00111111);
   89|  40.8k|      if (code_point < 0x800 || (0xd7ff < code_point && code_point < 0xe000)) {
  ------------------
  |  Branch (89:11): [True: 46, False: 40.8k]
  |  Branch (89:34): [True: 1.52k, False: 39.3k]
  |  Branch (89:57): [True: 26, False: 1.49k]
  ------------------
   90|     72|        return 0;
   91|     72|      }
   92|  40.8k|      if constexpr (!match_system(big_endian)) {
   93|  40.8k|        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
   94|  40.8k|      }
   95|  40.8k|      *utf16_output++ = char16_t(code_point);
   96|  40.8k|      pos += 3;
   97|  40.8k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (97:16): [True: 4.43k, False: 656]
  ------------------
   98|       |      // we have a 4-byte UTF-8 word.
   99|  4.43k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (99:11): [True: 36, False: 4.39k]
  ------------------
  100|     36|        return 0;
  101|     36|      } // minimal bound checking
  102|  4.39k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (102:11): [True: 150, False: 4.24k]
  ------------------
  103|    150|        return 0;
  104|    150|      }
  105|  4.24k|      if ((data[pos + 2] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (105:11): [True: 56, False: 4.19k]
  ------------------
  106|     56|        return 0;
  107|     56|      }
  108|  4.19k|      if ((data[pos + 3] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (108:11): [True: 20, False: 4.17k]
  ------------------
  109|     20|        return 0;
  110|     20|      }
  111|       |
  112|       |      // range check
  113|  4.17k|      uint32_t code_point = (leading_byte & 0b00000111) << 18 |
  114|  4.17k|                            (data[pos + 1] & 0b00111111) << 12 |
  115|  4.17k|                            (data[pos + 2] & 0b00111111) << 6 |
  116|  4.17k|                            (data[pos + 3] & 0b00111111);
  117|  4.17k|      if (code_point <= 0xffff || 0x10ffff < code_point) {
  ------------------
  |  Branch (117:11): [True: 42, False: 4.13k]
  |  Branch (117:35): [True: 38, False: 4.09k]
  ------------------
  118|     80|        return 0;
  119|     80|      }
  120|  4.09k|      code_point -= 0x10000;
  121|       |      // The mask is a no-op (code_point < 0x100000). It stops clang 18's SLP
  122|       |      // vectorizer on RISC-V V from narrowing code_point to 16 bits before
  123|       |      // the shift, which drops bits 16-19 of the code point.
  124|  4.09k|      uint16_t high_surrogate = uint16_t(0xD800 + ((code_point >> 10) & 0x3FF));
  125|  4.09k|      uint16_t low_surrogate = uint16_t(0xDC00 + (code_point & 0x3FF));
  126|  4.09k|      if constexpr (!match_system(big_endian)) {
  127|  4.09k|        high_surrogate = u16_swap_bytes(high_surrogate);
  128|  4.09k|        low_surrogate = u16_swap_bytes(low_surrogate);
  129|  4.09k|      }
  130|  4.09k|      *utf16_output++ = char16_t(high_surrogate);
  131|  4.09k|      *utf16_output++ = char16_t(low_surrogate);
  132|  4.09k|      pos += 4;
  133|  4.09k|    } else {
  134|    656|      return 0;
  135|    656|    }
  136|   644k|  }
  137|    594|  return utf16_output - start;
  138|  2.04k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf1619convert_with_errorsILNS_10endiannessE0EPKcQsr7simdutf6detailE22indexes_into_byte_likeIT0_EEENS_6resultES7_mPDs:
  145|  2.19k|                                               char16_t *utf16_output) {
  146|  2.19k|  size_t pos = 0;
  147|  2.19k|  char16_t *start{utf16_output};
  148|  2.74M|  while (pos < len) {
  ------------------
  |  Branch (148:10): [True: 2.74M, False: 616]
  ------------------
  149|       |#if SIMDUTF_CPLUSPLUS23
  150|       |    if !consteval
  151|       |#endif
  152|  2.74M|    {
  153|       |      // try to convert the next block of 16 ASCII bytes
  154|  2.74M|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (154:11): [True: 2.73M, False: 5.32k]
  ------------------
  155|       |                             // they are ascii
  156|  2.73M|        uint64_t v1;
  157|  2.73M|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
  158|  2.73M|        uint64_t v2;
  159|  2.73M|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
  160|  2.73M|        uint64_t v{v1 | v2};
  161|  2.73M|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (161:13): [True: 1.45M, False: 1.28M]
  ------------------
  162|  1.45M|          size_t final_pos = pos + 16;
  163|  24.6M|          while (pos < final_pos) {
  ------------------
  |  Branch (163:18): [True: 23.2M, False: 1.45M]
  ------------------
  164|  23.2M|            const char16_t byte = uint8_t(data[pos]);
  165|  23.2M|            *utf16_output++ =
  166|  23.2M|                !match_system(big_endian) ? u16_swap_bytes(byte) : byte;
  ------------------
  |  Branch (166:17): [Folded, False: 23.2M]
  ------------------
  167|  23.2M|            pos++;
  168|  23.2M|          }
  169|  1.45M|          continue;
  170|  1.45M|        }
  171|  2.73M|      }
  172|  2.74M|    }
  173|       |
  174|  1.29M|    auto leading_byte = uint8_t(data[pos]); // leading byte
  175|  1.29M|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (175:9): [True: 1.06M, False: 228k]
  ------------------
  176|       |      // converting one ASCII byte !!!
  177|  1.06M|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (177:25): [Folded, False: 1.06M]
  ------------------
  178|  1.06M|                            ? char16_t(u16_swap_bytes(leading_byte))
  179|  1.06M|                            : char16_t(leading_byte);
  180|  1.06M|      pos++;
  181|  1.06M|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (181:16): [True: 147k, False: 80.9k]
  ------------------
  182|       |      // We have a two-byte UTF-8, it should become
  183|       |      // a single UTF-16 word.
  184|   147k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (184:11): [True: 48, False: 147k]
  ------------------
  185|     48|        return result(error_code::TOO_SHORT, pos);
  186|     48|      } // minimal bound checking
  187|   147k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (187:11): [True: 222, False: 147k]
  ------------------
  188|    222|        return result(error_code::TOO_SHORT, pos);
  189|    222|      }
  190|       |      // range check
  191|   147k|      uint32_t code_point = (leading_byte & 0b00011111) << 6 |
  192|   147k|                            (uint8_t(data[pos + 1]) & 0b00111111);
  193|   147k|      if (code_point < 0x80) {
  ------------------
  |  Branch (193:11): [True: 18, False: 147k]
  ------------------
  194|     18|        return result(error_code::OVERLONG, pos);
  195|     18|      }
  196|       |      if constexpr (!match_system(big_endian)) {
  197|       |        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
  198|       |      }
  199|   147k|      *utf16_output++ = char16_t(code_point);
  200|   147k|      pos += 2;
  201|   147k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (201:16): [True: 63.7k, False: 17.2k]
  ------------------
  202|       |      // We have a three-byte UTF-8, it should become
  203|       |      // a single UTF-16 word.
  204|  63.7k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (204:11): [True: 30, False: 63.7k]
  ------------------
  205|     30|        return result(error_code::TOO_SHORT, pos);
  206|     30|      } // minimal bound checking
  207|       |
  208|  63.7k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (208:11): [True: 120, False: 63.6k]
  ------------------
  209|    120|        return result(error_code::TOO_SHORT, pos);
  210|    120|      }
  211|  63.6k|      if ((uint8_t(data[pos + 2]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (211:11): [True: 54, False: 63.5k]
  ------------------
  212|     54|        return result(error_code::TOO_SHORT, pos);
  213|     54|      }
  214|       |      // range check
  215|  63.5k|      uint32_t code_point = (leading_byte & 0b00001111) << 12 |
  216|  63.5k|                            (uint8_t(data[pos + 1]) & 0b00111111) << 6 |
  217|  63.5k|                            (uint8_t(data[pos + 2]) & 0b00111111);
  218|  63.5k|      if (code_point < 0x800) {
  ------------------
  |  Branch (218:11): [True: 24, False: 63.5k]
  ------------------
  219|     24|        return result(error_code::OVERLONG, pos);
  220|     24|      }
  221|  63.5k|      if (0xd7ff < code_point && code_point < 0xe000) {
  ------------------
  |  Branch (221:11): [True: 3.85k, False: 59.6k]
  |  Branch (221:34): [True: 6, False: 3.84k]
  ------------------
  222|      6|        return result(error_code::SURROGATE, pos);
  223|      6|      }
  224|       |      if constexpr (!match_system(big_endian)) {
  225|       |        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
  226|       |      }
  227|  63.5k|      *utf16_output++ = char16_t(code_point);
  228|  63.5k|      pos += 3;
  229|  63.5k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (229:16): [True: 16.5k, False: 706]
  ------------------
  230|       |      // we have a 4-byte UTF-8 word.
  231|  16.5k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (231:11): [True: 48, False: 16.4k]
  ------------------
  232|     48|        return result(error_code::TOO_SHORT, pos);
  233|     48|      } // minimal bound checking
  234|  16.4k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (234:11): [True: 126, False: 16.3k]
  ------------------
  235|    126|        return result(error_code::TOO_SHORT, pos);
  236|    126|      }
  237|  16.3k|      if ((uint8_t(data[pos + 2]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (237:11): [True: 36, False: 16.3k]
  ------------------
  238|     36|        return result(error_code::TOO_SHORT, pos);
  239|     36|      }
  240|  16.3k|      if ((uint8_t(data[pos + 3]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (240:11): [True: 42, False: 16.2k]
  ------------------
  241|     42|        return result(error_code::TOO_SHORT, pos);
  242|     42|      }
  243|       |
  244|       |      // range check
  245|  16.2k|      uint32_t code_point = (leading_byte & 0b00000111) << 18 |
  246|  16.2k|                            (uint8_t(data[pos + 1]) & 0b00111111) << 12 |
  247|  16.2k|                            (uint8_t(data[pos + 2]) & 0b00111111) << 6 |
  248|  16.2k|                            (uint8_t(data[pos + 3]) & 0b00111111);
  249|  16.2k|      if (code_point <= 0xffff) {
  ------------------
  |  Branch (249:11): [True: 36, False: 16.2k]
  ------------------
  250|     36|        return result(error_code::OVERLONG, pos);
  251|     36|      }
  252|  16.2k|      if (0x10ffff < code_point) {
  ------------------
  |  Branch (252:11): [True: 66, False: 16.1k]
  ------------------
  253|     66|        return result(error_code::TOO_LARGE, pos);
  254|     66|      }
  255|  16.1k|      code_point -= 0x10000;
  256|       |      // The mask is a no-op (code_point < 0x100000). It stops clang 18's SLP
  257|       |      // vectorizer on RISC-V V from narrowing code_point to 16 bits before
  258|       |      // the shift, which drops bits 16-19 of the code point.
  259|  16.1k|      uint16_t high_surrogate = uint16_t(0xD800 + ((code_point >> 10) & 0x3FF));
  260|  16.1k|      uint16_t low_surrogate = uint16_t(0xDC00 + (code_point & 0x3FF));
  261|       |      if constexpr (!match_system(big_endian)) {
  262|       |        high_surrogate = u16_swap_bytes(high_surrogate);
  263|       |        low_surrogate = u16_swap_bytes(low_surrogate);
  264|       |      }
  265|  16.1k|      *utf16_output++ = char16_t(high_surrogate);
  266|  16.1k|      *utf16_output++ = char16_t(low_surrogate);
  267|  16.1k|      pos += 4;
  268|  16.1k|    } else {
  269|       |      // we either have too many continuation bytes or an invalid leading byte
  270|    706|      if ((leading_byte & 0b11000000) == 0b10000000) {
  ------------------
  |  Branch (270:11): [True: 370, False: 336]
  ------------------
  271|    370|        return result(error_code::TOO_LONG, pos);
  272|    370|      } else {
  273|    336|        return result(error_code::HEADER_BITS, pos);
  274|    336|      }
  275|    706|    }
  276|  1.29M|  }
  277|    616|  return result(error_code::SUCCESS, utf16_output - start);
  278|  2.19k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf1619convert_with_errorsILNS_10endiannessE1EPKcQsr7simdutf6detailE22indexes_into_byte_likeIT0_EEENS_6resultES7_mPDs:
  145|  2.50k|                                               char16_t *utf16_output) {
  146|  2.50k|  size_t pos = 0;
  147|  2.50k|  char16_t *start{utf16_output};
  148|  2.41M|  while (pos < len) {
  ------------------
  |  Branch (148:10): [True: 2.41M, False: 920]
  ------------------
  149|       |#if SIMDUTF_CPLUSPLUS23
  150|       |    if !consteval
  151|       |#endif
  152|  2.41M|    {
  153|       |      // try to convert the next block of 16 ASCII bytes
  154|  2.41M|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (154:11): [True: 2.40M, False: 8.81k]
  ------------------
  155|       |                             // they are ascii
  156|  2.40M|        uint64_t v1;
  157|  2.40M|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
  158|  2.40M|        uint64_t v2;
  159|  2.40M|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
  160|  2.40M|        uint64_t v{v1 | v2};
  161|  2.40M|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (161:13): [True: 1.36M, False: 1.04M]
  ------------------
  162|  1.36M|          size_t final_pos = pos + 16;
  163|  23.1M|          while (pos < final_pos) {
  ------------------
  |  Branch (163:18): [True: 21.7M, False: 1.36M]
  ------------------
  164|  21.7M|            const char16_t byte = uint8_t(data[pos]);
  165|  21.7M|            *utf16_output++ =
  166|  21.7M|                !match_system(big_endian) ? u16_swap_bytes(byte) : byte;
  ------------------
  |  Branch (166:17): [True: 21.7M, Folded]
  ------------------
  167|  21.7M|            pos++;
  168|  21.7M|          }
  169|  1.36M|          continue;
  170|  1.36M|        }
  171|  2.40M|      }
  172|  2.41M|    }
  173|       |
  174|  1.05M|    auto leading_byte = uint8_t(data[pos]); // leading byte
  175|  1.05M|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (175:9): [True: 848k, False: 203k]
  ------------------
  176|       |      // converting one ASCII byte !!!
  177|   848k|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (177:25): [True: 848k, Folded]
  ------------------
  178|   848k|                            ? char16_t(u16_swap_bytes(leading_byte))
  179|   848k|                            : char16_t(leading_byte);
  180|   848k|      pos++;
  181|   848k|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (181:16): [True: 130k, False: 73.0k]
  ------------------
  182|       |      // We have a two-byte UTF-8, it should become
  183|       |      // a single UTF-16 word.
  184|   130k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (184:11): [True: 78, False: 130k]
  ------------------
  185|     78|        return result(error_code::TOO_SHORT, pos);
  186|     78|      } // minimal bound checking
  187|   130k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (187:11): [True: 186, False: 130k]
  ------------------
  188|    186|        return result(error_code::TOO_SHORT, pos);
  189|    186|      }
  190|       |      // range check
  191|   130k|      uint32_t code_point = (leading_byte & 0b00011111) << 6 |
  192|   130k|                            (uint8_t(data[pos + 1]) & 0b00111111);
  193|   130k|      if (code_point < 0x80) {
  ------------------
  |  Branch (193:11): [True: 18, False: 130k]
  ------------------
  194|     18|        return result(error_code::OVERLONG, pos);
  195|     18|      }
  196|   130k|      if constexpr (!match_system(big_endian)) {
  197|   130k|        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
  198|   130k|      }
  199|   130k|      *utf16_output++ = char16_t(code_point);
  200|   130k|      pos += 2;
  201|   130k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (201:16): [True: 63.0k, False: 9.92k]
  ------------------
  202|       |      // We have a three-byte UTF-8, it should become
  203|       |      // a single UTF-16 word.
  204|  63.0k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (204:11): [True: 36, False: 63.0k]
  ------------------
  205|     36|        return result(error_code::TOO_SHORT, pos);
  206|     36|      } // minimal bound checking
  207|       |
  208|  63.0k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (208:11): [True: 108, False: 62.9k]
  ------------------
  209|    108|        return result(error_code::TOO_SHORT, pos);
  210|    108|      }
  211|  62.9k|      if ((uint8_t(data[pos + 2]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (211:11): [True: 54, False: 62.8k]
  ------------------
  212|     54|        return result(error_code::TOO_SHORT, pos);
  213|     54|      }
  214|       |      // range check
  215|  62.8k|      uint32_t code_point = (leading_byte & 0b00001111) << 12 |
  216|  62.8k|                            (uint8_t(data[pos + 1]) & 0b00111111) << 6 |
  217|  62.8k|                            (uint8_t(data[pos + 2]) & 0b00111111);
  218|  62.8k|      if (code_point < 0x800) {
  ------------------
  |  Branch (218:11): [True: 36, False: 62.8k]
  ------------------
  219|     36|        return result(error_code::OVERLONG, pos);
  220|     36|      }
  221|  62.8k|      if (0xd7ff < code_point && code_point < 0xe000) {
  ------------------
  |  Branch (221:11): [True: 3.70k, False: 59.1k]
  |  Branch (221:34): [True: 12, False: 3.68k]
  ------------------
  222|     12|        return result(error_code::SURROGATE, pos);
  223|     12|      }
  224|  62.8k|      if constexpr (!match_system(big_endian)) {
  225|  62.8k|        code_point = uint32_t(u16_swap_bytes(uint16_t(code_point)));
  226|  62.8k|      }
  227|  62.8k|      *utf16_output++ = char16_t(code_point);
  228|  62.8k|      pos += 3;
  229|  62.8k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (229:16): [True: 9.13k, False: 788]
  ------------------
  230|       |      // we have a 4-byte UTF-8 word.
  231|  9.13k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (231:11): [True: 66, False: 9.06k]
  ------------------
  232|     66|        return result(error_code::TOO_SHORT, pos);
  233|     66|      } // minimal bound checking
  234|  9.06k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (234:11): [True: 102, False: 8.96k]
  ------------------
  235|    102|        return result(error_code::TOO_SHORT, pos);
  236|    102|      }
  237|  8.96k|      if ((uint8_t(data[pos + 2]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (237:11): [True: 18, False: 8.94k]
  ------------------
  238|     18|        return result(error_code::TOO_SHORT, pos);
  239|     18|      }
  240|  8.94k|      if ((uint8_t(data[pos + 3]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (240:11): [True: 18, False: 8.92k]
  ------------------
  241|     18|        return result(error_code::TOO_SHORT, pos);
  242|     18|      }
  243|       |
  244|       |      // range check
  245|  8.92k|      uint32_t code_point = (leading_byte & 0b00000111) << 18 |
  246|  8.92k|                            (uint8_t(data[pos + 1]) & 0b00111111) << 12 |
  247|  8.92k|                            (uint8_t(data[pos + 2]) & 0b00111111) << 6 |
  248|  8.92k|                            (uint8_t(data[pos + 3]) & 0b00111111);
  249|  8.92k|      if (code_point <= 0xffff) {
  ------------------
  |  Branch (249:11): [True: 30, False: 8.89k]
  ------------------
  250|     30|        return result(error_code::OVERLONG, pos);
  251|     30|      }
  252|  8.89k|      if (0x10ffff < code_point) {
  ------------------
  |  Branch (252:11): [True: 36, False: 8.86k]
  ------------------
  253|     36|        return result(error_code::TOO_LARGE, pos);
  254|     36|      }
  255|  8.86k|      code_point -= 0x10000;
  256|       |      // The mask is a no-op (code_point < 0x100000). It stops clang 18's SLP
  257|       |      // vectorizer on RISC-V V from narrowing code_point to 16 bits before
  258|       |      // the shift, which drops bits 16-19 of the code point.
  259|  8.86k|      uint16_t high_surrogate = uint16_t(0xD800 + ((code_point >> 10) & 0x3FF));
  260|  8.86k|      uint16_t low_surrogate = uint16_t(0xDC00 + (code_point & 0x3FF));
  261|  8.86k|      if constexpr (!match_system(big_endian)) {
  262|  8.86k|        high_surrogate = u16_swap_bytes(high_surrogate);
  263|  8.86k|        low_surrogate = u16_swap_bytes(low_surrogate);
  264|  8.86k|      }
  265|  8.86k|      *utf16_output++ = char16_t(high_surrogate);
  266|  8.86k|      *utf16_output++ = char16_t(low_surrogate);
  267|  8.86k|      pos += 4;
  268|  8.86k|    } else {
  269|       |      // we either have too many continuation bytes or an invalid leading byte
  270|    788|      if ((leading_byte & 0b11000000) == 0b10000000) {
  ------------------
  |  Branch (270:11): [True: 362, False: 426]
  ------------------
  271|    362|        return result(error_code::TOO_LONG, pos);
  272|    426|      } else {
  273|    426|        return result(error_code::HEADER_BITS, pos);
  274|    426|      }
  275|    788|    }
  276|  1.05M|  }
  277|    920|  return result(error_code::SUCCESS, utf16_output - start);
  278|  2.50k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf1630rewind_and_convert_with_errorsILNS_10endiannessE0EEENS_6resultEmPKcmPDs:
  298|    904|                                             char16_t *utf16_output) {
  299|    904|  size_t extra_len{0};
  300|       |  // We potentially need to go back in time and find a leading byte.
  301|       |  // In theory '3' would be sufficient, but sometimes the error can go back
  302|       |  // quite far.
  303|    904|  size_t how_far_back = prior_bytes;
  304|       |  // size_t how_far_back = 3; // 3 bytes in the past + current position
  305|       |  // if(how_far_back >= prior_bytes) { how_far_back = prior_bytes; }
  306|    904|  bool found_leading_bytes{false};
  307|       |  // important: it is i <= how_far_back and not 'i < how_far_back'.
  308|    960|  for (size_t i = 0; i <= how_far_back; i++) {
  ------------------
  |  Branch (308:22): [True: 920, False: 40]
  ------------------
  309|    920|    unsigned char byte = buf[-static_cast<std::ptrdiff_t>(i)];
  310|    920|    found_leading_bytes = ((byte & 0b11000000) != 0b10000000);
  311|    920|    if (found_leading_bytes) {
  ------------------
  |  Branch (311:9): [True: 864, False: 56]
  ------------------
  312|    864|      if (i > 0 && byte < 128) {
  ------------------
  |  Branch (312:11): [True: 16, False: 848]
  |  Branch (312:20): [True: 16, False: 0]
  ------------------
  313|       |        // If we had to go back and the leading byte is ascii
  314|       |        // then we can stop right away.
  315|     16|        return result(error_code::TOO_LONG, 0 - i + 1);
  316|     16|      }
  317|    848|      buf -= i;
  318|    848|      extra_len = i;
  319|    848|      break;
  320|    864|    }
  321|    920|  }
  322|       |  //
  323|       |  // It is possible for this function to return a negative count in its result.
  324|       |  // C++ Standard Section 18.1 defines size_t is in <cstddef> which is described
  325|       |  // in C Standard as <stddef.h>. C Standard Section 4.1.5 defines size_t as an
  326|       |  // unsigned integral type of the result of the sizeof operator
  327|       |  //
  328|       |  // An unsigned type will simply wrap round arithmetically (well defined).
  329|       |  //
  330|    888|  if (!found_leading_bytes) {
  ------------------
  |  Branch (330:7): [True: 40, False: 848]
  ------------------
  331|       |    // If how_far_back == 3, we may have four consecutive continuation bytes!!!
  332|       |    // [....] [continuation] [continuation] [continuation] | [buf is
  333|       |    // continuation] Or we possibly have a stream that does not start with a
  334|       |    // leading byte.
  335|     40|    return result(error_code::TOO_LONG, 0 - how_far_back);
  336|     40|  }
  337|    848|  result res = convert_with_errors<endian>(buf, len + extra_len, utf16_output);
  338|    848|  if (res.error) {
  ------------------
  |  Branch (338:7): [True: 700, False: 148]
  ------------------
  339|    700|    res.count -= extra_len;
  340|    700|  }
  341|    848|  return res;
  342|    888|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf1630rewind_and_convert_with_errorsILNS_10endiannessE1EEENS_6resultEmPKcmPDs:
  298|  1.02k|                                             char16_t *utf16_output) {
  299|  1.02k|  size_t extra_len{0};
  300|       |  // We potentially need to go back in time and find a leading byte.
  301|       |  // In theory '3' would be sufficient, but sometimes the error can go back
  302|       |  // quite far.
  303|  1.02k|  size_t how_far_back = prior_bytes;
  304|       |  // size_t how_far_back = 3; // 3 bytes in the past + current position
  305|       |  // if(how_far_back >= prior_bytes) { how_far_back = prior_bytes; }
  306|  1.02k|  bool found_leading_bytes{false};
  307|       |  // important: it is i <= how_far_back and not 'i < how_far_back'.
  308|  1.06k|  for (size_t i = 0; i <= how_far_back; i++) {
  ------------------
  |  Branch (308:22): [True: 1.02k, False: 36]
  ------------------
  309|  1.02k|    unsigned char byte = buf[-static_cast<std::ptrdiff_t>(i)];
  310|  1.02k|    found_leading_bytes = ((byte & 0b11000000) != 0b10000000);
  311|  1.02k|    if (found_leading_bytes) {
  ------------------
  |  Branch (311:9): [True: 984, False: 40]
  ------------------
  312|    984|      if (i > 0 && byte < 128) {
  ------------------
  |  Branch (312:11): [True: 4, False: 980]
  |  Branch (312:20): [True: 4, False: 0]
  ------------------
  313|       |        // If we had to go back and the leading byte is ascii
  314|       |        // then we can stop right away.
  315|      4|        return result(error_code::TOO_LONG, 0 - i + 1);
  316|      4|      }
  317|    980|      buf -= i;
  318|    980|      extra_len = i;
  319|    980|      break;
  320|    984|    }
  321|  1.02k|  }
  322|       |  //
  323|       |  // It is possible for this function to return a negative count in its result.
  324|       |  // C++ Standard Section 18.1 defines size_t is in <cstddef> which is described
  325|       |  // in C Standard as <stddef.h>. C Standard Section 4.1.5 defines size_t as an
  326|       |  // unsigned integral type of the result of the sizeof operator
  327|       |  //
  328|       |  // An unsigned type will simply wrap round arithmetically (well defined).
  329|       |  //
  330|  1.01k|  if (!found_leading_bytes) {
  ------------------
  |  Branch (330:7): [True: 36, False: 980]
  ------------------
  331|       |    // If how_far_back == 3, we may have four consecutive continuation bytes!!!
  332|       |    // [....] [continuation] [continuation] [continuation] | [buf is
  333|       |    // continuation] Or we possibly have a stream that does not start with a
  334|       |    // leading byte.
  335|     36|    return result(error_code::TOO_LONG, 0 - how_far_back);
  336|     36|  }
  337|    980|  result res = convert_with_errors<endian>(buf, len + extra_len, utf16_output);
  338|    980|  if (res.error) {
  ------------------
  |  Branch (338:7): [True: 696, False: 284]
  ------------------
  339|    696|    res.count -= extra_len;
  340|    696|  }
  341|    980|  return res;
  342|  1.01k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf1613convert_validILNS_10endiannessE0EPKcQsr7simdutf6detailE22indexes_into_byte_likeIT0_EEEmS7_mPDs:
   16|  1.03k|                                         char16_t *utf16_output) {
   17|  1.03k|  size_t pos = 0;
   18|  1.03k|  char16_t *start{utf16_output};
   19|  4.69M|  while (pos < len) {
  ------------------
  |  Branch (19:10): [True: 4.68M, False: 1.03k]
  ------------------
   20|       |#if SIMDUTF_CPLUSPLUS23
   21|       |    if !consteval
   22|       |#endif
   23|  4.68M|    {                       // try to convert the next block of 8 ASCII bytes
   24|  4.68M|      if (pos + 8 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (24:11): [True: 4.68M, False: 3.18k]
  ------------------
   25|       |                            // they are ascii
   26|  4.68M|        uint64_t v;
   27|  4.68M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   28|  4.68M|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (28:13): [True: 3.15M, False: 1.53M]
  ------------------
   29|  3.15M|          size_t final_pos = pos + 8;
   30|  28.3M|          while (pos < final_pos) {
  ------------------
  |  Branch (30:18): [True: 25.2M, False: 3.15M]
  ------------------
   31|  25.2M|            const char16_t byte = uint8_t(data[pos]);
   32|  25.2M|            *utf16_output++ =
   33|  25.2M|                !match_system(big_endian) ? u16_swap_bytes(byte) : byte;
  ------------------
  |  Branch (33:17): [Folded, False: 25.2M]
  ------------------
   34|  25.2M|            pos++;
   35|  25.2M|          }
   36|  3.15M|          continue;
   37|  3.15M|        }
   38|  4.68M|      }
   39|  4.68M|    }
   40|       |
   41|  1.53M|    auto leading_byte = uint8_t(data[pos]); // leading byte
   42|  1.53M|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (42:9): [True: 1.06M, False: 475k]
  ------------------
   43|       |      // converting one ASCII byte !!!
   44|  1.06M|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (44:25): [Folded, False: 1.06M]
  ------------------
   45|  1.06M|                            ? char16_t(u16_swap_bytes(leading_byte))
   46|  1.06M|                            : char16_t(leading_byte);
   47|  1.06M|      pos++;
   48|  1.06M|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (48:16): [True: 259k, False: 216k]
  ------------------
   49|       |      // We have a two-byte UTF-8, it should become
   50|       |      // a single UTF-16 word.
   51|   259k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (51:11): [True: 0, False: 259k]
  ------------------
   52|      0|        break;
   53|      0|      } // minimal bound checking
   54|   259k|      uint16_t code_point = uint16_t(((leading_byte & 0b00011111) << 6) |
   55|   259k|                                     (uint8_t(data[pos + 1]) & 0b00111111));
   56|       |      if constexpr (!match_system(big_endian)) {
   57|       |        code_point = u16_swap_bytes(uint16_t(code_point));
   58|       |      }
   59|   259k|      *utf16_output++ = char16_t(code_point);
   60|   259k|      pos += 2;
   61|   259k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (61:16): [True: 206k, False: 10.1k]
  ------------------
   62|       |      // We have a three-byte UTF-8, it should become
   63|       |      // a single UTF-16 word.
   64|   206k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (64:11): [True: 0, False: 206k]
  ------------------
   65|      0|        break;
   66|      0|      } // minimal bound checking
   67|   206k|      uint16_t code_point =
   68|   206k|          uint16_t(((leading_byte & 0b00001111) << 12) |
   69|   206k|                   ((uint8_t(data[pos + 1]) & 0b00111111) << 6) |
   70|   206k|                   (uint8_t(data[pos + 2]) & 0b00111111));
   71|       |      if constexpr (!match_system(big_endian)) {
   72|       |        code_point = u16_swap_bytes(uint16_t(code_point));
   73|       |      }
   74|   206k|      *utf16_output++ = char16_t(code_point);
   75|   206k|      pos += 3;
   76|   206k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (76:16): [True: 10.1k, False: 0]
  ------------------
   77|       |      // we have a 4-byte UTF-8 word.
   78|  10.1k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (78:11): [True: 0, False: 10.1k]
  ------------------
   79|      0|        break;
   80|      0|      } // minimal bound checking
   81|  10.1k|      uint32_t code_point = ((leading_byte & 0b00000111) << 18) |
   82|  10.1k|                            ((uint8_t(data[pos + 1]) & 0b00111111) << 12) |
   83|  10.1k|                            ((uint8_t(data[pos + 2]) & 0b00111111) << 6) |
   84|  10.1k|                            (uint8_t(data[pos + 3]) & 0b00111111);
   85|  10.1k|      code_point -= 0x10000;
   86|       |      // The mask is a no-op (code_point < 0x100000). It stops clang 18's SLP
   87|       |      // vectorizer on RISC-V V from narrowing code_point to 16 bits before
   88|       |      // the shift, which drops bits 16-19 of the code point.
   89|  10.1k|      uint16_t high_surrogate = uint16_t(0xD800 + ((code_point >> 10) & 0x3FF));
   90|  10.1k|      uint16_t low_surrogate = uint16_t(0xDC00 + (code_point & 0x3FF));
   91|       |      if constexpr (!match_system(big_endian)) {
   92|       |        high_surrogate = u16_swap_bytes(high_surrogate);
   93|       |        low_surrogate = u16_swap_bytes(low_surrogate);
   94|       |      }
   95|  10.1k|      *utf16_output++ = char16_t(high_surrogate);
   96|  10.1k|      *utf16_output++ = char16_t(low_surrogate);
   97|  10.1k|      pos += 4;
   98|  10.1k|    } else {
   99|       |      // we may have a continuation but we do not do error checking
  100|      0|      return 0;
  101|      0|    }
  102|  1.53M|  }
  103|  1.03k|  return utf16_output - start;
  104|  1.03k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf1613convert_validILNS_10endiannessE1EPKcQsr7simdutf6detailE22indexes_into_byte_likeIT0_EEEmS7_mPDs:
   16|  1.36k|                                         char16_t *utf16_output) {
   17|  1.36k|  size_t pos = 0;
   18|  1.36k|  char16_t *start{utf16_output};
   19|  3.90M|  while (pos < len) {
  ------------------
  |  Branch (19:10): [True: 3.90M, False: 1.36k]
  ------------------
   20|       |#if SIMDUTF_CPLUSPLUS23
   21|       |    if !consteval
   22|       |#endif
   23|  3.90M|    {                       // try to convert the next block of 8 ASCII bytes
   24|  3.90M|      if (pos + 8 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (24:11): [True: 3.89M, False: 4.32k]
  ------------------
   25|       |                            // they are ascii
   26|  3.89M|        uint64_t v;
   27|  3.89M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   28|  3.89M|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (28:13): [True: 3.01M, False: 880k]
  ------------------
   29|  3.01M|          size_t final_pos = pos + 8;
   30|  27.1M|          while (pos < final_pos) {
  ------------------
  |  Branch (30:18): [True: 24.1M, False: 3.01M]
  ------------------
   31|  24.1M|            const char16_t byte = uint8_t(data[pos]);
   32|  24.1M|            *utf16_output++ =
   33|  24.1M|                !match_system(big_endian) ? u16_swap_bytes(byte) : byte;
  ------------------
  |  Branch (33:17): [True: 24.1M, Folded]
  ------------------
   34|  24.1M|            pos++;
   35|  24.1M|          }
   36|  3.01M|          continue;
   37|  3.01M|        }
   38|  3.89M|      }
   39|  3.90M|    }
   40|       |
   41|   885k|    auto leading_byte = uint8_t(data[pos]); // leading byte
   42|   885k|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (42:9): [True: 572k, False: 312k]
  ------------------
   43|       |      // converting one ASCII byte !!!
   44|   572k|      *utf16_output++ = !match_system(big_endian)
  ------------------
  |  Branch (44:25): [True: 572k, Folded]
  ------------------
   45|   572k|                            ? char16_t(u16_swap_bytes(leading_byte))
   46|   572k|                            : char16_t(leading_byte);
   47|   572k|      pos++;
   48|   572k|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (48:16): [True: 215k, False: 97.5k]
  ------------------
   49|       |      // We have a two-byte UTF-8, it should become
   50|       |      // a single UTF-16 word.
   51|   215k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (51:11): [True: 0, False: 215k]
  ------------------
   52|      0|        break;
   53|      0|      } // minimal bound checking
   54|   215k|      uint16_t code_point = uint16_t(((leading_byte & 0b00011111) << 6) |
   55|   215k|                                     (uint8_t(data[pos + 1]) & 0b00111111));
   56|   215k|      if constexpr (!match_system(big_endian)) {
   57|   215k|        code_point = u16_swap_bytes(uint16_t(code_point));
   58|   215k|      }
   59|   215k|      *utf16_output++ = char16_t(code_point);
   60|   215k|      pos += 2;
   61|   215k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (61:16): [True: 72.6k, False: 24.8k]
  ------------------
   62|       |      // We have a three-byte UTF-8, it should become
   63|       |      // a single UTF-16 word.
   64|  72.6k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (64:11): [True: 0, False: 72.6k]
  ------------------
   65|      0|        break;
   66|      0|      } // minimal bound checking
   67|  72.6k|      uint16_t code_point =
   68|  72.6k|          uint16_t(((leading_byte & 0b00001111) << 12) |
   69|  72.6k|                   ((uint8_t(data[pos + 1]) & 0b00111111) << 6) |
   70|  72.6k|                   (uint8_t(data[pos + 2]) & 0b00111111));
   71|  72.6k|      if constexpr (!match_system(big_endian)) {
   72|  72.6k|        code_point = u16_swap_bytes(uint16_t(code_point));
   73|  72.6k|      }
   74|  72.6k|      *utf16_output++ = char16_t(code_point);
   75|  72.6k|      pos += 3;
   76|  72.6k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (76:16): [True: 24.8k, False: 0]
  ------------------
   77|       |      // we have a 4-byte UTF-8 word.
   78|  24.8k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (78:11): [True: 0, False: 24.8k]
  ------------------
   79|      0|        break;
   80|      0|      } // minimal bound checking
   81|  24.8k|      uint32_t code_point = ((leading_byte & 0b00000111) << 18) |
   82|  24.8k|                            ((uint8_t(data[pos + 1]) & 0b00111111) << 12) |
   83|  24.8k|                            ((uint8_t(data[pos + 2]) & 0b00111111) << 6) |
   84|  24.8k|                            (uint8_t(data[pos + 3]) & 0b00111111);
   85|  24.8k|      code_point -= 0x10000;
   86|       |      // The mask is a no-op (code_point < 0x100000). It stops clang 18's SLP
   87|       |      // vectorizer on RISC-V V from narrowing code_point to 16 bits before
   88|       |      // the shift, which drops bits 16-19 of the code point.
   89|  24.8k|      uint16_t high_surrogate = uint16_t(0xD800 + ((code_point >> 10) & 0x3FF));
   90|  24.8k|      uint16_t low_surrogate = uint16_t(0xDC00 + (code_point & 0x3FF));
   91|  24.8k|      if constexpr (!match_system(big_endian)) {
   92|  24.8k|        high_surrogate = u16_swap_bytes(high_surrogate);
   93|  24.8k|        low_surrogate = u16_swap_bytes(low_surrogate);
   94|  24.8k|      }
   95|  24.8k|      *utf16_output++ = char16_t(high_surrogate);
   96|  24.8k|      *utf16_output++ = char16_t(low_surrogate);
   97|  24.8k|      pos += 4;
   98|  24.8k|    } else {
   99|       |      // we may have a continuation but we do not do error checking
  100|      0|      return 0;
  101|      0|    }
  102|   885k|  }
  103|  1.36k|  return utf16_output - start;
  104|  1.36k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf3230rewind_and_convert_with_errorsEmPKcmPDi:
  249|  1.04k|                                             char32_t *utf32_output) {
  250|  1.04k|  size_t extra_len{0};
  251|       |  // We potentially need to go back in time and find a leading byte.
  252|  1.04k|  size_t how_far_back = 3; // 3 bytes in the past + current position
  253|  1.04k|  if (how_far_back > prior_bytes) {
  ------------------
  |  Branch (253:7): [True: 332, False: 708]
  ------------------
  254|    332|    how_far_back = prior_bytes;
  255|    332|  }
  256|  1.04k|  bool found_leading_bytes{false};
  257|       |  // important: it is i <= how_far_back and not 'i < how_far_back'.
  258|  1.08k|  for (size_t i = 0; i <= how_far_back; i++) {
  ------------------
  |  Branch (258:22): [True: 1.04k, False: 32]
  ------------------
  259|  1.04k|    unsigned char byte = buf[-static_cast<std::ptrdiff_t>(i)];
  260|  1.04k|    found_leading_bytes = ((byte & 0b11000000) != 0b10000000);
  261|  1.04k|    if (found_leading_bytes) {
  ------------------
  |  Branch (261:9): [True: 1.00k, False: 40]
  ------------------
  262|  1.00k|      if (i > 0 && byte < 128) {
  ------------------
  |  Branch (262:11): [True: 8, False: 1.00k]
  |  Branch (262:20): [True: 8, False: 0]
  ------------------
  263|       |        // If we had to go back and the leading byte is ascii
  264|       |        // then we can stop right away.
  265|      8|        return result(error_code::TOO_LONG, 0 - i + 1);
  266|      8|      }
  267|  1.00k|      buf -= i;
  268|  1.00k|      extra_len = i;
  269|  1.00k|      break;
  270|  1.00k|    }
  271|  1.04k|  }
  272|       |  //
  273|       |  // It is possible for this function to return a negative count in its result.
  274|       |  // C++ Standard Section 18.1 defines size_t is in <cstddef> which is described
  275|       |  // in C Standard as <stddef.h>. C Standard Section 4.1.5 defines size_t as an
  276|       |  // unsigned integral type of the result of the sizeof operator
  277|       |  //
  278|       |  // An unsigned type will simply wrap round arithmetically (well defined).
  279|       |  //
  280|  1.03k|  if (!found_leading_bytes) {
  ------------------
  |  Branch (280:7): [True: 32, False: 1.00k]
  ------------------
  281|       |    // If how_far_back == 3, we may have four consecutive continuation bytes!!!
  282|       |    // [....] [continuation] [continuation] [continuation] | [buf is
  283|       |    // continuation] Or we possibly have a stream that does not start with a
  284|       |    // leading byte.
  285|     32|    return result(error_code::TOO_LONG, 0 - how_far_back);
  286|     32|  }
  287|       |
  288|  1.00k|  result res = convert_with_errors(buf, len + extra_len, utf32_output);
  289|  1.00k|  if (res.error) {
  ------------------
  |  Branch (289:7): [True: 780, False: 220]
  ------------------
  290|    780|    res.count -= extra_len;
  291|    780|  }
  292|  1.00k|  return res;
  293|  1.03k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf3219convert_with_errorsIPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEENS_6resultES6_mPDi:
  121|  2.53k|                                               char32_t *utf32_output) {
  122|  2.53k|  size_t pos = 0;
  123|  2.53k|  char32_t *start{utf32_output};
  124|  3.04M|  while (pos < len) {
  ------------------
  |  Branch (124:10): [True: 3.04M, False: 796]
  ------------------
  125|       |#if SIMDUTF_CPLUSPLUS23
  126|       |    if !consteval
  127|       |#endif
  128|  3.04M|    {
  129|       |      // try to convert the next block of 16 ASCII bytes
  130|  3.04M|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (130:11): [True: 3.03M, False: 8.19k]
  ------------------
  131|       |                             // they are ascii
  132|  3.03M|        uint64_t v1;
  133|  3.03M|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
  134|  3.03M|        uint64_t v2;
  135|  3.03M|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
  136|  3.03M|        uint64_t v{v1 | v2};
  137|  3.03M|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (137:13): [True: 1.93M, False: 1.10M]
  ------------------
  138|  1.93M|          size_t final_pos = pos + 16;
  139|  32.8M|          while (pos < final_pos) {
  ------------------
  |  Branch (139:18): [True: 30.9M, False: 1.93M]
  ------------------
  140|  30.9M|            *utf32_output++ = uint8_t(data[pos]);
  141|  30.9M|            pos++;
  142|  30.9M|          }
  143|  1.93M|          continue;
  144|  1.93M|        }
  145|  3.03M|      }
  146|  3.04M|    }
  147|  1.10M|    auto leading_byte = uint8_t(data[pos]); // leading byte
  148|  1.10M|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (148:9): [True: 735k, False: 374k]
  ------------------
  149|       |      // converting one ASCII byte !!!
  150|   735k|      *utf32_output++ = char32_t(leading_byte);
  151|   735k|      pos++;
  152|   735k|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (152:16): [True: 146k, False: 227k]
  ------------------
  153|       |      // We have a two-byte UTF-8
  154|   146k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (154:11): [True: 102, False: 146k]
  ------------------
  155|    102|        return result(error_code::TOO_SHORT, pos);
  156|    102|      } // minimal bound checking
  157|   146k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (157:11): [True: 288, False: 146k]
  ------------------
  158|    288|        return result(error_code::TOO_SHORT, pos);
  159|    288|      }
  160|       |      // range check
  161|   146k|      uint32_t code_point = (leading_byte & 0b00011111) << 6 |
  162|   146k|                            (uint8_t(data[pos + 1]) & 0b00111111);
  163|   146k|      if (code_point < 0x80) {
  ------------------
  |  Branch (163:11): [True: 24, False: 146k]
  ------------------
  164|     24|        return result(error_code::OVERLONG, pos);
  165|     24|      }
  166|   146k|      *utf32_output++ = char32_t(code_point);
  167|   146k|      pos += 2;
  168|   227k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (168:16): [True: 214k, False: 13.2k]
  ------------------
  169|       |      // We have a three-byte UTF-8
  170|   214k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (170:11): [True: 66, False: 214k]
  ------------------
  171|     66|        return result(error_code::TOO_SHORT, pos);
  172|     66|      } // minimal bound checking
  173|       |
  174|   214k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (174:11): [True: 168, False: 213k]
  ------------------
  175|    168|        return result(error_code::TOO_SHORT, pos);
  176|    168|      }
  177|   213k|      if ((uint8_t(data[pos + 2]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (177:11): [True: 66, False: 213k]
  ------------------
  178|     66|        return result(error_code::TOO_SHORT, pos);
  179|     66|      }
  180|       |      // range check
  181|   213k|      uint32_t code_point = (leading_byte & 0b00001111) << 12 |
  182|   213k|                            (uint8_t(data[pos + 1]) & 0b00111111) << 6 |
  183|   213k|                            (uint8_t(data[pos + 2]) & 0b00111111);
  184|   213k|      if (code_point < 0x800) {
  ------------------
  |  Branch (184:11): [True: 24, False: 213k]
  ------------------
  185|     24|        return result(error_code::OVERLONG, pos);
  186|     24|      }
  187|   213k|      if (0xd7ff < code_point && code_point < 0xe000) {
  ------------------
  |  Branch (187:11): [True: 160k, False: 53.5k]
  |  Branch (187:34): [True: 6, False: 160k]
  ------------------
  188|      6|        return result(error_code::SURROGATE, pos);
  189|      6|      }
  190|   213k|      *utf32_output++ = char32_t(code_point);
  191|   213k|      pos += 3;
  192|   213k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (192:16): [True: 12.5k, False: 740]
  ------------------
  193|       |      // we have a 4-byte UTF-8 word.
  194|  12.5k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (194:11): [True: 36, False: 12.4k]
  ------------------
  195|     36|        return result(error_code::TOO_SHORT, pos);
  196|     36|      } // minimal bound checking
  197|  12.4k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (197:11): [True: 84, False: 12.3k]
  ------------------
  198|     84|        return result(error_code::TOO_SHORT, pos);
  199|     84|      }
  200|  12.3k|      if ((uint8_t(data[pos + 2]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (200:11): [True: 30, False: 12.3k]
  ------------------
  201|     30|        return result(error_code::TOO_SHORT, pos);
  202|     30|      }
  203|  12.3k|      if ((uint8_t(data[pos + 3]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (203:11): [True: 24, False: 12.3k]
  ------------------
  204|     24|        return result(error_code::TOO_SHORT, pos);
  205|     24|      }
  206|       |
  207|       |      // range check
  208|  12.3k|      uint32_t code_point = (leading_byte & 0b00000111) << 18 |
  209|  12.3k|                            (uint8_t(data[pos + 1]) & 0b00111111) << 12 |
  210|  12.3k|                            (uint8_t(data[pos + 2]) & 0b00111111) << 6 |
  211|  12.3k|                            (uint8_t(data[pos + 3]) & 0b00111111);
  212|  12.3k|      if (code_point <= 0xffff) {
  ------------------
  |  Branch (212:11): [True: 48, False: 12.2k]
  ------------------
  213|     48|        return result(error_code::OVERLONG, pos);
  214|     48|      }
  215|  12.2k|      if (0x10ffff < code_point) {
  ------------------
  |  Branch (215:11): [True: 36, False: 12.2k]
  ------------------
  216|     36|        return result(error_code::TOO_LARGE, pos);
  217|     36|      }
  218|  12.2k|      *utf32_output++ = char32_t(code_point);
  219|  12.2k|      pos += 4;
  220|  12.2k|    } else {
  221|       |      // we either have too many continuation bytes or an invalid leading byte
  222|    740|      if ((leading_byte & 0b11000000) == 0b10000000) {
  ------------------
  |  Branch (222:11): [True: 410, False: 330]
  ------------------
  223|    410|        return result(error_code::TOO_LONG, pos);
  224|    410|      } else {
  225|    330|        return result(error_code::HEADER_BITS, pos);
  226|    330|      }
  227|    740|    }
  228|  1.10M|  }
  229|    796|  return result(error_code::SUCCESS, utf32_output - start);
  230|  2.53k|}
simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf327convertIPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_mPDi:
   16|  2.01k|                                   char32_t *utf32_output) {
   17|  2.01k|  size_t pos = 0;
   18|  2.01k|  char32_t *start{utf32_output};
   19|  1.80M|  while (pos < len) {
  ------------------
  |  Branch (19:10): [True: 1.80M, False: 612]
  ------------------
   20|       |#if SIMDUTF_CPLUSPLUS23
   21|       |    if !consteval
   22|       |#endif
   23|  1.80M|    {
   24|       |      // try to convert the next block of 16 ASCII bytes
   25|  1.80M|      if (pos + 16 <= len) { // if it is safe to read 16 more bytes, check that
  ------------------
  |  Branch (25:11): [True: 1.79M, False: 4.41k]
  ------------------
   26|       |                             // they are ascii
   27|  1.79M|        uint64_t v1;
   28|  1.79M|        ::memcpy(&v1, data + pos, sizeof(uint64_t));
   29|  1.79M|        uint64_t v2;
   30|  1.79M|        ::memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
   31|  1.79M|        uint64_t v{v1 | v2};
   32|  1.79M|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (32:13): [True: 1.03M, False: 762k]
  ------------------
   33|  1.03M|          size_t final_pos = pos + 16;
   34|  17.6M|          while (pos < final_pos) {
  ------------------
  |  Branch (34:18): [True: 16.5M, False: 1.03M]
  ------------------
   35|  16.5M|            *utf32_output++ = uint8_t(data[pos]);
   36|  16.5M|            pos++;
   37|  16.5M|          }
   38|  1.03M|          continue;
   39|  1.03M|        }
   40|  1.79M|      }
   41|  1.80M|    }
   42|   767k|    auto leading_byte = uint8_t(data[pos]); // leading byte
   43|   767k|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (43:9): [True: 635k, False: 131k]
  ------------------
   44|       |      // converting one ASCII byte !!!
   45|   635k|      *utf32_output++ = char32_t(leading_byte);
   46|   635k|      pos++;
   47|   635k|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (47:16): [True: 75.2k, False: 56.4k]
  ------------------
   48|       |      // We have a two-byte UTF-8
   49|  75.2k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (49:11): [True: 36, False: 75.1k]
  ------------------
   50|     36|        return 0;
   51|     36|      } // minimal bound checking
   52|  75.1k|      if ((data[pos + 1] & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (52:11): [True: 146, False: 75.0k]
  ------------------
   53|    146|        return 0;
   54|    146|      }
   55|       |      // range check
   56|  75.0k|      uint32_t code_point = (leading_byte & 0b00011111) << 6 |
   57|  75.0k|                            (uint8_t(data[pos + 1]) & 0b00111111);
   58|  75.0k|      if (code_point < 0x80) {
  ------------------
  |  Branch (58:11): [True: 32, False: 75.0k]
  ------------------
   59|     32|        return 0;
   60|     32|      }
   61|  75.0k|      *utf32_output++ = char32_t(code_point);
   62|  75.0k|      pos += 2;
   63|  75.0k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (63:16): [True: 51.4k, False: 5.01k]
  ------------------
   64|       |      // We have a three-byte UTF-8
   65|  51.4k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (65:11): [True: 24, False: 51.4k]
  ------------------
   66|     24|        return 0;
   67|     24|      } // minimal bound checking
   68|       |
   69|  51.4k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (69:11): [True: 114, False: 51.2k]
  ------------------
   70|    114|        return 0;
   71|    114|      }
   72|  51.2k|      if ((uint8_t(data[pos + 2]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (72:11): [True: 66, False: 51.2k]
  ------------------
   73|     66|        return 0;
   74|     66|      }
   75|       |      // range check
   76|  51.2k|      uint32_t code_point = (leading_byte & 0b00001111) << 12 |
   77|  51.2k|                            (uint8_t(data[pos + 1]) & 0b00111111) << 6 |
   78|  51.2k|                            (uint8_t(data[pos + 2]) & 0b00111111);
   79|  51.2k|      if (code_point < 0x800 || (0xd7ff < code_point && code_point < 0xe000)) {
  ------------------
  |  Branch (79:11): [True: 42, False: 51.1k]
  |  Branch (79:34): [True: 1.38k, False: 49.8k]
  |  Branch (79:57): [True: 34, False: 1.34k]
  ------------------
   80|     76|        return 0;
   81|     76|      }
   82|  51.1k|      *utf32_output++ = char32_t(code_point);
   83|  51.1k|      pos += 3;
   84|  51.1k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (84:16): [True: 4.39k, False: 618]
  ------------------
   85|       |      // we have a 4-byte UTF-8 word.
   86|  4.39k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (86:11): [True: 30, False: 4.36k]
  ------------------
   87|     30|        return 0;
   88|     30|      } // minimal bound checking
   89|  4.36k|      if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (89:11): [True: 94, False: 4.26k]
  ------------------
   90|     94|        return 0;
   91|     94|      }
   92|  4.26k|      if ((uint8_t(data[pos + 2]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (92:11): [True: 46, False: 4.22k]
  ------------------
   93|     46|        return 0;
   94|     46|      }
   95|  4.22k|      if ((uint8_t(data[pos + 3]) & 0b11000000) != 0b10000000) {
  ------------------
  |  Branch (95:11): [True: 32, False: 4.19k]
  ------------------
   96|     32|        return 0;
   97|     32|      }
   98|       |
   99|       |      // range check
  100|  4.19k|      uint32_t code_point = (leading_byte & 0b00000111) << 18 |
  101|  4.19k|                            (uint8_t(data[pos + 1]) & 0b00111111) << 12 |
  102|  4.19k|                            (uint8_t(data[pos + 2]) & 0b00111111) << 6 |
  103|  4.19k|                            (uint8_t(data[pos + 3]) & 0b00111111);
  104|  4.19k|      if (code_point <= 0xffff || 0x10ffff < code_point) {
  ------------------
  |  Branch (104:11): [True: 44, False: 4.14k]
  |  Branch (104:35): [True: 40, False: 4.10k]
  ------------------
  105|     84|        return 0;
  106|     84|      }
  107|  4.10k|      *utf32_output++ = char32_t(code_point);
  108|  4.10k|      pos += 4;
  109|  4.10k|    } else {
  110|    618|      return 0;
  111|    618|    }
  112|   767k|  }
  113|    612|  return utf32_output - start;
  114|  2.01k|}

simdutf.cpp:_ZN7simdutf6scalar12_GLOBAL__N_113utf8_to_utf3213convert_validIPKcQsr7simdutf6detailE22indexes_into_byte_likeIT_EEEmS6_mPDi:
   16|  1.53k|                                         char32_t *utf32_output) {
   17|  1.53k|  size_t pos = 0;
   18|  1.53k|  char32_t *start{utf32_output};
   19|  4.20M|  while (pos < len) {
  ------------------
  |  Branch (19:10): [True: 4.20M, False: 1.53k]
  ------------------
   20|       |#if SIMDUTF_CPLUSPLUS23
   21|       |    if !consteval
   22|       |#endif
   23|  4.20M|    {
   24|       |      // try to convert the next block of 8 ASCII bytes
   25|  4.20M|      if (pos + 8 <= len) { // if it is safe to read 8 more bytes, check that
  ------------------
  |  Branch (25:11): [True: 4.19M, False: 4.72k]
  ------------------
   26|       |                            // they are ascii
   27|  4.19M|        uint64_t v;
   28|  4.19M|        ::memcpy(&v, data + pos, sizeof(uint64_t));
   29|  4.19M|        if ((v & 0x8080808080808080) == 0) {
  ------------------
  |  Branch (29:13): [True: 3.58M, False: 614k]
  ------------------
   30|  3.58M|          size_t final_pos = pos + 8;
   31|  32.2M|          while (pos < final_pos) {
  ------------------
  |  Branch (31:18): [True: 28.6M, False: 3.58M]
  ------------------
   32|  28.6M|            *utf32_output++ = uint8_t(data[pos]);
   33|  28.6M|            pos++;
   34|  28.6M|          }
   35|  3.58M|          continue;
   36|  3.58M|        }
   37|  4.19M|      }
   38|  4.20M|    }
   39|   619k|    auto leading_byte = uint8_t(data[pos]); // leading byte
   40|   619k|    if (leading_byte < 0b10000000) {
  ------------------
  |  Branch (40:9): [True: 343k, False: 275k]
  ------------------
   41|       |      // converting one ASCII byte !!!
   42|   343k|      *utf32_output++ = char32_t(leading_byte);
   43|   343k|      pos++;
   44|   343k|    } else if ((leading_byte & 0b11100000) == 0b11000000) {
  ------------------
  |  Branch (44:16): [True: 204k, False: 71.3k]
  ------------------
   45|       |      // We have a two-byte UTF-8
   46|   204k|      if (pos + 1 >= len) {
  ------------------
  |  Branch (46:11): [True: 0, False: 204k]
  ------------------
   47|      0|        break;
   48|      0|      } // minimal bound checking
   49|   204k|      *utf32_output++ = char32_t(((leading_byte & 0b00011111) << 6) |
   50|   204k|                                 (uint8_t(data[pos + 1]) & 0b00111111));
   51|   204k|      pos += 2;
   52|   204k|    } else if ((leading_byte & 0b11110000) == 0b11100000) {
  ------------------
  |  Branch (52:16): [True: 40.4k, False: 30.8k]
  ------------------
   53|       |      // We have a three-byte UTF-8
   54|  40.4k|      if (pos + 2 >= len) {
  ------------------
  |  Branch (54:11): [True: 0, False: 40.4k]
  ------------------
   55|      0|        break;
   56|      0|      } // minimal bound checking
   57|  40.4k|      *utf32_output++ = char32_t(((leading_byte & 0b00001111) << 12) |
   58|  40.4k|                                 ((uint8_t(data[pos + 1]) & 0b00111111) << 6) |
   59|  40.4k|                                 (uint8_t(data[pos + 2]) & 0b00111111));
   60|  40.4k|      pos += 3;
   61|  40.4k|    } else if ((leading_byte & 0b11111000) == 0b11110000) { // 0b11110000
  ------------------
  |  Branch (61:16): [True: 30.8k, False: 0]
  ------------------
   62|       |      // we have a 4-byte UTF-8 word.
   63|  30.8k|      if (pos + 3 >= len) {
  ------------------
  |  Branch (63:11): [True: 0, False: 30.8k]
  ------------------
   64|      0|        break;
   65|      0|      } // minimal bound checking
   66|  30.8k|      uint32_t code_word = ((leading_byte & 0b00000111) << 18) |
   67|  30.8k|                           ((uint8_t(data[pos + 1]) & 0b00111111) << 12) |
   68|  30.8k|                           ((uint8_t(data[pos + 2]) & 0b00111111) << 6) |
   69|  30.8k|                           (uint8_t(data[pos + 3]) & 0b00111111);
   70|  30.8k|      *utf32_output++ = char32_t(code_word);
   71|  30.8k|      pos += 4;
   72|  30.8k|    } else {
   73|       |      // we may have a continuation but we do not do error checking
   74|      0|      return 0;
   75|      0|    }
   76|   619k|  }
   77|  1.53k|  return utf32_output - start;
   78|  1.53k|}

_ZNK7simdutf8fallback14implementation13validate_utf8EPKcm:
   37|  4.11k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
   38|  4.11k|  return scalar::utf8::validate(buf, len);
   39|  4.11k|}
_ZNK7simdutf8fallback14implementation25validate_utf8_with_errorsEPKcm:
   44|  4.11k|    const char *buf, size_t len) const noexcept {
   45|  4.11k|  return scalar::utf8::validate_with_errors(buf, len);
   46|  4.11k|}
_ZNK7simdutf8fallback14implementation16validate_utf16leEPKDsm:
   77|  1.42k|                                 size_t len) const noexcept {
   78|  1.42k|  return scalar::utf16::validate<endianness::LITTLE>(buf, len);
   79|  1.42k|}
_ZNK7simdutf8fallback14implementation16validate_utf16beEPKDsm:
   85|  1.33k|                                 size_t len) const noexcept {
   86|  1.33k|  return scalar::utf16::validate<endianness::BIG>(buf, len);
   87|  1.33k|}
_ZNK7simdutf8fallback14implementation28validate_utf16le_with_errorsEPKDsm:
   90|  1.42k|    const char16_t *buf, size_t len) const noexcept {
   91|  1.42k|  return scalar::utf16::validate_with_errors<endianness::LITTLE>(buf, len);
   92|  1.42k|}
_ZNK7simdutf8fallback14implementation28validate_utf16be_with_errorsEPKDsm:
   95|  1.33k|    const char16_t *buf, size_t len) const noexcept {
   96|  1.33k|  return scalar::utf16::validate_with_errors<endianness::BIG>(buf, len);
   97|  1.33k|}
_ZNK7simdutf8fallback14implementation14validate_utf32EPKDim:
  114|  2.68k|implementation::validate_utf32(const char32_t *buf, size_t len) const noexcept {
  115|  2.68k|  return scalar::utf32::validate(buf, len);
  116|  2.68k|}
_ZNK7simdutf8fallback14implementation26validate_utf32_with_errorsEPKDim:
  121|  2.68k|    const char32_t *buf, size_t len) const noexcept {
  122|  2.68k|  return scalar::utf32::validate_with_errors(buf, len);
  123|  2.68k|}
_ZNK7simdutf8fallback14implementation22convert_latin1_to_utf8EPKcmPc:
  128|    486|    const char *buf, size_t len, char *utf8_output) const noexcept {
  129|    486|  return scalar::latin1_to_utf8::convert(buf, len, utf8_output);
  130|    486|}
_ZNK7simdutf8fallback14implementation25convert_latin1_to_utf16leEPKcmPDs:
  135|     82|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  136|     82|  return scalar::latin1_to_utf16::convert<endianness::LITTLE>(buf, len,
  137|     82|                                                              utf16_output);
  138|     82|}
_ZNK7simdutf8fallback14implementation25convert_latin1_to_utf16beEPKcmPDs:
  141|    108|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  142|    108|  return scalar::latin1_to_utf16::convert<endianness::BIG>(buf, len,
  143|    108|                                                           utf16_output);
  144|    108|}
_ZNK7simdutf8fallback14implementation23convert_latin1_to_utf32EPKcmPDi:
  149|    102|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  150|    102|  return scalar::latin1_to_utf32::convert(buf, len, utf32_output);
  151|    102|}
_ZNK7simdutf8fallback14implementation22convert_utf8_to_latin1EPKcmPc:
  156|    716|    const char *buf, size_t len, char *latin1_output) const noexcept {
  157|    716|  return scalar::utf8_to_latin1::convert(buf, len, latin1_output);
  158|    716|}
_ZNK7simdutf8fallback14implementation34convert_utf8_to_latin1_with_errorsEPKcmPc:
  161|    670|    const char *buf, size_t len, char *latin1_output) const noexcept {
  162|    670|  return scalar::utf8_to_latin1::convert_with_errors(buf, len, latin1_output);
  163|    670|}
_ZNK7simdutf8fallback14implementation23convert_utf8_to_utf16leEPKcmPDs:
  173|    950|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  174|    950|  return scalar::utf8_to_utf16::convert<endianness::LITTLE>(buf, len,
  175|    950|                                                            utf16_output);
  176|    950|}
_ZNK7simdutf8fallback14implementation23convert_utf8_to_utf16beEPKcmPDs:
  179|    974|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  180|    974|  return scalar::utf8_to_utf16::convert<endianness::BIG>(buf, len,
  181|    974|                                                         utf16_output);
  182|    974|}
_ZNK7simdutf8fallback14implementation35convert_utf8_to_utf16le_with_errorsEPKcmPDs:
  185|    782|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  186|    782|  return scalar::utf8_to_utf16::convert_with_errors<endianness::LITTLE>(
  187|    782|      buf, len, utf16_output);
  188|    782|}
_ZNK7simdutf8fallback14implementation35convert_utf8_to_utf16be_with_errorsEPKcmPDs:
  191|    902|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  192|    902|  return scalar::utf8_to_utf16::convert_with_errors<endianness::BIG>(
  193|    902|      buf, len, utf16_output);
  194|    902|}
_ZNK7simdutf8fallback14implementation29convert_valid_utf8_to_utf16leEPKcmPDs:
  197|    344|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  198|    344|  return scalar::utf8_to_utf16::convert_valid<endianness::LITTLE>(buf, len,
  199|    344|                                                                  utf16_output);
  200|    344|}
_ZNK7simdutf8fallback14implementation29convert_valid_utf8_to_utf16beEPKcmPDs:
  203|    456|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  204|    456|  return scalar::utf8_to_utf16::convert_valid<endianness::BIG>(buf, len,
  205|    456|                                                               utf16_output);
  206|    456|}
_ZNK7simdutf8fallback14implementation21convert_utf8_to_utf32EPKcmPDi:
  211|    950|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  212|    950|  return scalar::utf8_to_utf32::convert(buf, len, utf32_output);
  213|    950|}
_ZNK7simdutf8fallback14implementation33convert_utf8_to_utf32_with_errorsEPKcmPDi:
  216|    918|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  217|    918|  return scalar::utf8_to_utf32::convert_with_errors(buf, len, utf32_output);
  218|    918|}
_ZNK7simdutf8fallback14implementation27convert_valid_utf8_to_utf32EPKcmPDi:
  221|    512|    const char *input, size_t size, char32_t *utf32_output) const noexcept {
  222|    512|  return scalar::utf8_to_utf32::convert_valid(input, size, utf32_output);
  223|    512|}
_ZNK7simdutf8fallback14implementation25convert_utf16le_to_latin1EPKDsmPc:
  228|    134|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  229|    134|  return scalar::utf16_to_latin1::convert<endianness::LITTLE>(buf, len,
  230|    134|                                                              latin1_output);
  231|    134|}
_ZNK7simdutf8fallback14implementation25convert_utf16be_to_latin1EPKDsmPc:
  234|    116|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  235|    116|  return scalar::utf16_to_latin1::convert<endianness::BIG>(buf, len,
  236|    116|                                                           latin1_output);
  237|    116|}
_ZNK7simdutf8fallback14implementation37convert_utf16le_to_latin1_with_errorsEPKDsmPc:
  241|    264|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  242|    264|  return scalar::utf16_to_latin1::convert_with_errors<endianness::LITTLE>(
  243|    264|      buf, len, latin1_output);
  244|    264|}
_ZNK7simdutf8fallback14implementation37convert_utf16be_to_latin1_with_errorsEPKDsmPc:
  248|    248|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  249|    248|  return scalar::utf16_to_latin1::convert_with_errors<endianness::BIG>(
  250|    248|      buf, len, latin1_output);
  251|    248|}
_ZNK7simdutf8fallback14implementation23convert_utf16le_to_utf8EPKDsmPc:
  268|    506|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  269|    506|  return scalar::utf16_to_utf8::convert<endianness::LITTLE>(buf, len,
  270|    506|                                                            utf8_output);
  271|    506|}
_ZNK7simdutf8fallback14implementation23convert_utf16be_to_utf8EPKDsmPc:
  274|    394|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  275|    394|  return scalar::utf16_to_utf8::convert<endianness::BIG>(buf, len, utf8_output);
  276|    394|}
_ZNK7simdutf8fallback14implementation35convert_utf16le_to_utf8_with_errorsEPKDsmPc:
  279|    712|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  280|    712|  return scalar::utf16_to_utf8::convert_with_errors<endianness::LITTLE>(
  281|    712|      buf, len, utf8_output);
  282|    712|}
_ZNK7simdutf8fallback14implementation35convert_utf16be_to_utf8_with_errorsEPKDsmPc:
  285|    616|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  286|    616|  return scalar::utf16_to_utf8::convert_with_errors<endianness::BIG>(
  287|    616|      buf, len, utf8_output);
  288|    616|}
_ZNK7simdutf8fallback14implementation29convert_valid_utf16le_to_utf8EPKDsmPc:
  291|    372|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  292|    372|  return scalar::utf16_to_utf8::convert_valid<endianness::LITTLE>(buf, len,
  293|    372|                                                                  utf8_output);
  294|    372|}
_ZNK7simdutf8fallback14implementation29convert_valid_utf16be_to_utf8EPKDsmPc:
  297|    416|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  298|    416|  return scalar::utf16_to_utf8::convert_valid<endianness::BIG>(buf, len,
  299|    416|                                                               utf8_output);
  300|    416|}
_ZNK7simdutf8fallback14implementation23convert_utf32_to_latin1EPKDimPc:
  305|    186|    const char32_t *buf, size_t len, char *latin1_output) const noexcept {
  306|    186|  return scalar::utf32_to_latin1::convert(buf, len, latin1_output);
  307|    186|}
_ZNK7simdutf8fallback14implementation35convert_utf32_to_latin1_with_errorsEPKDimPc:
  310|    488|    const char32_t *buf, size_t len, char *latin1_output) const noexcept {
  311|    488|  return scalar::utf32_to_latin1::convert_with_errors(buf, len, latin1_output);
  312|    488|}
_ZNK7simdutf8fallback14implementation21convert_utf32_to_utf8EPKDimPc:
  322|    714|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  323|    714|  return scalar::utf32_to_utf8::convert(buf, len, utf8_output);
  324|    714|}
_ZNK7simdutf8fallback14implementation33convert_utf32_to_utf8_with_errorsEPKDimPc:
  327|    860|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  328|    860|  return scalar::utf32_to_utf8::convert_with_errors(buf, len, utf8_output);
  329|    860|}
_ZNK7simdutf8fallback14implementation27convert_valid_utf32_to_utf8EPKDimPc:
  332|    194|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  333|    194|  return scalar::utf32_to_utf8::convert_valid(buf, len, utf8_output);
  334|    194|}
_ZNK7simdutf8fallback14implementation24convert_utf32_to_utf16leEPKDimPDs:
  339|    502|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
  340|    502|  return scalar::utf32_to_utf16::convert<endianness::LITTLE>(buf, len,
  341|    502|                                                             utf16_output);
  342|    502|}
_ZNK7simdutf8fallback14implementation24convert_utf32_to_utf16beEPKDimPDs:
  345|    516|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
  346|    516|  return scalar::utf32_to_utf16::convert<endianness::BIG>(buf, len,
  347|    516|                                                          utf16_output);
  348|    516|}
_ZNK7simdutf8fallback14implementation36convert_utf32_to_utf16le_with_errorsEPKDimPDs:
  351|    772|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
  352|    772|  return scalar::utf32_to_utf16::convert_with_errors<endianness::LITTLE>(
  353|    772|      buf, len, utf16_output);
  354|    772|}
_ZNK7simdutf8fallback14implementation36convert_utf32_to_utf16be_with_errorsEPKDimPDs:
  357|    678|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
  358|    678|  return scalar::utf32_to_utf16::convert_with_errors<endianness::BIG>(
  359|    678|      buf, len, utf16_output);
  360|    678|}
_ZNK7simdutf8fallback14implementation30convert_valid_utf32_to_utf16leEPKDimPDs:
  363|    292|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
  364|    292|  return scalar::utf32_to_utf16::convert_valid<endianness::LITTLE>(
  365|    292|      buf, len, utf16_output);
  366|    292|}
_ZNK7simdutf8fallback14implementation30convert_valid_utf32_to_utf16beEPKDimPDs:
  369|    136|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
  370|    136|  return scalar::utf32_to_utf16::convert_valid<endianness::BIG>(buf, len,
  371|    136|                                                                utf16_output);
  372|    136|}
_ZNK7simdutf8fallback14implementation24convert_utf16le_to_utf32EPKDsmPDi:
  375|    308|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  376|    308|  return scalar::utf16_to_utf32::convert<endianness::LITTLE>(buf, len,
  377|    308|                                                             utf32_output);
  378|    308|}
_ZNK7simdutf8fallback14implementation24convert_utf16be_to_utf32EPKDsmPDi:
  381|    302|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  382|    302|  return scalar::utf16_to_utf32::convert<endianness::BIG>(buf, len,
  383|    302|                                                          utf32_output);
  384|    302|}
_ZNK7simdutf8fallback14implementation36convert_utf16le_to_utf32_with_errorsEPKDsmPDi:
  387|    386|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  388|    386|  return scalar::utf16_to_utf32::convert_with_errors<endianness::LITTLE>(
  389|    386|      buf, len, utf32_output);
  390|    386|}
_ZNK7simdutf8fallback14implementation36convert_utf16be_to_utf32_with_errorsEPKDsmPDi:
  393|    366|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  394|    366|  return scalar::utf16_to_utf32::convert_with_errors<endianness::BIG>(
  395|    366|      buf, len, utf32_output);
  396|    366|}
_ZNK7simdutf8fallback14implementation30convert_valid_utf16le_to_utf32EPKDsmPDi:
  399|    118|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  400|    118|  return scalar::utf16_to_utf32::convert_valid<endianness::LITTLE>(
  401|    118|      buf, len, utf32_output);
  402|    118|}
_ZNK7simdutf8fallback14implementation30convert_valid_utf16be_to_utf32EPKDsmPDi:
  405|    134|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  406|    134|  return scalar::utf16_to_utf32::convert_valid<endianness::BIG>(buf, len,
  407|    134|                                                                utf32_output);
  408|    134|}
_ZNK7simdutf8fallback14implementation13count_utf16leEPKDsm:
  419|  1.42k|    const char16_t *input, size_t length) const noexcept {
  420|  1.42k|  return scalar::utf16::count_code_points<endianness::LITTLE>(input, length);
  421|  1.42k|}
_ZNK7simdutf8fallback14implementation13count_utf16beEPKDsm:
  424|  1.33k|    const char16_t *input, size_t length) const noexcept {
  425|  1.33k|  return scalar::utf16::count_code_points<endianness::BIG>(input, length);
  426|  1.33k|}
_ZNK7simdutf8fallback14implementation10count_utf8EPKcm:
  431|  4.11k|implementation::count_utf8(const char *input, size_t length) const noexcept {
  432|  4.11k|  return scalar::utf8::count_code_points(input, length);
  433|  4.11k|}
_ZNK7simdutf8fallback14implementation23latin1_length_from_utf8EPKcm:
  443|    693|    const char *buf, size_t len) const noexcept {
  444|    693|  return scalar::utf8::count_code_points(buf, len);
  445|    693|}
_ZNK7simdutf8fallback14implementation23utf8_length_from_latin1EPKcm:
  450|    243|    const char *input, size_t length) const noexcept {
  451|    243|  return scalar::latin1_to_utf8::utf8_length_from_latin1(input, length);
  452|    243|}
_ZNK7simdutf8fallback14implementation24utf8_length_from_utf16leEPKDsm:
  457|    808|    const char16_t *input, size_t length) const noexcept {
  458|    808|  return scalar::utf16::utf8_length_from_utf16<endianness::LITTLE>(input,
  459|    808|                                                                   length);
  460|    808|}
_ZNK7simdutf8fallback14implementation24utf8_length_from_utf16beEPKDsm:
  463|    732|    const char16_t *input, size_t length) const noexcept {
  464|    732|  return scalar::utf16::utf8_length_from_utf16<endianness::BIG>(input, length);
  465|    732|}
_ZNK7simdutf8fallback14implementation25utf32_length_from_utf16leEPKDsm:
  470|    413|    const char16_t *input, size_t length) const noexcept {
  471|    413|  return scalar::utf16::utf32_length_from_utf16<endianness::LITTLE>(input,
  472|    413|                                                                    length);
  473|    413|}
_ZNK7simdutf8fallback14implementation25utf32_length_from_utf16beEPKDsm:
  476|    420|    const char16_t *input, size_t length) const noexcept {
  477|    420|  return scalar::utf16::utf32_length_from_utf16<endianness::BIG>(input, length);
  478|    420|}
_ZNK7simdutf8fallback14implementation22utf16_length_from_utf8EPKcm:
  483|  2.22k|    const char *input, size_t length) const noexcept {
  484|  2.22k|  return scalar::utf8::utf16_length_from_utf8(input, length);
  485|  2.22k|}
_ZNK7simdutf8fallback14implementation22utf8_length_from_utf32EPKDim:
  518|    892|    const char32_t *input, size_t length) const noexcept {
  519|    892|  return scalar::utf32::utf8_length_from_utf32(input, length);
  520|    892|}
_ZNK7simdutf8fallback14implementation23utf16_length_from_utf32EPKDim:
  525|  1.45k|    const char32_t *input, size_t length) const noexcept {
  526|  1.45k|  return scalar::utf32::utf16_length_from_utf32(input, length);
  527|  1.45k|}
_ZNK7simdutf8fallback14implementation22utf32_length_from_utf8EPKcm:
  532|  1.20k|    const char *input, size_t length) const noexcept {
  533|  1.20k|  return scalar::utf8::count_code_points(input, length);
  534|  1.20k|}

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1617count_code_pointsILNS_10endiannessE0EEEmPKDsm:
    8|  1.83k|                                               size_t size) {
    9|  1.83k|  size_t pos = 0;
   10|  1.83k|  size_t count = 0;
   11|   980k|  for (; pos < size / 32 * 32; pos += 32) {
  ------------------
  |  Branch (11:10): [True: 978k, False: 1.83k]
  ------------------
   12|   978k|    simd16x32<uint16_t> input(reinterpret_cast<const uint16_t *>(in + pos));
   13|       |    if constexpr (!match_system(big_endian)) {
   14|       |      input.swap_bytes();
   15|       |    }
   16|   978k|    uint64_t not_pair = input.not_in_range(0xDC00, 0xDFFF);
   17|   978k|    count += count_ones(not_pair) / 2;
   18|   978k|  }
   19|  1.83k|  return count +
   20|  1.83k|         scalar::utf16::count_code_points<big_endian>(in + pos, size - pos);
   21|  1.83k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1617count_code_pointsILNS_10endiannessE1EEEmPKDsm:
    8|  1.75k|                                               size_t size) {
    9|  1.75k|  size_t pos = 0;
   10|  1.75k|  size_t count = 0;
   11|  1.08M|  for (; pos < size / 32 * 32; pos += 32) {
  ------------------
  |  Branch (11:10): [True: 1.07M, False: 1.75k]
  ------------------
   12|  1.07M|    simd16x32<uint16_t> input(reinterpret_cast<const uint16_t *>(in + pos));
   13|  1.07M|    if constexpr (!match_system(big_endian)) {
   14|  1.07M|      input.swap_bytes();
   15|  1.07M|    }
   16|  1.07M|    uint64_t not_pair = input.not_in_range(0xDC00, 0xDFFF);
   17|  1.07M|    count += count_ones(not_pair) / 2;
   18|  1.07M|  }
   19|  1.75k|  return count +
   20|  1.75k|         scalar::utf16::count_code_points<big_endian>(in + pos, size - pos);
   21|  1.75k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1623utf32_length_from_utf16ILNS_10endiannessE0EEEmPKDsm:
   51|    413|                                                     size_t size) {
   52|    413|  return count_code_points<big_endian>(in, size);
   53|    413|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1623utf32_length_from_utf16ILNS_10endiannessE1EEEmPKDsm:
   51|    420|                                                     size_t size) {
   52|    420|  return count_code_points<big_endian>(in, size);
   53|    420|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1617count_code_pointsILNS_10endiannessE0EEEmPKDsm:
    8|  1.83k|                                               size_t size) {
    9|  1.83k|  size_t pos = 0;
   10|  1.83k|  size_t count = 0;
   11|   980k|  for (; pos < size / 32 * 32; pos += 32) {
  ------------------
  |  Branch (11:10): [True: 978k, False: 1.83k]
  ------------------
   12|   978k|    simd16x32<uint16_t> input(reinterpret_cast<const uint16_t *>(in + pos));
   13|       |    if constexpr (!match_system(big_endian)) {
   14|       |      input.swap_bytes();
   15|       |    }
   16|   978k|    uint64_t not_pair = input.not_in_range(0xDC00, 0xDFFF);
   17|   978k|    count += count_ones(not_pair) / 2;
   18|   978k|  }
   19|  1.83k|  return count +
   20|  1.83k|         scalar::utf16::count_code_points<big_endian>(in + pos, size - pos);
   21|  1.83k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1617count_code_pointsILNS_10endiannessE1EEEmPKDsm:
    8|  1.75k|                                               size_t size) {
    9|  1.75k|  size_t pos = 0;
   10|  1.75k|  size_t count = 0;
   11|  1.08M|  for (; pos < size / 32 * 32; pos += 32) {
  ------------------
  |  Branch (11:10): [True: 1.07M, False: 1.75k]
  ------------------
   12|  1.07M|    simd16x32<uint16_t> input(reinterpret_cast<const uint16_t *>(in + pos));
   13|  1.07M|    if constexpr (!match_system(big_endian)) {
   14|  1.07M|      input.swap_bytes();
   15|  1.07M|    }
   16|  1.07M|    uint64_t not_pair = input.not_in_range(0xDC00, 0xDFFF);
   17|  1.07M|    count += count_ones(not_pair) / 2;
   18|  1.07M|  }
   19|  1.75k|  return count +
   20|  1.75k|         scalar::utf16::count_code_points<big_endian>(in + pos, size - pos);
   21|  1.75k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1623utf32_length_from_utf16ILNS_10endiannessE0EEEmPKDsm:
   51|    413|                                                     size_t size) {
   52|    413|  return count_code_points<big_endian>(in, size);
   53|    413|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1623utf32_length_from_utf16ILNS_10endiannessE1EEEmPKDsm:
   51|    420|                                                     size_t size) {
   52|    420|  return count_code_points<big_endian>(in, size);
   53|    420|}

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf3222utf8_length_from_utf32EPKDim:
   11|    892|                                                    size_t length) {
   12|    892|  using vector_u32 = simd32<uint32_t>;
   13|       |
   14|    892|  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|    892|  const size_t max_increment = 3;
   19|       |
   20|    892|  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|    892|  const auto v_ffffff80 = vector_u32::splat(0xffffff80);
   28|    892|  const auto v_fffff800 = vector_u32::splat(0xfffff800);
   29|    892|  const auto v_ffff0000 = vector_u32::splat(0xffff0000);
   30|    892|  const auto one = vector_u32::splat(1);
   31|    892|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   32|       |
   33|    892|  size_t counter = 0;
   34|       |
   35|       |  // 1. vectorized loop unrolled 4 times
   36|    892|  {
   37|       |    // we use vector of uint32 counters, this is why this limit is used
   38|    892|    const size_t max_iterations =
   39|    892|        std::numeric_limits<uint32_t>::max() / (max_increment * 4);
   40|    892|    size_t blocks = length / (N * 4);
   41|    892|    length -= blocks * (N * 4);
   42|  1.09k|    while (blocks != 0) {
  ------------------
  |  Branch (42:12): [True: 205, False: 892]
  ------------------
   43|    205|      const size_t iterations = min(blocks, max_iterations);
   44|    205|      blocks -= iterations;
   45|       |
   46|    205|      simd32<uint32_t> acc = vector_u32::zero();
   47|  74.7k|      for (size_t i = 0; i < iterations; i++) {
  ------------------
  |  Branch (47:26): [True: 74.5k, False: 205]
  ------------------
   48|  74.5k|        const auto in0 = vector_u32(input + 0 * N);
   49|  74.5k|        const auto in1 = vector_u32(input + 1 * N);
   50|  74.5k|        const auto in2 = vector_u32(input + 2 * N);
   51|  74.5k|        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|  74.5k|        acc += min(one, in0 & v_ffffff80);
   70|  74.5k|        acc += min(one, in1 & v_ffffff80);
   71|  74.5k|        acc += min(one, in2 & v_ffffff80);
   72|  74.5k|        acc += min(one, in3 & v_ffffff80);
   73|       |
   74|  74.5k|        acc += min(one, in0 & v_fffff800);
   75|  74.5k|        acc += min(one, in1 & v_fffff800);
   76|  74.5k|        acc += min(one, in2 & v_fffff800);
   77|  74.5k|        acc += min(one, in3 & v_fffff800);
   78|       |
   79|  74.5k|        acc += min(one, in0 & v_ffff0000);
   80|  74.5k|        acc += min(one, in1 & v_ffff0000);
   81|  74.5k|        acc += min(one, in2 & v_ffff0000);
   82|  74.5k|        acc += min(one, in3 & v_ffff0000);
   83|  74.5k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   84|       |
   85|  74.5k|        input += 4 * N;
   86|  74.5k|      }
   87|       |
   88|    205|      counter += acc.sum();
   89|    205|    }
   90|    892|  }
   91|       |
   92|       |  // 2. vectorized loop for tail
   93|    892|  {
   94|    892|    const size_t max_iterations =
   95|    892|        std::numeric_limits<uint32_t>::max() / max_increment;
   96|    892|    size_t blocks = length / N;
   97|    892|    length -= blocks * N;
   98|  1.32k|    while (blocks != 0) {
  ------------------
  |  Branch (98:12): [True: 435, False: 892]
  ------------------
   99|    435|      const size_t iterations = min(blocks, max_iterations);
  100|    435|      blocks -= iterations;
  101|       |
  102|    435|      auto acc = vector_u32::zero();
  103|  1.52k|      for (size_t i = 0; i < iterations; i++) {
  ------------------
  |  Branch (103:26): [True: 1.08k, False: 435]
  ------------------
  104|  1.08k|        const auto in = vector_u32(input);
  105|       |
  106|       |#if SIMDUTF_SIMD_HAS_UNSIGNED_CMP
  107|       |        acc -= as_vector_u32(in > v_0000007f);
  108|       |        acc -= as_vector_u32(in > v_000007ff);
  109|       |        acc -= as_vector_u32(in > v_0000ffff);
  110|       |#else
  111|  1.08k|        acc += min(one, in & v_ffffff80);
  112|  1.08k|        acc += min(one, in & v_fffff800);
  113|  1.08k|        acc += min(one, in & v_ffff0000);
  114|  1.08k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
  115|       |
  116|  1.08k|        input += N;
  117|  1.08k|      }
  118|       |
  119|    435|      counter += acc.sum();
  120|    435|    }
  121|    892|  }
  122|       |
  123|    892|  const size_t consumed = input - start;
  124|    892|  if (consumed != 0) {
  ------------------
  |  Branch (124:7): [True: 495, False: 397]
  ------------------
  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|    495|    counter += consumed;
  128|    495|  }
  129|       |
  130|    892|  return counter + scalar::utf32::utf8_length_from_utf32(input, length);
  131|    892|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf323minImEET_S4_S4_:
    8|    640|template <typename T> T min(T a, T b) { return a <= b ? a : b; }
  ------------------
  |  Branch (8:48): [True: 640, False: 0]
  ------------------
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf3222utf8_length_from_utf32EPKDim:
   11|    892|                                                    size_t length) {
   12|    892|  using vector_u32 = simd32<uint32_t>;
   13|       |
   14|    892|  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|    892|  const size_t max_increment = 3;
   19|       |
   20|    892|  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|    892|  const auto v_ffffff80 = vector_u32::splat(0xffffff80);
   28|    892|  const auto v_fffff800 = vector_u32::splat(0xfffff800);
   29|    892|  const auto v_ffff0000 = vector_u32::splat(0xffff0000);
   30|    892|  const auto one = vector_u32::splat(1);
   31|    892|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   32|       |
   33|    892|  size_t counter = 0;
   34|       |
   35|       |  // 1. vectorized loop unrolled 4 times
   36|    892|  {
   37|       |    // we use vector of uint32 counters, this is why this limit is used
   38|    892|    const size_t max_iterations =
   39|    892|        std::numeric_limits<uint32_t>::max() / (max_increment * 4);
   40|    892|    size_t blocks = length / (N * 4);
   41|    892|    length -= blocks * (N * 4);
   42|  1.36k|    while (blocks != 0) {
  ------------------
  |  Branch (42:12): [True: 476, False: 892]
  ------------------
   43|    476|      const size_t iterations = min(blocks, max_iterations);
   44|    476|      blocks -= iterations;
   45|       |
   46|    476|      simd32<uint32_t> acc = vector_u32::zero();
   47|   149k|      for (size_t i = 0; i < iterations; i++) {
  ------------------
  |  Branch (47:26): [True: 149k, False: 476]
  ------------------
   48|   149k|        const auto in0 = vector_u32(input + 0 * N);
   49|   149k|        const auto in1 = vector_u32(input + 1 * N);
   50|   149k|        const auto in2 = vector_u32(input + 2 * N);
   51|   149k|        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|   149k|        acc += min(one, in0 & v_ffffff80);
   70|   149k|        acc += min(one, in1 & v_ffffff80);
   71|   149k|        acc += min(one, in2 & v_ffffff80);
   72|   149k|        acc += min(one, in3 & v_ffffff80);
   73|       |
   74|   149k|        acc += min(one, in0 & v_fffff800);
   75|   149k|        acc += min(one, in1 & v_fffff800);
   76|   149k|        acc += min(one, in2 & v_fffff800);
   77|   149k|        acc += min(one, in3 & v_fffff800);
   78|       |
   79|   149k|        acc += min(one, in0 & v_ffff0000);
   80|   149k|        acc += min(one, in1 & v_ffff0000);
   81|   149k|        acc += min(one, in2 & v_ffff0000);
   82|   149k|        acc += min(one, in3 & v_ffff0000);
   83|   149k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
   84|       |
   85|   149k|        input += 4 * N;
   86|   149k|      }
   87|       |
   88|    476|      counter += acc.sum();
   89|    476|    }
   90|    892|  }
   91|       |
   92|       |  // 2. vectorized loop for tail
   93|    892|  {
   94|    892|    const size_t max_iterations =
   95|    892|        std::numeric_limits<uint32_t>::max() / max_increment;
   96|    892|    size_t blocks = length / N;
   97|    892|    length -= blocks * N;
   98|  1.38k|    while (blocks != 0) {
  ------------------
  |  Branch (98:12): [True: 496, False: 892]
  ------------------
   99|    496|      const size_t iterations = min(blocks, max_iterations);
  100|    496|      blocks -= iterations;
  101|       |
  102|    496|      auto acc = vector_u32::zero();
  103|  1.70k|      for (size_t i = 0; i < iterations; i++) {
  ------------------
  |  Branch (103:26): [True: 1.20k, False: 496]
  ------------------
  104|  1.20k|        const auto in = vector_u32(input);
  105|       |
  106|       |#if SIMDUTF_SIMD_HAS_UNSIGNED_CMP
  107|       |        acc -= as_vector_u32(in > v_0000007f);
  108|       |        acc -= as_vector_u32(in > v_000007ff);
  109|       |        acc -= as_vector_u32(in > v_0000ffff);
  110|       |#else
  111|  1.20k|        acc += min(one, in & v_ffffff80);
  112|  1.20k|        acc += min(one, in & v_fffff800);
  113|  1.20k|        acc += min(one, in & v_ffff0000);
  114|  1.20k|#endif // SIMDUTF_SIMD_HAS_UNSIGNED_CMP
  115|       |
  116|  1.20k|        input += N;
  117|  1.20k|      }
  118|       |
  119|    496|      counter += acc.sum();
  120|    496|    }
  121|    892|  }
  122|       |
  123|    892|  const size_t consumed = input - start;
  124|    892|  if (consumed != 0) {
  ------------------
  |  Branch (124:7): [True: 544, False: 348]
  ------------------
  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|    544|    counter += consumed;
  128|    544|  }
  129|       |
  130|    892|  return counter + scalar::utf32::utf8_length_from_utf32(input, length);
  131|    892|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf323minImEET_S4_S4_:
    8|    972|template <typename T> T min(T a, T b) { return a <= b ? a : b; }
  ------------------
  |  Branch (8:48): [True: 972, False: 0]
  ------------------

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

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoderC2Ev:
  101|  1.38k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoder7convertEPKcmPc:
  147|    716|                                       char *latin1_output) {
  148|    716|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (148:9): [True: 172, False: 544]
  ------------------
  149|    172|      return scalar::utf8_to_latin1::convert(in, size, latin1_output);
  150|    172|    }
  151|    544|    size_t pos = 0;
  152|    544|    char *start{latin1_output};
  153|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  154|       |    // of 8 bytes when calling convert_masked_utf8_to_latin1. If you skip the
  155|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  156|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  157|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  158|       |    // back from the end counting 16 leading bytes, to give us a good margin.
  159|    544|    size_t leading_byte = 0;
  160|    544|    size_t margin = size;
  161|  12.1k|    for (; margin > 0 && leading_byte < 16; margin--) {
  ------------------
  |  Branch (161:12): [True: 12.1k, False: 14]
  |  Branch (161:26): [True: 11.6k, False: 530]
  ------------------
  162|  11.6k|      leading_byte += (int8_t(in[margin - 1]) >
  163|  11.6k|                       -65); // twos complement of -65 is 1011 1111 ...
  164|  11.6k|    }
  165|       |    // If the input is long enough, then we have that margin-1 is the eight last
  166|       |    // leading byte.
  167|    544|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  168|   608k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (168:12): [True: 608k, False: 508]
  ------------------
  169|   608k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  170|   608k|      if (input.is_ascii()) {
  ------------------
  |  Branch (170:11): [True: 571k, False: 36.7k]
  ------------------
  171|   571k|        input.store((int8_t *)latin1_output);
  172|   571k|        latin1_output += 64;
  173|   571k|        pos += 64;
  174|   571k|      } else {
  175|       |        // you might think that a for-loop would work, but under Visual Studio,
  176|       |        // it is not good enough.
  177|  36.7k|        static_assert(
  178|  36.7k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  179|  36.7k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  180|  36.7k|            "We support either two or four chunks per 64-byte block.");
  181|  36.7k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  182|  36.7k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  183|  36.7k|          this->check_utf8_bytes(input.chunks[0], zero);
  184|  36.7k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  185|       |        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  186|       |          this->check_utf8_bytes(input.chunks[0], zero);
  187|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  188|       |          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  189|       |          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  190|       |        }
  191|  36.7k|        uint64_t utf8_continuation_mask =
  192|  36.7k|            input.lt(-65 + 1); // -64 is 1100 0000 in twos complement. Note: in
  193|       |                               // this case, we also have ASCII to account for.
  194|  36.7k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (194:13): [True: 36, False: 36.7k]
  ------------------
  195|     36|          return 0; // error
  196|     36|        }
  197|  36.7k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  198|  36.7k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  199|       |        // We process in blocks of up to 12 bytes except possibly
  200|       |        // for fast paths which may process up to 16 bytes. For the
  201|       |        // slow path to work, we should have at least 12 input bytes left.
  202|  36.7k|        size_t max_starting_point = (pos + 64) - 12;
  203|       |        // Next loop is going to run at least five times.
  204|   364k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (204:16): [True: 327k, False: 36.7k]
  ------------------
  205|       |          // Performance note: our ability to compute 'consumed' and
  206|       |          // then shift and recompute is critical. If there is a
  207|       |          // latency of, say, 4 cycles on getting 'consumed', then
  208|       |          // the inner loop might have a total latency of about 6 cycles.
  209|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  210|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  211|       |          // for this section of the code. Hence, there is a limit
  212|       |          // to how much we can further increase this latency before
  213|       |          // it seriously harms performance.
  214|   327k|          size_t consumed = convert_masked_utf8_to_latin1(
  215|   327k|              in + pos, utf8_end_of_code_point_mask, latin1_output);
  216|   327k|          pos += consumed;
  217|   327k|          utf8_end_of_code_point_mask >>= consumed;
  218|   327k|        }
  219|       |        // At this point there may remain between 0 and 12 bytes in the
  220|       |        // 64-byte block. These bytes will be processed again. So we have an
  221|       |        // 80% efficiency (in the worst case). In practice we expect an
  222|       |        // 85% to 90% efficiency.
  223|  36.7k|      }
  224|   608k|    }
  225|    508|    if (errors()) {
  ------------------
  |  Branch (225:9): [True: 212, False: 296]
  ------------------
  226|    212|      return 0;
  227|    212|    }
  228|    296|    const size_t ascii = convert_ascii_tail(in, pos, size, latin1_output);
  229|    296|    pos += ascii;
  230|    296|    latin1_output += ascii;
  231|    296|    if (pos == size) {
  ------------------
  |  Branch (231:9): [True: 96, False: 200]
  ------------------
  232|     96|      return latin1_output - start;
  233|     96|    }
  234|    200|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|    200|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
  235|    200|    size_t howmany =
  236|    200|        scalar::utf8_to_latin1::convert(in + pos, size - pos, latin1_output);
  237|    200|    if (howmany == 0) {
  ------------------
  |  Branch (237:9): [True: 166, False: 34]
  ------------------
  238|    166|      return 0;
  239|    166|    }
  240|     34|    return latin1_output + howmany - start;
  241|    200|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  106|   114k|                                              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|   114k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  111|   114k|    this->error |= check_special_cases(input, prev1);
  112|   114k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin119check_special_casesENS1_4simd5simd8IhEES5_:
    8|   114k|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|   114k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   20|       |                                               // 11______ 11______
   21|   114k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   22|   114k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   23|   114k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   24|   114k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   25|   114k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   26|   114k|  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|   114k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   35|       |  // 11110101 1000____
   36|       |  // 1111011_ 1000____
   37|       |  // 11111___ 1000____
   38|   114k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   39|   114k|  constexpr const uint8_t FORBIDDEN = 0xff;
   40|       |
   41|   114k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   42|       |      // 0_______ ________ <ASCII in byte 1>
   43|   114k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   44|   114k|      TOO_LONG,
   45|       |      // 10______ ________ <continuation in byte 1>
   46|   114k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   47|       |      // 1100____ ________ <two byte lead in byte 1>
   48|   114k|      TOO_SHORT | OVERLONG_2,
   49|       |      // 1101____ ________ <two byte lead in byte 1>
   50|   114k|      FORBIDDEN,
   51|       |      // 1110____ ________ <three byte lead in byte 1>
   52|   114k|      FORBIDDEN,
   53|       |      // 1111____ ________ <four+ byte lead in byte 1>
   54|   114k|      FORBIDDEN);
   55|   114k|  constexpr const uint8_t CARRY =
   56|   114k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   57|   114k|  const simd8<uint8_t> byte_1_low =
   58|   114k|      (prev1 & 0x0F)
   59|   114k|          .lookup_16<uint8_t>(
   60|       |              // ____0000 ________
   61|   114k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   62|       |              // ____0001 ________
   63|   114k|              CARRY | OVERLONG_2,
   64|       |              // ____001_ ________
   65|   114k|              CARRY, CARRY,
   66|       |
   67|       |              // ____0100 ________
   68|   114k|              FORBIDDEN,
   69|       |              // ____0101 ________
   70|   114k|              FORBIDDEN,
   71|       |              // ____011_ ________
   72|   114k|              FORBIDDEN, FORBIDDEN,
   73|       |
   74|       |              // ____1___ ________
   75|   114k|              FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
   76|       |              // ____1101 ________
   77|   114k|              FORBIDDEN, FORBIDDEN, FORBIDDEN);
   78|   114k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   79|       |      // ________ 0_______ <ASCII in byte 2>
   80|   114k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   81|   114k|      TOO_SHORT, TOO_SHORT,
   82|       |
   83|       |      // ________ 1000____
   84|   114k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   85|   114k|          OVERLONG_4,
   86|       |      // ________ 1001____
   87|   114k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   88|       |      // ________ 101_____
   89|   114k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   90|   114k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   91|       |
   92|       |      // ________ 11______
   93|   114k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   94|   114k|  return (byte_1_high & byte_1_low & byte_2_high);
   95|   114k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoder6errorsEv:
  348|  20.8k|  simdutf_really_inline bool errors() const {
  349|  20.8k|    return this->error.any_bits_set_anywhere();
  350|  20.8k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoder18convert_ascii_tailEPKcmmPc:
  115|    650|                                                  size_t size, char *output) {
  116|       |    // A cheap test on the first bytes avoids any SIMD work for most non-ASCII
  117|       |    // tails.
  118|    650|    if (size - pos >= 8) {
  ------------------
  |  Branch (118:9): [True: 650, False: 0]
  ------------------
  119|    650|      uint64_t first_bytes;
  120|    650|      std::memcpy(&first_bytes, in + pos, 8);
  121|    650|      if (first_bytes & 0x8080808080808080) {
  ------------------
  |  Branch (121:11): [True: 140, False: 510]
  ------------------
  122|    140|        return 0;
  123|    140|      }
  124|    650|    }
  125|    510|    const size_t start = pos;
  126|    600|    while (pos + 64 <= size) {
  ------------------
  |  Branch (126:12): [True: 204, False: 396]
  ------------------
  127|    204|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  128|    204|      if (!input.is_ascii()) {
  ------------------
  |  Branch (128:11): [True: 114, False: 90]
  ------------------
  129|    114|        return pos - start;
  130|    114|      }
  131|     90|      input.store(reinterpret_cast<int8_t *>(output + (pos - start)));
  132|     90|      pos += 64;
  133|     90|    }
  134|    396|    if (pos == size || size < 64) {
  ------------------
  |  Branch (134:9): [True: 38, False: 358]
  |  Branch (134:24): [True: 0, False: 358]
  ------------------
  135|     38|      return pos - start;
  136|     38|    }
  137|    358|    simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + size - 64));
  138|    358|    if (!input.is_ascii()) {
  ------------------
  |  Branch (138:9): [True: 224, False: 134]
  ------------------
  139|    224|      return pos - start;
  140|    224|    }
  141|    134|    input.store(reinterpret_cast<int8_t *>(output + (pos - start) -
  142|    134|                                           (pos - (size - 64))));
  143|    134|    return size - start;
  144|    358|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_114utf8_to_latin121validating_transcoder19convert_with_errorsEPKcmPc:
  244|    670|                                                   char *latin1_output) {
  245|    670|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (245:9): [True: 170, False: 500]
  ------------------
  246|    170|      return scalar::utf8_to_latin1::convert_with_errors(in, size,
  247|    170|                                                         latin1_output);
  248|    170|    }
  249|    500|    size_t pos = 0;
  250|    500|    char *start{latin1_output};
  251|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  252|       |    // of 8 bytes when calling convert_masked_utf8_to_latin1. If you skip the
  253|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  254|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  255|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  256|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  257|    500|    size_t leading_byte = 0;
  258|    500|    size_t margin = size;
  259|  6.72k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (259:12): [True: 6.71k, False: 14]
  |  Branch (259:26): [True: 6.22k, False: 486]
  ------------------
  260|  6.22k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  261|  6.22k|    }
  262|       |    // If the input is long enough, then we have that margin-1 is the eight last
  263|       |    // leading byte.
  264|    500|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  265|   421k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (265:12): [True: 420k, False: 354]
  ------------------
  266|   420k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  267|   420k|      if (input.is_ascii()) {
  ------------------
  |  Branch (267:11): [True: 400k, False: 20.3k]
  ------------------
  268|   400k|        input.store((int8_t *)latin1_output);
  269|   400k|        latin1_output += 64;
  270|   400k|        pos += 64;
  271|   400k|      } else {
  272|       |        // you might think that a for-loop would work, but under Visual Studio,
  273|       |        // it is not good enough.
  274|  20.3k|        static_assert(
  275|  20.3k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  276|  20.3k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  277|  20.3k|            "We support either two or four chunks per 64-byte block.");
  278|  20.3k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  279|  20.3k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  280|  20.3k|          this->check_utf8_bytes(input.chunks[0], zero);
  281|  20.3k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  282|       |        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  283|       |          this->check_utf8_bytes(input.chunks[0], zero);
  284|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  285|       |          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  286|       |          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  287|       |        }
  288|  20.3k|        if (errors()) {
  ------------------
  |  Branch (288:13): [True: 146, False: 20.2k]
  ------------------
  289|       |          // rewind_and_convert_with_errors will seek a potential error from
  290|       |          // in+pos onward, with the ability to go back up to pos bytes, and
  291|       |          // read size-pos bytes forward.
  292|    146|          SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|    146|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
  293|    146|          result res = scalar::utf8_to_latin1::rewind_and_convert_with_errors(
  294|    146|              pos, in + pos, size - pos, latin1_output);
  295|    146|          res.count += pos;
  296|    146|          return res;
  297|    146|        }
  298|  20.2k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  299|  20.2k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  300|  20.2k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  301|       |        // We process in blocks of up to 12 bytes except possibly
  302|       |        // for fast paths which may process up to 16 bytes. For the
  303|       |        // slow path to work, we should have at least 12 input bytes left.
  304|  20.2k|        size_t max_starting_point = (pos + 64) - 12;
  305|       |        // Next loop is going to run at least five times.
  306|   201k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (306:16): [True: 181k, False: 20.2k]
  ------------------
  307|       |          // Performance note: our ability to compute 'consumed' and
  308|       |          // then shift and recompute is critical. If there is a
  309|       |          // latency of, say, 4 cycles on getting 'consumed', then
  310|       |          // the inner loop might have a total latency of about 6 cycles.
  311|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  312|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  313|       |          // for this section of the code. Hence, there is a limit
  314|       |          // to how much we can further increase this latency before
  315|       |          // it seriously harms performance.
  316|   181k|          size_t consumed = convert_masked_utf8_to_latin1(
  317|   181k|              in + pos, utf8_end_of_code_point_mask, latin1_output);
  318|   181k|          pos += consumed;
  319|   181k|          utf8_end_of_code_point_mask >>= consumed;
  320|   181k|        }
  321|       |        // At this point there may remain between 0 and 12 bytes in the
  322|       |        // 64-byte block. These bytes will be processed again. So we have an
  323|       |        // 80% efficiency (in the worst case). In practice we expect an
  324|       |        // 85% to 90% efficiency.
  325|  20.2k|      }
  326|   420k|    }
  327|    354|    const size_t ascii = convert_ascii_tail(in, pos, size, latin1_output);
  328|    354|    pos += ascii;
  329|    354|    latin1_output += ascii;
  330|    354|    if (pos == size) {
  ------------------
  |  Branch (330:9): [True: 76, False: 278]
  ------------------
  331|     76|      return result(error_code::SUCCESS, latin1_output - start);
  332|     76|    }
  333|       |    // rewind_and_convert_with_errors will seek a potential error from in+pos
  334|       |    // onward, with the ability to go back up to pos bytes, and read size-pos
  335|       |    // bytes forward.
  336|    278|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|    278|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
  337|    278|    result res = scalar::utf8_to_latin1::rewind_and_convert_with_errors(
  338|    278|        pos, in + pos, size - pos, latin1_output);
  339|    278|    if (res.error) { // In case of error, we want the error position
  ------------------
  |  Branch (339:9): [True: 174, False: 104]
  ------------------
  340|    174|      res.count += pos;
  341|    174|      return res;
  342|    174|    }
  343|       |    // In case of success, we want the number of words written
  344|    104|    latin1_output += res.count;
  345|    104|    return result(error_code::SUCCESS, latin1_output - start);
  346|    278|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoderC2Ev:
  101|  1.38k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoder7convertEPKcmPc:
  147|    716|                                       char *latin1_output) {
  148|    716|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (148:9): [True: 172, False: 544]
  ------------------
  149|    172|      return scalar::utf8_to_latin1::convert(in, size, latin1_output);
  150|    172|    }
  151|    544|    size_t pos = 0;
  152|    544|    char *start{latin1_output};
  153|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  154|       |    // of 8 bytes when calling convert_masked_utf8_to_latin1. If you skip the
  155|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  156|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  157|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  158|       |    // back from the end counting 16 leading bytes, to give us a good margin.
  159|    544|    size_t leading_byte = 0;
  160|    544|    size_t margin = size;
  161|  12.1k|    for (; margin > 0 && leading_byte < 16; margin--) {
  ------------------
  |  Branch (161:12): [True: 12.1k, False: 14]
  |  Branch (161:26): [True: 11.6k, False: 530]
  ------------------
  162|  11.6k|      leading_byte += (int8_t(in[margin - 1]) >
  163|  11.6k|                       -65); // twos complement of -65 is 1011 1111 ...
  164|  11.6k|    }
  165|       |    // If the input is long enough, then we have that margin-1 is the eight last
  166|       |    // leading byte.
  167|    544|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  168|   608k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (168:12): [True: 608k, False: 508]
  ------------------
  169|   608k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  170|   608k|      if (input.is_ascii()) {
  ------------------
  |  Branch (170:11): [True: 571k, False: 36.7k]
  ------------------
  171|   571k|        input.store((int8_t *)latin1_output);
  172|   571k|        latin1_output += 64;
  173|   571k|        pos += 64;
  174|   571k|      } else {
  175|       |        // you might think that a for-loop would work, but under Visual Studio,
  176|       |        // it is not good enough.
  177|  36.7k|        static_assert(
  178|  36.7k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  179|  36.7k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  180|  36.7k|            "We support either two or four chunks per 64-byte block.");
  181|  36.7k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  182|       |        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  183|       |          this->check_utf8_bytes(input.chunks[0], zero);
  184|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  185|  36.7k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  186|  36.7k|          this->check_utf8_bytes(input.chunks[0], zero);
  187|  36.7k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  188|  36.7k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  189|  36.7k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  190|  36.7k|        }
  191|  36.7k|        uint64_t utf8_continuation_mask =
  192|  36.7k|            input.lt(-65 + 1); // -64 is 1100 0000 in twos complement. Note: in
  193|       |                               // this case, we also have ASCII to account for.
  194|  36.7k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (194:13): [True: 36, False: 36.7k]
  ------------------
  195|     36|          return 0; // error
  196|     36|        }
  197|  36.7k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  198|  36.7k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  199|       |        // We process in blocks of up to 12 bytes except possibly
  200|       |        // for fast paths which may process up to 16 bytes. For the
  201|       |        // slow path to work, we should have at least 12 input bytes left.
  202|  36.7k|        size_t max_starting_point = (pos + 64) - 12;
  203|       |        // Next loop is going to run at least five times.
  204|   364k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (204:16): [True: 327k, False: 36.7k]
  ------------------
  205|       |          // Performance note: our ability to compute 'consumed' and
  206|       |          // then shift and recompute is critical. If there is a
  207|       |          // latency of, say, 4 cycles on getting 'consumed', then
  208|       |          // the inner loop might have a total latency of about 6 cycles.
  209|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  210|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  211|       |          // for this section of the code. Hence, there is a limit
  212|       |          // to how much we can further increase this latency before
  213|       |          // it seriously harms performance.
  214|   327k|          size_t consumed = convert_masked_utf8_to_latin1(
  215|   327k|              in + pos, utf8_end_of_code_point_mask, latin1_output);
  216|   327k|          pos += consumed;
  217|   327k|          utf8_end_of_code_point_mask >>= consumed;
  218|   327k|        }
  219|       |        // At this point there may remain between 0 and 12 bytes in the
  220|       |        // 64-byte block. These bytes will be processed again. So we have an
  221|       |        // 80% efficiency (in the worst case). In practice we expect an
  222|       |        // 85% to 90% efficiency.
  223|  36.7k|      }
  224|   608k|    }
  225|    508|    if (errors()) {
  ------------------
  |  Branch (225:9): [True: 212, False: 296]
  ------------------
  226|    212|      return 0;
  227|    212|    }
  228|    296|    const size_t ascii = convert_ascii_tail(in, pos, size, latin1_output);
  229|    296|    pos += ascii;
  230|    296|    latin1_output += ascii;
  231|    296|    if (pos == size) {
  ------------------
  |  Branch (231:9): [True: 96, False: 200]
  ------------------
  232|     96|      return latin1_output - start;
  233|     96|    }
  234|    200|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|    200|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
  235|    200|    size_t howmany =
  236|    200|        scalar::utf8_to_latin1::convert(in + pos, size - pos, latin1_output);
  237|    200|    if (howmany == 0) {
  ------------------
  |  Branch (237:9): [True: 166, False: 34]
  ------------------
  238|    166|      return 0;
  239|    166|    }
  240|     34|    return latin1_output + howmany - start;
  241|    200|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  106|   228k|                                              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|   228k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  111|   228k|    this->error |= check_special_cases(input, prev1);
  112|   228k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin119check_special_casesENS1_4simd5simd8IhEES5_:
    8|   228k|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|   228k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   20|       |                                               // 11______ 11______
   21|   228k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   22|   228k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   23|   228k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   24|   228k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   25|   228k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   26|   228k|  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|   228k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   35|       |  // 11110101 1000____
   36|       |  // 1111011_ 1000____
   37|       |  // 11111___ 1000____
   38|   228k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   39|   228k|  constexpr const uint8_t FORBIDDEN = 0xff;
   40|       |
   41|   228k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   42|       |      // 0_______ ________ <ASCII in byte 1>
   43|   228k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   44|   228k|      TOO_LONG,
   45|       |      // 10______ ________ <continuation in byte 1>
   46|   228k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   47|       |      // 1100____ ________ <two byte lead in byte 1>
   48|   228k|      TOO_SHORT | OVERLONG_2,
   49|       |      // 1101____ ________ <two byte lead in byte 1>
   50|   228k|      FORBIDDEN,
   51|       |      // 1110____ ________ <three byte lead in byte 1>
   52|   228k|      FORBIDDEN,
   53|       |      // 1111____ ________ <four+ byte lead in byte 1>
   54|   228k|      FORBIDDEN);
   55|   228k|  constexpr const uint8_t CARRY =
   56|   228k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   57|   228k|  const simd8<uint8_t> byte_1_low =
   58|   228k|      (prev1 & 0x0F)
   59|   228k|          .lookup_16<uint8_t>(
   60|       |              // ____0000 ________
   61|   228k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   62|       |              // ____0001 ________
   63|   228k|              CARRY | OVERLONG_2,
   64|       |              // ____001_ ________
   65|   228k|              CARRY, CARRY,
   66|       |
   67|       |              // ____0100 ________
   68|   228k|              FORBIDDEN,
   69|       |              // ____0101 ________
   70|   228k|              FORBIDDEN,
   71|       |              // ____011_ ________
   72|   228k|              FORBIDDEN, FORBIDDEN,
   73|       |
   74|       |              // ____1___ ________
   75|   228k|              FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
   76|       |              // ____1101 ________
   77|   228k|              FORBIDDEN, FORBIDDEN, FORBIDDEN);
   78|   228k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   79|       |      // ________ 0_______ <ASCII in byte 2>
   80|   228k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   81|   228k|      TOO_SHORT, TOO_SHORT,
   82|       |
   83|       |      // ________ 1000____
   84|   228k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   85|   228k|          OVERLONG_4,
   86|       |      // ________ 1001____
   87|   228k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   88|       |      // ________ 101_____
   89|   228k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   90|   228k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   91|       |
   92|       |      // ________ 11______
   93|   228k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   94|   228k|  return (byte_1_high & byte_1_low & byte_2_high);
   95|   228k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoder6errorsEv:
  348|  20.8k|  simdutf_really_inline bool errors() const {
  349|  20.8k|    return this->error.any_bits_set_anywhere();
  350|  20.8k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoder18convert_ascii_tailEPKcmmPc:
  115|    650|                                                  size_t size, char *output) {
  116|       |    // A cheap test on the first bytes avoids any SIMD work for most non-ASCII
  117|       |    // tails.
  118|    650|    if (size - pos >= 8) {
  ------------------
  |  Branch (118:9): [True: 650, False: 0]
  ------------------
  119|    650|      uint64_t first_bytes;
  120|    650|      std::memcpy(&first_bytes, in + pos, 8);
  121|    650|      if (first_bytes & 0x8080808080808080) {
  ------------------
  |  Branch (121:11): [True: 140, False: 510]
  ------------------
  122|    140|        return 0;
  123|    140|      }
  124|    650|    }
  125|    510|    const size_t start = pos;
  126|    600|    while (pos + 64 <= size) {
  ------------------
  |  Branch (126:12): [True: 204, False: 396]
  ------------------
  127|    204|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  128|    204|      if (!input.is_ascii()) {
  ------------------
  |  Branch (128:11): [True: 114, False: 90]
  ------------------
  129|    114|        return pos - start;
  130|    114|      }
  131|     90|      input.store(reinterpret_cast<int8_t *>(output + (pos - start)));
  132|     90|      pos += 64;
  133|     90|    }
  134|    396|    if (pos == size || size < 64) {
  ------------------
  |  Branch (134:9): [True: 38, False: 358]
  |  Branch (134:24): [True: 0, False: 358]
  ------------------
  135|     38|      return pos - start;
  136|     38|    }
  137|    358|    simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + size - 64));
  138|    358|    if (!input.is_ascii()) {
  ------------------
  |  Branch (138:9): [True: 224, False: 134]
  ------------------
  139|    224|      return pos - start;
  140|    224|    }
  141|    134|    input.store(reinterpret_cast<int8_t *>(output + (pos - start) -
  142|    134|                                           (pos - (size - 64))));
  143|    134|    return size - start;
  144|    358|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114utf8_to_latin121validating_transcoder19convert_with_errorsEPKcmPc:
  244|    670|                                                   char *latin1_output) {
  245|    670|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (245:9): [True: 170, False: 500]
  ------------------
  246|    170|      return scalar::utf8_to_latin1::convert_with_errors(in, size,
  247|    170|                                                         latin1_output);
  248|    170|    }
  249|    500|    size_t pos = 0;
  250|    500|    char *start{latin1_output};
  251|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  252|       |    // of 8 bytes when calling convert_masked_utf8_to_latin1. If you skip the
  253|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  254|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  255|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  256|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  257|    500|    size_t leading_byte = 0;
  258|    500|    size_t margin = size;
  259|  6.72k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (259:12): [True: 6.71k, False: 14]
  |  Branch (259:26): [True: 6.22k, False: 486]
  ------------------
  260|  6.22k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  261|  6.22k|    }
  262|       |    // If the input is long enough, then we have that margin-1 is the eight last
  263|       |    // leading byte.
  264|    500|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  265|   421k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (265:12): [True: 420k, False: 354]
  ------------------
  266|   420k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  267|   420k|      if (input.is_ascii()) {
  ------------------
  |  Branch (267:11): [True: 400k, False: 20.3k]
  ------------------
  268|   400k|        input.store((int8_t *)latin1_output);
  269|   400k|        latin1_output += 64;
  270|   400k|        pos += 64;
  271|   400k|      } else {
  272|       |        // you might think that a for-loop would work, but under Visual Studio,
  273|       |        // it is not good enough.
  274|  20.3k|        static_assert(
  275|  20.3k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  276|  20.3k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  277|  20.3k|            "We support either two or four chunks per 64-byte block.");
  278|  20.3k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  279|       |        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  280|       |          this->check_utf8_bytes(input.chunks[0], zero);
  281|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  282|  20.3k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  283|  20.3k|          this->check_utf8_bytes(input.chunks[0], zero);
  284|  20.3k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  285|  20.3k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  286|  20.3k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  287|  20.3k|        }
  288|  20.3k|        if (errors()) {
  ------------------
  |  Branch (288:13): [True: 146, False: 20.2k]
  ------------------
  289|       |          // rewind_and_convert_with_errors will seek a potential error from
  290|       |          // in+pos onward, with the ability to go back up to pos bytes, and
  291|       |          // read size-pos bytes forward.
  292|    146|          SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|    146|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
  293|    146|          result res = scalar::utf8_to_latin1::rewind_and_convert_with_errors(
  294|    146|              pos, in + pos, size - pos, latin1_output);
  295|    146|          res.count += pos;
  296|    146|          return res;
  297|    146|        }
  298|  20.2k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  299|  20.2k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  300|  20.2k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  301|       |        // We process in blocks of up to 12 bytes except possibly
  302|       |        // for fast paths which may process up to 16 bytes. For the
  303|       |        // slow path to work, we should have at least 12 input bytes left.
  304|  20.2k|        size_t max_starting_point = (pos + 64) - 12;
  305|       |        // Next loop is going to run at least five times.
  306|   201k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (306:16): [True: 181k, False: 20.2k]
  ------------------
  307|       |          // Performance note: our ability to compute 'consumed' and
  308|       |          // then shift and recompute is critical. If there is a
  309|       |          // latency of, say, 4 cycles on getting 'consumed', then
  310|       |          // the inner loop might have a total latency of about 6 cycles.
  311|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  312|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  313|       |          // for this section of the code. Hence, there is a limit
  314|       |          // to how much we can further increase this latency before
  315|       |          // it seriously harms performance.
  316|   181k|          size_t consumed = convert_masked_utf8_to_latin1(
  317|   181k|              in + pos, utf8_end_of_code_point_mask, latin1_output);
  318|   181k|          pos += consumed;
  319|   181k|          utf8_end_of_code_point_mask >>= consumed;
  320|   181k|        }
  321|       |        // At this point there may remain between 0 and 12 bytes in the
  322|       |        // 64-byte block. These bytes will be processed again. So we have an
  323|       |        // 80% efficiency (in the worst case). In practice we expect an
  324|       |        // 85% to 90% efficiency.
  325|  20.2k|      }
  326|   420k|    }
  327|    354|    const size_t ascii = convert_ascii_tail(in, pos, size, latin1_output);
  328|    354|    pos += ascii;
  329|    354|    latin1_output += ascii;
  330|    354|    if (pos == size) {
  ------------------
  |  Branch (330:9): [True: 76, False: 278]
  ------------------
  331|     76|      return result(error_code::SUCCESS, latin1_output - start);
  332|     76|    }
  333|       |    // rewind_and_convert_with_errors will seek a potential error from in+pos
  334|       |    // onward, with the ability to go back up to pos bytes, and read size-pos
  335|       |    // bytes forward.
  336|    278|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|    278|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
  337|    278|    result res = scalar::utf8_to_latin1::rewind_and_convert_with_errors(
  338|    278|        pos, in + pos, size - pos, latin1_output);
  339|    278|    if (res.error) { // In case of error, we want the error position
  ------------------
  |  Branch (339:9): [True: 174, False: 104]
  ------------------
  340|    174|      res.count += pos;
  341|    174|      return res;
  342|    174|    }
  343|       |    // In case of success, we want the number of words written
  344|    104|    latin1_output += res.count;
  345|    104|    return result(error_code::SUCCESS, latin1_output - start);
  346|    278|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoderC2Ev:
  114|  3.60k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoderC2Ev:
  114|  3.60k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder7convertILNS_10endiannessE0EEEmPKcmPDs:
  164|    950|                                       char16_t *utf16_output) {
  165|    950|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (165:9): [True: 310, False: 640]
  ------------------
  166|    310|      return scalar::utf8_to_utf16::convert<endian>(in, size, utf16_output);
  167|    310|    }
  168|    640|    size_t pos = 0;
  169|    640|    char16_t *start{utf16_output};
  170|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  171|       |    // of 8 bytes when calling convert_masked_utf8_to_utf16. If you skip the
  172|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  173|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  174|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  175|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  176|    640|    size_t leading_byte = 0;
  177|    640|    size_t margin = size;
  178|  8.55k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (178:12): [True: 8.54k, False: 14]
  |  Branch (178:26): [True: 7.91k, False: 626]
  ------------------
  179|  7.91k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  180|  7.91k|    }
  181|       |    // If the input is long enough, then we have that margin-1 is the eight last
  182|       |    // leading byte.
  183|    640|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  184|   676k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (184:12): [True: 675k, False: 604]
  ------------------
  185|   675k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  186|   675k|      if (input.is_ascii()) {
  ------------------
  |  Branch (186:11): [True: 539k, False: 135k]
  ------------------
  187|   539k|        input.store_ascii_as_utf16<endian>(utf16_output);
  188|   539k|        utf16_output += 64;
  189|   539k|        pos += 64;
  190|   539k|      } else {
  191|       |        // you might think that a for-loop would work, but under Visual Studio,
  192|       |        // it is not good enough.
  193|   135k|        static_assert(
  194|   135k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  195|   135k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  196|   135k|            "We support either two or four chunks per 64-byte block.");
  197|   135k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  198|   135k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  199|   135k|          this->check_utf8_bytes(input.chunks[0], zero);
  200|   135k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  201|       |        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  202|       |          this->check_utf8_bytes(input.chunks[0], zero);
  203|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  204|       |          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  205|       |          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  206|       |        }
  207|   135k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  208|   135k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (208:13): [True: 36, False: 135k]
  ------------------
  209|     36|          return 0; // error
  210|     36|        }
  211|   135k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  212|   135k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  213|       |        // We process in blocks of up to 12 bytes except possibly
  214|       |        // for fast paths which may process up to 16 bytes. For the
  215|       |        // slow path to work, we should have at least 12 input bytes left.
  216|   135k|        size_t max_starting_point = (pos + 64) - 12;
  217|       |        // Next loop is going to run at least five times.
  218|  1.33M|        while (pos < max_starting_point) {
  ------------------
  |  Branch (218:16): [True: 1.20M, False: 135k]
  ------------------
  219|       |          // Performance note: our ability to compute 'consumed' and
  220|       |          // then shift and recompute is critical. If there is a
  221|       |          // latency of, say, 4 cycles on getting 'consumed', then
  222|       |          // the inner loop might have a total latency of about 6 cycles.
  223|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  224|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  225|       |          // for this section of the code. Hence, there is a limit
  226|       |          // to how much we can further increase this latency before
  227|       |          // it seriously harms performance.
  228|  1.20M|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  229|  1.20M|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  230|  1.20M|          pos += consumed;
  231|  1.20M|          utf8_end_of_code_point_mask >>= consumed;
  232|  1.20M|        }
  233|       |        // At this point there may remain between 0 and 12 bytes in the
  234|       |        // 64-byte block. These bytes will be processed again. So we have an
  235|       |        // 80% efficiency (in the worst case). In practice we expect an
  236|       |        // 85% to 90% efficiency.
  237|   135k|      }
  238|   675k|    }
  239|    604|    if (errors()) {
  ------------------
  |  Branch (239:9): [True: 298, False: 306]
  ------------------
  240|    298|      return 0;
  241|    298|    }
  242|    306|    const size_t ascii =
  243|    306|        convert_ascii_tail<endian>(in, pos, size, utf16_output);
  244|    306|    pos += ascii;
  245|    306|    utf16_output += ascii;
  246|    306|    if (pos == size) {
  ------------------
  |  Branch (246:9): [True: 70, False: 236]
  ------------------
  247|     70|      return utf16_output - start;
  248|     70|    }
  249|    236|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|    236|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
  250|    236|    size_t howmany = scalar::utf8_to_utf16::convert<endian>(
  251|    236|        in + pos, size - pos, utf16_output);
  252|    236|    if (howmany == 0) {
  ------------------
  |  Branch (252:9): [True: 194, False: 42]
  ------------------
  253|    194|      return 0;
  254|    194|    }
  255|     42|    return utf16_output + howmany - start;
  256|    236|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  119|   922k|                                              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|   922k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  124|   922k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  125|   922k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  126|   922k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1619check_special_casesENS1_4simd5simd8IhEES5_:
    8|   922k|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|   922k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   16|       |                                               // 11______ 11______
   17|   922k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   18|   922k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   19|   922k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   20|   922k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   21|   922k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   22|   922k|  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|   922k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   31|       |  // 11110101 1000____
   32|       |  // 1111011_ 1000____
   33|       |  // 11111___ 1000____
   34|   922k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   35|       |
   36|   922k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   37|       |      // 0_______ ________ <ASCII in byte 1>
   38|   922k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   39|   922k|      TOO_LONG,
   40|       |      // 10______ ________ <continuation in byte 1>
   41|   922k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   42|       |      // 1100____ ________ <two byte lead in byte 1>
   43|   922k|      TOO_SHORT | OVERLONG_2,
   44|       |      // 1101____ ________ <two byte lead in byte 1>
   45|   922k|      TOO_SHORT,
   46|       |      // 1110____ ________ <three byte lead in byte 1>
   47|   922k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   48|       |      // 1111____ ________ <four+ byte lead in byte 1>
   49|   922k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   50|   922k|  constexpr const uint8_t CARRY =
   51|   922k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   52|   922k|  const simd8<uint8_t> byte_1_low =
   53|   922k|      (prev1 & 0x0F)
   54|   922k|          .lookup_16<uint8_t>(
   55|       |              // ____0000 ________
   56|   922k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   57|       |              // ____0001 ________
   58|   922k|              CARRY | OVERLONG_2,
   59|       |              // ____001_ ________
   60|   922k|              CARRY, CARRY,
   61|       |
   62|       |              // ____0100 ________
   63|   922k|              CARRY | TOO_LARGE,
   64|       |              // ____0101 ________
   65|   922k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   66|       |              // ____011_ ________
   67|   922k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   68|   922k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|       |
   70|       |              // ____1___ ________
   71|   922k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   72|   922k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|   922k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|   922k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|   922k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|       |              // ____1101 ________
   77|   922k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   78|   922k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   79|   922k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   80|   922k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   81|       |      // ________ 0_______ <ASCII in byte 2>
   82|   922k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   83|   922k|      TOO_SHORT, TOO_SHORT,
   84|       |
   85|       |      // ________ 1000____
   86|   922k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   87|   922k|          OVERLONG_4,
   88|       |      // ________ 1001____
   89|   922k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   90|       |      // ________ 101_____
   91|   922k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   92|   922k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|       |
   94|       |      // ________ 11______
   95|   922k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   96|   922k|  return (byte_1_high & byte_1_low & byte_2_high);
   97|   922k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1623check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  101|   922k|                        const simd8<uint8_t> sc) {
  102|   922k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  103|   922k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  104|   922k|  simd8<uint8_t> must23 =
  105|   922k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  106|   922k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  107|   922k|  return must23_80 ^ sc;
  108|   922k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder6errorsEv:
  366|   140k|  simdutf_really_inline bool errors() const {
  367|   140k|    return this->error.any_bits_set_anywhere();
  368|   140k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder18convert_ascii_tailILNS_10endiannessE0EEEmPKcmmPDs:
  131|    676|                                                  char16_t *output) {
  132|       |    // A cheap test on the first bytes avoids any SIMD work for most non-ASCII
  133|       |    // tails.
  134|    676|    if (size - pos >= 8) {
  ------------------
  |  Branch (134:9): [True: 676, False: 0]
  ------------------
  135|    676|      uint64_t first_bytes;
  136|    676|      std::memcpy(&first_bytes, in + pos, 8);
  137|    676|      if (first_bytes & 0x8080808080808080) {
  ------------------
  |  Branch (137:11): [True: 146, False: 530]
  ------------------
  138|    146|        return 0;
  139|    146|      }
  140|    676|    }
  141|    530|    const size_t start = pos;
  142|    586|    while (pos + 64 <= size) {
  ------------------
  |  Branch (142:12): [True: 234, False: 352]
  ------------------
  143|    234|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  144|    234|      if (!input.is_ascii()) {
  ------------------
  |  Branch (144:11): [True: 178, False: 56]
  ------------------
  145|    178|        return pos - start;
  146|    178|      }
  147|     56|      input.store_ascii_as_utf16<endian>(output + (pos - start));
  148|     56|      pos += 64;
  149|     56|    }
  150|    352|    if (pos == size || size < 64) {
  ------------------
  |  Branch (150:9): [True: 24, False: 328]
  |  Branch (150:24): [True: 0, False: 328]
  ------------------
  151|     24|      return pos - start;
  152|     24|    }
  153|    328|    simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + size - 64));
  154|    328|    if (!input.is_ascii()) {
  ------------------
  |  Branch (154:9): [True: 236, False: 92]
  ------------------
  155|    236|      return pos - start;
  156|    236|    }
  157|     92|    input.store_ascii_as_utf16<endian>(output + (pos - start) -
  158|     92|                                       (pos - (size - 64)));
  159|     92|    return size - start;
  160|    328|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder7convertILNS_10endiannessE1EEEmPKcmPDs:
  164|    974|                                       char16_t *utf16_output) {
  165|    974|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (165:9): [True: 314, False: 660]
  ------------------
  166|    314|      return scalar::utf8_to_utf16::convert<endian>(in, size, utf16_output);
  167|    314|    }
  168|    660|    size_t pos = 0;
  169|    660|    char16_t *start{utf16_output};
  170|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  171|       |    // of 8 bytes when calling convert_masked_utf8_to_utf16. If you skip the
  172|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  173|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  174|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  175|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  176|    660|    size_t leading_byte = 0;
  177|    660|    size_t margin = size;
  178|  8.12k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (178:12): [True: 8.10k, False: 14]
  |  Branch (178:26): [True: 7.46k, False: 646]
  ------------------
  179|  7.46k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  180|  7.46k|    }
  181|       |    // If the input is long enough, then we have that margin-1 is the eight last
  182|       |    // leading byte.
  183|    660|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  184|   585k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (184:12): [True: 585k, False: 620]
  ------------------
  185|   585k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  186|   585k|      if (input.is_ascii()) {
  ------------------
  |  Branch (186:11): [True: 399k, False: 186k]
  ------------------
  187|   399k|        input.store_ascii_as_utf16<endian>(utf16_output);
  188|   399k|        utf16_output += 64;
  189|   399k|        pos += 64;
  190|   399k|      } else {
  191|       |        // you might think that a for-loop would work, but under Visual Studio,
  192|       |        // it is not good enough.
  193|   186k|        static_assert(
  194|   186k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  195|   186k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  196|   186k|            "We support either two or four chunks per 64-byte block.");
  197|   186k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  198|   186k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  199|   186k|          this->check_utf8_bytes(input.chunks[0], zero);
  200|   186k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  201|       |        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  202|       |          this->check_utf8_bytes(input.chunks[0], zero);
  203|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  204|       |          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  205|       |          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  206|       |        }
  207|   186k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  208|   186k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (208:13): [True: 40, False: 185k]
  ------------------
  209|     40|          return 0; // error
  210|     40|        }
  211|   185k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  212|   185k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  213|       |        // We process in blocks of up to 12 bytes except possibly
  214|       |        // for fast paths which may process up to 16 bytes. For the
  215|       |        // slow path to work, we should have at least 12 input bytes left.
  216|   185k|        size_t max_starting_point = (pos + 64) - 12;
  217|       |        // Next loop is going to run at least five times.
  218|  1.84M|        while (pos < max_starting_point) {
  ------------------
  |  Branch (218:16): [True: 1.65M, False: 185k]
  ------------------
  219|       |          // Performance note: our ability to compute 'consumed' and
  220|       |          // then shift and recompute is critical. If there is a
  221|       |          // latency of, say, 4 cycles on getting 'consumed', then
  222|       |          // the inner loop might have a total latency of about 6 cycles.
  223|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  224|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  225|       |          // for this section of the code. Hence, there is a limit
  226|       |          // to how much we can further increase this latency before
  227|       |          // it seriously harms performance.
  228|  1.65M|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  229|  1.65M|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  230|  1.65M|          pos += consumed;
  231|  1.65M|          utf8_end_of_code_point_mask >>= consumed;
  232|  1.65M|        }
  233|       |        // At this point there may remain between 0 and 12 bytes in the
  234|       |        // 64-byte block. These bytes will be processed again. So we have an
  235|       |        // 80% efficiency (in the worst case). In practice we expect an
  236|       |        // 85% to 90% efficiency.
  237|   185k|      }
  238|   585k|    }
  239|    620|    if (errors()) {
  ------------------
  |  Branch (239:9): [True: 344, False: 276]
  ------------------
  240|    344|      return 0;
  241|    344|    }
  242|    276|    const size_t ascii =
  243|    276|        convert_ascii_tail<endian>(in, pos, size, utf16_output);
  244|    276|    pos += ascii;
  245|    276|    utf16_output += ascii;
  246|    276|    if (pos == size) {
  ------------------
  |  Branch (246:9): [True: 54, False: 222]
  ------------------
  247|     54|      return utf16_output - start;
  248|     54|    }
  249|    222|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|    222|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
  250|    222|    size_t howmany = scalar::utf8_to_utf16::convert<endian>(
  251|    222|        in + pos, size - pos, utf16_output);
  252|    222|    if (howmany == 0) {
  ------------------
  |  Branch (252:9): [True: 186, False: 36]
  ------------------
  253|    186|      return 0;
  254|    186|    }
  255|     36|    return utf16_output + howmany - start;
  256|    222|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder18convert_ascii_tailILNS_10endiannessE1EEEmPKcmmPDs:
  131|    766|                                                  char16_t *output) {
  132|       |    // A cheap test on the first bytes avoids any SIMD work for most non-ASCII
  133|       |    // tails.
  134|    766|    if (size - pos >= 8) {
  ------------------
  |  Branch (134:9): [True: 766, False: 0]
  ------------------
  135|    766|      uint64_t first_bytes;
  136|    766|      std::memcpy(&first_bytes, in + pos, 8);
  137|    766|      if (first_bytes & 0x8080808080808080) {
  ------------------
  |  Branch (137:11): [True: 194, False: 572]
  ------------------
  138|    194|        return 0;
  139|    194|      }
  140|    766|    }
  141|    572|    const size_t start = pos;
  142|    632|    while (pos + 64 <= size) {
  ------------------
  |  Branch (142:12): [True: 212, False: 420]
  ------------------
  143|    212|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  144|    212|      if (!input.is_ascii()) {
  ------------------
  |  Branch (144:11): [True: 152, False: 60]
  ------------------
  145|    152|        return pos - start;
  146|    152|      }
  147|     60|      input.store_ascii_as_utf16<endian>(output + (pos - start));
  148|     60|      pos += 64;
  149|     60|    }
  150|    420|    if (pos == size || size < 64) {
  ------------------
  |  Branch (150:9): [True: 26, False: 394]
  |  Branch (150:24): [True: 0, False: 394]
  ------------------
  151|     26|      return pos - start;
  152|     26|    }
  153|    394|    simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + size - 64));
  154|    394|    if (!input.is_ascii()) {
  ------------------
  |  Branch (154:9): [True: 286, False: 108]
  ------------------
  155|    286|      return pos - start;
  156|    286|    }
  157|    108|    input.store_ascii_as_utf16<endian>(output + (pos - start) -
  158|    108|                                       (pos - (size - 64)));
  159|    108|    return size - start;
  160|    394|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder19convert_with_errorsILNS_10endiannessE0EEENS_6resultEPKcmPDs:
  260|    782|                                                   char16_t *utf16_output) {
  261|    782|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (261:9): [True: 284, False: 498]
  ------------------
  262|    284|      return scalar::utf8_to_utf16::convert_with_errors<endian>(in, size,
  263|    284|                                                                utf16_output);
  264|    284|    }
  265|    498|    size_t pos = 0;
  266|    498|    char16_t *start{utf16_output};
  267|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  268|       |    // of 8 bytes when calling convert_masked_utf8_to_utf16. If you skip the
  269|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  270|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  271|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  272|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  273|    498|    size_t leading_byte = 0;
  274|    498|    size_t margin = size;
  275|  7.44k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (275:12): [True: 7.42k, False: 18]
  |  Branch (275:26): [True: 6.94k, False: 480]
  ------------------
  276|  6.94k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  277|  6.94k|    }
  278|       |    // If the input is long enough, then we have that margin-1 is the eight last
  279|       |    // leading byte.
  280|    498|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  281|   398k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (281:12): [True: 397k, False: 370]
  ------------------
  282|   397k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  283|   397k|      if (input.is_ascii()) {
  ------------------
  |  Branch (283:11): [True: 322k, False: 75.3k]
  ------------------
  284|   322k|        input.store_ascii_as_utf16<endian>(utf16_output);
  285|   322k|        utf16_output += 64;
  286|   322k|        pos += 64;
  287|   322k|      } else {
  288|       |        // you might think that a for-loop would work, but under Visual Studio,
  289|       |        // it is not good enough.
  290|  75.3k|        static_assert(
  291|  75.3k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  292|  75.3k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  293|  75.3k|            "We support either two or four chunks per 64-byte block.");
  294|  75.3k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  295|  75.3k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  296|  75.3k|          this->check_utf8_bytes(input.chunks[0], zero);
  297|  75.3k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  298|       |        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  299|       |          this->check_utf8_bytes(input.chunks[0], zero);
  300|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  301|       |          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  302|       |          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  303|       |        }
  304|  75.3k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  305|  75.3k|        if (errors() || (utf8_continuation_mask & 1)) {
  ------------------
  |  Branch (305:13): [True: 128, False: 75.2k]
  |  Branch (305:25): [True: 0, False: 75.2k]
  ------------------
  306|       |          // rewind_and_convert_with_errors will seek a potential error from
  307|       |          // in+pos onward, with the ability to go back up to pos bytes, and
  308|       |          // read size-pos bytes forward.
  309|    128|          SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|    128|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
  310|    128|          result res =
  311|    128|              scalar::utf8_to_utf16::rewind_and_convert_with_errors<endian>(
  312|    128|                  pos, in + pos, size - pos, utf16_output);
  313|    128|          res.count += pos;
  314|    128|          return res;
  315|    128|        }
  316|  75.2k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  317|  75.2k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  318|       |        // We process in blocks of up to 12 bytes except possibly
  319|       |        // for fast paths which may process up to 16 bytes. For the
  320|       |        // slow path to work, we should have at least 12 input bytes left.
  321|  75.2k|        size_t max_starting_point = (pos + 64) - 12;
  322|       |        // Next loop is going to run at least five times.
  323|   740k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (323:16): [True: 665k, False: 75.2k]
  ------------------
  324|       |          // Performance note: our ability to compute 'consumed' and
  325|       |          // then shift and recompute is critical. If there is a
  326|       |          // latency of, say, 4 cycles on getting 'consumed', then
  327|       |          // the inner loop might have a total latency of about 6 cycles.
  328|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  329|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  330|       |          // for this section of the code. Hence, there is a limit
  331|       |          // to how much we can further increase this latency before
  332|       |          // it seriously harms performance.
  333|   665k|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  334|   665k|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  335|   665k|          pos += consumed;
  336|   665k|          utf8_end_of_code_point_mask >>= consumed;
  337|   665k|        }
  338|       |        // At this point there may remain between 0 and 12 bytes in the
  339|       |        // 64-byte block. These bytes will be processed again. So we have an
  340|       |        // 80% efficiency (in the worst case). In practice we expect an
  341|       |        // 85% to 90% efficiency.
  342|  75.2k|      }
  343|   397k|    }
  344|    370|    const size_t ascii =
  345|    370|        convert_ascii_tail<endian>(in, pos, size, utf16_output);
  346|    370|    pos += ascii;
  347|    370|    utf16_output += ascii;
  348|    370|    if (pos == size) {
  ------------------
  |  Branch (348:9): [True: 46, False: 324]
  ------------------
  349|     46|      return result(error_code::SUCCESS, utf16_output - start);
  350|     46|    }
  351|       |    // rewind_and_convert_with_errors will seek a potential error from in+pos
  352|       |    // onward, with the ability to go back up to pos bytes, and read size-pos
  353|       |    // bytes forward.
  354|    324|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|    324|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
  355|    324|    result res = scalar::utf8_to_utf16::rewind_and_convert_with_errors<endian>(
  356|    324|        pos, in + pos, size - pos, utf16_output);
  357|    324|    if (res.error) { // In case of error, we want the error position
  ------------------
  |  Branch (357:9): [True: 250, False: 74]
  ------------------
  358|    250|      res.count += pos;
  359|    250|      return res;
  360|    250|    }
  361|       |    // In case of success, we want the number of words written
  362|     74|    utf16_output += res.count;
  363|     74|    return result(error_code::SUCCESS, utf16_output - start);
  364|    324|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1621validating_transcoder19convert_with_errorsILNS_10endiannessE1EEENS_6resultEPKcmPDs:
  260|    902|                                                   char16_t *utf16_output) {
  261|    902|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (261:9): [True: 312, False: 590]
  ------------------
  262|    312|      return scalar::utf8_to_utf16::convert_with_errors<endian>(in, size,
  263|    312|                                                                utf16_output);
  264|    312|    }
  265|    590|    size_t pos = 0;
  266|    590|    char16_t *start{utf16_output};
  267|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  268|       |    // of 8 bytes when calling convert_masked_utf8_to_utf16. If you skip the
  269|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  270|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  271|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  272|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  273|    590|    size_t leading_byte = 0;
  274|    590|    size_t margin = size;
  275|  8.64k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (275:12): [True: 8.62k, False: 14]
  |  Branch (275:26): [True: 8.05k, False: 576]
  ------------------
  276|  8.05k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  277|  8.05k|    }
  278|       |    // If the input is long enough, then we have that margin-1 is the eight last
  279|       |    // leading byte.
  280|    590|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  281|   370k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (281:12): [True: 369k, False: 490]
  ------------------
  282|   369k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  283|   369k|      if (input.is_ascii()) {
  ------------------
  |  Branch (283:11): [True: 305k, False: 64.0k]
  ------------------
  284|   305k|        input.store_ascii_as_utf16<endian>(utf16_output);
  285|   305k|        utf16_output += 64;
  286|   305k|        pos += 64;
  287|   305k|      } else {
  288|       |        // you might think that a for-loop would work, but under Visual Studio,
  289|       |        // it is not good enough.
  290|  64.0k|        static_assert(
  291|  64.0k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  292|  64.0k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  293|  64.0k|            "We support either two or four chunks per 64-byte block.");
  294|  64.0k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  295|  64.0k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  296|  64.0k|          this->check_utf8_bytes(input.chunks[0], zero);
  297|  64.0k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  298|       |        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  299|       |          this->check_utf8_bytes(input.chunks[0], zero);
  300|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  301|       |          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  302|       |          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  303|       |        }
  304|  64.0k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  305|  64.0k|        if (errors() || (utf8_continuation_mask & 1)) {
  ------------------
  |  Branch (305:13): [True: 100, False: 63.9k]
  |  Branch (305:25): [True: 0, False: 63.9k]
  ------------------
  306|       |          // rewind_and_convert_with_errors will seek a potential error from
  307|       |          // in+pos onward, with the ability to go back up to pos bytes, and
  308|       |          // read size-pos bytes forward.
  309|    100|          SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|    100|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
  310|    100|          result res =
  311|    100|              scalar::utf8_to_utf16::rewind_and_convert_with_errors<endian>(
  312|    100|                  pos, in + pos, size - pos, utf16_output);
  313|    100|          res.count += pos;
  314|    100|          return res;
  315|    100|        }
  316|  63.9k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  317|  63.9k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  318|       |        // We process in blocks of up to 12 bytes except possibly
  319|       |        // for fast paths which may process up to 16 bytes. For the
  320|       |        // slow path to work, we should have at least 12 input bytes left.
  321|  63.9k|        size_t max_starting_point = (pos + 64) - 12;
  322|       |        // Next loop is going to run at least five times.
  323|   628k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (323:16): [True: 564k, False: 63.9k]
  ------------------
  324|       |          // Performance note: our ability to compute 'consumed' and
  325|       |          // then shift and recompute is critical. If there is a
  326|       |          // latency of, say, 4 cycles on getting 'consumed', then
  327|       |          // the inner loop might have a total latency of about 6 cycles.
  328|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  329|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  330|       |          // for this section of the code. Hence, there is a limit
  331|       |          // to how much we can further increase this latency before
  332|       |          // it seriously harms performance.
  333|   564k|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  334|   564k|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  335|   564k|          pos += consumed;
  336|   564k|          utf8_end_of_code_point_mask >>= consumed;
  337|   564k|        }
  338|       |        // At this point there may remain between 0 and 12 bytes in the
  339|       |        // 64-byte block. These bytes will be processed again. So we have an
  340|       |        // 80% efficiency (in the worst case). In practice we expect an
  341|       |        // 85% to 90% efficiency.
  342|  63.9k|      }
  343|   369k|    }
  344|    490|    const size_t ascii =
  345|    490|        convert_ascii_tail<endian>(in, pos, size, utf16_output);
  346|    490|    pos += ascii;
  347|    490|    utf16_output += ascii;
  348|    490|    if (pos == size) {
  ------------------
  |  Branch (348:9): [True: 80, False: 410]
  ------------------
  349|     80|      return result(error_code::SUCCESS, utf16_output - start);
  350|     80|    }
  351|       |    // rewind_and_convert_with_errors will seek a potential error from in+pos
  352|       |    // onward, with the ability to go back up to pos bytes, and read size-pos
  353|       |    // bytes forward.
  354|    410|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|    410|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
  355|    410|    result res = scalar::utf8_to_utf16::rewind_and_convert_with_errors<endian>(
  356|    410|        pos, in + pos, size - pos, utf16_output);
  357|    410|    if (res.error) { // In case of error, we want the error position
  ------------------
  |  Branch (357:9): [True: 268, False: 142]
  ------------------
  358|    268|      res.count += pos;
  359|    268|      return res;
  360|    268|    }
  361|       |    // In case of success, we want the number of words written
  362|    142|    utf16_output += res.count;
  363|    142|    return result(error_code::SUCCESS, utf16_output - start);
  364|    410|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder7convertILNS_10endiannessE0EEEmPKcmPDs:
  164|    950|                                       char16_t *utf16_output) {
  165|    950|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (165:9): [True: 310, False: 640]
  ------------------
  166|    310|      return scalar::utf8_to_utf16::convert<endian>(in, size, utf16_output);
  167|    310|    }
  168|    640|    size_t pos = 0;
  169|    640|    char16_t *start{utf16_output};
  170|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  171|       |    // of 8 bytes when calling convert_masked_utf8_to_utf16. If you skip the
  172|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  173|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  174|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  175|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  176|    640|    size_t leading_byte = 0;
  177|    640|    size_t margin = size;
  178|  8.55k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (178:12): [True: 8.54k, False: 14]
  |  Branch (178:26): [True: 7.91k, False: 626]
  ------------------
  179|  7.91k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  180|  7.91k|    }
  181|       |    // If the input is long enough, then we have that margin-1 is the eight last
  182|       |    // leading byte.
  183|    640|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  184|   676k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (184:12): [True: 675k, False: 604]
  ------------------
  185|   675k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  186|   675k|      if (input.is_ascii()) {
  ------------------
  |  Branch (186:11): [True: 539k, False: 135k]
  ------------------
  187|   539k|        input.store_ascii_as_utf16<endian>(utf16_output);
  188|   539k|        utf16_output += 64;
  189|   539k|        pos += 64;
  190|   539k|      } else {
  191|       |        // you might think that a for-loop would work, but under Visual Studio,
  192|       |        // it is not good enough.
  193|   135k|        static_assert(
  194|   135k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  195|   135k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  196|   135k|            "We support either two or four chunks per 64-byte block.");
  197|   135k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  198|       |        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  199|       |          this->check_utf8_bytes(input.chunks[0], zero);
  200|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  201|   135k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  202|   135k|          this->check_utf8_bytes(input.chunks[0], zero);
  203|   135k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  204|   135k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  205|   135k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  206|   135k|        }
  207|   135k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  208|   135k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (208:13): [True: 36, False: 135k]
  ------------------
  209|     36|          return 0; // error
  210|     36|        }
  211|   135k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  212|   135k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  213|       |        // We process in blocks of up to 12 bytes except possibly
  214|       |        // for fast paths which may process up to 16 bytes. For the
  215|       |        // slow path to work, we should have at least 12 input bytes left.
  216|   135k|        size_t max_starting_point = (pos + 64) - 12;
  217|       |        // Next loop is going to run at least five times.
  218|  1.33M|        while (pos < max_starting_point) {
  ------------------
  |  Branch (218:16): [True: 1.20M, False: 135k]
  ------------------
  219|       |          // Performance note: our ability to compute 'consumed' and
  220|       |          // then shift and recompute is critical. If there is a
  221|       |          // latency of, say, 4 cycles on getting 'consumed', then
  222|       |          // the inner loop might have a total latency of about 6 cycles.
  223|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  224|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  225|       |          // for this section of the code. Hence, there is a limit
  226|       |          // to how much we can further increase this latency before
  227|       |          // it seriously harms performance.
  228|  1.20M|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  229|  1.20M|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  230|  1.20M|          pos += consumed;
  231|  1.20M|          utf8_end_of_code_point_mask >>= consumed;
  232|  1.20M|        }
  233|       |        // At this point there may remain between 0 and 12 bytes in the
  234|       |        // 64-byte block. These bytes will be processed again. So we have an
  235|       |        // 80% efficiency (in the worst case). In practice we expect an
  236|       |        // 85% to 90% efficiency.
  237|   135k|      }
  238|   675k|    }
  239|    604|    if (errors()) {
  ------------------
  |  Branch (239:9): [True: 298, False: 306]
  ------------------
  240|    298|      return 0;
  241|    298|    }
  242|    306|    const size_t ascii =
  243|    306|        convert_ascii_tail<endian>(in, pos, size, utf16_output);
  244|    306|    pos += ascii;
  245|    306|    utf16_output += ascii;
  246|    306|    if (pos == size) {
  ------------------
  |  Branch (246:9): [True: 70, False: 236]
  ------------------
  247|     70|      return utf16_output - start;
  248|     70|    }
  249|    236|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|    236|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
  250|    236|    size_t howmany = scalar::utf8_to_utf16::convert<endian>(
  251|    236|        in + pos, size - pos, utf16_output);
  252|    236|    if (howmany == 0) {
  ------------------
  |  Branch (252:9): [True: 194, False: 42]
  ------------------
  253|    194|      return 0;
  254|    194|    }
  255|     42|    return utf16_output + howmany - start;
  256|    236|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  119|  1.84M|                                              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|  1.84M|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  124|  1.84M|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  125|  1.84M|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  126|  1.84M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1619check_special_casesENS1_4simd5simd8IhEES5_:
    8|  1.84M|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|  1.84M|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   16|       |                                               // 11______ 11______
   17|  1.84M|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   18|  1.84M|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   19|  1.84M|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   20|  1.84M|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   21|  1.84M|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   22|  1.84M|  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|  1.84M|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   31|       |  // 11110101 1000____
   32|       |  // 1111011_ 1000____
   33|       |  // 11111___ 1000____
   34|  1.84M|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   35|       |
   36|  1.84M|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   37|       |      // 0_______ ________ <ASCII in byte 1>
   38|  1.84M|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   39|  1.84M|      TOO_LONG,
   40|       |      // 10______ ________ <continuation in byte 1>
   41|  1.84M|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   42|       |      // 1100____ ________ <two byte lead in byte 1>
   43|  1.84M|      TOO_SHORT | OVERLONG_2,
   44|       |      // 1101____ ________ <two byte lead in byte 1>
   45|  1.84M|      TOO_SHORT,
   46|       |      // 1110____ ________ <three byte lead in byte 1>
   47|  1.84M|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   48|       |      // 1111____ ________ <four+ byte lead in byte 1>
   49|  1.84M|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   50|  1.84M|  constexpr const uint8_t CARRY =
   51|  1.84M|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   52|  1.84M|  const simd8<uint8_t> byte_1_low =
   53|  1.84M|      (prev1 & 0x0F)
   54|  1.84M|          .lookup_16<uint8_t>(
   55|       |              // ____0000 ________
   56|  1.84M|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   57|       |              // ____0001 ________
   58|  1.84M|              CARRY | OVERLONG_2,
   59|       |              // ____001_ ________
   60|  1.84M|              CARRY, CARRY,
   61|       |
   62|       |              // ____0100 ________
   63|  1.84M|              CARRY | TOO_LARGE,
   64|       |              // ____0101 ________
   65|  1.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   66|       |              // ____011_ ________
   67|  1.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   68|  1.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|       |
   70|       |              // ____1___ ________
   71|  1.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   72|  1.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  1.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  1.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  1.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|       |              // ____1101 ________
   77|  1.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   78|  1.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   79|  1.84M|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   80|  1.84M|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   81|       |      // ________ 0_______ <ASCII in byte 2>
   82|  1.84M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   83|  1.84M|      TOO_SHORT, TOO_SHORT,
   84|       |
   85|       |      // ________ 1000____
   86|  1.84M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   87|  1.84M|          OVERLONG_4,
   88|       |      // ________ 1001____
   89|  1.84M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   90|       |      // ________ 101_____
   91|  1.84M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   92|  1.84M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|       |
   94|       |      // ________ 11______
   95|  1.84M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   96|  1.84M|  return (byte_1_high & byte_1_low & byte_2_high);
   97|  1.84M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1623check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  101|  1.84M|                        const simd8<uint8_t> sc) {
  102|  1.84M|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  103|  1.84M|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  104|  1.84M|  simd8<uint8_t> must23 =
  105|  1.84M|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  106|  1.84M|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  107|  1.84M|  return must23_80 ^ sc;
  108|  1.84M|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder6errorsEv:
  366|   140k|  simdutf_really_inline bool errors() const {
  367|   140k|    return this->error.any_bits_set_anywhere();
  368|   140k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder18convert_ascii_tailILNS_10endiannessE0EEEmPKcmmPDs:
  131|    676|                                                  char16_t *output) {
  132|       |    // A cheap test on the first bytes avoids any SIMD work for most non-ASCII
  133|       |    // tails.
  134|    676|    if (size - pos >= 8) {
  ------------------
  |  Branch (134:9): [True: 676, False: 0]
  ------------------
  135|    676|      uint64_t first_bytes;
  136|    676|      std::memcpy(&first_bytes, in + pos, 8);
  137|    676|      if (first_bytes & 0x8080808080808080) {
  ------------------
  |  Branch (137:11): [True: 146, False: 530]
  ------------------
  138|    146|        return 0;
  139|    146|      }
  140|    676|    }
  141|    530|    const size_t start = pos;
  142|    586|    while (pos + 64 <= size) {
  ------------------
  |  Branch (142:12): [True: 234, False: 352]
  ------------------
  143|    234|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  144|    234|      if (!input.is_ascii()) {
  ------------------
  |  Branch (144:11): [True: 178, False: 56]
  ------------------
  145|    178|        return pos - start;
  146|    178|      }
  147|     56|      input.store_ascii_as_utf16<endian>(output + (pos - start));
  148|     56|      pos += 64;
  149|     56|    }
  150|    352|    if (pos == size || size < 64) {
  ------------------
  |  Branch (150:9): [True: 24, False: 328]
  |  Branch (150:24): [True: 0, False: 328]
  ------------------
  151|     24|      return pos - start;
  152|     24|    }
  153|    328|    simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + size - 64));
  154|    328|    if (!input.is_ascii()) {
  ------------------
  |  Branch (154:9): [True: 236, False: 92]
  ------------------
  155|    236|      return pos - start;
  156|    236|    }
  157|     92|    input.store_ascii_as_utf16<endian>(output + (pos - start) -
  158|     92|                                       (pos - (size - 64)));
  159|     92|    return size - start;
  160|    328|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder7convertILNS_10endiannessE1EEEmPKcmPDs:
  164|    974|                                       char16_t *utf16_output) {
  165|    974|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (165:9): [True: 314, False: 660]
  ------------------
  166|    314|      return scalar::utf8_to_utf16::convert<endian>(in, size, utf16_output);
  167|    314|    }
  168|    660|    size_t pos = 0;
  169|    660|    char16_t *start{utf16_output};
  170|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  171|       |    // of 8 bytes when calling convert_masked_utf8_to_utf16. If you skip the
  172|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  173|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  174|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  175|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  176|    660|    size_t leading_byte = 0;
  177|    660|    size_t margin = size;
  178|  8.12k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (178:12): [True: 8.10k, False: 14]
  |  Branch (178:26): [True: 7.46k, False: 646]
  ------------------
  179|  7.46k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  180|  7.46k|    }
  181|       |    // If the input is long enough, then we have that margin-1 is the eight last
  182|       |    // leading byte.
  183|    660|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  184|   585k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (184:12): [True: 585k, False: 620]
  ------------------
  185|   585k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  186|   585k|      if (input.is_ascii()) {
  ------------------
  |  Branch (186:11): [True: 399k, False: 186k]
  ------------------
  187|   399k|        input.store_ascii_as_utf16<endian>(utf16_output);
  188|   399k|        utf16_output += 64;
  189|   399k|        pos += 64;
  190|   399k|      } else {
  191|       |        // you might think that a for-loop would work, but under Visual Studio,
  192|       |        // it is not good enough.
  193|   186k|        static_assert(
  194|   186k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  195|   186k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  196|   186k|            "We support either two or four chunks per 64-byte block.");
  197|   186k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  198|       |        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  199|       |          this->check_utf8_bytes(input.chunks[0], zero);
  200|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  201|   186k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  202|   186k|          this->check_utf8_bytes(input.chunks[0], zero);
  203|   186k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  204|   186k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  205|   186k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  206|   186k|        }
  207|   186k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  208|   186k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (208:13): [True: 40, False: 185k]
  ------------------
  209|     40|          return 0; // error
  210|     40|        }
  211|   185k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  212|   185k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  213|       |        // We process in blocks of up to 12 bytes except possibly
  214|       |        // for fast paths which may process up to 16 bytes. For the
  215|       |        // slow path to work, we should have at least 12 input bytes left.
  216|   185k|        size_t max_starting_point = (pos + 64) - 12;
  217|       |        // Next loop is going to run at least five times.
  218|  1.84M|        while (pos < max_starting_point) {
  ------------------
  |  Branch (218:16): [True: 1.65M, False: 185k]
  ------------------
  219|       |          // Performance note: our ability to compute 'consumed' and
  220|       |          // then shift and recompute is critical. If there is a
  221|       |          // latency of, say, 4 cycles on getting 'consumed', then
  222|       |          // the inner loop might have a total latency of about 6 cycles.
  223|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  224|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  225|       |          // for this section of the code. Hence, there is a limit
  226|       |          // to how much we can further increase this latency before
  227|       |          // it seriously harms performance.
  228|  1.65M|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  229|  1.65M|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  230|  1.65M|          pos += consumed;
  231|  1.65M|          utf8_end_of_code_point_mask >>= consumed;
  232|  1.65M|        }
  233|       |        // At this point there may remain between 0 and 12 bytes in the
  234|       |        // 64-byte block. These bytes will be processed again. So we have an
  235|       |        // 80% efficiency (in the worst case). In practice we expect an
  236|       |        // 85% to 90% efficiency.
  237|   185k|      }
  238|   585k|    }
  239|    620|    if (errors()) {
  ------------------
  |  Branch (239:9): [True: 344, False: 276]
  ------------------
  240|    344|      return 0;
  241|    344|    }
  242|    276|    const size_t ascii =
  243|    276|        convert_ascii_tail<endian>(in, pos, size, utf16_output);
  244|    276|    pos += ascii;
  245|    276|    utf16_output += ascii;
  246|    276|    if (pos == size) {
  ------------------
  |  Branch (246:9): [True: 54, False: 222]
  ------------------
  247|     54|      return utf16_output - start;
  248|     54|    }
  249|    222|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|    222|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
  250|    222|    size_t howmany = scalar::utf8_to_utf16::convert<endian>(
  251|    222|        in + pos, size - pos, utf16_output);
  252|    222|    if (howmany == 0) {
  ------------------
  |  Branch (252:9): [True: 186, False: 36]
  ------------------
  253|    186|      return 0;
  254|    186|    }
  255|     36|    return utf16_output + howmany - start;
  256|    222|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder18convert_ascii_tailILNS_10endiannessE1EEEmPKcmmPDs:
  131|    766|                                                  char16_t *output) {
  132|       |    // A cheap test on the first bytes avoids any SIMD work for most non-ASCII
  133|       |    // tails.
  134|    766|    if (size - pos >= 8) {
  ------------------
  |  Branch (134:9): [True: 766, False: 0]
  ------------------
  135|    766|      uint64_t first_bytes;
  136|    766|      std::memcpy(&first_bytes, in + pos, 8);
  137|    766|      if (first_bytes & 0x8080808080808080) {
  ------------------
  |  Branch (137:11): [True: 194, False: 572]
  ------------------
  138|    194|        return 0;
  139|    194|      }
  140|    766|    }
  141|    572|    const size_t start = pos;
  142|    632|    while (pos + 64 <= size) {
  ------------------
  |  Branch (142:12): [True: 212, False: 420]
  ------------------
  143|    212|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  144|    212|      if (!input.is_ascii()) {
  ------------------
  |  Branch (144:11): [True: 152, False: 60]
  ------------------
  145|    152|        return pos - start;
  146|    152|      }
  147|     60|      input.store_ascii_as_utf16<endian>(output + (pos - start));
  148|     60|      pos += 64;
  149|     60|    }
  150|    420|    if (pos == size || size < 64) {
  ------------------
  |  Branch (150:9): [True: 26, False: 394]
  |  Branch (150:24): [True: 0, False: 394]
  ------------------
  151|     26|      return pos - start;
  152|     26|    }
  153|    394|    simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + size - 64));
  154|    394|    if (!input.is_ascii()) {
  ------------------
  |  Branch (154:9): [True: 286, False: 108]
  ------------------
  155|    286|      return pos - start;
  156|    286|    }
  157|    108|    input.store_ascii_as_utf16<endian>(output + (pos - start) -
  158|    108|                                       (pos - (size - 64)));
  159|    108|    return size - start;
  160|    394|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder19convert_with_errorsILNS_10endiannessE0EEENS_6resultEPKcmPDs:
  260|    782|                                                   char16_t *utf16_output) {
  261|    782|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (261:9): [True: 284, False: 498]
  ------------------
  262|    284|      return scalar::utf8_to_utf16::convert_with_errors<endian>(in, size,
  263|    284|                                                                utf16_output);
  264|    284|    }
  265|    498|    size_t pos = 0;
  266|    498|    char16_t *start{utf16_output};
  267|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  268|       |    // of 8 bytes when calling convert_masked_utf8_to_utf16. If you skip the
  269|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  270|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  271|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  272|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  273|    498|    size_t leading_byte = 0;
  274|    498|    size_t margin = size;
  275|  7.44k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (275:12): [True: 7.42k, False: 18]
  |  Branch (275:26): [True: 6.94k, False: 480]
  ------------------
  276|  6.94k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  277|  6.94k|    }
  278|       |    // If the input is long enough, then we have that margin-1 is the eight last
  279|       |    // leading byte.
  280|    498|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  281|   398k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (281:12): [True: 397k, False: 370]
  ------------------
  282|   397k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  283|   397k|      if (input.is_ascii()) {
  ------------------
  |  Branch (283:11): [True: 322k, False: 75.3k]
  ------------------
  284|   322k|        input.store_ascii_as_utf16<endian>(utf16_output);
  285|   322k|        utf16_output += 64;
  286|   322k|        pos += 64;
  287|   322k|      } else {
  288|       |        // you might think that a for-loop would work, but under Visual Studio,
  289|       |        // it is not good enough.
  290|  75.3k|        static_assert(
  291|  75.3k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  292|  75.3k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  293|  75.3k|            "We support either two or four chunks per 64-byte block.");
  294|  75.3k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  295|       |        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  296|       |          this->check_utf8_bytes(input.chunks[0], zero);
  297|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  298|  75.3k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  299|  75.3k|          this->check_utf8_bytes(input.chunks[0], zero);
  300|  75.3k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  301|  75.3k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  302|  75.3k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  303|  75.3k|        }
  304|  75.3k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  305|  75.3k|        if (errors() || (utf8_continuation_mask & 1)) {
  ------------------
  |  Branch (305:13): [True: 128, False: 75.2k]
  |  Branch (305:25): [True: 0, False: 75.2k]
  ------------------
  306|       |          // rewind_and_convert_with_errors will seek a potential error from
  307|       |          // in+pos onward, with the ability to go back up to pos bytes, and
  308|       |          // read size-pos bytes forward.
  309|    128|          SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|    128|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
  310|    128|          result res =
  311|    128|              scalar::utf8_to_utf16::rewind_and_convert_with_errors<endian>(
  312|    128|                  pos, in + pos, size - pos, utf16_output);
  313|    128|          res.count += pos;
  314|    128|          return res;
  315|    128|        }
  316|  75.2k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  317|  75.2k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  318|       |        // We process in blocks of up to 12 bytes except possibly
  319|       |        // for fast paths which may process up to 16 bytes. For the
  320|       |        // slow path to work, we should have at least 12 input bytes left.
  321|  75.2k|        size_t max_starting_point = (pos + 64) - 12;
  322|       |        // Next loop is going to run at least five times.
  323|   740k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (323:16): [True: 665k, False: 75.2k]
  ------------------
  324|       |          // Performance note: our ability to compute 'consumed' and
  325|       |          // then shift and recompute is critical. If there is a
  326|       |          // latency of, say, 4 cycles on getting 'consumed', then
  327|       |          // the inner loop might have a total latency of about 6 cycles.
  328|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  329|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  330|       |          // for this section of the code. Hence, there is a limit
  331|       |          // to how much we can further increase this latency before
  332|       |          // it seriously harms performance.
  333|   665k|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  334|   665k|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  335|   665k|          pos += consumed;
  336|   665k|          utf8_end_of_code_point_mask >>= consumed;
  337|   665k|        }
  338|       |        // At this point there may remain between 0 and 12 bytes in the
  339|       |        // 64-byte block. These bytes will be processed again. So we have an
  340|       |        // 80% efficiency (in the worst case). In practice we expect an
  341|       |        // 85% to 90% efficiency.
  342|  75.2k|      }
  343|   397k|    }
  344|    370|    const size_t ascii =
  345|    370|        convert_ascii_tail<endian>(in, pos, size, utf16_output);
  346|    370|    pos += ascii;
  347|    370|    utf16_output += ascii;
  348|    370|    if (pos == size) {
  ------------------
  |  Branch (348:9): [True: 46, False: 324]
  ------------------
  349|     46|      return result(error_code::SUCCESS, utf16_output - start);
  350|     46|    }
  351|       |    // rewind_and_convert_with_errors will seek a potential error from in+pos
  352|       |    // onward, with the ability to go back up to pos bytes, and read size-pos
  353|       |    // bytes forward.
  354|    324|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|    324|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
  355|    324|    result res = scalar::utf8_to_utf16::rewind_and_convert_with_errors<endian>(
  356|    324|        pos, in + pos, size - pos, utf16_output);
  357|    324|    if (res.error) { // In case of error, we want the error position
  ------------------
  |  Branch (357:9): [True: 250, False: 74]
  ------------------
  358|    250|      res.count += pos;
  359|    250|      return res;
  360|    250|    }
  361|       |    // In case of success, we want the number of words written
  362|     74|    utf16_output += res.count;
  363|     74|    return result(error_code::SUCCESS, utf16_output - start);
  364|    324|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1621validating_transcoder19convert_with_errorsILNS_10endiannessE1EEENS_6resultEPKcmPDs:
  260|    902|                                                   char16_t *utf16_output) {
  261|    902|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (261:9): [True: 312, False: 590]
  ------------------
  262|    312|      return scalar::utf8_to_utf16::convert_with_errors<endian>(in, size,
  263|    312|                                                                utf16_output);
  264|    312|    }
  265|    590|    size_t pos = 0;
  266|    590|    char16_t *start{utf16_output};
  267|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  268|       |    // of 8 bytes when calling convert_masked_utf8_to_utf16. If you skip the
  269|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  270|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  271|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  272|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  273|    590|    size_t leading_byte = 0;
  274|    590|    size_t margin = size;
  275|  8.64k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (275:12): [True: 8.62k, False: 14]
  |  Branch (275:26): [True: 8.05k, False: 576]
  ------------------
  276|  8.05k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  277|  8.05k|    }
  278|       |    // If the input is long enough, then we have that margin-1 is the eight last
  279|       |    // leading byte.
  280|    590|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  281|   370k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (281:12): [True: 369k, False: 490]
  ------------------
  282|   369k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  283|   369k|      if (input.is_ascii()) {
  ------------------
  |  Branch (283:11): [True: 305k, False: 64.0k]
  ------------------
  284|   305k|        input.store_ascii_as_utf16<endian>(utf16_output);
  285|   305k|        utf16_output += 64;
  286|   305k|        pos += 64;
  287|   305k|      } else {
  288|       |        // you might think that a for-loop would work, but under Visual Studio,
  289|       |        // it is not good enough.
  290|  64.0k|        static_assert(
  291|  64.0k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  292|  64.0k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  293|  64.0k|            "We support either two or four chunks per 64-byte block.");
  294|  64.0k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  295|       |        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  296|       |          this->check_utf8_bytes(input.chunks[0], zero);
  297|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  298|  64.0k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  299|  64.0k|          this->check_utf8_bytes(input.chunks[0], zero);
  300|  64.0k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  301|  64.0k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  302|  64.0k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  303|  64.0k|        }
  304|  64.0k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  305|  64.0k|        if (errors() || (utf8_continuation_mask & 1)) {
  ------------------
  |  Branch (305:13): [True: 100, False: 63.9k]
  |  Branch (305:25): [True: 0, False: 63.9k]
  ------------------
  306|       |          // rewind_and_convert_with_errors will seek a potential error from
  307|       |          // in+pos onward, with the ability to go back up to pos bytes, and
  308|       |          // read size-pos bytes forward.
  309|    100|          SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|    100|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
  310|    100|          result res =
  311|    100|              scalar::utf8_to_utf16::rewind_and_convert_with_errors<endian>(
  312|    100|                  pos, in + pos, size - pos, utf16_output);
  313|    100|          res.count += pos;
  314|    100|          return res;
  315|    100|        }
  316|  63.9k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  317|  63.9k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  318|       |        // We process in blocks of up to 12 bytes except possibly
  319|       |        // for fast paths which may process up to 16 bytes. For the
  320|       |        // slow path to work, we should have at least 12 input bytes left.
  321|  63.9k|        size_t max_starting_point = (pos + 64) - 12;
  322|       |        // Next loop is going to run at least five times.
  323|   628k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (323:16): [True: 564k, False: 63.9k]
  ------------------
  324|       |          // Performance note: our ability to compute 'consumed' and
  325|       |          // then shift and recompute is critical. If there is a
  326|       |          // latency of, say, 4 cycles on getting 'consumed', then
  327|       |          // the inner loop might have a total latency of about 6 cycles.
  328|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  329|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  330|       |          // for this section of the code. Hence, there is a limit
  331|       |          // to how much we can further increase this latency before
  332|       |          // it seriously harms performance.
  333|   564k|          size_t consumed = convert_masked_utf8_to_utf16<endian>(
  334|   564k|              in + pos, utf8_end_of_code_point_mask, utf16_output);
  335|   564k|          pos += consumed;
  336|   564k|          utf8_end_of_code_point_mask >>= consumed;
  337|   564k|        }
  338|       |        // At this point there may remain between 0 and 12 bytes in the
  339|       |        // 64-byte block. These bytes will be processed again. So we have an
  340|       |        // 80% efficiency (in the worst case). In practice we expect an
  341|       |        // 85% to 90% efficiency.
  342|  63.9k|      }
  343|   369k|    }
  344|    490|    const size_t ascii =
  345|    490|        convert_ascii_tail<endian>(in, pos, size, utf16_output);
  346|    490|    pos += ascii;
  347|    490|    utf16_output += ascii;
  348|    490|    if (pos == size) {
  ------------------
  |  Branch (348:9): [True: 80, False: 410]
  ------------------
  349|     80|      return result(error_code::SUCCESS, utf16_output - start);
  350|     80|    }
  351|       |    // rewind_and_convert_with_errors will seek a potential error from in+pos
  352|       |    // onward, with the ability to go back up to pos bytes, and read size-pos
  353|       |    // bytes forward.
  354|    410|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|    410|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
  355|    410|    result res = scalar::utf8_to_utf16::rewind_and_convert_with_errors<endian>(
  356|    410|        pos, in + pos, size - pos, utf16_output);
  357|    410|    if (res.error) { // In case of error, we want the error position
  ------------------
  |  Branch (357:9): [True: 268, False: 142]
  ------------------
  358|    268|      res.count += pos;
  359|    268|      return res;
  360|    268|    }
  361|       |    // In case of success, we want the number of words written
  362|    142|    utf16_output += res.count;
  363|    142|    return result(error_code::SUCCESS, utf16_output - start);
  364|    410|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1613convert_validILNS_10endiannessE0EEEmPKcmPDs:
   10|    344|                                         char16_t *utf16_output) noexcept {
   11|       |  // The implementation is not specific to haswell and should be moved to the
   12|       |  // generic directory.
   13|    344|  size_t pos = 0;
   14|    344|  char16_t *start{utf16_output};
   15|    344|  const size_t safety_margin = 16; // to avoid overruns!
   16|   454k|  while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (16:10): [True: 454k, False: 344]
  ------------------
   17|       |    // this loop could be unrolled further. For example, we could process the
   18|       |    // mask far more than 64 bytes.
   19|   454k|    simd8x64<int8_t> in(reinterpret_cast<const int8_t *>(input + pos));
   20|   454k|    if (in.is_ascii()) {
  ------------------
  |  Branch (20:9): [True: 276k, False: 178k]
  ------------------
   21|   276k|      in.store_ascii_as_utf16<endian>(utf16_output);
   22|   276k|      utf16_output += 64;
   23|   276k|      pos += 64;
   24|   276k|    } else {
   25|       |      // Slow path. We hope that the compiler will recognize that this is a slow
   26|       |      // path. Anything that is not a continuation mask is a 'leading byte',
   27|       |      // that is, the start of a new code point.
   28|   178k|      uint64_t utf8_continuation_mask = in.lt(-65 + 1);
   29|       |      // -65 is 0b10111111 in two-complement's, so largest possible continuation
   30|       |      // byte
   31|   178k|      uint64_t utf8_leading_mask = ~utf8_continuation_mask;
   32|       |      // The *start* of code points is not so useful, rather, we want the *end*
   33|       |      // of code points.
   34|   178k|      uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
   35|       |      // We process in blocks of up to 12 bytes except possibly
   36|       |      // for fast paths which may process up to 16 bytes. For the
   37|       |      // slow path to work, we should have at least 12 input bytes left.
   38|   178k|      size_t max_starting_point = (pos + 64) - 12;
   39|       |      // Next loop is going to run at least five times when using solely
   40|       |      // the slow/regular path, and at least four times if there are fast paths.
   41|  1.77M|      while (pos < max_starting_point) {
  ------------------
  |  Branch (41:14): [True: 1.59M, False: 178k]
  ------------------
   42|       |        // Performance note: our ability to compute 'consumed' and
   43|       |        // then shift and recompute is critical. If there is a
   44|       |        // latency of, say, 4 cycles on getting 'consumed', then
   45|       |        // the inner loop might have a total latency of about 6 cycles.
   46|       |        // Yet we process between 6 to 12 inputs bytes, thus we get
   47|       |        // a speed limit between 1 cycle/byte and 0.5 cycle/byte
   48|       |        // for this section of the code. Hence, there is a limit
   49|       |        // to how much we can further increase this latency before
   50|       |        // it seriously harms performance.
   51|       |        //
   52|       |        // Thus we may allow convert_masked_utf8_to_utf16 to process
   53|       |        // more bytes at a time under a fast-path mode where 16 bytes
   54|       |        // are consumed at once (e.g., when encountering ASCII).
   55|  1.59M|        size_t consumed = convert_masked_utf8_to_utf16<endian>(
   56|  1.59M|            input + pos, utf8_end_of_code_point_mask, utf16_output);
   57|  1.59M|        pos += consumed;
   58|  1.59M|        utf8_end_of_code_point_mask >>= consumed;
   59|  1.59M|      }
   60|       |      // At this point there may remain between 0 and 12 bytes in the
   61|       |      // 64-byte block. These bytes will be processed again. So we have an
   62|       |      // 80% efficiency (in the worst case). In practice we expect an
   63|       |      // 85% to 90% efficiency.
   64|   178k|    }
   65|   454k|  }
   66|    344|  utf16_output += scalar::utf8_to_utf16::convert_valid<endian>(
   67|    344|      input + pos, size - pos, utf16_output);
   68|    344|  return utf16_output - start;
   69|    344|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf1613convert_validILNS_10endiannessE1EEEmPKcmPDs:
   10|    456|                                         char16_t *utf16_output) noexcept {
   11|       |  // The implementation is not specific to haswell and should be moved to the
   12|       |  // generic directory.
   13|    456|  size_t pos = 0;
   14|    456|  char16_t *start{utf16_output};
   15|    456|  const size_t safety_margin = 16; // to avoid overruns!
   16|   408k|  while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (16:10): [True: 408k, False: 456]
  ------------------
   17|       |    // this loop could be unrolled further. For example, we could process the
   18|       |    // mask far more than 64 bytes.
   19|   408k|    simd8x64<int8_t> in(reinterpret_cast<const int8_t *>(input + pos));
   20|   408k|    if (in.is_ascii()) {
  ------------------
  |  Branch (20:9): [True: 326k, False: 81.8k]
  ------------------
   21|   326k|      in.store_ascii_as_utf16<endian>(utf16_output);
   22|   326k|      utf16_output += 64;
   23|   326k|      pos += 64;
   24|   326k|    } else {
   25|       |      // Slow path. We hope that the compiler will recognize that this is a slow
   26|       |      // path. Anything that is not a continuation mask is a 'leading byte',
   27|       |      // that is, the start of a new code point.
   28|  81.8k|      uint64_t utf8_continuation_mask = in.lt(-65 + 1);
   29|       |      // -65 is 0b10111111 in two-complement's, so largest possible continuation
   30|       |      // byte
   31|  81.8k|      uint64_t utf8_leading_mask = ~utf8_continuation_mask;
   32|       |      // The *start* of code points is not so useful, rather, we want the *end*
   33|       |      // of code points.
   34|  81.8k|      uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
   35|       |      // We process in blocks of up to 12 bytes except possibly
   36|       |      // for fast paths which may process up to 16 bytes. For the
   37|       |      // slow path to work, we should have at least 12 input bytes left.
   38|  81.8k|      size_t max_starting_point = (pos + 64) - 12;
   39|       |      // Next loop is going to run at least five times when using solely
   40|       |      // the slow/regular path, and at least four times if there are fast paths.
   41|   793k|      while (pos < max_starting_point) {
  ------------------
  |  Branch (41:14): [True: 711k, False: 81.8k]
  ------------------
   42|       |        // Performance note: our ability to compute 'consumed' and
   43|       |        // then shift and recompute is critical. If there is a
   44|       |        // latency of, say, 4 cycles on getting 'consumed', then
   45|       |        // the inner loop might have a total latency of about 6 cycles.
   46|       |        // Yet we process between 6 to 12 inputs bytes, thus we get
   47|       |        // a speed limit between 1 cycle/byte and 0.5 cycle/byte
   48|       |        // for this section of the code. Hence, there is a limit
   49|       |        // to how much we can further increase this latency before
   50|       |        // it seriously harms performance.
   51|       |        //
   52|       |        // Thus we may allow convert_masked_utf8_to_utf16 to process
   53|       |        // more bytes at a time under a fast-path mode where 16 bytes
   54|       |        // are consumed at once (e.g., when encountering ASCII).
   55|   711k|        size_t consumed = convert_masked_utf8_to_utf16<endian>(
   56|   711k|            input + pos, utf8_end_of_code_point_mask, utf16_output);
   57|   711k|        pos += consumed;
   58|   711k|        utf8_end_of_code_point_mask >>= consumed;
   59|   711k|      }
   60|       |      // At this point there may remain between 0 and 12 bytes in the
   61|       |      // 64-byte block. These bytes will be processed again. So we have an
   62|       |      // 80% efficiency (in the worst case). In practice we expect an
   63|       |      // 85% to 90% efficiency.
   64|  81.8k|    }
   65|   408k|  }
   66|    456|  utf16_output += scalar::utf8_to_utf16::convert_valid<endian>(
   67|    456|      input + pos, size - pos, utf16_output);
   68|    456|  return utf16_output - start;
   69|    456|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1613convert_validILNS_10endiannessE0EEEmPKcmPDs:
   10|    344|                                         char16_t *utf16_output) noexcept {
   11|       |  // The implementation is not specific to haswell and should be moved to the
   12|       |  // generic directory.
   13|    344|  size_t pos = 0;
   14|    344|  char16_t *start{utf16_output};
   15|    344|  const size_t safety_margin = 16; // to avoid overruns!
   16|   454k|  while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (16:10): [True: 454k, False: 344]
  ------------------
   17|       |    // this loop could be unrolled further. For example, we could process the
   18|       |    // mask far more than 64 bytes.
   19|   454k|    simd8x64<int8_t> in(reinterpret_cast<const int8_t *>(input + pos));
   20|   454k|    if (in.is_ascii()) {
  ------------------
  |  Branch (20:9): [True: 276k, False: 178k]
  ------------------
   21|   276k|      in.store_ascii_as_utf16<endian>(utf16_output);
   22|   276k|      utf16_output += 64;
   23|   276k|      pos += 64;
   24|   276k|    } else {
   25|       |      // Slow path. We hope that the compiler will recognize that this is a slow
   26|       |      // path. Anything that is not a continuation mask is a 'leading byte',
   27|       |      // that is, the start of a new code point.
   28|   178k|      uint64_t utf8_continuation_mask = in.lt(-65 + 1);
   29|       |      // -65 is 0b10111111 in two-complement's, so largest possible continuation
   30|       |      // byte
   31|   178k|      uint64_t utf8_leading_mask = ~utf8_continuation_mask;
   32|       |      // The *start* of code points is not so useful, rather, we want the *end*
   33|       |      // of code points.
   34|   178k|      uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
   35|       |      // We process in blocks of up to 12 bytes except possibly
   36|       |      // for fast paths which may process up to 16 bytes. For the
   37|       |      // slow path to work, we should have at least 12 input bytes left.
   38|   178k|      size_t max_starting_point = (pos + 64) - 12;
   39|       |      // Next loop is going to run at least five times when using solely
   40|       |      // the slow/regular path, and at least four times if there are fast paths.
   41|  1.77M|      while (pos < max_starting_point) {
  ------------------
  |  Branch (41:14): [True: 1.59M, False: 178k]
  ------------------
   42|       |        // Performance note: our ability to compute 'consumed' and
   43|       |        // then shift and recompute is critical. If there is a
   44|       |        // latency of, say, 4 cycles on getting 'consumed', then
   45|       |        // the inner loop might have a total latency of about 6 cycles.
   46|       |        // Yet we process between 6 to 12 inputs bytes, thus we get
   47|       |        // a speed limit between 1 cycle/byte and 0.5 cycle/byte
   48|       |        // for this section of the code. Hence, there is a limit
   49|       |        // to how much we can further increase this latency before
   50|       |        // it seriously harms performance.
   51|       |        //
   52|       |        // Thus we may allow convert_masked_utf8_to_utf16 to process
   53|       |        // more bytes at a time under a fast-path mode where 16 bytes
   54|       |        // are consumed at once (e.g., when encountering ASCII).
   55|  1.59M|        size_t consumed = convert_masked_utf8_to_utf16<endian>(
   56|  1.59M|            input + pos, utf8_end_of_code_point_mask, utf16_output);
   57|  1.59M|        pos += consumed;
   58|  1.59M|        utf8_end_of_code_point_mask >>= consumed;
   59|  1.59M|      }
   60|       |      // At this point there may remain between 0 and 12 bytes in the
   61|       |      // 64-byte block. These bytes will be processed again. So we have an
   62|       |      // 80% efficiency (in the worst case). In practice we expect an
   63|       |      // 85% to 90% efficiency.
   64|   178k|    }
   65|   454k|  }
   66|    344|  utf16_output += scalar::utf8_to_utf16::convert_valid<endian>(
   67|    344|      input + pos, size - pos, utf16_output);
   68|    344|  return utf16_output - start;
   69|    344|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf1613convert_validILNS_10endiannessE1EEEmPKcmPDs:
   10|    456|                                         char16_t *utf16_output) noexcept {
   11|       |  // The implementation is not specific to haswell and should be moved to the
   12|       |  // generic directory.
   13|    456|  size_t pos = 0;
   14|    456|  char16_t *start{utf16_output};
   15|    456|  const size_t safety_margin = 16; // to avoid overruns!
   16|   408k|  while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (16:10): [True: 408k, False: 456]
  ------------------
   17|       |    // this loop could be unrolled further. For example, we could process the
   18|       |    // mask far more than 64 bytes.
   19|   408k|    simd8x64<int8_t> in(reinterpret_cast<const int8_t *>(input + pos));
   20|   408k|    if (in.is_ascii()) {
  ------------------
  |  Branch (20:9): [True: 326k, False: 81.8k]
  ------------------
   21|   326k|      in.store_ascii_as_utf16<endian>(utf16_output);
   22|   326k|      utf16_output += 64;
   23|   326k|      pos += 64;
   24|   326k|    } else {
   25|       |      // Slow path. We hope that the compiler will recognize that this is a slow
   26|       |      // path. Anything that is not a continuation mask is a 'leading byte',
   27|       |      // that is, the start of a new code point.
   28|  81.8k|      uint64_t utf8_continuation_mask = in.lt(-65 + 1);
   29|       |      // -65 is 0b10111111 in two-complement's, so largest possible continuation
   30|       |      // byte
   31|  81.8k|      uint64_t utf8_leading_mask = ~utf8_continuation_mask;
   32|       |      // The *start* of code points is not so useful, rather, we want the *end*
   33|       |      // of code points.
   34|  81.8k|      uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
   35|       |      // We process in blocks of up to 12 bytes except possibly
   36|       |      // for fast paths which may process up to 16 bytes. For the
   37|       |      // slow path to work, we should have at least 12 input bytes left.
   38|  81.8k|      size_t max_starting_point = (pos + 64) - 12;
   39|       |      // Next loop is going to run at least five times when using solely
   40|       |      // the slow/regular path, and at least four times if there are fast paths.
   41|   793k|      while (pos < max_starting_point) {
  ------------------
  |  Branch (41:14): [True: 711k, False: 81.8k]
  ------------------
   42|       |        // Performance note: our ability to compute 'consumed' and
   43|       |        // then shift and recompute is critical. If there is a
   44|       |        // latency of, say, 4 cycles on getting 'consumed', then
   45|       |        // the inner loop might have a total latency of about 6 cycles.
   46|       |        // Yet we process between 6 to 12 inputs bytes, thus we get
   47|       |        // a speed limit between 1 cycle/byte and 0.5 cycle/byte
   48|       |        // for this section of the code. Hence, there is a limit
   49|       |        // to how much we can further increase this latency before
   50|       |        // it seriously harms performance.
   51|       |        //
   52|       |        // Thus we may allow convert_masked_utf8_to_utf16 to process
   53|       |        // more bytes at a time under a fast-path mode where 16 bytes
   54|       |        // are consumed at once (e.g., when encountering ASCII).
   55|   711k|        size_t consumed = convert_masked_utf8_to_utf16<endian>(
   56|   711k|            input + pos, utf8_end_of_code_point_mask, utf16_output);
   57|   711k|        pos += consumed;
   58|   711k|        utf8_end_of_code_point_mask >>= consumed;
   59|   711k|      }
   60|       |      // At this point there may remain between 0 and 12 bytes in the
   61|       |      // 64-byte block. These bytes will be processed again. So we have an
   62|       |      // 80% efficiency (in the worst case). In practice we expect an
   63|       |      // 85% to 90% efficiency.
   64|  81.8k|    }
   65|   408k|  }
   66|    456|  utf16_output += scalar::utf8_to_utf16::convert_valid<endian>(
   67|    456|      input + pos, size - pos, utf16_output);
   68|    456|  return utf16_output - start;
   69|    456|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoderC2Ev:
  114|  1.86k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoder7convertEPKcmPDi:
  161|    950|                                       char32_t *utf32_output) {
  162|    950|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (162:9): [True: 334, False: 616]
  ------------------
  163|    334|      return scalar::utf8_to_utf32::convert(in, size, utf32_output);
  164|    334|    }
  165|    616|    size_t pos = 0;
  166|    616|    char32_t *start{utf32_output};
  167|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  168|       |    // of 8 words when calling convert_masked_utf8_to_utf32. If you skip the
  169|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  170|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  171|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  172|       |    // back from the end counting 16 leading bytes, to give us a good margin.
  173|    616|    size_t leading_byte = 0;
  174|    616|    size_t margin = size;
  175|  9.41k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (175:12): [True: 9.40k, False: 14]
  |  Branch (175:26): [True: 8.80k, False: 602]
  ------------------
  176|  8.80k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  177|  8.80k|    }
  178|       |    // If the input is long enough, then we have that margin-1 is the fourth
  179|       |    // last leading byte.
  180|    616|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  181|   723k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (181:12): [True: 722k, False: 586]
  ------------------
  182|   722k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  183|   722k|      if (input.is_ascii()) {
  ------------------
  |  Branch (183:11): [True: 438k, False: 284k]
  ------------------
  184|   438k|        input.store_ascii_as_utf32(utf32_output);
  185|   438k|        utf32_output += 64;
  186|   438k|        pos += 64;
  187|   438k|      } else {
  188|       |        // you might think that a for-loop would work, but under Visual Studio,
  189|       |        // it is not good enough.
  190|   284k|        static_assert(
  191|   284k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  192|   284k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  193|   284k|            "We support either two or four chunks per 64-byte block.");
  194|   284k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  195|   284k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  196|   284k|          this->check_utf8_bytes(input.chunks[0], zero);
  197|   284k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  198|       |        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  199|       |          this->check_utf8_bytes(input.chunks[0], zero);
  200|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  201|       |          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  202|       |          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  203|       |        }
  204|   284k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  205|   284k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (205:13): [True: 30, False: 284k]
  ------------------
  206|     30|          return 0; // we have an error
  207|     30|        }
  208|   284k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  209|   284k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  210|       |        // We process in blocks of up to 12 bytes except possibly
  211|       |        // for fast paths which may process up to 16 bytes. For the
  212|       |        // slow path to work, we should have at least 12 input bytes left.
  213|   284k|        size_t max_starting_point = (pos + 64) - 12;
  214|       |        // Next loop is going to run at least five times.
  215|  2.83M|        while (pos < max_starting_point) {
  ------------------
  |  Branch (215:16): [True: 2.54M, False: 284k]
  ------------------
  216|       |          // Performance note: our ability to compute 'consumed' and
  217|       |          // then shift and recompute is critical. If there is a
  218|       |          // latency of, say, 4 cycles on getting 'consumed', then
  219|       |          // the inner loop might have a total latency of about 6 cycles.
  220|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  221|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  222|       |          // for this section of the code. Hence, there is a limit
  223|       |          // to how much we can further increase this latency before
  224|       |          // it seriously harms performance.
  225|  2.54M|          size_t consumed = convert_masked_utf8_to_utf32(
  226|  2.54M|              in + pos, utf8_end_of_code_point_mask, utf32_output);
  227|  2.54M|          pos += consumed;
  228|  2.54M|          utf8_end_of_code_point_mask >>= consumed;
  229|  2.54M|        }
  230|       |        // At this point there may remain between 0 and 12 bytes in the
  231|       |        // 64-byte block. These bytes will be processed again. So we have an
  232|       |        // 80% efficiency (in the worst case). In practice we expect an
  233|       |        // 85% to 90% efficiency.
  234|   284k|      }
  235|   722k|    }
  236|    586|    if (errors()) {
  ------------------
  |  Branch (236:9): [True: 330, False: 256]
  ------------------
  237|    330|      return 0;
  238|    330|    }
  239|    256|    const size_t ascii = convert_ascii_tail(in, pos, size, utf32_output);
  240|    256|    pos += ascii;
  241|    256|    utf32_output += ascii;
  242|    256|    if (pos == size) {
  ------------------
  |  Branch (242:9): [True: 60, False: 196]
  ------------------
  243|     60|      return utf32_output - start;
  244|     60|    }
  245|    196|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|    196|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
  246|    196|    size_t howmany =
  247|    196|        scalar::utf8_to_utf32::convert(in + pos, size - pos, utf32_output);
  248|    196|    if (howmany == 0) {
  ------------------
  |  Branch (248:9): [True: 162, False: 34]
  ------------------
  249|    162|      return 0;
  250|    162|    }
  251|     34|    return utf32_output + howmany - start;
  252|    196|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  119|   704k|                                              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|   704k|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  124|   704k|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  125|   704k|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  126|   704k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3219check_special_casesENS1_4simd5simd8IhEES5_:
    8|   704k|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|   704k|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   16|       |                                               // 11______ 11______
   17|   704k|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   18|   704k|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   19|   704k|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   20|   704k|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   21|   704k|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   22|   704k|  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|   704k|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   31|       |  // 11110101 1000____
   32|       |  // 1111011_ 1000____
   33|       |  // 11111___ 1000____
   34|   704k|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   35|       |
   36|   704k|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   37|       |      // 0_______ ________ <ASCII in byte 1>
   38|   704k|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   39|   704k|      TOO_LONG,
   40|       |      // 10______ ________ <continuation in byte 1>
   41|   704k|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   42|       |      // 1100____ ________ <two byte lead in byte 1>
   43|   704k|      TOO_SHORT | OVERLONG_2,
   44|       |      // 1101____ ________ <two byte lead in byte 1>
   45|   704k|      TOO_SHORT,
   46|       |      // 1110____ ________ <three byte lead in byte 1>
   47|   704k|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   48|       |      // 1111____ ________ <four+ byte lead in byte 1>
   49|   704k|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   50|   704k|  constexpr const uint8_t CARRY =
   51|   704k|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   52|   704k|  const simd8<uint8_t> byte_1_low =
   53|   704k|      (prev1 & 0x0F)
   54|   704k|          .lookup_16<uint8_t>(
   55|       |              // ____0000 ________
   56|   704k|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   57|       |              // ____0001 ________
   58|   704k|              CARRY | OVERLONG_2,
   59|       |              // ____001_ ________
   60|   704k|              CARRY, CARRY,
   61|       |
   62|       |              // ____0100 ________
   63|   704k|              CARRY | TOO_LARGE,
   64|       |              // ____0101 ________
   65|   704k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   66|       |              // ____011_ ________
   67|   704k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   68|   704k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|       |
   70|       |              // ____1___ ________
   71|   704k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   72|   704k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|   704k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|   704k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|   704k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|       |              // ____1101 ________
   77|   704k|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   78|   704k|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   79|   704k|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   80|   704k|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   81|       |      // ________ 0_______ <ASCII in byte 2>
   82|   704k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   83|   704k|      TOO_SHORT, TOO_SHORT,
   84|       |
   85|       |      // ________ 1000____
   86|   704k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   87|   704k|          OVERLONG_4,
   88|       |      // ________ 1001____
   89|   704k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   90|       |      // ________ 101_____
   91|   704k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   92|   704k|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|       |
   94|       |      // ________ 11______
   95|   704k|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   96|   704k|  return (byte_1_high & byte_1_low & byte_2_high);
   97|   704k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3223check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  101|   704k|                        const simd8<uint8_t> sc) {
  102|   704k|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  103|   704k|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  104|   704k|  simd8<uint8_t> must23 =
  105|   704k|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  106|   704k|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  107|   704k|  return must23_80 ^ sc;
  108|   704k|}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoder6errorsEv:
  355|  68.4k|  simdutf_really_inline bool errors() const {
  356|  68.4k|    return this->error.any_bits_set_anywhere();
  357|  68.4k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoder18convert_ascii_tailEPKcmmPDi:
  130|    752|                                                  char32_t *output) {
  131|       |    // A cheap test on the first bytes avoids any SIMD work for most non-ASCII
  132|       |    // tails.
  133|    752|    if (size - pos >= 8) {
  ------------------
  |  Branch (133:9): [True: 752, False: 0]
  ------------------
  134|    752|      uint64_t first_bytes;
  135|    752|      std::memcpy(&first_bytes, in + pos, 8);
  136|    752|      if (first_bytes & 0x8080808080808080) {
  ------------------
  |  Branch (136:11): [True: 204, False: 548]
  ------------------
  137|    204|        return 0;
  138|    204|      }
  139|    752|    }
  140|    548|    const size_t start = pos;
  141|    610|    while (pos + 64 <= size) {
  ------------------
  |  Branch (141:12): [True: 252, False: 358]
  ------------------
  142|    252|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  143|    252|      if (!input.is_ascii()) {
  ------------------
  |  Branch (143:11): [True: 190, False: 62]
  ------------------
  144|    190|        return pos - start;
  145|    190|      }
  146|     62|      input.store_ascii_as_utf32(output + (pos - start));
  147|     62|      pos += 64;
  148|     62|    }
  149|    358|    if (pos == size || size < 64) {
  ------------------
  |  Branch (149:9): [True: 26, False: 332]
  |  Branch (149:24): [True: 0, False: 332]
  ------------------
  150|     26|      return pos - start;
  151|     26|    }
  152|    332|    simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + size - 64));
  153|    332|    if (!input.is_ascii()) {
  ------------------
  |  Branch (153:9): [True: 210, False: 122]
  ------------------
  154|    210|      return pos - start;
  155|    210|    }
  156|    122|    input.store_ascii_as_utf32(output + (pos - start) - (pos - (size - 64)));
  157|    122|    return size - start;
  158|    332|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3221validating_transcoder19convert_with_errorsEPKcmPDi:
  255|    918|                                                   char32_t *utf32_output) {
  256|    918|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (256:9): [True: 310, False: 608]
  ------------------
  257|    310|      return scalar::utf8_to_utf32::convert_with_errors(in, size, utf32_output);
  258|    310|    }
  259|    608|    size_t pos = 0;
  260|    608|    char32_t *start{utf32_output};
  261|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  262|       |    // of 8 bytes when calling convert_masked_utf8_to_utf32. If you skip the
  263|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  264|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  265|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  266|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  267|    608|    size_t leading_byte = 0;
  268|    608|    size_t margin = size;
  269|  8.13k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (269:12): [True: 8.11k, False: 16]
  |  Branch (269:26): [True: 7.52k, False: 592]
  ------------------
  270|  7.52k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  271|  7.52k|    }
  272|       |    // If the input is long enough, then we have that margin-1 is the fourth
  273|       |    // last leading byte.
  274|    608|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  275|   519k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (275:12): [True: 518k, False: 496]
  ------------------
  276|   518k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  277|   518k|      if (input.is_ascii()) {
  ------------------
  |  Branch (277:11): [True: 450k, False: 67.9k]
  ------------------
  278|   450k|        input.store_ascii_as_utf32(utf32_output);
  279|   450k|        utf32_output += 64;
  280|   450k|        pos += 64;
  281|   450k|      } else {
  282|       |        // you might think that a for-loop would work, but under Visual Studio,
  283|       |        // it is not good enough.
  284|  67.9k|        static_assert(
  285|  67.9k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  286|  67.9k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  287|  67.9k|            "We support either two or four chunks per 64-byte block.");
  288|  67.9k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  289|  67.9k|        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  290|  67.9k|          this->check_utf8_bytes(input.chunks[0], zero);
  291|  67.9k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  292|       |        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  293|       |          this->check_utf8_bytes(input.chunks[0], zero);
  294|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  295|       |          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  296|       |          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  297|       |        }
  298|  67.9k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  299|  67.9k|        if (errors() || (utf8_continuation_mask & 1)) {
  ------------------
  |  Branch (299:13): [True: 112, False: 67.7k]
  |  Branch (299:25): [True: 0, False: 67.7k]
  ------------------
  300|    112|          SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|    112|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
  301|    112|          result res = scalar::utf8_to_utf32::rewind_and_convert_with_errors(
  302|    112|              pos, in + pos, size - pos, utf32_output);
  303|    112|          res.count += pos;
  304|    112|          return res;
  305|    112|        }
  306|  67.7k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  307|  67.7k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  308|       |        // We process in blocks of up to 12 bytes except possibly
  309|       |        // for fast paths which may process up to 16 bytes. For the
  310|       |        // slow path to work, we should have at least 12 input bytes left.
  311|  67.7k|        size_t max_starting_point = (pos + 64) - 12;
  312|       |        // Next loop is going to run at least five times.
  313|   631k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (313:16): [True: 563k, False: 67.7k]
  ------------------
  314|       |          // Performance note: our ability to compute 'consumed' and
  315|       |          // then shift and recompute is critical. If there is a
  316|       |          // latency of, say, 4 cycles on getting 'consumed', then
  317|       |          // the inner loop might have a total latency of about 6 cycles.
  318|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  319|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  320|       |          // for this section of the code. Hence, there is a limit
  321|       |          // to how much we can further increase this latency before
  322|       |          // it seriously harms performance.
  323|   563k|          size_t consumed = convert_masked_utf8_to_utf32(
  324|   563k|              in + pos, utf8_end_of_code_point_mask, utf32_output);
  325|   563k|          pos += consumed;
  326|   563k|          utf8_end_of_code_point_mask >>= consumed;
  327|   563k|        }
  328|       |        // At this point there may remain between 0 and 12 bytes in the
  329|       |        // 64-byte block. These bytes will be processed again. So we have an
  330|       |        // 80% efficiency (in the worst case). In practice we expect an
  331|       |        // 85% to 90% efficiency.
  332|  67.7k|      }
  333|   518k|    }
  334|    496|    const size_t ascii = convert_ascii_tail(in, pos, size, utf32_output);
  335|    496|    pos += ascii;
  336|    496|    utf32_output += ascii;
  337|    496|    if (pos == size) {
  ------------------
  |  Branch (337:9): [True: 88, False: 408]
  ------------------
  338|     88|      return result(error_code::SUCCESS, utf32_output - start);
  339|     88|    }
  340|       |    // rewind_and_convert_with_errors will seek a potential error from in+pos
  341|       |    // onward, with the ability to go back up to pos bytes, and read size-pos
  342|       |    // bytes forward.
  343|    408|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|    408|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
  344|    408|    result res = scalar::utf8_to_utf32::rewind_and_convert_with_errors(
  345|    408|        pos, in + pos, size - pos, utf32_output);
  346|    408|    if (res.error) { // In case of error, we want the error position
  ------------------
  |  Branch (346:9): [True: 298, False: 110]
  ------------------
  347|    298|      res.count += pos;
  348|    298|      return res;
  349|    298|    }
  350|       |    // In case of success, we want the number of words written
  351|    110|    utf32_output += res.count;
  352|    110|    return result(error_code::SUCCESS, utf32_output - start);
  353|    408|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoderC2Ev:
  114|  1.86k|  validating_transcoder() : error(uint8_t(0)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoder7convertEPKcmPDi:
  161|    950|                                       char32_t *utf32_output) {
  162|    950|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (162:9): [True: 334, False: 616]
  ------------------
  163|    334|      return scalar::utf8_to_utf32::convert(in, size, utf32_output);
  164|    334|    }
  165|    616|    size_t pos = 0;
  166|    616|    char32_t *start{utf32_output};
  167|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  168|       |    // of 8 words when calling convert_masked_utf8_to_utf32. If you skip the
  169|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  170|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  171|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  172|       |    // back from the end counting 16 leading bytes, to give us a good margin.
  173|    616|    size_t leading_byte = 0;
  174|    616|    size_t margin = size;
  175|  9.41k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (175:12): [True: 9.40k, False: 14]
  |  Branch (175:26): [True: 8.80k, False: 602]
  ------------------
  176|  8.80k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  177|  8.80k|    }
  178|       |    // If the input is long enough, then we have that margin-1 is the fourth
  179|       |    // last leading byte.
  180|    616|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  181|   723k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (181:12): [True: 722k, False: 586]
  ------------------
  182|   722k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  183|   722k|      if (input.is_ascii()) {
  ------------------
  |  Branch (183:11): [True: 438k, False: 284k]
  ------------------
  184|   438k|        input.store_ascii_as_utf32(utf32_output);
  185|   438k|        utf32_output += 64;
  186|   438k|        pos += 64;
  187|   438k|      } else {
  188|       |        // you might think that a for-loop would work, but under Visual Studio,
  189|       |        // it is not good enough.
  190|   284k|        static_assert(
  191|   284k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  192|   284k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  193|   284k|            "We support either two or four chunks per 64-byte block.");
  194|   284k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  195|       |        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  196|       |          this->check_utf8_bytes(input.chunks[0], zero);
  197|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  198|   284k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  199|   284k|          this->check_utf8_bytes(input.chunks[0], zero);
  200|   284k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  201|   284k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  202|   284k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  203|   284k|        }
  204|   284k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  205|   284k|        if (utf8_continuation_mask & 1) {
  ------------------
  |  Branch (205:13): [True: 30, False: 284k]
  ------------------
  206|     30|          return 0; // we have an error
  207|     30|        }
  208|   284k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  209|   284k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  210|       |        // We process in blocks of up to 12 bytes except possibly
  211|       |        // for fast paths which may process up to 16 bytes. For the
  212|       |        // slow path to work, we should have at least 12 input bytes left.
  213|   284k|        size_t max_starting_point = (pos + 64) - 12;
  214|       |        // Next loop is going to run at least five times.
  215|  2.83M|        while (pos < max_starting_point) {
  ------------------
  |  Branch (215:16): [True: 2.54M, False: 284k]
  ------------------
  216|       |          // Performance note: our ability to compute 'consumed' and
  217|       |          // then shift and recompute is critical. If there is a
  218|       |          // latency of, say, 4 cycles on getting 'consumed', then
  219|       |          // the inner loop might have a total latency of about 6 cycles.
  220|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  221|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  222|       |          // for this section of the code. Hence, there is a limit
  223|       |          // to how much we can further increase this latency before
  224|       |          // it seriously harms performance.
  225|  2.54M|          size_t consumed = convert_masked_utf8_to_utf32(
  226|  2.54M|              in + pos, utf8_end_of_code_point_mask, utf32_output);
  227|  2.54M|          pos += consumed;
  228|  2.54M|          utf8_end_of_code_point_mask >>= consumed;
  229|  2.54M|        }
  230|       |        // At this point there may remain between 0 and 12 bytes in the
  231|       |        // 64-byte block. These bytes will be processed again. So we have an
  232|       |        // 80% efficiency (in the worst case). In practice we expect an
  233|       |        // 85% to 90% efficiency.
  234|   284k|      }
  235|   722k|    }
  236|    586|    if (errors()) {
  ------------------
  |  Branch (236:9): [True: 330, False: 256]
  ------------------
  237|    330|      return 0;
  238|    330|    }
  239|    256|    const size_t ascii = convert_ascii_tail(in, pos, size, utf32_output);
  240|    256|    pos += ascii;
  241|    256|    utf32_output += ascii;
  242|    256|    if (pos == size) {
  ------------------
  |  Branch (242:9): [True: 60, False: 196]
  ------------------
  243|     60|      return utf32_output - start;
  244|     60|    }
  245|    196|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|    196|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
  246|    196|    size_t howmany =
  247|    196|        scalar::utf8_to_utf32::convert(in + pos, size - pos, utf32_output);
  248|    196|    if (howmany == 0) {
  ------------------
  |  Branch (248:9): [True: 162, False: 34]
  ------------------
  249|    162|      return 0;
  250|    162|    }
  251|     34|    return utf32_output + howmany - start;
  252|    196|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoder16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  119|  1.40M|                                              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|  1.40M|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  124|  1.40M|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  125|  1.40M|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  126|  1.40M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3219check_special_casesENS1_4simd5simd8IhEES5_:
    8|  1.40M|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|  1.40M|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   16|       |                                               // 11______ 11______
   17|  1.40M|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   18|  1.40M|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   19|  1.40M|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   20|  1.40M|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   21|  1.40M|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   22|  1.40M|  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|  1.40M|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   31|       |  // 11110101 1000____
   32|       |  // 1111011_ 1000____
   33|       |  // 11111___ 1000____
   34|  1.40M|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   35|       |
   36|  1.40M|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   37|       |      // 0_______ ________ <ASCII in byte 1>
   38|  1.40M|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   39|  1.40M|      TOO_LONG,
   40|       |      // 10______ ________ <continuation in byte 1>
   41|  1.40M|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   42|       |      // 1100____ ________ <two byte lead in byte 1>
   43|  1.40M|      TOO_SHORT | OVERLONG_2,
   44|       |      // 1101____ ________ <two byte lead in byte 1>
   45|  1.40M|      TOO_SHORT,
   46|       |      // 1110____ ________ <three byte lead in byte 1>
   47|  1.40M|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   48|       |      // 1111____ ________ <four+ byte lead in byte 1>
   49|  1.40M|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   50|  1.40M|  constexpr const uint8_t CARRY =
   51|  1.40M|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   52|  1.40M|  const simd8<uint8_t> byte_1_low =
   53|  1.40M|      (prev1 & 0x0F)
   54|  1.40M|          .lookup_16<uint8_t>(
   55|       |              // ____0000 ________
   56|  1.40M|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   57|       |              // ____0001 ________
   58|  1.40M|              CARRY | OVERLONG_2,
   59|       |              // ____001_ ________
   60|  1.40M|              CARRY, CARRY,
   61|       |
   62|       |              // ____0100 ________
   63|  1.40M|              CARRY | TOO_LARGE,
   64|       |              // ____0101 ________
   65|  1.40M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   66|       |              // ____011_ ________
   67|  1.40M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   68|  1.40M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|       |
   70|       |              // ____1___ ________
   71|  1.40M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   72|  1.40M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  1.40M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  1.40M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  1.40M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|       |              // ____1101 ________
   77|  1.40M|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   78|  1.40M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   79|  1.40M|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   80|  1.40M|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   81|       |      // ________ 0_______ <ASCII in byte 2>
   82|  1.40M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   83|  1.40M|      TOO_SHORT, TOO_SHORT,
   84|       |
   85|       |      // ________ 1000____
   86|  1.40M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   87|  1.40M|          OVERLONG_4,
   88|       |      // ________ 1001____
   89|  1.40M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   90|       |      // ________ 101_____
   91|  1.40M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   92|  1.40M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|       |
   94|       |      // ________ 11______
   95|  1.40M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   96|  1.40M|  return (byte_1_high & byte_1_low & byte_2_high);
   97|  1.40M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3223check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  101|  1.40M|                        const simd8<uint8_t> sc) {
  102|  1.40M|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  103|  1.40M|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  104|  1.40M|  simd8<uint8_t> must23 =
  105|  1.40M|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  106|  1.40M|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  107|  1.40M|  return must23_80 ^ sc;
  108|  1.40M|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoder6errorsEv:
  355|  68.4k|  simdutf_really_inline bool errors() const {
  356|  68.4k|    return this->error.any_bits_set_anywhere();
  357|  68.4k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoder18convert_ascii_tailEPKcmmPDi:
  130|    752|                                                  char32_t *output) {
  131|       |    // A cheap test on the first bytes avoids any SIMD work for most non-ASCII
  132|       |    // tails.
  133|    752|    if (size - pos >= 8) {
  ------------------
  |  Branch (133:9): [True: 752, False: 0]
  ------------------
  134|    752|      uint64_t first_bytes;
  135|    752|      std::memcpy(&first_bytes, in + pos, 8);
  136|    752|      if (first_bytes & 0x8080808080808080) {
  ------------------
  |  Branch (136:11): [True: 204, False: 548]
  ------------------
  137|    204|        return 0;
  138|    204|      }
  139|    752|    }
  140|    548|    const size_t start = pos;
  141|    610|    while (pos + 64 <= size) {
  ------------------
  |  Branch (141:12): [True: 252, False: 358]
  ------------------
  142|    252|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  143|    252|      if (!input.is_ascii()) {
  ------------------
  |  Branch (143:11): [True: 190, False: 62]
  ------------------
  144|    190|        return pos - start;
  145|    190|      }
  146|     62|      input.store_ascii_as_utf32(output + (pos - start));
  147|     62|      pos += 64;
  148|     62|    }
  149|    358|    if (pos == size || size < 64) {
  ------------------
  |  Branch (149:9): [True: 26, False: 332]
  |  Branch (149:24): [True: 0, False: 332]
  ------------------
  150|     26|      return pos - start;
  151|     26|    }
  152|    332|    simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + size - 64));
  153|    332|    if (!input.is_ascii()) {
  ------------------
  |  Branch (153:9): [True: 210, False: 122]
  ------------------
  154|    210|      return pos - start;
  155|    210|    }
  156|    122|    input.store_ascii_as_utf32(output + (pos - start) - (pos - (size - 64)));
  157|    122|    return size - start;
  158|    332|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3221validating_transcoder19convert_with_errorsEPKcmPDi:
  255|    918|                                                   char32_t *utf32_output) {
  256|    918|    if (size < 64) { // too short for the main loop
  ------------------
  |  Branch (256:9): [True: 310, False: 608]
  ------------------
  257|    310|      return scalar::utf8_to_utf32::convert_with_errors(in, size, utf32_output);
  258|    310|    }
  259|    608|    size_t pos = 0;
  260|    608|    char32_t *start{utf32_output};
  261|       |    // In the worst case, we have the haswell kernel which can cause an overflow
  262|       |    // of 8 bytes when calling convert_masked_utf8_to_utf32. If you skip the
  263|       |    // last 16 bytes, and if the data is valid, then it is entirely safe because
  264|       |    // 16 UTF-8 bytes generate much more than 8 bytes. However, you cannot
  265|       |    // generally assume that you have valid UTF-8 input, so we are going to go
  266|       |    // back from the end counting 8 leading bytes, to give us a good margin.
  267|    608|    size_t leading_byte = 0;
  268|    608|    size_t margin = size;
  269|  8.13k|    for (; margin > 0 && leading_byte < 8; margin--) {
  ------------------
  |  Branch (269:12): [True: 8.11k, False: 16]
  |  Branch (269:26): [True: 7.52k, False: 592]
  ------------------
  270|  7.52k|      leading_byte += (int8_t(in[margin - 1]) > -65);
  271|  7.52k|    }
  272|       |    // If the input is long enough, then we have that margin-1 is the fourth
  273|       |    // last leading byte.
  274|    608|    const size_t safety_margin = size - margin + 1; // to avoid overruns!
  275|   519k|    while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (275:12): [True: 518k, False: 496]
  ------------------
  276|   518k|      simd8x64<int8_t> input(reinterpret_cast<const int8_t *>(in + pos));
  277|   518k|      if (input.is_ascii()) {
  ------------------
  |  Branch (277:11): [True: 450k, False: 67.9k]
  ------------------
  278|   450k|        input.store_ascii_as_utf32(utf32_output);
  279|   450k|        utf32_output += 64;
  280|   450k|        pos += 64;
  281|   450k|      } else {
  282|       |        // you might think that a for-loop would work, but under Visual Studio,
  283|       |        // it is not good enough.
  284|  67.9k|        static_assert(
  285|  67.9k|            (simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  286|  67.9k|                (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  287|  67.9k|            "We support either two or four chunks per 64-byte block.");
  288|  67.9k|        auto zero = simd8<uint8_t>{uint8_t(0)};
  289|       |        if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  290|       |          this->check_utf8_bytes(input.chunks[0], zero);
  291|       |          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  292|  67.9k|        } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  293|  67.9k|          this->check_utf8_bytes(input.chunks[0], zero);
  294|  67.9k|          this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  295|  67.9k|          this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  296|  67.9k|          this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  297|  67.9k|        }
  298|  67.9k|        uint64_t utf8_continuation_mask = input.lt(-65 + 1);
  299|  67.9k|        if (errors() || (utf8_continuation_mask & 1)) {
  ------------------
  |  Branch (299:13): [True: 112, False: 67.7k]
  |  Branch (299:25): [True: 0, False: 67.7k]
  ------------------
  300|    112|          SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|    112|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
  301|    112|          result res = scalar::utf8_to_utf32::rewind_and_convert_with_errors(
  302|    112|              pos, in + pos, size - pos, utf32_output);
  303|    112|          res.count += pos;
  304|    112|          return res;
  305|    112|        }
  306|  67.7k|        uint64_t utf8_leading_mask = ~utf8_continuation_mask;
  307|  67.7k|        uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
  308|       |        // We process in blocks of up to 12 bytes except possibly
  309|       |        // for fast paths which may process up to 16 bytes. For the
  310|       |        // slow path to work, we should have at least 12 input bytes left.
  311|  67.7k|        size_t max_starting_point = (pos + 64) - 12;
  312|       |        // Next loop is going to run at least five times.
  313|   631k|        while (pos < max_starting_point) {
  ------------------
  |  Branch (313:16): [True: 563k, False: 67.7k]
  ------------------
  314|       |          // Performance note: our ability to compute 'consumed' and
  315|       |          // then shift and recompute is critical. If there is a
  316|       |          // latency of, say, 4 cycles on getting 'consumed', then
  317|       |          // the inner loop might have a total latency of about 6 cycles.
  318|       |          // Yet we process between 6 to 12 inputs bytes, thus we get
  319|       |          // a speed limit between 1 cycle/byte and 0.5 cycle/byte
  320|       |          // for this section of the code. Hence, there is a limit
  321|       |          // to how much we can further increase this latency before
  322|       |          // it seriously harms performance.
  323|   563k|          size_t consumed = convert_masked_utf8_to_utf32(
  324|   563k|              in + pos, utf8_end_of_code_point_mask, utf32_output);
  325|   563k|          pos += consumed;
  326|   563k|          utf8_end_of_code_point_mask >>= consumed;
  327|   563k|        }
  328|       |        // At this point there may remain between 0 and 12 bytes in the
  329|       |        // 64-byte block. These bytes will be processed again. So we have an
  330|       |        // 80% efficiency (in the worst case). In practice we expect an
  331|       |        // 85% to 90% efficiency.
  332|  67.7k|      }
  333|   518k|    }
  334|    496|    const size_t ascii = convert_ascii_tail(in, pos, size, utf32_output);
  335|    496|    pos += ascii;
  336|    496|    utf32_output += ascii;
  337|    496|    if (pos == size) {
  ------------------
  |  Branch (337:9): [True: 88, False: 408]
  ------------------
  338|     88|      return result(error_code::SUCCESS, utf32_output - start);
  339|     88|    }
  340|       |    // rewind_and_convert_with_errors will seek a potential error from in+pos
  341|       |    // onward, with the ability to go back up to pos bytes, and read size-pos
  342|       |    // bytes forward.
  343|    408|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|    408|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
  344|    408|    result res = scalar::utf8_to_utf32::rewind_and_convert_with_errors(
  345|    408|        pos, in + pos, size - pos, utf32_output);
  346|    408|    if (res.error) { // In case of error, we want the error position
  ------------------
  |  Branch (346:9): [True: 298, False: 110]
  ------------------
  347|    298|      res.count += pos;
  348|    298|      return res;
  349|    298|    }
  350|       |    // In case of success, we want the number of words written
  351|    110|    utf32_output += res.count;
  352|    110|    return result(error_code::SUCCESS, utf32_output - start);
  353|    408|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_113utf8_to_utf3213convert_validEPKcmPDi:
    9|    512|                                         char32_t *utf32_output) noexcept {
   10|    512|  size_t pos = 0;
   11|    512|  char32_t *start{utf32_output};
   12|    512|  const size_t safety_margin = 16; // to avoid overruns!
   13|   472k|  while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (13:10): [True: 472k, False: 512]
  ------------------
   14|   472k|    simd8x64<int8_t> in(reinterpret_cast<const int8_t *>(input + pos));
   15|   472k|    if (in.is_ascii()) {
  ------------------
  |  Branch (15:9): [True: 405k, False: 66.9k]
  ------------------
   16|   405k|      in.store_ascii_as_utf32(utf32_output);
   17|   405k|      utf32_output += 64;
   18|   405k|      pos += 64;
   19|   405k|    } else {
   20|       |      // -65 is 0b10111111 in two-complement's, so largest possible continuation
   21|       |      // byte
   22|  66.9k|      uint64_t utf8_continuation_mask = in.lt(-65 + 1);
   23|  66.9k|      uint64_t utf8_leading_mask = ~utf8_continuation_mask;
   24|  66.9k|      uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
   25|  66.9k|      size_t max_starting_point = (pos + 64) - 12;
   26|   646k|      while (pos < max_starting_point) {
  ------------------
  |  Branch (26:14): [True: 579k, False: 66.9k]
  ------------------
   27|   579k|        size_t consumed = convert_masked_utf8_to_utf32(
   28|   579k|            input + pos, utf8_end_of_code_point_mask, utf32_output);
   29|   579k|        pos += consumed;
   30|   579k|        utf8_end_of_code_point_mask >>= consumed;
   31|   579k|      }
   32|  66.9k|    }
   33|   472k|  }
   34|    512|  utf32_output += scalar::utf8_to_utf32::convert_valid(input + pos, size - pos,
   35|    512|                                                       utf32_output);
   36|    512|  return utf32_output - start;
   37|    512|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_113utf8_to_utf3213convert_validEPKcmPDi:
    9|    512|                                         char32_t *utf32_output) noexcept {
   10|    512|  size_t pos = 0;
   11|    512|  char32_t *start{utf32_output};
   12|    512|  const size_t safety_margin = 16; // to avoid overruns!
   13|   472k|  while (pos + 64 + safety_margin <= size) {
  ------------------
  |  Branch (13:10): [True: 472k, False: 512]
  ------------------
   14|   472k|    simd8x64<int8_t> in(reinterpret_cast<const int8_t *>(input + pos));
   15|   472k|    if (in.is_ascii()) {
  ------------------
  |  Branch (15:9): [True: 405k, False: 66.9k]
  ------------------
   16|   405k|      in.store_ascii_as_utf32(utf32_output);
   17|   405k|      utf32_output += 64;
   18|   405k|      pos += 64;
   19|   405k|    } else {
   20|       |      // -65 is 0b10111111 in two-complement's, so largest possible continuation
   21|       |      // byte
   22|  66.9k|      uint64_t utf8_continuation_mask = in.lt(-65 + 1);
   23|  66.9k|      uint64_t utf8_leading_mask = ~utf8_continuation_mask;
   24|  66.9k|      uint64_t utf8_end_of_code_point_mask = utf8_leading_mask >> 1;
   25|  66.9k|      size_t max_starting_point = (pos + 64) - 12;
   26|   646k|      while (pos < max_starting_point) {
  ------------------
  |  Branch (26:14): [True: 579k, False: 66.9k]
  ------------------
   27|   579k|        size_t consumed = convert_masked_utf8_to_utf32(
   28|   579k|            input + pos, utf8_end_of_code_point_mask, utf32_output);
   29|   579k|        pos += consumed;
   30|   579k|        utf8_end_of_code_point_mask >>= consumed;
   31|   579k|      }
   32|  66.9k|    }
   33|   472k|  }
   34|    512|  utf32_output += scalar::utf8_to_utf32::convert_valid(input + pos, size - pos,
   35|    512|                                                       utf32_output);
   36|    512|  return utf32_output - start;
   37|    512|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker16check_next_inputERKNS1_4simd8simd8x64IhEE:
  215|  5.20M|  simdutf_really_inline bool check_next_input(const simd8x64<uint8_t> &input) {
  216|  5.20M|    if (simdutf_likely(is_ascii(input))) {
  ------------------
  |  |   90|  5.20M|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 4.26M, False: 941k]
  |  |  ------------------
  ------------------
  217|  4.26M|      this->error |= this->prev_incomplete;
  218|  4.26M|      return true;
  219|  4.26M|    } else {
  220|       |      // you might think that a for-loop would work, but under Visual Studio, it
  221|       |      // is not good enough.
  222|   941k|      static_assert((simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  223|   941k|                        (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  224|   941k|                    "We support either two or four chunks per 64-byte block.");
  225|   941k|      if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  226|   941k|        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  227|   941k|        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  228|       |      } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  229|       |        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  230|       |        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  231|       |        this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  232|       |        this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  233|       |      }
  234|   941k|      this->prev_incomplete =
  235|   941k|          is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1]);
  236|   941k|      this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1];
  237|   941k|      return false;
  238|   941k|    }
  239|  5.20M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  195|  1.88M|                                              const simd8<uint8_t> prev_input) {
  196|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  197|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  198|       |    // small negative numbers)
  199|  1.88M|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  200|  1.88M|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  201|  1.88M|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  202|  1.88M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation19check_special_casesENS1_4simd5simd8IhEES5_:
    9|  1.88M|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|  1.88M|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   17|       |                                               // 11______ 11______
   18|  1.88M|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   19|  1.88M|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   20|  1.88M|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   21|  1.88M|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   22|  1.88M|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   23|  1.88M|  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|  1.88M|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   32|       |  // 11110101 1000____
   33|       |  // 1111011_ 1000____
   34|       |  // 11111___ 1000____
   35|  1.88M|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   36|       |
   37|  1.88M|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   38|       |      // 0_______ ________ <ASCII in byte 1>
   39|  1.88M|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   40|  1.88M|      TOO_LONG,
   41|       |      // 10______ ________ <continuation in byte 1>
   42|  1.88M|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   43|       |      // 1100____ ________ <two byte lead in byte 1>
   44|  1.88M|      TOO_SHORT | OVERLONG_2,
   45|       |      // 1101____ ________ <two byte lead in byte 1>
   46|  1.88M|      TOO_SHORT,
   47|       |      // 1110____ ________ <three byte lead in byte 1>
   48|  1.88M|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   49|       |      // 1111____ ________ <four+ byte lead in byte 1>
   50|  1.88M|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   51|  1.88M|  constexpr const uint8_t CARRY =
   52|  1.88M|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   53|  1.88M|  const simd8<uint8_t> byte_1_low =
   54|  1.88M|      (prev1 & 0x0F)
   55|  1.88M|          .lookup_16<uint8_t>(
   56|       |              // ____0000 ________
   57|  1.88M|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   58|       |              // ____0001 ________
   59|  1.88M|              CARRY | OVERLONG_2,
   60|       |              // ____001_ ________
   61|  1.88M|              CARRY, CARRY,
   62|       |
   63|       |              // ____0100 ________
   64|  1.88M|              CARRY | TOO_LARGE,
   65|       |              // ____0101 ________
   66|  1.88M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   67|       |              // ____011_ ________
   68|  1.88M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|  1.88M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   70|       |
   71|       |              // ____1___ ________
   72|  1.88M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  1.88M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  1.88M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  1.88M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|  1.88M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   77|       |              // ____1101 ________
   78|  1.88M|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   79|  1.88M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   80|  1.88M|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   81|  1.88M|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   82|       |      // ________ 0_______ <ASCII in byte 2>
   83|  1.88M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   84|  1.88M|      TOO_SHORT, TOO_SHORT,
   85|       |
   86|       |      // ________ 1000____
   87|  1.88M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   88|  1.88M|          OVERLONG_4,
   89|       |      // ________ 1001____
   90|  1.88M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   91|       |      // ________ 101_____
   92|  1.88M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|  1.88M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   94|       |
   95|       |      // ________ 11______
   96|  1.88M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   97|  1.88M|  return (byte_1_high & byte_1_low & byte_2_high);
   98|  1.88M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation23check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  102|  1.88M|                        const simd8<uint8_t> sc) {
  103|  1.88M|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  104|  1.88M|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  105|  1.88M|  simd8<uint8_t> must23 =
  106|  1.88M|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  107|  1.88M|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  108|  1.88M|  return must23_80 ^ sc;
  109|  1.88M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation13is_incompleteENS1_4simd5simd8IhEE:
  115|   941k|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|   941k|  static const uint8_t max_array[32] = {255,
  120|   941k|                                        255,
  121|   941k|                                        255,
  122|   941k|                                        255,
  123|   941k|                                        255,
  124|   941k|                                        255,
  125|   941k|                                        255,
  126|   941k|                                        255,
  127|   941k|                                        255,
  128|   941k|                                        255,
  129|   941k|                                        255,
  130|   941k|                                        255,
  131|   941k|                                        255,
  132|   941k|                                        255,
  133|   941k|                                        255,
  134|   941k|                                        255,
  135|   941k|                                        255,
  136|   941k|                                        255,
  137|   941k|                                        255,
  138|   941k|                                        255,
  139|   941k|                                        255,
  140|   941k|                                        255,
  141|   941k|                                        255,
  142|   941k|                                        255,
  143|   941k|                                        255,
  144|   941k|                                        255,
  145|   941k|                                        255,
  146|   941k|                                        255,
  147|   941k|                                        255,
  148|   941k|                                        0b11110000u - 1,
  149|   941k|                                        0b11100000u - 1,
  150|   941k|                                        0b11000000u - 1};
  151|   941k|  const simd8<uint8_t> max_value(
  152|   941k|      &max_array[sizeof(max_array) - sizeof(simd8<uint8_t>)]);
  153|   941k|  return input.gt_bits(max_value);
  154|   941k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker9check_eofEv:
  207|  7.05k|  simdutf_really_inline void check_eof() {
  208|       |    // If the previous block had incomplete UTF-8 characters at the end, an
  209|       |    // ASCII block can't possibly finish them.
  210|  7.05k|    this->error |= this->prev_incomplete;
  211|  7.05k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_115utf8_validation12utf8_checker6errorsEv:
  242|  2.12M|  simdutf_really_inline bool errors() const {
  243|  2.12M|    return this->error.any_bits_set_anywhere();
  244|  2.12M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker16check_next_inputERKNS1_4simd8simd8x64IhEE:
  215|  5.20M|  simdutf_really_inline bool check_next_input(const simd8x64<uint8_t> &input) {
  216|  5.20M|    if (simdutf_likely(is_ascii(input))) {
  ------------------
  |  |   90|  5.20M|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 4.26M, False: 941k]
  |  |  ------------------
  ------------------
  217|  4.26M|      this->error |= this->prev_incomplete;
  218|  4.26M|      return true;
  219|  4.26M|    } else {
  220|       |      // you might think that a for-loop would work, but under Visual Studio, it
  221|       |      // is not good enough.
  222|   941k|      static_assert((simd8x64<uint8_t>::NUM_CHUNKS == 2) ||
  223|   941k|                        (simd8x64<uint8_t>::NUM_CHUNKS == 4),
  224|   941k|                    "We support either two or four chunks per 64-byte block.");
  225|       |      if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 2) {
  226|       |        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  227|       |        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  228|   941k|      } else if constexpr (simd8x64<uint8_t>::NUM_CHUNKS == 4) {
  229|   941k|        this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
  230|   941k|        this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
  231|   941k|        this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
  232|   941k|        this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
  233|   941k|      }
  234|   941k|      this->prev_incomplete =
  235|   941k|          is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1]);
  236|   941k|      this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS - 1];
  237|   941k|      return false;
  238|   941k|    }
  239|  5.20M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker16check_utf8_bytesENS1_4simd5simd8IhEES6_:
  195|  3.76M|                                              const simd8<uint8_t> prev_input) {
  196|       |    // Flip prev1...prev3 so we can easily determine if they are 2+, 3+ or 4+
  197|       |    // lead bytes (2, 3, 4-byte leads become large positive numbers instead of
  198|       |    // small negative numbers)
  199|  3.76M|    simd8<uint8_t> prev1 = input.prev<1>(prev_input);
  200|  3.76M|    simd8<uint8_t> sc = check_special_cases(input, prev1);
  201|  3.76M|    this->error |= check_multibyte_lengths(input, prev_input, sc);
  202|  3.76M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation19check_special_casesENS1_4simd5simd8IhEES5_:
    9|  3.76M|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|  3.76M|  constexpr const uint8_t TOO_SHORT = 1 << 0;  // 11______ 0_______
   17|       |                                               // 11______ 11______
   18|  3.76M|  constexpr const uint8_t TOO_LONG = 1 << 1;   // 0_______ 10______
   19|  3.76M|  constexpr const uint8_t OVERLONG_3 = 1 << 2; // 11100000 100_____
   20|  3.76M|  constexpr const uint8_t SURROGATE = 1 << 4;  // 11101101 101_____
   21|  3.76M|  constexpr const uint8_t OVERLONG_2 = 1 << 5; // 1100000_ 10______
   22|  3.76M|  constexpr const uint8_t TWO_CONTS = 1 << 7;  // 10______ 10______
   23|  3.76M|  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|  3.76M|  constexpr const uint8_t TOO_LARGE_1000 = 1 << 6;
   32|       |  // 11110101 1000____
   33|       |  // 1111011_ 1000____
   34|       |  // 11111___ 1000____
   35|  3.76M|  constexpr const uint8_t OVERLONG_4 = 1 << 6; // 11110000 1000____
   36|       |
   37|  3.76M|  const simd8<uint8_t> byte_1_high = prev1.shr<4>().lookup_16<uint8_t>(
   38|       |      // 0_______ ________ <ASCII in byte 1>
   39|  3.76M|      TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG, TOO_LONG,
   40|  3.76M|      TOO_LONG,
   41|       |      // 10______ ________ <continuation in byte 1>
   42|  3.76M|      TWO_CONTS, TWO_CONTS, TWO_CONTS, TWO_CONTS,
   43|       |      // 1100____ ________ <two byte lead in byte 1>
   44|  3.76M|      TOO_SHORT | OVERLONG_2,
   45|       |      // 1101____ ________ <two byte lead in byte 1>
   46|  3.76M|      TOO_SHORT,
   47|       |      // 1110____ ________ <three byte lead in byte 1>
   48|  3.76M|      TOO_SHORT | OVERLONG_3 | SURROGATE,
   49|       |      // 1111____ ________ <four+ byte lead in byte 1>
   50|  3.76M|      TOO_SHORT | TOO_LARGE | TOO_LARGE_1000 | OVERLONG_4);
   51|  3.76M|  constexpr const uint8_t CARRY =
   52|  3.76M|      TOO_SHORT | TOO_LONG | TWO_CONTS; // These all have ____ in byte 1 .
   53|  3.76M|  const simd8<uint8_t> byte_1_low =
   54|  3.76M|      (prev1 & 0x0F)
   55|  3.76M|          .lookup_16<uint8_t>(
   56|       |              // ____0000 ________
   57|  3.76M|              CARRY | OVERLONG_3 | OVERLONG_2 | OVERLONG_4,
   58|       |              // ____0001 ________
   59|  3.76M|              CARRY | OVERLONG_2,
   60|       |              // ____001_ ________
   61|  3.76M|              CARRY, CARRY,
   62|       |
   63|       |              // ____0100 ________
   64|  3.76M|              CARRY | TOO_LARGE,
   65|       |              // ____0101 ________
   66|  3.76M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   67|       |              // ____011_ ________
   68|  3.76M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   69|  3.76M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   70|       |
   71|       |              // ____1___ ________
   72|  3.76M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   73|  3.76M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   74|  3.76M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   75|  3.76M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   76|  3.76M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   77|       |              // ____1101 ________
   78|  3.76M|              CARRY | TOO_LARGE | TOO_LARGE_1000 | SURROGATE,
   79|  3.76M|              CARRY | TOO_LARGE | TOO_LARGE_1000,
   80|  3.76M|              CARRY | TOO_LARGE | TOO_LARGE_1000);
   81|  3.76M|  const simd8<uint8_t> byte_2_high = input.shr<4>().lookup_16<uint8_t>(
   82|       |      // ________ 0_______ <ASCII in byte 2>
   83|  3.76M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT,
   84|  3.76M|      TOO_SHORT, TOO_SHORT,
   85|       |
   86|       |      // ________ 1000____
   87|  3.76M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE_1000 |
   88|  3.76M|          OVERLONG_4,
   89|       |      // ________ 1001____
   90|  3.76M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | OVERLONG_3 | TOO_LARGE,
   91|       |      // ________ 101_____
   92|  3.76M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   93|  3.76M|      TOO_LONG | OVERLONG_2 | TWO_CONTS | SURROGATE | TOO_LARGE,
   94|       |
   95|       |      // ________ 11______
   96|  3.76M|      TOO_SHORT, TOO_SHORT, TOO_SHORT, TOO_SHORT);
   97|  3.76M|  return (byte_1_high & byte_1_low & byte_2_high);
   98|  3.76M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation23check_multibyte_lengthsENS1_4simd5simd8IhEES5_S5_:
  102|  3.76M|                        const simd8<uint8_t> sc) {
  103|  3.76M|  simd8<uint8_t> prev2 = input.prev<2>(prev_input);
  104|  3.76M|  simd8<uint8_t> prev3 = input.prev<3>(prev_input);
  105|  3.76M|  simd8<uint8_t> must23 =
  106|  3.76M|      simd8<uint8_t>(must_be_2_3_continuation(prev2, prev3));
  107|  3.76M|  simd8<uint8_t> must23_80 = must23 & uint8_t(0x80);
  108|  3.76M|  return must23_80 ^ sc;
  109|  3.76M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation13is_incompleteENS1_4simd5simd8IhEE:
  115|   941k|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|   941k|  static const uint8_t max_array[32] = {255,
  120|   941k|                                        255,
  121|   941k|                                        255,
  122|   941k|                                        255,
  123|   941k|                                        255,
  124|   941k|                                        255,
  125|   941k|                                        255,
  126|   941k|                                        255,
  127|   941k|                                        255,
  128|   941k|                                        255,
  129|   941k|                                        255,
  130|   941k|                                        255,
  131|   941k|                                        255,
  132|   941k|                                        255,
  133|   941k|                                        255,
  134|   941k|                                        255,
  135|   941k|                                        255,
  136|   941k|                                        255,
  137|   941k|                                        255,
  138|   941k|                                        255,
  139|   941k|                                        255,
  140|   941k|                                        255,
  141|   941k|                                        255,
  142|   941k|                                        255,
  143|   941k|                                        255,
  144|   941k|                                        255,
  145|   941k|                                        255,
  146|   941k|                                        255,
  147|   941k|                                        255,
  148|   941k|                                        0b11110000u - 1,
  149|   941k|                                        0b11100000u - 1,
  150|   941k|                                        0b11000000u - 1};
  151|   941k|  const simd8<uint8_t> max_value(
  152|   941k|      &max_array[sizeof(max_array) - sizeof(simd8<uint8_t>)]);
  153|   941k|  return input.gt_bits(max_value);
  154|   941k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker9check_eofEv:
  207|  7.05k|  simdutf_really_inline void check_eof() {
  208|       |    // If the previous block had incomplete UTF-8 characters at the end, an
  209|       |    // ASCII block can't possibly finish them.
  210|  7.05k|    this->error |= this->prev_incomplete;
  211|  7.05k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_115utf8_validation12utf8_checker6errorsEv:
  242|  2.12M|  simdutf_really_inline bool errors() const {
  243|  2.12M|    return this->error.any_bits_set_anywhere();
  244|  2.12M|  }

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation21generic_validate_utf8EPKcm:
   27|  4.11k|bool generic_validate_utf8(const char *input, size_t length) {
   28|  4.11k|  return generic_validate_utf8<utf8_checker>(
   29|  4.11k|      reinterpret_cast<const uint8_t *>(input), length);
   30|  4.11k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation21generic_validate_utf8INS2_12utf8_checkerEEEbPKhm:
   10|  4.11k|bool generic_validate_utf8(const uint8_t *input, size_t length) {
   11|  4.11k|  checker c{};
   12|  4.11k|  buf_block_reader<64> reader(input, length);
   13|  3.08M|  while (reader.has_full_block()) {
  ------------------
  |  Branch (13:10): [True: 3.07M, False: 4.11k]
  ------------------
   14|  3.07M|    simd::simd8x64<uint8_t> in(reader.full_block());
   15|  3.07M|    c.check_next_input(in);
   16|  3.07M|    reader.advance();
   17|  3.07M|  }
   18|  4.11k|  uint8_t block[64]{};
   19|  4.11k|  reader.get_remainder(block);
   20|  4.11k|  simd::simd8x64<uint8_t> in(block);
   21|  4.11k|  c.check_next_input(in);
   22|  4.11k|  reader.advance();
   23|  4.11k|  c.check_eof();
   24|  4.11k|  return !c.errors();
   25|  4.11k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation33generic_validate_utf8_with_errorsEPKcm:
   78|  4.11k|result generic_validate_utf8_with_errors(const char *input, size_t length) {
   79|  4.11k|  return generic_validate_utf8_with_errors<utf8_checker>(
   80|  4.11k|      reinterpret_cast<const uint8_t *>(input), length);
   81|  4.11k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_115utf8_validation33generic_validate_utf8_with_errorsINS2_12utf8_checkerEEENS_6resultEPKhm:
   36|  4.11k|result generic_validate_utf8_with_errors(const uint8_t *input, size_t length) {
   37|  4.11k|  checker c{};
   38|  4.11k|  buf_block_reader<64> reader(input, length);
   39|  4.11k|  size_t count{0};
   40|  2.12M|  while (reader.has_full_block()) {
  ------------------
  |  Branch (40:10): [True: 2.11M, False: 2.93k]
  ------------------
   41|  2.11M|    simd::simd8x64<uint8_t> in(reader.full_block());
   42|  2.11M|    c.check_next_input(in);
   43|  2.11M|    if (c.errors()) {
  ------------------
  |  Branch (43:9): [True: 1.18k, False: 2.11M]
  ------------------
   44|  1.18k|      if (count != 0) {
  ------------------
  |  Branch (44:11): [True: 295, False: 886]
  ------------------
   45|    295|        count--;
   46|    295|      } // Sometimes the error is only detected in the next chunk
   47|  1.18k|      SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|  1.18k|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
   48|  1.18k|      result res = scalar::utf8::rewind_and_validate_with_errors(
   49|  1.18k|          reinterpret_cast<const char *>(input),
   50|  1.18k|          reinterpret_cast<const char *>(input + count), length - count);
   51|  1.18k|      res.count += count;
   52|  1.18k|      return res;
   53|  1.18k|    }
   54|  2.11M|    reader.advance();
   55|  2.11M|    count += 64;
   56|  2.11M|  }
   57|  2.93k|  uint8_t block[64]{};
   58|  2.93k|  reader.get_remainder(block);
   59|  2.93k|  simd::simd8x64<uint8_t> in(block);
   60|  2.93k|  c.check_next_input(in);
   61|  2.93k|  reader.advance();
   62|  2.93k|  c.check_eof();
   63|  2.93k|  if (c.errors()) {
  ------------------
  |  Branch (63:7): [True: 1.22k, False: 1.71k]
  ------------------
   64|  1.22k|    if (count != 0) {
  ------------------
  |  Branch (64:9): [True: 472, False: 748]
  ------------------
   65|    472|      count--;
   66|    472|    } // Sometimes the error is only detected in the next chunk
   67|  1.22k|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|  1.22k|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
   68|  1.22k|    result res = scalar::utf8::rewind_and_validate_with_errors(
   69|  1.22k|        reinterpret_cast<const char *>(input),
   70|  1.22k|        reinterpret_cast<const char *>(input) + count, length - count);
   71|  1.22k|    res.count += count;
   72|  1.22k|    return res;
   73|  1.71k|  } else {
   74|  1.71k|    return result(error_code::SUCCESS, length);
   75|  1.71k|  }
   76|  2.93k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation21generic_validate_utf8EPKcm:
   27|  4.11k|bool generic_validate_utf8(const char *input, size_t length) {
   28|  4.11k|  return generic_validate_utf8<utf8_checker>(
   29|  4.11k|      reinterpret_cast<const uint8_t *>(input), length);
   30|  4.11k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation21generic_validate_utf8INS2_12utf8_checkerEEEbPKhm:
   10|  4.11k|bool generic_validate_utf8(const uint8_t *input, size_t length) {
   11|  4.11k|  checker c{};
   12|  4.11k|  buf_block_reader<64> reader(input, length);
   13|  3.08M|  while (reader.has_full_block()) {
  ------------------
  |  Branch (13:10): [True: 3.07M, False: 4.11k]
  ------------------
   14|  3.07M|    simd::simd8x64<uint8_t> in(reader.full_block());
   15|  3.07M|    c.check_next_input(in);
   16|  3.07M|    reader.advance();
   17|  3.07M|  }
   18|  4.11k|  uint8_t block[64]{};
   19|  4.11k|  reader.get_remainder(block);
   20|  4.11k|  simd::simd8x64<uint8_t> in(block);
   21|  4.11k|  c.check_next_input(in);
   22|  4.11k|  reader.advance();
   23|  4.11k|  c.check_eof();
   24|  4.11k|  return !c.errors();
   25|  4.11k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation33generic_validate_utf8_with_errorsEPKcm:
   78|  4.11k|result generic_validate_utf8_with_errors(const char *input, size_t length) {
   79|  4.11k|  return generic_validate_utf8_with_errors<utf8_checker>(
   80|  4.11k|      reinterpret_cast<const uint8_t *>(input), length);
   81|  4.11k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_115utf8_validation33generic_validate_utf8_with_errorsINS2_12utf8_checkerEEENS_6resultEPKhm:
   36|  4.11k|result generic_validate_utf8_with_errors(const uint8_t *input, size_t length) {
   37|  4.11k|  checker c{};
   38|  4.11k|  buf_block_reader<64> reader(input, length);
   39|  4.11k|  size_t count{0};
   40|  2.12M|  while (reader.has_full_block()) {
  ------------------
  |  Branch (40:10): [True: 2.11M, False: 2.93k]
  ------------------
   41|  2.11M|    simd::simd8x64<uint8_t> in(reader.full_block());
   42|  2.11M|    c.check_next_input(in);
   43|  2.11M|    if (c.errors()) {
  ------------------
  |  Branch (43:9): [True: 1.18k, False: 2.11M]
  ------------------
   44|  1.18k|      if (count != 0) {
  ------------------
  |  Branch (44:11): [True: 295, False: 886]
  ------------------
   45|    295|        count--;
   46|    295|      } // Sometimes the error is only detected in the next chunk
   47|  1.18k|      SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|  1.18k|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
   48|  1.18k|      result res = scalar::utf8::rewind_and_validate_with_errors(
   49|  1.18k|          reinterpret_cast<const char *>(input),
   50|  1.18k|          reinterpret_cast<const char *>(input + count), length - count);
   51|  1.18k|      res.count += count;
   52|  1.18k|      return res;
   53|  1.18k|    }
   54|  2.11M|    reader.advance();
   55|  2.11M|    count += 64;
   56|  2.11M|  }
   57|  2.93k|  uint8_t block[64]{};
   58|  2.93k|  reader.get_remainder(block);
   59|  2.93k|  simd::simd8x64<uint8_t> in(block);
   60|  2.93k|  c.check_next_input(in);
   61|  2.93k|  reader.advance();
   62|  2.93k|  c.check_eof();
   63|  2.93k|  if (c.errors()) {
  ------------------
  |  Branch (63:7): [True: 1.22k, False: 1.71k]
  ------------------
   64|  1.22k|    if (count != 0) {
  ------------------
  |  Branch (64:9): [True: 472, False: 748]
  ------------------
   65|    472|      count--;
   66|    472|    } // Sometimes the error is only detected in the next chunk
   67|  1.22k|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   16|  1.22k|#define SIMDUTF_VZEROUPPER() (void)0
  ------------------
   68|  1.22k|    result res = scalar::utf8::rewind_and_validate_with_errors(
   69|  1.22k|        reinterpret_cast<const char *>(input),
   70|  1.22k|        reinterpret_cast<const char *>(input) + count, length - count);
   71|  1.22k|    res.count += count;
   72|  1.22k|    return res;
   73|  1.71k|  } else {
   74|  1.71k|    return result(error_code::SUCCESS, length);
   75|  1.71k|  }
   76|  2.93k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1626validate_utf16_with_errorsILNS_10endiannessE0EEEKNS_6resultEPKDsm:
   49|  2.82k|const result validate_utf16_with_errors(const char16_t *input, size_t size) {
   50|  2.82k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   93|  2.82k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 17, False: 2.80k]
  |  |  ------------------
  ------------------
   51|     17|    return result(error_code::SUCCESS, 0);
   52|     17|  }
   53|       |
   54|  2.80k|  const char16_t *start = input;
   55|  2.80k|  const char16_t *end = input + size;
   56|       |
   57|  2.80k|  const auto v_d8 = simd8<uint8_t>::splat(0xd8);
   58|  2.80k|  const auto v_f8 = simd8<uint8_t>::splat(0xf8);
   59|  2.80k|  const auto v_fc = simd8<uint8_t>::splat(0xfc);
   60|  2.80k|  const auto v_dc = simd8<uint8_t>::splat(0xdc);
   61|       |
   62|  2.61M|  while (input + simd16<uint16_t>::SIZE * 2 < end) {
  ------------------
  |  Branch (62:10): [True: 2.61M, False: 2.59k]
  ------------------
   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|  2.61M|    auto in0 = simd16<uint16_t>(input);
   67|  2.61M|    auto in1 =
   68|  2.61M|        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|  2.61M|    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|  2.61M|    const auto surrogates_wordmask = (in & v_f8) == v_d8;
   76|  2.61M|    const uint16_t surrogates_bitmask =
   77|  2.61M|        static_cast<uint16_t>(surrogates_wordmask.to_bitmask());
   78|  2.61M|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (78:9): [True: 2.56M, False: 44.8k]
  ------------------
   79|  2.56M|      input += 16;
   80|  2.56M|    } 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|  44.8k|      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|  44.8k|      const auto vH = (in & v_fc) == v_dc;
   93|  44.8k|      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|  44.8k|      const uint16_t L = static_cast<uint16_t>(~H & surrogates_bitmask);
   98|       |
   99|  44.8k|      const uint16_t a = static_cast<uint16_t>(
  100|  44.8k|          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|  44.8k|      const uint16_t b = static_cast<uint16_t>(
  104|  44.8k|          a << 1); // Just mark that the opinput - startite fact is hold,
  105|       |                   // thanks to that we have only two masks for valid case.
  106|  44.8k|      const uint16_t c = static_cast<uint16_t>(
  107|  44.8k|          V | a | b); // Combine all the masks into the final one.
  108|       |
  109|  44.8k|      if (c == 0xffff) {
  ------------------
  |  Branch (109:11): [True: 35.5k, False: 9.24k]
  ------------------
  110|       |        // The whole input register contains valid UTF-16, i.e.,
  111|       |        // either single code units or proper surrogate pairs.
  112|  35.5k|        input += 16;
  113|  35.5k|      } else if (c == 0x7fff) {
  ------------------
  |  Branch (113:18): [True: 9.03k, False: 208]
  ------------------
  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|  9.03k|        input += 15;
  119|  9.03k|      } else {
  120|    208|        return result(error_code::SURROGATE, input - start);
  121|    208|      }
  122|  44.8k|    }
  123|  2.61M|  }
  124|       |
  125|  2.59k|  return result(error_code::SUCCESS, input - start);
  126|  2.80k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf1626validate_utf16_with_errorsILNS_10endiannessE1EEEKNS_6resultEPKDsm:
   49|  2.65k|const result validate_utf16_with_errors(const char16_t *input, size_t size) {
   50|  2.65k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   93|  2.65k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 16, False: 2.63k]
  |  |  ------------------
  ------------------
   51|     16|    return result(error_code::SUCCESS, 0);
   52|     16|  }
   53|       |
   54|  2.63k|  const char16_t *start = input;
   55|  2.63k|  const char16_t *end = input + size;
   56|       |
   57|  2.63k|  const auto v_d8 = simd8<uint8_t>::splat(0xd8);
   58|  2.63k|  const auto v_f8 = simd8<uint8_t>::splat(0xf8);
   59|  2.63k|  const auto v_fc = simd8<uint8_t>::splat(0xfc);
   60|  2.63k|  const auto v_dc = simd8<uint8_t>::splat(0xdc);
   61|       |
   62|  2.63M|  while (input + simd16<uint16_t>::SIZE * 2 < end) {
  ------------------
  |  Branch (62:10): [True: 2.63M, False: 2.47k]
  ------------------
   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|  2.63M|    auto in0 = simd16<uint16_t>(input);
   67|  2.63M|    auto in1 =
   68|  2.63M|        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|  2.63M|    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|  2.63M|    const auto surrogates_wordmask = (in & v_f8) == v_d8;
   76|  2.63M|    const uint16_t surrogates_bitmask =
   77|  2.63M|        static_cast<uint16_t>(surrogates_wordmask.to_bitmask());
   78|  2.63M|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (78:9): [True: 2.60M, False: 26.5k]
  ------------------
   79|  2.60M|      input += 16;
   80|  2.60M|    } 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|  26.5k|      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|  26.5k|      const auto vH = (in & v_fc) == v_dc;
   93|  26.5k|      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|  26.5k|      const uint16_t L = static_cast<uint16_t>(~H & surrogates_bitmask);
   98|       |
   99|  26.5k|      const uint16_t a = static_cast<uint16_t>(
  100|  26.5k|          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|  26.5k|      const uint16_t b = static_cast<uint16_t>(
  104|  26.5k|          a << 1); // Just mark that the opinput - startite fact is hold,
  105|       |                   // thanks to that we have only two masks for valid case.
  106|  26.5k|      const uint16_t c = static_cast<uint16_t>(
  107|  26.5k|          V | a | b); // Combine all the masks into the final one.
  108|       |
  109|  26.5k|      if (c == 0xffff) {
  ------------------
  |  Branch (109:11): [True: 20.7k, False: 5.77k]
  ------------------
  110|       |        // The whole input register contains valid UTF-16, i.e.,
  111|       |        // either single code units or proper surrogate pairs.
  112|  20.7k|        input += 16;
  113|  20.7k|      } else if (c == 0x7fff) {
  ------------------
  |  Branch (113:18): [True: 5.61k, False: 162]
  ------------------
  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|  5.61k|        input += 15;
  119|  5.61k|      } else {
  120|    162|        return result(error_code::SURROGATE, input - start);
  121|    162|      }
  122|  26.5k|    }
  123|  2.63M|  }
  124|       |
  125|  2.47k|  return result(error_code::SUCCESS, input - start);
  126|  2.63k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1626validate_utf16_with_errorsILNS_10endiannessE0EEEKNS_6resultEPKDsm:
   49|  2.82k|const result validate_utf16_with_errors(const char16_t *input, size_t size) {
   50|  2.82k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   93|  2.82k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 17, False: 2.80k]
  |  |  ------------------
  ------------------
   51|     17|    return result(error_code::SUCCESS, 0);
   52|     17|  }
   53|       |
   54|  2.80k|  const char16_t *start = input;
   55|  2.80k|  const char16_t *end = input + size;
   56|       |
   57|  2.80k|  const auto v_d8 = simd8<uint8_t>::splat(0xd8);
   58|  2.80k|  const auto v_f8 = simd8<uint8_t>::splat(0xf8);
   59|  2.80k|  const auto v_fc = simd8<uint8_t>::splat(0xfc);
   60|  2.80k|  const auto v_dc = simd8<uint8_t>::splat(0xdc);
   61|       |
   62|  2.61M|  while (input + simd16<uint16_t>::SIZE * 2 < end) {
  ------------------
  |  Branch (62:10): [True: 2.61M, False: 2.50k]
  ------------------
   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|  2.61M|    auto in0 = simd16<uint16_t>(input);
   67|  2.61M|    auto in1 =
   68|  2.61M|        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|  2.61M|    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|  2.61M|    const auto surrogates_wordmask = (in & v_f8) == v_d8;
   76|  2.61M|    const uint16_t surrogates_bitmask =
   77|  2.61M|        static_cast<uint16_t>(surrogates_wordmask.to_bitmask());
   78|  2.61M|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (78:9): [True: 2.56M, False: 45.3k]
  ------------------
   79|  2.56M|      input += 16;
   80|  2.56M|    } 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|  45.3k|      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|  45.3k|      const auto vH = (in & v_fc) == v_dc;
   93|  45.3k|      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|  45.3k|      const uint16_t L = static_cast<uint16_t>(~H & surrogates_bitmask);
   98|       |
   99|  45.3k|      const uint16_t a = static_cast<uint16_t>(
  100|  45.3k|          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|  45.3k|      const uint16_t b = static_cast<uint16_t>(
  104|  45.3k|          a << 1); // Just mark that the opinput - startite fact is hold,
  105|       |                   // thanks to that we have only two masks for valid case.
  106|  45.3k|      const uint16_t c = static_cast<uint16_t>(
  107|  45.3k|          V | a | b); // Combine all the masks into the final one.
  108|       |
  109|  45.3k|      if (c == 0xffff) {
  ------------------
  |  Branch (109:11): [True: 35.9k, False: 9.43k]
  ------------------
  110|       |        // The whole input register contains valid UTF-16, i.e.,
  111|       |        // either single code units or proper surrogate pairs.
  112|  35.9k|        input += 16;
  113|  35.9k|      } else if (c == 0x7fff) {
  ------------------
  |  Branch (113:18): [True: 9.13k, False: 300]
  ------------------
  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|  9.13k|        input += 15;
  119|  9.13k|      } else {
  120|    300|        return result(error_code::SURROGATE, input - start);
  121|    300|      }
  122|  45.3k|    }
  123|  2.61M|  }
  124|       |
  125|  2.50k|  return result(error_code::SUCCESS, input - start);
  126|  2.80k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf1626validate_utf16_with_errorsILNS_10endiannessE1EEEKNS_6resultEPKDsm:
   49|  2.65k|const result validate_utf16_with_errors(const char16_t *input, size_t size) {
   50|  2.65k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   93|  2.65k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 16, False: 2.63k]
  |  |  ------------------
  ------------------
   51|     16|    return result(error_code::SUCCESS, 0);
   52|     16|  }
   53|       |
   54|  2.63k|  const char16_t *start = input;
   55|  2.63k|  const char16_t *end = input + size;
   56|       |
   57|  2.63k|  const auto v_d8 = simd8<uint8_t>::splat(0xd8);
   58|  2.63k|  const auto v_f8 = simd8<uint8_t>::splat(0xf8);
   59|  2.63k|  const auto v_fc = simd8<uint8_t>::splat(0xfc);
   60|  2.63k|  const auto v_dc = simd8<uint8_t>::splat(0xdc);
   61|       |
   62|  2.64M|  while (input + simd16<uint16_t>::SIZE * 2 < end) {
  ------------------
  |  Branch (62:10): [True: 2.63M, False: 2.38k]
  ------------------
   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|  2.63M|    auto in0 = simd16<uint16_t>(input);
   67|  2.63M|    auto in1 =
   68|  2.63M|        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|  2.63M|    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|  2.63M|    const auto surrogates_wordmask = (in & v_f8) == v_d8;
   76|  2.63M|    const uint16_t surrogates_bitmask =
   77|  2.63M|        static_cast<uint16_t>(surrogates_wordmask.to_bitmask());
   78|  2.63M|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (78:9): [True: 2.61M, False: 27.0k]
  ------------------
   79|  2.61M|      input += 16;
   80|  2.61M|    } 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|  27.0k|      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|  27.0k|      const auto vH = (in & v_fc) == v_dc;
   93|  27.0k|      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|  27.0k|      const uint16_t L = static_cast<uint16_t>(~H & surrogates_bitmask);
   98|       |
   99|  27.0k|      const uint16_t a = static_cast<uint16_t>(
  100|  27.0k|          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|  27.0k|      const uint16_t b = static_cast<uint16_t>(
  104|  27.0k|          a << 1); // Just mark that the opinput - startite fact is hold,
  105|       |                   // thanks to that we have only two masks for valid case.
  106|  27.0k|      const uint16_t c = static_cast<uint16_t>(
  107|  27.0k|          V | a | b); // Combine all the masks into the final one.
  108|       |
  109|  27.0k|      if (c == 0xffff) {
  ------------------
  |  Branch (109:11): [True: 21.0k, False: 5.98k]
  ------------------
  110|       |        // The whole input register contains valid UTF-16, i.e.,
  111|       |        // either single code units or proper surrogate pairs.
  112|  21.0k|        input += 16;
  113|  21.0k|      } else if (c == 0x7fff) {
  ------------------
  |  Branch (113:18): [True: 5.73k, False: 250]
  ------------------
  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|  5.73k|        input += 15;
  119|  5.73k|      } else {
  120|    250|        return result(error_code::SURROGATE, input - start);
  121|    250|      }
  122|  27.0k|    }
  123|  2.63M|  }
  124|       |
  125|  2.38k|  return result(error_code::SUCCESS, input - start);
  126|  2.63k|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf328validateEPKDim:
    6|  2.68k|simdutf_really_inline bool validate(const char32_t *input, size_t size) {
    7|  2.68k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   93|  2.68k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 24, False: 2.66k]
  |  |  ------------------
  ------------------
    8|       |    // empty input is valid UTF-32. protect the implementation from
    9|       |    // handling nullptr
   10|     24|    return true;
   11|     24|  }
   12|       |
   13|  2.66k|  const char32_t *end = input + size;
   14|       |
   15|  2.66k|  using vector_u32 = simd32<uint32_t>;
   16|       |
   17|  2.66k|  const auto standardmax = vector_u32::splat(0x10ffff);
   18|  2.66k|  const auto offset = vector_u32::splat(0xffff2000);
   19|  2.66k|  const auto standardoffsetmax = vector_u32::splat(0xfffff7ff);
   20|  2.66k|  auto currentmax = vector_u32::zero();
   21|  2.66k|  auto currentoffsetmax = vector_u32::zero();
   22|       |
   23|  2.66k|  constexpr size_t N = vector_u32::ELEMENTS;
   24|       |
   25|  1.15M|  while (input + N < end) {
  ------------------
  |  Branch (25:10): [True: 1.15M, False: 2.66k]
  ------------------
   26|  1.15M|    auto in = vector_u32(input);
   27|  1.15M|    if constexpr (!match_system(endianness::BIG)) {
   28|  1.15M|      in.swap_bytes();
   29|  1.15M|    }
   30|       |
   31|  1.15M|    currentmax = max(currentmax, in);
   32|  1.15M|    currentoffsetmax = max(currentoffsetmax, in + offset);
   33|  1.15M|    input += N;
   34|  1.15M|  }
   35|       |
   36|  2.66k|  const auto too_large = currentmax > standardmax;
   37|  2.66k|  if (too_large.any()) {
  ------------------
  |  Branch (37:7): [True: 994, False: 1.66k]
  ------------------
   38|    994|    return false;
   39|    994|  }
   40|       |
   41|  1.66k|  const auto surrogate = currentoffsetmax > standardoffsetmax;
   42|  1.66k|  if (surrogate.any()) {
  ------------------
  |  Branch (42:7): [True: 22, False: 1.64k]
  ------------------
   43|     22|    return false;
   44|     22|  }
   45|       |
   46|  1.64k|  return scalar::utf32::validate(input, end - input);
   47|  1.66k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_15utf3220validate_with_errorsEPKDim:
   50|  2.68k|                                                  size_t size) {
   51|  2.68k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   93|  2.68k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 24, False: 2.66k]
  |  |  ------------------
  ------------------
   52|       |    // empty input is valid UTF-32. protect the implementation from
   53|       |    // handling nullptr
   54|     24|    return result(error_code::SUCCESS, 0);
   55|     24|  }
   56|       |
   57|  2.66k|  const char32_t *start = input;
   58|  2.66k|  const char32_t *end = input + size;
   59|       |
   60|  2.66k|  using vector_u32 = simd32<uint32_t>;
   61|       |
   62|  2.66k|  const auto standardmax = vector_u32::splat(0x10ffff + 1);
   63|  2.66k|  const auto surrogate_mask = vector_u32::splat(0xfffff800);
   64|  2.66k|  const auto surrogate_byte = vector_u32::splat(0x0000d800);
   65|       |
   66|  2.66k|  constexpr size_t N = vector_u32::ELEMENTS;
   67|       |
   68|  73.5k|  while (input + N < end) {
  ------------------
  |  Branch (68:10): [True: 71.8k, False: 1.64k]
  ------------------
   69|  71.8k|    auto in = vector_u32(input);
   70|  71.8k|    if constexpr (!match_system(endianness::BIG)) {
   71|  71.8k|      in.swap_bytes();
   72|  71.8k|    }
   73|       |
   74|  71.8k|    const auto too_large = in >= standardmax;
   75|  71.8k|    const auto surrogate = (in & surrogate_mask) == surrogate_byte;
   76|       |
   77|  71.8k|    const auto combined = too_large | surrogate;
   78|  71.8k|    if (simdutf_unlikely(combined.any())) {
  ------------------
  |  |   93|  71.8k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 1.01k, False: 70.8k]
  |  |  ------------------
  ------------------
   79|  1.01k|      const size_t consumed = input - start;
   80|  1.01k|      auto sr = scalar::utf32::validate_with_errors(input, end - input);
   81|  1.01k|      sr.count += consumed;
   82|       |
   83|  1.01k|      return sr;
   84|  1.01k|    }
   85|       |
   86|  70.8k|    input += N;
   87|  70.8k|  }
   88|       |
   89|  1.64k|  const size_t consumed = input - start;
   90|  1.64k|  auto sr = scalar::utf32::validate_with_errors(input, end - input);
   91|  1.64k|  sr.count += consumed;
   92|       |
   93|  1.64k|  return sr;
   94|  2.66k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf328validateEPKDim:
    6|  2.68k|simdutf_really_inline bool validate(const char32_t *input, size_t size) {
    7|  2.68k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   93|  2.68k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 24, False: 2.66k]
  |  |  ------------------
  ------------------
    8|       |    // empty input is valid UTF-32. protect the implementation from
    9|       |    // handling nullptr
   10|     24|    return true;
   11|     24|  }
   12|       |
   13|  2.66k|  const char32_t *end = input + size;
   14|       |
   15|  2.66k|  using vector_u32 = simd32<uint32_t>;
   16|       |
   17|  2.66k|  const auto standardmax = vector_u32::splat(0x10ffff);
   18|  2.66k|  const auto offset = vector_u32::splat(0xffff2000);
   19|  2.66k|  const auto standardoffsetmax = vector_u32::splat(0xfffff7ff);
   20|  2.66k|  auto currentmax = vector_u32::zero();
   21|  2.66k|  auto currentoffsetmax = vector_u32::zero();
   22|       |
   23|  2.66k|  constexpr size_t N = vector_u32::ELEMENTS;
   24|       |
   25|  2.31M|  while (input + N < end) {
  ------------------
  |  Branch (25:10): [True: 2.30M, False: 2.66k]
  ------------------
   26|  2.30M|    auto in = vector_u32(input);
   27|  2.30M|    if constexpr (!match_system(endianness::BIG)) {
   28|  2.30M|      in.swap_bytes();
   29|  2.30M|    }
   30|       |
   31|  2.30M|    currentmax = max(currentmax, in);
   32|  2.30M|    currentoffsetmax = max(currentoffsetmax, in + offset);
   33|  2.30M|    input += N;
   34|  2.30M|  }
   35|       |
   36|  2.66k|  const auto too_large = currentmax > standardmax;
   37|  2.66k|  if (too_large.any()) {
  ------------------
  |  Branch (37:7): [True: 1.16k, False: 1.49k]
  ------------------
   38|  1.16k|    return false;
   39|  1.16k|  }
   40|       |
   41|  1.49k|  const auto surrogate = currentoffsetmax > standardoffsetmax;
   42|  1.49k|  if (surrogate.any()) {
  ------------------
  |  Branch (42:7): [True: 46, False: 1.44k]
  ------------------
   43|     46|    return false;
   44|     46|  }
   45|       |
   46|  1.44k|  return scalar::utf32::validate(input, end - input);
   47|  1.49k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_15utf3220validate_with_errorsEPKDim:
   50|  2.68k|                                                  size_t size) {
   51|  2.68k|  if (simdutf_unlikely(size == 0)) {
  ------------------
  |  |   93|  2.68k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 24, False: 2.66k]
  |  |  ------------------
  ------------------
   52|       |    // empty input is valid UTF-32. protect the implementation from
   53|       |    // handling nullptr
   54|     24|    return result(error_code::SUCCESS, 0);
   55|     24|  }
   56|       |
   57|  2.66k|  const char32_t *start = input;
   58|  2.66k|  const char32_t *end = input + size;
   59|       |
   60|  2.66k|  using vector_u32 = simd32<uint32_t>;
   61|       |
   62|  2.66k|  const auto standardmax = vector_u32::splat(0x10ffff + 1);
   63|  2.66k|  const auto surrogate_mask = vector_u32::splat(0xfffff800);
   64|  2.66k|  const auto surrogate_byte = vector_u32::splat(0x0000d800);
   65|       |
   66|  2.66k|  constexpr size_t N = vector_u32::ELEMENTS;
   67|       |
   68|   144k|  while (input + N < end) {
  ------------------
  |  Branch (68:10): [True: 143k, False: 1.44k]
  ------------------
   69|   143k|    auto in = vector_u32(input);
   70|   143k|    if constexpr (!match_system(endianness::BIG)) {
   71|   143k|      in.swap_bytes();
   72|   143k|    }
   73|       |
   74|   143k|    const auto too_large = in >= standardmax;
   75|   143k|    const auto surrogate = (in & surrogate_mask) == surrogate_byte;
   76|       |
   77|   143k|    const auto combined = too_large | surrogate;
   78|   143k|    if (simdutf_unlikely(combined.any())) {
  ------------------
  |  |   93|   143k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 1.21k, False: 142k]
  |  |  ------------------
  ------------------
   79|  1.21k|      const size_t consumed = input - start;
   80|  1.21k|      auto sr = scalar::utf32::validate_with_errors(input, end - input);
   81|  1.21k|      sr.count += consumed;
   82|       |
   83|  1.21k|      return sr;
   84|  1.21k|    }
   85|       |
   86|   142k|    input += N;
   87|   142k|  }
   88|       |
   89|  1.44k|  const size_t consumed = input - start;
   90|  1.44k|  auto sr = scalar::utf32::validate_with_errors(input, end - input);
   91|  1.44k|  sr.count += consumed;
   92|       |
   93|  1.44k|  return sr;
   94|  2.66k|}

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128avx2_convert_latin1_to_utf32EPKcmPDi:
    3|    102|                             char32_t *utf32_output) {
    4|    102|  size_t rounded_len = ((len | 7) ^ 7); // Round down to nearest multiple of 8
    5|       |
    6|   834k|  for (size_t i = 0; i < rounded_len; i += 8) {
  ------------------
  |  Branch (6:22): [True: 834k, False: 102]
  ------------------
    7|       |    // Load 8 Latin1 characters into a 64-bit register
    8|   834k|    __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|   834k|    __m256i out = _mm256_cvtepu8_epi32(in);
   13|       |
   14|       |    // Store the results back to memory
   15|   834k|    _mm256_storeu_si256((__m256i *)&utf32_output[i], out);
   16|   834k|  }
   17|       |
   18|       |  // return pointers pointing to where we left off
   19|    102|  return std::make_pair(buf + rounded_len, utf32_output + rounded_len);
   20|    102|}

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128avx2_convert_utf16_to_latin1ILNS_10endiannessE0EEENSt3__14pairIPKDsPcEES7_mS8_:
    4|    134|                             char *latin1_output) {
    5|    134|  const char16_t *end = buf + len;
    6|  39.2k|  while (end - buf >= 32) {
  ------------------
  |  Branch (6:10): [True: 39.1k, False: 100]
  ------------------
    7|       |    // Load 16 UTF-16 characters into 256-bit AVX2 register
    8|  39.1k|    __m256i in0 = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buf));
    9|  39.1k|    __m256i in1 =
   10|  39.1k|        _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|  39.1k|    __m256i high_byte_mask = _mm256_set1_epi16((int16_t)0xFF00);
   21|  39.1k|    if (_mm256_testz_si256(_mm256_or_si256(in0, in1), high_byte_mask)) {
  ------------------
  |  Branch (21:9): [True: 39.0k, False: 34]
  ------------------
   22|       |      // Pack 16-bit characters into 8-bit and store in latin1_output
   23|  39.0k|      const __m256i packed = _mm256_packus_epi16(in0, in1);
   24|       |
   25|  39.0k|      const __m256i result = _mm256_permute4x64_epi64(packed, 0b11011000);
   26|       |
   27|  39.0k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(latin1_output), result);
   28|       |      // Adjust pointers for the next iteration
   29|  39.0k|      buf += 32;
   30|  39.0k|      latin1_output += 32;
   31|  39.0k|    } else {
   32|     34|      return std::make_pair(nullptr, reinterpret_cast<char *>(latin1_output));
   33|     34|    }
   34|  39.1k|  } // while
   35|    100|  return std::make_pair(buf, latin1_output);
   36|    134|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128avx2_convert_utf16_to_latin1ILNS_10endiannessE1EEENSt3__14pairIPKDsPcEES7_mS8_:
    4|    116|                             char *latin1_output) {
    5|    116|  const char16_t *end = buf + len;
    6|  1.07k|  while (end - buf >= 32) {
  ------------------
  |  Branch (6:10): [True: 972, False: 98]
  ------------------
    7|       |    // Load 16 UTF-16 characters into 256-bit AVX2 register
    8|    972|    __m256i in0 = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buf));
    9|    972|    __m256i in1 =
   10|    972|        _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buf + 16));
   11|       |
   12|    972|    if constexpr (!match_system(big_endian)) {
   13|    972|      const __m256i swap = _mm256_setr_epi8(
   14|    972|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   15|    972|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   16|    972|      in0 = _mm256_shuffle_epi8(in0, swap);
   17|    972|      in1 = _mm256_shuffle_epi8(in1, swap);
   18|    972|    }
   19|       |
   20|    972|    __m256i high_byte_mask = _mm256_set1_epi16((int16_t)0xFF00);
   21|    972|    if (_mm256_testz_si256(_mm256_or_si256(in0, in1), high_byte_mask)) {
  ------------------
  |  Branch (21:9): [True: 954, False: 18]
  ------------------
   22|       |      // Pack 16-bit characters into 8-bit and store in latin1_output
   23|    954|      const __m256i packed = _mm256_packus_epi16(in0, in1);
   24|       |
   25|    954|      const __m256i result = _mm256_permute4x64_epi64(packed, 0b11011000);
   26|       |
   27|    954|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(latin1_output), result);
   28|       |      // Adjust pointers for the next iteration
   29|    954|      buf += 32;
   30|    954|      latin1_output += 32;
   31|    954|    } else {
   32|     18|      return std::make_pair(nullptr, reinterpret_cast<char *>(latin1_output));
   33|     18|    }
   34|    972|  } // while
   35|     98|  return std::make_pair(buf, latin1_output);
   36|    116|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_140avx2_convert_utf16_to_latin1_with_errorsILNS_10endiannessE0EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
   41|    264|                                         char *latin1_output) {
   42|    264|  const char16_t *start = buf;
   43|    264|  const char16_t *end = buf + len;
   44|   451k|  while (end - buf >= 16) {
  ------------------
  |  Branch (44:10): [True: 451k, False: 168]
  ------------------
   45|   451k|    __m256i in = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buf));
   46|       |
   47|       |    if constexpr (!match_system(big_endian)) {
   48|       |      const __m256i swap = _mm256_setr_epi8(
   49|       |          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   50|       |          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   51|       |      in = _mm256_shuffle_epi8(in, swap);
   52|       |    }
   53|       |
   54|   451k|    __m256i high_byte_mask = _mm256_set1_epi16((int16_t)0xFF00);
   55|   451k|    if (_mm256_testz_si256(in, high_byte_mask)) {
  ------------------
  |  Branch (55:9): [True: 451k, False: 96]
  ------------------
   56|   451k|      __m128i lo = _mm256_extractf128_si256(in, 0);
   57|   451k|      __m128i hi = _mm256_extractf128_si256(in, 1);
   58|   451k|      __m128i latin1_packed_lo = _mm_packus_epi16(lo, lo);
   59|   451k|      __m128i latin1_packed_hi = _mm_packus_epi16(hi, hi);
   60|   451k|      _mm_storel_epi64(reinterpret_cast<__m128i *>(latin1_output),
   61|   451k|                       latin1_packed_lo);
   62|   451k|      _mm_storel_epi64(reinterpret_cast<__m128i *>(latin1_output + 8),
   63|   451k|                       latin1_packed_hi);
   64|   451k|      buf += 16;
   65|   451k|      latin1_output += 16;
   66|   451k|    } else {
   67|       |      // Fallback to scalar code for handling errors
   68|    426|      for (int k = 0; k < 16; k++) {
  ------------------
  |  Branch (68:23): [True: 426, False: 0]
  ------------------
   69|    426|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
   70|    426|        if (word <= 0xff) {
  ------------------
  |  Branch (70:13): [True: 330, False: 96]
  ------------------
   71|    330|          *latin1_output++ = char(word);
   72|    330|        } else {
   73|     96|          return std::make_pair(
   74|     96|              result{error_code::TOO_LARGE, (size_t)(buf - start + k)},
   75|     96|              latin1_output);
   76|     96|        }
   77|    426|      }
   78|      0|      buf += 16;
   79|      0|    }
   80|   451k|  } // while
   81|    168|  return std::make_pair(result{error_code::SUCCESS, (size_t)(buf - start)},
   82|    168|                        latin1_output);
   83|    264|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_140avx2_convert_utf16_to_latin1_with_errorsILNS_10endiannessE1EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
   41|    248|                                         char *latin1_output) {
   42|    248|  const char16_t *start = buf;
   43|    248|  const char16_t *end = buf + len;
   44|   457k|  while (end - buf >= 16) {
  ------------------
  |  Branch (44:10): [True: 457k, False: 142]
  ------------------
   45|   457k|    __m256i in = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(buf));
   46|       |
   47|   457k|    if constexpr (!match_system(big_endian)) {
   48|   457k|      const __m256i swap = _mm256_setr_epi8(
   49|   457k|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   50|   457k|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   51|   457k|      in = _mm256_shuffle_epi8(in, swap);
   52|   457k|    }
   53|       |
   54|   457k|    __m256i high_byte_mask = _mm256_set1_epi16((int16_t)0xFF00);
   55|   457k|    if (_mm256_testz_si256(in, high_byte_mask)) {
  ------------------
  |  Branch (55:9): [True: 457k, False: 106]
  ------------------
   56|   457k|      __m128i lo = _mm256_extractf128_si256(in, 0);
   57|   457k|      __m128i hi = _mm256_extractf128_si256(in, 1);
   58|   457k|      __m128i latin1_packed_lo = _mm_packus_epi16(lo, lo);
   59|   457k|      __m128i latin1_packed_hi = _mm_packus_epi16(hi, hi);
   60|   457k|      _mm_storel_epi64(reinterpret_cast<__m128i *>(latin1_output),
   61|   457k|                       latin1_packed_lo);
   62|   457k|      _mm_storel_epi64(reinterpret_cast<__m128i *>(latin1_output + 8),
   63|   457k|                       latin1_packed_hi);
   64|   457k|      buf += 16;
   65|   457k|      latin1_output += 16;
   66|   457k|    } else {
   67|       |      // Fallback to scalar code for handling errors
   68|    526|      for (int k = 0; k < 16; k++) {
  ------------------
  |  Branch (68:23): [True: 526, False: 0]
  ------------------
   69|    526|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
   70|    526|        if (word <= 0xff) {
  ------------------
  |  Branch (70:13): [True: 420, False: 106]
  ------------------
   71|    420|          *latin1_output++ = char(word);
   72|    420|        } else {
   73|    106|          return std::make_pair(
   74|    106|              result{error_code::TOO_LARGE, (size_t)(buf - start + k)},
   75|    106|              latin1_output);
   76|    106|        }
   77|    526|      }
   78|      0|      buf += 16;
   79|      0|    }
   80|   457k|  } // while
   81|    142|  return std::make_pair(result{error_code::SUCCESS, (size_t)(buf - start)},
   82|    142|                        latin1_output);
   83|    248|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_127avx2_convert_utf16_to_utf32ILNS_10endiannessE0EEENSt3__14pairIPKDsPDiEES7_mS8_:
   57|    426|                            char32_t *utf32_output) {
   58|    426|  const char16_t *end = buf + len;
   59|    426|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
   60|    426|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
   61|       |
   62|   326k|  while (end - buf >= 16) {
  ------------------
  |  Branch (62:10): [True: 326k, False: 336]
  ------------------
   63|   326k|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
   64|   326k|    if (big_endian) {
  ------------------
  |  Branch (64:9): [Folded, False: 326k]
  ------------------
   65|      0|      const __m256i swap = _mm256_setr_epi8(
   66|      0|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   67|      0|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   68|      0|      in = _mm256_shuffle_epi8(in, swap);
   69|      0|    }
   70|       |
   71|       |    // 1. Check if there are any surrogate word in the input chunk.
   72|       |    //    We have also deal with situation when there is a surrogate word
   73|       |    //    at the end of a chunk.
   74|   326k|    const __m256i surrogates_bytemask =
   75|   326k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_d800);
   76|       |
   77|       |    // bitmask = 0x0000 if there are no surrogates
   78|       |    //         = 0xc000 if the last word is a surrogate
   79|   326k|    const uint32_t surrogates_bitmask =
   80|   326k|        static_cast<uint32_t>(_mm256_movemask_epi8(surrogates_bytemask));
   81|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
   82|       |    // However, it is likely an uncommon occurrence.
   83|   326k|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (83:9): [True: 301k, False: 25.2k]
  ------------------
   84|       |      // case: we extend all sixteen 16-bit code units to sixteen 32-bit code
   85|       |      // units
   86|   301k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(utf32_output),
   87|   301k|                          _mm256_cvtepu16_epi32(_mm256_castsi256_si128(in)));
   88|   301k|      _mm256_storeu_si256(
   89|   301k|          reinterpret_cast<__m256i *>(utf32_output + 8),
   90|   301k|          _mm256_cvtepu16_epi32(_mm256_extractf128_si256(in, 1)));
   91|   301k|      utf32_output += 16;
   92|   301k|      buf += 16;
   93|       |      // surrogate pair(s) in a register
   94|   301k|    } else {
   95|       |      // Let us do a scalar fallback.
   96|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
   97|       |      // in the presence of surrogate pairs may require non-trivial tables.
   98|  25.2k|      size_t forward = 15;
   99|  25.2k|      size_t k = 0;
  100|  25.2k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (100:11): [True: 0, False: 25.2k]
  ------------------
  101|      0|        forward = size_t(end - buf - 1);
  102|      0|      }
  103|   376k|      for (; k < forward; k++) {
  ------------------
  |  Branch (103:14): [True: 351k, False: 25.1k]
  ------------------
  104|   351k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  105|   351k|        if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (105:13): [True: 324k, False: 27.2k]
  ------------------
  106|       |          // No surrogate pair
  107|   324k|          *utf32_output++ = char32_t(word);
  108|   324k|        } else {
  109|       |          // must be a surrogate pair
  110|  27.2k|          uint16_t diff = uint16_t(word - 0xD800);
  111|  27.2k|          uint16_t next_word =
  112|  27.2k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  113|  27.2k|          k++;
  114|  27.2k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  115|  27.2k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (115:15): [True: 90, False: 27.1k]
  ------------------
  116|     90|            return std::make_pair(nullptr, utf32_output);
  117|     90|          }
  118|  27.1k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  119|  27.1k|          *utf32_output++ = char32_t(value);
  120|  27.1k|        }
  121|   351k|      }
  122|  25.1k|      buf += k;
  123|  25.1k|    }
  124|   326k|  } // while
  125|    336|  return std::make_pair(buf, utf32_output);
  126|    426|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_127avx2_convert_utf16_to_utf32ILNS_10endiannessE1EEENSt3__14pairIPKDsPDiEES7_mS8_:
   57|    436|                            char32_t *utf32_output) {
   58|    436|  const char16_t *end = buf + len;
   59|    436|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
   60|    436|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
   61|       |
   62|   247k|  while (end - buf >= 16) {
  ------------------
  |  Branch (62:10): [True: 247k, False: 346]
  ------------------
   63|   247k|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
   64|   247k|    if (big_endian) {
  ------------------
  |  Branch (64:9): [True: 247k, Folded]
  ------------------
   65|   247k|      const __m256i swap = _mm256_setr_epi8(
   66|   247k|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   67|   247k|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   68|   247k|      in = _mm256_shuffle_epi8(in, swap);
   69|   247k|    }
   70|       |
   71|       |    // 1. Check if there are any surrogate word in the input chunk.
   72|       |    //    We have also deal with situation when there is a surrogate word
   73|       |    //    at the end of a chunk.
   74|   247k|    const __m256i surrogates_bytemask =
   75|   247k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_d800);
   76|       |
   77|       |    // bitmask = 0x0000 if there are no surrogates
   78|       |    //         = 0xc000 if the last word is a surrogate
   79|   247k|    const uint32_t surrogates_bitmask =
   80|   247k|        static_cast<uint32_t>(_mm256_movemask_epi8(surrogates_bytemask));
   81|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
   82|       |    // However, it is likely an uncommon occurrence.
   83|   247k|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (83:9): [True: 245k, False: 1.62k]
  ------------------
   84|       |      // case: we extend all sixteen 16-bit code units to sixteen 32-bit code
   85|       |      // units
   86|   245k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(utf32_output),
   87|   245k|                          _mm256_cvtepu16_epi32(_mm256_castsi256_si128(in)));
   88|   245k|      _mm256_storeu_si256(
   89|   245k|          reinterpret_cast<__m256i *>(utf32_output + 8),
   90|   245k|          _mm256_cvtepu16_epi32(_mm256_extractf128_si256(in, 1)));
   91|   245k|      utf32_output += 16;
   92|   245k|      buf += 16;
   93|       |      // surrogate pair(s) in a register
   94|   245k|    } else {
   95|       |      // Let us do a scalar fallback.
   96|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
   97|       |      // in the presence of surrogate pairs may require non-trivial tables.
   98|  1.62k|      size_t forward = 15;
   99|  1.62k|      size_t k = 0;
  100|  1.62k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (100:11): [True: 0, False: 1.62k]
  ------------------
  101|      0|        forward = size_t(end - buf - 1);
  102|      0|      }
  103|  23.1k|      for (; k < forward; k++) {
  ------------------
  |  Branch (103:14): [True: 21.5k, False: 1.53k]
  ------------------
  104|  21.5k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  105|  21.5k|        if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (105:13): [True: 19.4k, False: 2.09k]
  ------------------
  106|       |          // No surrogate pair
  107|  19.4k|          *utf32_output++ = char32_t(word);
  108|  19.4k|        } else {
  109|       |          // must be a surrogate pair
  110|  2.09k|          uint16_t diff = uint16_t(word - 0xD800);
  111|  2.09k|          uint16_t next_word =
  112|  2.09k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  113|  2.09k|          k++;
  114|  2.09k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  115|  2.09k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (115:15): [True: 90, False: 2.00k]
  ------------------
  116|     90|            return std::make_pair(nullptr, utf32_output);
  117|     90|          }
  118|  2.00k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  119|  2.00k|          *utf32_output++ = char32_t(value);
  120|  2.00k|        }
  121|  21.5k|      }
  122|  1.53k|      buf += k;
  123|  1.53k|    }
  124|   247k|  } // while
  125|    346|  return std::make_pair(buf, utf32_output);
  126|    436|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_139avx2_convert_utf16_to_utf32_with_errorsILNS_10endiannessE0EEENSt3__14pairINS_6resultEPDiEEPKDsmS7_:
  138|    386|                                        char32_t *utf32_output) {
  139|    386|  const char16_t *start = buf;
  140|    386|  const char16_t *end = buf + len;
  141|    386|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
  142|    386|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
  143|       |
  144|   180k|  while (end - buf >= 16) {
  ------------------
  |  Branch (144:10): [True: 179k, False: 278]
  ------------------
  145|   179k|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
  146|   179k|    if (big_endian) {
  ------------------
  |  Branch (146:9): [Folded, False: 179k]
  ------------------
  147|      0|      const __m256i swap = _mm256_setr_epi8(
  148|      0|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
  149|      0|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
  150|      0|      in = _mm256_shuffle_epi8(in, swap);
  151|      0|    }
  152|       |
  153|       |    // 1. Check if there are any surrogate word in the input chunk.
  154|       |    //    We have also deal with situation when there is a surrogate word
  155|       |    //    at the end of a chunk.
  156|   179k|    const __m256i surrogates_bytemask =
  157|   179k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_d800);
  158|       |
  159|       |    // bitmask = 0x0000 if there are no surrogates
  160|       |    //         = 0xc000 if the last word is a surrogate
  161|   179k|    const uint32_t surrogates_bitmask =
  162|   179k|        static_cast<uint32_t>(_mm256_movemask_epi8(surrogates_bytemask));
  163|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  164|       |    // However, it is likely an uncommon occurrence.
  165|   179k|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (165:9): [True: 171k, False: 7.89k]
  ------------------
  166|       |      // case: we extend all sixteen 16-bit code units to sixteen 32-bit code
  167|       |      // units
  168|   171k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(utf32_output),
  169|   171k|                          _mm256_cvtepu16_epi32(_mm256_castsi256_si128(in)));
  170|   171k|      _mm256_storeu_si256(
  171|   171k|          reinterpret_cast<__m256i *>(utf32_output + 8),
  172|   171k|          _mm256_cvtepu16_epi32(_mm256_extractf128_si256(in, 1)));
  173|   171k|      utf32_output += 16;
  174|   171k|      buf += 16;
  175|       |      // surrogate pair(s) in a register
  176|   171k|    } else {
  177|       |      // Let us do a scalar fallback.
  178|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  179|       |      // in the presence of surrogate pairs may require non-trivial tables.
  180|  7.89k|      size_t forward = 15;
  181|  7.89k|      size_t k = 0;
  182|  7.89k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (182:11): [True: 0, False: 7.89k]
  ------------------
  183|      0|        forward = size_t(end - buf - 1);
  184|      0|      }
  185|   113k|      for (; k < forward; k++) {
  ------------------
  |  Branch (185:14): [True: 106k, False: 7.78k]
  ------------------
  186|   106k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  187|   106k|        if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (187:13): [True: 93.6k, False: 12.3k]
  ------------------
  188|       |          // No surrogate pair
  189|  93.6k|          *utf32_output++ = char32_t(word);
  190|  93.6k|        } else {
  191|       |          // must be a surrogate pair
  192|  12.3k|          uint16_t diff = uint16_t(word - 0xD800);
  193|  12.3k|          uint16_t next_word =
  194|  12.3k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  195|  12.3k|          k++;
  196|  12.3k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  197|  12.3k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (197:15): [True: 108, False: 12.2k]
  ------------------
  198|    108|            return std::make_pair(
  199|    108|                result(error_code::SURROGATE, buf - start + k - 1),
  200|    108|                utf32_output);
  201|    108|          }
  202|  12.2k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  203|  12.2k|          *utf32_output++ = char32_t(value);
  204|  12.2k|        }
  205|   106k|      }
  206|  7.78k|      buf += k;
  207|  7.78k|    }
  208|   179k|  } // while
  209|    278|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf32_output);
  210|    386|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_139avx2_convert_utf16_to_utf32_with_errorsILNS_10endiannessE1EEENSt3__14pairINS_6resultEPDiEEPKDsmS7_:
  138|    366|                                        char32_t *utf32_output) {
  139|    366|  const char16_t *start = buf;
  140|    366|  const char16_t *end = buf + len;
  141|    366|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
  142|    366|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
  143|       |
  144|   191k|  while (end - buf >= 16) {
  ------------------
  |  Branch (144:10): [True: 190k, False: 282]
  ------------------
  145|   190k|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
  146|   190k|    if (big_endian) {
  ------------------
  |  Branch (146:9): [True: 190k, Folded]
  ------------------
  147|   190k|      const __m256i swap = _mm256_setr_epi8(
  148|   190k|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
  149|   190k|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
  150|   190k|      in = _mm256_shuffle_epi8(in, swap);
  151|   190k|    }
  152|       |
  153|       |    // 1. Check if there are any surrogate word in the input chunk.
  154|       |    //    We have also deal with situation when there is a surrogate word
  155|       |    //    at the end of a chunk.
  156|   190k|    const __m256i surrogates_bytemask =
  157|   190k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_d800);
  158|       |
  159|       |    // bitmask = 0x0000 if there are no surrogates
  160|       |    //         = 0xc000 if the last word is a surrogate
  161|   190k|    const uint32_t surrogates_bitmask =
  162|   190k|        static_cast<uint32_t>(_mm256_movemask_epi8(surrogates_bytemask));
  163|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  164|       |    // However, it is likely an uncommon occurrence.
  165|   190k|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (165:9): [True: 185k, False: 5.55k]
  ------------------
  166|       |      // case: we extend all sixteen 16-bit code units to sixteen 32-bit code
  167|       |      // units
  168|   185k|      _mm256_storeu_si256(reinterpret_cast<__m256i *>(utf32_output),
  169|   185k|                          _mm256_cvtepu16_epi32(_mm256_castsi256_si128(in)));
  170|   185k|      _mm256_storeu_si256(
  171|   185k|          reinterpret_cast<__m256i *>(utf32_output + 8),
  172|   185k|          _mm256_cvtepu16_epi32(_mm256_extractf128_si256(in, 1)));
  173|   185k|      utf32_output += 16;
  174|   185k|      buf += 16;
  175|       |      // surrogate pair(s) in a register
  176|   185k|    } else {
  177|       |      // Let us do a scalar fallback.
  178|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  179|       |      // in the presence of surrogate pairs may require non-trivial tables.
  180|  5.55k|      size_t forward = 15;
  181|  5.55k|      size_t k = 0;
  182|  5.55k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (182:11): [True: 0, False: 5.55k]
  ------------------
  183|      0|        forward = size_t(end - buf - 1);
  184|      0|      }
  185|  80.0k|      for (; k < forward; k++) {
  ------------------
  |  Branch (185:14): [True: 74.5k, False: 5.46k]
  ------------------
  186|  74.5k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  187|  74.5k|        if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (187:13): [True: 66.1k, False: 8.48k]
  ------------------
  188|       |          // No surrogate pair
  189|  66.1k|          *utf32_output++ = char32_t(word);
  190|  66.1k|        } else {
  191|       |          // must be a surrogate pair
  192|  8.48k|          uint16_t diff = uint16_t(word - 0xD800);
  193|  8.48k|          uint16_t next_word =
  194|  8.48k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  195|  8.48k|          k++;
  196|  8.48k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  197|  8.48k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (197:15): [True: 84, False: 8.39k]
  ------------------
  198|     84|            return std::make_pair(
  199|     84|                result(error_code::SURROGATE, buf - start + k - 1),
  200|     84|                utf32_output);
  201|     84|          }
  202|  8.39k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  203|  8.39k|          *utf32_output++ = char32_t(value);
  204|  8.39k|        }
  205|  74.5k|      }
  206|  5.46k|      buf += k;
  207|  5.46k|    }
  208|   190k|  } // while
  209|    282|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf32_output);
  210|    366|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_126avx2_convert_utf16_to_utf8ILNS_10endiannessE0EEENSt3__14pairIPKDsPcEES7_mS8_:
   56|    878|avx2_convert_utf16_to_utf8(const char16_t *buf, size_t len, char *utf8_output) {
   57|    878|  const char16_t *end = buf + len;
   58|    878|  const __m256i v_0000 = _mm256_setzero_si256();
   59|    878|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
   60|    878|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
   61|    878|  const __m256i v_c080 = _mm256_set1_epi16((int16_t)0xc080);
   62|    878|  const size_t safety_margin =
   63|    878|      12; // to avoid overruns, see issue
   64|       |          // https://github.com/simdutf/simdutf/issues/92
   65|       |
   66|   864k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (66:10): [True: 863k, False: 742]
  ------------------
   67|   863k|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
   68|   863k|    if (big_endian) {
  ------------------
  |  Branch (68:9): [Folded, False: 863k]
  ------------------
   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|   863k|    const __m256i v_ff80 = _mm256_set1_epi16((int16_t)0xff80);
   76|   863k|    if (_mm256_testz_si256(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (76:9): [True: 730k, False: 133k]
  ------------------
   77|       |      // 1. pack the bytes
   78|   730k|      const __m128i utf8_packed = _mm_packus_epi16(
   79|   730k|          _mm256_castsi256_si128(in), _mm256_extractf128_si256(in, 1));
   80|       |      // 2. store (16 bytes)
   81|   730k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   82|       |      // 3. adjust pointers
   83|   730k|      buf += 16;
   84|   730k|      utf8_output += 16;
   85|   730k|      continue; // we are done for this round!
   86|   730k|    }
   87|       |    // no bits set above 7th bit
   88|   133k|    const __m256i one_byte_bytemask =
   89|   133k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_ff80), v_0000);
   90|   133k|    const uint32_t one_byte_bitmask =
   91|   133k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
   92|       |
   93|       |    // no bits set above 11th bit
   94|   133k|    const __m256i one_or_two_bytes_bytemask =
   95|   133k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_0000);
   96|   133k|    const uint32_t one_or_two_bytes_bitmask =
   97|   133k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
   98|   133k|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (98:9): [True: 46.5k, False: 87.1k]
  ------------------
   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|  46.5k|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
  104|  46.5k|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
  105|       |
  106|       |      // t0 = [000a|aaaa|bbbb|bb00]
  107|  46.5k|      const __m256i t0 = _mm256_slli_epi16(in, 2);
  108|       |      // t1 = [000a|aaaa|0000|0000]
  109|  46.5k|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
  110|       |      // t2 = [0000|0000|00bb|bbbb]
  111|  46.5k|      const __m256i t2 = _mm256_and_si256(in, v_003f);
  112|       |      // t3 = [000a|aaaa|00bb|bbbb]
  113|  46.5k|      const __m256i t3 = _mm256_or_si256(t1, t2);
  114|       |      // t4 = [110a|aaaa|10bb|bbbb]
  115|  46.5k|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
  116|       |
  117|       |      // 2. merge ASCII and 2-byte codewords
  118|  46.5k|      const __m256i utf8_unpacked =
  119|  46.5k|          _mm256_blendv_epi8(t4, in, one_byte_bytemask);
  120|       |
  121|       |      // 3. prepare bitmask for 8-bit lookup
  122|  46.5k|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
  123|  46.5k|      const uint32_t M1 = M0 >> 7;
  124|  46.5k|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
  125|       |      // 4. pack the bytes
  126|       |
  127|  46.5k|      const uint8_t *row =
  128|  46.5k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
  129|  46.5k|      const uint8_t *row_2 =
  130|  46.5k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
  131|  46.5k|                                                                       16)][0];
  132|       |
  133|  46.5k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  134|  46.5k|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
  135|       |
  136|  46.5k|      const __m256i utf8_packed = _mm256_shuffle_epi8(
  137|  46.5k|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|  46.5k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|  46.5k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  138|       |      // 5. store bytes
  139|  46.5k|      _mm_storeu_si128((__m128i *)utf8_output,
  140|  46.5k|                       _mm256_castsi256_si128(utf8_packed));
  141|  46.5k|      utf8_output += row[0];
  142|  46.5k|      _mm_storeu_si128((__m128i *)utf8_output,
  143|  46.5k|                       _mm256_extractf128_si256(utf8_packed, 1));
  144|  46.5k|      utf8_output += row_2[0];
  145|       |
  146|       |      // 6. adjust pointers
  147|  46.5k|      buf += 16;
  148|  46.5k|      continue;
  149|  46.5k|    }
  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|  87.1k|    const __m256i surrogates_bytemask =
  154|  87.1k|        _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|  87.1k|    const uint32_t surrogates_bitmask =
  159|  87.1k|        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|  87.1k|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (162:9): [True: 79.6k, False: 7.54k]
  ------------------
  163|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  164|  79.6k|      const __m256i dup_even = _mm256_setr_epi16(
  165|  79.6k|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  166|  79.6k|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  167|       |
  168|       |      /* In this branch we handle three cases:
  169|       |         1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  170|       |        single UFT-8 byte
  171|       |         2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              - two
  172|       |        UTF-8 bytes
  173|       |         3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  174|       |        three UTF-8 bytes
  175|       |
  176|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  177|       |        we have room for four bytes. However, we need five distinct bit
  178|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  179|       |
  180|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  181|       |        in register t2.
  182|       |
  183|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  184|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  185|       |        differ by exactly one bit.
  186|       |
  187|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  188|       |        into account the case (i.e, the number of bytes to write).
  189|       |      */
  190|       |      /**
  191|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  192|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  193|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  194|       |       */
  195|  79.6k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  196|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  197|  79.6k|      const __m256i t0 = _mm256_shuffle_epi8(in, dup_even);
  198|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  199|  79.6k|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  195|  79.6k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  200|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  201|  79.6k|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  195|  79.6k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  202|       |
  203|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  204|  79.6k|      const __m256i s0 = _mm256_srli_epi16(in, 4);
  205|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  206|  79.6k|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  195|  79.6k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  207|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  208|  79.6k|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  195|  79.6k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  209|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  210|  79.6k|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  195|  79.6k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  211|  79.6k|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  212|  79.6k|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  195|  79.6k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  213|  79.6k|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  214|  79.6k|#undef simdutf_vec
  215|       |
  216|       |      // 4. expand code units 16-bit => 32-bit
  217|  79.6k|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  218|  79.6k|      const __m256i out1 = _mm256_unpackhi_epi16(t2, s4);
  219|       |
  220|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  221|  79.6k|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  222|  79.6k|                            (one_or_two_bytes_bitmask & 0xaaaaaaaa);
  223|       |      // Due to the wider registers, the following path is less likely to be
  224|       |      // useful.
  225|       |      /*if(mask == 0) {
  226|       |        // We only have three-byte code units. Use fast path.
  227|       |        const __m256i shuffle =
  228|       |      _mm256_setr_epi8(2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1,
  229|       |      2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1); const __m256i utf8_0 =
  230|       |      _mm256_shuffle_epi8(out0, shuffle); const __m256i utf8_1 =
  231|       |      _mm256_shuffle_epi8(out1, shuffle);
  232|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_0));
  233|       |        utf8_output += 12;
  234|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_1));
  235|       |        utf8_output += 12;
  236|       |        _mm_storeu_si128((__m128i*)utf8_output,
  237|       |      _mm256_extractf128_si256(utf8_0,1)); utf8_output += 12;
  238|       |        _mm_storeu_si128((__m128i*)utf8_output,
  239|       |      _mm256_extractf128_si256(utf8_1,1)); utf8_output += 12; buf += 16;
  240|       |        continue;
  241|       |      }*/
  242|  79.6k|      const uint8_t mask0 = uint8_t(mask);
  243|  79.6k|      const uint8_t *row0 =
  244|  79.6k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  245|  79.6k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  246|  79.6k|      const __m128i utf8_0 =
  247|  79.6k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  248|       |
  249|  79.6k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  250|  79.6k|      const uint8_t *row1 =
  251|  79.6k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  252|  79.6k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  253|  79.6k|      const __m128i utf8_1 =
  254|  79.6k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  255|       |
  256|  79.6k|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  257|  79.6k|      const uint8_t *row2 =
  258|  79.6k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  259|  79.6k|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  260|  79.6k|      const __m128i utf8_2 =
  261|  79.6k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  262|       |
  263|  79.6k|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  264|  79.6k|      const uint8_t *row3 =
  265|  79.6k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  266|  79.6k|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  267|  79.6k|      const __m128i utf8_3 =
  268|  79.6k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  269|       |
  270|  79.6k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  271|  79.6k|      utf8_output += row0[0];
  272|  79.6k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  273|  79.6k|      utf8_output += row1[0];
  274|  79.6k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  275|  79.6k|      utf8_output += row2[0];
  276|  79.6k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  277|  79.6k|      utf8_output += row3[0];
  278|  79.6k|      buf += 16;
  279|       |      // surrogate pair(s) in a register
  280|  79.6k|    } else {
  281|       |      // Let us do a scalar fallback.
  282|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  283|       |      // in the presence of surrogate pairs may require non-trivial tables.
  284|  7.54k|      size_t forward = 15;
  285|  7.54k|      size_t k = 0;
  286|  7.54k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (286:11): [True: 0, False: 7.54k]
  ------------------
  287|      0|        forward = size_t(end - buf - 1);
  288|      0|      }
  289|   110k|      for (; k < forward; k++) {
  ------------------
  |  Branch (289:14): [True: 102k, False: 7.40k]
  ------------------
  290|   102k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  291|   102k|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (291:13): [True: 13.7k, False: 89.2k]
  ------------------
  292|  13.7k|          *utf8_output++ = char(word);
  293|  89.2k|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (293:20): [True: 4.67k, False: 84.5k]
  ------------------
  294|  4.67k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  295|  4.67k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  296|  84.5k|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (296:20): [True: 75.1k, False: 9.39k]
  ------------------
  297|  75.1k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  298|  75.1k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  299|  75.1k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  300|  75.1k|        } else {
  301|       |          // must be a surrogate pair
  302|  9.39k|          uint16_t diff = uint16_t(word - 0xD800);
  303|  9.39k|          uint16_t next_word =
  304|  9.39k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  305|  9.39k|          k++;
  306|  9.39k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  307|  9.39k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (307:15): [True: 136, False: 9.25k]
  ------------------
  308|    136|            return std::make_pair(nullptr, utf8_output);
  309|    136|          }
  310|  9.25k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  311|  9.25k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  312|  9.25k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  313|  9.25k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  314|  9.25k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  315|  9.25k|        }
  316|   102k|      }
  317|  7.40k|      buf += k;
  318|  7.40k|    }
  319|  87.1k|  } // while
  320|    742|  return std::make_pair(buf, utf8_output);
  321|    878|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_126avx2_convert_utf16_to_utf8ILNS_10endiannessE1EEENSt3__14pairIPKDsPcEES7_mS8_:
   56|    810|avx2_convert_utf16_to_utf8(const char16_t *buf, size_t len, char *utf8_output) {
   57|    810|  const char16_t *end = buf + len;
   58|    810|  const __m256i v_0000 = _mm256_setzero_si256();
   59|    810|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
   60|    810|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
   61|    810|  const __m256i v_c080 = _mm256_set1_epi16((int16_t)0xc080);
   62|    810|  const size_t safety_margin =
   63|    810|      12; // to avoid overruns, see issue
   64|       |          // https://github.com/simdutf/simdutf/issues/92
   65|       |
   66|  1.10M|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (66:10): [True: 1.10M, False: 706]
  ------------------
   67|  1.10M|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
   68|  1.10M|    if (big_endian) {
  ------------------
  |  Branch (68:9): [True: 1.10M, Folded]
  ------------------
   69|  1.10M|      const __m256i swap = _mm256_setr_epi8(
   70|  1.10M|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
   71|  1.10M|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
   72|  1.10M|      in = _mm256_shuffle_epi8(in, swap);
   73|  1.10M|    }
   74|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
   75|  1.10M|    const __m256i v_ff80 = _mm256_set1_epi16((int16_t)0xff80);
   76|  1.10M|    if (_mm256_testz_si256(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (76:9): [True: 882k, False: 224k]
  ------------------
   77|       |      // 1. pack the bytes
   78|   882k|      const __m128i utf8_packed = _mm_packus_epi16(
   79|   882k|          _mm256_castsi256_si128(in), _mm256_extractf128_si256(in, 1));
   80|       |      // 2. store (16 bytes)
   81|   882k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   82|       |      // 3. adjust pointers
   83|   882k|      buf += 16;
   84|   882k|      utf8_output += 16;
   85|   882k|      continue; // we are done for this round!
   86|   882k|    }
   87|       |    // no bits set above 7th bit
   88|   224k|    const __m256i one_byte_bytemask =
   89|   224k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_ff80), v_0000);
   90|   224k|    const uint32_t one_byte_bitmask =
   91|   224k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
   92|       |
   93|       |    // no bits set above 11th bit
   94|   224k|    const __m256i one_or_two_bytes_bytemask =
   95|   224k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_0000);
   96|   224k|    const uint32_t one_or_two_bytes_bitmask =
   97|   224k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
   98|   224k|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (98:9): [True: 23.9k, False: 200k]
  ------------------
   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|  23.9k|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
  104|  23.9k|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
  105|       |
  106|       |      // t0 = [000a|aaaa|bbbb|bb00]
  107|  23.9k|      const __m256i t0 = _mm256_slli_epi16(in, 2);
  108|       |      // t1 = [000a|aaaa|0000|0000]
  109|  23.9k|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
  110|       |      // t2 = [0000|0000|00bb|bbbb]
  111|  23.9k|      const __m256i t2 = _mm256_and_si256(in, v_003f);
  112|       |      // t3 = [000a|aaaa|00bb|bbbb]
  113|  23.9k|      const __m256i t3 = _mm256_or_si256(t1, t2);
  114|       |      // t4 = [110a|aaaa|10bb|bbbb]
  115|  23.9k|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
  116|       |
  117|       |      // 2. merge ASCII and 2-byte codewords
  118|  23.9k|      const __m256i utf8_unpacked =
  119|  23.9k|          _mm256_blendv_epi8(t4, in, one_byte_bytemask);
  120|       |
  121|       |      // 3. prepare bitmask for 8-bit lookup
  122|  23.9k|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
  123|  23.9k|      const uint32_t M1 = M0 >> 7;
  124|  23.9k|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
  125|       |      // 4. pack the bytes
  126|       |
  127|  23.9k|      const uint8_t *row =
  128|  23.9k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
  129|  23.9k|      const uint8_t *row_2 =
  130|  23.9k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
  131|  23.9k|                                                                       16)][0];
  132|       |
  133|  23.9k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  134|  23.9k|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
  135|       |
  136|  23.9k|      const __m256i utf8_packed = _mm256_shuffle_epi8(
  137|  23.9k|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|  23.9k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|  23.9k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  138|       |      // 5. store bytes
  139|  23.9k|      _mm_storeu_si128((__m128i *)utf8_output,
  140|  23.9k|                       _mm256_castsi256_si128(utf8_packed));
  141|  23.9k|      utf8_output += row[0];
  142|  23.9k|      _mm_storeu_si128((__m128i *)utf8_output,
  143|  23.9k|                       _mm256_extractf128_si256(utf8_packed, 1));
  144|  23.9k|      utf8_output += row_2[0];
  145|       |
  146|       |      // 6. adjust pointers
  147|  23.9k|      buf += 16;
  148|  23.9k|      continue;
  149|  23.9k|    }
  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|   200k|    const __m256i surrogates_bytemask =
  154|   200k|        _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|   200k|    const uint32_t surrogates_bitmask =
  159|   200k|        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|   200k|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (162:9): [True: 190k, False: 9.45k]
  ------------------
  163|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  164|   190k|      const __m256i dup_even = _mm256_setr_epi16(
  165|   190k|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  166|   190k|          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|   190k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  196|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  197|   190k|      const __m256i t0 = _mm256_shuffle_epi8(in, dup_even);
  198|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  199|   190k|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  195|   190k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  200|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  201|   190k|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  195|   190k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  202|       |
  203|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  204|   190k|      const __m256i s0 = _mm256_srli_epi16(in, 4);
  205|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  206|   190k|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  195|   190k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  207|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  208|   190k|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  195|   190k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  209|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  210|   190k|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  195|   190k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  211|   190k|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  212|   190k|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  195|   190k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  213|   190k|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  214|   190k|#undef simdutf_vec
  215|       |
  216|       |      // 4. expand code units 16-bit => 32-bit
  217|   190k|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  218|   190k|      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|   190k|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  222|   190k|                            (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|   190k|      const uint8_t mask0 = uint8_t(mask);
  243|   190k|      const uint8_t *row0 =
  244|   190k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  245|   190k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  246|   190k|      const __m128i utf8_0 =
  247|   190k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  248|       |
  249|   190k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  250|   190k|      const uint8_t *row1 =
  251|   190k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  252|   190k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  253|   190k|      const __m128i utf8_1 =
  254|   190k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  255|       |
  256|   190k|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  257|   190k|      const uint8_t *row2 =
  258|   190k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  259|   190k|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  260|   190k|      const __m128i utf8_2 =
  261|   190k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  262|       |
  263|   190k|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  264|   190k|      const uint8_t *row3 =
  265|   190k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  266|   190k|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  267|   190k|      const __m128i utf8_3 =
  268|   190k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  269|       |
  270|   190k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  271|   190k|      utf8_output += row0[0];
  272|   190k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  273|   190k|      utf8_output += row1[0];
  274|   190k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  275|   190k|      utf8_output += row2[0];
  276|   190k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  277|   190k|      utf8_output += row3[0];
  278|   190k|      buf += 16;
  279|       |      // surrogate pair(s) in a register
  280|   190k|    } 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|  9.45k|      size_t forward = 15;
  285|  9.45k|      size_t k = 0;
  286|  9.45k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (286:11): [True: 0, False: 9.45k]
  ------------------
  287|      0|        forward = size_t(end - buf - 1);
  288|      0|      }
  289|   139k|      for (; k < forward; k++) {
  ------------------
  |  Branch (289:14): [True: 130k, False: 9.34k]
  ------------------
  290|   130k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  291|   130k|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (291:13): [True: 16.0k, False: 114k]
  ------------------
  292|  16.0k|          *utf8_output++ = char(word);
  293|   114k|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (293:20): [True: 3.80k, False: 110k]
  ------------------
  294|  3.80k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  295|  3.80k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  296|   110k|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (296:20): [True: 100k, False: 10.5k]
  ------------------
  297|   100k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  298|   100k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  299|   100k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  300|   100k|        } else {
  301|       |          // must be a surrogate pair
  302|  10.5k|          uint16_t diff = uint16_t(word - 0xD800);
  303|  10.5k|          uint16_t next_word =
  304|  10.5k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  305|  10.5k|          k++;
  306|  10.5k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  307|  10.5k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (307:15): [True: 104, False: 10.4k]
  ------------------
  308|    104|            return std::make_pair(nullptr, utf8_output);
  309|    104|          }
  310|  10.4k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  311|  10.4k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  312|  10.4k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  313|  10.4k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  314|  10.4k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  315|  10.4k|        }
  316|   130k|      }
  317|  9.34k|      buf += k;
  318|  9.34k|    }
  319|   200k|  } // while
  320|    706|  return std::make_pair(buf, utf8_output);
  321|    810|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_138avx2_convert_utf16_to_utf8_with_errorsILNS_10endiannessE0EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
  333|    712|                                       char *utf8_output) {
  334|    712|  const char16_t *start = buf;
  335|    712|  const char16_t *end = buf + len;
  336|       |
  337|    712|  const __m256i v_0000 = _mm256_setzero_si256();
  338|    712|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
  339|    712|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
  340|    712|  const __m256i v_c080 = _mm256_set1_epi16((int16_t)0xc080);
  341|    712|  const size_t safety_margin =
  342|    712|      12; // to avoid overruns, see issue
  343|       |          // https://github.com/simdutf/simdutf/issues/92
  344|       |
  345|   622k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (345:10): [True: 621k, False: 560]
  ------------------
  346|   621k|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
  347|   621k|    if (big_endian) {
  ------------------
  |  Branch (347:9): [Folded, False: 621k]
  ------------------
  348|      0|      const __m256i swap = _mm256_setr_epi8(
  349|      0|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
  350|      0|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
  351|      0|      in = _mm256_shuffle_epi8(in, swap);
  352|      0|    }
  353|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
  354|   621k|    const __m256i v_ff80 = _mm256_set1_epi16((int16_t)0xff80);
  355|   621k|    if (_mm256_testz_si256(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (355:9): [True: 358k, False: 262k]
  ------------------
  356|       |      // 1. pack the bytes
  357|   358k|      const __m128i utf8_packed = _mm_packus_epi16(
  358|   358k|          _mm256_castsi256_si128(in), _mm256_extractf128_si256(in, 1));
  359|       |      // 2. store (16 bytes)
  360|   358k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  361|       |      // 3. adjust pointers
  362|   358k|      buf += 16;
  363|   358k|      utf8_output += 16;
  364|   358k|      continue; // we are done for this round!
  365|   358k|    }
  366|       |    // no bits set above 7th bit
  367|   262k|    const __m256i one_byte_bytemask =
  368|   262k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_ff80), v_0000);
  369|   262k|    const uint32_t one_byte_bitmask =
  370|   262k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
  371|       |
  372|       |    // no bits set above 11th bit
  373|   262k|    const __m256i one_or_two_bytes_bytemask =
  374|   262k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_0000);
  375|   262k|    const uint32_t one_or_two_bytes_bitmask =
  376|   262k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
  377|   262k|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (377:9): [True: 12.1k, False: 250k]
  ------------------
  378|       |
  379|       |      // 1. prepare 2-byte values
  380|       |      // input 16-bit word : [0000|0aaa|aabb|bbbb] x 8
  381|       |      // expected output   : [110a|aaaa|10bb|bbbb] x 8
  382|  12.1k|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
  383|  12.1k|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
  384|       |
  385|       |      // t0 = [000a|aaaa|bbbb|bb00]
  386|  12.1k|      const __m256i t0 = _mm256_slli_epi16(in, 2);
  387|       |      // t1 = [000a|aaaa|0000|0000]
  388|  12.1k|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
  389|       |      // t2 = [0000|0000|00bb|bbbb]
  390|  12.1k|      const __m256i t2 = _mm256_and_si256(in, v_003f);
  391|       |      // t3 = [000a|aaaa|00bb|bbbb]
  392|  12.1k|      const __m256i t3 = _mm256_or_si256(t1, t2);
  393|       |      // t4 = [110a|aaaa|10bb|bbbb]
  394|  12.1k|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
  395|       |
  396|       |      // 2. merge ASCII and 2-byte codewords
  397|  12.1k|      const __m256i utf8_unpacked =
  398|  12.1k|          _mm256_blendv_epi8(t4, in, one_byte_bytemask);
  399|       |
  400|       |      // 3. prepare bitmask for 8-bit lookup
  401|  12.1k|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
  402|  12.1k|      const uint32_t M1 = M0 >> 7;
  403|  12.1k|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
  404|       |      // 4. pack the bytes
  405|       |
  406|  12.1k|      const uint8_t *row =
  407|  12.1k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
  408|  12.1k|      const uint8_t *row_2 =
  409|  12.1k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
  410|  12.1k|                                                                       16)][0];
  411|       |
  412|  12.1k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  413|  12.1k|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
  414|       |
  415|  12.1k|      const __m256i utf8_packed = _mm256_shuffle_epi8(
  416|  12.1k|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|  12.1k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|  12.1k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  417|       |      // 5. store bytes
  418|  12.1k|      _mm_storeu_si128((__m128i *)utf8_output,
  419|  12.1k|                       _mm256_castsi256_si128(utf8_packed));
  420|  12.1k|      utf8_output += row[0];
  421|  12.1k|      _mm_storeu_si128((__m128i *)utf8_output,
  422|  12.1k|                       _mm256_extractf128_si256(utf8_packed, 1));
  423|  12.1k|      utf8_output += row_2[0];
  424|       |
  425|       |      // 6. adjust pointers
  426|  12.1k|      buf += 16;
  427|  12.1k|      continue;
  428|  12.1k|    }
  429|       |    // 1. Check if there are any surrogate word in the input chunk.
  430|       |    //    We have also deal with situation when there is a surrogate word
  431|       |    //    at the end of a chunk.
  432|   250k|    const __m256i surrogates_bytemask =
  433|   250k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_d800);
  434|       |
  435|       |    // bitmask = 0x0000 if there are no surrogates
  436|       |    //         = 0xc000 if the last word is a surrogate
  437|   250k|    const uint32_t surrogates_bitmask =
  438|   250k|        static_cast<uint32_t>(_mm256_movemask_epi8(surrogates_bytemask));
  439|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  440|       |    // However, it is likely an uncommon occurrence.
  441|   250k|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (441:9): [True: 244k, False: 5.79k]
  ------------------
  442|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  443|   244k|      const __m256i dup_even = _mm256_setr_epi16(
  444|   244k|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  445|   244k|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  446|       |
  447|       |      /* In this branch we handle three cases:
  448|       |         1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  449|       |        single UFT-8 byte
  450|       |         2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              - two
  451|       |        UTF-8 bytes
  452|       |         3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  453|       |        three UTF-8 bytes
  454|       |
  455|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  456|       |        we have room for four bytes. However, we need five distinct bit
  457|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  458|       |
  459|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  460|       |        in register t2.
  461|       |
  462|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  463|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  464|       |        differ by exactly one bit.
  465|       |
  466|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  467|       |        into account the case (i.e, the number of bytes to write).
  468|       |      */
  469|       |      /**
  470|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  471|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  472|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  473|       |       */
  474|   244k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  475|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  476|   244k|      const __m256i t0 = _mm256_shuffle_epi8(in, dup_even);
  477|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  478|   244k|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  474|   244k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  479|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  480|   244k|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  474|   244k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  481|       |
  482|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  483|   244k|      const __m256i s0 = _mm256_srli_epi16(in, 4);
  484|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  485|   244k|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  474|   244k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  486|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  487|   244k|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  474|   244k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  488|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  489|   244k|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  474|   244k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  490|   244k|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  491|   244k|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  474|   244k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  492|   244k|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  493|   244k|#undef simdutf_vec
  494|       |
  495|       |      // 4. expand code units 16-bit => 32-bit
  496|   244k|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  497|   244k|      const __m256i out1 = _mm256_unpackhi_epi16(t2, s4);
  498|       |
  499|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  500|   244k|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  501|   244k|                            (one_or_two_bytes_bitmask & 0xaaaaaaaa);
  502|       |      // Due to the wider registers, the following path is less likely to be
  503|       |      // useful.
  504|       |      /*if(mask == 0) {
  505|       |        // We only have three-byte code units. Use fast path.
  506|       |        const __m256i shuffle =
  507|       |      _mm256_setr_epi8(2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1,
  508|       |      2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1); const __m256i utf8_0 =
  509|       |      _mm256_shuffle_epi8(out0, shuffle); const __m256i utf8_1 =
  510|       |      _mm256_shuffle_epi8(out1, shuffle);
  511|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_0));
  512|       |        utf8_output += 12;
  513|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_1));
  514|       |        utf8_output += 12;
  515|       |        _mm_storeu_si128((__m128i*)utf8_output,
  516|       |      _mm256_extractf128_si256(utf8_0,1)); utf8_output += 12;
  517|       |        _mm_storeu_si128((__m128i*)utf8_output,
  518|       |      _mm256_extractf128_si256(utf8_1,1)); utf8_output += 12; buf += 16;
  519|       |        continue;
  520|       |      }*/
  521|   244k|      const uint8_t mask0 = uint8_t(mask);
  522|   244k|      const uint8_t *row0 =
  523|   244k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  524|   244k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  525|   244k|      const __m128i utf8_0 =
  526|   244k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  527|       |
  528|   244k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  529|   244k|      const uint8_t *row1 =
  530|   244k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  531|   244k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  532|   244k|      const __m128i utf8_1 =
  533|   244k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  534|       |
  535|   244k|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  536|   244k|      const uint8_t *row2 =
  537|   244k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  538|   244k|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  539|   244k|      const __m128i utf8_2 =
  540|   244k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  541|       |
  542|   244k|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  543|   244k|      const uint8_t *row3 =
  544|   244k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  545|   244k|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  546|   244k|      const __m128i utf8_3 =
  547|   244k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  548|       |
  549|   244k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  550|   244k|      utf8_output += row0[0];
  551|   244k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  552|   244k|      utf8_output += row1[0];
  553|   244k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  554|   244k|      utf8_output += row2[0];
  555|   244k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  556|   244k|      utf8_output += row3[0];
  557|   244k|      buf += 16;
  558|       |      // surrogate pair(s) in a register
  559|   244k|    } else {
  560|       |      // Let us do a scalar fallback.
  561|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  562|       |      // in the presence of surrogate pairs may require non-trivial tables.
  563|  5.79k|      size_t forward = 15;
  564|  5.79k|      size_t k = 0;
  565|  5.79k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (565:11): [True: 0, False: 5.79k]
  ------------------
  566|      0|        forward = size_t(end - buf - 1);
  567|      0|      }
  568|  85.2k|      for (; k < forward; k++) {
  ------------------
  |  Branch (568:14): [True: 79.5k, False: 5.64k]
  ------------------
  569|  79.5k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  570|  79.5k|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (570:13): [True: 11.2k, False: 68.3k]
  ------------------
  571|  11.2k|          *utf8_output++ = char(word);
  572|  68.3k|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (572:20): [True: 2.92k, False: 65.4k]
  ------------------
  573|  2.92k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  574|  2.92k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  575|  65.4k|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (575:20): [True: 59.0k, False: 6.38k]
  ------------------
  576|  59.0k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  577|  59.0k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  578|  59.0k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  579|  59.0k|        } else {
  580|       |          // must be a surrogate pair
  581|  6.38k|          uint16_t diff = uint16_t(word - 0xD800);
  582|  6.38k|          uint16_t next_word =
  583|  6.38k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  584|  6.38k|          k++;
  585|  6.38k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  586|  6.38k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (586:15): [True: 152, False: 6.22k]
  ------------------
  587|    152|            return std::make_pair(
  588|    152|                result(error_code::SURROGATE, buf - start + k - 1),
  589|    152|                utf8_output);
  590|    152|          }
  591|  6.22k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  592|  6.22k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  593|  6.22k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  594|  6.22k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  595|  6.22k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  596|  6.22k|        }
  597|  79.5k|      }
  598|  5.64k|      buf += k;
  599|  5.64k|    }
  600|   250k|  } // while
  601|    560|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  602|    712|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_138avx2_convert_utf16_to_utf8_with_errorsILNS_10endiannessE1EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
  333|    616|                                       char *utf8_output) {
  334|    616|  const char16_t *start = buf;
  335|    616|  const char16_t *end = buf + len;
  336|       |
  337|    616|  const __m256i v_0000 = _mm256_setzero_si256();
  338|    616|  const __m256i v_f800 = _mm256_set1_epi16((int16_t)0xf800);
  339|    616|  const __m256i v_d800 = _mm256_set1_epi16((int16_t)0xd800);
  340|    616|  const __m256i v_c080 = _mm256_set1_epi16((int16_t)0xc080);
  341|    616|  const size_t safety_margin =
  342|    616|      12; // to avoid overruns, see issue
  343|       |          // https://github.com/simdutf/simdutf/issues/92
  344|       |
  345|   477k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (345:10): [True: 477k, False: 472]
  ------------------
  346|   477k|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
  347|   477k|    if (big_endian) {
  ------------------
  |  Branch (347:9): [True: 477k, Folded]
  ------------------
  348|   477k|      const __m256i swap = _mm256_setr_epi8(
  349|   477k|          1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
  350|   477k|          21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
  351|   477k|      in = _mm256_shuffle_epi8(in, swap);
  352|   477k|    }
  353|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
  354|   477k|    const __m256i v_ff80 = _mm256_set1_epi16((int16_t)0xff80);
  355|   477k|    if (_mm256_testz_si256(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (355:9): [True: 328k, False: 148k]
  ------------------
  356|       |      // 1. pack the bytes
  357|   328k|      const __m128i utf8_packed = _mm_packus_epi16(
  358|   328k|          _mm256_castsi256_si128(in), _mm256_extractf128_si256(in, 1));
  359|       |      // 2. store (16 bytes)
  360|   328k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  361|       |      // 3. adjust pointers
  362|   328k|      buf += 16;
  363|   328k|      utf8_output += 16;
  364|   328k|      continue; // we are done for this round!
  365|   328k|    }
  366|       |    // no bits set above 7th bit
  367|   148k|    const __m256i one_byte_bytemask =
  368|   148k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_ff80), v_0000);
  369|   148k|    const uint32_t one_byte_bitmask =
  370|   148k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
  371|       |
  372|       |    // no bits set above 11th bit
  373|   148k|    const __m256i one_or_two_bytes_bytemask =
  374|   148k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_0000);
  375|   148k|    const uint32_t one_or_two_bytes_bitmask =
  376|   148k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
  377|   148k|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (377:9): [True: 27.0k, False: 121k]
  ------------------
  378|       |
  379|       |      // 1. prepare 2-byte values
  380|       |      // input 16-bit word : [0000|0aaa|aabb|bbbb] x 8
  381|       |      // expected output   : [110a|aaaa|10bb|bbbb] x 8
  382|  27.0k|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
  383|  27.0k|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
  384|       |
  385|       |      // t0 = [000a|aaaa|bbbb|bb00]
  386|  27.0k|      const __m256i t0 = _mm256_slli_epi16(in, 2);
  387|       |      // t1 = [000a|aaaa|0000|0000]
  388|  27.0k|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
  389|       |      // t2 = [0000|0000|00bb|bbbb]
  390|  27.0k|      const __m256i t2 = _mm256_and_si256(in, v_003f);
  391|       |      // t3 = [000a|aaaa|00bb|bbbb]
  392|  27.0k|      const __m256i t3 = _mm256_or_si256(t1, t2);
  393|       |      // t4 = [110a|aaaa|10bb|bbbb]
  394|  27.0k|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
  395|       |
  396|       |      // 2. merge ASCII and 2-byte codewords
  397|  27.0k|      const __m256i utf8_unpacked =
  398|  27.0k|          _mm256_blendv_epi8(t4, in, one_byte_bytemask);
  399|       |
  400|       |      // 3. prepare bitmask for 8-bit lookup
  401|  27.0k|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
  402|  27.0k|      const uint32_t M1 = M0 >> 7;
  403|  27.0k|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
  404|       |      // 4. pack the bytes
  405|       |
  406|  27.0k|      const uint8_t *row =
  407|  27.0k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
  408|  27.0k|      const uint8_t *row_2 =
  409|  27.0k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
  410|  27.0k|                                                                       16)][0];
  411|       |
  412|  27.0k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  413|  27.0k|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
  414|       |
  415|  27.0k|      const __m256i utf8_packed = _mm256_shuffle_epi8(
  416|  27.0k|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|  27.0k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|  27.0k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  417|       |      // 5. store bytes
  418|  27.0k|      _mm_storeu_si128((__m128i *)utf8_output,
  419|  27.0k|                       _mm256_castsi256_si128(utf8_packed));
  420|  27.0k|      utf8_output += row[0];
  421|  27.0k|      _mm_storeu_si128((__m128i *)utf8_output,
  422|  27.0k|                       _mm256_extractf128_si256(utf8_packed, 1));
  423|  27.0k|      utf8_output += row_2[0];
  424|       |
  425|       |      // 6. adjust pointers
  426|  27.0k|      buf += 16;
  427|  27.0k|      continue;
  428|  27.0k|    }
  429|       |    // 1. Check if there are any surrogate word in the input chunk.
  430|       |    //    We have also deal with situation when there is a surrogate word
  431|       |    //    at the end of a chunk.
  432|   121k|    const __m256i surrogates_bytemask =
  433|   121k|        _mm256_cmpeq_epi16(_mm256_and_si256(in, v_f800), v_d800);
  434|       |
  435|       |    // bitmask = 0x0000 if there are no surrogates
  436|       |    //         = 0xc000 if the last word is a surrogate
  437|   121k|    const uint32_t surrogates_bitmask =
  438|   121k|        static_cast<uint32_t>(_mm256_movemask_epi8(surrogates_bytemask));
  439|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  440|       |    // However, it is likely an uncommon occurrence.
  441|   121k|    if (surrogates_bitmask == 0x00000000) {
  ------------------
  |  Branch (441:9): [True: 110k, False: 10.6k]
  ------------------
  442|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  443|   110k|      const __m256i dup_even = _mm256_setr_epi16(
  444|   110k|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  445|   110k|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  446|       |
  447|       |      /* In this branch we handle three cases:
  448|       |         1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  449|       |        single UFT-8 byte
  450|       |         2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              - two
  451|       |        UTF-8 bytes
  452|       |         3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  453|       |        three UTF-8 bytes
  454|       |
  455|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  456|       |        we have room for four bytes. However, we need five distinct bit
  457|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  458|       |
  459|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  460|       |        in register t2.
  461|       |
  462|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  463|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  464|       |        differ by exactly one bit.
  465|       |
  466|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  467|       |        into account the case (i.e, the number of bytes to write).
  468|       |      */
  469|       |      /**
  470|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  471|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  472|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  473|       |       */
  474|   110k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  475|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  476|   110k|      const __m256i t0 = _mm256_shuffle_epi8(in, dup_even);
  477|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  478|   110k|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  474|   110k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  479|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  480|   110k|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  474|   110k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  481|       |
  482|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  483|   110k|      const __m256i s0 = _mm256_srli_epi16(in, 4);
  484|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  485|   110k|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  474|   110k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  486|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  487|   110k|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  474|   110k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  488|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  489|   110k|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  474|   110k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  490|   110k|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  491|   110k|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  474|   110k|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  492|   110k|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  493|   110k|#undef simdutf_vec
  494|       |
  495|       |      // 4. expand code units 16-bit => 32-bit
  496|   110k|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  497|   110k|      const __m256i out1 = _mm256_unpackhi_epi16(t2, s4);
  498|       |
  499|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  500|   110k|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  501|   110k|                            (one_or_two_bytes_bitmask & 0xaaaaaaaa);
  502|       |      // Due to the wider registers, the following path is less likely to be
  503|       |      // useful.
  504|       |      /*if(mask == 0) {
  505|       |        // We only have three-byte code units. Use fast path.
  506|       |        const __m256i shuffle =
  507|       |      _mm256_setr_epi8(2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1,
  508|       |      2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1); const __m256i utf8_0 =
  509|       |      _mm256_shuffle_epi8(out0, shuffle); const __m256i utf8_1 =
  510|       |      _mm256_shuffle_epi8(out1, shuffle);
  511|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_0));
  512|       |        utf8_output += 12;
  513|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_1));
  514|       |        utf8_output += 12;
  515|       |        _mm_storeu_si128((__m128i*)utf8_output,
  516|       |      _mm256_extractf128_si256(utf8_0,1)); utf8_output += 12;
  517|       |        _mm_storeu_si128((__m128i*)utf8_output,
  518|       |      _mm256_extractf128_si256(utf8_1,1)); utf8_output += 12; buf += 16;
  519|       |        continue;
  520|       |      }*/
  521|   110k|      const uint8_t mask0 = uint8_t(mask);
  522|   110k|      const uint8_t *row0 =
  523|   110k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  524|   110k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  525|   110k|      const __m128i utf8_0 =
  526|   110k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  527|       |
  528|   110k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  529|   110k|      const uint8_t *row1 =
  530|   110k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  531|   110k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  532|   110k|      const __m128i utf8_1 =
  533|   110k|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  534|       |
  535|   110k|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  536|   110k|      const uint8_t *row2 =
  537|   110k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  538|   110k|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  539|   110k|      const __m128i utf8_2 =
  540|   110k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  541|       |
  542|   110k|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  543|   110k|      const uint8_t *row3 =
  544|   110k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  545|   110k|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  546|   110k|      const __m128i utf8_3 =
  547|   110k|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  548|       |
  549|   110k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  550|   110k|      utf8_output += row0[0];
  551|   110k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  552|   110k|      utf8_output += row1[0];
  553|   110k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  554|   110k|      utf8_output += row2[0];
  555|   110k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  556|   110k|      utf8_output += row3[0];
  557|   110k|      buf += 16;
  558|       |      // surrogate pair(s) in a register
  559|   110k|    } else {
  560|       |      // Let us do a scalar fallback.
  561|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  562|       |      // in the presence of surrogate pairs may require non-trivial tables.
  563|  10.6k|      size_t forward = 15;
  564|  10.6k|      size_t k = 0;
  565|  10.6k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (565:11): [True: 0, False: 10.6k]
  ------------------
  566|      0|        forward = size_t(end - buf - 1);
  567|      0|      }
  568|   157k|      for (; k < forward; k++) {
  ------------------
  |  Branch (568:14): [True: 147k, False: 10.4k]
  ------------------
  569|   147k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  570|   147k|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (570:13): [True: 56.8k, False: 90.4k]
  ------------------
  571|  56.8k|          *utf8_output++ = char(word);
  572|  90.4k|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (572:20): [True: 6.24k, False: 84.2k]
  ------------------
  573|  6.24k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  574|  6.24k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  575|  84.2k|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (575:20): [True: 72.9k, False: 11.2k]
  ------------------
  576|  72.9k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  577|  72.9k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  578|  72.9k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  579|  72.9k|        } else {
  580|       |          // must be a surrogate pair
  581|  11.2k|          uint16_t diff = uint16_t(word - 0xD800);
  582|  11.2k|          uint16_t next_word =
  583|  11.2k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  584|  11.2k|          k++;
  585|  11.2k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  586|  11.2k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (586:15): [True: 144, False: 11.1k]
  ------------------
  587|    144|            return std::make_pair(
  588|    144|                result(error_code::SURROGATE, buf - start + k - 1),
  589|    144|                utf8_output);
  590|    144|          }
  591|  11.1k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  592|  11.1k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  593|  11.1k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  594|  11.1k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  595|  11.1k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  596|  11.1k|        }
  597|   147k|      }
  598|  10.4k|      buf += k;
  599|  10.4k|    }
  600|   121k|  } // while
  601|    472|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  602|    616|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_128avx2_convert_utf32_to_latin1EPKDimPc:
    3|    186|                             char *latin1_output) {
    4|    186|  const size_t rounded_len =
    5|    186|      len & ~0x1F; // Round down to nearest multiple of 32
    6|       |
    7|    186|  const __m256i high_bytes_mask = _mm256_set1_epi32(0xFFFFFF00);
    8|       |
    9|    774|  for (size_t i = 0; i < rounded_len; i += 4 * 8) {
  ------------------
  |  Branch (9:22): [True: 622, False: 152]
  ------------------
   10|    622|    __m256i a = _mm256_loadu_si256((__m256i *)(buf + 0 * 8));
   11|    622|    __m256i b = _mm256_loadu_si256((__m256i *)(buf + 1 * 8));
   12|    622|    __m256i c = _mm256_loadu_si256((__m256i *)(buf + 2 * 8));
   13|    622|    __m256i d = _mm256_loadu_si256((__m256i *)(buf + 3 * 8));
   14|       |
   15|    622|    const __m256i check_combined =
   16|    622|        _mm256_or_si256(_mm256_or_si256(a, b), _mm256_or_si256(c, d));
   17|       |
   18|    622|    if (!_mm256_testz_si256(check_combined, high_bytes_mask)) {
  ------------------
  |  Branch (18:9): [True: 34, False: 588]
  ------------------
   19|     34|      return std::make_pair(nullptr, latin1_output);
   20|     34|    }
   21|       |
   22|    588|    b = _mm256_slli_epi32(b, 1 * 8);
   23|    588|    c = _mm256_slli_epi32(c, 2 * 8);
   24|    588|    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|    588|    const __m256i t0 =
   35|    588|        _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|    588|    const __m256i shuffle_bytes =
   40|    588|        _mm256_setr_epi8(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15,
   41|    588|                         0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15);
   42|       |
   43|    588|    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|    588|    const __m256i shuffle_dwords = _mm256_setr_epi32(0, 4, 1, 5, 2, 6, 3, 7);
   48|    588|    const __m256i t2 = _mm256_permutevar8x32_epi32(t1, shuffle_dwords);
   49|       |// clang format on
   50|       |
   51|    588|    _mm256_storeu_si256((__m256i *)latin1_output, t2);
   52|       |
   53|    588|    latin1_output += 32;
   54|    588|    buf += 32;
   55|    588|  }
   56|       |
   57|    152|  return std::make_pair(buf, latin1_output);
   58|    186|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_140avx2_convert_utf32_to_latin1_with_errorsEPKDimPc:
   62|    488|                                         char *latin1_output) {
   63|    488|  const size_t rounded_len =
   64|    488|      len & ~0x1F; // Round down to nearest multiple of 32
   65|       |
   66|    488|  const char32_t *start = buf;
   67|       |
   68|    488|  const __m256i high_bytes_mask = _mm256_set1_epi32(0xFFFFFF00);
   69|       |
   70|  17.2k|  for (size_t i = 0; i < rounded_len; i += 4 * 8) {
  ------------------
  |  Branch (70:22): [True: 16.9k, False: 348]
  ------------------
   71|  16.9k|    __m256i a = _mm256_loadu_si256((__m256i *)(buf + 0 * 8));
   72|  16.9k|    __m256i b = _mm256_loadu_si256((__m256i *)(buf + 1 * 8));
   73|  16.9k|    __m256i c = _mm256_loadu_si256((__m256i *)(buf + 2 * 8));
   74|  16.9k|    __m256i d = _mm256_loadu_si256((__m256i *)(buf + 3 * 8));
   75|       |
   76|  16.9k|    const __m256i check_combined =
   77|  16.9k|        _mm256_or_si256(_mm256_or_si256(a, b), _mm256_or_si256(c, d));
   78|       |
   79|  16.9k|    if (!_mm256_testz_si256(check_combined, high_bytes_mask)) {
  ------------------
  |  Branch (79:9): [True: 140, False: 16.7k]
  ------------------
   80|       |      // Fallback to scalar code for handling errors
   81|    778|      for (int k = 0; k < 4 * 8; k++) {
  ------------------
  |  Branch (81:23): [True: 778, False: 0]
  ------------------
   82|    778|        char32_t codepoint = buf[k];
   83|    778|        if (codepoint <= 0xFF) {
  ------------------
  |  Branch (83:13): [True: 638, False: 140]
  ------------------
   84|    638|          *latin1_output++ = static_cast<char>(codepoint);
   85|    638|        } else {
   86|    140|          return std::make_pair(result(error_code::TOO_LARGE, buf - start + k),
   87|    140|                                latin1_output);
   88|    140|        }
   89|    778|      }
   90|    140|    }
   91|       |
   92|  16.7k|    b = _mm256_slli_epi32(b, 1 * 8);
   93|  16.7k|    c = _mm256_slli_epi32(c, 2 * 8);
   94|  16.7k|    d = _mm256_slli_epi32(d, 3 * 8);
   95|       |
   96|  16.7k|    const __m256i t0 =
   97|  16.7k|        _mm256_or_si256(_mm256_or_si256(a, b), _mm256_or_si256(c, d));
   98|       |
   99|  16.7k|    const __m256i shuffle_bytes =
  100|  16.7k|        _mm256_setr_epi8(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15,
  101|  16.7k|                         0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15);
  102|       |
  103|  16.7k|    const __m256i t1 = _mm256_shuffle_epi8(t0, shuffle_bytes);
  104|       |
  105|  16.7k|    const __m256i shuffle_dwords = _mm256_setr_epi32(0, 4, 1, 5, 2, 6, 3, 7);
  106|  16.7k|    const __m256i t2 = _mm256_permutevar8x32_epi32(t1, shuffle_dwords);
  107|       |
  108|  16.7k|    _mm256_storeu_si256((__m256i *)latin1_output, t2);
  109|       |
  110|  16.7k|    latin1_output += 32;
  111|  16.7k|    buf += 32;
  112|  16.7k|  }
  113|       |
  114|    348|  return std::make_pair(result(error_code::SUCCESS, buf - start),
  115|    348|                        latin1_output);
  116|    488|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_127avx2_convert_utf32_to_utf16ILNS_10endiannessE0EEENSt3__14pairIPKDiPDsEES7_mS8_:
    4|    794|                            char16_t *utf16_output) {
    5|    794|  const char32_t *end = buf + len;
    6|       |
    7|    794|  const size_t safety_margin =
    8|    794|      12; // to avoid overruns, see issue
    9|       |          // https://github.com/simdutf/simdutf/issues/92
   10|    794|  __m256i forbidden_bytemask = _mm256_setzero_si256();
   11|       |
   12|    794|  const __m256i v_ffff0000 = _mm256_set1_epi32((int32_t)0xffff0000);
   13|    794|  const __m256i v_f800 = _mm256_set1_epi32((uint32_t)0xf800);
   14|    794|  const __m256i v_d800 = _mm256_set1_epi32((uint32_t)0xd800);
   15|       |
   16|  19.7k|  while (end - buf >= std::ptrdiff_t(8 + safety_margin)) {
  ------------------
  |  Branch (16:10): [True: 19.1k, False: 642]
  ------------------
   17|  19.1k|    const __m256i in = _mm256_loadu_si256((__m256i *)buf);
   18|       |
   19|  19.1k|    if (simdutf_likely(_mm256_testz_si256(in, v_ffff0000))) {
  ------------------
  |  |   90|  19.1k|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 17.3k, False: 1.76k]
  |  |  ------------------
  ------------------
   20|       |      // no bits set above 16th bit <=> can pack to UTF16
   21|       |      // without surrogate pairs
   22|  17.3k|      forbidden_bytemask = _mm256_or_si256(
   23|  17.3k|          forbidden_bytemask,
   24|  17.3k|          _mm256_cmpeq_epi32(_mm256_and_si256(in, v_f800), v_d800));
   25|       |
   26|  17.3k|      __m128i utf16_packed = _mm_packus_epi32(_mm256_castsi256_si128(in),
   27|  17.3k|                                              _mm256_extractf128_si256(in, 1));
   28|  17.3k|      if (big_endian) {
  ------------------
  |  Branch (28:11): [Folded, False: 17.3k]
  ------------------
   29|      0|        const __m128i swap =
   30|      0|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   31|      0|        utf16_packed = _mm_shuffle_epi8(utf16_packed, swap);
   32|      0|      }
   33|  17.3k|      _mm_storeu_si128((__m128i *)utf16_output, utf16_packed);
   34|  17.3k|      utf16_output += 8;
   35|  17.3k|      buf += 8;
   36|  17.3k|    } else {
   37|  1.76k|      size_t forward = 7;
   38|  1.76k|      size_t k = 0;
   39|  1.76k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (39:11): [True: 0, False: 1.76k]
  ------------------
   40|      0|        forward = size_t(end - buf - 1);
   41|      0|      }
   42|  13.4k|      for (; k < forward; k++) {
  ------------------
  |  Branch (42:14): [True: 11.8k, False: 1.61k]
  ------------------
   43|  11.8k|        uint32_t word = buf[k];
   44|  11.8k|        if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (44:13): [True: 3.44k, False: 8.37k]
  ------------------
   45|       |          // will not generate a surrogate pair
   46|  3.44k|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (46:15): [True: 764, False: 2.68k]
  |  Branch (46:33): [True: 24, False: 740]
  ------------------
   47|     24|            return std::make_pair(nullptr, utf16_output);
   48|     24|          }
   49|  3.42k|          *utf16_output++ =
   50|  3.42k|              big_endian
  ------------------
  |  Branch (50:15): [Folded, False: 3.42k]
  ------------------
   51|  3.42k|                  ? char16_t((uint16_t(word) >> 8) | (uint16_t(word) << 8))
   52|  3.42k|                  : char16_t(word);
   53|  8.37k|        } else {
   54|       |          // will generate a surrogate pair
   55|  8.37k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (55:15): [True: 128, False: 8.24k]
  ------------------
   56|    128|            return std::make_pair(nullptr, utf16_output);
   57|    128|          }
   58|  8.24k|          word -= 0x10000;
   59|  8.24k|          uint16_t high_surrogate = uint16_t(0xD800 + (word >> 10));
   60|  8.24k|          uint16_t low_surrogate = uint16_t(0xDC00 + (word & 0x3FF));
   61|  8.24k|          if (big_endian) {
  ------------------
  |  Branch (61:15): [Folded, False: 8.24k]
  ------------------
   62|      0|            high_surrogate =
   63|      0|                uint16_t((high_surrogate >> 8) | (high_surrogate << 8));
   64|      0|            low_surrogate =
   65|      0|                uint16_t((low_surrogate >> 8) | (low_surrogate << 8));
   66|      0|          }
   67|  8.24k|          *utf16_output++ = char16_t(high_surrogate);
   68|  8.24k|          *utf16_output++ = char16_t(low_surrogate);
   69|  8.24k|        }
   70|  11.8k|      }
   71|  1.61k|      buf += k;
   72|  1.61k|    }
   73|  19.1k|  }
   74|       |
   75|       |  // check for invalid input
   76|    642|  if (static_cast<uint32_t>(_mm256_movemask_epi8(forbidden_bytemask)) != 0) {
  ------------------
  |  Branch (76:7): [True: 32, False: 610]
  ------------------
   77|     32|    return std::make_pair(nullptr, utf16_output);
   78|     32|  }
   79|       |
   80|    610|  return std::make_pair(buf, utf16_output);
   81|    642|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_127avx2_convert_utf32_to_utf16ILNS_10endiannessE1EEENSt3__14pairIPKDiPDsEES7_mS8_:
    4|    652|                            char16_t *utf16_output) {
    5|    652|  const char32_t *end = buf + len;
    6|       |
    7|    652|  const size_t safety_margin =
    8|    652|      12; // to avoid overruns, see issue
    9|       |          // https://github.com/simdutf/simdutf/issues/92
   10|    652|  __m256i forbidden_bytemask = _mm256_setzero_si256();
   11|       |
   12|    652|  const __m256i v_ffff0000 = _mm256_set1_epi32((int32_t)0xffff0000);
   13|    652|  const __m256i v_f800 = _mm256_set1_epi32((uint32_t)0xf800);
   14|    652|  const __m256i v_d800 = _mm256_set1_epi32((uint32_t)0xd800);
   15|       |
   16|  8.92k|  while (end - buf >= std::ptrdiff_t(8 + safety_margin)) {
  ------------------
  |  Branch (16:10): [True: 8.43k, False: 492]
  ------------------
   17|  8.43k|    const __m256i in = _mm256_loadu_si256((__m256i *)buf);
   18|       |
   19|  8.43k|    if (simdutf_likely(_mm256_testz_si256(in, v_ffff0000))) {
  ------------------
  |  |   90|  8.43k|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 5.26k, False: 3.16k]
  |  |  ------------------
  ------------------
   20|       |      // no bits set above 16th bit <=> can pack to UTF16
   21|       |      // without surrogate pairs
   22|  5.26k|      forbidden_bytemask = _mm256_or_si256(
   23|  5.26k|          forbidden_bytemask,
   24|  5.26k|          _mm256_cmpeq_epi32(_mm256_and_si256(in, v_f800), v_d800));
   25|       |
   26|  5.26k|      __m128i utf16_packed = _mm_packus_epi32(_mm256_castsi256_si128(in),
   27|  5.26k|                                              _mm256_extractf128_si256(in, 1));
   28|  5.26k|      if (big_endian) {
  ------------------
  |  Branch (28:11): [True: 5.26k, Folded]
  ------------------
   29|  5.26k|        const __m128i swap =
   30|  5.26k|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   31|  5.26k|        utf16_packed = _mm_shuffle_epi8(utf16_packed, swap);
   32|  5.26k|      }
   33|  5.26k|      _mm_storeu_si128((__m128i *)utf16_output, utf16_packed);
   34|  5.26k|      utf16_output += 8;
   35|  5.26k|      buf += 8;
   36|  5.26k|    } else {
   37|  3.16k|      size_t forward = 7;
   38|  3.16k|      size_t k = 0;
   39|  3.16k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (39:11): [True: 0, False: 3.16k]
  ------------------
   40|      0|        forward = size_t(end - buf - 1);
   41|      0|      }
   42|  24.6k|      for (; k < forward; k++) {
  ------------------
  |  Branch (42:14): [True: 21.6k, False: 3.00k]
  ------------------
   43|  21.6k|        uint32_t word = buf[k];
   44|  21.6k|        if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (44:13): [True: 2.51k, False: 19.1k]
  ------------------
   45|       |          // will not generate a surrogate pair
   46|  2.51k|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (46:15): [True: 228, False: 2.28k]
  |  Branch (46:33): [True: 24, False: 204]
  ------------------
   47|     24|            return std::make_pair(nullptr, utf16_output);
   48|     24|          }
   49|  2.48k|          *utf16_output++ =
   50|  2.48k|              big_endian
  ------------------
  |  Branch (50:15): [True: 2.48k, Folded]
  ------------------
   51|  2.48k|                  ? char16_t((uint16_t(word) >> 8) | (uint16_t(word) << 8))
   52|  2.48k|                  : char16_t(word);
   53|  19.1k|        } else {
   54|       |          // will generate a surrogate pair
   55|  19.1k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (55:15): [True: 136, False: 18.9k]
  ------------------
   56|    136|            return std::make_pair(nullptr, utf16_output);
   57|    136|          }
   58|  18.9k|          word -= 0x10000;
   59|  18.9k|          uint16_t high_surrogate = uint16_t(0xD800 + (word >> 10));
   60|  18.9k|          uint16_t low_surrogate = uint16_t(0xDC00 + (word & 0x3FF));
   61|  18.9k|          if (big_endian) {
  ------------------
  |  Branch (61:15): [True: 18.9k, Folded]
  ------------------
   62|  18.9k|            high_surrogate =
   63|  18.9k|                uint16_t((high_surrogate >> 8) | (high_surrogate << 8));
   64|  18.9k|            low_surrogate =
   65|  18.9k|                uint16_t((low_surrogate >> 8) | (low_surrogate << 8));
   66|  18.9k|          }
   67|  18.9k|          *utf16_output++ = char16_t(high_surrogate);
   68|  18.9k|          *utf16_output++ = char16_t(low_surrogate);
   69|  18.9k|        }
   70|  21.6k|      }
   71|  3.00k|      buf += k;
   72|  3.00k|    }
   73|  8.43k|  }
   74|       |
   75|       |  // check for invalid input
   76|    492|  if (static_cast<uint32_t>(_mm256_movemask_epi8(forbidden_bytemask)) != 0) {
  ------------------
  |  Branch (76:7): [True: 32, False: 460]
  ------------------
   77|     32|    return std::make_pair(nullptr, utf16_output);
   78|     32|  }
   79|       |
   80|    460|  return std::make_pair(buf, utf16_output);
   81|    492|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_139avx2_convert_utf32_to_utf16_with_errorsILNS_10endiannessE0EEENSt3__14pairINS_6resultEPDsEEPKDimS7_:
   86|    772|                                        char16_t *utf16_output) {
   87|    772|  const char32_t *start = buf;
   88|    772|  const char32_t *end = buf + len;
   89|       |
   90|    772|  const size_t safety_margin =
   91|    772|      12; // to avoid overruns, see issue
   92|       |          // https://github.com/simdutf/simdutf/issues/92
   93|       |
   94|    772|  const __m256i v_ffff0000 = _mm256_set1_epi32((int32_t)0xffff0000);
   95|    772|  const __m256i v_f800 = _mm256_set1_epi32((uint32_t)0xf800);
   96|    772|  const __m256i v_d800 = _mm256_set1_epi32((uint32_t)0xd800);
   97|       |
   98|  12.8k|  while (end - buf >= std::ptrdiff_t(8 + safety_margin)) {
  ------------------
  |  Branch (98:10): [True: 12.2k, False: 552]
  ------------------
   99|  12.2k|    const __m256i in = _mm256_loadu_si256((__m256i *)buf);
  100|       |
  101|  12.2k|    if (simdutf_likely(_mm256_testz_si256(in, v_ffff0000))) {
  ------------------
  |  |   90|  12.2k|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 9.88k, False: 2.39k]
  |  |  ------------------
  ------------------
  102|       |      // no bits set above 16th bit <=> can pack to UTF16 without surrogate
  103|       |      // pairs
  104|  9.88k|      const __m256i forbidden_bytemask =
  105|  9.88k|          _mm256_cmpeq_epi32(_mm256_and_si256(in, v_f800), v_d800);
  106|  9.88k|      if (static_cast<uint32_t>(_mm256_movemask_epi8(forbidden_bytemask)) !=
  ------------------
  |  Branch (106:11): [True: 28, False: 9.85k]
  ------------------
  107|  9.88k|          0x0) {
  108|     28|        return std::make_pair(result(error_code::SURROGATE, buf - start),
  109|     28|                              utf16_output);
  110|     28|      }
  111|       |
  112|  9.85k|      __m128i utf16_packed = _mm_packus_epi32(_mm256_castsi256_si128(in),
  113|  9.85k|                                              _mm256_extractf128_si256(in, 1));
  114|  9.85k|      if (big_endian) {
  ------------------
  |  Branch (114:11): [Folded, False: 9.85k]
  ------------------
  115|      0|        const __m128i swap =
  116|      0|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  117|      0|        utf16_packed = _mm_shuffle_epi8(utf16_packed, swap);
  118|      0|      }
  119|  9.85k|      _mm_storeu_si128((__m128i *)utf16_output, utf16_packed);
  120|  9.85k|      utf16_output += 8;
  121|  9.85k|      buf += 8;
  122|  9.85k|    } else {
  123|  2.39k|      size_t forward = 7;
  124|  2.39k|      size_t k = 0;
  125|  2.39k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (125:11): [True: 0, False: 2.39k]
  ------------------
  126|      0|        forward = size_t(end - buf - 1);
  127|      0|      }
  128|  18.1k|      for (; k < forward; k++) {
  ------------------
  |  Branch (128:14): [True: 15.9k, False: 2.20k]
  ------------------
  129|  15.9k|        uint32_t word = buf[k];
  130|  15.9k|        if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (130:13): [True: 9.14k, False: 6.84k]
  ------------------
  131|       |          // will not generate a surrogate pair
  132|  9.14k|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (132:15): [True: 822, False: 8.31k]
  |  Branch (132:33): [True: 20, False: 802]
  ------------------
  133|     20|            return std::make_pair(
  134|     20|                result(error_code::SURROGATE, buf - start + k), utf16_output);
  135|     20|          }
  136|  9.12k|          *utf16_output++ =
  137|  9.12k|              big_endian
  ------------------
  |  Branch (137:15): [Folded, False: 9.12k]
  ------------------
  138|  9.12k|                  ? char16_t((uint16_t(word) >> 8) | (uint16_t(word) << 8))
  139|  9.12k|                  : char16_t(word);
  140|  9.12k|        } else {
  141|       |          // will generate a surrogate pair
  142|  6.84k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (142:15): [True: 172, False: 6.67k]
  ------------------
  143|    172|            return std::make_pair(
  144|    172|                result(error_code::TOO_LARGE, buf - start + k), utf16_output);
  145|    172|          }
  146|  6.67k|          word -= 0x10000;
  147|  6.67k|          uint16_t high_surrogate = uint16_t(0xD800 + (word >> 10));
  148|  6.67k|          uint16_t low_surrogate = uint16_t(0xDC00 + (word & 0x3FF));
  149|  6.67k|          if (big_endian) {
  ------------------
  |  Branch (149:15): [Folded, False: 6.67k]
  ------------------
  150|      0|            high_surrogate =
  151|      0|                uint16_t((high_surrogate >> 8) | (high_surrogate << 8));
  152|      0|            low_surrogate =
  153|      0|                uint16_t((low_surrogate >> 8) | (low_surrogate << 8));
  154|      0|          }
  155|  6.67k|          *utf16_output++ = char16_t(high_surrogate);
  156|  6.67k|          *utf16_output++ = char16_t(low_surrogate);
  157|  6.67k|        }
  158|  15.9k|      }
  159|  2.20k|      buf += k;
  160|  2.20k|    }
  161|  12.2k|  }
  162|       |
  163|    552|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf16_output);
  164|    772|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_139avx2_convert_utf32_to_utf16_with_errorsILNS_10endiannessE1EEENSt3__14pairINS_6resultEPDsEEPKDimS7_:
   86|    678|                                        char16_t *utf16_output) {
   87|    678|  const char32_t *start = buf;
   88|    678|  const char32_t *end = buf + len;
   89|       |
   90|    678|  const size_t safety_margin =
   91|    678|      12; // to avoid overruns, see issue
   92|       |          // https://github.com/simdutf/simdutf/issues/92
   93|       |
   94|    678|  const __m256i v_ffff0000 = _mm256_set1_epi32((int32_t)0xffff0000);
   95|    678|  const __m256i v_f800 = _mm256_set1_epi32((uint32_t)0xf800);
   96|    678|  const __m256i v_d800 = _mm256_set1_epi32((uint32_t)0xd800);
   97|       |
   98|  20.1k|  while (end - buf >= std::ptrdiff_t(8 + safety_margin)) {
  ------------------
  |  Branch (98:10): [True: 19.6k, False: 506]
  ------------------
   99|  19.6k|    const __m256i in = _mm256_loadu_si256((__m256i *)buf);
  100|       |
  101|  19.6k|    if (simdutf_likely(_mm256_testz_si256(in, v_ffff0000))) {
  ------------------
  |  |   90|  19.6k|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 18.9k, False: 754]
  |  |  ------------------
  ------------------
  102|       |      // no bits set above 16th bit <=> can pack to UTF16 without surrogate
  103|       |      // pairs
  104|  18.9k|      const __m256i forbidden_bytemask =
  105|  18.9k|          _mm256_cmpeq_epi32(_mm256_and_si256(in, v_f800), v_d800);
  106|  18.9k|      if (static_cast<uint32_t>(_mm256_movemask_epi8(forbidden_bytemask)) !=
  ------------------
  |  Branch (106:11): [True: 10, False: 18.9k]
  ------------------
  107|  18.9k|          0x0) {
  108|     10|        return std::make_pair(result(error_code::SURROGATE, buf - start),
  109|     10|                              utf16_output);
  110|     10|      }
  111|       |
  112|  18.9k|      __m128i utf16_packed = _mm_packus_epi32(_mm256_castsi256_si128(in),
  113|  18.9k|                                              _mm256_extractf128_si256(in, 1));
  114|  18.9k|      if (big_endian) {
  ------------------
  |  Branch (114:11): [True: 18.9k, Folded]
  ------------------
  115|  18.9k|        const __m128i swap =
  116|  18.9k|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  117|  18.9k|        utf16_packed = _mm_shuffle_epi8(utf16_packed, swap);
  118|  18.9k|      }
  119|  18.9k|      _mm_storeu_si128((__m128i *)utf16_output, utf16_packed);
  120|  18.9k|      utf16_output += 8;
  121|  18.9k|      buf += 8;
  122|  18.9k|    } else {
  123|    754|      size_t forward = 7;
  124|    754|      size_t k = 0;
  125|    754|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (125:11): [True: 0, False: 754]
  ------------------
  126|      0|        forward = size_t(end - buf - 1);
  127|      0|      }
  128|  5.24k|      for (; k < forward; k++) {
  ------------------
  |  Branch (128:14): [True: 4.65k, False: 592]
  ------------------
  129|  4.65k|        uint32_t word = buf[k];
  130|  4.65k|        if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (130:13): [True: 2.37k, False: 2.27k]
  ------------------
  131|       |          // will not generate a surrogate pair
  132|  2.37k|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (132:15): [True: 496, False: 1.88k]
  |  Branch (132:33): [True: 10, False: 486]
  ------------------
  133|     10|            return std::make_pair(
  134|     10|                result(error_code::SURROGATE, buf - start + k), utf16_output);
  135|     10|          }
  136|  2.36k|          *utf16_output++ =
  137|  2.36k|              big_endian
  ------------------
  |  Branch (137:15): [True: 2.36k, Folded]
  ------------------
  138|  2.36k|                  ? char16_t((uint16_t(word) >> 8) | (uint16_t(word) << 8))
  139|  2.36k|                  : char16_t(word);
  140|  2.36k|        } else {
  141|       |          // will generate a surrogate pair
  142|  2.27k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (142:15): [True: 152, False: 2.12k]
  ------------------
  143|    152|            return std::make_pair(
  144|    152|                result(error_code::TOO_LARGE, buf - start + k), utf16_output);
  145|    152|          }
  146|  2.12k|          word -= 0x10000;
  147|  2.12k|          uint16_t high_surrogate = uint16_t(0xD800 + (word >> 10));
  148|  2.12k|          uint16_t low_surrogate = uint16_t(0xDC00 + (word & 0x3FF));
  149|  2.12k|          if (big_endian) {
  ------------------
  |  Branch (149:15): [True: 2.12k, Folded]
  ------------------
  150|  2.12k|            high_surrogate =
  151|  2.12k|                uint16_t((high_surrogate >> 8) | (high_surrogate << 8));
  152|  2.12k|            low_surrogate =
  153|  2.12k|                uint16_t((low_surrogate >> 8) | (low_surrogate << 8));
  154|  2.12k|          }
  155|  2.12k|          *utf16_output++ = char16_t(high_surrogate);
  156|  2.12k|          *utf16_output++ = char16_t(low_surrogate);
  157|  2.12k|        }
  158|  4.65k|      }
  159|    592|      buf += k;
  160|    592|    }
  161|  19.6k|  }
  162|       |
  163|    506|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf16_output);
  164|    678|}

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_126avx2_convert_utf32_to_utf8EPKDimPc:
    2|    908|avx2_convert_utf32_to_utf8(const char32_t *buf, size_t len, char *utf8_output) {
    3|    908|  const char32_t *end = buf + len;
    4|    908|  const __m256i v_0000 = _mm256_setzero_si256();
    5|    908|  const __m256i v_ffff0000 = _mm256_set1_epi32((uint32_t)0xffff0000);
    6|    908|  const __m256i v_ff80 = _mm256_set1_epi16((uint16_t)0xff80);
    7|    908|  const __m256i v_f800 = _mm256_set1_epi16((uint16_t)0xf800);
    8|    908|  const __m256i v_c080 = _mm256_set1_epi16((uint16_t)0xc080);
    9|    908|  const __m256i v_7fffffff = _mm256_set1_epi32((uint32_t)0x7fffffff);
   10|    908|  __m256i running_max = _mm256_setzero_si256();
   11|    908|  __m256i forbidden_bytemask = _mm256_setzero_si256();
   12|       |
   13|    908|  const size_t safety_margin =
   14|    908|      12; // to avoid overruns, see issue
   15|       |          // https://github.com/simdutf/simdutf/issues/92
   16|       |
   17|  6.15k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (17:10): [True: 5.48k, False: 674]
  ------------------
   18|  5.48k|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
   19|  5.48k|    __m256i nextin = _mm256_loadu_si256((__m256i *)buf + 1);
   20|  5.48k|    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|  5.48k|    __m256i in_16 = _mm256_packus_epi32(_mm256_and_si256(in, v_7fffffff),
   25|  5.48k|                                        _mm256_and_si256(nextin, v_7fffffff));
   26|  5.48k|    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|  5.48k|    if (_mm256_testz_si256(in_16, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (31:9): [True: 1.05k, False: 4.42k]
  ------------------
   32|       |      // 1. pack the bytes
   33|  1.05k|      const __m128i utf8_packed = _mm_packus_epi16(
   34|  1.05k|          _mm256_castsi256_si128(in_16), _mm256_extractf128_si256(in_16, 1));
   35|       |      // 2. store (16 bytes)
   36|  1.05k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   37|       |      // 3. adjust pointers
   38|  1.05k|      buf += 16;
   39|  1.05k|      utf8_output += 16;
   40|  1.05k|      continue; // we are done for this round!
   41|  1.05k|    }
   42|       |    // no bits set above 7th bit
   43|  4.42k|    const __m256i one_byte_bytemask =
   44|  4.42k|        _mm256_cmpeq_epi16(_mm256_and_si256(in_16, v_ff80), v_0000);
   45|  4.42k|    const uint32_t one_byte_bitmask =
   46|  4.42k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
   47|       |
   48|       |    // no bits set above 11th bit
   49|  4.42k|    const __m256i one_or_two_bytes_bytemask =
   50|  4.42k|        _mm256_cmpeq_epi16(_mm256_and_si256(in_16, v_f800), v_0000);
   51|  4.42k|    const uint32_t one_or_two_bytes_bitmask =
   52|  4.42k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
   53|  4.42k|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (53:9): [True: 2.10k, False: 2.32k]
  ------------------
   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|  2.10k|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
   58|  2.10k|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
   59|       |
   60|       |      // t0 = [000a|aaaa|bbbb|bb00]
   61|  2.10k|      const __m256i t0 = _mm256_slli_epi16(in_16, 2);
   62|       |      // t1 = [000a|aaaa|0000|0000]
   63|  2.10k|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
   64|       |      // t2 = [0000|0000|00bb|bbbb]
   65|  2.10k|      const __m256i t2 = _mm256_and_si256(in_16, v_003f);
   66|       |      // t3 = [000a|aaaa|00bb|bbbb]
   67|  2.10k|      const __m256i t3 = _mm256_or_si256(t1, t2);
   68|       |      // t4 = [110a|aaaa|10bb|bbbb]
   69|  2.10k|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
   70|       |
   71|       |      // 2. merge ASCII and 2-byte codewords
   72|  2.10k|      const __m256i utf8_unpacked =
   73|  2.10k|          _mm256_blendv_epi8(t4, in_16, one_byte_bytemask);
   74|       |
   75|       |      // 3. prepare bitmask for 8-bit lookup
   76|  2.10k|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
   77|  2.10k|      const uint32_t M1 = M0 >> 7;
   78|  2.10k|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
   79|       |      // 4. pack the bytes
   80|       |
   81|  2.10k|      const uint8_t *row =
   82|  2.10k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
   83|  2.10k|      const uint8_t *row_2 =
   84|  2.10k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
   85|  2.10k|                                                                       16)][0];
   86|       |
   87|  2.10k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
   88|  2.10k|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
   89|       |
   90|  2.10k|      const __m256i utf8_packed = _mm256_shuffle_epi8(
   91|  2.10k|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|  2.10k|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|  2.10k|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
   92|       |      // 5. store bytes
   93|  2.10k|      _mm_storeu_si128((__m128i *)utf8_output,
   94|  2.10k|                       _mm256_castsi256_si128(utf8_packed));
   95|  2.10k|      utf8_output += row[0];
   96|  2.10k|      _mm_storeu_si128((__m128i *)utf8_output,
   97|  2.10k|                       _mm256_extractf128_si256(utf8_packed, 1));
   98|  2.10k|      utf8_output += row_2[0];
   99|       |
  100|       |      // 6. adjust pointers
  101|  2.10k|      buf += 16;
  102|  2.10k|      continue;
  103|  2.10k|    }
  104|       |    // Must check for overflow in packing
  105|  2.32k|    const __m256i saturation_bytemask = _mm256_cmpeq_epi32(
  106|  2.32k|        _mm256_and_si256(_mm256_or_si256(in, nextin), v_ffff0000), v_0000);
  107|  2.32k|    const uint32_t saturation_bitmask =
  108|  2.32k|        static_cast<uint32_t>(_mm256_movemask_epi8(saturation_bytemask));
  109|  2.32k|    if (saturation_bitmask == 0xffffffff) {
  ------------------
  |  Branch (109:9): [True: 832, False: 1.49k]
  ------------------
  110|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  111|    832|      const __m256i v_d800 = _mm256_set1_epi16((uint16_t)0xd800);
  112|    832|      forbidden_bytemask = _mm256_or_si256(
  113|    832|          forbidden_bytemask,
  114|    832|          _mm256_cmpeq_epi16(_mm256_and_si256(in_16, v_f800), v_d800));
  115|       |
  116|    832|      const __m256i dup_even = _mm256_setr_epi16(
  117|    832|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  118|    832|          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|    832|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  148|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  149|    832|      const __m256i t0 = _mm256_shuffle_epi8(in_16, dup_even);
  150|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  151|    832|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  147|    832|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  152|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  153|    832|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  147|    832|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  154|       |
  155|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  156|    832|      const __m256i s0 = _mm256_srli_epi16(in_16, 4);
  157|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  158|    832|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  147|    832|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  159|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  160|    832|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  147|    832|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  161|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  162|    832|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  147|    832|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  163|    832|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  164|    832|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  147|    832|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  165|    832|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  166|    832|#undef simdutf_vec
  167|       |
  168|       |      // 4. expand code units 16-bit => 32-bit
  169|    832|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  170|    832|      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|    832|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  174|    832|                            (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|    832|      const uint8_t mask0 = uint8_t(mask);
  195|    832|      const uint8_t *row0 =
  196|    832|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  197|    832|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  198|    832|      const __m128i utf8_0 =
  199|    832|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  200|       |
  201|    832|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  202|    832|      const uint8_t *row1 =
  203|    832|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  204|    832|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  205|    832|      const __m128i utf8_1 =
  206|    832|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  207|       |
  208|    832|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  209|    832|      const uint8_t *row2 =
  210|    832|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  211|    832|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  212|    832|      const __m128i utf8_2 =
  213|    832|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  214|       |
  215|    832|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  216|    832|      const uint8_t *row3 =
  217|    832|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  218|    832|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  219|    832|      const __m128i utf8_3 =
  220|    832|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  221|       |
  222|    832|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  223|    832|      utf8_output += row0[0];
  224|    832|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  225|    832|      utf8_output += row1[0];
  226|    832|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  227|    832|      utf8_output += row2[0];
  228|    832|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  229|    832|      utf8_output += row3[0];
  230|    832|      buf += 16;
  231|  1.49k|    } 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|  1.49k|      size_t forward = 15;
  237|  1.49k|      size_t k = 0;
  238|  1.49k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (238:11): [True: 0, False: 1.49k]
  ------------------
  239|      0|        forward = size_t(end - buf - 1);
  240|      0|      }
  241|  21.1k|      for (; k < forward; k++) {
  ------------------
  |  Branch (241:14): [True: 19.9k, False: 1.25k]
  ------------------
  242|  19.9k|        uint32_t word = buf[k];
  243|  19.9k|        if ((word & 0xFFFFFF80) == 0) { // 1-byte (ASCII)
  ------------------
  |  Branch (243:13): [True: 9.06k, False: 10.8k]
  ------------------
  244|  9.06k|          *utf8_output++ = char(word);
  245|  10.8k|        } else if ((word & 0xFFFFF800) == 0) { // 2-byte
  ------------------
  |  Branch (245:20): [True: 1.99k, False: 8.86k]
  ------------------
  246|  1.99k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  247|  1.99k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  248|  8.86k|        } else if ((word & 0xFFFF0000) == 0) { // 3-byte
  ------------------
  |  Branch (248:20): [True: 4.06k, False: 4.80k]
  ------------------
  249|  4.06k|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (249:15): [True: 1.66k, False: 2.39k]
  |  Branch (249:33): [True: 28, False: 1.63k]
  ------------------
  250|     28|            return std::make_pair(nullptr, utf8_output);
  251|     28|          }
  252|  4.03k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  253|  4.03k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  254|  4.03k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  255|  4.80k|        } else { // 4-byte
  256|  4.80k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (256:15): [True: 206, False: 4.60k]
  ------------------
  257|    206|            return std::make_pair(nullptr, utf8_output);
  258|    206|          }
  259|  4.60k|          *utf8_output++ = char((word >> 18) | 0b11110000);
  260|  4.60k|          *utf8_output++ = char(((word >> 12) & 0b111111) | 0b10000000);
  261|  4.60k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  262|  4.60k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  263|  4.60k|        }
  264|  19.9k|      }
  265|  1.25k|      buf += k;
  266|  1.25k|    }
  267|  2.32k|  } // while
  268|       |
  269|       |  // check for invalid input
  270|    674|  const __m256i v_10ffff = _mm256_set1_epi32((uint32_t)0x10ffff);
  271|    674|  if (static_cast<uint32_t>(_mm256_movemask_epi8(_mm256_cmpeq_epi32(
  ------------------
  |  Branch (271:7): [True: 34, False: 640]
  ------------------
  272|    674|          _mm256_max_epu32(running_max, v_10ffff), v_10ffff))) != 0xffffffff) {
  273|     34|    return std::make_pair(nullptr, utf8_output);
  274|     34|  }
  275|       |
  276|    640|  if (static_cast<uint32_t>(_mm256_movemask_epi8(forbidden_bytemask)) != 0) {
  ------------------
  |  Branch (276:7): [True: 60, False: 580]
  ------------------
  277|     60|    return std::make_pair(nullptr, utf8_output);
  278|     60|  }
  279|       |
  280|    580|  return std::make_pair(buf, utf8_output);
  281|    640|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_138avx2_convert_utf32_to_utf8_with_errorsEPKDimPc:
  285|    860|                                       char *utf8_output) {
  286|    860|  const char32_t *end = buf + len;
  287|    860|  const char32_t *start = buf;
  288|       |
  289|    860|  const __m256i v_0000 = _mm256_setzero_si256();
  290|    860|  const __m256i v_ffff0000 = _mm256_set1_epi32((uint32_t)0xffff0000);
  291|    860|  const __m256i v_ff80 = _mm256_set1_epi16((uint16_t)0xff80);
  292|    860|  const __m256i v_f800 = _mm256_set1_epi16((uint16_t)0xf800);
  293|    860|  const __m256i v_c080 = _mm256_set1_epi16((uint16_t)0xc080);
  294|    860|  const __m256i v_7fffffff = _mm256_set1_epi32((uint32_t)0x7fffffff);
  295|    860|  const __m256i v_10ffff = _mm256_set1_epi32((uint32_t)0x10ffff);
  296|       |
  297|    860|  const size_t safety_margin =
  298|    860|      12; // to avoid overruns, see issue
  299|       |          // https://github.com/simdutf/simdutf/issues/92
  300|       |
  301|  2.68k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (301:10): [True: 2.04k, False: 646]
  ------------------
  302|  2.04k|    __m256i in = _mm256_loadu_si256((__m256i *)buf);
  303|  2.04k|    __m256i nextin = _mm256_loadu_si256((__m256i *)buf + 1);
  304|       |    // Check for too large input
  305|  2.04k|    const __m256i max_input =
  306|  2.04k|        _mm256_max_epu32(_mm256_max_epu32(in, nextin), v_10ffff);
  307|  2.04k|    if (static_cast<uint32_t>(_mm256_movemask_epi8(
  ------------------
  |  Branch (307:9): [True: 150, False: 1.89k]
  ------------------
  308|  2.04k|            _mm256_cmpeq_epi32(max_input, v_10ffff))) != 0xffffffff) {
  309|    150|      return std::make_pair(result(error_code::TOO_LARGE, buf - start),
  310|    150|                            utf8_output);
  311|    150|    }
  312|       |
  313|       |    // Pack 32-bit UTF-32 code units to 16-bit UTF-16 code units with unsigned
  314|       |    // saturation
  315|  1.89k|    __m256i in_16 = _mm256_packus_epi32(_mm256_and_si256(in, v_7fffffff),
  316|  1.89k|                                        _mm256_and_si256(nextin, v_7fffffff));
  317|  1.89k|    in_16 = _mm256_permute4x64_epi64(in_16, 0b11011000);
  318|       |
  319|       |    // Try to apply UTF-16 => UTF-8 routine on 256 bits
  320|       |    // (haswell/avx2_convert_utf16_to_utf8.cpp)
  321|       |
  322|  1.89k|    if (_mm256_testz_si256(in_16, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (322:9): [True: 486, False: 1.40k]
  ------------------
  323|       |      // 1. pack the bytes
  324|    486|      const __m128i utf8_packed = _mm_packus_epi16(
  325|    486|          _mm256_castsi256_si128(in_16), _mm256_extractf128_si256(in_16, 1));
  326|       |      // 2. store (16 bytes)
  327|    486|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  328|       |      // 3. adjust pointers
  329|    486|      buf += 16;
  330|    486|      utf8_output += 16;
  331|    486|      continue; // we are done for this round!
  332|    486|    }
  333|       |    // no bits set above 7th bit
  334|  1.40k|    const __m256i one_byte_bytemask =
  335|  1.40k|        _mm256_cmpeq_epi16(_mm256_and_si256(in_16, v_ff80), v_0000);
  336|  1.40k|    const uint32_t one_byte_bitmask =
  337|  1.40k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_byte_bytemask));
  338|       |
  339|       |    // no bits set above 11th bit
  340|  1.40k|    const __m256i one_or_two_bytes_bytemask =
  341|  1.40k|        _mm256_cmpeq_epi16(_mm256_and_si256(in_16, v_f800), v_0000);
  342|  1.40k|    const uint32_t one_or_two_bytes_bitmask =
  343|  1.40k|        static_cast<uint32_t>(_mm256_movemask_epi8(one_or_two_bytes_bytemask));
  344|  1.40k|    if (one_or_two_bytes_bitmask == 0xffffffff) {
  ------------------
  |  Branch (344:9): [True: 318, False: 1.08k]
  ------------------
  345|       |      // 1. prepare 2-byte values
  346|       |      // input 16-bit word : [0000|0aaa|aabb|bbbb] x 8
  347|       |      // expected output   : [110a|aaaa|10bb|bbbb] x 8
  348|    318|      const __m256i v_1f00 = _mm256_set1_epi16((int16_t)0x1f00);
  349|    318|      const __m256i v_003f = _mm256_set1_epi16((int16_t)0x003f);
  350|       |
  351|       |      // t0 = [000a|aaaa|bbbb|bb00]
  352|    318|      const __m256i t0 = _mm256_slli_epi16(in_16, 2);
  353|       |      // t1 = [000a|aaaa|0000|0000]
  354|    318|      const __m256i t1 = _mm256_and_si256(t0, v_1f00);
  355|       |      // t2 = [0000|0000|00bb|bbbb]
  356|    318|      const __m256i t2 = _mm256_and_si256(in_16, v_003f);
  357|       |      // t3 = [000a|aaaa|00bb|bbbb]
  358|    318|      const __m256i t3 = _mm256_or_si256(t1, t2);
  359|       |      // t4 = [110a|aaaa|10bb|bbbb]
  360|    318|      const __m256i t4 = _mm256_or_si256(t3, v_c080);
  361|       |
  362|       |      // 2. merge ASCII and 2-byte codewords
  363|    318|      const __m256i utf8_unpacked =
  364|    318|          _mm256_blendv_epi8(t4, in_16, one_byte_bytemask);
  365|       |
  366|       |      // 3. prepare bitmask for 8-bit lookup
  367|    318|      const uint32_t M0 = one_byte_bitmask & 0x55555555;
  368|    318|      const uint32_t M1 = M0 >> 7;
  369|    318|      const uint32_t M2 = (M1 | M0) & 0x00ff00ff;
  370|       |      // 4. pack the bytes
  371|       |
  372|    318|      const uint8_t *row =
  373|    318|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2)][0];
  374|    318|      const uint8_t *row_2 =
  375|    318|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[uint8_t(M2 >>
  376|    318|                                                                       16)][0];
  377|       |
  378|    318|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  379|    318|      const __m128i shuffle_2 = _mm_loadu_si128((__m128i *)(row_2 + 1));
  380|       |
  381|    318|      const __m256i utf8_packed = _mm256_shuffle_epi8(
  382|    318|          utf8_unpacked, _mm256_setr_m128i(shuffle, shuffle_2));
  ------------------
  |  |    7|    318|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    8|    318|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  383|       |      // 5. store bytes
  384|    318|      _mm_storeu_si128((__m128i *)utf8_output,
  385|    318|                       _mm256_castsi256_si128(utf8_packed));
  386|    318|      utf8_output += row[0];
  387|    318|      _mm_storeu_si128((__m128i *)utf8_output,
  388|    318|                       _mm256_extractf128_si256(utf8_packed, 1));
  389|    318|      utf8_output += row_2[0];
  390|       |
  391|       |      // 6. adjust pointers
  392|    318|      buf += 16;
  393|    318|      continue;
  394|    318|    }
  395|       |    // Must check for overflow in packing
  396|  1.08k|    const __m256i saturation_bytemask = _mm256_cmpeq_epi32(
  397|  1.08k|        _mm256_and_si256(_mm256_or_si256(in, nextin), v_ffff0000), v_0000);
  398|  1.08k|    const uint32_t saturation_bitmask =
  399|  1.08k|        static_cast<uint32_t>(_mm256_movemask_epi8(saturation_bytemask));
  400|  1.08k|    if (saturation_bitmask == 0xffffffff) {
  ------------------
  |  Branch (400:9): [True: 452, False: 634]
  ------------------
  401|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  402|       |
  403|       |      // Check for illegal surrogate code units
  404|    452|      const __m256i v_d800 = _mm256_set1_epi16((uint16_t)0xd800);
  405|    452|      const __m256i forbidden_bytemask =
  406|    452|          _mm256_cmpeq_epi16(_mm256_and_si256(in_16, v_f800), v_d800);
  407|    452|      if (static_cast<uint32_t>(_mm256_movemask_epi8(forbidden_bytemask)) !=
  ------------------
  |  Branch (407:11): [True: 44, False: 408]
  ------------------
  408|    452|          0x0) {
  409|     44|        return std::make_pair(result(error_code::SURROGATE, buf - start),
  410|     44|                              utf8_output);
  411|     44|      }
  412|       |
  413|    408|      const __m256i dup_even = _mm256_setr_epi16(
  414|    408|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e,
  415|    408|          0x0000, 0x0202, 0x0404, 0x0606, 0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  416|       |
  417|       |      /* In this branch we handle three cases:
  418|       |        1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  419|       |        single UFT-8 byte
  420|       |        2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              - two
  421|       |        UTF-8 bytes
  422|       |        3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  423|       |        three UTF-8 bytes
  424|       |
  425|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  426|       |        we have room for four bytes. However, we need five distinct bit
  427|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  428|       |
  429|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  430|       |        in register t2.
  431|       |
  432|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  433|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  434|       |        differ by exactly one bit.
  435|       |
  436|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  437|       |        into account the case (i.e, the number of bytes to write).
  438|       |      */
  439|       |      /**
  440|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  441|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  442|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  443|       |       */
  444|    408|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  445|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  446|    408|      const __m256i t0 = _mm256_shuffle_epi8(in_16, dup_even);
  447|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  448|    408|      const __m256i t1 = _mm256_and_si256(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  444|    408|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  449|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  450|    408|      const __m256i t2 = _mm256_or_si256(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  444|    408|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  451|       |
  452|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  453|    408|      const __m256i s0 = _mm256_srli_epi16(in_16, 4);
  454|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  455|    408|      const __m256i s1 = _mm256_and_si256(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  444|    408|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  456|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  457|    408|      const __m256i s2 = _mm256_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  444|    408|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  458|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  459|    408|      const __m256i s3 = _mm256_or_si256(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  444|    408|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  460|    408|      const __m256i m0 = _mm256_andnot_si256(one_or_two_bytes_bytemask,
  461|    408|                                             simdutf_vec(0b0100000000000000));
  ------------------
  |  |  444|    408|#define simdutf_vec(x) _mm256_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  462|    408|      const __m256i s4 = _mm256_xor_si256(s3, m0);
  463|    408|#undef simdutf_vec
  464|       |
  465|       |      // 4. expand code units 16-bit => 32-bit
  466|    408|      const __m256i out0 = _mm256_unpacklo_epi16(t2, s4);
  467|    408|      const __m256i out1 = _mm256_unpackhi_epi16(t2, s4);
  468|       |
  469|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  470|    408|      const uint32_t mask = (one_byte_bitmask & 0x55555555) |
  471|    408|                            (one_or_two_bytes_bitmask & 0xaaaaaaaa);
  472|       |      // Due to the wider registers, the following path is less likely to be
  473|       |      // useful.
  474|       |      /*if(mask == 0) {
  475|       |        // We only have three-byte code units. Use fast path.
  476|       |        const __m256i shuffle =
  477|       |      _mm256_setr_epi8(2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1,
  478|       |      2,3,1,6,7,5,10,11,9,14,15,13,-1,-1,-1,-1); const __m256i utf8_0 =
  479|       |      _mm256_shuffle_epi8(out0, shuffle); const __m256i utf8_1 =
  480|       |      _mm256_shuffle_epi8(out1, shuffle);
  481|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_0));
  482|       |        utf8_output += 12;
  483|       |        _mm_storeu_si128((__m128i*)utf8_output, _mm256_castsi256_si128(utf8_1));
  484|       |        utf8_output += 12;
  485|       |        _mm_storeu_si128((__m128i*)utf8_output,
  486|       |      _mm256_extractf128_si256(utf8_0,1)); utf8_output += 12;
  487|       |        _mm_storeu_si128((__m128i*)utf8_output,
  488|       |      _mm256_extractf128_si256(utf8_1,1)); utf8_output += 12; buf += 16;
  489|       |        continue;
  490|       |      }*/
  491|    408|      const uint8_t mask0 = uint8_t(mask);
  492|    408|      const uint8_t *row0 =
  493|    408|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  494|    408|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  495|    408|      const __m128i utf8_0 =
  496|    408|          _mm_shuffle_epi8(_mm256_castsi256_si128(out0), shuffle0);
  497|       |
  498|    408|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  499|    408|      const uint8_t *row1 =
  500|    408|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  501|    408|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  502|    408|      const __m128i utf8_1 =
  503|    408|          _mm_shuffle_epi8(_mm256_castsi256_si128(out1), shuffle1);
  504|       |
  505|    408|      const uint8_t mask2 = static_cast<uint8_t>(mask >> 16);
  506|    408|      const uint8_t *row2 =
  507|    408|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask2][0];
  508|    408|      const __m128i shuffle2 = _mm_loadu_si128((__m128i *)(row2 + 1));
  509|    408|      const __m128i utf8_2 =
  510|    408|          _mm_shuffle_epi8(_mm256_extractf128_si256(out0, 1), shuffle2);
  511|       |
  512|    408|      const uint8_t mask3 = static_cast<uint8_t>(mask >> 24);
  513|    408|      const uint8_t *row3 =
  514|    408|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask3][0];
  515|    408|      const __m128i shuffle3 = _mm_loadu_si128((__m128i *)(row3 + 1));
  516|    408|      const __m128i utf8_3 =
  517|    408|          _mm_shuffle_epi8(_mm256_extractf128_si256(out1, 1), shuffle3);
  518|       |
  519|    408|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  520|    408|      utf8_output += row0[0];
  521|    408|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  522|    408|      utf8_output += row1[0];
  523|    408|      _mm_storeu_si128((__m128i *)utf8_output, utf8_2);
  524|    408|      utf8_output += row2[0];
  525|    408|      _mm_storeu_si128((__m128i *)utf8_output, utf8_3);
  526|    408|      utf8_output += row3[0];
  527|    408|      buf += 16;
  528|    634|    } else {
  529|       |      // case: at least one 32-bit word is larger than 0xFFFF <=> it will
  530|       |      // produce four UTF-8 bytes. Let us do a scalar fallback. It may seem
  531|       |      // wasteful to use scalar code, but being efficient with SIMD may require
  532|       |      // large, non-trivial tables?
  533|    634|      size_t forward = 15;
  534|    634|      size_t k = 0;
  535|    634|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (535:11): [True: 0, False: 634]
  ------------------
  536|      0|        forward = size_t(end - buf - 1);
  537|      0|      }
  538|  9.96k|      for (; k < forward; k++) {
  ------------------
  |  Branch (538:14): [True: 9.34k, False: 614]
  ------------------
  539|  9.34k|        uint32_t word = buf[k];
  540|  9.34k|        if ((word & 0xFFFFFF80) == 0) { // 1-byte (ASCII)
  ------------------
  |  Branch (540:13): [True: 2.13k, False: 7.21k]
  ------------------
  541|  2.13k|          *utf8_output++ = char(word);
  542|  7.21k|        } else if ((word & 0xFFFFF800) == 0) { // 2-byte
  ------------------
  |  Branch (542:20): [True: 612, False: 6.60k]
  ------------------
  543|    612|          *utf8_output++ = char((word >> 6) | 0b11000000);
  544|    612|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  545|  6.60k|        } else if ((word & 0xFFFF0000) == 0) { // 3-byte
  ------------------
  |  Branch (545:20): [True: 1.65k, False: 4.95k]
  ------------------
  546|  1.65k|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (546:15): [True: 876, False: 778]
  |  Branch (546:33): [True: 20, False: 856]
  ------------------
  547|     20|            return std::make_pair(
  548|     20|                result(error_code::SURROGATE, buf - start + k), utf8_output);
  549|     20|          }
  550|  1.63k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  551|  1.63k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  552|  1.63k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  553|  4.95k|        } else { // 4-byte
  554|  4.95k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (554:15): [True: 0, False: 4.95k]
  ------------------
  555|      0|            return std::make_pair(
  556|      0|                result(error_code::TOO_LARGE, buf - start + k), utf8_output);
  557|      0|          }
  558|  4.95k|          *utf8_output++ = char((word >> 18) | 0b11110000);
  559|  4.95k|          *utf8_output++ = char(((word >> 12) & 0b111111) | 0b10000000);
  560|  4.95k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  561|  4.95k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  562|  4.95k|        }
  563|  9.34k|      }
  564|    614|      buf += k;
  565|    614|    }
  566|  1.08k|  } // while
  567|       |
  568|    646|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  569|    860|}

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

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

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

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

_ZNK7simdutf7haswell14implementation13validate_utf8EPKcm:
  266|  4.11k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
  267|  4.11k|  return haswell::utf8_validation::generic_validate_utf8(buf, len);
  268|  4.11k|}
_ZNK7simdutf7haswell14implementation25validate_utf8_with_errorsEPKcm:
  273|  4.11k|    const char *buf, size_t len) const noexcept {
  274|  4.11k|  return haswell::utf8_validation::generic_validate_utf8_with_errors(buf, len);
  275|  4.11k|}
_ZNK7simdutf7haswell14implementation16validate_utf16leEPKDsm:
  312|  1.42k|                                 size_t len) const noexcept {
  313|  1.42k|  if (simdutf_unlikely(len == 0)) {
  ------------------
  |  |   93|  1.42k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 17, False: 1.40k]
  |  |  ------------------
  ------------------
  314|       |    // empty input is valid UTF-16. protect the implementation from
  315|       |    // handling nullptr
  316|     17|    return true;
  317|     17|  }
  318|  1.40k|  const auto res =
  319|  1.40k|      haswell::utf16::validate_utf16_with_errors<endianness::LITTLE>(buf, len);
  320|  1.40k|  if (res.is_err()) {
  ------------------
  |  Branch (320:7): [True: 104, False: 1.29k]
  ------------------
  321|    104|    return false;
  322|    104|  }
  323|       |
  324|  1.29k|  if (res.count == len) {
  ------------------
  |  Branch (324:7): [True: 0, False: 1.29k]
  ------------------
  325|      0|    return true;
  326|      0|  }
  327|       |
  328|  1.29k|  return scalar::utf16::validate<endianness::LITTLE>(buf + res.count,
  329|  1.29k|                                                     len - res.count);
  330|  1.29k|}
_ZNK7simdutf7haswell14implementation16validate_utf16beEPKDsm:
  336|  1.33k|                                 size_t len) const noexcept {
  337|  1.33k|  if (simdutf_unlikely(len == 0)) {
  ------------------
  |  |   93|  1.33k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 16, False: 1.31k]
  |  |  ------------------
  ------------------
  338|       |    // empty input is valid UTF-16. protect the implementation from
  339|       |    // handling nullptr
  340|     16|    return true;
  341|     16|  }
  342|  1.31k|  const auto res =
  343|  1.31k|      haswell::utf16::validate_utf16_with_errors<endianness::BIG>(buf, len);
  344|  1.31k|  if (res.is_err()) {
  ------------------
  |  Branch (344:7): [True: 81, False: 1.23k]
  ------------------
  345|     81|    return false;
  346|     81|  }
  347|       |
  348|  1.23k|  if (res.count == len) {
  ------------------
  |  Branch (348:7): [True: 0, False: 1.23k]
  ------------------
  349|      0|    return true;
  350|      0|  }
  351|       |
  352|  1.23k|  return scalar::utf16::validate<endianness::BIG>(buf + res.count,
  353|  1.23k|                                                  len - res.count);
  354|  1.23k|}
_ZNK7simdutf7haswell14implementation28validate_utf16le_with_errorsEPKDsm:
  357|  1.42k|    const char16_t *buf, size_t len) const noexcept {
  358|       |
  359|  1.42k|  const result res =
  360|  1.42k|      haswell::utf16::validate_utf16_with_errors<endianness::LITTLE>(buf, len);
  361|  1.42k|  if (res.count != len) {
  ------------------
  |  Branch (361:7): [True: 1.40k, False: 17]
  ------------------
  362|  1.40k|    const result scalar_res =
  363|  1.40k|        scalar::utf16::validate_with_errors<endianness::LITTLE>(
  364|  1.40k|            buf + res.count, len - res.count);
  365|  1.40k|    return result(scalar_res.error, res.count + scalar_res.count);
  366|  1.40k|  } else {
  367|     17|    return res;
  368|     17|  }
  369|  1.42k|}
_ZNK7simdutf7haswell14implementation28validate_utf16be_with_errorsEPKDsm:
  372|  1.33k|    const char16_t *buf, size_t len) const noexcept {
  373|  1.33k|  const result res =
  374|  1.33k|      haswell::utf16::validate_utf16_with_errors<endianness::BIG>(buf, len);
  375|  1.33k|  if (res.count != len) {
  ------------------
  |  Branch (375:7): [True: 1.31k, False: 16]
  ------------------
  376|  1.31k|    const result scalar_res =
  377|  1.31k|        scalar::utf16::validate_with_errors<endianness::BIG>(buf + res.count,
  378|  1.31k|                                                             len - res.count);
  379|  1.31k|    return result(scalar_res.error, res.count + scalar_res.count);
  380|  1.31k|  } else {
  381|     16|    return res;
  382|     16|  }
  383|  1.33k|}
_ZNK7simdutf7haswell14implementation14validate_utf32EPKDim:
  398|  2.68k|implementation::validate_utf32(const char32_t *buf, size_t len) const noexcept {
  399|  2.68k|  return utf32::validate(buf, len);
  400|  2.68k|}
_ZNK7simdutf7haswell14implementation26validate_utf32_with_errorsEPKDim:
  405|  2.68k|    const char32_t *buf, size_t len) const noexcept {
  406|  2.68k|  return utf32::validate_with_errors(buf, len);
  407|  2.68k|}
_ZNK7simdutf7haswell14implementation22convert_latin1_to_utf8EPKcmPc:
  412|    486|    const char *buf, size_t len, char *utf8_output) const noexcept {
  413|    486|  std::pair<const char *, char *> ret =
  414|    486|      avx2_convert_latin1_to_utf8(buf, len, utf8_output);
  415|    486|  size_t converted_chars = ret.second - utf8_output;
  416|       |
  417|    486|  if (ret.first != buf + len) {
  ------------------
  |  Branch (417:7): [True: 482, False: 4]
  ------------------
  418|    482|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  419|    482|        ret.first, len - (ret.first - buf), ret.second);
  420|    482|    converted_chars += scalar_converted_chars;
  421|    482|  }
  422|       |
  423|    486|  return converted_chars;
  424|    486|}
_ZNK7simdutf7haswell14implementation25convert_latin1_to_utf16leEPKcmPDs:
  429|     82|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  430|     82|  std::pair<const char *, char16_t *> ret =
  431|     82|      avx2_convert_latin1_to_utf16<endianness::LITTLE>(buf, len, utf16_output);
  432|     82|  if (ret.first == nullptr) {
  ------------------
  |  Branch (432:7): [True: 4, False: 78]
  ------------------
  433|      4|    return 0;
  434|      4|  }
  435|     78|  size_t converted_chars = ret.second - utf16_output;
  436|     78|  if (ret.first != buf + len) {
  ------------------
  |  Branch (436:7): [True: 64, False: 14]
  ------------------
  437|     64|    const size_t scalar_converted_chars =
  438|     64|        scalar::latin1_to_utf16::convert<endianness::LITTLE>(
  439|     64|            ret.first, len - (ret.first - buf), ret.second);
  440|     64|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (440:9): [True: 0, False: 64]
  ------------------
  441|      0|      return 0;
  442|      0|    }
  443|     64|    converted_chars += scalar_converted_chars;
  444|     64|  }
  445|     78|  return converted_chars;
  446|     78|}
_ZNK7simdutf7haswell14implementation25convert_latin1_to_utf16beEPKcmPDs:
  449|    108|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  450|    108|  std::pair<const char *, char16_t *> ret =
  451|    108|      avx2_convert_latin1_to_utf16<endianness::BIG>(buf, len, utf16_output);
  452|    108|  if (ret.first == nullptr) {
  ------------------
  |  Branch (452:7): [True: 4, False: 104]
  ------------------
  453|      4|    return 0;
  454|      4|  }
  455|    104|  size_t converted_chars = ret.second - utf16_output;
  456|    104|  if (ret.first != buf + len) {
  ------------------
  |  Branch (456:7): [True: 88, False: 16]
  ------------------
  457|     88|    const size_t scalar_converted_chars =
  458|     88|        scalar::latin1_to_utf16::convert<endianness::BIG>(
  459|     88|            ret.first, len - (ret.first - buf), ret.second);
  460|     88|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (460:9): [True: 0, False: 88]
  ------------------
  461|      0|      return 0;
  462|      0|    }
  463|     88|    converted_chars += scalar_converted_chars;
  464|     88|  }
  465|    104|  return converted_chars;
  466|    104|}
_ZNK7simdutf7haswell14implementation23convert_latin1_to_utf32EPKcmPDi:
  471|    102|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  472|    102|  std::pair<const char *, char32_t *> ret =
  473|    102|      avx2_convert_latin1_to_utf32(buf, len, utf32_output);
  474|    102|  if (ret.first == nullptr) {
  ------------------
  |  Branch (474:7): [True: 4, False: 98]
  ------------------
  475|      4|    return 0;
  476|      4|  }
  477|     98|  size_t converted_chars = ret.second - utf32_output;
  478|     98|  if (ret.first != buf + len) {
  ------------------
  |  Branch (478:7): [True: 68, False: 30]
  ------------------
  479|     68|    const size_t scalar_converted_chars = scalar::latin1_to_utf32::convert(
  480|     68|        ret.first, len - (ret.first - buf), ret.second);
  481|     68|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (481:9): [True: 0, False: 68]
  ------------------
  482|      0|      return 0;
  483|      0|    }
  484|     68|    converted_chars += scalar_converted_chars;
  485|     68|  }
  486|     98|  return converted_chars;
  487|     98|}
_ZNK7simdutf7haswell14implementation22convert_utf8_to_latin1EPKcmPc:
  492|    716|    const char *buf, size_t len, char *latin1_output) const noexcept {
  493|    716|  utf8_to_latin1::validating_transcoder converter;
  494|    716|  return converter.convert(buf, len, latin1_output);
  495|    716|}
_ZNK7simdutf7haswell14implementation34convert_utf8_to_latin1_with_errorsEPKcmPc:
  498|    670|    const char *buf, size_t len, char *latin1_output) const noexcept {
  499|    670|  utf8_to_latin1::validating_transcoder converter;
  500|    670|  return converter.convert_with_errors(buf, len, latin1_output);
  501|    670|}
_ZNK7simdutf7haswell14implementation23convert_utf8_to_utf16leEPKcmPDs:
  511|    950|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  512|    950|  utf8_to_utf16::validating_transcoder converter;
  513|    950|  return converter.convert<endianness::LITTLE>(buf, len, utf16_output);
  514|    950|}
_ZNK7simdutf7haswell14implementation23convert_utf8_to_utf16beEPKcmPDs:
  517|    974|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  518|    974|  utf8_to_utf16::validating_transcoder converter;
  519|    974|  return converter.convert<endianness::BIG>(buf, len, utf16_output);
  520|    974|}
_ZNK7simdutf7haswell14implementation35convert_utf8_to_utf16le_with_errorsEPKcmPDs:
  523|    782|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  524|    782|  utf8_to_utf16::validating_transcoder converter;
  525|    782|  return converter.convert_with_errors<endianness::LITTLE>(buf, len,
  526|    782|                                                           utf16_output);
  527|    782|}
_ZNK7simdutf7haswell14implementation35convert_utf8_to_utf16be_with_errorsEPKcmPDs:
  530|    902|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  531|    902|  utf8_to_utf16::validating_transcoder converter;
  532|    902|  return converter.convert_with_errors<endianness::BIG>(buf, len, utf16_output);
  533|    902|}
_ZNK7simdutf7haswell14implementation29convert_valid_utf8_to_utf16leEPKcmPDs:
  536|    344|    const char *input, size_t size, char16_t *utf16_output) const noexcept {
  537|    344|  return utf8_to_utf16::convert_valid<endianness::LITTLE>(input, size,
  538|    344|                                                          utf16_output);
  539|    344|}
_ZNK7simdutf7haswell14implementation29convert_valid_utf8_to_utf16beEPKcmPDs:
  542|    456|    const char *input, size_t size, char16_t *utf16_output) const noexcept {
  543|    456|  return utf8_to_utf16::convert_valid<endianness::BIG>(input, size,
  544|    456|                                                       utf16_output);
  545|    456|}
_ZNK7simdutf7haswell14implementation21convert_utf8_to_utf32EPKcmPDi:
  550|    950|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  551|    950|  utf8_to_utf32::validating_transcoder converter;
  552|    950|  return converter.convert(buf, len, utf32_output);
  553|    950|}
_ZNK7simdutf7haswell14implementation33convert_utf8_to_utf32_with_errorsEPKcmPDi:
  556|    918|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  557|    918|  utf8_to_utf32::validating_transcoder converter;
  558|    918|  return converter.convert_with_errors(buf, len, utf32_output);
  559|    918|}
_ZNK7simdutf7haswell14implementation27convert_valid_utf8_to_utf32EPKcmPDi:
  562|    512|    const char *input, size_t size, char32_t *utf32_output) const noexcept {
  563|    512|  return utf8_to_utf32::convert_valid(input, size, utf32_output);
  564|    512|}
_ZNK7simdutf7haswell14implementation25convert_utf16le_to_latin1EPKDsmPc:
  569|    134|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  570|    134|  std::pair<const char16_t *, char *> ret =
  571|    134|      haswell::avx2_convert_utf16_to_latin1<endianness::LITTLE>(buf, len,
  572|    134|                                                                latin1_output);
  573|    134|  if (ret.first == nullptr) {
  ------------------
  |  Branch (573:7): [True: 38, False: 96]
  ------------------
  574|     38|    return 0;
  575|     38|  }
  576|     96|  size_t saved_bytes = ret.second - latin1_output;
  577|     96|  if (ret.first != buf + len) {
  ------------------
  |  Branch (577:7): [True: 84, False: 12]
  ------------------
  578|     84|    const size_t scalar_saved_bytes =
  579|     84|        scalar::utf16_to_latin1::convert<endianness::LITTLE>(
  580|     84|            ret.first, len - (ret.first - buf), ret.second);
  581|     84|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (581:9): [True: 48, False: 36]
  ------------------
  582|     48|      return 0;
  583|     48|    }
  584|     36|    saved_bytes += scalar_saved_bytes;
  585|     36|  }
  586|     48|  return saved_bytes;
  587|     96|}
_ZNK7simdutf7haswell14implementation25convert_utf16be_to_latin1EPKDsmPc:
  590|    116|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  591|    116|  std::pair<const char16_t *, char *> ret =
  592|    116|      haswell::avx2_convert_utf16_to_latin1<endianness::BIG>(buf, len,
  593|    116|                                                             latin1_output);
  594|    116|  if (ret.first == nullptr) {
  ------------------
  |  Branch (594:7): [True: 22, False: 94]
  ------------------
  595|     22|    return 0;
  596|     22|  }
  597|     94|  size_t saved_bytes = ret.second - latin1_output;
  598|     94|  if (ret.first != buf + len) {
  ------------------
  |  Branch (598:7): [True: 80, False: 14]
  ------------------
  599|     80|    const size_t scalar_saved_bytes =
  600|     80|        scalar::utf16_to_latin1::convert<endianness::BIG>(
  601|     80|            ret.first, len - (ret.first - buf), ret.second);
  602|     80|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (602:9): [True: 48, False: 32]
  ------------------
  603|     48|      return 0;
  604|     48|    }
  605|     32|    saved_bytes += scalar_saved_bytes;
  606|     32|  }
  607|     46|  return saved_bytes;
  608|     94|}
_ZNK7simdutf7haswell14implementation37convert_utf16le_to_latin1_with_errorsEPKDsmPc:
  612|    264|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  613|    264|  std::pair<result, char *> ret =
  614|    264|      avx2_convert_utf16_to_latin1_with_errors<endianness::LITTLE>(
  615|    264|          buf, len, latin1_output);
  616|    264|  if (ret.first.error) {
  ------------------
  |  Branch (616:7): [True: 96, False: 168]
  ------------------
  617|     96|    return ret.first;
  618|     96|  } // Can return directly since scalar fallback already found correct
  619|       |    // ret.first.count
  620|    168|  if (ret.first.count != len) { // All good so far, but not finished
  ------------------
  |  Branch (620:7): [True: 132, False: 36]
  ------------------
  621|    132|    result scalar_res =
  622|    132|        scalar::utf16_to_latin1::convert_with_errors<endianness::LITTLE>(
  623|    132|            buf + ret.first.count, len - ret.first.count, ret.second);
  624|    132|    if (scalar_res.error) {
  ------------------
  |  Branch (624:9): [True: 78, False: 54]
  ------------------
  625|     78|      scalar_res.count += ret.first.count;
  626|     78|      return scalar_res;
  627|     78|    } else {
  628|     54|      ret.second += scalar_res.count;
  629|     54|    }
  630|    132|  }
  631|     90|  ret.first.count =
  632|     90|      ret.second -
  633|     90|      latin1_output; // Set count to the number of 8-bit code units written
  634|     90|  return ret.first;
  635|    168|}
_ZNK7simdutf7haswell14implementation37convert_utf16be_to_latin1_with_errorsEPKDsmPc:
  639|    248|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  640|    248|  std::pair<result, char *> ret =
  641|    248|      avx2_convert_utf16_to_latin1_with_errors<endianness::BIG>(buf, len,
  642|    248|                                                                latin1_output);
  643|    248|  if (ret.first.error) {
  ------------------
  |  Branch (643:7): [True: 106, False: 142]
  ------------------
  644|    106|    return ret.first;
  645|    106|  } // Can return directly since scalar fallback already found correct
  646|       |    // ret.first.count
  647|    142|  if (ret.first.count != len) { // All good so far, but not finished
  ------------------
  |  Branch (647:7): [True: 116, False: 26]
  ------------------
  648|    116|    result scalar_res =
  649|    116|        scalar::utf16_to_latin1::convert_with_errors<endianness::BIG>(
  650|    116|            buf + ret.first.count, len - ret.first.count, ret.second);
  651|    116|    if (scalar_res.error) {
  ------------------
  |  Branch (651:9): [True: 58, False: 58]
  ------------------
  652|     58|      scalar_res.count += ret.first.count;
  653|     58|      return scalar_res;
  654|     58|    } else {
  655|     58|      ret.second += scalar_res.count;
  656|     58|    }
  657|    116|  }
  658|     84|  ret.first.count =
  659|     84|      ret.second -
  660|     84|      latin1_output; // Set count to the number of 8-bit code units written
  661|     84|  return ret.first;
  662|    142|}
_ZNK7simdutf7haswell14implementation23convert_utf16le_to_utf8EPKDsmPc:
  679|    878|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  680|    878|  std::pair<const char16_t *, char *> ret =
  681|    878|      haswell::avx2_convert_utf16_to_utf8<endianness::LITTLE>(buf, len,
  682|    878|                                                              utf8_output);
  683|    878|  if (ret.first == nullptr) {
  ------------------
  |  Branch (683:7): [True: 142, False: 736]
  ------------------
  684|    142|    return 0;
  685|    142|  }
  686|    736|  size_t saved_bytes = ret.second - utf8_output;
  687|    736|  if (ret.first != buf + len) {
  ------------------
  |  Branch (687:7): [True: 734, False: 2]
  ------------------
  688|    734|    const size_t scalar_saved_bytes =
  689|    734|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  690|    734|            ret.first, len - (ret.first - buf), ret.second);
  691|    734|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (691:9): [True: 90, False: 644]
  ------------------
  692|     90|      return 0;
  693|     90|    }
  694|    644|    saved_bytes += scalar_saved_bytes;
  695|    644|  }
  696|    646|  return saved_bytes;
  697|    736|}
_ZNK7simdutf7haswell14implementation23convert_utf16be_to_utf8EPKDsmPc:
  700|    810|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  701|    810|  std::pair<const char16_t *, char *> ret =
  702|    810|      haswell::avx2_convert_utf16_to_utf8<endianness::BIG>(buf, len,
  703|    810|                                                           utf8_output);
  704|    810|  if (ret.first == nullptr) {
  ------------------
  |  Branch (704:7): [True: 110, False: 700]
  ------------------
  705|    110|    return 0;
  706|    110|  }
  707|    700|  size_t saved_bytes = ret.second - utf8_output;
  708|    700|  if (ret.first != buf + len) {
  ------------------
  |  Branch (708:7): [True: 698, False: 2]
  ------------------
  709|    698|    const size_t scalar_saved_bytes =
  710|    698|        scalar::utf16_to_utf8::convert<endianness::BIG>(
  711|    698|            ret.first, len - (ret.first - buf), ret.second);
  712|    698|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (712:9): [True: 84, False: 614]
  ------------------
  713|     84|      return 0;
  714|     84|    }
  715|    614|    saved_bytes += scalar_saved_bytes;
  716|    614|  }
  717|    616|  return saved_bytes;
  718|    700|}
_ZNK7simdutf7haswell14implementation35convert_utf16le_to_utf8_with_errorsEPKDsmPc:
  742|    712|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  743|    712|  return convert_utf16_to_utf8_with_details<endianness::LITTLE>(buf, len,
  744|    712|                                                                utf8_output);
  745|    712|}
_ZNK7simdutf7haswell14implementation35convert_utf16be_to_utf8_with_errorsEPKDsmPc:
  748|    616|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  749|    616|  return convert_utf16_to_utf8_with_details<endianness::BIG>(buf, len,
  750|    616|                                                             utf8_output);
  751|    616|}
_ZNK7simdutf7haswell14implementation29convert_valid_utf16le_to_utf8EPKDsmPc:
  754|    372|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  755|    372|  return convert_utf16le_to_utf8(buf, len, utf8_output);
  756|    372|}
_ZNK7simdutf7haswell14implementation29convert_valid_utf16be_to_utf8EPKDsmPc:
  759|    416|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  760|    416|  return convert_utf16be_to_utf8(buf, len, utf8_output);
  761|    416|}
_ZNK7simdutf7haswell14implementation21convert_utf32_to_utf8EPKDimPc:
  766|    908|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  767|    908|  std::pair<const char32_t *, char *> ret =
  768|    908|      avx2_convert_utf32_to_utf8(buf, len, utf8_output);
  769|    908|  if (ret.first == nullptr) {
  ------------------
  |  Branch (769:7): [True: 334, False: 574]
  ------------------
  770|    334|    return 0;
  771|    334|  }
  772|    574|  size_t saved_bytes = ret.second - utf8_output;
  773|    574|  if (ret.first != buf + len) {
  ------------------
  |  Branch (773:7): [True: 572, False: 2]
  ------------------
  774|    572|    SIMDUTF_VZEROUPPER();
  ------------------
  |  |   22|    572|#define SIMDUTF_VZEROUPPER() _mm256_zeroupper()
  ------------------
  775|    572|    const size_t scalar_saved_bytes = scalar::utf32_to_utf8::convert(
  776|    572|        ret.first, len - (ret.first - buf), ret.second);
  777|    572|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (777:9): [True: 248, False: 324]
  ------------------
  778|    248|      return 0;
  779|    248|    }
  780|    324|    saved_bytes += scalar_saved_bytes;
  781|    324|  }
  782|    326|  return saved_bytes;
  783|    574|}
_ZNK7simdutf7haswell14implementation23convert_utf32_to_latin1EPKDimPc:
  788|    186|    const char32_t *buf, size_t len, char *latin1_output) const noexcept {
  789|    186|  std::pair<const char32_t *, char *> ret =
  790|    186|      avx2_convert_utf32_to_latin1(buf, len, latin1_output);
  791|    186|  if (ret.first == nullptr) {
  ------------------
  |  Branch (791:7): [True: 38, False: 148]
  ------------------
  792|     38|    return 0;
  793|     38|  }
  794|    148|  size_t saved_bytes = ret.second - latin1_output;
  795|    148|  if (ret.first != buf + len) {
  ------------------
  |  Branch (795:7): [True: 130, False: 18]
  ------------------
  796|    130|    const size_t scalar_saved_bytes = scalar::utf32_to_latin1::convert(
  797|    130|        ret.first, len - (ret.first - buf), ret.second);
  798|    130|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (798:9): [True: 114, False: 16]
  ------------------
  799|    114|      return 0;
  800|    114|    }
  801|     16|    saved_bytes += scalar_saved_bytes;
  802|     16|  }
  803|     34|  return saved_bytes;
  804|    148|}
_ZNK7simdutf7haswell14implementation35convert_utf32_to_latin1_with_errorsEPKDimPc:
  807|    488|    const char32_t *buf, size_t len, char *latin1_output) const noexcept {
  808|       |  // ret.first.count is always the position in the buffer, not the number of
  809|       |  // code units written even if finished
  810|    488|  std::pair<result, char *> ret =
  811|    488|      avx2_convert_utf32_to_latin1_with_errors(buf, len, latin1_output);
  812|    488|  if (ret.first.count != len) {
  ------------------
  |  Branch (812:7): [True: 470, False: 18]
  ------------------
  813|    470|    result scalar_res = scalar::utf32_to_latin1::convert_with_errors(
  814|    470|        buf + ret.first.count, len - ret.first.count, ret.second);
  815|    470|    if (scalar_res.error) {
  ------------------
  |  Branch (815:9): [True: 436, False: 34]
  ------------------
  816|    436|      scalar_res.count += ret.first.count;
  817|    436|      return scalar_res;
  818|    436|    } else {
  819|     34|      ret.second += scalar_res.count;
  820|     34|    }
  821|    470|  }
  822|     52|  ret.first.count =
  823|     52|      ret.second -
  824|     52|      latin1_output; // Set count to the number of 8-bit code units written
  825|     52|  return ret.first;
  826|    488|}
_ZNK7simdutf7haswell14implementation33convert_utf32_to_utf8_with_errorsEPKDimPc:
  836|    860|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  837|       |  // ret.first.count is always the position in the buffer, not the number of
  838|       |  // code units written even if finished
  839|    860|  std::pair<result, char *> ret =
  840|    860|      haswell::avx2_convert_utf32_to_utf8_with_errors(buf, len, utf8_output);
  841|    860|  if (ret.first.count != len) {
  ------------------
  |  Branch (841:7): [True: 856, False: 4]
  ------------------
  842|    856|    result scalar_res = scalar::utf32_to_utf8::convert_with_errors(
  843|    856|        buf + ret.first.count, len - ret.first.count, ret.second);
  844|    856|    if (scalar_res.error) {
  ------------------
  |  Branch (844:9): [True: 654, False: 202]
  ------------------
  845|    654|      scalar_res.count += ret.first.count;
  846|    654|      return scalar_res;
  847|    654|    } else {
  848|    202|      ret.second += scalar_res.count;
  849|    202|    }
  850|    856|  }
  851|    206|  ret.first.count =
  852|    206|      ret.second -
  853|    206|      utf8_output; // Set count to the number of 8-bit code units written
  854|    206|  return ret.first;
  855|    860|}
_ZNK7simdutf7haswell14implementation24convert_utf16le_to_utf32EPKDsmPDi:
  860|    426|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  861|    426|  std::pair<const char16_t *, char32_t *> ret =
  862|    426|      haswell::avx2_convert_utf16_to_utf32<endianness::LITTLE>(buf, len,
  863|    426|                                                               utf32_output);
  864|    426|  if (ret.first == nullptr) {
  ------------------
  |  Branch (864:7): [True: 96, False: 330]
  ------------------
  865|     96|    return 0;
  866|     96|  }
  867|    330|  size_t saved_bytes = ret.second - utf32_output;
  868|    330|  if (ret.first != buf + len) {
  ------------------
  |  Branch (868:7): [True: 290, False: 40]
  ------------------
  869|    290|    const size_t scalar_saved_bytes =
  870|    290|        scalar::utf16_to_utf32::convert<endianness::LITTLE>(
  871|    290|            ret.first, len - (ret.first - buf), ret.second);
  872|    290|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (872:9): [True: 92, False: 198]
  ------------------
  873|     92|      return 0;
  874|     92|    }
  875|    198|    saved_bytes += scalar_saved_bytes;
  876|    198|  }
  877|    238|  return saved_bytes;
  878|    330|}
_ZNK7simdutf7haswell14implementation24convert_utf16be_to_utf32EPKDsmPDi:
  881|    436|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  882|    436|  std::pair<const char16_t *, char32_t *> ret =
  883|    436|      haswell::avx2_convert_utf16_to_utf32<endianness::BIG>(buf, len,
  884|    436|                                                            utf32_output);
  885|    436|  if (ret.first == nullptr) {
  ------------------
  |  Branch (885:7): [True: 94, False: 342]
  ------------------
  886|     94|    return 0;
  887|     94|  }
  888|    342|  size_t saved_bytes = ret.second - utf32_output;
  889|    342|  if (ret.first != buf + len) {
  ------------------
  |  Branch (889:7): [True: 300, False: 42]
  ------------------
  890|    300|    const size_t scalar_saved_bytes =
  891|    300|        scalar::utf16_to_utf32::convert<endianness::BIG>(
  892|    300|            ret.first, len - (ret.first - buf), ret.second);
  893|    300|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (893:9): [True: 108, False: 192]
  ------------------
  894|    108|      return 0;
  895|    108|    }
  896|    192|    saved_bytes += scalar_saved_bytes;
  897|    192|  }
  898|    234|  return saved_bytes;
  899|    342|}
_ZNK7simdutf7haswell14implementation36convert_utf16le_to_utf32_with_errorsEPKDsmPDi:
  902|    386|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  903|       |  // ret.first.count is always the position in the buffer, not the number of
  904|       |  // code units written even if finished
  905|    386|  std::pair<result, char32_t *> ret =
  906|    386|      haswell::avx2_convert_utf16_to_utf32_with_errors<endianness::LITTLE>(
  907|    386|          buf, len, utf32_output);
  908|    386|  if (ret.first.error) {
  ------------------
  |  Branch (908:7): [True: 108, False: 278]
  ------------------
  909|    108|    return ret.first;
  910|    108|  } // Can return directly since scalar fallback already found correct
  911|       |    // ret.first.count
  912|    278|  if (ret.first.count != len) { // All good so far, but not finished
  ------------------
  |  Branch (912:7): [True: 248, False: 30]
  ------------------
  913|    248|    result scalar_res =
  914|    248|        scalar::utf16_to_utf32::convert_with_errors<endianness::LITTLE>(
  915|    248|            buf + ret.first.count, len - ret.first.count, ret.second);
  916|    248|    if (scalar_res.error) {
  ------------------
  |  Branch (916:9): [True: 90, False: 158]
  ------------------
  917|     90|      scalar_res.count += ret.first.count;
  918|     90|      return scalar_res;
  919|    158|    } else {
  920|    158|      ret.second += scalar_res.count;
  921|    158|    }
  922|    248|  }
  923|    188|  ret.first.count =
  924|    188|      ret.second -
  925|    188|      utf32_output; // Set count to the number of 8-bit code units written
  926|    188|  return ret.first;
  927|    278|}
_ZNK7simdutf7haswell14implementation36convert_utf16be_to_utf32_with_errorsEPKDsmPDi:
  930|    366|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  931|       |  // ret.first.count is always the position in the buffer, not the number of
  932|       |  // code units written even if finished
  933|    366|  std::pair<result, char32_t *> ret =
  934|    366|      haswell::avx2_convert_utf16_to_utf32_with_errors<endianness::BIG>(
  935|    366|          buf, len, utf32_output);
  936|    366|  if (ret.first.error) {
  ------------------
  |  Branch (936:7): [True: 84, False: 282]
  ------------------
  937|     84|    return ret.first;
  938|     84|  } // Can return directly since scalar fallback already found correct
  939|       |    // ret.first.count
  940|    282|  if (ret.first.count != len) { // All good so far, but not finished
  ------------------
  |  Branch (940:7): [True: 256, False: 26]
  ------------------
  941|    256|    result scalar_res =
  942|    256|        scalar::utf16_to_utf32::convert_with_errors<endianness::BIG>(
  943|    256|            buf + ret.first.count, len - ret.first.count, ret.second);
  944|    256|    if (scalar_res.error) {
  ------------------
  |  Branch (944:9): [True: 112, False: 144]
  ------------------
  945|    112|      scalar_res.count += ret.first.count;
  946|    112|      return scalar_res;
  947|    144|    } else {
  948|    144|      ret.second += scalar_res.count;
  949|    144|    }
  950|    256|  }
  951|    170|  ret.first.count =
  952|    170|      ret.second -
  953|    170|      utf32_output; // Set count to the number of 8-bit code units written
  954|    170|  return ret.first;
  955|    282|}
_ZNK7simdutf7haswell14implementation27convert_valid_utf32_to_utf8EPKDimPc:
  960|    194|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  961|    194|  return convert_utf32_to_utf8(buf, len, utf8_output);
  962|    194|}
_ZNK7simdutf7haswell14implementation24convert_utf32_to_utf16leEPKDimPDs:
  967|    794|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
  968|    794|  std::pair<const char32_t *, char16_t *> ret =
  969|    794|      avx2_convert_utf32_to_utf16<endianness::LITTLE>(buf, len, utf16_output);
  970|    794|  if (ret.first == nullptr) {
  ------------------
  |  Branch (970:7): [True: 190, False: 604]
  ------------------
  971|    190|    return 0;
  972|    190|  }
  973|    604|  size_t saved_bytes = ret.second - utf16_output;
  974|    604|  if (ret.first != buf + len) {
  ------------------
  |  Branch (974:7): [True: 600, False: 4]
  ------------------
  975|    600|    const size_t scalar_saved_bytes =
  976|    600|        scalar::utf32_to_utf16::convert<endianness::LITTLE>(
  977|    600|            ret.first, len - (ret.first - buf), ret.second);
  978|    600|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (978:9): [True: 182, False: 418]
  ------------------
  979|    182|      return 0;
  980|    182|    }
  981|    418|    saved_bytes += scalar_saved_bytes;
  982|    418|  }
  983|    422|  return saved_bytes;
  984|    604|}
_ZNK7simdutf7haswell14implementation24convert_utf32_to_utf16beEPKDimPDs:
  987|    652|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
  988|    652|  std::pair<const char32_t *, char16_t *> ret =
  989|    652|      avx2_convert_utf32_to_utf16<endianness::BIG>(buf, len, utf16_output);
  990|    652|  if (ret.first == nullptr) {
  ------------------
  |  Branch (990:7): [True: 198, False: 454]
  ------------------
  991|    198|    return 0;
  992|    198|  }
  993|    454|  size_t saved_bytes = ret.second - utf16_output;
  994|    454|  if (ret.first != buf + len) {
  ------------------
  |  Branch (994:7): [True: 452, False: 2]
  ------------------
  995|    452|    const size_t scalar_saved_bytes =
  996|    452|        scalar::utf32_to_utf16::convert<endianness::BIG>(
  997|    452|            ret.first, len - (ret.first - buf), ret.second);
  998|    452|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (998:9): [True: 178, False: 274]
  ------------------
  999|    178|      return 0;
 1000|    178|    }
 1001|    274|    saved_bytes += scalar_saved_bytes;
 1002|    274|  }
 1003|    276|  return saved_bytes;
 1004|    454|}
_ZNK7simdutf7haswell14implementation36convert_utf32_to_utf16le_with_errorsEPKDimPDs:
 1007|    772|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
 1008|       |  // ret.first.count is always the position in the buffer, not the number of
 1009|       |  // code units written even if finished
 1010|    772|  std::pair<result, char16_t *> ret =
 1011|    772|      haswell::avx2_convert_utf32_to_utf16_with_errors<endianness::LITTLE>(
 1012|    772|          buf, len, utf16_output);
 1013|    772|  if (ret.first.count != len) {
  ------------------
  |  Branch (1013:7): [True: 768, False: 4]
  ------------------
 1014|    768|    result scalar_res =
 1015|    768|        scalar::utf32_to_utf16::convert_with_errors<endianness::LITTLE>(
 1016|    768|            buf + ret.first.count, len - ret.first.count, ret.second);
 1017|    768|    if (scalar_res.error) {
  ------------------
  |  Branch (1017:9): [True: 596, False: 172]
  ------------------
 1018|    596|      scalar_res.count += ret.first.count;
 1019|    596|      return scalar_res;
 1020|    596|    } else {
 1021|    172|      ret.second += scalar_res.count;
 1022|    172|    }
 1023|    768|  }
 1024|    176|  ret.first.count =
 1025|    176|      ret.second -
 1026|    176|      utf16_output; // Set count to the number of 8-bit code units written
 1027|    176|  return ret.first;
 1028|    772|}
_ZNK7simdutf7haswell14implementation36convert_utf32_to_utf16be_with_errorsEPKDimPDs:
 1031|    678|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
 1032|       |  // ret.first.count is always the position in the buffer, not the number of
 1033|       |  // code units written even if finished
 1034|    678|  std::pair<result, char16_t *> ret =
 1035|    678|      haswell::avx2_convert_utf32_to_utf16_with_errors<endianness::BIG>(
 1036|    678|          buf, len, utf16_output);
 1037|    678|  if (ret.first.count != len) {
  ------------------
  |  Branch (1037:7): [True: 674, False: 4]
  ------------------
 1038|    674|    result scalar_res =
 1039|    674|        scalar::utf32_to_utf16::convert_with_errors<endianness::BIG>(
 1040|    674|            buf + ret.first.count, len - ret.first.count, ret.second);
 1041|    674|    if (scalar_res.error) {
  ------------------
  |  Branch (1041:9): [True: 498, False: 176]
  ------------------
 1042|    498|      scalar_res.count += ret.first.count;
 1043|    498|      return scalar_res;
 1044|    498|    } else {
 1045|    176|      ret.second += scalar_res.count;
 1046|    176|    }
 1047|    674|  }
 1048|    180|  ret.first.count =
 1049|    180|      ret.second -
 1050|    180|      utf16_output; // Set count to the number of 8-bit code units written
 1051|    180|  return ret.first;
 1052|    678|}
_ZNK7simdutf7haswell14implementation30convert_valid_utf32_to_utf16leEPKDimPDs:
 1055|    292|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
 1056|    292|  return convert_utf32_to_utf16le(buf, len, utf16_output);
 1057|    292|}
_ZNK7simdutf7haswell14implementation30convert_valid_utf32_to_utf16beEPKDimPDs:
 1060|    136|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
 1061|    136|  return convert_utf32_to_utf16be(buf, len, utf16_output);
 1062|    136|}
_ZNK7simdutf7haswell14implementation30convert_valid_utf16le_to_utf32EPKDsmPDi:
 1065|    118|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
 1066|    118|  return convert_utf16le_to_utf32(buf, len, utf32_output);
 1067|    118|}
_ZNK7simdutf7haswell14implementation30convert_valid_utf16be_to_utf32EPKDsmPDi:
 1070|    134|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
 1071|    134|  return convert_utf16be_to_utf32(buf, len, utf32_output);
 1072|    134|}
_ZNK7simdutf7haswell14implementation13count_utf16leEPKDsm:
 1083|  1.42k|    const char16_t *input, size_t length) const noexcept {
 1084|  1.42k|  return utf16::count_code_points<endianness::LITTLE>(input, length);
 1085|  1.42k|}
_ZNK7simdutf7haswell14implementation13count_utf16beEPKDsm:
 1088|  1.33k|    const char16_t *input, size_t length) const noexcept {
 1089|  1.33k|  return utf16::count_code_points<endianness::BIG>(input, length);
 1090|  1.33k|}
_ZNK7simdutf7haswell14implementation10count_utf8EPKcm:
 1095|  4.81k|implementation::count_utf8(const char *in, size_t size) const noexcept {
 1096|  4.81k|  return utf8::count_code_points_bytemask(in, size);
 1097|  4.81k|}
_ZNK7simdutf7haswell14implementation23latin1_length_from_utf8EPKcm:
 1107|    693|    const char *buf, size_t len) const noexcept {
 1108|    693|  return count_utf8(buf, len);
 1109|    693|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16leEPKDsm:
 1114|    808|    const char16_t *input, size_t length) const noexcept {
 1115|    808|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1116|    808|                                                                    length);
 1117|    808|}
_ZNK7simdutf7haswell14implementation24utf8_length_from_utf16beEPKDsm:
 1120|    732|    const char16_t *input, size_t length) const noexcept {
 1121|    732|  return utf16::utf8_length_from_utf16_bytemask<endianness::BIG>(input, length);
 1122|    732|}
_ZNK7simdutf7haswell14implementation25utf32_length_from_utf16leEPKDsm:
 1127|    413|    const char16_t *input, size_t length) const noexcept {
 1128|    413|  return utf16::utf32_length_from_utf16<endianness::LITTLE>(input, length);
 1129|    413|}
_ZNK7simdutf7haswell14implementation25utf32_length_from_utf16beEPKDsm:
 1132|    420|    const char16_t *input, size_t length) const noexcept {
 1133|    420|  return utf16::utf32_length_from_utf16<endianness::BIG>(input, length);
 1134|    420|}
_ZNK7simdutf7haswell14implementation22utf16_length_from_utf8EPKcm:
 1139|  2.22k|    const char *input, size_t length) const noexcept {
 1140|  2.22k|  return utf8::utf16_length_from_utf8_bytemask(input, length);
 1141|  2.22k|}
_ZNK7simdutf7haswell14implementation23utf8_length_from_latin1EPKcm:
 1180|    243|    const char *input, size_t len) const noexcept {
 1181|    243|  const uint8_t *data = reinterpret_cast<const uint8_t *>(input);
 1182|    243|  size_t answer = len / sizeof(__m256i) * sizeof(__m256i);
 1183|    243|  size_t i = 0;
 1184|    243|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1184:7): [True: 101, False: 142]
  ------------------
 1185|    101|    __m256i four_64bits = _mm256_setzero_si256();
 1186|  2.73k|    while (i + sizeof(__m256i) <= len) {
  ------------------
  |  Branch (1186:12): [True: 2.63k, False: 101]
  ------------------
 1187|  2.63k|      __m256i runner = _mm256_setzero_si256();
 1188|       |      // We can do up to 255 loops without overflow.
 1189|  2.63k|      size_t iterations = (len - i) / sizeof(__m256i);
 1190|  2.63k|      if (iterations > 255) {
  ------------------
  |  Branch (1190:11): [True: 2.53k, False: 101]
  ------------------
 1191|  2.53k|        iterations = 255;
 1192|  2.53k|      }
 1193|  2.63k|      size_t max_i = i + iterations * sizeof(__m256i) - sizeof(__m256i);
 1194|   164k|      for (; i + 4 * sizeof(__m256i) <= max_i; i += 4 * sizeof(__m256i)) {
  ------------------
  |  Branch (1194:14): [True: 161k, False: 2.63k]
  ------------------
 1195|   161k|        __m256i input1 = _mm256_loadu_si256((const __m256i *)(data + i));
 1196|   161k|        __m256i input2 =
 1197|   161k|            _mm256_loadu_si256((const __m256i *)(data + i + sizeof(__m256i)));
 1198|   161k|        __m256i input3 = _mm256_loadu_si256(
 1199|   161k|            (const __m256i *)(data + i + 2 * sizeof(__m256i)));
 1200|   161k|        __m256i input4 = _mm256_loadu_si256(
 1201|   161k|            (const __m256i *)(data + i + 3 * sizeof(__m256i)));
 1202|   161k|        __m256i input12 =
 1203|   161k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input1),
 1204|   161k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input2));
 1205|   161k|        __m256i input23 =
 1206|   161k|            _mm256_add_epi8(_mm256_cmpgt_epi8(_mm256_setzero_si256(), input3),
 1207|   161k|                            _mm256_cmpgt_epi8(_mm256_setzero_si256(), input4));
 1208|   161k|        __m256i input1234 = _mm256_add_epi8(input12, input23);
 1209|   161k|        runner = _mm256_sub_epi8(runner, input1234);
 1210|   161k|      }
 1211|  10.4k|      for (; i <= max_i; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1211:14): [True: 7.84k, False: 2.63k]
  ------------------
 1212|  7.84k|        __m256i input_256_chunk =
 1213|  7.84k|            _mm256_loadu_si256((const __m256i *)(data + i));
 1214|  7.84k|        runner = _mm256_sub_epi8(
 1215|  7.84k|            runner, _mm256_cmpgt_epi8(_mm256_setzero_si256(), input_256_chunk));
 1216|  7.84k|      }
 1217|  2.63k|      four_64bits = _mm256_add_epi64(
 1218|  2.63k|          four_64bits, _mm256_sad_epu8(runner, _mm256_setzero_si256()));
 1219|  2.63k|    }
 1220|    101|    answer += _mm256_extract_epi64(four_64bits, 0) +
 1221|    101|              _mm256_extract_epi64(four_64bits, 1) +
 1222|    101|              _mm256_extract_epi64(four_64bits, 2) +
 1223|    101|              _mm256_extract_epi64(four_64bits, 3);
 1224|    142|  } else if (answer > 0) {
  ------------------
  |  Branch (1224:14): [True: 67, False: 75]
  ------------------
 1225|    737|    for (; i + sizeof(__m256i) <= len; i += sizeof(__m256i)) {
  ------------------
  |  Branch (1225:12): [True: 670, False: 67]
  ------------------
 1226|    670|      __m256i latin = _mm256_loadu_si256((const __m256i *)(data + i));
 1227|    670|      uint32_t non_ascii = _mm256_movemask_epi8(latin);
 1228|    670|      answer += count_ones(non_ascii);
 1229|    670|    }
 1230|     67|  }
 1231|    243|  return answer + scalar::latin1::utf8_length_from_latin1(
 1232|    243|                      reinterpret_cast<const char *>(data + i), len - i);
 1233|    243|}
_ZNK7simdutf7haswell14implementation22utf8_length_from_utf32EPKDim:
 1238|    892|    const char32_t *input, size_t length) const noexcept {
 1239|    892|  return utf32::utf8_length_from_utf32(input, length);
 1240|    892|}
_ZNK7simdutf7haswell14implementation23utf16_length_from_utf32EPKDim:
 1245|  1.45k|    const char32_t *input, size_t length) const noexcept {
 1246|  1.45k|  const __m256i v_00000000 = _mm256_setzero_si256();
 1247|  1.45k|  const __m256i v_ffff0000 = _mm256_set1_epi32((uint32_t)0xffff0000);
 1248|  1.45k|  size_t pos = 0;
 1249|  1.45k|  size_t count = 0;
 1250|   483k|  for (; pos + 8 <= length; pos += 8) {
  ------------------
  |  Branch (1250:10): [True: 482k, False: 1.45k]
  ------------------
 1251|   482k|    __m256i in = _mm256_loadu_si256((__m256i *)(input + pos));
 1252|   482k|    const __m256i surrogate_bytemask =
 1253|   482k|        _mm256_cmpeq_epi32(_mm256_and_si256(in, v_ffff0000), v_00000000);
 1254|   482k|    const uint32_t surrogate_bitmask =
 1255|   482k|        static_cast<uint32_t>(_mm256_movemask_epi8(surrogate_bytemask));
 1256|   482k|    size_t surrogate_count = (32 - count_ones(surrogate_bitmask)) / 4;
 1257|   482k|    count += 8 + surrogate_count;
 1258|   482k|  }
 1259|  1.45k|  return count +
 1260|  1.45k|         scalar::utf32::utf16_length_from_utf32(input + pos, length - pos);
 1261|  1.45k|}
_ZNK7simdutf7haswell14implementation22utf32_length_from_utf8EPKcm:
 1266|  1.20k|    const char *input, size_t length) const noexcept {
 1267|  1.20k|  return utf8::count_code_points(input, length);
 1268|  1.20k|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_18is_asciiERKNS1_4simd8simd8x64IhEE:
   13|  5.20M|simdutf_really_inline bool is_ascii(const simd8x64<uint8_t> &input) {
   14|  5.20M|  return input.reduce_or().is_ascii();
   15|  5.20M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_124must_be_2_3_continuationENS1_4simd5simd8IhEES4_:
   22|  3.50M|                         const simd8<uint8_t> prev3) {
   23|  3.50M|  simd8<uint8_t> is_third_byte =
   24|  3.50M|      prev2.saturating_sub(0xe0u - 0x80); // Only 111_____ will be > 0x80
   25|  3.50M|  simd8<uint8_t> is_fourth_byte =
   26|  3.50M|      prev3.saturating_sub(0xf0u - 0x80); // Only 1111____ will be > 0x80
   27|  3.50M|  return simd8<bool>(is_third_byte | is_fourth_byte);
   28|  3.50M|}
_ZN7simdutf7haswell34convert_utf16_to_utf8_with_detailsILNS_10endiannessE0EEENS_11full_resultEPKDsmPc:
  722|    712|    const char16_t *buf, size_t len, char *utf8_output) {
  723|    712|  std::pair<result, char *> ret =
  724|    712|      haswell::avx2_convert_utf16_to_utf8_with_errors<big_endian>(buf, len,
  725|    712|                                                                  utf8_output);
  726|    712|  if (ret.first.error) {
  ------------------
  |  Branch (726:7): [True: 152, False: 560]
  ------------------
  727|    152|    return full_result(ret.first.error, ret.first.count,
  728|    152|                       size_t(ret.second - utf8_output));
  729|    152|  }
  730|    560|  if (ret.first.count != len) {
  ------------------
  |  Branch (730:7): [True: 556, False: 4]
  ------------------
  731|    556|    full_result sres =
  732|    556|        scalar::utf16_to_utf8::convert_with_errors<big_endian, false>(
  733|    556|            buf + ret.first.count, len - ret.first.count, ret.second, 0);
  734|    556|    return full_result(sres.error, ret.first.count + sres.input_count,
  735|    556|                       size_t(ret.second - utf8_output) + sres.output_count);
  736|    556|  }
  737|      4|  return full_result(error_code::SUCCESS, len,
  738|      4|                     size_t(ret.second - utf8_output));
  739|    560|}
_ZN7simdutf7haswell34convert_utf16_to_utf8_with_detailsILNS_10endiannessE1EEENS_11full_resultEPKDsmPc:
  722|    616|    const char16_t *buf, size_t len, char *utf8_output) {
  723|    616|  std::pair<result, char *> ret =
  724|    616|      haswell::avx2_convert_utf16_to_utf8_with_errors<big_endian>(buf, len,
  725|    616|                                                                  utf8_output);
  726|    616|  if (ret.first.error) {
  ------------------
  |  Branch (726:7): [True: 144, False: 472]
  ------------------
  727|    144|    return full_result(ret.first.error, ret.first.count,
  728|    144|                       size_t(ret.second - utf8_output));
  729|    144|  }
  730|    472|  if (ret.first.count != len) {
  ------------------
  |  Branch (730:7): [True: 468, False: 4]
  ------------------
  731|    468|    full_result sres =
  732|    468|        scalar::utf16_to_utf8::convert_with_errors<big_endian, false>(
  733|    468|            buf + ret.first.count, len - ret.first.count, ret.second, 0);
  734|    468|    return full_result(sres.error, ret.first.count + sres.input_count,
  735|    468|                       size_t(ret.second - utf8_output) + sres.output_count);
  736|    468|  }
  737|      4|  return full_result(error_code::SUCCESS, len,
  738|      4|                     size_t(ret.second - utf8_output));
  739|    472|}

_ZNK7simdutf14implementation27supported_by_runtime_systemEv:
   64|      8|bool implementation::supported_by_runtime_system() const {
   65|      8|  uint32_t required_instruction_sets = this->required_instruction_sets();
   66|      8|  uint32_t supported_instruction_sets =
   67|      8|      internal::detect_supported_architectures();
   68|      8|  return ((supported_instruction_sets & required_instruction_sets) ==
   69|      8|          required_instruction_sets);
   70|      8|}
_ZNK7simdutf8internal29available_implementation_list5beginEv:
 1513|      1|available_implementation_list::begin() const noexcept {
 1514|      1|  return internal::get_available_implementation_pointers().begin();
 1515|      1|}
_ZNK7simdutf8internal29available_implementation_list3endEv:
 1517|      1|available_implementation_list::end() const noexcept {
 1518|      1|  return internal::get_available_implementation_pointers().end();
 1519|      1|}
_ZN7simdutf29get_available_implementationsEv:
 1568|      1|get_available_implementations() {
 1569|      1|#if !SIMDUTF_USE_STATIC_INITIALIZATION
 1570|      1|  static const internal::available_implementation_list
 1571|      1|      available_implementations_instance{};
 1572|      1|#endif
 1573|      1|  return available_implementations_instance;
 1574|      1|}
simdutf.cpp:_ZN7simdutf8internalL37get_available_implementation_pointersEv:
  938|      2|get_available_implementation_pointers() {
  939|      2|#if !SIMDUTF_USE_STATIC_INITIALIZATION
  940|      2|  static const std::initializer_list<const implementation *>
  941|      2|      available_implementation_pointers{
  942|      2|  #if SIMDUTF_IMPLEMENTATION_ICELAKE
  943|      2|          get_icelake_singleton(),
  944|      2|  #endif
  945|      2|  #if SIMDUTF_IMPLEMENTATION_HASWELL
  946|      2|          get_haswell_singleton(),
  947|      2|  #endif
  948|      2|  #if SIMDUTF_IMPLEMENTATION_WESTMERE
  949|      2|          get_westmere_singleton(),
  950|      2|  #endif
  951|       |  #if SIMDUTF_IMPLEMENTATION_ARM64
  952|       |          get_arm64_singleton(),
  953|       |  #endif
  954|       |  #if SIMDUTF_IMPLEMENTATION_PPC64
  955|       |          get_ppc64_singleton(),
  956|       |  #endif
  957|       |  #if SIMDUTF_IMPLEMENTATION_RVV
  958|       |          get_rvv_singleton(),
  959|       |  #endif
  960|       |  #if SIMDUTF_IMPLEMENTATION_LASX
  961|       |          get_lasx_singleton(),
  962|       |  #endif
  963|       |  #if SIMDUTF_IMPLEMENTATION_LSX
  964|       |          get_lsx_singleton(),
  965|       |  #endif
  966|      2|  #if SIMDUTF_IMPLEMENTATION_FALLBACK
  967|      2|          get_fallback_singleton(),
  968|      2|  #endif
  969|      2|      };
  970|      2|#endif
  971|      2|  return available_implementation_pointers;
  972|      2|}
simdutf.cpp:_ZN7simdutf8internalL21get_icelake_singletonEv:
  157|      1|static const icelake::implementation *get_icelake_singleton() {
  158|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  159|      1|  static const icelake::implementation icelake_singleton{};
  160|      1|  #endif
  161|      1|  return &icelake_singleton;
  162|      1|}
simdutf.cpp:_ZN7simdutf8internalL21get_haswell_singletonEv:
  168|      1|static const haswell::implementation *get_haswell_singleton() {
  169|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  170|      1|  static const haswell::implementation haswell_singleton{};
  171|      1|  #endif
  172|      1|  return &haswell_singleton;
  173|      1|}
simdutf.cpp:_ZN7simdutf8internalL22get_westmere_singletonEv:
  179|      1|static const westmere::implementation *get_westmere_singleton() {
  180|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  181|      1|  static const westmere::implementation westmere_singleton{};
  182|      1|  #endif
  183|      1|  return &westmere_singleton;
  184|      1|}
simdutf.cpp:_ZN7simdutf8internalL22get_fallback_singletonEv:
  245|      1|static const fallback::implementation *get_fallback_singleton() {
  246|      1|  #if !SIMDUTF_USE_STATIC_INITIALIZATION
  247|      1|  static const fallback::implementation fallback_singleton{};
  248|      1|  #endif
  249|      1|  return &fallback_singleton;
  250|      1|}

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

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

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2EDv4_x:
   97|  70.1M|      : base16_numeric<uint16_t>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEC2EDv4_x:
   73|  70.1M|      : base16<T>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6base16ItNS2_6simd16IbEEEC2EDv4_x:
   20|  70.1M|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE4packERKS4_S6_:
  149|  5.24M|                                                   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|  5.24M|    const __m128i lo_0 = _mm256_extracti128_si256(v0, 0);
  156|  5.24M|    const __m128i lo_1 = _mm256_extracti128_si256(v1, 0);
  157|       |
  158|       |    // get the 1st lanes
  159|  5.24M|    const __m128i hi_0 = _mm256_extracti128_si256(v0, 1);
  160|  5.24M|    const __m128i hi_1 = _mm256_extracti128_si256(v1, 1);
  161|       |
  162|       |    // build new vectors (shuffle lanes)
  163|  5.24M|    const __m256i t0 = _mm256_set_m128i(lo_1, lo_0);
  ------------------
  |  |    4|  5.24M|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  5.24M|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  164|  5.24M|    const __m256i t1 = _mm256_set_m128i(hi_1, hi_0);
  ------------------
  |  |    4|  5.24M|      _mm256_permute2f128_si256(_mm256_castsi128_si256(xmm1),                  \
  |  |    5|  5.24M|                                _mm256_castsi128_si256(xmm2), 2)
  ------------------
  165|       |
  166|       |    // pack code units in linear order from v0 and v1
  167|  5.24M|    return _mm256_packus_epi16(t0, t1);
  168|  5.24M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd9simd16x32ItEC2EPKt:
  202|  2.05M|      : chunks{simd16<T>::load(ptr),
  203|  2.05M|               simd16<T>::load(ptr + sizeof(simd16<T>) / sizeof(T))} {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE4loadEPKt:
   66|  16.5M|  static simdutf_really_inline simd16<T> load(const T values[8]) {
   67|  16.5M|    return _mm256_loadu_si256(reinterpret_cast<const __m256i *>(values));
   68|  16.5M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd9simd16x32ItE10swap_bytesEv:
  229|  1.07M|  simdutf_really_inline void swap_bytes() {
  230|  1.07M|    this->chunks[0] = this->chunks[0].swap_bytes();
  231|  1.07M|    this->chunks[1] = this->chunks[1].swap_bytes();
  232|  1.07M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE10swap_bytesEv:
  139|  3.11M|  simdutf_really_inline simd16<uint16_t> swap_bytes() const {
  140|  3.11M|    const __m256i swap = _mm256_setr_epi8(
  141|  3.11M|        1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18,
  142|  3.11M|        21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30);
  143|  3.11M|    return _mm256_shuffle_epi8(*this, swap);
  144|  3.11M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE5splatEt:
   58|  14.4M|  static simdutf_really_inline simd16<T> splat(T _value) {
   59|  14.4M|    return _mm256_set1_epi16(_value);
   60|  14.4M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simdeqENS2_6simd16ItEES4_:
   26|  10.1M|                                               const simd16<T> rhs) {
   27|  10.1M|    return _mm256_cmpeq_epi16(lhs, rhs);
   28|  10.1M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16IbEC2EDv4_x:
   45|  14.2M|  simdutf_really_inline simd16(const __m256i _value) : base16<bool>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6base16IbNS2_6simd16IbEEEC2EDv4_x:
   20|  14.2M|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd9simd16x32IbEC2ENS2_6simd16IbEES6_:
  200|  2.05M|      : chunks{chunk0, chunk1} {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd9simd16x32IbE10to_bitmaskEv:
  210|  2.05M|  simdutf_really_inline uint64_t to_bitmask() const {
  211|  2.05M|    uint64_t r_lo = uint32_t(this->chunks[0].to_bitmask());
  212|  2.05M|    uint64_t r_hi = this->chunks[1].to_bitmask();
  213|  2.05M|    return r_lo | (r_hi << 32);
  214|  2.05M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16IbE10to_bitmaskEv:
   50|  4.11M|  simdutf_really_inline bitmask_type to_bitmask() const {
   51|  4.11M|    return _mm256_movemask_epi8(*this);
   52|  4.11M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE3shrILi8EEES4_v:
  134|  5.22M|  template <int N> simdutf_really_inline simd16<uint16_t> shr() const {
  135|  5.22M|    return simd16<uint16_t>(_mm256_srli_epi16(*this, N));
  136|  5.22M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEleES4_:
  117|  4.11M|  operator<=(const simd16<uint16_t> other) const {
  118|  4.11M|    return other.max_val(*this) == other;
  119|  4.11M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE7max_valES4_:
  108|  4.11M|  max_val(const simd16<uint16_t> other) const {
  109|  4.11M|    return _mm256_max_epu16(*this, other);
  110|  4.11M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2EPKDs:
  104|  10.4M|      : simd16(load(reinterpret_cast<const uint16_t *>(values))) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEC2Et:
  100|  10.3M|  simdutf_really_inline simd16(uint16_t _value) : simd16(splat(_value)) {}
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd9simd16x32ItE12not_in_rangeEtt:
  249|  2.05M|  simdutf_really_inline uint64_t not_in_range(const T low, const T high) const {
  250|  2.05M|    const simd16<T> mask_low = simd16<T>::splat(static_cast<T>(low - 1));
  251|  2.05M|    const simd16<T> mask_high = simd16<T>::splat(static_cast<T>(high + 1));
  252|  2.05M|    return simd16x32<bool>(
  253|  2.05M|               (this->chunks[0] >= mask_high) | (this->chunks[0] <= mask_low),
  254|  2.05M|               (this->chunks[1] >= mask_high) | (this->chunks[1] <= mask_low))
  255|  2.05M|        .to_bitmask();
  256|  2.05M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItEgeES4_:
  121|  4.11M|  operator>=(const simd16<uint16_t> other) const {
  122|  4.11M|    return other.min_val(*this) == other;
  123|  4.11M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE7min_valES4_:
  112|  4.11M|  min_val(const simd16<uint16_t> other) const {
  113|  4.11M|    return _mm256_min_epu16(*this, other);
  114|  4.11M|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItE4zeroEv:
   62|  1.57k|  static simdutf_really_inline simd16<T> zero() {
   63|  1.57k|    return _mm256_setzero_si256();
   64|  1.57k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd3minENS2_6simd16ItEES4_:
  259|  3.85M|simd16<uint16_t> min(const simd16<uint16_t> a, simd16<uint16_t> b) {
  260|  3.85M|  return _mm256_min_epu16(a.value, b.value);
  261|  3.85M|}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEpLENS2_6simd16ItEE:
   87|  5.77M|  simdutf_really_inline simd16<T> &operator+=(const simd16<T> other) {
   88|  5.77M|    *this = *this + other;
   89|  5.77M|    return *static_cast<simd16<T> *>(this);
   90|  5.77M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd14base16_numericItEplENS2_6simd16ItEE:
   84|  5.77M|  simdutf_really_inline simd16<T> operator+(const simd16<T> other) const {
   85|  5.77M|    return _mm256_add_epi16(*this, other);
   86|  5.77M|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd16ItE3sumEv:
  170|  1.57k|  simdutf_really_inline uint64_t sum() const {
  171|  1.57k|    const auto lo_u16 = _mm256_and_si256(value, _mm256_set1_epi32(0x0000ffff));
  172|  1.57k|    const auto hi_u16 = _mm256_srli_epi32(value, 16);
  173|  1.57k|    const auto sum_u32 = _mm256_add_epi32(lo_u16, hi_u16);
  174|       |
  175|  1.57k|    const auto lo_u32 =
  176|  1.57k|        _mm256_and_si256(sum_u32, _mm256_set1_epi64x(0xffffffff));
  177|  1.57k|    const auto hi_u32 = _mm256_srli_epi64(sum_u32, 32);
  178|  1.57k|    const auto sum_u64 = _mm256_add_epi64(lo_u32, hi_u32);
  179|       |
  180|  1.57k|    return uint64_t(_mm256_extract_epi64(sum_u64, 0)) +
  181|  1.57k|           uint64_t(_mm256_extract_epi64(sum_u64, 1)) +
  182|  1.57k|           uint64_t(_mm256_extract_epi64(sum_u64, 2)) +
  183|       |           uint64_t(_mm256_extract_epi64(sum_u64, 3));
  184|  1.57k|  }

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

simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd64ImE4zeroEv:
   27|  7.03k|  simdutf_really_inline static simd64<uint64_t> zero() {
   28|  7.03k|    return _mm256_setzero_si256();
   29|  7.03k|  }
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd64ImEC2EDv4_x:
    9|  60.8k|  simdutf_really_inline simd64(const __m256i v) : value(v) {}
simdutf.cpp:_ZN7simdutf7haswell12_GLOBAL__N_14simd6simd64ImEpLES4_:
   21|  53.7k|  simdutf_really_inline simd64 &operator+=(const simd64 other) {
   22|  53.7k|    value = _mm256_add_epi64(value, other.value);
   23|  53.7k|    return *this;
   24|  53.7k|  }
simdutf.cpp:_ZNK7simdutf7haswell12_GLOBAL__N_14simd6simd64ImE3sumEv:
   15|  7.03k|  simdutf_really_inline uint64_t sum() const {
   16|  7.03k|    return _mm256_extract_epi64(value, 0) + _mm256_extract_epi64(value, 1) +
   17|  7.03k|           _mm256_extract_epi64(value, 2) + _mm256_extract_epi64(value, 3);
   18|  7.03k|  }

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

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

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2Ev:
  183|  24.7k|  simdutf_really_inline simd8() : base8_numeric<uint8_t>() {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhEC2Ev:
  118|  24.7k|  simdutf_really_inline base8_numeric() : base8<T>() {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2Ev:
   68|  24.7k|  simdutf_really_inline base8() : base<simd8<T>>() {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2Ev:
   13|  24.7k|  simdutf_really_inline base() : value{__m128i()} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IhE9reduce_orEv:
  290|  5.20M|  simdutf_really_inline simd8<T> reduce_or() const {
  291|  5.20M|    return (this->chunks[0] | this->chunks[1]) |
  292|  5.20M|           (this->chunks[2] | this->chunks[3]);
  293|  5.20M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEorES5_:
   42|  34.1M|  simdutf_really_inline Child operator|(const Child other) const {
   43|  34.1M|    return _mm_or_si128(*this, other);
   44|  34.1M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2EDv2_x:
  185|   341M|      : base8_numeric<uint8_t>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhEC2EDv2_x:
  120|   341M|      : base8<T>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEEC2EDv2_x:
   69|   341M|  simdutf_really_inline base8(const __m128i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEC2EDv2_x:
   16|   341M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE8is_asciiEv:
  228|  5.20M|  simdutf_really_inline bool is_ascii() const {
  229|  5.20M|    return _mm_movemask_epi8(*this) == 0;
  230|  5.20M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEoRES5_:
   51|  11.5M|  simdutf_really_inline Child &operator|=(const Child other) {
   52|  11.5M|    auto this_cast = static_cast<Child *>(this);
   53|  11.5M|    *this_cast = *this_cast | other;
   54|  11.5M|    return *this_cast;
   55|  11.5M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi1EEENS4_IhEES8_:
   79|  7.24M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   80|       |    return _mm_alignr_epi8(*this, prev_chunk, 16 - N);
   81|  7.24M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE3shrILi4EEES4_v:
  238|  14.4M|  template <int N> simdutf_really_inline simd8<uint8_t> shr() const {
  239|  14.4M|    return simd8<uint8_t>(_mm_srli_epi16(*this, N)) & uint8_t(0xFFu >> N);
  240|  14.4M|  }
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|  21.7M|            L replace15) const {
  152|  21.7M|    return lookup_16(simd8<L>::repeat_16(
  153|  21.7M|        replace0, replace1, replace2, replace3, replace4, replace5, replace6,
  154|  21.7M|        replace7, replace8, replace9, replace10, replace11, replace12,
  155|  21.7M|        replace13, replace14, replace15));
  156|  21.7M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE9lookup_16IhEENS2_5simd8IT_EES8_:
  142|  21.7M|  simdutf_really_inline simd8<L> lookup_16(simd8<L> lookup_table) const {
  143|  21.7M|    return _mm_shuffle_epi8(lookup_table, *this);
  144|  21.7M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE9repeat_16Ehhhhhhhhhhhhhhhh:
  113|  21.7M|                                                  T v14, T v15) {
  114|  21.7M|    return simd8<T>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
  115|  21.7M|                    v14, v15);
  116|  21.7M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2Ehhhhhhhhhhhhhhhh:
  196|  21.7M|      : simd8(_mm_setr_epi8(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
  197|  21.7M|                            v12, v13, v14, v15)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2Eh:
  188|  50.0M|  simdutf_really_inline simd8(uint8_t _value) : simd8(splat(_value)) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi2EEENS4_IhEES8_:
   79|  7.01M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   80|       |    return _mm_alignr_epi8(*this, prev_chunk, 16 - N);
   81|  7.01M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5base8IhNS2_5simd8IbEEE4prevILi3EEENS4_IhEES8_:
   79|  7.01M|  simdutf_really_inline simd8<T> prev(const simd8<T> prev_chunk) const {
   80|       |    return _mm_alignr_epi8(*this, prev_chunk, 16 - N);
   81|  7.01M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE14saturating_subES4_:
  201|  14.9M|  saturating_sub(const simd8<uint8_t> other) const {
  202|  14.9M|    return _mm_subs_epu8(*this, other);
  203|  14.9M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IbEC2EDv2_x:
   91|  48.0M|  simdutf_really_inline simd8(const __m128i _value) : base8<bool>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IbNS2_5simd8IbEEEC2EDv2_x:
   69|  48.0M|  simdutf_really_inline base8(const __m128i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEC2EDv2_x:
   16|  48.0M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IbEEEcvRKDv2_xEv:
   18|  48.0M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEeoES5_:
   48|  7.01M|  simdutf_really_inline Child operator^(const Child other) const {
   49|  7.01M|    return _mm_xor_si128(*this, other);
   50|  7.01M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEC2EPKh:
  190|   941k|  simdutf_really_inline simd8(const uint8_t *values) : simd8(load(values)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE4loadEPKh:
  106|  21.7M|  static simdutf_really_inline simd8<T> load(const T values[16]) {
  107|  21.7M|    return _mm_loadu_si128(reinterpret_cast<const __m128i *>(values));
  108|  21.7M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE7gt_bitsES4_:
  212|   941k|  gt_bits(const simd8<uint8_t> other) const {
  213|   941k|    return this->saturating_sub(other);
  214|   941k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEC2EDv2_x:
   16|   112M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEcvRKDv2_xEv:
   18|   152M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IbE10to_bitmaskEv:
   95|  13.6M|  simdutf_really_inline int to_bitmask() const {
   96|  13.6M|    return _mm_movemask_epi8(*this);
   97|  13.6M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE21any_bits_set_anywhereEv:
  235|  2.35M|  simdutf_really_inline bool any_bits_set_anywhere() const {
  236|  2.35M|    return !bits_not_set_anywhere();
  237|  2.35M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE21bits_not_set_anywhereEv:
  232|  2.35M|  simdutf_really_inline bool bits_not_set_anywhere() const {
  233|  2.35M|    return _mm_testz_si128(*this, *this);
  234|  2.35M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaEC2EPKa:
  270|  6.51M|      : chunks{simd8<T>::load(ptr),
  271|  6.51M|               simd8<T>::load(ptr + sizeof(simd8<T>) / sizeof(T)),
  272|  6.51M|               simd8<T>::load(ptr + 2 * sizeof(simd8<T>) / sizeof(T)),
  273|  6.51M|               simd8<T>::load(ptr + 3 * sizeof(simd8<T>) / sizeof(T))} {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIaE4loadEPKa:
  106|  47.1M|  static simdutf_really_inline simd8<T> load(const T values[16]) {
  107|  47.1M|    return _mm_loadu_si128(reinterpret_cast<const __m128i *>(values));
  108|  47.1M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IaEC2EDv2_x:
  163|  87.2M|      : base8_numeric<int8_t>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIaEC2EDv2_x:
  120|  87.2M|      : base8<T>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5base8IaNS2_5simd8IbEEEC2EDv2_x:
   69|  87.2M|  simdutf_really_inline base8(const __m128i _value) : base<simd8<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IaEEEC2EDv2_x:
   16|  87.2M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE8is_asciiEv:
  295|  5.63M|  simdutf_really_inline bool is_ascii() const {
  296|  5.63M|    return this->reduce_or().is_ascii();
  297|  5.63M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE9reduce_orEv:
  290|  5.63M|  simdutf_really_inline simd8<T> reduce_or() const {
  291|  5.63M|    return (this->chunks[0] | this->chunks[1]) |
  292|  5.63M|           (this->chunks[2] | this->chunks[3]);
  293|  5.63M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IaEEEorES5_:
   42|  16.9M|  simdutf_really_inline Child operator|(const Child other) const {
   43|  16.9M|    return _mm_or_si128(*this, other);
   44|  16.9M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IaEEEcvRKDv2_xEv:
   18|   140M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IaE8is_asciiEv:
  168|  5.63M|  simdutf_really_inline bool is_ascii() const {
  169|  5.63M|    return _mm_movemask_epi8(*this) == 0;
  170|  5.63M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE5storeEPa:
  275|   972k|  simdutf_really_inline void store(T *ptr) const {
  276|   972k|    this->chunks[0].store(ptr + sizeof(simd8<T>) * 0 / sizeof(T));
  277|   972k|    this->chunks[1].store(ptr + sizeof(simd8<T>) * 1 / sizeof(T));
  278|   972k|    this->chunks[2].store(ptr + sizeof(simd8<T>) * 2 / sizeof(T));
  279|   972k|    this->chunks[3].store(ptr + sizeof(simd8<T>) * 3 / sizeof(T));
  280|   972k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIaE5storeEPa:
  123|  3.88M|  simdutf_really_inline void store(T dst[16]) const {
  124|  3.88M|    return _mm_storeu_si128(reinterpret_cast<__m128i *>(dst), *this);
  125|  3.88M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IaEcvNS3_IhEEEv:
  251|  6.09M|simdutf_really_inline simd8<int8_t>::operator simd8<uint8_t>() const {
  252|  6.09M|  return this->value;
  253|  6.09M|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE2ltEa:
  326|  1.19M|  simdutf_really_inline uint64_t lt(const T m) const {
  327|  1.19M|    const simd8<T> mask = simd8<T>::splat(m);
  328|  1.19M|    return simd8x64<bool>(this->chunks[0] < mask, this->chunks[1] < mask,
  329|  1.19M|                          this->chunks[2] < mask, this->chunks[3] < mask)
  330|  1.19M|        .to_bitmask();
  331|  1.19M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIaE5splatEa:
  102|  23.1M|  static simdutf_really_inline simd8<T> splat(T _value) {
  103|  23.1M|    return _mm_set1_epi8(_value);
  104|  23.1M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IaEltES4_:
  176|  4.78M|  simdutf_really_inline simd8<bool> operator<(const simd8<int8_t> other) const {
  177|  4.78M|    return _mm_cmpgt_epi8(other, *this);
  178|  4.78M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IbEC2ENS2_5simd8IbEES6_S6_S6_:
  268|  2.07M|      : chunks{chunk0, chunk1, chunk2, chunk3} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IbE10to_bitmaskEv:
  318|  2.07M|  simdutf_really_inline uint64_t to_bitmask() const {
  319|  2.07M|    uint64_t r0 = uint32_t(this->chunks[0].to_bitmask());
  320|  2.07M|    uint64_t r1 = this->chunks[1].to_bitmask();
  321|  2.07M|    uint64_t r2 = this->chunks[2].to_bitmask();
  322|  2.07M|    uint64_t r3 = this->chunks[3].to_bitmask();
  323|  2.07M|    return r0 | (r1 << 16) | (r2 << 32) | (r3 << 48);
  324|  2.07M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE20store_ascii_as_utf32EPDi:
  311|  1.29M|  simdutf_really_inline void store_ascii_as_utf32(char32_t *ptr) const {
  312|  1.29M|    this->chunks[0].store_ascii_as_utf32(ptr + sizeof(simd8<T>) * 0);
  313|  1.29M|    this->chunks[1].store_ascii_as_utf32(ptr + sizeof(simd8<T>) * 1);
  314|  1.29M|    this->chunks[2].store_ascii_as_utf32(ptr + sizeof(simd8<T>) * 2);
  315|  1.29M|    this->chunks[3].store_ascii_as_utf32(ptr + sizeof(simd8<T>) * 3);
  316|  1.29M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IaEEE20store_ascii_as_utf32EPDi:
   32|  5.17M|  simdutf_really_inline void store_ascii_as_utf32(char32_t *p) const {
   33|  5.17M|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p), _mm_cvtepu8_epi32(*this));
   34|  5.17M|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p + 4),
   35|  5.17M|                     _mm_cvtepu8_epi32(_mm_srli_si128(*this, 4)));
   36|  5.17M|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p + 8),
   37|  5.17M|                     _mm_cvtepu8_epi32(_mm_srli_si128(*this, 8)));
   38|  5.17M|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p + 12),
   39|       |                     _mm_cvtepu8_epi32(_mm_srli_si128(*this, 12)));
   40|  5.17M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE4zeroEv:
  105|   222k|  static simdutf_really_inline simd8<T> zero() { return _mm_setzero_si128(); }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IaEgtES4_:
  173|  24.6M|  simdutf_really_inline simd8<bool> operator>(const simd8<int8_t> other) const {
  174|  24.6M|    return _mm_cmpgt_epi8(*this, other);
  175|  24.6M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd5simd8IaEC2Ea:
  165|  21.0M|  simdutf_really_inline simd8(int8_t _value) : simd8(splat(_value)) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhEmIENS2_5simd8IhEE:
  134|  27.4M|  simdutf_really_inline simd8<T> &operator-=(const simd8<T> other) {
  135|  27.4M|    *this = *this - other;
  136|  27.4M|    return *static_cast<simd8<T> *>(this);
  137|  27.4M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhEmiENS2_5simd8IhEE:
  131|  27.4M|  simdutf_really_inline simd8<T> operator-(const simd8<T> other) const {
  132|  27.4M|    return _mm_sub_epi8(*this, other);
  133|  27.4M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd10sum_8bytesENS2_5simd8IhEE:
  366|   107k|simdutf_really_inline simd64<uint64_t> sum_8bytes(const simd8<uint8_t> v) {
  367|   107k|  return _mm_sad_epu8(v.value, simd8<uint8_t>::zero());
  368|   107k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE9sum_bytesEv:
  245|  4.90k|  simdutf_really_inline uint64_t sum_bytes() const {
  246|  4.90k|    const auto tmp = _mm_sad_epu8(value, _mm_setzero_si128());
  247|  4.90k|    return _mm_extract_epi64(tmp, 0) + _mm_extract_epi64(tmp, 1);
  248|  4.90k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhEgeES4_:
  217|  6.34M|  operator>=(const simd8<uint8_t> other) const {
  218|  6.34M|    return other.min_val(*this) == other;
  219|  6.34M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd5simd8IhE7min_valES4_:
  207|  6.34M|  min_val(const simd8<uint8_t> other) const {
  208|  6.34M|    return _mm_min_epu8(*this, other);
  209|  6.34M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE2gtEa:
  333|   881k|  simdutf_really_inline uint64_t gt(const T m) const {
  334|   881k|    const simd8<T> mask = simd8<T>::splat(m);
  335|   881k|    return simd8x64<bool>(this->chunks[0] > mask, this->chunks[1] > mask,
  336|   881k|                          this->chunks[2] > mask, this->chunks[3] > mask)
  337|   881k|        .to_bitmask();
  338|   881k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEC2EDv2_x:
   16|  28.5M|  simdutf_really_inline base(const __m128i _value) : value(_value) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEcvRKDv2_xEv:
   18|  28.5M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd13base8_numericIhE5splatEh:
  102|  50.0M|  static simdutf_really_inline simd8<T> splat(T _value) {
  103|  50.0M|    return _mm_set1_epi8(_value);
  104|  50.0M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEcvRKDv2_xEv:
   18|   417M|  simdutf_really_inline operator const __m128i &() const { return this->value; }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdeqENS2_5simd8IhEES4_:
   72|  11.6M|                                               const simd8<T> rhs) {
   73|  11.6M|    return _mm_cmpeq_epi8(lhs, rhs);
   74|  11.6M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IhEEEanES5_:
   45|  48.5M|  simdutf_really_inline Child operator&(const Child other) const {
   46|  48.5M|    return _mm_and_si128(*this, other);
   47|  48.5M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IhEC2EPKh:
  270|  5.20M|      : chunks{simd8<T>::load(ptr),
  271|  5.20M|               simd8<T>::load(ptr + sizeof(simd8<T>) / sizeof(T)),
  272|  5.20M|               simd8<T>::load(ptr + 2 * sizeof(simd8<T>) / sizeof(T)),
  273|  5.20M|               simd8<T>::load(ptr + 3 * sizeof(simd8<T>) / sizeof(T))} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16ItEEEanES5_:
   45|  16.8M|  simdutf_really_inline Child operator&(const Child other) const {
   46|  16.8M|    return _mm_and_si128(*this, other);
   47|  16.8M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE20store_ascii_as_utf16ILNS_10endiannessE0EEEvPDs:
  300|  1.13M|  simdutf_really_inline void store_ascii_as_utf16(char16_t *ptr) const {
  301|  1.13M|    this->chunks[0].template store_ascii_as_utf16<endian>(ptr +
  302|  1.13M|                                                          sizeof(simd8<T>) * 0);
  303|  1.13M|    this->chunks[1].template store_ascii_as_utf16<endian>(ptr +
  304|  1.13M|                                                          sizeof(simd8<T>) * 1);
  305|  1.13M|    this->chunks[2].template store_ascii_as_utf16<endian>(ptr +
  306|  1.13M|                                                          sizeof(simd8<T>) * 2);
  307|  1.13M|    this->chunks[3].template store_ascii_as_utf16<endian>(ptr +
  308|  1.13M|                                                          sizeof(simd8<T>) * 3);
  309|  1.13M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IaEEE20store_ascii_as_utf16ILNS_10endiannessE0EEEvPDs:
   20|  4.55M|  simdutf_really_inline void store_ascii_as_utf16(char16_t *p) const {
   21|  4.55M|    __m128i first = _mm_cvtepu8_epi16(*this);
   22|  4.55M|    __m128i second = _mm_cvtepu8_epi16(_mm_srli_si128(*this, 8));
   23|  4.55M|    if (big_endian) {
  ------------------
  |  Branch (23:9): [Folded, False: 4.55M]
  ------------------
   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|  4.55M|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p), first);
   30|  4.55M|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p + 8), second);
   31|  4.55M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd8simd8x64IaE20store_ascii_as_utf16ILNS_10endiannessE1EEEvPDs:
  300|  1.03M|  simdutf_really_inline void store_ascii_as_utf16(char16_t *ptr) const {
  301|  1.03M|    this->chunks[0].template store_ascii_as_utf16<endian>(ptr +
  302|  1.03M|                                                          sizeof(simd8<T>) * 0);
  303|  1.03M|    this->chunks[1].template store_ascii_as_utf16<endian>(ptr +
  304|  1.03M|                                                          sizeof(simd8<T>) * 1);
  305|  1.03M|    this->chunks[2].template store_ascii_as_utf16<endian>(ptr +
  306|  1.03M|                                                          sizeof(simd8<T>) * 2);
  307|  1.03M|    this->chunks[3].template store_ascii_as_utf16<endian>(ptr +
  308|  1.03M|                                                          sizeof(simd8<T>) * 3);
  309|  1.03M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_5simd8IaEEE20store_ascii_as_utf16ILNS_10endiannessE1EEEvPDs:
   20|  4.12M|  simdutf_really_inline void store_ascii_as_utf16(char16_t *p) const {
   21|  4.12M|    __m128i first = _mm_cvtepu8_epi16(*this);
   22|  4.12M|    __m128i second = _mm_cvtepu8_epi16(_mm_srli_si128(*this, 8));
   23|  4.12M|    if (big_endian) {
  ------------------
  |  Branch (23:9): [True: 4.12M, Folded]
  ------------------
   24|  4.12M|      const __m128i swap =
   25|  4.12M|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   26|  4.12M|      first = _mm_shuffle_epi8(first, swap);
   27|  4.12M|      second = _mm_shuffle_epi8(second, swap);
   28|  4.12M|    }
   29|  4.12M|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p), first);
   30|  4.12M|    _mm_storeu_si128(reinterpret_cast<__m128i *>(p + 8), second);
   31|  4.12M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd12as_vector_u8ENS2_6simd32IjEE:
  370|  8.27k|simdutf_really_inline simd8<uint8_t> as_vector_u8(const simd32<uint32_t> v) {
  371|  8.27k|  return simd8<uint8_t>(v.value);
  372|  8.27k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd4baseINS2_6simd16IbEEEorES5_:
   42|  8.23M|  simdutf_really_inline Child operator|(const Child other) const {
   43|  8.23M|    return _mm_or_si128(*this, other);
   44|  8.23M|  }

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16ItEC2EDv2_x:
   79|   112M|      : base16_numeric<uint16_t>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItEC2EDv2_x:
   54|   112M|      : base16<T>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6base16ItNS2_6simd16IbEEEC2EDv2_x:
    8|   112M|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16ItE4packERKS4_S6_:
  130|  5.25M|                                                   const simd16<uint16_t> &v1) {
  131|  5.25M|    return _mm_packus_epi16(v0, v1);
  132|  5.25M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd9simd16x32ItEC2EPKt:
  164|  2.05M|      : chunks{simd16<T>::load(ptr),
  165|  2.05M|               simd16<T>::load(ptr + sizeof(simd16<T>) / sizeof(T)),
  166|  2.05M|               simd16<T>::load(ptr + 2 * sizeof(simd16<T>) / sizeof(T)),
  167|  2.05M|               simd16<T>::load(ptr + 3 * sizeof(simd16<T>) / sizeof(T))} {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItE4loadEPKt:
   47|  22.5M|  static simdutf_really_inline simd16<T> load(const T values[8]) {
   48|  22.5M|    return _mm_loadu_si128(reinterpret_cast<const __m128i *>(values));
   49|  22.5M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd9simd16x32ItE10swap_bytesEv:
  200|  1.07M|  simdutf_really_inline void swap_bytes() {
  201|  1.07M|    this->chunks[0] = this->chunks[0].swap_bytes();
  202|  1.07M|    this->chunks[1] = this->chunks[1].swap_bytes();
  203|  1.07M|    this->chunks[2] = this->chunks[2].swap_bytes();
  204|  1.07M|    this->chunks[3] = this->chunks[3].swap_bytes();
  205|  1.07M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16ItE10swap_bytesEv:
  121|  6.23M|  simdutf_really_inline simd16<uint16_t> swap_bytes() const {
  122|  6.23M|    const __m128i swap =
  123|  6.23M|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  124|  6.23M|    return _mm_shuffle_epi8(*this, swap);
  125|  6.23M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItE5splatEt:
   41|  22.1M|  static simdutf_really_inline simd16<T> splat(T _value) {
   42|  22.1M|    return _mm_set1_epi16(_value);
   43|  22.1M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdeqENS2_6simd16ItEES4_:
   11|  20.3M|                                               const simd16<T> rhs) {
   12|  20.3M|    return _mm_cmpeq_epi16(lhs, rhs);
   13|  20.3M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16IbEC2EDv2_x:
   28|  28.5M|  simdutf_really_inline simd16(const __m128i _value) : base16<bool>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6base16IbNS2_6simd16IbEEEC2EDv2_x:
    8|  28.5M|      : base<simd16<T>>(_value) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd9simd16x32IbEC2ENS2_6simd16IbEES6_S6_S6_:
  162|  2.05M|      : chunks{chunk0, chunk1, chunk2, chunk3} {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd9simd16x32IbE10to_bitmaskEv:
  192|  2.05M|  simdutf_really_inline uint64_t to_bitmask() const {
  193|  2.05M|    uint64_t r0 = uint32_t(this->chunks[0].to_bitmask());
  194|  2.05M|    uint64_t r1 = this->chunks[1].to_bitmask();
  195|  2.05M|    uint64_t r2 = this->chunks[2].to_bitmask();
  196|  2.05M|    uint64_t r3 = this->chunks[3].to_bitmask();
  197|  2.05M|    return r0 | (r1 << 16) | (r2 << 32) | (r3 << 48);
  198|  2.05M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16IbE10to_bitmaskEv:
   33|  8.23M|  simdutf_really_inline int to_bitmask() const {
   34|  8.23M|    return _mm_movemask_epi8(*this);
   35|  8.23M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16ItEgeES4_:
  104|  8.23M|  operator>=(const simd16<uint16_t> other) const {
  105|  8.23M|    return other.min_val(*this) == other;
  106|  8.23M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16ItE7min_valES4_:
   95|  8.23M|  min_val(const simd16<uint16_t> other) const {
   96|  8.23M|    return _mm_min_epu16(*this, other);
   97|  8.23M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16ItE3shrILi8EEES4_v:
  116|  5.22M|  template <int N> simdutf_really_inline simd16<uint16_t> shr() const {
  117|  5.22M|    return simd16<uint16_t>(_mm_srli_epi16(*this, N));
  118|  5.22M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16ItEleES4_:
  100|  8.23M|  operator<=(const simd16<uint16_t> other) const {
  101|  8.23M|    return other.max_val(*this) == other;
  102|  8.23M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16ItE7max_valES4_:
   90|  8.23M|  max_val(const simd16<uint16_t> other) const {
   91|  8.23M|    return _mm_max_epu16(*this, other);
   92|  8.23M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16ItEC2EPKDs:
   86|  10.5M|      : simd16(load(reinterpret_cast<const uint16_t *>(values))) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd16ItEC2Et:
   82|  18.0M|  simdutf_really_inline simd16(uint16_t _value) : simd16(splat(_value)) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd9simd16x32ItE12not_in_rangeEtt:
  228|  2.05M|  simdutf_really_inline uint64_t not_in_range(const T low, const T high) const {
  229|  2.05M|    const simd16<T> mask_low = simd16<T>::splat(static_cast<T>(low - 1));
  230|  2.05M|    const simd16<T> mask_high = simd16<T>::splat(static_cast<T>(high + 1));
  231|  2.05M|    return simd16x32<bool>(
  232|  2.05M|               (this->chunks[0] >= mask_high) | (this->chunks[0] <= mask_low),
  233|  2.05M|               (this->chunks[1] >= mask_high) | (this->chunks[1] <= mask_low),
  234|  2.05M|               (this->chunks[2] >= mask_high) | (this->chunks[2] <= mask_low),
  235|  2.05M|               (this->chunks[3] >= mask_high) | (this->chunks[3] <= mask_low))
  236|  2.05M|        .to_bitmask();
  237|  2.05M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItE4zeroEv:
   45|  1.63k|  static simdutf_really_inline simd16<T> zero() { return _mm_setzero_si128(); }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd3minENS2_6simd16ItEES4_:
  240|  7.70M|simd16<uint16_t> min(const simd16<uint16_t> a, simd16<uint16_t> b) {
  241|  7.70M|  return _mm_min_epu16(a.value, b.value);
  242|  7.70M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItEpLENS2_6simd16ItEE:
   68|  11.5M|  simdutf_really_inline simd16<T> &operator+=(const simd16<T> other) {
   69|  11.5M|    *this = *this + other;
   70|  11.5M|    return *static_cast<simd16<T> *>(this);
   71|  11.5M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd14base16_numericItEplENS2_6simd16ItEE:
   65|  11.5M|  simdutf_really_inline simd16<T> operator+(const simd16<T> other) const {
   66|  11.5M|    return _mm_add_epi16(*this, other);
   67|  11.5M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd16ItE3sumEv:
  134|  1.63k|  simdutf_really_inline uint64_t sum() const {
  135|  1.63k|    const auto lo_u16 = _mm_and_si128(value, _mm_set1_epi32(0x0000ffff));
  136|  1.63k|    const auto hi_u16 = _mm_srli_epi32(value, 16);
  137|  1.63k|    const auto sum_u32 = _mm_add_epi32(lo_u16, hi_u16);
  138|       |
  139|  1.63k|    const auto lo_u32 = _mm_and_si128(sum_u32, _mm_set1_epi64x(0xffffffff));
  140|  1.63k|    const auto hi_u32 = _mm_srli_epi64(sum_u32, 32);
  141|  1.63k|    const auto sum_u64 = _mm_add_epi64(lo_u32, hi_u32);
  142|       |
  143|  1.63k|    return uint64_t(_mm_extract_epi64(sum_u64, 0)) +
  144|       |           uint64_t(_mm_extract_epi64(sum_u64, 1));
  145|  1.63k|  }

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd32IjE5splatEj:
   56|  32.3k|  simdutf_really_inline static simd32<uint32_t> splat(uint32_t v) {
   57|  32.3k|    return _mm_set1_epi32(v);
   58|  32.3k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd32IjEC2EDv2_x:
    9|  13.2M|  simdutf_really_inline simd32(const __m128i v) : value(v) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd32IjE4zeroEv:
   52|  6.29k|  simdutf_really_inline static simd32<uint32_t> zero() {
   53|  6.29k|    return _mm_setzero_si128();
   54|  6.29k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd32IjEC2IDiEEPKT_:
   13|  3.05M|      : value(_mm_loadu_si128(reinterpret_cast<const __m128i *>(ptr))) {}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd32IjE10swap_bytesEv:
   22|  2.45M|  simdutf_really_inline simd32<uint32_t> swap_bytes() const {
   23|  2.45M|    const __m128i shuffle =
   24|  2.45M|        _mm_setr_epi8(3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11, 15, 14, 13, 12);
   25|       |
   26|  2.45M|    return _mm_shuffle_epi8(value, shuffle);
   27|  2.45M|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd3maxENS2_6simd32IjEES4_:
   94|  4.62M|                                           const simd32<uint32_t> b) {
   95|  4.62M|  return _mm_max_epu32(a.value, b.value);
   96|  4.62M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdplENS2_6simd32IjEES4_:
  119|  2.31M|                                                 const simd32<uint32_t> b) {
  120|  2.31M|  return _mm_add_epi32(a.value, b.value);
  121|  2.31M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdgtENS2_6simd32IjEES4_:
  143|  16.9k|                                             const simd32<uint32_t> b) {
  144|  16.9k|  return !(b >= a);
  145|  16.9k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdntENS2_6simd32IbEE:
  138|  16.9k|simdutf_really_inline simd32<bool> operator!(const simd32<bool> v) {
  139|  16.9k|  return _mm_xor_si128(v.value, _mm_set1_epi8(-1));
  140|  16.9k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd32IbEC2EDv2_x:
   69|   481k|  simdutf_really_inline simd32(const __m128i v) : value(v) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdgeENS2_6simd32IjEES4_:
  134|   160k|                                              const simd32<uint32_t> b) {
  135|   160k|  return _mm_cmpeq_epi32(_mm_max_epu32(a.value, b.value), a.value);
  136|   160k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd32IbE3anyEv:
   71|   151k|  simdutf_really_inline bool any() const {
   72|   151k|    return _mm_movemask_epi8(value) != 0;
   73|   151k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdeqENS2_6simd32IjEES4_:
  129|   143k|                                              const simd32<uint32_t> b) {
  130|   143k|  return _mm_cmpeq_epi32(a.value, b.value);
  131|   143k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdanENS2_6simd32IjEES4_:
  104|  1.94M|                                                 const simd32<uint32_t> b) {
  105|  1.94M|  return _mm_and_si128(a.value, b.value);
  106|  1.94M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdorIbEENS2_6simd32IT_EES6_S6_:
   84|   152k|                                          const simd32<T> b) {
   85|   152k|  return _mm_or_si128(a.value, b.value);
   86|   152k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd3minENS2_6simd32IjEES4_:
   89|  1.79M|                                           const simd32<uint32_t> b) {
   90|  1.79M|  return _mm_min_epu32(a.value, b.value);
   91|  1.79M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd32IjEpLES4_:
   46|  1.79M|  simdutf_really_inline simd32 &operator+=(const simd32 other) {
   47|  1.79M|    value = _mm_add_epi32(value, other.value);
   48|  1.79M|    return *this;
   49|  1.79M|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd32IjE3sumEv:
   15|    972|  simdutf_really_inline uint64_t sum() const {
   16|    972|    return uint64_t(_mm_extract_epi32(value, 0)) +
   17|    972|           uint64_t(_mm_extract_epi32(value, 1)) +
   18|    972|           uint64_t(_mm_extract_epi32(value, 2)) +
   19|       |           uint64_t(_mm_extract_epi32(value, 3));
   20|    972|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdeqENS2_6simd32IjEEj:
   99|  8.27k|                                              uint32_t b) {
  100|  8.27k|  return _mm_cmpeq_epi32(a.value, _mm_set1_epi32(b));
  101|  8.27k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdanENS2_6simd32IjEEj:
  109|  24.8k|                                                 uint32_t b) {
  110|  24.8k|  return _mm_and_si128(a.value, _mm_set1_epi32(b));
  111|  24.8k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd32IbE15to_4bit_bitmaskEv:
   75|  8.27k|  simdutf_really_inline uint8_t to_4bit_bitmask() const {
   76|  8.27k|    return uint8_t(_mm_movemask_ps(_mm_castsi128_ps(value)));
   77|  8.27k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdmiENS2_6simd32IjEEj:
  124|  8.27k|                                                 uint32_t b) {
  125|  8.27k|  return _mm_sub_epi32(a.value, _mm_set1_epi32(b));
  126|  8.27k|}
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd32IjE3shrILi10EEES4_v:
   29|  8.27k|  template <int N> simdutf_really_inline simd32<uint32_t> shr() const {
   30|  8.27k|    return _mm_srli_epi32(value, N);
   31|  8.27k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd32IjE3shlILi16EEES4_v:
   33|  8.27k|  template <int N> simdutf_really_inline simd32<uint32_t> shl() const {
   34|  8.27k|    return _mm_slli_epi32(value, N);
   35|  8.27k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdorENS2_6simd32IjEEj:
  114|  8.27k|                                                 uint32_t b) {
  115|  8.27k|  return _mm_or_si128(a.value, _mm_set1_epi32(b));
  116|  8.27k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simdorIjEENS2_6simd32IT_EES6_S6_:
   84|  8.27k|                                          const simd32<T> b) {
   85|  8.27k|  return _mm_or_si128(a.value, b.value);
   86|  8.27k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6selectENS2_6simd32IbEENS3_IjEES5_:
  149|  8.27k|                                              const simd32<uint32_t> v_false) {
  150|  8.27k|  return _mm_blendv_epi8(v_false.value, v_true.value, cond.value);
  151|  8.27k|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd64ImE4zeroEv:
   26|  7.03k|  simdutf_really_inline static simd64<uint64_t> zero() {
   27|  7.03k|    return _mm_setzero_si128();
   28|  7.03k|  }
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd64ImEC2EDv2_x:
    9|   114k|  simdutf_really_inline simd64(const __m128i v) : value(v) {}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_14simd6simd64ImEpLES4_:
   20|   107k|  simdutf_really_inline simd64 &operator+=(const simd64 other) {
   21|   107k|    value = _mm_add_epi64(value, other.value);
   22|   107k|    return *this;
   23|   107k|  }
simdutf.cpp:_ZNK7simdutf8westmere12_GLOBAL__N_14simd6simd64ImE3sumEv:
   15|  7.03k|  simdutf_really_inline uint64_t sum() const {
   16|  7.03k|    return _mm_extract_epi64(value, 0) + _mm_extract_epi64(value, 1);
   17|  7.03k|  }

_ZNK7simdutf8westmere14implementation13validate_utf8EPKcm:
  299|  4.11k|implementation::validate_utf8(const char *buf, size_t len) const noexcept {
  300|  4.11k|  return westmere::utf8_validation::generic_validate_utf8(buf, len);
  301|  4.11k|}
_ZNK7simdutf8westmere14implementation25validate_utf8_with_errorsEPKcm:
  306|  4.11k|    const char *buf, size_t len) const noexcept {
  307|  4.11k|  return westmere::utf8_validation::generic_validate_utf8_with_errors(buf, len);
  308|  4.11k|}
_ZNK7simdutf8westmere14implementation16validate_utf16leEPKDsm:
  345|  1.42k|                                 size_t len) const noexcept {
  346|  1.42k|  if (simdutf_unlikely(len == 0)) {
  ------------------
  |  |   93|  1.42k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 17, False: 1.40k]
  |  |  ------------------
  ------------------
  347|       |    // empty input is valid UTF-16. protect the implementation from
  348|       |    // handling nullptr
  349|     17|    return true;
  350|     17|  }
  351|  1.40k|  const auto res =
  352|  1.40k|      westmere::utf16::validate_utf16_with_errors<endianness::LITTLE>(buf, len);
  353|  1.40k|  if (res.is_err()) {
  ------------------
  |  Branch (353:7): [True: 150, False: 1.25k]
  ------------------
  354|    150|    return false;
  355|    150|  }
  356|       |
  357|  1.25k|  if (res.count == len)
  ------------------
  |  Branch (357:7): [True: 0, False: 1.25k]
  ------------------
  358|      0|    return true;
  359|       |
  360|  1.25k|  return scalar::utf16::validate<endianness::LITTLE>(buf + res.count,
  361|  1.25k|                                                     len - res.count);
  362|  1.25k|}
_ZNK7simdutf8westmere14implementation16validate_utf16beEPKDsm:
  368|  1.33k|                                 size_t len) const noexcept {
  369|  1.33k|  if (simdutf_unlikely(len == 0)) {
  ------------------
  |  |   93|  1.33k|    #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
  |  |  ------------------
  |  |  |  Branch (93:33): [True: 16, False: 1.31k]
  |  |  ------------------
  ------------------
  370|       |    // empty input is valid UTF-16. protect the implementation from
  371|       |    // handling nullptr
  372|     16|    return true;
  373|     16|  }
  374|  1.31k|  const auto res =
  375|  1.31k|      westmere::utf16::validate_utf16_with_errors<endianness::BIG>(buf, len);
  376|  1.31k|  if (res.is_err()) {
  ------------------
  |  Branch (376:7): [True: 125, False: 1.19k]
  ------------------
  377|    125|    return false;
  378|    125|  }
  379|       |
  380|  1.19k|  if (res.count == len)
  ------------------
  |  Branch (380:7): [True: 0, False: 1.19k]
  ------------------
  381|      0|    return true;
  382|       |
  383|  1.19k|  return scalar::utf16::validate<endianness::BIG>(buf + res.count,
  384|  1.19k|                                                  len - res.count);
  385|  1.19k|}
_ZNK7simdutf8westmere14implementation28validate_utf16le_with_errorsEPKDsm:
  388|  1.42k|    const char16_t *buf, size_t len) const noexcept {
  389|  1.42k|  const result res =
  390|  1.42k|      westmere::utf16::validate_utf16_with_errors<endianness::LITTLE>(buf, len);
  391|  1.42k|  if (res.count != len) {
  ------------------
  |  Branch (391:7): [True: 1.40k, False: 17]
  ------------------
  392|  1.40k|    const result scalar_res =
  393|  1.40k|        scalar::utf16::validate_with_errors<endianness::LITTLE>(
  394|  1.40k|            buf + res.count, len - res.count);
  395|  1.40k|    return result(scalar_res.error, res.count + scalar_res.count);
  396|  1.40k|  } else {
  397|     17|    return res;
  398|     17|  }
  399|  1.42k|}
_ZNK7simdutf8westmere14implementation28validate_utf16be_with_errorsEPKDsm:
  402|  1.33k|    const char16_t *buf, size_t len) const noexcept {
  403|  1.33k|  const result res =
  404|  1.33k|      westmere::utf16::validate_utf16_with_errors<endianness::BIG>(buf, len);
  405|  1.33k|  if (res.count != len) {
  ------------------
  |  Branch (405:7): [True: 1.31k, False: 16]
  ------------------
  406|  1.31k|    result scalar_res = scalar::utf16::validate_with_errors<endianness::BIG>(
  407|  1.31k|        buf + res.count, len - res.count);
  408|  1.31k|    return result(scalar_res.error, res.count + scalar_res.count);
  409|  1.31k|  } else {
  410|     16|    return res;
  411|     16|  }
  412|  1.33k|}
_ZNK7simdutf8westmere14implementation14validate_utf32EPKDim:
  427|  2.68k|implementation::validate_utf32(const char32_t *buf, size_t len) const noexcept {
  428|  2.68k|  return utf32::validate(buf, len);
  429|  2.68k|}
_ZNK7simdutf8westmere14implementation26validate_utf32_with_errorsEPKDim:
  434|  2.68k|    const char32_t *buf, size_t len) const noexcept {
  435|  2.68k|  return utf32::validate_with_errors(buf, len);
  436|  2.68k|}
_ZNK7simdutf8westmere14implementation22convert_latin1_to_utf8EPKcmPc:
  441|    486|    const char *buf, size_t len, char *utf8_output) const noexcept {
  442|       |
  443|    486|  std::pair<const char *, char *> ret =
  444|    486|      sse_convert_latin1_to_utf8(buf, len, utf8_output);
  445|    486|  size_t converted_chars = ret.second - utf8_output;
  446|       |
  447|    486|  if (ret.first != buf + len) {
  ------------------
  |  Branch (447:7): [True: 400, False: 86]
  ------------------
  448|    400|    const size_t scalar_converted_chars = scalar::latin1_to_utf8::convert(
  449|    400|        ret.first, len - (ret.first - buf), ret.second);
  450|    400|    converted_chars += scalar_converted_chars;
  451|    400|  }
  452|       |
  453|    486|  return converted_chars;
  454|    486|}
_ZNK7simdutf8westmere14implementation25convert_latin1_to_utf16leEPKcmPDs:
  459|     82|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  460|     82|  std::pair<const char *, char16_t *> ret =
  461|     82|      sse_convert_latin1_to_utf16<endianness::LITTLE>(buf, len, utf16_output);
  462|     82|  if (ret.first == nullptr) {
  ------------------
  |  Branch (462:7): [True: 4, False: 78]
  ------------------
  463|      4|    return 0;
  464|      4|  }
  465|     78|  size_t converted_chars = ret.second - utf16_output;
  466|     78|  if (ret.first != buf + len) {
  ------------------
  |  Branch (466:7): [True: 64, False: 14]
  ------------------
  467|     64|    const size_t scalar_converted_chars =
  468|     64|        scalar::latin1_to_utf16::convert<endianness::LITTLE>(
  469|     64|            ret.first, len - (ret.first - buf), ret.second);
  470|     64|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (470:9): [True: 0, False: 64]
  ------------------
  471|      0|      return 0;
  472|      0|    }
  473|     64|    converted_chars += scalar_converted_chars;
  474|     64|  }
  475|     78|  return converted_chars;
  476|     78|}
_ZNK7simdutf8westmere14implementation25convert_latin1_to_utf16beEPKcmPDs:
  479|    108|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  480|    108|  std::pair<const char *, char16_t *> ret =
  481|    108|      sse_convert_latin1_to_utf16<endianness::BIG>(buf, len, utf16_output);
  482|    108|  if (ret.first == nullptr) {
  ------------------
  |  Branch (482:7): [True: 4, False: 104]
  ------------------
  483|      4|    return 0;
  484|      4|  }
  485|    104|  size_t converted_chars = ret.second - utf16_output;
  486|    104|  if (ret.first != buf + len) {
  ------------------
  |  Branch (486:7): [True: 88, False: 16]
  ------------------
  487|     88|    const size_t scalar_converted_chars =
  488|     88|        scalar::latin1_to_utf16::convert<endianness::BIG>(
  489|     88|            ret.first, len - (ret.first - buf), ret.second);
  490|     88|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (490:9): [True: 0, False: 88]
  ------------------
  491|      0|      return 0;
  492|      0|    }
  493|     88|    converted_chars += scalar_converted_chars;
  494|     88|  }
  495|    104|  return converted_chars;
  496|    104|}
_ZNK7simdutf8westmere14implementation23convert_latin1_to_utf32EPKcmPDi:
  501|    102|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  502|    102|  std::pair<const char *, char32_t *> ret =
  503|    102|      sse_convert_latin1_to_utf32(buf, len, utf32_output);
  504|    102|  if (ret.first == nullptr) {
  ------------------
  |  Branch (504:7): [True: 4, False: 98]
  ------------------
  505|      4|    return 0;
  506|      4|  }
  507|     98|  size_t converted_chars = ret.second - utf32_output;
  508|     98|  if (ret.first != buf + len) {
  ------------------
  |  Branch (508:7): [True: 80, False: 18]
  ------------------
  509|     80|    const size_t scalar_converted_chars = scalar::latin1_to_utf32::convert(
  510|     80|        ret.first, len - (ret.first - buf), ret.second);
  511|     80|    if (scalar_converted_chars == 0) {
  ------------------
  |  Branch (511:9): [True: 0, False: 80]
  ------------------
  512|      0|      return 0;
  513|      0|    }
  514|     80|    converted_chars += scalar_converted_chars;
  515|     80|  }
  516|     98|  return converted_chars;
  517|     98|}
_ZNK7simdutf8westmere14implementation22convert_utf8_to_latin1EPKcmPc:
  522|    716|    const char *buf, size_t len, char *latin1_output) const noexcept {
  523|    716|  utf8_to_latin1::validating_transcoder converter;
  524|    716|  return converter.convert(buf, len, latin1_output);
  525|    716|}
_ZNK7simdutf8westmere14implementation34convert_utf8_to_latin1_with_errorsEPKcmPc:
  528|    670|    const char *buf, size_t len, char *latin1_output) const noexcept {
  529|    670|  utf8_to_latin1::validating_transcoder converter;
  530|    670|  return converter.convert_with_errors(buf, len, latin1_output);
  531|    670|}
_ZNK7simdutf8westmere14implementation23convert_utf8_to_utf16leEPKcmPDs:
  541|    950|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  542|    950|  utf8_to_utf16::validating_transcoder converter;
  543|    950|  return converter.convert<endianness::LITTLE>(buf, len, utf16_output);
  544|    950|}
_ZNK7simdutf8westmere14implementation23convert_utf8_to_utf16beEPKcmPDs:
  547|    974|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  548|    974|  utf8_to_utf16::validating_transcoder converter;
  549|    974|  return converter.convert<endianness::BIG>(buf, len, utf16_output);
  550|    974|}
_ZNK7simdutf8westmere14implementation35convert_utf8_to_utf16le_with_errorsEPKcmPDs:
  553|    782|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  554|    782|  utf8_to_utf16::validating_transcoder converter;
  555|    782|  return converter.convert_with_errors<endianness::LITTLE>(buf, len,
  556|    782|                                                           utf16_output);
  557|    782|}
_ZNK7simdutf8westmere14implementation35convert_utf8_to_utf16be_with_errorsEPKcmPDs:
  560|    902|    const char *buf, size_t len, char16_t *utf16_output) const noexcept {
  561|    902|  utf8_to_utf16::validating_transcoder converter;
  562|    902|  return converter.convert_with_errors<endianness::BIG>(buf, len, utf16_output);
  563|    902|}
_ZNK7simdutf8westmere14implementation29convert_valid_utf8_to_utf16leEPKcmPDs:
  566|    344|    const char *input, size_t size, char16_t *utf16_output) const noexcept {
  567|    344|  return utf8_to_utf16::convert_valid<endianness::LITTLE>(input, size,
  568|    344|                                                          utf16_output);
  569|    344|}
_ZNK7simdutf8westmere14implementation29convert_valid_utf8_to_utf16beEPKcmPDs:
  572|    456|    const char *input, size_t size, char16_t *utf16_output) const noexcept {
  573|    456|  return utf8_to_utf16::convert_valid<endianness::BIG>(input, size,
  574|    456|                                                       utf16_output);
  575|    456|}
_ZNK7simdutf8westmere14implementation21convert_utf8_to_utf32EPKcmPDi:
  580|    950|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  581|    950|  utf8_to_utf32::validating_transcoder converter;
  582|    950|  return converter.convert(buf, len, utf32_output);
  583|    950|}
_ZNK7simdutf8westmere14implementation33convert_utf8_to_utf32_with_errorsEPKcmPDi:
  586|    918|    const char *buf, size_t len, char32_t *utf32_output) const noexcept {
  587|    918|  utf8_to_utf32::validating_transcoder converter;
  588|    918|  return converter.convert_with_errors(buf, len, utf32_output);
  589|    918|}
_ZNK7simdutf8westmere14implementation27convert_valid_utf8_to_utf32EPKcmPDi:
  592|    512|    const char *input, size_t size, char32_t *utf32_output) const noexcept {
  593|    512|  return utf8_to_utf32::convert_valid(input, size, utf32_output);
  594|    512|}
_ZNK7simdutf8westmere14implementation25convert_utf16le_to_latin1EPKDsmPc:
  599|    134|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  600|    134|  std::pair<const char16_t *, char *> ret =
  601|    134|      sse_convert_utf16_to_latin1<endianness::LITTLE>(buf, len, latin1_output);
  602|    134|  if (ret.first == nullptr) {
  ------------------
  |  Branch (602:7): [True: 50, False: 84]
  ------------------
  603|     50|    return 0;
  604|     50|  }
  605|     84|  size_t saved_bytes = ret.second - latin1_output;
  606|       |
  607|     84|  if (ret.first != buf + len) {
  ------------------
  |  Branch (607:7): [True: 68, False: 16]
  ------------------
  608|     68|    const size_t scalar_saved_bytes =
  609|     68|        scalar::utf16_to_latin1::convert<endianness::LITTLE>(
  610|     68|            ret.first, len - (ret.first - buf), ret.second);
  611|     68|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (611:9): [True: 36, False: 32]
  ------------------
  612|     36|      return 0;
  613|     36|    }
  614|     32|    saved_bytes += scalar_saved_bytes;
  615|     32|  }
  616|     48|  return saved_bytes;
  617|     84|}
_ZNK7simdutf8westmere14implementation25convert_utf16be_to_latin1EPKDsmPc:
  620|    116|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  621|    116|  std::pair<const char16_t *, char *> ret =
  622|    116|      sse_convert_utf16_to_latin1<endianness::BIG>(buf, len, latin1_output);
  623|    116|  if (ret.first == nullptr) {
  ------------------
  |  Branch (623:7): [True: 36, False: 80]
  ------------------
  624|     36|    return 0;
  625|     36|  }
  626|     80|  size_t saved_bytes = ret.second - latin1_output;
  627|       |
  628|     80|  if (ret.first != buf + len) {
  ------------------
  |  Branch (628:7): [True: 62, False: 18]
  ------------------
  629|     62|    const size_t scalar_saved_bytes =
  630|     62|        scalar::utf16_to_latin1::convert<endianness::BIG>(
  631|     62|            ret.first, len - (ret.first - buf), ret.second);
  632|     62|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (632:9): [True: 34, False: 28]
  ------------------
  633|     34|      return 0;
  634|     34|    }
  635|     28|    saved_bytes += scalar_saved_bytes;
  636|     28|  }
  637|     46|  return saved_bytes;
  638|     80|}
_ZNK7simdutf8westmere14implementation37convert_utf16le_to_latin1_with_errorsEPKDsmPc:
  642|    264|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  643|    264|  std::pair<result, char *> ret =
  644|    264|      sse_convert_utf16_to_latin1_with_errors<endianness::LITTLE>(
  645|    264|          buf, len, latin1_output);
  646|    264|  if (ret.first.error) {
  ------------------
  |  Branch (646:7): [True: 136, False: 128]
  ------------------
  647|    136|    return ret.first;
  648|    136|  } // Can return directly since scalar fallback already found correct
  649|       |    // ret.first.count
  650|    128|  if (ret.first.count != len) { // All good so far, but not finished
  ------------------
  |  Branch (650:7): [True: 86, False: 42]
  ------------------
  651|     86|    result scalar_res =
  652|     86|        scalar::utf16_to_latin1::convert_with_errors<endianness::LITTLE>(
  653|     86|            buf + ret.first.count, len - ret.first.count, ret.second);
  654|     86|    if (scalar_res.error) {
  ------------------
  |  Branch (654:9): [True: 38, False: 48]
  ------------------
  655|     38|      scalar_res.count += ret.first.count;
  656|     38|      return scalar_res;
  657|     48|    } else {
  658|     48|      ret.second += scalar_res.count;
  659|     48|    }
  660|     86|  }
  661|     90|  ret.first.count =
  662|     90|      ret.second -
  663|     90|      latin1_output; // Set count to the number of 8-bit code units written
  664|     90|  return ret.first;
  665|    128|}
_ZNK7simdutf8westmere14implementation37convert_utf16be_to_latin1_with_errorsEPKDsmPc:
  669|    248|    const char16_t *buf, size_t len, char *latin1_output) const noexcept {
  670|    248|  std::pair<result, char *> ret =
  671|    248|      sse_convert_utf16_to_latin1_with_errors<endianness::BIG>(buf, len,
  672|    248|                                                               latin1_output);
  673|    248|  if (ret.first.error) {
  ------------------
  |  Branch (673:7): [True: 138, False: 110]
  ------------------
  674|    138|    return ret.first;
  675|    138|  } // Can return directly since scalar fallback already found correct
  676|       |    // ret.first.count
  677|    110|  if (ret.first.count != len) { // All good so far, but not finished
  ------------------
  |  Branch (677:7): [True: 80, False: 30]
  ------------------
  678|     80|    result scalar_res =
  679|     80|        scalar::utf16_to_latin1::convert_with_errors<endianness::BIG>(
  680|     80|            buf + ret.first.count, len - ret.first.count, ret.second);
  681|     80|    if (scalar_res.error) {
  ------------------
  |  Branch (681:9): [True: 26, False: 54]
  ------------------
  682|     26|      scalar_res.count += ret.first.count;
  683|     26|      return scalar_res;
  684|     54|    } else {
  685|     54|      ret.second += scalar_res.count;
  686|     54|    }
  687|     80|  }
  688|     84|  ret.first.count =
  689|     84|      ret.second -
  690|     84|      latin1_output; // Set count to the number of 8-bit code units written
  691|     84|  return ret.first;
  692|    110|}
_ZNK7simdutf8westmere14implementation23convert_utf16le_to_utf8EPKDsmPc:
  709|    878|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  710|    878|  std::pair<const char16_t *, char *> ret =
  711|    878|      sse_convert_utf16_to_utf8<endianness::LITTLE>(buf, len, utf8_output);
  712|    878|  if (ret.first == nullptr) {
  ------------------
  |  Branch (712:7): [True: 130, False: 748]
  ------------------
  713|    130|    return 0;
  714|    130|  }
  715|    748|  size_t saved_bytes = ret.second - utf8_output;
  716|    748|  if (ret.first != buf + len) {
  ------------------
  |  Branch (716:7): [True: 746, False: 2]
  ------------------
  717|    746|    const size_t scalar_saved_bytes =
  718|    746|        scalar::utf16_to_utf8::convert<endianness::LITTLE>(
  719|    746|            ret.first, len - (ret.first - buf), ret.second);
  720|    746|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (720:9): [True: 102, False: 644]
  ------------------
  721|    102|      return 0;
  722|    102|    }
  723|    644|    saved_bytes += scalar_saved_bytes;
  724|    644|  }
  725|    646|  return saved_bytes;
  726|    748|}
_ZNK7simdutf8westmere14implementation23convert_utf16be_to_utf8EPKDsmPc:
  729|    810|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  730|    810|  std::pair<const char16_t *, char *> ret =
  731|    810|      sse_convert_utf16_to_utf8<endianness::BIG>(buf, len, utf8_output);
  732|    810|  if (ret.first == nullptr) {
  ------------------
  |  Branch (732:7): [True: 94, False: 716]
  ------------------
  733|     94|    return 0;
  734|     94|  }
  735|    716|  size_t saved_bytes = ret.second - utf8_output;
  736|    716|  if (ret.first != buf + len) {
  ------------------
  |  Branch (736:7): [True: 714, False: 2]
  ------------------
  737|    714|    const size_t scalar_saved_bytes =
  738|    714|        scalar::utf16_to_utf8::convert<endianness::BIG>(
  739|    714|            ret.first, len - (ret.first - buf), ret.second);
  740|    714|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (740:9): [True: 100, False: 614]
  ------------------
  741|    100|      return 0;
  742|    100|    }
  743|    614|    saved_bytes += scalar_saved_bytes;
  744|    614|  }
  745|    616|  return saved_bytes;
  746|    716|}
_ZNK7simdutf8westmere14implementation35convert_utf16le_to_utf8_with_errorsEPKDsmPc:
  770|    712|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  771|    712|  return convert_utf16_to_utf8_with_details<endianness::LITTLE>(buf, len,
  772|    712|                                                                utf8_output);
  773|    712|}
_ZNK7simdutf8westmere14implementation35convert_utf16be_to_utf8_with_errorsEPKDsmPc:
  776|    616|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  777|    616|  return convert_utf16_to_utf8_with_details<endianness::BIG>(buf, len,
  778|    616|                                                             utf8_output);
  779|    616|}
_ZNK7simdutf8westmere14implementation29convert_valid_utf16le_to_utf8EPKDsmPc:
  782|    372|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  783|    372|  return convert_utf16le_to_utf8(buf, len, utf8_output);
  784|    372|}
_ZNK7simdutf8westmere14implementation29convert_valid_utf16be_to_utf8EPKDsmPc:
  787|    416|    const char16_t *buf, size_t len, char *utf8_output) const noexcept {
  788|    416|  return convert_utf16be_to_utf8(buf, len, utf8_output);
  789|    416|}
_ZNK7simdutf8westmere14implementation23convert_utf32_to_latin1EPKDimPc:
  794|    186|    const char32_t *buf, size_t len, char *latin1_output) const noexcept {
  795|    186|  std::pair<const char32_t *, char *> ret =
  796|    186|      sse_convert_utf32_to_latin1(buf, len, latin1_output);
  797|    186|  if (ret.first == nullptr) {
  ------------------
  |  Branch (797:7): [True: 52, False: 134]
  ------------------
  798|     52|    return 0;
  799|     52|  }
  800|    134|  size_t saved_bytes = ret.second - latin1_output;
  801|       |  // if (ret.first != buf + len) {
  802|    134|  if (ret.first < buf + len) {
  ------------------
  |  Branch (802:7): [True: 114, False: 20]
  ------------------
  803|    114|    const size_t scalar_saved_bytes = scalar::utf32_to_latin1::convert(
  804|    114|        ret.first, len - (ret.first - buf), ret.second);
  805|    114|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (805:9): [True: 100, False: 14]
  ------------------
  806|    100|      return 0;
  807|    100|    }
  808|     14|    saved_bytes += scalar_saved_bytes;
  809|     14|  }
  810|     34|  return saved_bytes;
  811|    134|}
_ZNK7simdutf8westmere14implementation35convert_utf32_to_latin1_with_errorsEPKDimPc:
  814|    488|    const char32_t *buf, size_t len, char *latin1_output) const noexcept {
  815|       |  // ret.first.count is always the position in the buffer, not the number of
  816|       |  // code units written even if finished
  817|    488|  std::pair<result, char *> ret =
  818|    488|      westmere::sse_convert_utf32_to_latin1_with_errors(buf, len,
  819|    488|                                                        latin1_output);
  820|    488|  if (ret.first.count != len) {
  ------------------
  |  Branch (820:7): [True: 464, False: 24]
  ------------------
  821|    464|    result scalar_res = scalar::utf32_to_latin1::convert_with_errors(
  822|    464|        buf + ret.first.count, len - ret.first.count, ret.second);
  823|    464|    if (scalar_res.error) {
  ------------------
  |  Branch (823:9): [True: 436, False: 28]
  ------------------
  824|    436|      scalar_res.count += ret.first.count;
  825|    436|      return scalar_res;
  826|    436|    } else {
  827|     28|      ret.second += scalar_res.count;
  828|     28|    }
  829|    464|  }
  830|     52|  ret.first.count =
  831|     52|      ret.second -
  832|     52|      latin1_output; // Set count to the number of 8-bit code units written
  833|     52|  return ret.first;
  834|    488|}
_ZNK7simdutf8westmere14implementation21convert_utf32_to_utf8EPKDimPc:
  845|    908|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  846|    908|  std::pair<const char32_t *, char *> ret =
  847|    908|      sse_convert_utf32_to_utf8(buf, len, utf8_output);
  848|    908|  if (ret.first == nullptr) {
  ------------------
  |  Branch (848:7): [True: 306, False: 602]
  ------------------
  849|    306|    return 0;
  850|    306|  }
  851|    602|  size_t saved_bytes = ret.second - utf8_output;
  852|    602|  if (ret.first != buf + len) {
  ------------------
  |  Branch (852:7): [True: 600, False: 2]
  ------------------
  853|    600|    const size_t scalar_saved_bytes = scalar::utf32_to_utf8::convert(
  854|    600|        ret.first, len - (ret.first - buf), ret.second);
  855|    600|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (855:9): [True: 276, False: 324]
  ------------------
  856|    276|      return 0;
  857|    276|    }
  858|    324|    saved_bytes += scalar_saved_bytes;
  859|    324|  }
  860|    326|  return saved_bytes;
  861|    602|}
_ZNK7simdutf8westmere14implementation33convert_utf32_to_utf8_with_errorsEPKDimPc:
  864|    860|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  865|       |  // ret.first.count is always the position in the buffer, not the number of
  866|       |  // code units written even if finished
  867|    860|  std::pair<result, char *> ret =
  868|    860|      westmere::sse_convert_utf32_to_utf8_with_errors(buf, len, utf8_output);
  869|    860|  if (ret.first.count != len) {
  ------------------
  |  Branch (869:7): [True: 856, False: 4]
  ------------------
  870|    856|    result scalar_res = scalar::utf32_to_utf8::convert_with_errors(
  871|    856|        buf + ret.first.count, len - ret.first.count, ret.second);
  872|    856|    if (scalar_res.error) {
  ------------------
  |  Branch (872:9): [True: 654, False: 202]
  ------------------
  873|    654|      scalar_res.count += ret.first.count;
  874|    654|      return scalar_res;
  875|    654|    } else {
  876|    202|      ret.second += scalar_res.count;
  877|    202|    }
  878|    856|  }
  879|    206|  ret.first.count =
  880|    206|      ret.second -
  881|    206|      utf8_output; // Set count to the number of 8-bit code units written
  882|    206|  return ret.first;
  883|    860|}
_ZNK7simdutf8westmere14implementation24convert_utf16le_to_utf32EPKDsmPDi:
  888|    426|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  889|    426|  std::pair<const char16_t *, char32_t *> ret =
  890|    426|      sse_convert_utf16_to_utf32<endianness::LITTLE>(buf, len, utf32_output);
  891|    426|  if (ret.first == nullptr) {
  ------------------
  |  Branch (891:7): [True: 122, False: 304]
  ------------------
  892|    122|    return 0;
  893|    122|  }
  894|    304|  size_t saved_bytes = ret.second - utf32_output;
  895|    304|  if (ret.first != buf + len) {
  ------------------
  |  Branch (895:7): [True: 244, False: 60]
  ------------------
  896|    244|    const size_t scalar_saved_bytes =
  897|    244|        scalar::utf16_to_utf32::convert<endianness::LITTLE>(
  898|    244|            ret.first, len - (ret.first - buf), ret.second);
  899|    244|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (899:9): [True: 66, False: 178]
  ------------------
  900|     66|      return 0;
  901|     66|    }
  902|    178|    saved_bytes += scalar_saved_bytes;
  903|    178|  }
  904|    238|  return saved_bytes;
  905|    304|}
_ZNK7simdutf8westmere14implementation24convert_utf16be_to_utf32EPKDsmPDi:
  908|    436|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  909|    436|  std::pair<const char16_t *, char32_t *> ret =
  910|    436|      sse_convert_utf16_to_utf32<endianness::BIG>(buf, len, utf32_output);
  911|    436|  if (ret.first == nullptr) {
  ------------------
  |  Branch (911:7): [True: 132, False: 304]
  ------------------
  912|    132|    return 0;
  913|    132|  }
  914|    304|  size_t saved_bytes = ret.second - utf32_output;
  915|    304|  if (ret.first != buf + len) {
  ------------------
  |  Branch (915:7): [True: 250, False: 54]
  ------------------
  916|    250|    const size_t scalar_saved_bytes =
  917|    250|        scalar::utf16_to_utf32::convert<endianness::BIG>(
  918|    250|            ret.first, len - (ret.first - buf), ret.second);
  919|    250|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (919:9): [True: 70, False: 180]
  ------------------
  920|     70|      return 0;
  921|     70|    }
  922|    180|    saved_bytes += scalar_saved_bytes;
  923|    180|  }
  924|    234|  return saved_bytes;
  925|    304|}
_ZNK7simdutf8westmere14implementation36convert_utf16le_to_utf32_with_errorsEPKDsmPDi:
  928|    386|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  929|       |  // ret.first.count is always the position in the buffer, not the number of
  930|       |  // code units written even if finished
  931|    386|  std::pair<result, char32_t *> ret =
  932|    386|      westmere::sse_convert_utf16_to_utf32_with_errors<endianness::LITTLE>(
  933|    386|          buf, len, utf32_output);
  934|    386|  if (ret.first.error) {
  ------------------
  |  Branch (934:7): [True: 128, False: 258]
  ------------------
  935|    128|    return ret.first;
  936|    128|  } // Can return directly since scalar fallback already found correct
  937|       |    // ret.first.count
  938|    258|  if (ret.first.count != len) { // All good so far, but not finished
  ------------------
  |  Branch (938:7): [True: 206, False: 52]
  ------------------
  939|    206|    result scalar_res =
  940|    206|        scalar::utf16_to_utf32::convert_with_errors<endianness::LITTLE>(
  941|    206|            buf + ret.first.count, len - ret.first.count, ret.second);
  942|    206|    if (scalar_res.error) {
  ------------------
  |  Branch (942:9): [True: 70, False: 136]
  ------------------
  943|     70|      scalar_res.count += ret.first.count;
  944|     70|      return scalar_res;
  945|    136|    } else {
  946|    136|      ret.second += scalar_res.count;
  947|    136|    }
  948|    206|  }
  949|    188|  ret.first.count =
  950|    188|      ret.second -
  951|    188|      utf32_output; // Set count to the number of 8-bit code units written
  952|    188|  return ret.first;
  953|    258|}
_ZNK7simdutf8westmere14implementation36convert_utf16be_to_utf32_with_errorsEPKDsmPDi:
  956|    366|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
  957|       |  // ret.first.count is always the position in the buffer, not the number of
  958|       |  // code units written even if finished
  959|    366|  std::pair<result, char32_t *> ret =
  960|    366|      westmere::sse_convert_utf16_to_utf32_with_errors<endianness::BIG>(
  961|    366|          buf, len, utf32_output);
  962|    366|  if (ret.first.error) {
  ------------------
  |  Branch (962:7): [True: 120, False: 246]
  ------------------
  963|    120|    return ret.first;
  964|    120|  } // Can return directly since scalar fallback already found correct
  965|       |    // ret.first.count
  966|    246|  if (ret.first.count != len) { // All good so far, but not finished
  ------------------
  |  Branch (966:7): [True: 206, False: 40]
  ------------------
  967|    206|    result scalar_res =
  968|    206|        scalar::utf16_to_utf32::convert_with_errors<endianness::BIG>(
  969|    206|            buf + ret.first.count, len - ret.first.count, ret.second);
  970|    206|    if (scalar_res.error) {
  ------------------
  |  Branch (970:9): [True: 76, False: 130]
  ------------------
  971|     76|      scalar_res.count += ret.first.count;
  972|     76|      return scalar_res;
  973|    130|    } else {
  974|    130|      ret.second += scalar_res.count;
  975|    130|    }
  976|    206|  }
  977|    170|  ret.first.count =
  978|    170|      ret.second -
  979|    170|      utf32_output; // Set count to the number of 8-bit code units written
  980|    170|  return ret.first;
  981|    246|}
_ZNK7simdutf8westmere14implementation27convert_valid_utf32_to_utf8EPKDimPc:
  986|    194|    const char32_t *buf, size_t len, char *utf8_output) const noexcept {
  987|    194|  return convert_utf32_to_utf8(buf, len, utf8_output);
  988|    194|}
_ZNK7simdutf8westmere14implementation24convert_utf32_to_utf16leEPKDimPDs:
  993|    794|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
  994|    794|  std::pair<const char32_t *, char16_t *> ret =
  995|    794|      sse_convert_utf32_to_utf16<endianness::LITTLE>(buf, len, utf16_output);
  996|    794|  if (ret.first == nullptr) {
  ------------------
  |  Branch (996:7): [True: 58, False: 736]
  ------------------
  997|     58|    return 0;
  998|     58|  }
  999|    736|  size_t saved_bytes = ret.second - utf16_output;
 1000|    736|  if (ret.first != buf + len) {
  ------------------
  |  Branch (1000:7): [True: 732, False: 4]
  ------------------
 1001|    732|    const size_t scalar_saved_bytes =
 1002|    732|        scalar::utf32_to_utf16::convert<endianness::LITTLE>(
 1003|    732|            ret.first, len - (ret.first - buf), ret.second);
 1004|    732|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (1004:9): [True: 314, False: 418]
  ------------------
 1005|    314|      return 0;
 1006|    314|    }
 1007|    418|    saved_bytes += scalar_saved_bytes;
 1008|    418|  }
 1009|    422|  return saved_bytes;
 1010|    736|}
_ZNK7simdutf8westmere14implementation24convert_utf32_to_utf16beEPKDimPDs:
 1013|    652|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
 1014|    652|  std::pair<const char32_t *, char16_t *> ret =
 1015|    652|      sse_convert_utf32_to_utf16<endianness::BIG>(buf, len, utf16_output);
 1016|    652|  if (ret.first == nullptr) {
  ------------------
  |  Branch (1016:7): [True: 66, False: 586]
  ------------------
 1017|     66|    return 0;
 1018|     66|  }
 1019|    586|  size_t saved_bytes = ret.second - utf16_output;
 1020|    586|  if (ret.first != buf + len) {
  ------------------
  |  Branch (1020:7): [True: 584, False: 2]
  ------------------
 1021|    584|    const size_t scalar_saved_bytes =
 1022|    584|        scalar::utf32_to_utf16::convert<endianness::BIG>(
 1023|    584|            ret.first, len - (ret.first - buf), ret.second);
 1024|    584|    if (scalar_saved_bytes == 0) {
  ------------------
  |  Branch (1024:9): [True: 310, False: 274]
  ------------------
 1025|    310|      return 0;
 1026|    310|    }
 1027|    274|    saved_bytes += scalar_saved_bytes;
 1028|    274|  }
 1029|    276|  return saved_bytes;
 1030|    586|}
_ZNK7simdutf8westmere14implementation36convert_utf32_to_utf16le_with_errorsEPKDimPDs:
 1033|    772|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
 1034|       |  // ret.first.count is always the position in the buffer, not the number of
 1035|       |  // code units written even if finished
 1036|    772|  std::pair<result, char16_t *> ret =
 1037|    772|      westmere::sse_convert_utf32_to_utf16_with_errors<endianness::LITTLE>(
 1038|    772|          buf, len, utf16_output);
 1039|    772|  if (ret.first.count != len) {
  ------------------
  |  Branch (1039:7): [True: 748, False: 24]
  ------------------
 1040|    748|    result scalar_res =
 1041|    748|        scalar::utf32_to_utf16::convert_with_errors<endianness::LITTLE>(
 1042|    748|            buf + ret.first.count, len - ret.first.count, ret.second);
 1043|    748|    if (scalar_res.error) {
  ------------------
  |  Branch (1043:9): [True: 596, False: 152]
  ------------------
 1044|    596|      scalar_res.count += ret.first.count;
 1045|    596|      return scalar_res;
 1046|    596|    } else {
 1047|    152|      ret.second += scalar_res.count;
 1048|    152|    }
 1049|    748|  }
 1050|    176|  ret.first.count =
 1051|    176|      ret.second -
 1052|    176|      utf16_output; // Set count to the number of 8-bit code units written
 1053|    176|  return ret.first;
 1054|    772|}
_ZNK7simdutf8westmere14implementation36convert_utf32_to_utf16be_with_errorsEPKDimPDs:
 1057|    678|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
 1058|       |  // ret.first.count is always the position in the buffer, not the number of
 1059|       |  // code units written even if finished
 1060|    678|  std::pair<result, char16_t *> ret =
 1061|    678|      westmere::sse_convert_utf32_to_utf16_with_errors<endianness::BIG>(
 1062|    678|          buf, len, utf16_output);
 1063|    678|  if (ret.first.count != len) {
  ------------------
  |  Branch (1063:7): [True: 658, False: 20]
  ------------------
 1064|    658|    result scalar_res =
 1065|    658|        scalar::utf32_to_utf16::convert_with_errors<endianness::BIG>(
 1066|    658|            buf + ret.first.count, len - ret.first.count, ret.second);
 1067|    658|    if (scalar_res.error) {
  ------------------
  |  Branch (1067:9): [True: 498, False: 160]
  ------------------
 1068|    498|      scalar_res.count += ret.first.count;
 1069|    498|      return scalar_res;
 1070|    498|    } else {
 1071|    160|      ret.second += scalar_res.count;
 1072|    160|    }
 1073|    658|  }
 1074|    180|  ret.first.count =
 1075|    180|      ret.second -
 1076|    180|      utf16_output; // Set count to the number of 8-bit code units written
 1077|    180|  return ret.first;
 1078|    678|}
_ZNK7simdutf8westmere14implementation30convert_valid_utf32_to_utf16leEPKDimPDs:
 1081|    292|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
 1082|    292|  return convert_utf32_to_utf16le(buf, len, utf16_output);
 1083|    292|}
_ZNK7simdutf8westmere14implementation30convert_valid_utf32_to_utf16beEPKDimPDs:
 1086|    136|    const char32_t *buf, size_t len, char16_t *utf16_output) const noexcept {
 1087|    136|  return convert_utf32_to_utf16be(buf, len, utf16_output);
 1088|    136|}
_ZNK7simdutf8westmere14implementation30convert_valid_utf16le_to_utf32EPKDsmPDi:
 1091|    118|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
 1092|    118|  return convert_utf16le_to_utf32(buf, len, utf32_output);
 1093|    118|}
_ZNK7simdutf8westmere14implementation30convert_valid_utf16be_to_utf32EPKDsmPDi:
 1096|    134|    const char16_t *buf, size_t len, char32_t *utf32_output) const noexcept {
 1097|    134|  return convert_utf16be_to_utf32(buf, len, utf32_output);
 1098|    134|}
_ZNK7simdutf8westmere14implementation13count_utf16leEPKDsm:
 1109|  1.42k|    const char16_t *input, size_t length) const noexcept {
 1110|  1.42k|  return utf16::count_code_points<endianness::LITTLE>(input, length);
 1111|  1.42k|}
_ZNK7simdutf8westmere14implementation13count_utf16beEPKDsm:
 1114|  1.33k|    const char16_t *input, size_t length) const noexcept {
 1115|  1.33k|  return utf16::count_code_points<endianness::BIG>(input, length);
 1116|  1.33k|}
_ZNK7simdutf8westmere14implementation10count_utf8EPKcm:
 1121|  4.81k|implementation::count_utf8(const char *input, size_t length) const noexcept {
 1122|  4.81k|  return utf8::count_code_points_bytemask(input, length);
 1123|  4.81k|}
_ZNK7simdutf8westmere14implementation23latin1_length_from_utf8EPKcm:
 1133|    693|    const char *buf, size_t len) const noexcept {
 1134|    693|  return count_utf8(buf, len);
 1135|    693|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16leEPKDsm:
 1140|    808|    const char16_t *input, size_t length) const noexcept {
 1141|    808|  return utf16::utf8_length_from_utf16_bytemask<endianness::LITTLE>(input,
 1142|    808|                                                                    length);
 1143|    808|}
_ZNK7simdutf8westmere14implementation24utf8_length_from_utf16beEPKDsm:
 1146|    732|    const char16_t *input, size_t length) const noexcept {
 1147|    732|  return utf16::utf8_length_from_utf16_bytemask<endianness::BIG>(input, length);
 1148|    732|}
_ZNK7simdutf8westmere14implementation23utf8_length_from_latin1EPKcm:
 1153|    243|    const char *input, size_t len) const noexcept {
 1154|    243|  const uint8_t *str = reinterpret_cast<const uint8_t *>(input);
 1155|    243|  size_t answer = len / sizeof(__m128i) * sizeof(__m128i);
 1156|    243|  size_t i = 0;
 1157|    243|  if (answer >= 2048) { // long strings optimization
  ------------------
  |  Branch (1157:7): [True: 101, False: 142]
  ------------------
 1158|    101|    __m128i two_64bits = _mm_setzero_si128();
 1159|  5.31k|    while (i + sizeof(__m128i) <= len) {
  ------------------
  |  Branch (1159:12): [True: 5.21k, False: 101]
  ------------------
 1160|  5.21k|      __m128i runner = _mm_setzero_si128();
 1161|  5.21k|      size_t iterations = (len - i) / sizeof(__m128i);
 1162|  5.21k|      if (iterations > 255) {
  ------------------
  |  Branch (1162:11): [True: 5.11k, False: 101]
  ------------------
 1163|  5.11k|        iterations = 255;
 1164|  5.11k|      }
 1165|  5.21k|      size_t max_i = i + iterations * sizeof(__m128i) - sizeof(__m128i);
 1166|   329k|      for (; i + 4 * sizeof(__m128i) <= max_i; i += 4 * sizeof(__m128i)) {
  ------------------
  |  Branch (1166:14): [True: 323k, False: 5.21k]
  ------------------
 1167|   323k|        __m128i input1 = _mm_loadu_si128((const __m128i *)(str + i));
 1168|   323k|        __m128i input2 =
 1169|   323k|            _mm_loadu_si128((const __m128i *)(str + i + sizeof(__m128i)));
 1170|   323k|        __m128i input3 =
 1171|   323k|            _mm_loadu_si128((const __m128i *)(str + i + 2 * sizeof(__m128i)));
 1172|   323k|        __m128i input4 =
 1173|   323k|            _mm_loadu_si128((const __m128i *)(str + i + 3 * sizeof(__m128i)));
 1174|   323k|        __m128i input12 =
 1175|   323k|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input1),
 1176|   323k|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input2));
 1177|   323k|        __m128i input34 =
 1178|   323k|            _mm_add_epi8(_mm_cmpgt_epi8(_mm_setzero_si128(), input3),
 1179|   323k|                         _mm_cmpgt_epi8(_mm_setzero_si128(), input4));
 1180|   323k|        __m128i input1234 = _mm_add_epi8(input12, input34);
 1181|   323k|        runner = _mm_sub_epi8(runner, input1234);
 1182|   323k|      }
 1183|  20.7k|      for (; i <= max_i; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1183:14): [True: 15.5k, False: 5.21k]
  ------------------
 1184|  15.5k|        __m128i more_input = _mm_loadu_si128((const __m128i *)(str + i));
 1185|  15.5k|        runner = _mm_sub_epi8(runner,
 1186|  15.5k|                              _mm_cmpgt_epi8(_mm_setzero_si128(), more_input));
 1187|  15.5k|      }
 1188|  5.21k|      two_64bits =
 1189|  5.21k|          _mm_add_epi64(two_64bits, _mm_sad_epu8(runner, _mm_setzero_si128()));
 1190|  5.21k|    }
 1191|    101|    answer +=
 1192|    101|        _mm_extract_epi64(two_64bits, 0) + _mm_extract_epi64(two_64bits, 1);
 1193|    142|  } else if (answer > 0) { // short string optimization
  ------------------
  |  Branch (1193:14): [True: 89, False: 53]
  ------------------
 1194|    759|    for (; i + 2 * sizeof(__m128i) <= len; i += 2 * sizeof(__m128i)) {
  ------------------
  |  Branch (1194:12): [True: 670, False: 89]
  ------------------
 1195|    670|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1196|    670|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1197|    670|      answer += count_ones(non_ascii);
 1198|    670|      latin = _mm_loadu_si128((const __m128i *)(input + i) + 1);
 1199|    670|      non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1200|    670|      answer += count_ones(non_ascii);
 1201|    670|    }
 1202|    133|    for (; i + sizeof(__m128i) <= len; i += sizeof(__m128i)) {
  ------------------
  |  Branch (1202:12): [True: 44, False: 89]
  ------------------
 1203|     44|      __m128i latin = _mm_loadu_si128((const __m128i *)(input + i));
 1204|     44|      uint16_t non_ascii = (uint16_t)_mm_movemask_epi8(latin);
 1205|     44|      answer += count_ones(non_ascii);
 1206|     44|    }
 1207|     89|  }
 1208|    243|  return answer + scalar::latin1::utf8_length_from_latin1(
 1209|    243|                      reinterpret_cast<const char *>(str + i), len - i);
 1210|    243|}
_ZNK7simdutf8westmere14implementation25utf32_length_from_utf16leEPKDsm:
 1215|    413|    const char16_t *input, size_t length) const noexcept {
 1216|    413|  return utf16::utf32_length_from_utf16<endianness::LITTLE>(input, length);
 1217|    413|}
_ZNK7simdutf8westmere14implementation25utf32_length_from_utf16beEPKDsm:
 1220|    420|    const char16_t *input, size_t length) const noexcept {
 1221|    420|  return utf16::utf32_length_from_utf16<endianness::BIG>(input, length);
 1222|    420|}
_ZNK7simdutf8westmere14implementation22utf16_length_from_utf8EPKcm:
 1227|  2.22k|    const char *input, size_t length) const noexcept {
 1228|  2.22k|  return utf8::utf16_length_from_utf8_bytemask(input, length);
 1229|  2.22k|}
_ZNK7simdutf8westmere14implementation22utf8_length_from_utf32EPKDim:
 1268|    892|    const char32_t *input, size_t length) const noexcept {
 1269|    892|  return utf32::utf8_length_from_utf32(input, length);
 1270|    892|}
_ZNK7simdutf8westmere14implementation23utf16_length_from_utf32EPKDim:
 1275|  1.45k|    const char32_t *input, size_t length) const noexcept {
 1276|  1.45k|  const __m128i v_00000000 = _mm_setzero_si128();
 1277|  1.45k|  const __m128i v_ffff0000 = _mm_set1_epi32((uint32_t)0xffff0000);
 1278|  1.45k|  size_t pos = 0;
 1279|  1.45k|  size_t count = 0;
 1280|   966k|  for (; pos + 4 <= length; pos += 4) {
  ------------------
  |  Branch (1280:10): [True: 965k, False: 1.45k]
  ------------------
 1281|   965k|    __m128i in = _mm_loadu_si128((__m128i *)(input + pos));
 1282|   965k|    const __m128i surrogate_bytemask =
 1283|   965k|        _mm_cmpeq_epi32(_mm_and_si128(in, v_ffff0000), v_00000000);
 1284|   965k|    const uint16_t surrogate_bitmask =
 1285|   965k|        static_cast<uint16_t>(_mm_movemask_epi8(surrogate_bytemask));
 1286|   965k|    size_t surrogate_count = (16 - count_ones(surrogate_bitmask)) / 4;
 1287|   965k|    count += 4 + surrogate_count;
 1288|   965k|  }
 1289|  1.45k|  return count +
 1290|  1.45k|         scalar::utf32::utf16_length_from_utf32(input + pos, length - pos);
 1291|  1.45k|}
_ZNK7simdutf8westmere14implementation22utf32_length_from_utf8EPKcm:
 1296|  1.20k|    const char *input, size_t length) const noexcept {
 1297|  1.20k|  return utf8::count_code_points(input, length);
 1298|  1.20k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_18is_asciiERKNS1_4simd8simd8x64IhEE:
   13|  5.20M|simdutf_really_inline bool is_ascii(const simd8x64<uint8_t> &input) {
   14|  5.20M|  return input.reduce_or().is_ascii();
   15|  5.20M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_124must_be_2_3_continuationENS1_4simd5simd8IhEES4_:
   22|  7.01M|                         const simd8<uint8_t> prev3) {
   23|  7.01M|  simd8<uint8_t> is_third_byte =
   24|  7.01M|      prev2.saturating_sub(0xe0u - 0x80); // Only 111_____ will be >= 0x80
   25|  7.01M|  simd8<uint8_t> is_fourth_byte =
   26|  7.01M|      prev3.saturating_sub(0xf0u - 0x80); // Only 1111____ will be >= 0x80
   27|  7.01M|  return simd8<bool>(is_third_byte | is_fourth_byte);
   28|  7.01M|}
_ZN7simdutf8westmere34convert_utf16_to_utf8_with_detailsILNS_10endiannessE0EEENS_11full_resultEPKDsmPc:
  750|    712|    const char16_t *buf, size_t len, char *utf8_output) {
  751|    712|  std::pair<result, char *> ret =
  752|    712|      westmere::sse_convert_utf16_to_utf8_with_errors<big_endian>(buf, len,
  753|    712|                                                                  utf8_output);
  754|    712|  if (ret.first.error) {
  ------------------
  |  Branch (754:7): [True: 130, False: 582]
  ------------------
  755|    130|    return full_result(ret.first.error, ret.first.count,
  756|    130|                       size_t(ret.second - utf8_output));
  757|    130|  }
  758|    582|  if (ret.first.count != len) {
  ------------------
  |  Branch (758:7): [True: 578, False: 4]
  ------------------
  759|    578|    full_result sres =
  760|    578|        scalar::utf16_to_utf8::convert_with_errors<big_endian, false>(
  761|    578|            buf + ret.first.count, len - ret.first.count, ret.second, 0);
  762|    578|    return full_result(sres.error, ret.first.count + sres.input_count,
  763|    578|                       size_t(ret.second - utf8_output) + sres.output_count);
  764|    578|  }
  765|      4|  return full_result(error_code::SUCCESS, len,
  766|      4|                     size_t(ret.second - utf8_output));
  767|    582|}
_ZN7simdutf8westmere34convert_utf16_to_utf8_with_detailsILNS_10endiannessE1EEENS_11full_resultEPKDsmPc:
  750|    616|    const char16_t *buf, size_t len, char *utf8_output) {
  751|    616|  std::pair<result, char *> ret =
  752|    616|      westmere::sse_convert_utf16_to_utf8_with_errors<big_endian>(buf, len,
  753|    616|                                                                  utf8_output);
  754|    616|  if (ret.first.error) {
  ------------------
  |  Branch (754:7): [True: 128, False: 488]
  ------------------
  755|    128|    return full_result(ret.first.error, ret.first.count,
  756|    128|                       size_t(ret.second - utf8_output));
  757|    128|  }
  758|    488|  if (ret.first.count != len) {
  ------------------
  |  Branch (758:7): [True: 484, False: 4]
  ------------------
  759|    484|    full_result sres =
  760|    484|        scalar::utf16_to_utf8::convert_with_errors<big_endian, false>(
  761|    484|            buf + ret.first.count, len - ret.first.count, ret.second, 0);
  762|    484|    return full_result(sres.error, ret.first.count + sres.input_count,
  763|    484|                       size_t(ret.second - utf8_output) + sres.output_count);
  764|    484|  }
  765|      4|  return full_result(error_code::SUCCESS, len,
  766|      4|                     size_t(ret.second - utf8_output));
  767|    488|}

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

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

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

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

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_127sse_convert_utf16_to_latin1ILNS_10endiannessE0EEENSt3__14pairIPKDsPcEES7_mS8_:
    4|    134|                            char *latin1_output) {
    5|    134|  const char16_t *end = buf + len;
    6|   156k|  while (end - buf >= 8) {
  ------------------
  |  Branch (6:10): [True: 156k, False: 88]
  ------------------
    7|       |    // Load 8 UTF-16 characters into 128-bit SSE register
    8|   156k|    __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|   156k|    __m128i high_byte_mask = _mm_set1_epi16((int16_t)0xFF00);
   17|   156k|    if (_mm_testz_si128(in, high_byte_mask)) {
  ------------------
  |  Branch (17:9): [True: 156k, False: 46]
  ------------------
   18|       |      // Pack 16-bit characters into 8-bit and store in latin1_output
   19|   156k|      __m128i latin1_packed = _mm_packus_epi16(in, in);
   20|   156k|      _mm_storel_epi64(reinterpret_cast<__m128i *>(latin1_output),
   21|   156k|                       latin1_packed);
   22|       |      // Adjust pointers for next iteration
   23|   156k|      buf += 8;
   24|   156k|      latin1_output += 8;
   25|   156k|    } else {
   26|     46|      return std::make_pair(nullptr, reinterpret_cast<char *>(latin1_output));
   27|     46|    }
   28|   156k|  } // while
   29|     88|  return std::make_pair(buf, latin1_output);
   30|    134|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_127sse_convert_utf16_to_latin1ILNS_10endiannessE1EEENSt3__14pairIPKDsPcEES7_mS8_:
    4|    116|                            char *latin1_output) {
    5|    116|  const char16_t *end = buf + len;
    6|  3.96k|  while (end - buf >= 8) {
  ------------------
  |  Branch (6:10): [True: 3.88k, False: 84]
  ------------------
    7|       |    // Load 8 UTF-16 characters into 128-bit SSE register
    8|  3.88k|    __m128i in = _mm_loadu_si128(reinterpret_cast<const __m128i *>(buf));
    9|       |
   10|  3.88k|    if constexpr (!match_system(big_endian)) {
   11|  3.88k|      const __m128i swap =
   12|  3.88k|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   13|  3.88k|      in = _mm_shuffle_epi8(in, swap);
   14|  3.88k|    }
   15|       |
   16|  3.88k|    __m128i high_byte_mask = _mm_set1_epi16((int16_t)0xFF00);
   17|  3.88k|    if (_mm_testz_si128(in, high_byte_mask)) {
  ------------------
  |  Branch (17:9): [True: 3.85k, False: 32]
  ------------------
   18|       |      // Pack 16-bit characters into 8-bit and store in latin1_output
   19|  3.85k|      __m128i latin1_packed = _mm_packus_epi16(in, in);
   20|  3.85k|      _mm_storel_epi64(reinterpret_cast<__m128i *>(latin1_output),
   21|  3.85k|                       latin1_packed);
   22|       |      // Adjust pointers for next iteration
   23|  3.85k|      buf += 8;
   24|  3.85k|      latin1_output += 8;
   25|  3.85k|    } else {
   26|     32|      return std::make_pair(nullptr, reinterpret_cast<char *>(latin1_output));
   27|     32|    }
   28|  3.88k|  } // while
   29|     84|  return std::make_pair(buf, latin1_output);
   30|    116|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_139sse_convert_utf16_to_latin1_with_errorsILNS_10endiannessE0EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
   35|    264|                                        char *latin1_output) {
   36|    264|  const char16_t *start = buf;
   37|    264|  const char16_t *end = buf + len;
   38|   903k|  while (end - buf >= 8) {
  ------------------
  |  Branch (38:10): [True: 903k, False: 128]
  ------------------
   39|   903k|    __m128i in = _mm_loadu_si128(reinterpret_cast<const __m128i *>(buf));
   40|       |
   41|       |    if constexpr (!match_system(big_endian)) {
   42|       |      const __m128i swap =
   43|       |          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   44|       |      in = _mm_shuffle_epi8(in, swap);
   45|       |    }
   46|       |
   47|   903k|    __m128i high_byte_mask = _mm_set1_epi16((int16_t)0xFF00);
   48|   903k|    if (_mm_testz_si128(in, high_byte_mask)) {
  ------------------
  |  Branch (48:9): [True: 903k, False: 136]
  ------------------
   49|   903k|      __m128i latin1_packed = _mm_packus_epi16(in, in);
   50|   903k|      _mm_storel_epi64(reinterpret_cast<__m128i *>(latin1_output),
   51|   903k|                       latin1_packed);
   52|   903k|      buf += 8;
   53|   903k|      latin1_output += 8;
   54|   903k|    } else {
   55|       |      // Fallback to scalar code for handling errors
   56|    440|      for (int k = 0; k < 8; k++) {
  ------------------
  |  Branch (56:23): [True: 440, False: 0]
  ------------------
   57|    440|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
   58|    440|        if (word <= 0xff) {
  ------------------
  |  Branch (58:13): [True: 304, False: 136]
  ------------------
   59|    304|          *latin1_output++ = char(word);
   60|    304|        } else {
   61|    136|          return std::make_pair(result(error_code::TOO_LARGE, buf - start + k),
   62|    136|                                latin1_output);
   63|    136|        }
   64|    440|      }
   65|      0|      buf += 8;
   66|      0|    }
   67|   903k|  } // while
   68|    128|  return std::make_pair(result(error_code::SUCCESS, buf - start),
   69|    128|                        latin1_output);
   70|    264|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_139sse_convert_utf16_to_latin1_with_errorsILNS_10endiannessE1EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
   35|    248|                                        char *latin1_output) {
   36|    248|  const char16_t *start = buf;
   37|    248|  const char16_t *end = buf + len;
   38|   914k|  while (end - buf >= 8) {
  ------------------
  |  Branch (38:10): [True: 914k, False: 110]
  ------------------
   39|   914k|    __m128i in = _mm_loadu_si128(reinterpret_cast<const __m128i *>(buf));
   40|       |
   41|   914k|    if constexpr (!match_system(big_endian)) {
   42|   914k|      const __m128i swap =
   43|   914k|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   44|   914k|      in = _mm_shuffle_epi8(in, swap);
   45|   914k|    }
   46|       |
   47|   914k|    __m128i high_byte_mask = _mm_set1_epi16((int16_t)0xFF00);
   48|   914k|    if (_mm_testz_si128(in, high_byte_mask)) {
  ------------------
  |  Branch (48:9): [True: 914k, False: 138]
  ------------------
   49|   914k|      __m128i latin1_packed = _mm_packus_epi16(in, in);
   50|   914k|      _mm_storel_epi64(reinterpret_cast<__m128i *>(latin1_output),
   51|   914k|                       latin1_packed);
   52|   914k|      buf += 8;
   53|   914k|      latin1_output += 8;
   54|   914k|    } else {
   55|       |      // Fallback to scalar code for handling errors
   56|    486|      for (int k = 0; k < 8; k++) {
  ------------------
  |  Branch (56:23): [True: 486, False: 0]
  ------------------
   57|    486|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
   58|    486|        if (word <= 0xff) {
  ------------------
  |  Branch (58:13): [True: 348, False: 138]
  ------------------
   59|    348|          *latin1_output++ = char(word);
   60|    348|        } else {
   61|    138|          return std::make_pair(result(error_code::TOO_LARGE, buf - start + k),
   62|    138|                                latin1_output);
   63|    138|        }
   64|    486|      }
   65|      0|      buf += 8;
   66|      0|    }
   67|   914k|  } // while
   68|    110|  return std::make_pair(result(error_code::SUCCESS, buf - start),
   69|    110|                        latin1_output);
   70|    248|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_126sse_convert_utf16_to_utf32ILNS_10endiannessE0EEENSt3__14pairIPKDsPDiEES7_mS8_:
   57|    426|                           char32_t *utf32_output) {
   58|    426|  const char16_t *end = buf + len;
   59|       |
   60|    426|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
   61|    426|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
   62|       |
   63|   629k|  while (end - buf >= 8) {
  ------------------
  |  Branch (63:10): [True: 629k, False: 310]
  ------------------
   64|   629k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
   65|       |
   66|   629k|    if (big_endian) {
  ------------------
  |  Branch (66:9): [Folded, False: 629k]
  ------------------
   67|      0|      const __m128i swap =
   68|      0|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   69|      0|      in = _mm_shuffle_epi8(in, swap);
   70|      0|    }
   71|       |
   72|       |    // 1. Check if there are any surrogate word in the input chunk.
   73|       |    //    We have also deal with situation when there is a surrogate word
   74|       |    //    at the end of a chunk.
   75|   629k|    const __m128i surrogates_bytemask =
   76|   629k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_d800);
   77|       |
   78|       |    // bitmask = 0x0000 if there are no surrogates
   79|       |    //         = 0xc000 if the last word is a surrogate
   80|   629k|    const uint16_t surrogates_bitmask =
   81|   629k|        static_cast<uint16_t>(_mm_movemask_epi8(surrogates_bytemask));
   82|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
   83|       |    // However, it is likely an uncommon occurrence.
   84|   629k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (84:9): [True: 604k, False: 24.2k]
  ------------------
   85|       |      // case: no surrogate pair, extend 16-bit code units to 32-bit code units
   86|   604k|      _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output),
   87|   604k|                       _mm_cvtepu16_epi32(in));
   88|   604k|      _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 4),
   89|   604k|                       _mm_cvtepu16_epi32(_mm_srli_si128(in, 8)));
   90|   604k|      utf32_output += 8;
   91|   604k|      buf += 8;
   92|       |      // surrogate pair(s) in a register
   93|   604k|    } else {
   94|       |      // Let us do a scalar fallback.
   95|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
   96|       |      // in the presence of surrogate pairs may require non-trivial tables.
   97|  24.2k|      size_t forward = 15;
   98|  24.2k|      size_t k = 0;
   99|  24.2k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (99:11): [True: 92, False: 24.1k]
  ------------------
  100|     92|        forward = size_t(end - buf - 1);
  101|     92|      }
  102|   358k|      for (; k < forward; k++) {
  ------------------
  |  Branch (102:14): [True: 334k, False: 24.0k]
  ------------------
  103|   334k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  104|   334k|        if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (104:13): [True: 307k, False: 27.3k]
  ------------------
  105|   307k|          *utf32_output++ = char32_t(word);
  106|   307k|        } else {
  107|       |          // must be a surrogate pair
  108|  27.3k|          uint16_t diff = uint16_t(word - 0xD800);
  109|  27.3k|          uint16_t next_word =
  110|  27.3k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  111|  27.3k|          k++;
  112|  27.3k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  113|  27.3k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (113:15): [True: 116, False: 27.2k]
  ------------------
  114|    116|            return std::make_pair(nullptr, utf32_output);
  115|    116|          }
  116|  27.2k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  117|  27.2k|          *utf32_output++ = char32_t(value);
  118|  27.2k|        }
  119|   334k|      }
  120|  24.0k|      buf += k;
  121|  24.0k|    }
  122|   629k|  } // while
  123|    310|  return std::make_pair(buf, utf32_output);
  124|    426|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_126sse_convert_utf16_to_utf32ILNS_10endiannessE1EEENSt3__14pairIPKDsPDiEES7_mS8_:
   57|    436|                           char32_t *utf32_output) {
   58|    436|  const char16_t *end = buf + len;
   59|       |
   60|    436|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
   61|    436|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
   62|       |
   63|   493k|  while (end - buf >= 8) {
  ------------------
  |  Branch (63:10): [True: 493k, False: 308]
  ------------------
   64|   493k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
   65|       |
   66|   493k|    if (big_endian) {
  ------------------
  |  Branch (66:9): [True: 493k, Folded]
  ------------------
   67|   493k|      const __m128i swap =
   68|   493k|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   69|   493k|      in = _mm_shuffle_epi8(in, swap);
   70|   493k|    }
   71|       |
   72|       |    // 1. Check if there are any surrogate word in the input chunk.
   73|       |    //    We have also deal with situation when there is a surrogate word
   74|       |    //    at the end of a chunk.
   75|   493k|    const __m128i surrogates_bytemask =
   76|   493k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_d800);
   77|       |
   78|       |    // bitmask = 0x0000 if there are no surrogates
   79|       |    //         = 0xc000 if the last word is a surrogate
   80|   493k|    const uint16_t surrogates_bitmask =
   81|   493k|        static_cast<uint16_t>(_mm_movemask_epi8(surrogates_bytemask));
   82|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
   83|       |    // However, it is likely an uncommon occurrence.
   84|   493k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (84:9): [True: 491k, False: 1.65k]
  ------------------
   85|       |      // case: no surrogate pair, extend 16-bit code units to 32-bit code units
   86|   491k|      _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output),
   87|   491k|                       _mm_cvtepu16_epi32(in));
   88|   491k|      _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 4),
   89|   491k|                       _mm_cvtepu16_epi32(_mm_srli_si128(in, 8)));
   90|   491k|      utf32_output += 8;
   91|   491k|      buf += 8;
   92|       |      // surrogate pair(s) in a register
   93|   491k|    } else {
   94|       |      // Let us do a scalar fallback.
   95|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
   96|       |      // in the presence of surrogate pairs may require non-trivial tables.
   97|  1.65k|      size_t forward = 15;
   98|  1.65k|      size_t k = 0;
   99|  1.65k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (99:11): [True: 98, False: 1.55k]
  ------------------
  100|     98|        forward = size_t(end - buf - 1);
  101|     98|      }
  102|  22.6k|      for (; k < forward; k++) {
  ------------------
  |  Branch (102:14): [True: 21.1k, False: 1.52k]
  ------------------
  103|  21.1k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  104|  21.1k|        if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (104:13): [True: 18.9k, False: 2.20k]
  ------------------
  105|  18.9k|          *utf32_output++ = char32_t(word);
  106|  18.9k|        } else {
  107|       |          // must be a surrogate pair
  108|  2.20k|          uint16_t diff = uint16_t(word - 0xD800);
  109|  2.20k|          uint16_t next_word =
  110|  2.20k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  111|  2.20k|          k++;
  112|  2.20k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  113|  2.20k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (113:15): [True: 128, False: 2.07k]
  ------------------
  114|    128|            return std::make_pair(nullptr, utf32_output);
  115|    128|          }
  116|  2.07k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  117|  2.07k|          *utf32_output++ = char32_t(value);
  118|  2.07k|        }
  119|  21.1k|      }
  120|  1.52k|      buf += k;
  121|  1.52k|    }
  122|   493k|  } // while
  123|    308|  return std::make_pair(buf, utf32_output);
  124|    436|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_138sse_convert_utf16_to_utf32_with_errorsILNS_10endiannessE0EEENSt3__14pairINS_6resultEPDiEEPKDsmS7_:
  136|    386|                                       char32_t *utf32_output) {
  137|    386|  const char16_t *start = buf;
  138|    386|  const char16_t *end = buf + len;
  139|       |
  140|    386|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
  141|    386|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
  142|       |
  143|   352k|  while (end - buf >= 8) {
  ------------------
  |  Branch (143:10): [True: 352k, False: 258]
  ------------------
  144|   352k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
  145|       |
  146|   352k|    if (big_endian) {
  ------------------
  |  Branch (146:9): [Folded, False: 352k]
  ------------------
  147|      0|      const __m128i swap =
  148|      0|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  149|      0|      in = _mm_shuffle_epi8(in, swap);
  150|      0|    }
  151|       |
  152|       |    // 1. Check if there are any surrogate word in the input chunk.
  153|       |    //    We have also deal with situation when there is a surrogate word
  154|       |    //    at the end of a chunk.
  155|   352k|    const __m128i surrogates_bytemask =
  156|   352k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_d800);
  157|       |
  158|       |    // bitmask = 0x0000 if there are no surrogates
  159|       |    //         = 0xc000 if the last word is a surrogate
  160|   352k|    const uint16_t surrogates_bitmask =
  161|   352k|        static_cast<uint16_t>(_mm_movemask_epi8(surrogates_bytemask));
  162|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  163|       |    // However, it is likely an uncommon occurrence.
  164|   352k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (164:9): [True: 344k, False: 7.55k]
  ------------------
  165|       |      // case: no surrogate pair, extend 16-bit code units to 32-bit code units
  166|   344k|      _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output),
  167|   344k|                       _mm_cvtepu16_epi32(in));
  168|   344k|      _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 4),
  169|   344k|                       _mm_cvtepu16_epi32(_mm_srli_si128(in, 8)));
  170|   344k|      utf32_output += 8;
  171|   344k|      buf += 8;
  172|       |      // surrogate pair(s) in a register
  173|   344k|    } else {
  174|       |      // Let us do a scalar fallback.
  175|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  176|       |      // in the presence of surrogate pairs may require non-trivial tables.
  177|  7.55k|      size_t forward = 15;
  178|  7.55k|      size_t k = 0;
  179|  7.55k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (179:11): [True: 88, False: 7.46k]
  ------------------
  180|     88|        forward = size_t(end - buf - 1);
  181|     88|      }
  182|   107k|      for (; k < forward; k++) {
  ------------------
  |  Branch (182:14): [True: 100k, False: 7.42k]
  ------------------
  183|   100k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  184|   100k|        if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (184:13): [True: 87.5k, False: 12.4k]
  ------------------
  185|  87.5k|          *utf32_output++ = char32_t(word);
  186|  87.5k|        } else {
  187|       |          // must be a surrogate pair
  188|  12.4k|          uint16_t diff = uint16_t(word - 0xD800);
  189|  12.4k|          uint16_t next_word =
  190|  12.4k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  191|  12.4k|          k++;
  192|  12.4k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  193|  12.4k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (193:15): [True: 128, False: 12.3k]
  ------------------
  194|    128|            return std::make_pair(
  195|    128|                result(error_code::SURROGATE, buf - start + k - 1),
  196|    128|                utf32_output);
  197|    128|          }
  198|  12.3k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  199|  12.3k|          *utf32_output++ = char32_t(value);
  200|  12.3k|        }
  201|   100k|      }
  202|  7.42k|      buf += k;
  203|  7.42k|    }
  204|   352k|  } // while
  205|    258|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf32_output);
  206|    386|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_138sse_convert_utf16_to_utf32_with_errorsILNS_10endiannessE1EEENSt3__14pairINS_6resultEPDiEEPKDsmS7_:
  136|    366|                                       char32_t *utf32_output) {
  137|    366|  const char16_t *start = buf;
  138|    366|  const char16_t *end = buf + len;
  139|       |
  140|    366|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
  141|    366|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
  142|       |
  143|   376k|  while (end - buf >= 8) {
  ------------------
  |  Branch (143:10): [True: 376k, False: 246]
  ------------------
  144|   376k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
  145|       |
  146|   376k|    if (big_endian) {
  ------------------
  |  Branch (146:9): [True: 376k, Folded]
  ------------------
  147|   376k|      const __m128i swap =
  148|   376k|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  149|   376k|      in = _mm_shuffle_epi8(in, swap);
  150|   376k|    }
  151|       |
  152|       |    // 1. Check if there are any surrogate word in the input chunk.
  153|       |    //    We have also deal with situation when there is a surrogate word
  154|       |    //    at the end of a chunk.
  155|   376k|    const __m128i surrogates_bytemask =
  156|   376k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_d800);
  157|       |
  158|       |    // bitmask = 0x0000 if there are no surrogates
  159|       |    //         = 0xc000 if the last word is a surrogate
  160|   376k|    const uint16_t surrogates_bitmask =
  161|   376k|        static_cast<uint16_t>(_mm_movemask_epi8(surrogates_bytemask));
  162|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  163|       |    // However, it is likely an uncommon occurrence.
  164|   376k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (164:9): [True: 371k, False: 5.28k]
  ------------------
  165|       |      // case: no surrogate pair, extend 16-bit code units to 32-bit code units
  166|   371k|      _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output),
  167|   371k|                       _mm_cvtepu16_epi32(in));
  168|   371k|      _mm_storeu_si128(reinterpret_cast<__m128i *>(utf32_output + 4),
  169|   371k|                       _mm_cvtepu16_epi32(_mm_srli_si128(in, 8)));
  170|   371k|      utf32_output += 8;
  171|   371k|      buf += 8;
  172|       |      // surrogate pair(s) in a register
  173|   371k|    } else {
  174|       |      // Let us do a scalar fallback.
  175|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  176|       |      // in the presence of surrogate pairs may require non-trivial tables.
  177|  5.28k|      size_t forward = 15;
  178|  5.28k|      size_t k = 0;
  179|  5.28k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (179:11): [True: 94, False: 5.19k]
  ------------------
  180|     94|        forward = size_t(end - buf - 1);
  181|     94|      }
  182|  74.9k|      for (; k < forward; k++) {
  ------------------
  |  Branch (182:14): [True: 69.8k, False: 5.16k]
  ------------------
  183|  69.8k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  184|  69.8k|        if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (184:13): [True: 61.2k, False: 8.59k]
  ------------------
  185|  61.2k|          *utf32_output++ = char32_t(word);
  186|  61.2k|        } else {
  187|       |          // must be a surrogate pair
  188|  8.59k|          uint16_t diff = uint16_t(word - 0xD800);
  189|  8.59k|          uint16_t next_word =
  190|  8.59k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  191|  8.59k|          k++;
  192|  8.59k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  193|  8.59k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (193:15): [True: 120, False: 8.47k]
  ------------------
  194|    120|            return std::make_pair(
  195|    120|                result(error_code::SURROGATE, buf - start + k - 1),
  196|    120|                utf32_output);
  197|    120|          }
  198|  8.47k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  199|  8.47k|          *utf32_output++ = char32_t(value);
  200|  8.47k|        }
  201|  69.8k|      }
  202|  5.16k|      buf += k;
  203|  5.16k|    }
  204|   376k|  } // while
  205|    246|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf32_output);
  206|    366|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_125sse_convert_utf16_to_utf8ILNS_10endiannessE0EEENSt3__14pairIPKDsPcEES7_mS8_:
   56|    878|sse_convert_utf16_to_utf8(const char16_t *buf, size_t len, char *utf8_output) {
   57|       |
   58|    878|  const char16_t *end = buf + len;
   59|       |
   60|    878|  const __m128i v_0000 = _mm_setzero_si128();
   61|    878|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
   62|    878|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
   63|    878|  const size_t safety_margin =
   64|    878|      12; // to avoid overruns, see issue
   65|       |          // https://github.com/simdutf/simdutf/issues/92
   66|       |
   67|   952k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (67:10): [True: 951k, False: 754]
  ------------------
   68|   951k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
   69|   951k|    if (big_endian) {
  ------------------
  |  Branch (69:9): [Folded, False: 951k]
  ------------------
   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|   951k|    const __m128i v_ff80 = _mm_set1_epi16((int16_t)0xff80);
   76|   951k|    if (_mm_testz_si128(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (76:9): [True: 769k, False: 182k]
  ------------------
   77|   769k|      __m128i nextin = _mm_loadu_si128((__m128i *)buf + 1);
   78|   769k|      if (big_endian) {
  ------------------
  |  Branch (78:11): [Folded, False: 769k]
  ------------------
   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|   769k|      if (!_mm_testz_si128(nextin, v_ff80)) {
  ------------------
  |  Branch (83:11): [True: 34.1k, False: 734k]
  ------------------
   84|       |        // 1. pack the bytes
   85|       |        // obviously suboptimal.
   86|  34.1k|        const __m128i utf8_packed = _mm_packus_epi16(in, in);
   87|       |        // 2. store (16 bytes)
   88|  34.1k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   89|       |        // 3. adjust pointers
   90|  34.1k|        buf += 8;
   91|  34.1k|        utf8_output += 8;
   92|  34.1k|        in = nextin;
   93|   734k|      } else {
   94|       |        // 1. pack the bytes
   95|       |        // obviously suboptimal.
   96|   734k|        const __m128i utf8_packed = _mm_packus_epi16(in, nextin);
   97|       |        // 2. store (16 bytes)
   98|   734k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   99|       |        // 3. adjust pointers
  100|   734k|        buf += 16;
  101|   734k|        utf8_output += 16;
  102|   734k|        continue; // we are done for this round!
  103|   734k|      }
  104|   769k|    }
  105|       |
  106|       |    // no bits set above 7th bit
  107|   216k|    const __m128i one_byte_bytemask =
  108|   216k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_ff80), v_0000);
  109|   216k|    const uint16_t one_byte_bitmask =
  110|   216k|        static_cast<uint16_t>(_mm_movemask_epi8(one_byte_bytemask));
  111|       |
  112|       |    // no bits set above 11th bit
  113|   216k|    const __m128i one_or_two_bytes_bytemask =
  114|   216k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_0000);
  115|   216k|    const uint16_t one_or_two_bytes_bitmask =
  116|   216k|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  117|       |
  118|   216k|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (118:9): [True: 81.3k, False: 135k]
  ------------------
  119|  81.3k|      internal::westmere::write_v_u16_11bits_to_utf8(
  120|  81.3k|          in, utf8_output, one_byte_bytemask, one_byte_bitmask);
  121|  81.3k|      buf += 8;
  122|  81.3k|      continue;
  123|  81.3k|    }
  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|   135k|    const __m128i surrogates_bytemask =
  129|   135k|        _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|   135k|    const uint16_t surrogates_bitmask =
  134|   135k|        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|   135k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (137:9): [True: 127k, False: 7.27k]
  ------------------
  138|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  139|   127k|      const __m128i dup_even = _mm_setr_epi16(0x0000, 0x0202, 0x0404, 0x0606,
  140|   127k|                                              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|   127k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  170|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  171|   127k|      const __m128i t0 = _mm_shuffle_epi8(in, dup_even);
  172|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  173|   127k|      const __m128i t1 = _mm_and_si128(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  169|   127k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  174|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  175|   127k|      const __m128i t2 = _mm_or_si128(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  169|   127k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  176|       |
  177|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  178|   127k|      const __m128i s0 = _mm_srli_epi16(in, 4);
  179|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  180|   127k|      const __m128i s1 = _mm_and_si128(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  169|   127k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  181|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  182|   127k|      const __m128i s2 = _mm_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  169|   127k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  183|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  184|   127k|      const __m128i s3 = _mm_or_si128(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  169|   127k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  185|   127k|      const __m128i m0 = _mm_andnot_si128(one_or_two_bytes_bytemask,
  186|   127k|                                          simdutf_vec(0b0100000000000000));
  ------------------
  |  |  169|   127k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  187|   127k|      const __m128i s4 = _mm_xor_si128(s3, m0);
  188|   127k|#undef simdutf_vec
  189|       |
  190|       |      // 4. expand code units 16-bit => 32-bit
  191|   127k|      const __m128i out0 = _mm_unpacklo_epi16(t2, s4);
  192|   127k|      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|   127k|      const uint16_t mask =
  196|   127k|          (one_byte_bitmask & 0x5555) | (one_or_two_bytes_bitmask & 0xaaaa);
  197|   127k|      if (mask == 0) {
  ------------------
  |  Branch (197:11): [True: 30.5k, False: 97.2k]
  ------------------
  198|       |        // We only have three-byte code units. Use fast path.
  199|  30.5k|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  200|  30.5k|                                              15, 13, -1, -1, -1, -1);
  201|  30.5k|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  202|  30.5k|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  203|  30.5k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  204|  30.5k|        utf8_output += 12;
  205|  30.5k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  206|  30.5k|        utf8_output += 12;
  207|  30.5k|        buf += 8;
  208|  30.5k|        continue;
  209|  30.5k|      }
  210|  97.2k|      const uint8_t mask0 = uint8_t(mask);
  211|       |
  212|  97.2k|      const uint8_t *row0 =
  213|  97.2k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  214|  97.2k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  215|  97.2k|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  216|       |
  217|  97.2k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  218|       |
  219|  97.2k|      const uint8_t *row1 =
  220|  97.2k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  221|  97.2k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  222|  97.2k|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  223|       |
  224|  97.2k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  225|  97.2k|      utf8_output += row0[0];
  226|  97.2k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  227|  97.2k|      utf8_output += row1[0];
  228|       |
  229|  97.2k|      buf += 8;
  230|       |      // surrogate pair(s) in a register
  231|  97.2k|    } 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|  7.27k|      size_t forward = 15;
  236|  7.27k|      size_t k = 0;
  237|  7.27k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (237:11): [True: 0, False: 7.27k]
  ------------------
  238|      0|        forward = size_t(end - buf - 1);
  239|      0|      }
  240|   105k|      for (; k < forward; k++) {
  ------------------
  |  Branch (240:14): [True: 98.8k, False: 7.14k]
  ------------------
  241|  98.8k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  242|  98.8k|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (242:13): [True: 12.8k, False: 85.9k]
  ------------------
  243|  12.8k|          *utf8_output++ = char(word);
  244|  85.9k|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (244:20): [True: 4.31k, False: 81.6k]
  ------------------
  245|  4.31k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  246|  4.31k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  247|  81.6k|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (247:20): [True: 72.2k, False: 9.36k]
  ------------------
  248|  72.2k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  249|  72.2k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  250|  72.2k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  251|  72.2k|        } else {
  252|       |          // must be a surrogate pair
  253|  9.36k|          uint16_t diff = uint16_t(word - 0xD800);
  254|  9.36k|          uint16_t next_word =
  255|  9.36k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  256|  9.36k|          k++;
  257|  9.36k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  258|  9.36k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (258:15): [True: 124, False: 9.24k]
  ------------------
  259|    124|            return std::make_pair(nullptr, utf8_output);
  260|    124|          }
  261|  9.24k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  262|  9.24k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  263|  9.24k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  264|  9.24k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  265|  9.24k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  266|  9.24k|        }
  267|  98.8k|      }
  268|  7.14k|      buf += k;
  269|  7.14k|    }
  270|   135k|  } // while
  271|       |
  272|    754|  return std::make_pair(buf, utf8_output);
  273|    878|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_125sse_convert_utf16_to_utf8ILNS_10endiannessE1EEENSt3__14pairIPKDsPcEES7_mS8_:
   56|    810|sse_convert_utf16_to_utf8(const char16_t *buf, size_t len, char *utf8_output) {
   57|       |
   58|    810|  const char16_t *end = buf + len;
   59|       |
   60|    810|  const __m128i v_0000 = _mm_setzero_si128();
   61|    810|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
   62|    810|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
   63|    810|  const size_t safety_margin =
   64|    810|      12; // to avoid overruns, see issue
   65|       |          // https://github.com/simdutf/simdutf/issues/92
   66|       |
   67|  1.27M|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (67:10): [True: 1.27M, False: 722]
  ------------------
   68|  1.27M|    __m128i in = _mm_loadu_si128((__m128i *)buf);
   69|  1.27M|    if (big_endian) {
  ------------------
  |  Branch (69:9): [True: 1.27M, Folded]
  ------------------
   70|  1.27M|      const __m128i swap =
   71|  1.27M|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   72|  1.27M|      in = _mm_shuffle_epi8(in, swap);
   73|  1.27M|    }
   74|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
   75|  1.27M|    const __m128i v_ff80 = _mm_set1_epi16((int16_t)0xff80);
   76|  1.27M|    if (_mm_testz_si128(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (76:9): [True: 932k, False: 338k]
  ------------------
   77|   932k|      __m128i nextin = _mm_loadu_si128((__m128i *)buf + 1);
   78|   932k|      if (big_endian) {
  ------------------
  |  Branch (78:11): [True: 932k, Folded]
  ------------------
   79|   932k|        const __m128i swap =
   80|   932k|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   81|   932k|        nextin = _mm_shuffle_epi8(nextin, swap);
   82|   932k|      }
   83|   932k|      if (!_mm_testz_si128(nextin, v_ff80)) {
  ------------------
  |  Branch (83:11): [True: 46.7k, False: 886k]
  ------------------
   84|       |        // 1. pack the bytes
   85|       |        // obviously suboptimal.
   86|  46.7k|        const __m128i utf8_packed = _mm_packus_epi16(in, in);
   87|       |        // 2. store (16 bytes)
   88|  46.7k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   89|       |        // 3. adjust pointers
   90|  46.7k|        buf += 8;
   91|  46.7k|        utf8_output += 8;
   92|  46.7k|        in = nextin;
   93|   886k|      } else {
   94|       |        // 1. pack the bytes
   95|       |        // obviously suboptimal.
   96|   886k|        const __m128i utf8_packed = _mm_packus_epi16(in, nextin);
   97|       |        // 2. store (16 bytes)
   98|   886k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   99|       |        // 3. adjust pointers
  100|   886k|        buf += 16;
  101|   886k|        utf8_output += 16;
  102|   886k|        continue; // we are done for this round!
  103|   886k|      }
  104|   932k|    }
  105|       |
  106|       |    // no bits set above 7th bit
  107|   385k|    const __m128i one_byte_bytemask =
  108|   385k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_ff80), v_0000);
  109|   385k|    const uint16_t one_byte_bitmask =
  110|   385k|        static_cast<uint16_t>(_mm_movemask_epi8(one_byte_bytemask));
  111|       |
  112|       |    // no bits set above 11th bit
  113|   385k|    const __m128i one_or_two_bytes_bytemask =
  114|   385k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_0000);
  115|   385k|    const uint16_t one_or_two_bytes_bitmask =
  116|   385k|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  117|       |
  118|   385k|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (118:9): [True: 47.4k, False: 337k]
  ------------------
  119|  47.4k|      internal::westmere::write_v_u16_11bits_to_utf8(
  120|  47.4k|          in, utf8_output, one_byte_bytemask, one_byte_bitmask);
  121|  47.4k|      buf += 8;
  122|  47.4k|      continue;
  123|  47.4k|    }
  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|   337k|    const __m128i surrogates_bytemask =
  129|   337k|        _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|   337k|    const uint16_t surrogates_bitmask =
  134|   337k|        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|   337k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (137:9): [True: 328k, False: 9.10k]
  ------------------
  138|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  139|   328k|      const __m128i dup_even = _mm_setr_epi16(0x0000, 0x0202, 0x0404, 0x0606,
  140|   328k|                                              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|   328k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  170|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  171|   328k|      const __m128i t0 = _mm_shuffle_epi8(in, dup_even);
  172|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  173|   328k|      const __m128i t1 = _mm_and_si128(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  169|   328k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  174|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  175|   328k|      const __m128i t2 = _mm_or_si128(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  169|   328k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  176|       |
  177|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  178|   328k|      const __m128i s0 = _mm_srli_epi16(in, 4);
  179|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  180|   328k|      const __m128i s1 = _mm_and_si128(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  169|   328k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  181|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  182|   328k|      const __m128i s2 = _mm_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  169|   328k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  183|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  184|   328k|      const __m128i s3 = _mm_or_si128(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  169|   328k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  185|   328k|      const __m128i m0 = _mm_andnot_si128(one_or_two_bytes_bytemask,
  186|   328k|                                          simdutf_vec(0b0100000000000000));
  ------------------
  |  |  169|   328k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  187|   328k|      const __m128i s4 = _mm_xor_si128(s3, m0);
  188|   328k|#undef simdutf_vec
  189|       |
  190|       |      // 4. expand code units 16-bit => 32-bit
  191|   328k|      const __m128i out0 = _mm_unpacklo_epi16(t2, s4);
  192|   328k|      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|   328k|      const uint16_t mask =
  196|   328k|          (one_byte_bitmask & 0x5555) | (one_or_two_bytes_bitmask & 0xaaaa);
  197|   328k|      if (mask == 0) {
  ------------------
  |  Branch (197:11): [True: 120k, False: 207k]
  ------------------
  198|       |        // We only have three-byte code units. Use fast path.
  199|   120k|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  200|   120k|                                              15, 13, -1, -1, -1, -1);
  201|   120k|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  202|   120k|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  203|   120k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  204|   120k|        utf8_output += 12;
  205|   120k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  206|   120k|        utf8_output += 12;
  207|   120k|        buf += 8;
  208|   120k|        continue;
  209|   120k|      }
  210|   207k|      const uint8_t mask0 = uint8_t(mask);
  211|       |
  212|   207k|      const uint8_t *row0 =
  213|   207k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  214|   207k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  215|   207k|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  216|       |
  217|   207k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  218|       |
  219|   207k|      const uint8_t *row1 =
  220|   207k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  221|   207k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  222|   207k|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  223|       |
  224|   207k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  225|   207k|      utf8_output += row0[0];
  226|   207k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  227|   207k|      utf8_output += row1[0];
  228|       |
  229|   207k|      buf += 8;
  230|       |      // surrogate pair(s) in a register
  231|   207k|    } 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|  9.10k|      size_t forward = 15;
  236|  9.10k|      size_t k = 0;
  237|  9.10k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (237:11): [True: 0, False: 9.10k]
  ------------------
  238|      0|        forward = size_t(end - buf - 1);
  239|      0|      }
  240|   134k|      for (; k < forward; k++) {
  ------------------
  |  Branch (240:14): [True: 125k, False: 9.01k]
  ------------------
  241|   125k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  242|   125k|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (242:13): [True: 14.8k, False: 110k]
  ------------------
  243|  14.8k|          *utf8_output++ = char(word);
  244|   110k|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (244:20): [True: 3.01k, False: 107k]
  ------------------
  245|  3.01k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  246|  3.01k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  247|   107k|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (247:20): [True: 97.0k, False: 10.5k]
  ------------------
  248|  97.0k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  249|  97.0k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  250|  97.0k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  251|  97.0k|        } else {
  252|       |          // must be a surrogate pair
  253|  10.5k|          uint16_t diff = uint16_t(word - 0xD800);
  254|  10.5k|          uint16_t next_word =
  255|  10.5k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  256|  10.5k|          k++;
  257|  10.5k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  258|  10.5k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (258:15): [True: 88, False: 10.4k]
  ------------------
  259|     88|            return std::make_pair(nullptr, utf8_output);
  260|     88|          }
  261|  10.4k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  262|  10.4k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  263|  10.4k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  264|  10.4k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  265|  10.4k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  266|  10.4k|        }
  267|   125k|      }
  268|  9.01k|      buf += k;
  269|  9.01k|    }
  270|   337k|  } // while
  271|       |
  272|    722|  return std::make_pair(buf, utf8_output);
  273|    810|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_137sse_convert_utf16_to_utf8_with_errorsILNS_10endiannessE0EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
  285|    712|                                      char *utf8_output) {
  286|    712|  const char16_t *start = buf;
  287|    712|  const char16_t *end = buf + len;
  288|       |
  289|    712|  const __m128i v_0000 = _mm_setzero_si128();
  290|    712|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
  291|    712|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
  292|    712|  const size_t safety_margin =
  293|    712|      12; // to avoid overruns, see issue
  294|       |          // https://github.com/simdutf/simdutf/issues/92
  295|       |
  296|   853k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (296:10): [True: 853k, False: 582]
  ------------------
  297|   853k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
  298|   853k|    if (big_endian) {
  ------------------
  |  Branch (298:9): [Folded, False: 853k]
  ------------------
  299|      0|      const __m128i swap =
  300|      0|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  301|      0|      in = _mm_shuffle_epi8(in, swap);
  302|      0|    }
  303|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
  304|   853k|    const __m128i v_ff80 = _mm_set1_epi16((int16_t)0xff80);
  305|   853k|    if (_mm_testz_si128(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (305:9): [True: 384k, False: 468k]
  ------------------
  306|   384k|      __m128i nextin = _mm_loadu_si128((__m128i *)buf + 1);
  307|   384k|      if (big_endian) {
  ------------------
  |  Branch (307:11): [Folded, False: 384k]
  ------------------
  308|      0|        const __m128i swap =
  309|      0|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  310|      0|        nextin = _mm_shuffle_epi8(nextin, swap);
  311|      0|      }
  312|   384k|      if (!_mm_testz_si128(nextin, v_ff80)) {
  ------------------
  |  Branch (312:11): [True: 20.8k, False: 363k]
  ------------------
  313|       |        // 1. pack the bytes
  314|       |        // obviously suboptimal.
  315|  20.8k|        const __m128i utf8_packed = _mm_packus_epi16(in, in);
  316|       |        // 2. store (16 bytes)
  317|  20.8k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  318|       |        // 3. adjust pointers
  319|  20.8k|        buf += 8;
  320|  20.8k|        utf8_output += 8;
  321|  20.8k|        in = nextin;
  322|   363k|      } else {
  323|       |        // 1. pack the bytes
  324|       |        // obviously suboptimal.
  325|   363k|        const __m128i utf8_packed = _mm_packus_epi16(in, nextin);
  326|       |        // 2. store (16 bytes)
  327|   363k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  328|       |        // 3. adjust pointers
  329|   363k|        buf += 16;
  330|   363k|        utf8_output += 16;
  331|   363k|        continue; // we are done for this round!
  332|   363k|      }
  333|   384k|    }
  334|       |
  335|       |    // no bits set above 7th bit
  336|   489k|    const __m128i one_byte_bytemask =
  337|   489k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_ff80), v_0000);
  338|   489k|    const uint16_t one_byte_bitmask =
  339|   489k|        static_cast<uint16_t>(_mm_movemask_epi8(one_byte_bytemask));
  340|       |
  341|       |    // no bits set above 11th bit
  342|   489k|    const __m128i one_or_two_bytes_bytemask =
  343|   489k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_0000);
  344|   489k|    const uint16_t one_or_two_bytes_bitmask =
  345|   489k|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  346|       |
  347|   489k|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (347:9): [True: 23.0k, False: 466k]
  ------------------
  348|  23.0k|      internal::westmere::write_v_u16_11bits_to_utf8(
  349|  23.0k|          in, utf8_output, one_byte_bytemask, one_byte_bitmask);
  350|  23.0k|      buf += 8;
  351|  23.0k|      continue;
  352|  23.0k|    }
  353|       |
  354|       |    // 1. Check if there are any surrogate word in the input chunk.
  355|       |    //    We have also deal with situation when there is a surrogate word
  356|       |    //    at the end of a chunk.
  357|   466k|    const __m128i surrogates_bytemask =
  358|   466k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_d800);
  359|       |
  360|       |    // bitmask = 0x0000 if there are no surrogates
  361|       |    //         = 0xc000 if the last word is a surrogate
  362|   466k|    const uint16_t surrogates_bitmask =
  363|   466k|        static_cast<uint16_t>(_mm_movemask_epi8(surrogates_bytemask));
  364|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  365|       |    // However, it is likely an uncommon occurrence.
  366|   466k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (366:9): [True: 460k, False: 5.58k]
  ------------------
  367|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  368|   460k|      const __m128i dup_even = _mm_setr_epi16(0x0000, 0x0202, 0x0404, 0x0606,
  369|   460k|                                              0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  370|       |
  371|       |      /* In this branch we handle three cases:
  372|       |         1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  373|       |        single UFT-8 byte
  374|       |         2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              - two
  375|       |        UTF-8 bytes
  376|       |         3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  377|       |        three UTF-8 bytes
  378|       |
  379|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  380|       |        we have room for four bytes. However, we need five distinct bit
  381|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  382|       |
  383|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  384|       |        in register t2.
  385|       |
  386|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  387|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  388|       |        differ by exactly one bit.
  389|       |
  390|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  391|       |        into account the case (i.e, the number of bytes to write).
  392|       |      */
  393|       |      /**
  394|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  395|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  396|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  397|       |       */
  398|   460k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  399|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  400|   460k|      const __m128i t0 = _mm_shuffle_epi8(in, dup_even);
  401|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  402|   460k|      const __m128i t1 = _mm_and_si128(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  398|   460k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  403|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  404|   460k|      const __m128i t2 = _mm_or_si128(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  398|   460k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  405|       |
  406|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  407|   460k|      const __m128i s0 = _mm_srli_epi16(in, 4);
  408|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  409|   460k|      const __m128i s1 = _mm_and_si128(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  398|   460k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  410|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  411|   460k|      const __m128i s2 = _mm_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  398|   460k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  412|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  413|   460k|      const __m128i s3 = _mm_or_si128(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  398|   460k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  414|   460k|      const __m128i m0 = _mm_andnot_si128(one_or_two_bytes_bytemask,
  415|   460k|                                          simdutf_vec(0b0100000000000000));
  ------------------
  |  |  398|   460k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  416|   460k|      const __m128i s4 = _mm_xor_si128(s3, m0);
  417|   460k|#undef simdutf_vec
  418|       |
  419|       |      // 4. expand code units 16-bit => 32-bit
  420|   460k|      const __m128i out0 = _mm_unpacklo_epi16(t2, s4);
  421|   460k|      const __m128i out1 = _mm_unpackhi_epi16(t2, s4);
  422|       |
  423|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  424|   460k|      const uint16_t mask =
  425|   460k|          (one_byte_bitmask & 0x5555) | (one_or_two_bytes_bitmask & 0xaaaa);
  426|   460k|      if (mask == 0) {
  ------------------
  |  Branch (426:11): [True: 333k, False: 126k]
  ------------------
  427|       |        // We only have three-byte code units. Use fast path.
  428|   333k|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  429|   333k|                                              15, 13, -1, -1, -1, -1);
  430|   333k|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  431|   333k|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  432|   333k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  433|   333k|        utf8_output += 12;
  434|   333k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  435|   333k|        utf8_output += 12;
  436|   333k|        buf += 8;
  437|   333k|        continue;
  438|   333k|      }
  439|   126k|      const uint8_t mask0 = uint8_t(mask);
  440|       |
  441|   126k|      const uint8_t *row0 =
  442|   126k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  443|   126k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  444|   126k|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  445|       |
  446|   126k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  447|       |
  448|   126k|      const uint8_t *row1 =
  449|   126k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  450|   126k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  451|   126k|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  452|       |
  453|   126k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  454|   126k|      utf8_output += row0[0];
  455|   126k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  456|   126k|      utf8_output += row1[0];
  457|       |
  458|   126k|      buf += 8;
  459|       |      // surrogate pair(s) in a register
  460|   126k|    } else {
  461|       |      // Let us do a scalar fallback.
  462|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  463|       |      // in the presence of surrogate pairs may require non-trivial tables.
  464|  5.58k|      size_t forward = 15;
  465|  5.58k|      size_t k = 0;
  466|  5.58k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (466:11): [True: 0, False: 5.58k]
  ------------------
  467|      0|        forward = size_t(end - buf - 1);
  468|      0|      }
  469|  81.6k|      for (; k < forward; k++) {
  ------------------
  |  Branch (469:14): [True: 76.2k, False: 5.45k]
  ------------------
  470|  76.2k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  471|  76.2k|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (471:13): [True: 10.1k, False: 66.0k]
  ------------------
  472|  10.1k|          *utf8_output++ = char(word);
  473|  66.0k|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (473:20): [True: 2.52k, False: 63.4k]
  ------------------
  474|  2.52k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  475|  2.52k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  476|  63.4k|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (476:20): [True: 57.1k, False: 6.35k]
  ------------------
  477|  57.1k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  478|  57.1k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  479|  57.1k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  480|  57.1k|        } else {
  481|       |          // must be a surrogate pair
  482|  6.35k|          uint16_t diff = uint16_t(word - 0xD800);
  483|  6.35k|          uint16_t next_word =
  484|  6.35k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  485|  6.35k|          k++;
  486|  6.35k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  487|  6.35k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (487:15): [True: 130, False: 6.22k]
  ------------------
  488|    130|            return std::make_pair(
  489|    130|                result(error_code::SURROGATE, buf - start + k - 1),
  490|    130|                utf8_output);
  491|    130|          }
  492|  6.22k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  493|  6.22k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  494|  6.22k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  495|  6.22k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  496|  6.22k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  497|  6.22k|        }
  498|  76.2k|      }
  499|  5.45k|      buf += k;
  500|  5.45k|    }
  501|   466k|  } // while
  502|       |
  503|    582|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  504|    712|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_137sse_convert_utf16_to_utf8_with_errorsILNS_10endiannessE1EEENSt3__14pairINS_6resultEPcEEPKDsmS7_:
  285|    616|                                      char *utf8_output) {
  286|    616|  const char16_t *start = buf;
  287|    616|  const char16_t *end = buf + len;
  288|       |
  289|    616|  const __m128i v_0000 = _mm_setzero_si128();
  290|    616|  const __m128i v_f800 = _mm_set1_epi16((int16_t)0xf800);
  291|    616|  const __m128i v_d800 = _mm_set1_epi16((int16_t)0xd800);
  292|    616|  const size_t safety_margin =
  293|    616|      12; // to avoid overruns, see issue
  294|       |          // https://github.com/simdutf/simdutf/issues/92
  295|       |
  296|   575k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (296:10): [True: 574k, False: 488]
  ------------------
  297|   574k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
  298|   574k|    if (big_endian) {
  ------------------
  |  Branch (298:9): [True: 574k, Folded]
  ------------------
  299|   574k|      const __m128i swap =
  300|   574k|          _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  301|   574k|      in = _mm_shuffle_epi8(in, swap);
  302|   574k|    }
  303|       |    // a single 16-bit UTF-16 word can yield 1, 2 or 3 UTF-8 bytes
  304|   574k|    const __m128i v_ff80 = _mm_set1_epi16((int16_t)0xff80);
  305|   574k|    if (_mm_testz_si128(in, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (305:9): [True: 369k, False: 205k]
  ------------------
  306|   369k|      __m128i nextin = _mm_loadu_si128((__m128i *)buf + 1);
  307|   369k|      if (big_endian) {
  ------------------
  |  Branch (307:11): [True: 369k, Folded]
  ------------------
  308|   369k|        const __m128i swap =
  309|   369k|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  310|   369k|        nextin = _mm_shuffle_epi8(nextin, swap);
  311|   369k|      }
  312|   369k|      if (!_mm_testz_si128(nextin, v_ff80)) {
  ------------------
  |  Branch (312:11): [True: 35.7k, False: 333k]
  ------------------
  313|       |        // 1. pack the bytes
  314|       |        // obviously suboptimal.
  315|  35.7k|        const __m128i utf8_packed = _mm_packus_epi16(in, in);
  316|       |        // 2. store (16 bytes)
  317|  35.7k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  318|       |        // 3. adjust pointers
  319|  35.7k|        buf += 8;
  320|  35.7k|        utf8_output += 8;
  321|  35.7k|        in = nextin;
  322|   333k|      } else {
  323|       |        // 1. pack the bytes
  324|       |        // obviously suboptimal.
  325|   333k|        const __m128i utf8_packed = _mm_packus_epi16(in, nextin);
  326|       |        // 2. store (16 bytes)
  327|   333k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  328|       |        // 3. adjust pointers
  329|   333k|        buf += 16;
  330|   333k|        utf8_output += 16;
  331|   333k|        continue; // we are done for this round!
  332|   333k|      }
  333|   369k|    }
  334|       |
  335|       |    // no bits set above 7th bit
  336|   241k|    const __m128i one_byte_bytemask =
  337|   241k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_ff80), v_0000);
  338|   241k|    const uint16_t one_byte_bitmask =
  339|   241k|        static_cast<uint16_t>(_mm_movemask_epi8(one_byte_bytemask));
  340|       |
  341|       |    // no bits set above 11th bit
  342|   241k|    const __m128i one_or_two_bytes_bytemask =
  343|   241k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_0000);
  344|   241k|    const uint16_t one_or_two_bytes_bitmask =
  345|   241k|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  346|       |
  347|   241k|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (347:9): [True: 44.6k, False: 196k]
  ------------------
  348|  44.6k|      internal::westmere::write_v_u16_11bits_to_utf8(
  349|  44.6k|          in, utf8_output, one_byte_bytemask, one_byte_bitmask);
  350|  44.6k|      buf += 8;
  351|  44.6k|      continue;
  352|  44.6k|    }
  353|       |
  354|       |    // 1. Check if there are any surrogate word in the input chunk.
  355|       |    //    We have also deal with situation when there is a surrogate word
  356|       |    //    at the end of a chunk.
  357|   196k|    const __m128i surrogates_bytemask =
  358|   196k|        _mm_cmpeq_epi16(_mm_and_si128(in, v_f800), v_d800);
  359|       |
  360|       |    // bitmask = 0x0000 if there are no surrogates
  361|       |    //         = 0xc000 if the last word is a surrogate
  362|   196k|    const uint16_t surrogates_bitmask =
  363|   196k|        static_cast<uint16_t>(_mm_movemask_epi8(surrogates_bytemask));
  364|       |    // It might seem like checking for surrogates_bitmask == 0xc000 could help.
  365|       |    // However, it is likely an uncommon occurrence.
  366|   196k|    if (surrogates_bitmask == 0x0000) {
  ------------------
  |  Branch (366:9): [True: 186k, False: 10.1k]
  ------------------
  367|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  368|   186k|      const __m128i dup_even = _mm_setr_epi16(0x0000, 0x0202, 0x0404, 0x0606,
  369|   186k|                                              0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  370|       |
  371|       |      /* In this branch we handle three cases:
  372|       |         1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  373|       |        single UFT-8 byte
  374|       |         2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              - two
  375|       |        UTF-8 bytes
  376|       |         3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  377|       |        three UTF-8 bytes
  378|       |
  379|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  380|       |        we have room for four bytes. However, we need five distinct bit
  381|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  382|       |
  383|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  384|       |        in register t2.
  385|       |
  386|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  387|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  388|       |        differ by exactly one bit.
  389|       |
  390|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  391|       |        into account the case (i.e, the number of bytes to write).
  392|       |      */
  393|       |      /**
  394|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  395|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  396|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  397|       |       */
  398|   186k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  399|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  400|   186k|      const __m128i t0 = _mm_shuffle_epi8(in, dup_even);
  401|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  402|   186k|      const __m128i t1 = _mm_and_si128(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  398|   186k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  403|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  404|   186k|      const __m128i t2 = _mm_or_si128(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  398|   186k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  405|       |
  406|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  407|   186k|      const __m128i s0 = _mm_srli_epi16(in, 4);
  408|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  409|   186k|      const __m128i s1 = _mm_and_si128(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  398|   186k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  410|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  411|   186k|      const __m128i s2 = _mm_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  398|   186k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  412|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  413|   186k|      const __m128i s3 = _mm_or_si128(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  398|   186k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  414|   186k|      const __m128i m0 = _mm_andnot_si128(one_or_two_bytes_bytemask,
  415|   186k|                                          simdutf_vec(0b0100000000000000));
  ------------------
  |  |  398|   186k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  416|   186k|      const __m128i s4 = _mm_xor_si128(s3, m0);
  417|   186k|#undef simdutf_vec
  418|       |
  419|       |      // 4. expand code units 16-bit => 32-bit
  420|   186k|      const __m128i out0 = _mm_unpacklo_epi16(t2, s4);
  421|   186k|      const __m128i out1 = _mm_unpackhi_epi16(t2, s4);
  422|       |
  423|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  424|   186k|      const uint16_t mask =
  425|   186k|          (one_byte_bitmask & 0x5555) | (one_or_two_bytes_bitmask & 0xaaaa);
  426|   186k|      if (mask == 0) {
  ------------------
  |  Branch (426:11): [True: 104k, False: 82.4k]
  ------------------
  427|       |        // We only have three-byte code units. Use fast path.
  428|   104k|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  429|   104k|                                              15, 13, -1, -1, -1, -1);
  430|   104k|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  431|   104k|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  432|   104k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  433|   104k|        utf8_output += 12;
  434|   104k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  435|   104k|        utf8_output += 12;
  436|   104k|        buf += 8;
  437|   104k|        continue;
  438|   104k|      }
  439|  82.4k|      const uint8_t mask0 = uint8_t(mask);
  440|       |
  441|  82.4k|      const uint8_t *row0 =
  442|  82.4k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  443|  82.4k|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  444|  82.4k|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  445|       |
  446|  82.4k|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  447|       |
  448|  82.4k|      const uint8_t *row1 =
  449|  82.4k|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  450|  82.4k|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  451|  82.4k|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  452|       |
  453|  82.4k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  454|  82.4k|      utf8_output += row0[0];
  455|  82.4k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  456|  82.4k|      utf8_output += row1[0];
  457|       |
  458|  82.4k|      buf += 8;
  459|       |      // surrogate pair(s) in a register
  460|  82.4k|    } else {
  461|       |      // Let us do a scalar fallback.
  462|       |      // It may seem wasteful to use scalar code, but being efficient with SIMD
  463|       |      // in the presence of surrogate pairs may require non-trivial tables.
  464|  10.1k|      size_t forward = 15;
  465|  10.1k|      size_t k = 0;
  466|  10.1k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (466:11): [True: 0, False: 10.1k]
  ------------------
  467|      0|        forward = size_t(end - buf - 1);
  468|      0|      }
  469|   149k|      for (; k < forward; k++) {
  ------------------
  |  Branch (469:14): [True: 139k, False: 9.98k]
  ------------------
  470|   139k|        uint16_t word = scalar::utf16::swap_if_needed<big_endian>(buf[k]);
  471|   139k|        if ((word & 0xFF80) == 0) {
  ------------------
  |  Branch (471:13): [True: 54.7k, False: 84.6k]
  ------------------
  472|  54.7k|          *utf8_output++ = char(word);
  473|  84.6k|        } else if ((word & 0xF800) == 0) {
  ------------------
  |  Branch (473:20): [True: 5.92k, False: 78.7k]
  ------------------
  474|  5.92k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  475|  5.92k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  476|  78.7k|        } else if ((word & 0xF800) != 0xD800) {
  ------------------
  |  Branch (476:20): [True: 67.4k, False: 11.2k]
  ------------------
  477|  67.4k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  478|  67.4k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  479|  67.4k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  480|  67.4k|        } else {
  481|       |          // must be a surrogate pair
  482|  11.2k|          uint16_t diff = uint16_t(word - 0xD800);
  483|  11.2k|          uint16_t next_word =
  484|  11.2k|              scalar::utf16::swap_if_needed<big_endian>(buf[k + 1]);
  485|  11.2k|          k++;
  486|  11.2k|          uint16_t diff2 = uint16_t(next_word - 0xDC00);
  487|  11.2k|          if ((diff | diff2) > 0x3FF) {
  ------------------
  |  Branch (487:15): [True: 128, False: 11.0k]
  ------------------
  488|    128|            return std::make_pair(
  489|    128|                result(error_code::SURROGATE, buf - start + k - 1),
  490|    128|                utf8_output);
  491|    128|          }
  492|  11.0k|          uint32_t value = (diff << 10) + diff2 + 0x10000;
  493|  11.0k|          *utf8_output++ = char((value >> 18) | 0b11110000);
  494|  11.0k|          *utf8_output++ = char(((value >> 12) & 0b111111) | 0b10000000);
  495|  11.0k|          *utf8_output++ = char(((value >> 6) & 0b111111) | 0b10000000);
  496|  11.0k|          *utf8_output++ = char((value & 0b111111) | 0b10000000);
  497|  11.0k|        }
  498|   139k|      }
  499|  9.98k|      buf += k;
  500|  9.98k|    }
  501|   196k|  } // while
  502|       |
  503|    488|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  504|    616|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_127sse_convert_utf32_to_latin1EPKDimPc:
    3|    186|                            char *latin1_output) {
    4|    186|  const size_t rounded_len = len & ~0xF; // Round down to nearest multiple of 16
    5|       |
    6|    186|  __m128i high_bytes_mask = _mm_set1_epi32(0xFFFFFF00);
    7|    186|  __m128i shufmask =
    8|    186|      _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 12, 8, 4, 0);
    9|       |
   10|  1.37k|  for (size_t i = 0; i < rounded_len; i += 16) {
  ------------------
  |  Branch (10:22): [True: 1.23k, False: 138]
  ------------------
   11|  1.23k|    __m128i in1 = _mm_loadu_si128((__m128i *)buf);
   12|  1.23k|    __m128i in2 = _mm_loadu_si128((__m128i *)(buf + 4));
   13|  1.23k|    __m128i in3 = _mm_loadu_si128((__m128i *)(buf + 8));
   14|  1.23k|    __m128i in4 = _mm_loadu_si128((__m128i *)(buf + 12));
   15|       |
   16|  1.23k|    __m128i check_combined = _mm_or_si128(in1, in2);
   17|  1.23k|    check_combined = _mm_or_si128(check_combined, in3);
   18|  1.23k|    check_combined = _mm_or_si128(check_combined, in4);
   19|       |
   20|  1.23k|    if (!_mm_testz_si128(check_combined, high_bytes_mask)) {
  ------------------
  |  Branch (20:9): [True: 48, False: 1.18k]
  ------------------
   21|     48|      return std::make_pair(nullptr, latin1_output);
   22|     48|    }
   23|  1.18k|    __m128i pack1 = _mm_unpacklo_epi32(_mm_shuffle_epi8(in1, shufmask),
   24|  1.18k|                                       _mm_shuffle_epi8(in2, shufmask));
   25|  1.18k|    __m128i pack2 = _mm_unpacklo_epi32(_mm_shuffle_epi8(in3, shufmask),
   26|  1.18k|                                       _mm_shuffle_epi8(in4, shufmask));
   27|  1.18k|    __m128i pack = _mm_unpacklo_epi64(pack1, pack2);
   28|  1.18k|    _mm_storeu_si128((__m128i *)latin1_output, pack);
   29|  1.18k|    latin1_output += 16;
   30|  1.18k|    buf += 16;
   31|  1.18k|  }
   32|       |
   33|    138|  return std::make_pair(buf, latin1_output);
   34|    186|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_139sse_convert_utf32_to_latin1_with_errorsEPKDimPc:
   38|    488|                                        char *latin1_output) {
   39|    488|  const char32_t *start = buf;
   40|    488|  const size_t rounded_len = len & ~0xF; // Round down to nearest multiple of 16
   41|       |
   42|    488|  __m128i high_bytes_mask = _mm_set1_epi32(0xFFFFFF00);
   43|    488|  __m128i shufmask =
   44|    488|      _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 12, 8, 4, 0);
   45|       |
   46|  34.0k|  for (size_t i = 0; i < rounded_len; i += 16) {
  ------------------
  |  Branch (46:22): [True: 33.7k, False: 272]
  ------------------
   47|  33.7k|    __m128i in1 = _mm_loadu_si128((__m128i *)buf);
   48|  33.7k|    __m128i in2 = _mm_loadu_si128((__m128i *)(buf + 4));
   49|  33.7k|    __m128i in3 = _mm_loadu_si128((__m128i *)(buf + 8));
   50|  33.7k|    __m128i in4 = _mm_loadu_si128((__m128i *)(buf + 12));
   51|       |
   52|  33.7k|    __m128i check_combined = _mm_or_si128(in1, in2);
   53|  33.7k|    check_combined = _mm_or_si128(check_combined, in3);
   54|  33.7k|    check_combined = _mm_or_si128(check_combined, in4);
   55|       |
   56|  33.7k|    if (!_mm_testz_si128(check_combined, high_bytes_mask)) {
  ------------------
  |  Branch (56:9): [True: 216, False: 33.5k]
  ------------------
   57|       |      // Fallback to scalar code for handling errors
   58|    802|      for (int k = 0; k < 16; k++) {
  ------------------
  |  Branch (58:23): [True: 802, False: 0]
  ------------------
   59|    802|        char32_t codepoint = buf[k];
   60|    802|        if (codepoint <= 0xff) {
  ------------------
  |  Branch (60:13): [True: 586, False: 216]
  ------------------
   61|    586|          *latin1_output++ = char(codepoint);
   62|    586|        } else {
   63|    216|          return std::make_pair(result(error_code::TOO_LARGE, buf - start + k),
   64|    216|                                latin1_output);
   65|    216|        }
   66|    802|      }
   67|      0|      buf += 16;
   68|      0|      continue;
   69|    216|    }
   70|  33.5k|    __m128i pack1 = _mm_unpacklo_epi32(_mm_shuffle_epi8(in1, shufmask),
   71|  33.5k|                                       _mm_shuffle_epi8(in2, shufmask));
   72|  33.5k|    __m128i pack2 = _mm_unpacklo_epi32(_mm_shuffle_epi8(in3, shufmask),
   73|  33.5k|                                       _mm_shuffle_epi8(in4, shufmask));
   74|  33.5k|    __m128i pack = _mm_unpacklo_epi64(pack1, pack2);
   75|  33.5k|    _mm_storeu_si128((__m128i *)latin1_output, pack);
   76|  33.5k|    latin1_output += 16;
   77|  33.5k|    buf += 16;
   78|  33.5k|  }
   79|       |
   80|    272|  return std::make_pair(result(error_code::SUCCESS, buf - start),
   81|    272|                        latin1_output);
   82|    488|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_126sse_convert_utf32_to_utf16ILNS_10endiannessE0EEENSt3__14pairIPKDiPDsEES7_mS8_:
   58|    794|                           char16_t *utf16_output) {
   59|       |
   60|    794|  const char32_t *end = buf + len;
   61|       |
   62|    794|  const __m128i v_ffff0000 = _mm_set1_epi32((int32_t)0xffff0000);
   63|    794|  __m128i forbidden_bytemask = _mm_setzero_si128();
   64|       |
   65|  10.1k|  while (end - buf >= 16 + 8) {
  ------------------
  |  Branch (65:10): [True: 9.39k, False: 750]
  ------------------
   66|  9.39k|    const __m128i *ptr = reinterpret_cast<const __m128i *>(buf);
   67|  9.39k|    const __m128i in0 = _mm_loadu_si128(ptr + 0);
   68|  9.39k|    const __m128i in1 = _mm_loadu_si128(ptr + 1);
   69|  9.39k|    const __m128i in2 = _mm_loadu_si128(ptr + 2);
   70|  9.39k|    const __m128i in3 = _mm_loadu_si128(ptr + 3);
   71|       |
   72|  9.39k|    const __m128i combined =
   73|  9.39k|        _mm_or_si128(_mm_or_si128(in2, in3), _mm_or_si128(in0, in1));
   74|  9.39k|    if (simdutf_likely(_mm_testz_si128(combined, v_ffff0000))) {
  ------------------
  |  |   90|  9.39k|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 8.62k, False: 766]
  |  |  ------------------
  ------------------
   75|       |      // No bits set above 16th, directly pack UTF-32 to UTF-16
   76|  8.62k|      __m128i utf16_packed0 = _mm_packus_epi32(in0, in1);
   77|  8.62k|      __m128i utf16_packed1 = _mm_packus_epi32(in2, in3);
   78|       |
   79|  8.62k|      const __m128i v_f800 = _mm_set1_epi16((uint16_t)0xf800);
   80|  8.62k|      const __m128i v_d800 = _mm_set1_epi16((uint16_t)0xd800);
   81|  8.62k|      forbidden_bytemask = _mm_or_si128(
   82|  8.62k|          forbidden_bytemask,
   83|  8.62k|          _mm_or_si128(
   84|  8.62k|              _mm_cmpeq_epi16(_mm_and_si128(utf16_packed0, v_f800), v_d800),
   85|  8.62k|              _mm_cmpeq_epi16(_mm_and_si128(utf16_packed1, v_f800), v_d800)));
   86|       |
   87|  8.62k|      if (big_endian) {
  ------------------
  |  Branch (87:11): [Folded, False: 8.62k]
  ------------------
   88|      0|        const __m128i swap =
   89|      0|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   90|      0|        utf16_packed0 = _mm_shuffle_epi8(utf16_packed0, swap);
   91|      0|        utf16_packed1 = _mm_shuffle_epi8(utf16_packed1, swap);
   92|      0|      }
   93|       |
   94|  8.62k|      _mm_storeu_si128((__m128i *)utf16_output + 0, utf16_packed0);
   95|  8.62k|      _mm_storeu_si128((__m128i *)utf16_output + 1, utf16_packed1);
   96|  8.62k|      utf16_output += 16;
   97|  8.62k|      buf += 16;
   98|  8.62k|    } else {
   99|    766|      if (!validate_utf32(in0, in1) || !validate_utf32(in2, in3)) {
  ------------------
  |  Branch (99:11): [True: 24, False: 742]
  |  Branch (99:40): [True: 20, False: 722]
  ------------------
  100|     44|        return std::make_pair(nullptr, utf16_output);
  101|     44|      }
  102|       |
  103|    722|      const auto ret0 = sse_expand_surrogate<big_endian>(in0);
  104|    722|      _mm_storeu_si128((__m128i *)utf16_output, ret0.compressed);
  105|    722|      utf16_output += ret0.u16count;
  106|       |
  107|    722|      const auto ret1 = sse_expand_surrogate<big_endian>(in1);
  108|    722|      _mm_storeu_si128((__m128i *)utf16_output, ret1.compressed);
  109|    722|      utf16_output += ret1.u16count;
  110|       |
  111|    722|      const auto ret2 = sse_expand_surrogate<big_endian>(in2);
  112|    722|      _mm_storeu_si128((__m128i *)utf16_output, ret2.compressed);
  113|    722|      utf16_output += ret2.u16count;
  114|       |
  115|    722|      const auto ret3 = sse_expand_surrogate<big_endian>(in3);
  116|    722|      _mm_storeu_si128((__m128i *)utf16_output, ret3.compressed);
  117|    722|      utf16_output += ret3.u16count;
  118|       |
  119|    722|      buf += 16;
  120|    722|    }
  121|  9.39k|  }
  122|       |
  123|       |  // check for invalid input
  124|    750|  if (static_cast<uint32_t>(_mm_movemask_epi8(forbidden_bytemask)) != 0) {
  ------------------
  |  Branch (124:7): [True: 8, False: 742]
  ------------------
  125|      8|    return std::make_pair(nullptr, utf16_output);
  126|      8|  }
  127|       |
  128|    742|  return std::make_pair(buf, utf16_output);
  129|    750|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_114validate_utf32EDv2_xS2_:
   37|  4.26k|simdutf_really_inline bool validate_utf32(const __m128i a, const __m128i b) {
   38|  4.26k|  using vector_u32 = simd32<uint32_t>;
   39|       |
   40|  4.26k|  const auto in0 = vector_u32(a);
   41|  4.26k|  const auto in1 = vector_u32(b);
   42|       |
   43|  4.26k|  const auto standardmax = vector_u32::splat(0x10ffff);
   44|  4.26k|  const auto offset = vector_u32::splat(0xffff2000);
   45|  4.26k|  const auto standardoffsetmax = vector_u32::splat(0xfffff7ff);
   46|       |
   47|  4.26k|  const auto too_large = max(in0, in1) > standardmax;
   48|  4.26k|  const auto surrogate0 = (in0 + offset) > standardoffsetmax;
   49|  4.26k|  const auto surrogate1 = (in1 + offset) > standardoffsetmax;
   50|       |
   51|  4.26k|  const auto combined = too_large | surrogate0 | surrogate1;
   52|  4.26k|  return !combined.any();
   53|  4.26k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_120sse_expand_surrogateILNS_10endiannessE0EEENS1_18expansion_result_tEDv2_x:
    9|  2.88k|expansion_result_t sse_expand_surrogate(const __m128i x) {
   10|  2.88k|  using vector_u32 = simd32<uint32_t>;
   11|  2.88k|  using vector_u8 = simd8<uint8_t>;
   12|       |
   13|  2.88k|  const auto in = vector_u32(x);
   14|       |
   15|  2.88k|  const auto non_surrogate_mask = (in & uint32_t(0xffff0000)) == uint32_t(0);
   16|  2.88k|  const auto mask = (~non_surrogate_mask.to_4bit_bitmask()) & 0xf;
   17|       |
   18|  2.88k|  const auto t0 = in - uint32_t(0x00010000);
   19|  2.88k|  const auto hi = t0.shr<10>() & uint32_t(0x000003ff);
   20|  2.88k|  const auto lo = t0.shl<16>() & uint32_t(0x03ff0000);
   21|  2.88k|  const auto surrogates = (lo | hi) | uint32_t(0xdc00d800);
   22|       |
   23|  2.88k|  const auto merged = as_vector_u8(select(non_surrogate_mask, in, surrogates));
   24|       |
   25|  2.88k|  const auto shuffle = vector_u8::load(
   26|  2.88k|      (byte_order == endianness::LITTLE)
  ------------------
  |  Branch (26:7): [True: 2.88k, Folded]
  ------------------
   27|  2.88k|          ? tables::utf32_to_utf16::pack_utf32_to_utf16le[mask]
   28|  2.88k|          : tables::utf32_to_utf16::pack_utf32_to_utf16be[mask]);
   29|       |
   30|  2.88k|  const size_t u16count = (4 + count_ones(mask));
   31|  2.88k|  const auto compressed = shuffle.lookup_16(merged);
   32|       |
   33|  2.88k|  return {u16count, compressed};
   34|  2.88k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_126sse_convert_utf32_to_utf16ILNS_10endiannessE1EEENSt3__14pairIPKDiPDsEES7_mS8_:
   58|    652|                           char16_t *utf16_output) {
   59|       |
   60|    652|  const char32_t *end = buf + len;
   61|       |
   62|    652|  const __m128i v_ffff0000 = _mm_set1_epi32((int32_t)0xffff0000);
   63|    652|  __m128i forbidden_bytemask = _mm_setzero_si128();
   64|       |
   65|  4.58k|  while (end - buf >= 16 + 8) {
  ------------------
  |  Branch (65:10): [True: 3.98k, False: 604]
  ------------------
   66|  3.98k|    const __m128i *ptr = reinterpret_cast<const __m128i *>(buf);
   67|  3.98k|    const __m128i in0 = _mm_loadu_si128(ptr + 0);
   68|  3.98k|    const __m128i in1 = _mm_loadu_si128(ptr + 1);
   69|  3.98k|    const __m128i in2 = _mm_loadu_si128(ptr + 2);
   70|  3.98k|    const __m128i in3 = _mm_loadu_si128(ptr + 3);
   71|       |
   72|  3.98k|    const __m128i combined =
   73|  3.98k|        _mm_or_si128(_mm_or_si128(in2, in3), _mm_or_si128(in0, in1));
   74|  3.98k|    if (simdutf_likely(_mm_testz_si128(combined, v_ffff0000))) {
  ------------------
  |  |   90|  3.98k|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 2.58k, False: 1.39k]
  |  |  ------------------
  ------------------
   75|       |      // No bits set above 16th, directly pack UTF-32 to UTF-16
   76|  2.58k|      __m128i utf16_packed0 = _mm_packus_epi32(in0, in1);
   77|  2.58k|      __m128i utf16_packed1 = _mm_packus_epi32(in2, in3);
   78|       |
   79|  2.58k|      const __m128i v_f800 = _mm_set1_epi16((uint16_t)0xf800);
   80|  2.58k|      const __m128i v_d800 = _mm_set1_epi16((uint16_t)0xd800);
   81|  2.58k|      forbidden_bytemask = _mm_or_si128(
   82|  2.58k|          forbidden_bytemask,
   83|  2.58k|          _mm_or_si128(
   84|  2.58k|              _mm_cmpeq_epi16(_mm_and_si128(utf16_packed0, v_f800), v_d800),
   85|  2.58k|              _mm_cmpeq_epi16(_mm_and_si128(utf16_packed1, v_f800), v_d800)));
   86|       |
   87|  2.58k|      if (big_endian) {
  ------------------
  |  Branch (87:11): [True: 2.58k, Folded]
  ------------------
   88|  2.58k|        const __m128i swap =
   89|  2.58k|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   90|  2.58k|        utf16_packed0 = _mm_shuffle_epi8(utf16_packed0, swap);
   91|  2.58k|        utf16_packed1 = _mm_shuffle_epi8(utf16_packed1, swap);
   92|  2.58k|      }
   93|       |
   94|  2.58k|      _mm_storeu_si128((__m128i *)utf16_output + 0, utf16_packed0);
   95|  2.58k|      _mm_storeu_si128((__m128i *)utf16_output + 1, utf16_packed1);
   96|  2.58k|      utf16_output += 16;
   97|  2.58k|      buf += 16;
   98|  2.58k|    } else {
   99|  1.39k|      if (!validate_utf32(in0, in1) || !validate_utf32(in2, in3)) {
  ------------------
  |  Branch (99:11): [True: 32, False: 1.36k]
  |  Branch (99:40): [True: 16, False: 1.34k]
  ------------------
  100|     48|        return std::make_pair(nullptr, utf16_output);
  101|     48|      }
  102|       |
  103|  1.34k|      const auto ret0 = sse_expand_surrogate<big_endian>(in0);
  104|  1.34k|      _mm_storeu_si128((__m128i *)utf16_output, ret0.compressed);
  105|  1.34k|      utf16_output += ret0.u16count;
  106|       |
  107|  1.34k|      const auto ret1 = sse_expand_surrogate<big_endian>(in1);
  108|  1.34k|      _mm_storeu_si128((__m128i *)utf16_output, ret1.compressed);
  109|  1.34k|      utf16_output += ret1.u16count;
  110|       |
  111|  1.34k|      const auto ret2 = sse_expand_surrogate<big_endian>(in2);
  112|  1.34k|      _mm_storeu_si128((__m128i *)utf16_output, ret2.compressed);
  113|  1.34k|      utf16_output += ret2.u16count;
  114|       |
  115|  1.34k|      const auto ret3 = sse_expand_surrogate<big_endian>(in3);
  116|  1.34k|      _mm_storeu_si128((__m128i *)utf16_output, ret3.compressed);
  117|  1.34k|      utf16_output += ret3.u16count;
  118|       |
  119|  1.34k|      buf += 16;
  120|  1.34k|    }
  121|  3.98k|  }
  122|       |
  123|       |  // check for invalid input
  124|    604|  if (static_cast<uint32_t>(_mm_movemask_epi8(forbidden_bytemask)) != 0) {
  ------------------
  |  Branch (124:7): [True: 12, False: 592]
  ------------------
  125|     12|    return std::make_pair(nullptr, utf16_output);
  126|     12|  }
  127|       |
  128|    592|  return std::make_pair(buf, utf16_output);
  129|    604|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_120sse_expand_surrogateILNS_10endiannessE1EEENS1_18expansion_result_tEDv2_x:
    9|  5.38k|expansion_result_t sse_expand_surrogate(const __m128i x) {
   10|  5.38k|  using vector_u32 = simd32<uint32_t>;
   11|  5.38k|  using vector_u8 = simd8<uint8_t>;
   12|       |
   13|  5.38k|  const auto in = vector_u32(x);
   14|       |
   15|  5.38k|  const auto non_surrogate_mask = (in & uint32_t(0xffff0000)) == uint32_t(0);
   16|  5.38k|  const auto mask = (~non_surrogate_mask.to_4bit_bitmask()) & 0xf;
   17|       |
   18|  5.38k|  const auto t0 = in - uint32_t(0x00010000);
   19|  5.38k|  const auto hi = t0.shr<10>() & uint32_t(0x000003ff);
   20|  5.38k|  const auto lo = t0.shl<16>() & uint32_t(0x03ff0000);
   21|  5.38k|  const auto surrogates = (lo | hi) | uint32_t(0xdc00d800);
   22|       |
   23|  5.38k|  const auto merged = as_vector_u8(select(non_surrogate_mask, in, surrogates));
   24|       |
   25|  5.38k|  const auto shuffle = vector_u8::load(
   26|  5.38k|      (byte_order == endianness::LITTLE)
  ------------------
  |  Branch (26:7): [Folded, False: 5.38k]
  ------------------
   27|  5.38k|          ? tables::utf32_to_utf16::pack_utf32_to_utf16le[mask]
   28|  5.38k|          : tables::utf32_to_utf16::pack_utf32_to_utf16be[mask]);
   29|       |
   30|  5.38k|  const size_t u16count = (4 + count_ones(mask));
   31|  5.38k|  const auto compressed = shuffle.lookup_16(merged);
   32|       |
   33|  5.38k|  return {u16count, compressed};
   34|  5.38k|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_138sse_convert_utf32_to_utf16_with_errorsILNS_10endiannessE0EEENSt3__14pairINS_6resultEPDsEEPKDimS7_:
  134|    772|                                       char16_t *utf16_output) {
  135|    772|  const char32_t *start = buf;
  136|    772|  const char32_t *end = buf + len;
  137|       |
  138|    772|  const __m128i v_ffff0000 = _mm_set1_epi32((int32_t)0xffff0000);
  139|       |
  140|  12.9k|  while (end - buf >= 8) {
  ------------------
  |  Branch (140:10): [True: 12.6k, False: 330]
  ------------------
  141|  12.6k|    const __m128i in = _mm_loadu_si128((__m128i *)buf);
  142|  12.6k|    const __m128i nextin = _mm_loadu_si128((__m128i *)buf + 1);
  143|       |
  144|  12.6k|    const __m128i combined = _mm_or_si128(in, nextin);
  145|  12.6k|    if (simdutf_likely(_mm_testz_si128(combined, v_ffff0000))) {
  ------------------
  |  |   90|  12.6k|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 9.94k, False: 2.67k]
  |  |  ------------------
  ------------------
  146|       |      // No bits set above 16th, directly pack UTF-32 to UTF-16
  147|  9.94k|      __m128i utf16_packed = _mm_packus_epi32(in, nextin);
  148|       |
  149|  9.94k|      const __m128i v_f800 = _mm_set1_epi16((uint16_t)0xf800);
  150|  9.94k|      const __m128i v_d800 = _mm_set1_epi16((uint16_t)0xd800);
  151|  9.94k|      const __m128i forbidden_bytemask =
  152|  9.94k|          _mm_cmpeq_epi16(_mm_and_si128(utf16_packed, v_f800), v_d800);
  153|  9.94k|      if (static_cast<uint32_t>(_mm_movemask_epi8(forbidden_bytemask)) != 0) {
  ------------------
  |  Branch (153:11): [True: 42, False: 9.90k]
  ------------------
  154|     42|        return std::make_pair(result(error_code::SURROGATE, buf - start),
  155|     42|                              utf16_output);
  156|     42|      }
  157|       |
  158|  9.90k|      if (big_endian) {
  ------------------
  |  Branch (158:11): [Folded, False: 9.90k]
  ------------------
  159|      0|        const __m128i swap =
  160|      0|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  161|      0|        utf16_packed = _mm_shuffle_epi8(utf16_packed, swap);
  162|      0|      }
  163|       |
  164|  9.90k|      _mm_storeu_si128((__m128i *)utf16_output, utf16_packed);
  165|  9.90k|      utf16_output += 8;
  166|  9.90k|      buf += 8;
  167|  9.90k|    } else {
  168|  2.67k|      size_t forward = 7;
  169|  2.67k|      size_t k = 0;
  170|  2.67k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (170:11): [True: 0, False: 2.67k]
  ------------------
  171|      0|        forward = size_t(end - buf - 1);
  172|      0|      }
  173|  19.4k|      for (; k < forward; k++) {
  ------------------
  |  Branch (173:14): [True: 17.2k, False: 2.27k]
  ------------------
  174|  17.2k|        uint32_t word = buf[k];
  175|  17.2k|        if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (175:13): [True: 9.80k, False: 7.40k]
  ------------------
  176|       |          // will not generate a surrogate pair
  177|  9.80k|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (177:15): [True: 1.01k, False: 8.78k]
  |  Branch (177:33): [True: 58, False: 956]
  ------------------
  178|     58|            return std::make_pair(
  179|     58|                result(error_code::SURROGATE, buf - start + k), utf16_output);
  180|     58|          }
  181|  9.74k|          *utf16_output++ =
  182|  9.74k|              big_endian
  ------------------
  |  Branch (182:15): [Folded, False: 9.74k]
  ------------------
  183|  9.74k|                  ? char16_t((uint16_t(word) >> 8) | (uint16_t(word) << 8))
  184|  9.74k|                  : char16_t(word);
  185|  9.74k|        } else {
  186|       |          // will generate a surrogate pair
  187|  7.40k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (187:15): [True: 342, False: 7.05k]
  ------------------
  188|    342|            return std::make_pair(
  189|    342|                result(error_code::TOO_LARGE, buf - start + k), utf16_output);
  190|    342|          }
  191|  7.05k|          word -= 0x10000;
  192|  7.05k|          uint16_t high_surrogate = uint16_t(0xD800 + (word >> 10));
  193|  7.05k|          uint16_t low_surrogate = uint16_t(0xDC00 + (word & 0x3FF));
  194|  7.05k|          if (big_endian) {
  ------------------
  |  Branch (194:15): [Folded, False: 7.05k]
  ------------------
  195|      0|            high_surrogate =
  196|      0|                uint16_t((high_surrogate >> 8) | (high_surrogate << 8));
  197|      0|            low_surrogate =
  198|      0|                uint16_t((low_surrogate >> 8) | (low_surrogate << 8));
  199|      0|          }
  200|  7.05k|          *utf16_output++ = char16_t(high_surrogate);
  201|  7.05k|          *utf16_output++ = char16_t(low_surrogate);
  202|  7.05k|        }
  203|  17.2k|      }
  204|  2.27k|      buf += k;
  205|  2.27k|    }
  206|  12.6k|  }
  207|       |
  208|    330|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf16_output);
  209|    772|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_138sse_convert_utf32_to_utf16_with_errorsILNS_10endiannessE1EEENSt3__14pairINS_6resultEPDsEEPKDimS7_:
  134|    678|                                       char16_t *utf16_output) {
  135|    678|  const char32_t *start = buf;
  136|    678|  const char32_t *end = buf + len;
  137|       |
  138|    678|  const __m128i v_ffff0000 = _mm_set1_epi32((int32_t)0xffff0000);
  139|       |
  140|  20.2k|  while (end - buf >= 8) {
  ------------------
  |  Branch (140:10): [True: 19.9k, False: 312]
  ------------------
  141|  19.9k|    const __m128i in = _mm_loadu_si128((__m128i *)buf);
  142|  19.9k|    const __m128i nextin = _mm_loadu_si128((__m128i *)buf + 1);
  143|       |
  144|  19.9k|    const __m128i combined = _mm_or_si128(in, nextin);
  145|  19.9k|    if (simdutf_likely(_mm_testz_si128(combined, v_ffff0000))) {
  ------------------
  |  |   90|  19.9k|    #define simdutf_likely(x) __builtin_expect(!!(x), 1)
  |  |  ------------------
  |  |  |  Branch (90:31): [True: 18.9k, False: 1.01k]
  |  |  ------------------
  ------------------
  146|       |      // No bits set above 16th, directly pack UTF-32 to UTF-16
  147|  18.9k|      __m128i utf16_packed = _mm_packus_epi32(in, nextin);
  148|       |
  149|  18.9k|      const __m128i v_f800 = _mm_set1_epi16((uint16_t)0xf800);
  150|  18.9k|      const __m128i v_d800 = _mm_set1_epi16((uint16_t)0xd800);
  151|  18.9k|      const __m128i forbidden_bytemask =
  152|  18.9k|          _mm_cmpeq_epi16(_mm_and_si128(utf16_packed, v_f800), v_d800);
  153|  18.9k|      if (static_cast<uint32_t>(_mm_movemask_epi8(forbidden_bytemask)) != 0) {
  ------------------
  |  Branch (153:11): [True: 16, False: 18.9k]
  ------------------
  154|     16|        return std::make_pair(result(error_code::SURROGATE, buf - start),
  155|     16|                              utf16_output);
  156|     16|      }
  157|       |
  158|  18.9k|      if (big_endian) {
  ------------------
  |  Branch (158:11): [True: 18.9k, Folded]
  ------------------
  159|  18.9k|        const __m128i swap =
  160|  18.9k|            _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
  161|  18.9k|        utf16_packed = _mm_shuffle_epi8(utf16_packed, swap);
  162|  18.9k|      }
  163|       |
  164|  18.9k|      _mm_storeu_si128((__m128i *)utf16_output, utf16_packed);
  165|  18.9k|      utf16_output += 8;
  166|  18.9k|      buf += 8;
  167|  18.9k|    } else {
  168|  1.01k|      size_t forward = 7;
  169|  1.01k|      size_t k = 0;
  170|  1.01k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (170:11): [True: 0, False: 1.01k]
  ------------------
  171|      0|        forward = size_t(end - buf - 1);
  172|      0|      }
  173|  6.39k|      for (; k < forward; k++) {
  ------------------
  |  Branch (173:14): [True: 5.73k, False: 662]
  ------------------
  174|  5.73k|        uint32_t word = buf[k];
  175|  5.73k|        if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (175:13): [True: 2.95k, False: 2.78k]
  ------------------
  176|       |          // will not generate a surrogate pair
  177|  2.95k|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (177:15): [True: 660, False: 2.29k]
  |  Branch (177:33): [True: 34, False: 626]
  ------------------
  178|     34|            return std::make_pair(
  179|     34|                result(error_code::SURROGATE, buf - start + k), utf16_output);
  180|     34|          }
  181|  2.91k|          *utf16_output++ =
  182|  2.91k|              big_endian
  ------------------
  |  Branch (182:15): [True: 2.91k, Folded]
  ------------------
  183|  2.91k|                  ? char16_t((uint16_t(word) >> 8) | (uint16_t(word) << 8))
  184|  2.91k|                  : char16_t(word);
  185|  2.91k|        } else {
  186|       |          // will generate a surrogate pair
  187|  2.78k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (187:15): [True: 316, False: 2.46k]
  ------------------
  188|    316|            return std::make_pair(
  189|    316|                result(error_code::TOO_LARGE, buf - start + k), utf16_output);
  190|    316|          }
  191|  2.46k|          word -= 0x10000;
  192|  2.46k|          uint16_t high_surrogate = uint16_t(0xD800 + (word >> 10));
  193|  2.46k|          uint16_t low_surrogate = uint16_t(0xDC00 + (word & 0x3FF));
  194|  2.46k|          if (big_endian) {
  ------------------
  |  Branch (194:15): [True: 2.46k, Folded]
  ------------------
  195|  2.46k|            high_surrogate =
  196|  2.46k|                uint16_t((high_surrogate >> 8) | (high_surrogate << 8));
  197|  2.46k|            low_surrogate =
  198|  2.46k|                uint16_t((low_surrogate >> 8) | (low_surrogate << 8));
  199|  2.46k|          }
  200|  2.46k|          *utf16_output++ = char16_t(high_surrogate);
  201|  2.46k|          *utf16_output++ = char16_t(low_surrogate);
  202|  2.46k|        }
  203|  5.73k|      }
  204|    662|      buf += k;
  205|    662|    }
  206|  19.9k|  }
  207|       |
  208|    312|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf16_output);
  209|    678|}

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_125sse_convert_utf32_to_utf8EPKDimPc:
    2|    908|sse_convert_utf32_to_utf8(const char32_t *buf, size_t len, char *utf8_output) {
    3|    908|  const char32_t *end = buf + len;
    4|       |
    5|    908|  const __m128i v_0000 = _mm_setzero_si128();              //__m128 = 128 bits
    6|    908|  const __m128i v_f800 = _mm_set1_epi16((uint16_t)0xf800); // 1111 1000 0000
    7|       |                                                           // 0000
    8|    908|  const __m128i v_c080 = _mm_set1_epi16((uint16_t)0xc080); // 1100 0000 1000
    9|       |                                                           // 0000
   10|    908|  const __m128i v_ff80 = _mm_set1_epi16((uint16_t)0xff80); // 1111 1111 1000
   11|       |                                                           // 0000
   12|    908|  const __m128i v_ffff0000 = _mm_set1_epi32(
   13|    908|      (uint32_t)0xffff0000); // 1111 1111 1111 1111 0000 0000 0000 0000
   14|    908|  const __m128i v_7fffffff = _mm_set1_epi32(
   15|    908|      (uint32_t)0x7fffffff); // 0111 1111 1111 1111 1111 1111 1111 1111
   16|    908|  __m128i running_max = _mm_setzero_si128();
   17|    908|  __m128i forbidden_bytemask = _mm_setzero_si128();
   18|    908|  const size_t safety_margin =
   19|    908|      12; // to avoid overruns, see issue
   20|       |          // https://github.com/simdutf/simdutf/issues/92
   21|       |
   22|  8.28k|  while (end - buf >=
  ------------------
  |  Branch (22:10): [True: 7.60k, False: 678]
  ------------------
   23|  8.28k|         std::ptrdiff_t(
   24|  8.28k|             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|  7.60k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
   29|  7.60k|    __m128i nextin = _mm_loadu_si128(
   30|  7.60k|        (__m128i *)buf + 1); // These two values can hold only 8 UTF32 chars
   31|  7.60k|    running_max = _mm_max_epu32(
   32|  7.60k|        _mm_max_epu32(in, running_max), // take element-wise max char32_t from
   33|       |                                        // in and running_max vector
   34|  7.60k|        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|  7.60k|    __m128i in_16 = _mm_packus_epi32(
   40|  7.60k|        _mm_and_si128(in, v_7fffffff),
   41|  7.60k|        _mm_and_si128(
   42|  7.60k|            nextin,
   43|  7.60k|            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|  7.60k|    if (_mm_testz_si128(in_16, v_ff80)) { // if the first two blocks are ASCII
  ------------------
  |  Branch (60:9): [True: 1.88k, False: 5.71k]
  ------------------
   61|  1.88k|      __m128i thirdin = _mm_loadu_si128((__m128i *)buf + 2);
   62|  1.88k|      __m128i fourthin = _mm_loadu_si128((__m128i *)buf + 3);
   63|  1.88k|      running_max = _mm_max_epu32(
   64|  1.88k|          _mm_max_epu32(thirdin, running_max),
   65|  1.88k|          fourthin); // take the running max of all 4 vectors thus far
   66|  1.88k|      __m128i nextin_16 = _mm_packus_epi32(
   67|  1.88k|          _mm_and_si128(thirdin, v_7fffffff),
   68|  1.88k|          _mm_and_si128(fourthin,
   69|  1.88k|                        v_7fffffff)); // pack into 1 vector, now you have two
   70|  1.88k|      if (!_mm_testz_si128(
  ------------------
  |  Branch (70:11): [True: 780, False: 1.10k]
  ------------------
   71|  1.88k|              nextin_16,
   72|  1.88k|              v_ff80)) { // checks if the second packed vector is ASCII, if not:
   73|       |        // 1. pack the bytes
   74|       |        // obviously suboptimal.
   75|    780|        const __m128i utf8_packed = _mm_packus_epi16(
   76|    780|            in_16, in_16); // creates two copy of in_16 in 1 vector
   77|       |        // 2. store (16 bytes)
   78|    780|        _mm_storeu_si128((__m128i *)utf8_output,
   79|    780|                         utf8_packed); // put them into the output
   80|       |        // 3. adjust pointers
   81|    780|        buf += 8; // the char32_t buffer pointer goes up 8 char32_t chars* 32
   82|       |                  // bits =  256 bits
   83|    780|        utf8_output +=
   84|    780|            8; // same with output, e.g. lift the first two blocks alone.
   85|       |        // Proceed with next input
   86|    780|        in_16 = nextin_16;
   87|       |        // We need to update in and nextin because they are used later.
   88|    780|        in = thirdin;
   89|    780|        nextin = fourthin;
   90|  1.10k|      } else {
   91|       |        // 1. pack the bytes
   92|  1.10k|        const __m128i utf8_packed = _mm_packus_epi16(in_16, nextin_16);
   93|       |        // 2. store (16 bytes)
   94|  1.10k|        _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
   95|       |        // 3. adjust pointers
   96|  1.10k|        buf += 16;
   97|  1.10k|        utf8_output += 16;
   98|  1.10k|        continue; // we are done for this round!
   99|  1.10k|      }
  100|  1.88k|    }
  101|       |
  102|       |    // no bits set above 7th bit -- find out all the ASCII characters
  103|  6.49k|    const __m128i one_byte_bytemask =
  104|  6.49k|        _mm_cmpeq_epi16( // this takes four bytes at a time and compares:
  105|  6.49k|            _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|  6.49k|            v_0000                        //
  108|  6.49k|        ); // 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|  6.49k|    const uint16_t one_byte_bitmask = static_cast<uint16_t>(_mm_movemask_epi8(
  113|  6.49k|        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|  6.49k|    const __m128i one_or_two_bytes_bytemask =
  118|  6.49k|        _mm_cmpeq_epi16(_mm_and_si128(in_16, v_f800), v_0000);
  119|  6.49k|    const uint16_t one_or_two_bytes_bitmask =
  120|  6.49k|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  121|       |
  122|  6.49k|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (122:9): [True: 3.77k, False: 2.72k]
  ------------------
  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|  3.77k|      const __m128i v_1f00 =
  129|  3.77k|          _mm_set1_epi16((int16_t)0x1f00); // 0001 1111 0000 0000
  130|  3.77k|      const __m128i v_003f =
  131|  3.77k|          _mm_set1_epi16((int16_t)0x003f); // 0000 0000 0011 1111
  132|       |
  133|       |      // t0 = [000a|aaaa|bbbb|bb00]
  134|  3.77k|      const __m128i t0 = _mm_slli_epi16(in_16, 2); // shift packed vector by two
  135|       |      // t1 = [000a|aaaa|0000|0000]
  136|  3.77k|      const __m128i t1 = _mm_and_si128(t0, v_1f00); // potential first utf8 byte
  137|       |      // t2 = [0000|0000|00bb|bbbb]
  138|  3.77k|      const __m128i t2 =
  139|  3.77k|          _mm_and_si128(in_16, v_003f); // potential second utf8 byte
  140|       |      // t3 = [000a|aaaa|00bb|bbbb]
  141|  3.77k|      const __m128i t3 =
  142|  3.77k|          _mm_or_si128(t1, t2); // first and second potential utf8 byte together
  143|       |      // t4 = [110a|aaaa|10bb|bbbb]
  144|  3.77k|      const __m128i t4 = _mm_or_si128(
  145|  3.77k|          t3,
  146|  3.77k|          v_c080); // t3 | 1100 0000 1000 0000 = full potential 2-byte utf8 unit
  147|       |
  148|       |      // 2. merge ASCII and 2-byte codewords
  149|  3.77k|      const __m128i utf8_unpacked =
  150|  3.77k|          _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|  3.77k|      const uint16_t m0 = one_byte_bitmask & 0x5555; // m0 = 0h0g0f0e0d0c0b0a
  156|  3.77k|      const uint16_t m1 =
  157|  3.77k|          static_cast<uint16_t>(m0 >> 7); // m1 = 00000000h0g0f0e0
  158|  3.77k|      const uint8_t m2 =
  159|  3.77k|          static_cast<uint8_t>((m0 | m1) & 0xff); // m2 =         hdgcfbea
  160|       |      // 4. pack the bytes
  161|  3.77k|      const uint8_t *row =
  162|  3.77k|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[m2][0];
  163|  3.77k|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  164|  3.77k|      const __m128i utf8_packed = _mm_shuffle_epi8(utf8_unpacked, shuffle);
  165|       |
  166|       |      // 5. store bytes
  167|  3.77k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  168|       |
  169|       |      // 6. adjust pointers
  170|  3.77k|      buf += 8;
  171|  3.77k|      utf8_output += row[0];
  172|  3.77k|      continue;
  173|  3.77k|    }
  174|       |
  175|       |    // Check for overflow in packing
  176|       |
  177|  2.72k|    const __m128i saturation_bytemask = _mm_cmpeq_epi32(
  178|  2.72k|        _mm_and_si128(_mm_or_si128(in, nextin), v_ffff0000), v_0000);
  179|  2.72k|    const uint32_t saturation_bitmask =
  180|  2.72k|        static_cast<uint32_t>(_mm_movemask_epi8(saturation_bytemask));
  181|  2.72k|    if (saturation_bitmask == 0xffff) {
  ------------------
  |  Branch (181:9): [True: 1.35k, False: 1.37k]
  ------------------
  182|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  183|  1.35k|      const __m128i v_d800 = _mm_set1_epi16((uint16_t)0xd800);
  184|  1.35k|      forbidden_bytemask =
  185|  1.35k|          _mm_or_si128(forbidden_bytemask,
  186|  1.35k|                       _mm_cmpeq_epi16(_mm_and_si128(in_16, v_f800), v_d800));
  187|       |
  188|  1.35k|      const __m128i dup_even = _mm_setr_epi16(0x0000, 0x0202, 0x0404, 0x0606,
  189|  1.35k|                                              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|  1.35k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  219|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  220|  1.35k|      const __m128i t0 = _mm_shuffle_epi8(in_16, dup_even);
  221|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  222|  1.35k|      const __m128i t1 = _mm_and_si128(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  218|  1.35k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  223|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  224|  1.35k|      const __m128i t2 = _mm_or_si128(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  218|  1.35k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  225|       |
  226|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  227|  1.35k|      const __m128i s0 = _mm_srli_epi16(in_16, 4);
  228|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  229|  1.35k|      const __m128i s1 = _mm_and_si128(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  218|  1.35k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  230|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  231|  1.35k|      const __m128i s2 = _mm_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  218|  1.35k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  232|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  233|  1.35k|      const __m128i s3 = _mm_or_si128(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  218|  1.35k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  234|  1.35k|      const __m128i m0 = _mm_andnot_si128(one_or_two_bytes_bytemask,
  235|  1.35k|                                          simdutf_vec(0b0100000000000000));
  ------------------
  |  |  218|  1.35k|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  236|  1.35k|      const __m128i s4 = _mm_xor_si128(s3, m0);
  237|  1.35k|#undef simdutf_vec
  238|       |
  239|       |      // 4. expand code units 16-bit => 32-bit
  240|  1.35k|      const __m128i out0 = _mm_unpacklo_epi16(t2, s4);
  241|  1.35k|      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|  1.35k|      const uint16_t mask =
  245|  1.35k|          (one_byte_bitmask & 0x5555) | (one_or_two_bytes_bitmask & 0xaaaa);
  246|  1.35k|      if (mask == 0) {
  ------------------
  |  Branch (246:11): [True: 630, False: 726]
  ------------------
  247|       |        // We only have three-byte code units. Use fast path.
  248|    630|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  249|    630|                                              15, 13, -1, -1, -1, -1);
  250|    630|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  251|    630|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  252|    630|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  253|    630|        utf8_output += 12;
  254|    630|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  255|    630|        utf8_output += 12;
  256|    630|        buf += 8;
  257|    630|        continue;
  258|    630|      }
  259|    726|      const uint8_t mask0 = uint8_t(mask);
  260|       |
  261|    726|      const uint8_t *row0 =
  262|    726|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  263|    726|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  264|    726|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  265|       |
  266|    726|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  267|       |
  268|    726|      const uint8_t *row1 =
  269|    726|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  270|    726|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  271|    726|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  272|       |
  273|    726|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  274|    726|      utf8_output += row0[0];
  275|    726|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  276|    726|      utf8_output += row1[0];
  277|       |
  278|    726|      buf += 8;
  279|  1.37k|    } 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|  1.37k|      size_t forward = 15;
  285|  1.37k|      size_t k = 0;
  286|  1.37k|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (286:11): [True: 0, False: 1.37k]
  ------------------
  287|      0|        forward = size_t(end - buf - 1);
  288|      0|      }
  289|  19.2k|      for (; k < forward; k++) {
  ------------------
  |  Branch (289:14): [True: 18.1k, False: 1.14k]
  ------------------
  290|  18.1k|        uint32_t word = buf[k];
  291|  18.1k|        if ((word & 0xFFFFFF80) == 0) {
  ------------------
  |  Branch (291:13): [True: 7.86k, False: 10.2k]
  ------------------
  292|  7.86k|          *utf8_output++ = char(word);
  293|  10.2k|        } else if ((word & 0xFFFFF800) == 0) {
  ------------------
  |  Branch (293:20): [True: 1.64k, False: 8.63k]
  ------------------
  294|  1.64k|          *utf8_output++ = char((word >> 6) | 0b11000000);
  295|  1.64k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  296|  8.63k|        } else if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (296:20): [True: 3.84k, False: 4.79k]
  ------------------
  297|  3.84k|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (297:15): [True: 1.55k, False: 2.29k]
  |  Branch (297:33): [True: 26, False: 1.52k]
  ------------------
  298|     26|            return std::make_pair(nullptr, utf8_output);
  299|     26|          }
  300|  3.81k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  301|  3.81k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  302|  3.81k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  303|  4.79k|        } else {
  304|  4.79k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (304:15): [True: 204, False: 4.58k]
  ------------------
  305|    204|            return std::make_pair(nullptr, utf8_output);
  306|    204|          }
  307|  4.58k|          *utf8_output++ = char((word >> 18) | 0b11110000);
  308|  4.58k|          *utf8_output++ = char(((word >> 12) & 0b111111) | 0b10000000);
  309|  4.58k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  310|  4.58k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  311|  4.58k|        }
  312|  18.1k|      }
  313|  1.14k|      buf += k;
  314|  1.14k|    }
  315|  2.72k|  } // while
  316|       |
  317|       |  // check for invalid input
  318|    678|  const __m128i v_10ffff = _mm_set1_epi32((uint32_t)0x10ffff);
  319|    678|  if (static_cast<uint16_t>(_mm_movemask_epi8(_mm_cmpeq_epi32(
  ------------------
  |  Branch (319:7): [True: 20, False: 658]
  ------------------
  320|    678|          _mm_max_epu32(running_max, v_10ffff), v_10ffff))) != 0xffff) {
  321|     20|    return std::make_pair(nullptr, utf8_output);
  322|     20|  }
  323|       |
  324|    658|  if (static_cast<uint32_t>(_mm_movemask_epi8(forbidden_bytemask)) != 0) {
  ------------------
  |  Branch (324:7): [True: 50, False: 608]
  ------------------
  325|     50|    return std::make_pair(nullptr, utf8_output);
  326|     50|  }
  327|       |
  328|    608|  return std::make_pair(buf, utf8_output);
  329|    658|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_137sse_convert_utf32_to_utf8_with_errorsEPKDimPc:
  333|    860|                                      char *utf8_output) {
  334|    860|  const char32_t *end = buf + len;
  335|    860|  const char32_t *start = buf;
  336|       |
  337|    860|  const __m128i v_0000 = _mm_setzero_si128();
  338|    860|  const __m128i v_f800 = _mm_set1_epi16((uint16_t)0xf800);
  339|    860|  const __m128i v_c080 = _mm_set1_epi16((uint16_t)0xc080);
  340|    860|  const __m128i v_ff80 = _mm_set1_epi16((uint16_t)0xff80);
  341|    860|  const __m128i v_ffff0000 = _mm_set1_epi32((uint32_t)0xffff0000);
  342|    860|  const __m128i v_7fffffff = _mm_set1_epi32((uint32_t)0x7fffffff);
  343|    860|  const __m128i v_10ffff = _mm_set1_epi32((uint32_t)0x10ffff);
  344|       |
  345|    860|  const size_t safety_margin =
  346|    860|      12; // to avoid overruns, see issue
  347|       |          // https://github.com/simdutf/simdutf/issues/92
  348|       |
  349|  3.90k|  while (end - buf >= std::ptrdiff_t(16 + safety_margin)) {
  ------------------
  |  Branch (349:10): [True: 3.22k, False: 674]
  ------------------
  350|       |    // We load two 16 bytes registers for a total of 32 bytes or 8 characters.
  351|  3.22k|    __m128i in = _mm_loadu_si128((__m128i *)buf);
  352|  3.22k|    __m128i nextin = _mm_loadu_si128((__m128i *)buf + 1);
  353|       |    // Check for too large input
  354|  3.22k|    __m128i max_input = _mm_max_epu32(_mm_max_epu32(in, nextin), v_10ffff);
  355|  3.22k|    if (static_cast<uint16_t>(_mm_movemask_epi8(
  ------------------
  |  Branch (355:9): [True: 56, False: 3.17k]
  ------------------
  356|  3.22k|            _mm_cmpeq_epi32(max_input, v_10ffff))) != 0xffff) {
  357|     56|      return std::make_pair(result(error_code::TOO_LARGE, buf - start),
  358|     56|                            utf8_output);
  359|     56|    }
  360|       |
  361|       |    // Pack 32-bit UTF-32 code units to 16-bit UTF-16 code units with unsigned
  362|       |    // saturation
  363|  3.17k|    __m128i in_16 = _mm_packus_epi32(_mm_and_si128(in, v_7fffffff),
  364|  3.17k|                                     _mm_and_si128(nextin, v_7fffffff));
  365|       |
  366|       |    // Try to apply UTF-16 => UTF-8 from ./sse_convert_utf16_to_utf8.cpp
  367|       |
  368|       |    // Check for ASCII fast path
  369|  3.17k|    if (_mm_testz_si128(in_16, v_ff80)) { // ASCII fast path!!!!
  ------------------
  |  Branch (369:9): [True: 1.09k, False: 2.07k]
  ------------------
  370|       |      // 1. pack the bytes
  371|       |      // obviously suboptimal.
  372|  1.09k|      const __m128i utf8_packed = _mm_packus_epi16(in_16, in_16);
  373|       |      // 2. store (16 bytes)
  374|  1.09k|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  375|       |      // 3. adjust pointers
  376|  1.09k|      buf += 8;
  377|  1.09k|      utf8_output += 8;
  378|  1.09k|      continue;
  379|  1.09k|    }
  380|       |
  381|       |    // no bits set above 7th bit
  382|  2.07k|    const __m128i one_byte_bytemask =
  383|  2.07k|        _mm_cmpeq_epi16(_mm_and_si128(in_16, v_ff80), v_0000);
  384|  2.07k|    const uint16_t one_byte_bitmask =
  385|  2.07k|        static_cast<uint16_t>(_mm_movemask_epi8(one_byte_bytemask));
  386|       |
  387|       |    // no bits set above 11th bit
  388|  2.07k|    const __m128i one_or_two_bytes_bytemask =
  389|  2.07k|        _mm_cmpeq_epi16(_mm_and_si128(in_16, v_f800), v_0000);
  390|  2.07k|    const uint16_t one_or_two_bytes_bitmask =
  391|  2.07k|        static_cast<uint16_t>(_mm_movemask_epi8(one_or_two_bytes_bytemask));
  392|       |
  393|  2.07k|    if (one_or_two_bytes_bitmask == 0xffff) {
  ------------------
  |  Branch (393:9): [True: 570, False: 1.50k]
  ------------------
  394|       |      // case: all code units either produce 1 or 2 UTF-8 bytes (at least one
  395|       |      // produces 2 bytes)
  396|       |      // 1. prepare 2-byte values
  397|       |      // input 16-bit word : [0000|0aaa|aabb|bbbb] x 8
  398|       |      // expected output   : [110a|aaaa|10bb|bbbb] x 8
  399|    570|      const __m128i v_1f00 = _mm_set1_epi16((int16_t)0x1f00);
  400|    570|      const __m128i v_003f = _mm_set1_epi16((int16_t)0x003f);
  401|       |
  402|       |      // t0 = [000a|aaaa|bbbb|bb00]
  403|    570|      const __m128i t0 = _mm_slli_epi16(in_16, 2);
  404|       |      // t1 = [000a|aaaa|0000|0000]
  405|    570|      const __m128i t1 = _mm_and_si128(t0, v_1f00);
  406|       |      // t2 = [0000|0000|00bb|bbbb]
  407|    570|      const __m128i t2 = _mm_and_si128(in_16, v_003f);
  408|       |      // t3 = [000a|aaaa|00bb|bbbb]
  409|    570|      const __m128i t3 = _mm_or_si128(t1, t2);
  410|       |      // t4 = [110a|aaaa|10bb|bbbb]
  411|    570|      const __m128i t4 = _mm_or_si128(t3, v_c080);
  412|       |
  413|       |      // 2. merge ASCII and 2-byte codewords
  414|    570|      const __m128i utf8_unpacked =
  415|    570|          _mm_blendv_epi8(t4, in_16, one_byte_bytemask);
  416|       |
  417|       |      // 3. prepare bitmask for 8-bit lookup
  418|       |      //    one_byte_bitmask = hhggffeeddccbbaa -- the bits are doubled (h -
  419|       |      //    MSB, a - LSB)
  420|    570|      const uint16_t m0 = one_byte_bitmask & 0x5555; // m0 = 0h0g0f0e0d0c0b0a
  421|    570|      const uint16_t m1 =
  422|    570|          static_cast<uint16_t>(m0 >> 7); // m1 = 00000000h0g0f0e0
  423|    570|      const uint8_t m2 =
  424|    570|          static_cast<uint8_t>((m0 | m1) & 0xff); // m2 =         hdgcfbea
  425|       |      // 4. pack the bytes
  426|    570|      const uint8_t *row =
  427|    570|          &simdutf::tables::utf16_to_utf8::pack_1_2_utf8_bytes[m2][0];
  428|    570|      const __m128i shuffle = _mm_loadu_si128((__m128i *)(row + 1));
  429|    570|      const __m128i utf8_packed = _mm_shuffle_epi8(utf8_unpacked, shuffle);
  430|       |
  431|       |      // 5. store bytes
  432|    570|      _mm_storeu_si128((__m128i *)utf8_output, utf8_packed);
  433|       |
  434|       |      // 6. adjust pointers
  435|    570|      buf += 8;
  436|    570|      utf8_output += row[0];
  437|    570|      continue;
  438|    570|    }
  439|       |
  440|       |    // Check for overflow in packing
  441|  1.50k|    const __m128i saturation_bytemask = _mm_cmpeq_epi32(
  442|  1.50k|        _mm_and_si128(_mm_or_si128(in, nextin), v_ffff0000), v_0000);
  443|  1.50k|    const uint32_t saturation_bitmask =
  444|  1.50k|        static_cast<uint32_t>(_mm_movemask_epi8(saturation_bytemask));
  445|       |
  446|  1.50k|    if (saturation_bitmask == 0xffff) {
  ------------------
  |  Branch (446:9): [True: 808, False: 696]
  ------------------
  447|       |      // case: code units from register produce either 1, 2 or 3 UTF-8 bytes
  448|       |
  449|       |      // Check for illegal surrogate code units
  450|    808|      const __m128i v_d800 = _mm_set1_epi16((uint16_t)0xd800);
  451|    808|      const __m128i forbidden_bytemask =
  452|    808|          _mm_cmpeq_epi16(_mm_and_si128(in_16, v_f800), v_d800);
  453|    808|      if (static_cast<uint32_t>(_mm_movemask_epi8(forbidden_bytemask)) != 0) {
  ------------------
  |  Branch (453:11): [True: 24, False: 784]
  ------------------
  454|     24|        return std::make_pair(result(error_code::SURROGATE, buf - start),
  455|     24|                              utf8_output);
  456|     24|      }
  457|       |
  458|    784|      const __m128i dup_even = _mm_setr_epi16(0x0000, 0x0202, 0x0404, 0x0606,
  459|    784|                                              0x0808, 0x0a0a, 0x0c0c, 0x0e0e);
  460|       |
  461|       |      /* In this branch we handle three cases:
  462|       |          1. [0000|0000|0ccc|cccc] => [0ccc|cccc]                           -
  463|       |        single UFT-8 byte
  464|       |          2. [0000|0bbb|bbcc|cccc] => [110b|bbbb], [10cc|cccc]              -
  465|       |        two UTF-8 bytes
  466|       |          3. [aaaa|bbbb|bbcc|cccc] => [1110|aaaa], [10bb|bbbb], [10cc|cccc] -
  467|       |        three UTF-8 bytes
  468|       |
  469|       |        We expand the input word (16-bit) into two code units (32-bit), thus
  470|       |        we have room for four bytes. However, we need five distinct bit
  471|       |        layouts. Note that the last byte in cases #2 and #3 is the same.
  472|       |
  473|       |        We precompute byte 1 for case #1 and the common byte for cases #2 & #3
  474|       |        in register t2.
  475|       |
  476|       |        We precompute byte 1 for case #3 and -- **conditionally** -- precompute
  477|       |        either byte 1 for case #2 or byte 2 for case #3. Note that they
  478|       |        differ by exactly one bit.
  479|       |
  480|       |        Finally from these two code units we build proper UTF-8 sequence, taking
  481|       |        into account the case (i.e, the number of bytes to write).
  482|       |      */
  483|       |      /**
  484|       |       * Given [aaaa|bbbb|bbcc|cccc] our goal is to produce:
  485|       |       * t2 => [0ccc|cccc] [10cc|cccc]
  486|       |       * s4 => [1110|aaaa] ([110b|bbbb] OR [10bb|bbbb])
  487|       |       */
  488|    784|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  489|       |      // [aaaa|bbbb|bbcc|cccc] => [bbcc|cccc|bbcc|cccc]
  490|    784|      const __m128i t0 = _mm_shuffle_epi8(in_16, dup_even);
  491|       |      // [bbcc|cccc|bbcc|cccc] => [00cc|cccc|0bcc|cccc]
  492|    784|      const __m128i t1 = _mm_and_si128(t0, simdutf_vec(0b0011111101111111));
  ------------------
  |  |  488|    784|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  493|       |      // [00cc|cccc|0bcc|cccc] => [10cc|cccc|0bcc|cccc]
  494|    784|      const __m128i t2 = _mm_or_si128(t1, simdutf_vec(0b1000000000000000));
  ------------------
  |  |  488|    784|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  495|       |
  496|       |      // [aaaa|bbbb|bbcc|cccc] =>  [0000|aaaa|bbbb|bbcc]
  497|    784|      const __m128i s0 = _mm_srli_epi16(in_16, 4);
  498|       |      // [0000|aaaa|bbbb|bbcc] => [0000|aaaa|bbbb|bb00]
  499|    784|      const __m128i s1 = _mm_and_si128(s0, simdutf_vec(0b0000111111111100));
  ------------------
  |  |  488|    784|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  500|       |      // [0000|aaaa|bbbb|bb00] => [00bb|bbbb|0000|aaaa]
  501|    784|      const __m128i s2 = _mm_maddubs_epi16(s1, simdutf_vec(0x0140));
  ------------------
  |  |  488|    784|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  502|       |      // [00bb|bbbb|0000|aaaa] => [11bb|bbbb|1110|aaaa]
  503|    784|      const __m128i s3 = _mm_or_si128(s2, simdutf_vec(0b1100000011100000));
  ------------------
  |  |  488|    784|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  504|    784|      const __m128i m0 = _mm_andnot_si128(one_or_two_bytes_bytemask,
  505|    784|                                          simdutf_vec(0b0100000000000000));
  ------------------
  |  |  488|    784|#define simdutf_vec(x) _mm_set1_epi16(static_cast<uint16_t>(x))
  ------------------
  506|    784|      const __m128i s4 = _mm_xor_si128(s3, m0);
  507|    784|#undef simdutf_vec
  508|       |
  509|       |      // 4. expand code units 16-bit => 32-bit
  510|    784|      const __m128i out0 = _mm_unpacklo_epi16(t2, s4);
  511|    784|      const __m128i out1 = _mm_unpackhi_epi16(t2, s4);
  512|       |
  513|       |      // 5. compress 32-bit code units into 1, 2 or 3 bytes -- 2 x shuffle
  514|    784|      const uint16_t mask =
  515|    784|          (one_byte_bitmask & 0x5555) | (one_or_two_bytes_bitmask & 0xaaaa);
  516|    784|      if (mask == 0) {
  ------------------
  |  Branch (516:11): [True: 462, False: 322]
  ------------------
  517|       |        // We only have three-byte code units. Use fast path.
  518|    462|        const __m128i shuffle = _mm_setr_epi8(2, 3, 1, 6, 7, 5, 10, 11, 9, 14,
  519|    462|                                              15, 13, -1, -1, -1, -1);
  520|    462|        const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle);
  521|    462|        const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle);
  522|    462|        _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  523|    462|        utf8_output += 12;
  524|    462|        _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  525|    462|        utf8_output += 12;
  526|    462|        buf += 8;
  527|    462|        continue;
  528|    462|      }
  529|    322|      const uint8_t mask0 = uint8_t(mask);
  530|       |
  531|    322|      const uint8_t *row0 =
  532|    322|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask0][0];
  533|    322|      const __m128i shuffle0 = _mm_loadu_si128((__m128i *)(row0 + 1));
  534|    322|      const __m128i utf8_0 = _mm_shuffle_epi8(out0, shuffle0);
  535|       |
  536|    322|      const uint8_t mask1 = static_cast<uint8_t>(mask >> 8);
  537|       |
  538|    322|      const uint8_t *row1 =
  539|    322|          &simdutf::tables::utf16_to_utf8::pack_1_2_3_utf8_bytes[mask1][0];
  540|    322|      const __m128i shuffle1 = _mm_loadu_si128((__m128i *)(row1 + 1));
  541|    322|      const __m128i utf8_1 = _mm_shuffle_epi8(out1, shuffle1);
  542|       |
  543|    322|      _mm_storeu_si128((__m128i *)utf8_output, utf8_0);
  544|    322|      utf8_output += row0[0];
  545|    322|      _mm_storeu_si128((__m128i *)utf8_output, utf8_1);
  546|    322|      utf8_output += row1[0];
  547|       |
  548|    322|      buf += 8;
  549|    696|    } else {
  550|       |      // case: at least one 32-bit word produce a surrogate pair in UTF-16 <=>
  551|       |      // will produce four UTF-8 bytes Let us do a scalar fallback. It may seem
  552|       |      // wasteful to use scalar code, but being efficient with SIMD in the
  553|       |      // presence of surrogate pairs may require non-trivial tables.
  554|    696|      size_t forward = 15;
  555|    696|      size_t k = 0;
  556|    696|      if (size_t(end - buf) < forward + 1) {
  ------------------
  |  Branch (556:11): [True: 0, False: 696]
  ------------------
  557|      0|        forward = size_t(end - buf - 1);
  558|      0|      }
  559|  10.5k|      for (; k < forward; k++) {
  ------------------
  |  Branch (559:14): [True: 9.92k, False: 590]
  ------------------
  560|  9.92k|        uint32_t word = buf[k];
  561|  9.92k|        if ((word & 0xFFFFFF80) == 0) {
  ------------------
  |  Branch (561:13): [True: 2.43k, False: 7.49k]
  ------------------
  562|  2.43k|          *utf8_output++ = char(word);
  563|  7.49k|        } else if ((word & 0xFFFFF800) == 0) {
  ------------------
  |  Branch (563:20): [True: 576, False: 6.91k]
  ------------------
  564|    576|          *utf8_output++ = char((word >> 6) | 0b11000000);
  565|    576|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  566|  6.91k|        } else if ((word & 0xFFFF0000) == 0) {
  ------------------
  |  Branch (566:20): [True: 1.68k, False: 5.22k]
  ------------------
  567|  1.68k|          if (word >= 0xD800 && word <= 0xDFFF) {
  ------------------
  |  Branch (567:15): [True: 856, False: 832]
  |  Branch (567:33): [True: 22, False: 834]
  ------------------
  568|     22|            return std::make_pair(
  569|     22|                result(error_code::SURROGATE, buf - start + k), utf8_output);
  570|     22|          }
  571|  1.66k|          *utf8_output++ = char((word >> 12) | 0b11100000);
  572|  1.66k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  573|  1.66k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  574|  5.22k|        } else {
  575|  5.22k|          if (word > 0x10FFFF) {
  ------------------
  |  Branch (575:15): [True: 84, False: 5.14k]
  ------------------
  576|     84|            return std::make_pair(
  577|     84|                result(error_code::TOO_LARGE, buf - start + k), utf8_output);
  578|     84|          }
  579|  5.14k|          *utf8_output++ = char((word >> 18) | 0b11110000);
  580|  5.14k|          *utf8_output++ = char(((word >> 12) & 0b111111) | 0b10000000);
  581|  5.14k|          *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
  582|  5.14k|          *utf8_output++ = char((word & 0b111111) | 0b10000000);
  583|  5.14k|        }
  584|  9.92k|      }
  585|    590|      buf += k;
  586|    590|    }
  587|  1.50k|  } // while
  588|    674|  return std::make_pair(result(error_code::SUCCESS, buf - start), utf8_output);
  589|    860|}

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

simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_128convert_masked_utf8_to_utf16ILNS_10endiannessE0EEEmPKcmRPDs:
   10|  3.46M|                                    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|  3.46M|  const __m128i swap =
   23|  3.46M|      _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   24|  3.46M|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   25|  3.46M|  const uint16_t input_utf8_end_of_code_point_mask =
   26|  3.46M|      utf8_end_of_code_point_mask & 0xfff;
   27|  3.46M|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (27:7): [True: 11.5k, False: 3.44M]
  ------------------
   28|       |    // We process the data in chunks of 12 bytes.
   29|       |    // Note: using 16 bytes is unsafe, see issue_ossfuzz_71218
   30|  11.5k|    __m128i ascii_first = _mm_cvtepu8_epi16(in);
   31|  11.5k|    __m128i ascii_second = _mm_cvtepu8_epi16(_mm_srli_si128(in, 8));
   32|  11.5k|    if (big_endian) {
  ------------------
  |  Branch (32:9): [Folded, False: 11.5k]
  ------------------
   33|      0|      ascii_first = _mm_shuffle_epi8(ascii_first, swap);
   34|      0|      ascii_second = _mm_shuffle_epi8(ascii_second, swap);
   35|      0|    }
   36|  11.5k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf16_output), ascii_first);
   37|  11.5k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf16_output + 8),
   38|  11.5k|                     ascii_second);
   39|  11.5k|    utf16_output += 12; // We wrote 12 16-bit characters.
   40|  11.5k|    return 12;          // We consumed 12 bytes.
   41|  11.5k|  }
   42|  3.44M|  if (((utf8_end_of_code_point_mask & 0xFFFF) == 0xaaaa)) {
  ------------------
  |  Branch (42:7): [True: 10.2k, False: 3.43M]
  ------------------
   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|  10.2k|    const __m128i sh =
   47|  10.2k|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   48|  10.2k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   49|  10.2k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   50|  10.2k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   51|  10.2k|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   52|  10.2k|    if (big_endian)
  ------------------
  |  Branch (52:9): [Folded, False: 10.2k]
  ------------------
   53|      0|      composed = _mm_shuffle_epi8(composed, swap);
   54|  10.2k|    _mm_storeu_si128((__m128i *)utf16_output, composed);
   55|  10.2k|    utf16_output += 8; // We wrote 16 bytes, 8 code points.
   56|  10.2k|    return 16;
   57|  10.2k|  }
   58|  3.43M|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (58:7): [True: 3.73k, False: 3.43M]
  ------------------
   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|  3.73k|    const __m128i sh =
   63|  3.73k|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   64|  3.73k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   65|  3.73k|    const __m128i ascii =
   66|  3.73k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   67|  3.73k|    const __m128i middlebyte =
   68|  3.73k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   69|  3.73k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   70|  3.73k|    const __m128i highbyte =
   71|  3.73k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   72|  3.73k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   73|  3.73k|    const __m128i composed =
   74|  3.73k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   75|  3.73k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
   76|  3.73k|    if (big_endian)
  ------------------
  |  Branch (76:9): [Folded, False: 3.73k]
  ------------------
   77|      0|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
   78|  3.73k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
   79|  3.73k|    utf16_output += 4;
   80|  3.73k|    return 12;
   81|  3.73k|  }
   82|       |  /// We do not have a fast path available, so we fallback.
   83|       |
   84|  3.43M|  const uint8_t idx =
   85|  3.43M|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   86|  3.43M|  const uint8_t consumed =
   87|  3.43M|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   88|  3.43M|  if (idx < 64) {
  ------------------
  |  Branch (88:7): [True: 2.88M, False: 547k]
  ------------------
   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|  2.88M|    const __m128i sh =
   96|  2.88M|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   97|  2.88M|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   98|  2.88M|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   99|  2.88M|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
  100|  2.88M|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
  101|  2.88M|    if (big_endian)
  ------------------
  |  Branch (101:9): [Folded, False: 2.88M]
  ------------------
  102|      0|      composed = _mm_shuffle_epi8(composed, swap);
  103|  2.88M|    _mm_storeu_si128((__m128i *)utf16_output, composed);
  104|  2.88M|    utf16_output += 6; // We wrote 12 bytes, 6 code points.
  105|  2.88M|  } else if (idx < 145) {
  ------------------
  |  Branch (105:14): [True: 492k, False: 54.5k]
  ------------------
  106|       |    // FOUR (4) input code-code units
  107|   492k|    const __m128i sh =
  108|   492k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  109|   492k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  110|   492k|    const __m128i ascii =
  111|   492k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
  112|   492k|    const __m128i middlebyte =
  113|   492k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  114|   492k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  115|   492k|    const __m128i highbyte =
  116|   492k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  117|   492k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  118|   492k|    const __m128i composed =
  119|   492k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  120|   492k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
  121|   492k|    if (big_endian)
  ------------------
  |  Branch (121:9): [Folded, False: 492k]
  ------------------
  122|      0|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
  123|   492k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
  124|   492k|    utf16_output += 4;
  125|   492k|  } else if (idx < 209) {
  ------------------
  |  Branch (125:14): [True: 53.4k, False: 1.14k]
  ------------------
  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|  53.4k|    const __m128i sh =
  137|  53.4k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  138|  53.4k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  139|  53.4k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  140|  53.4k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  141|  53.4k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  142|  53.4k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  143|       |    // correct for spurious high bit
  144|  53.4k|    const __m128i correct =
  145|  53.4k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  146|  53.4k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  147|  53.4k|    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|  53.4k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0xff000000));
  151|  53.4k|    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|  53.4k|    const __m128i composed =
  157|  53.4k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  158|  53.4k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  159|  53.4k|    const __m128i composedminus =
  160|  53.4k|        _mm_sub_epi32(composed, _mm_set1_epi32(0x10000));
  161|  53.4k|    const __m128i lowtenbits =
  162|  53.4k|        _mm_and_si128(composedminus, _mm_set1_epi32(0x3ff));
  163|       |    // Notice the 0x3ff mask:
  164|  53.4k|    const __m128i hightenbits =
  165|  53.4k|        _mm_and_si128(_mm_srli_epi32(composedminus, 10), _mm_set1_epi32(0x3ff));
  166|  53.4k|    const __m128i lowtenbitsadd =
  167|  53.4k|        _mm_add_epi32(lowtenbits, _mm_set1_epi32(0xDC00));
  168|  53.4k|    const __m128i hightenbitsadd =
  169|  53.4k|        _mm_add_epi32(hightenbits, _mm_set1_epi32(0xD800));
  170|  53.4k|    const __m128i lowtenbitsaddshifted = _mm_slli_epi32(lowtenbitsadd, 16);
  171|  53.4k|    __m128i surrogates = _mm_or_si128(hightenbitsadd, lowtenbitsaddshifted);
  172|  53.4k|    uint32_t basic_buffer[4];
  173|  53.4k|    uint32_t basic_buffer_swap[4];
  174|  53.4k|    if (big_endian) {
  ------------------
  |  Branch (174:9): [Folded, False: 53.4k]
  ------------------
  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|  53.4k|    _mm_storeu_si128((__m128i *)basic_buffer, composed);
  180|  53.4k|    uint32_t surrogate_buffer[4];
  181|  53.4k|    _mm_storeu_si128((__m128i *)surrogate_buffer, surrogates);
  182|   213k|    for (size_t i = 0; i < 3; i++) {
  ------------------
  |  Branch (182:24): [True: 160k, False: 53.4k]
  ------------------
  183|   160k|      if (basic_buffer[i] > 0x3c00000) {
  ------------------
  |  Branch (183:11): [True: 44.3k, False: 115k]
  ------------------
  184|  44.3k|        utf16_output[0] = uint16_t(surrogate_buffer[i] & 0xffff);
  185|  44.3k|        utf16_output[1] = uint16_t(surrogate_buffer[i] >> 16);
  186|  44.3k|        utf16_output += 2;
  187|   115k|      } else {
  188|   115k|        utf16_output[0] = big_endian ? uint16_t(basic_buffer_swap[i])
  ------------------
  |  Branch (188:27): [Folded, False: 115k]
  ------------------
  189|   115k|                                     : uint16_t(basic_buffer[i]);
  190|   115k|        utf16_output++;
  191|   115k|      }
  192|   160k|    }
  193|  53.4k|  } else {
  194|       |    // here we know that there is an error but we do not handle errors
  195|  1.14k|  }
  196|  3.43M|  return consumed;
  197|  3.43M|}
simdutf.cpp:_ZN7simdutf8westmere12_GLOBAL__N_128convert_masked_utf8_to_utf16ILNS_10endiannessE1EEEmPKcmRPDs:
   10|  2.93M|                                    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|  2.93M|  const __m128i swap =
   23|  2.93M|      _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   24|  2.93M|  const __m128i in = _mm_loadu_si128((__m128i *)input);
   25|  2.93M|  const uint16_t input_utf8_end_of_code_point_mask =
   26|  2.93M|      utf8_end_of_code_point_mask & 0xfff;
   27|  2.93M|  if (utf8_end_of_code_point_mask == 0xfff) {
  ------------------
  |  Branch (27:7): [True: 8.75k, False: 2.92M]
  ------------------
   28|       |    // We process the data in chunks of 12 bytes.
   29|       |    // Note: using 16 bytes is unsafe, see issue_ossfuzz_71218
   30|  8.75k|    __m128i ascii_first = _mm_cvtepu8_epi16(in);
   31|  8.75k|    __m128i ascii_second = _mm_cvtepu8_epi16(_mm_srli_si128(in, 8));
   32|  8.75k|    if (big_endian) {
  ------------------
  |  Branch (32:9): [True: 8.75k, Folded]
  ------------------
   33|  8.75k|      ascii_first = _mm_shuffle_epi8(ascii_first, swap);
   34|  8.75k|      ascii_second = _mm_shuffle_epi8(ascii_second, swap);
   35|  8.75k|    }
   36|  8.75k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf16_output), ascii_first);
   37|  8.75k|    _mm_storeu_si128(reinterpret_cast<__m128i *>(utf16_output + 8),
   38|  8.75k|                     ascii_second);
   39|  8.75k|    utf16_output += 12; // We wrote 12 16-bit characters.
   40|  8.75k|    return 12;          // We consumed 12 bytes.
   41|  8.75k|  }
   42|  2.92M|  if (((utf8_end_of_code_point_mask & 0xFFFF) == 0xaaaa)) {
  ------------------
  |  Branch (42:7): [True: 17.7k, False: 2.90M]
  ------------------
   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|  17.7k|    const __m128i sh =
   47|  17.7k|        _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
   48|  17.7k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   49|  17.7k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   50|  17.7k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
   51|  17.7k|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
   52|  17.7k|    if (big_endian)
  ------------------
  |  Branch (52:9): [True: 17.7k, Folded]
  ------------------
   53|  17.7k|      composed = _mm_shuffle_epi8(composed, swap);
   54|  17.7k|    _mm_storeu_si128((__m128i *)utf16_output, composed);
   55|  17.7k|    utf16_output += 8; // We wrote 16 bytes, 8 code points.
   56|  17.7k|    return 16;
   57|  17.7k|  }
   58|  2.90M|  if (input_utf8_end_of_code_point_mask == 0x924) {
  ------------------
  |  Branch (58:7): [True: 6.78k, False: 2.89M]
  ------------------
   59|       |    // We want to take 4 3-byte UTF-8 code units and turn them into 4 2-byte
   60|       |    // UTF-16 code units. There is probably a more efficient sequence, but the
   61|       |    // following might do.
   62|  6.78k|    const __m128i sh =
   63|  6.78k|        _mm_setr_epi8(2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1);
   64|  6.78k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   65|  6.78k|    const __m128i ascii =
   66|  6.78k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
   67|  6.78k|    const __m128i middlebyte =
   68|  6.78k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
   69|  6.78k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
   70|  6.78k|    const __m128i highbyte =
   71|  6.78k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
   72|  6.78k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
   73|  6.78k|    const __m128i composed =
   74|  6.78k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
   75|  6.78k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
   76|  6.78k|    if (big_endian)
  ------------------
  |  Branch (76:9): [True: 6.78k, Folded]
  ------------------
   77|  6.78k|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
   78|  6.78k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
   79|  6.78k|    utf16_output += 4;
   80|  6.78k|    return 12;
   81|  6.78k|  }
   82|       |  /// We do not have a fast path available, so we fallback.
   83|       |
   84|  2.89M|  const uint8_t idx =
   85|  2.89M|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][0];
   86|  2.89M|  const uint8_t consumed =
   87|  2.89M|      tables::utf8_to_utf16::utf8bigindex[input_utf8_end_of_code_point_mask][1];
   88|  2.89M|  if (idx < 64) {
  ------------------
  |  Branch (88:7): [True: 2.60M, False: 290k]
  ------------------
   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|  2.60M|    const __m128i sh =
   96|  2.60M|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
   97|  2.60M|    const __m128i perm = _mm_shuffle_epi8(in, sh);
   98|  2.60M|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi16(0x7f));
   99|  2.60M|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi16(0x1f00));
  100|  2.60M|    __m128i composed = _mm_or_si128(ascii, _mm_srli_epi16(highbyte, 2));
  101|  2.60M|    if (big_endian)
  ------------------
  |  Branch (101:9): [True: 2.60M, Folded]
  ------------------
  102|  2.60M|      composed = _mm_shuffle_epi8(composed, swap);
  103|  2.60M|    _mm_storeu_si128((__m128i *)utf16_output, composed);
  104|  2.60M|    utf16_output += 6; // We wrote 12 bytes, 6 code points.
  105|  2.60M|  } else if (idx < 145) {
  ------------------
  |  Branch (105:14): [True: 235k, False: 55.1k]
  ------------------
  106|       |    // FOUR (4) input code-code units
  107|   235k|    const __m128i sh =
  108|   235k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  109|   235k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  110|   235k|    const __m128i ascii =
  111|   235k|        _mm_and_si128(perm, _mm_set1_epi32(0x7f)); // 7 or 6 bits
  112|   235k|    const __m128i middlebyte =
  113|   235k|        _mm_and_si128(perm, _mm_set1_epi32(0x3f00)); // 5 or 6 bits
  114|   235k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  115|   235k|    const __m128i highbyte =
  116|   235k|        _mm_and_si128(perm, _mm_set1_epi32(0x0f0000)); // 4 bits
  117|   235k|    const __m128i highbyte_shifted = _mm_srli_epi32(highbyte, 4);
  118|   235k|    const __m128i composed =
  119|   235k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted), highbyte_shifted);
  120|   235k|    __m128i composed_repacked = _mm_packus_epi32(composed, composed);
  121|   235k|    if (big_endian)
  ------------------
  |  Branch (121:9): [True: 235k, Folded]
  ------------------
  122|   235k|      composed_repacked = _mm_shuffle_epi8(composed_repacked, swap);
  123|   235k|    _mm_storeu_si128((__m128i *)utf16_output, composed_repacked);
  124|   235k|    utf16_output += 4;
  125|   235k|  } else if (idx < 209) {
  ------------------
  |  Branch (125:14): [True: 54.0k, False: 1.16k]
  ------------------
  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|  54.0k|    const __m128i sh =
  137|  54.0k|        _mm_loadu_si128((const __m128i *)tables::utf8_to_utf16::shufutf8[idx]);
  138|  54.0k|    const __m128i perm = _mm_shuffle_epi8(in, sh);
  139|  54.0k|    const __m128i ascii = _mm_and_si128(perm, _mm_set1_epi32(0x7f));
  140|  54.0k|    const __m128i middlebyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f00));
  141|  54.0k|    const __m128i middlebyte_shifted = _mm_srli_epi32(middlebyte, 2);
  142|  54.0k|    __m128i middlehighbyte = _mm_and_si128(perm, _mm_set1_epi32(0x3f0000));
  143|       |    // correct for spurious high bit
  144|  54.0k|    const __m128i correct =
  145|  54.0k|        _mm_srli_epi32(_mm_and_si128(perm, _mm_set1_epi32(0x400000)), 1);
  146|  54.0k|    middlehighbyte = _mm_xor_si128(correct, middlehighbyte);
  147|  54.0k|    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|  54.0k|    const __m128i highbyte = _mm_and_si128(perm, _mm_set1_epi32(0xff000000));
  151|  54.0k|    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|  54.0k|    const __m128i composed =
  157|  54.0k|        _mm_or_si128(_mm_or_si128(ascii, middlebyte_shifted),
  158|  54.0k|                     _mm_or_si128(highbyte_shifted, middlehighbyte_shifted));
  159|  54.0k|    const __m128i composedminus =
  160|  54.0k|        _mm_sub_epi32(composed, _mm_set1_epi32(0x10000));
  161|  54.0k|    const __m128i lowtenbits =
  162|  54.0k|        _mm_and_si128(composedminus, _mm_set1_epi32(0x3ff));
  163|       |    // Notice the 0x3ff mask:
  164|  54.0k|    const __m128i hightenbits =
  165|  54.0k|        _mm_and_si128(_mm_srli_epi32(composedminus, 10), _mm_set1_epi32(0x3ff));
  166|  54.0k|    const __m128i lowtenbitsadd =
  167|  54.0k|        _mm_add_epi32(lowtenbits, _mm_set1_epi32(0xDC00));
  168|  54.0k|    const __m128i hightenbitsadd =
  169|  54.0k|        _mm_add_epi32(hightenbits, _mm_set1_epi32(0xD800));
  170|  54.0k|    const __m128i lowtenbitsaddshifted = _mm_slli_epi32(lowtenbitsadd, 16);
  171|  54.0k|    __m128i surrogates = _mm_or_si128(hightenbitsadd, lowtenbitsaddshifted);
  172|  54.0k|    uint32_t basic_buffer[4];
  173|  54.0k|    uint32_t basic_buffer_swap[4];
  174|  54.0k|    if (big_endian) {
  ------------------
  |  Branch (174:9): [True: 54.0k, Folded]
  ------------------
  175|  54.0k|      _mm_storeu_si128((__m128i *)basic_buffer_swap,
  176|  54.0k|                       _mm_shuffle_epi8(composed, swap));
  177|  54.0k|      surrogates = _mm_shuffle_epi8(surrogates, swap);
  178|  54.0k|    }
  179|  54.0k|    _mm_storeu_si128((__m128i *)basic_buffer, composed);
  180|  54.0k|    uint32_t surrogate_buffer[4];
  181|  54.0k|    _mm_storeu_si128((__m128i *)surrogate_buffer, surrogates);
  182|   216k|    for (size_t i = 0; i < 3; i++) {
  ------------------
  |  Branch (182:24): [True: 162k, False: 54.0k]
  ------------------
  183|   162k|      if (basic_buffer[i] > 0x3c00000) {
  ------------------
  |  Branch (183:11): [True: 45.2k, False: 116k]
  ------------------
  184|  45.2k|        utf16_output[0] = uint16_t(surrogate_buffer[i] & 0xffff);
  185|  45.2k|        utf16_output[1] = uint16_t(surrogate_buffer[i] >> 16);
  186|  45.2k|        utf16_output += 2;
  187|   116k|      } else {
  188|   116k|        utf16_output[0] = big_endian ? uint16_t(basic_buffer_swap[i])
  ------------------
  |  Branch (188:27): [True: 116k, Folded]
  ------------------
  189|   116k|                                     : uint16_t(basic_buffer[i]);
  190|   116k|        utf16_output++;
  191|   116k|      }
  192|   162k|    }
  193|  54.0k|  } else {
  194|       |    // here we know that there is an error but we do not handle errors
  195|  1.16k|  }
  196|  2.89M|  return consumed;
  197|  2.90M|}

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

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

