Skip to content

Commit fa40745

Browse files
Nick-NuonDaniel Lemirelemire
authored
Latin1 <=> UTF-X conversion + tests + benchmarks (simdutf#247)
* Validate latin * Added Latin1 <=> UTF-X, tests TBD * UTF -X <=> Latin1 conversions, test TBD * Most Latin1 <=> UTF-X now passes compilation * Implemented UTF32 => latin1 for archs on my CPU * "Hello world" test UTF32 => Latin1 * Mostly works * UTF32 => Latin1 test compiling but test failing * Got a segfault here. * Fixed segfault * Less verbosity * Same * utf32 => Latin1 large input test * test for Latin1 => UTF32 test. WIP * fixed tests * UTF32 => latin1 valid tests WIP * Done with UTF 32 <=> Latin1 ? * valid utf32 => latin1 tests * UTF8 => Latin1 mostly done. Need tests. * more tests for UTF8 => Latin1 * Some more tests * UTF8 => Latin1 with errors tests * 4_byte too large test UTF8=>latin1 working * utf8 => latin1 too_large_input test works * Header bits test work + small fixes * UTF8 =>Latin1 /w errors test done * utf8 => latin1 convert_valid tests done * latin1 => UTF8 tests * utf16le => latin1 tests * utf16le => Latin1 with errors tests * utf16le => latin1 tests * utf16be => Latin1 tests * latin1 => utf16be tests * utf8 => Latin1 benchmarks * fixing icu test attempt * icu benchmark test * Various minor fixes * partial cleanup * More cleaning up * buggy cleanup * better safe than sorry increnemental cleanup * Very incremental cleanup that copiles #2 * Slowly but surely! * Small, sure,safe & incremental * More incremental cleanup * More increments * More increments * More increments * More increments * Preliminary Cleanup done * Minor adjustment * Latin1 => utf8 benchmarks (untested) * latin1 => utf16le bench untested * latin1 => utf32 benchmark + basic tests * utf16 => latin1 benchmark * utf32 => Latin1 benchmark * fix wrong size causing segfaults... * Latin1 => utf8 icu * latin1 => utf16 iconv (prev was also iconv) * Latin1 =>Utf32 iconv * Latin1 => UTF16 Iconv bench * UTF32 => Latin1 Iconv * latin1 => utf8 icu bench * Fix some buffer overflow errors * Fixes to latin1 => UTF-16 bench * Latin1 => UTF32 icu bench * UTF16 => Latin1 ICU * UTF32 => Latin1 ICU benches * Working UTF16 =>Latin1 icu bench * utf32 => Latin1 Icu working * Some fixes * Some fixes to benches + modest README changes * README done + minor changes * More ICU checks for safety * Remove comments * fixes * Various fixes on the latin 1 branch * Fixes. * latin1_from_utf16 unused parameter deletion * latin1_from_utf32 unused parameter deletion * utf32 length from latin1 unused parameter deletion * fixes * utf16 length from latin1 unusued parameter deletion * more parameter deletion * more parameter deletions * Windows fixes * arm64 dummy/scalar implementation * More windows fixes * Update tests/convert_utf32_to_latin1_with_errors_tests.cpp Co-authored-by: Daniel Lemire <daniel@lemire.me> * Update tests/convert_utf32_to_latin1_tests.cpp Co-authored-by: Daniel Lemire <daniel@lemire.me> * partial fixes * Remove extraneous comments added by mistake * remove extraneous comments * Windows Fixes/fix utf32 => latin1 tests * CMakeLists fixes * More fixes * Yet more fixes * Made tests deterministic again + removed comments * More Windows fixes * s390/big endian fixes * Windows fixes * Cleaned up comments --------- Co-authored-by: Daniel Lemire <dlemire@lemire.me> Co-authored-by: Daniel Lemire <daniel@lemire.me>
1 parent b470795 commit fa40745

70 files changed

Lines changed: 5384 additions & 106 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 233 additions & 19 deletions
Large diffs are not rendered by default.

benchmarks/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT MINGW)
5656
target_link_libraries(simdutf_benchmarks_benchmark PUBLIC stdc++fs)
5757
endif()
5858

