@@ -13,12 +13,12 @@ public unsafe class Utf8SIMDValidationTests
13
13
{
14
14
15
15
16
- private const int NumTrials = 1000 ;
16
+ private const int NumTrials = 100 ;
17
17
private static readonly RandomUtf8 generator = new RandomUtf8 ( 1234 , 1 , 1 , 1 , 1 ) ;
18
18
private static readonly Random rand = new Random ( ) ;
19
19
20
20
// int[] outputLengths = { 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024, 1088, 1152, 1216, 1280, 1344, 1408, 1472, 1536, 1600, 1664, 1728, 1792, 1856, 1920, 1984, 2048, 2112, 2176, 2240, 2304, 2368, 2432, 2496, 2560, 2624, 2688, 2752, 2816, 2880, 2944, 3008, 3072, 3136, 3200, 3264, 3328, 3392, 3456, 3520, 3584, 3648, 3712, 3776, 3840, 3904, 3968, 4032, 4096, 4160, 4224, 4288, 4352, 4416, 4480, 4544, 4608, 4672, 4736, 4800, 4864, 4928, 4992, 5056, 5120, 5184, 5248, 5312, 5376, 5440, 5504, 5568, 5632, 5696, 5760, 5824, 5888, 5952, 6016, 6080, 6144, 6208, 6272, 6336, 6400, 6464, 6528, 6592, 6656, 6720, 6784, 6848, 6912, 6976, 7040, 7104, 7168, 7232, 7296, 7360, 7424, 7488, 7552, 7616, 7680, 7744, 7808, 7872, 7936, 8000, 8064, 8128, 8192, 8256, 8320, 8384, 8448, 8512, 8576, 8640, 8704, 8768, 8832, 8896, 8960, 9024, 9088, 9152, 9216, 9280, 9344, 9408, 9472, 9536, 9600, 9664, 9728, 9792, 9856, 9920, 9984, 10000 };
21
- static int [ ] outputLengths = { 128 , 256 , 345 , 512 , 968 , 1024 , 1000 } ;
21
+ static int [ ] outputLengths = { 128 , 345 , 1000 } ;
22
22
23
23
[ Flags ]
24
24
public enum TestSystemRequirements
@@ -76,7 +76,7 @@ public TestIfCondition(Func<bool> condition, string skipReason)
76
76
77
77
78
78
79
- public void simpleGoodSequences ( Utf8ValidationDelegate utf8ValidationDelegate )
79
+ private void simpleGoodSequences ( Utf8ValidationDelegate utf8ValidationDelegate )
80
80
{
81
81
string [ ] goodSequences = {
82
82
"a" ,
@@ -144,7 +144,7 @@ public void simpleGoodSequencesAVX()
144
144
}
145
145
146
146
147
- public void BadSequences ( Utf8ValidationDelegate utf8ValidationDelegate )
147
+ private void BadSequences ( Utf8ValidationDelegate utf8ValidationDelegate )
148
148
{
149
149
string [ ] badSequences = {
150
150
"\xC3 \x28 " ,
@@ -231,13 +231,13 @@ public void BadSequencesAVX()
231
231
}
232
232
233
233
// this was in the C++ code
234
- public void Node48995Test ( Utf8ValidationDelegate utf8ValidationDelegate )
234
+ private void Node48995Test ( Utf8ValidationDelegate utf8ValidationDelegate )
235
235
{
236
236
byte [ ] bad = new byte [ ] { 0x80 } ;
237
237
Assert . False ( ValidateUtf8 ( bad , utf8ValidationDelegate ) ) ;
238
238
}
239
239
240
- public void NoError ( Utf8ValidationDelegate utf8ValidationDelegate )
240
+ private void NoError ( Utf8ValidationDelegate utf8ValidationDelegate )
241
241
{
242
242
foreach ( int outputLength in outputLengths )
243
243
{
@@ -299,7 +299,7 @@ public void NoErrorAVX()
299
299
NoError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
300
300
}
301
301
302
- public void NoErrorSpecificByteCount ( Utf8ValidationDelegate utf8ValidationDelegate )
302
+ private void NoErrorSpecificByteCount ( Utf8ValidationDelegate utf8ValidationDelegate )
303
303
{
304
304
RunTestForByteLength ( 1 , utf8ValidationDelegate ) ;
305
305
RunTestForByteLength ( 2 , utf8ValidationDelegate ) ;
@@ -369,7 +369,7 @@ public void NoErrorSpecificByteCountAVX()
369
369
NoErrorSpecificByteCount ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
370
370
}
371
371
372
- public void NoErrorIncompleteThenASCII ( Utf8ValidationDelegate utf8ValidationDelegate )
372
+ private void NoErrorIncompleteThenASCII ( Utf8ValidationDelegate utf8ValidationDelegate )
373
373
{
374
374
foreach ( int outputLength in outputLengths ) {
375
375
for ( int trial = 0 ; trial < NumTrials ; trial ++ )
@@ -438,20 +438,18 @@ public void NoErrorIncompleteThenASCIIScalar()
438
438
// NoErrorIncompleteThenASCII(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
439
439
// }
440
440
441
- [ Fact ]
442
- [ Trait ( "Category" , "avx" ) ]
441
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
443
442
public void NoErrorIncompleteThenASCIIAVX ( )
444
443
{
445
444
NoErrorIncompleteThenASCII ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
446
445
}
447
446
448
447
449
448
450
- public void NoErrorIncompleteAt256Vector ( Utf8ValidationDelegate utf8ValidationDelegate )
449
+ private void NoErrorIncompleteAt256Vector ( Utf8ValidationDelegate utf8ValidationDelegate )
451
450
{
452
- // foreach (int outputLength in outputLengths)
451
+ foreach ( int outputLength in outputLengths )
453
452
{
454
- int outputLength = 256 ;
455
453
for ( int trial = 0 ; trial < NumTrials ; trial ++ )
456
454
{
457
455
@@ -515,14 +513,13 @@ public void NoErrorIncompleteAt256VectorScalar()
515
513
// NoErrorIncompleteAt256Vector(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
516
514
// }
517
515
518
- [ Fact ]
519
- [ Trait ( "Category" , "avx" ) ]
516
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
520
517
public void NoErrorIncompleteAt256VectorAVX ( )
521
518
{
522
519
NoErrorIncompleteAt256Vector ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
523
520
}
524
521
525
- public void BadHeaderBits ( Utf8ValidationDelegate utf8ValidationDelegate )
522
+ private void BadHeaderBits ( Utf8ValidationDelegate utf8ValidationDelegate )
526
523
{
527
524
foreach ( int outputLength in outputLengths )
528
525
{
@@ -590,14 +587,13 @@ public void BadHeaderBitsScalar()
590
587
// NoErrorSpecificByteCount(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
591
588
// }
592
589
593
- [ Fact ]
594
- [ Trait ( "Category" , "avx" ) ]
590
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
595
591
public void BadHeaderBitsAVX ( )
596
592
{
597
593
BadHeaderBits ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
598
594
}
599
595
600
- public void TooShortError ( Utf8ValidationDelegate utf8ValidationDelegate )
596
+ private void TooShortError ( Utf8ValidationDelegate utf8ValidationDelegate )
601
597
{
602
598
foreach ( int outputLength in outputLengths )
603
599
{
@@ -663,14 +659,13 @@ public void TooShortErrorScalar()
663
659
// TooShortError(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
664
660
// }
665
661
666
- [ Fact ]
667
- [ Trait ( "Category" , "avx" ) ]
662
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
668
663
public void TooShortErrorAVX ( )
669
664
{
670
665
TooShortError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
671
666
}
672
667
673
- public void TooLongError ( Utf8ValidationDelegate utf8ValidationDelegate )
668
+ private void TooLongError ( Utf8ValidationDelegate utf8ValidationDelegate )
674
669
{
675
670
676
671
foreach ( int outputLength in outputLengths )
@@ -736,14 +731,13 @@ public void TooLongErrorScalar()
736
731
// TooLongError(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
737
732
// }
738
733
739
- [ Fact ]
740
- [ Trait ( "Category" , "avx" ) ]
734
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
741
735
public void TooLongErrorAVX ( )
742
736
{
743
737
TooLongError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
744
738
}
745
739
746
- public void OverlongError ( Utf8ValidationDelegate utf8ValidationDelegate )
740
+ private void OverlongError ( Utf8ValidationDelegate utf8ValidationDelegate )
747
741
{
748
742
for ( int trial = 0 ; trial < NumTrials ; trial ++ )
749
743
{
@@ -818,15 +812,14 @@ public void OverlongErrorScalar()
818
812
// OverlongError(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
819
813
// }
820
814
821
- [ Fact ]
822
- [ Trait ( "Category" , "avx" ) ]
815
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
823
816
public void OverlongErrorAVX ( )
824
817
{
825
818
OverlongError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
826
819
}
827
820
828
821
829
- public void TooShortErrorAtEnd ( Utf8ValidationDelegate utf8ValidationDelegate )
822
+ private void TooShortErrorAtEnd ( Utf8ValidationDelegate utf8ValidationDelegate )
830
823
{
831
824
for ( int trial = 0 ; trial < NumTrials ; trial ++ )
832
825
{
@@ -912,15 +905,15 @@ public void TooShortErrorAtEndAVX()
912
905
TooShortErrorAtEnd ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
913
906
}
914
907
915
- [ Fact ]
908
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
916
909
public void TooShortErrorAtEndAvx2 ( )
917
910
{
918
911
TooShortErrorAtEnd ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
919
912
}
920
913
921
914
922
915
//corresponds to condition 5.4.1 in the paper
923
- public void Invalid0xf50xff ( Utf8ValidationDelegate utf8ValidationDelegate )
916
+ private void Invalid0xf50xff ( Utf8ValidationDelegate utf8ValidationDelegate )
924
917
{
925
918
926
919
var invalidBytes = Enumerable . Range ( 0xF5 , 0x100 - 0xF5 ) . Select ( i => ( byte ) i ) . ToArray ( ) ; // 0xF5 to 0xFF
@@ -972,14 +965,13 @@ public void Invalid0xf50xffScalar()
972
965
// Invalid0xf50xff(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
973
966
// }
974
967
975
- [ Fact ]
976
- [ Trait ( "Category" , "avx" ) ]
968
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
977
969
public void Invalid0xf50xffAVX ( )
978
970
{
979
971
Invalid0xf50xff ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
980
972
}
981
973
982
- [ Fact ]
974
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
983
975
public void Invalid0xf50xffAvx2 ( )
984
976
{
985
977
Invalid0xf50xff ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
@@ -1049,7 +1041,7 @@ static void PrintHexAndBinary(byte[] bytes, int highlightIndex = -1)
1049
1041
}
1050
1042
1051
1043
1052
- public void TooLargeError ( Utf8ValidationDelegate utf8ValidationDelegate )
1044
+ private void TooLargeError ( Utf8ValidationDelegate utf8ValidationDelegate )
1053
1045
{
1054
1046
foreach ( int outputLength in outputLengths )
1055
1047
{
@@ -1106,15 +1098,14 @@ public void TooLargeErrorScalar()
1106
1098
// TooLargeError(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
1107
1099
// }
1108
1100
1109
- [ Fact ]
1110
- [ Trait ( "Category" , "avx" ) ]
1101
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
1111
1102
public void TooLargeErrorAvx ( )
1112
1103
{
1113
1104
TooLargeError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
1114
1105
}
1115
1106
1116
1107
1117
- public void AsciiPlusContinuationAtEndError ( Utf8ValidationDelegate utf8ValidationDelegate )
1108
+ private void AsciiPlusContinuationAtEndError ( Utf8ValidationDelegate utf8ValidationDelegate )
1118
1109
{
1119
1110
foreach ( int outputLength in outputLengths )
1120
1111
{
@@ -1169,20 +1160,19 @@ public void AsciiPlusContinuationAtEndErrorScalar()
1169
1160
// AsciiPlusContinuationAtEndError(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
1170
1161
// }
1171
1162
1172
- [ Fact ]
1173
- [ Trait ( "Category" , "avx" ) ]
1163
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
1174
1164
public void AsciiPlusContinuationAtEndErrorAVX ( )
1175
1165
{
1176
1166
AsciiPlusContinuationAtEndError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
1177
1167
}
1178
1168
1179
- [ Fact ]
1169
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
1180
1170
public void AsciiPlusContinuationAtEndErrorAvx2 ( )
1181
1171
{
1182
1172
AsciiPlusContinuationAtEndError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
1183
1173
}
1184
1174
1185
- public void SurrogateErrorTest ( Utf8ValidationDelegate utf8ValidationDelegate )
1175
+ private void SurrogateErrorTest ( Utf8ValidationDelegate utf8ValidationDelegate )
1186
1176
{
1187
1177
foreach ( int outputLength in outputLengths )
1188
1178
{
@@ -1249,15 +1239,14 @@ public void SurrogateErrorTestScalar()
1249
1239
// SurrogateErrorTest(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
1250
1240
// }
1251
1241
1252
- [ Fact ]
1253
- [ Trait ( "Category" , "avx" ) ]
1242
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
1254
1243
public void SurrogateErrorTestAVX ( )
1255
1244
{
1256
1245
SurrogateErrorTest ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
1257
1246
}
1258
1247
1259
1248
1260
- public void BruteForceTest ( Utf8ValidationDelegate utf8ValidationDelegate )
1249
+ private void BruteForceTest ( Utf8ValidationDelegate utf8ValidationDelegate )
1261
1250
{
1262
1251
foreach ( int outputLength in outputLengths )
1263
1252
{
@@ -1336,8 +1325,7 @@ public void BruteForceTestScalar()
1336
1325
// BruteForceTest(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
1337
1326
// }
1338
1327
1339
- [ Fact ]
1340
- [ Trait ( "Category" , "avx" ) ]
1328
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
1341
1329
public void BruteForceTestAVX ( )
1342
1330
{
1343
1331
BruteForceTest ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
0 commit comments