59-
target_link_libraries(simdutf_benchmarks_benchmark PUBLIC simdutf simdutf::tests::helpers)
59+
target_link_libraries(simdutf_benchmarks_benchmark PUBLIC simdutf simdutf::tests::helpers)
6060

6161
add_library(simdutf::benchmarks::benchmark ALIAS simdutf_benchmarks_benchmark)

benchmarks/src/apple_arm_events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ struct AppleEvents {
11121112
u64 val = counters_1[idx] - counters_0[idx];
11131113
printf("%14s: %llu\n", alias->alias, val);
11141114
}*/
1115-
return performance_counters{
1115+
return performance_counters {
11161116
counters_0[counter_map[0]], counters_0[counter_map[3]],
11171117
counters_0[counter_map[2]], counters_0[counter_map[1]]};
11181118
}

benchmarks/src/benchmark.cpp

Lines changed: 972 additions & 20 deletions
Large diffs are not rendered by default.

benchmarks/src/benchmark.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <unicode/uconfig.h>
2323
#include <unicode/platform.h>
2424
#include <unicode/unistr.h>
25+
#include <unicode/ucnv.h>
2526
#endif
2627

2728
#if ICONV_AVAILABLE
@@ -69,36 +70,60 @@ namespace simdutf::benchmarks {
6970
void run_validate_utf32_with_errors(const simdutf::implementation& implementation, size_t iterations);
7071
void run_count_utf8(const simdutf::implementation& implementation, size_t iterations);
7172
void run_count_utf16(const simdutf::implementation& implementation, size_t iterations);
73+
void run_convert_latin1_to_utf8(const simdutf::implementation& implementation, size_t iterations);
74+
void run_convert_latin1_to_utf16(const simdutf::implementation& implementation, size_t iterations);
75+
void run_convert_latin1_to_utf32(const simdutf::implementation& implementation, size_t iterations);
76+
void run_convert_utf8_to_latin1(const simdutf::implementation& implementation, size_t iterations);
77+
void run_convert_utf8_to_latin1_with_errors(const simdutf::implementation& implementation, size_t iterations);
7278
void run_convert_utf8_to_utf16(const simdutf::implementation& implementation, size_t iterations);
7379
void run_convert_utf8_to_utf16_with_errors(const simdutf::implementation& implementation, size_t iterations);
7480
void run_convert_utf8_to_utf32(const simdutf::implementation& implementation, size_t iterations);
7581
void run_convert_utf8_to_utf32_with_errors(const simdutf::implementation& implementation, size_t iterations);
7682
void run_convert_utf8_to_utf16_with_dynamic_allocation(const simdutf::implementation& implementation, size_t iterations);
7783
void run_convert_utf8_to_utf32_with_dynamic_allocation(const simdutf::implementation& implementation, size_t iterations);
84+
void run_convert_valid_utf8_to_latin1(const simdutf::implementation& implementation, size_t iterations);
7885
void run_convert_valid_utf8_to_utf16(const simdutf::implementation& implementation, size_t iterations);
7986
void run_convert_valid_utf8_to_utf32(const simdutf::implementation& implementation, size_t iterations);
87+
void run_convert_utf16_to_latin1(const simdutf::implementation& implementation, size_t iterations);
88+
void run_convert_utf16_to_latin1_with_errors(const simdutf::implementation& implementation, size_t iterations);
8089
void run_convert_utf16_to_utf8(const simdutf::implementation& implementation, size_t iterations);
8190
void run_convert_utf16_to_utf8_with_errors(const simdutf::implementation& implementation, size_t iterations);
8291
void run_convert_utf16_to_utf32(const simdutf::implementation& implementation, size_t iterations);
8392
void run_convert_utf16_to_utf32_with_errors(const simdutf::implementation& implementation, size_t iterations);
8493
void run_convert_utf16_to_utf8_with_dynamic_allocation(const simdutf::implementation& implementation, size_t iterations);
8594
void run_convert_utf16_to_utf32_with_dynamic_allocation(const simdutf::implementation& implementation, size_t iterations);
95+
void run_convert_valid_utf16_to_latin1(const simdutf::implementation& implementation, size_t iterations);
8696
void run_convert_valid_utf16_to_utf8(const simdutf::implementation& implementation, size_t iterations);
97+
void run_convert_utf32_to_latin1(const simdutf::implementation& implementation, size_t iterations);
98+
void run_convert_utf32_to_latin1_with_errors(const simdutf::implementation& implementation, size_t iterations);
8799
void run_convert_utf32_to_utf8(const simdutf::implementation& implementation, size_t iterations);
88100
void run_convert_utf32_to_utf8_with_errors(const simdutf::implementation& implementation, size_t iterations);
101+
void run_convert_valid_utf32_to_latin1(const simdutf::implementation& implementation, size_t iterations);
89102
void run_convert_valid_utf32_to_utf8(const simdutf::implementation& implementation, size_t iterations);
90103
void run_convert_utf32_to_utf16(const simdutf::implementation& implementation, size_t iterations);
91104
void run_convert_utf32_to_utf16_with_errors(const simdutf::implementation& implementation, size_t iterations);
92105
void run_convert_valid_utf32_to_utf16(const simdutf::implementation& implementation, size_t iterations);
93106
void run_convert_valid_utf16_to_utf32(const simdutf::implementation& implementation, size_t iterations);
94107
void run_detect_encodings(const simdutf::implementation& implementation, size_t iterations);
95108
#if ICU_AVAILABLE
109+
void run_convert_latin1_to_utf8_icu(size_t iterations);
110+
void run_convert_latin1_to_utf16_icu(size_t iterations);
111+
void run_convert_latin1_to_utf32_icu(size_t iterations);
112+
void run_convert_utf8_to_latin1_icu(size_t iterations);
96113
void run_convert_utf8_to_utf16_icu(size_t iterations);
97114
void run_convert_utf16_to_utf8_icu(size_t iterations);
115+
void run_convert_utf16_to_latin1_icu(size_t iterations);
116+
void run_convert_utf32_to_latin1_icu(size_t iterations);
98117
#endif
99118
#if ICONV_AVAILABLE
119+
void run_convert_latin1_to_utf8_iconv(size_t iterations);
120+
void run_convert_latin1_to_utf16_iconv(size_t iterations);
121+
void run_convert_latin1_to_utf32_iconv(size_t iterations);
122+
void run_convert_utf8_to_latin1_iconv(size_t iterations);
100123
void run_convert_utf8_to_utf16_iconv(size_t iterations);
101124
void run_convert_utf16_to_utf8_iconv(size_t iterations);
125+
void run_convert_utf16_to_latin1_iconv(size_t iterations);
126+
void run_convert_utf32_to_latin1_iconv(size_t iterations);
102127
#endif
103128
#ifdef INOUE2008
104129
/**

include/simdutf/encoding_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum encoding_type {
88
UTF16_BE = 4, // BOM 0xfe 0xff
99
UTF32_LE = 8, // BOM 0xff 0xfe 0x00 0x00
1010
UTF32_BE = 16, // BOM 0x00 0x00 0xfe 0xff
11+
Latin1 = 32,
1112

1213
unspecified = 0
1314
};

include/simdutf/error.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ enum error_code {
1010
TOO_LONG, // We either have too many consecutive continuation bytes or the string starts with a continuation byte.
1111
OVERLONG, // The decoded character must be above U+7F for two-byte characters, U+7FF for three-byte characters,
1212
// and U+FFFF for four-byte characters.
13-
TOO_LARGE, // The decoded character must be less than or equal to U+10FFFF OR less than or equal than U+7F for ASCII.
13+
TOO_LARGE, // The decoded character must be less than or equal to U+10FFFF,less than or equal than U+7F for ASCII OR less than equal than U+FF for Latin1
1414
SURROGATE, // The decoded character must be not be in U+D800...DFFF (UTF-8 or UTF-32) OR
15-
// a high surrogate must be followed by a low surrogate and a low surrogate must be preceded by a high surrogate (UTF-16)
15+
// a high surrogate must be followed by a low surrogate and a low surrogate must be preceded by a high surrogate (UTF-16) OR
16+
// there must be no surrogate at all (Latin1)
1617
OTHER // Not related to validation/transcoding.
1718
};
1819

0 commit comments

Comments
 (0)