@@ -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" ,
@@ -137,15 +137,15 @@ public void simpleGoodSequencesScalar()
137
137
// simpleGoodSequences(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
138
138
// }
139
139
140
- [ Fact ]
141
140
[ Trait ( "Category" , "avx" ) ]
141
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
142
142
public void simpleGoodSequencesAVX ( )
143
143
{
144
144
simpleGoodSequences ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
145
145
}
146
146
147
147
148
- public void BadSequences ( Utf8ValidationDelegate utf8ValidationDelegate )
148
+ private void BadSequences ( Utf8ValidationDelegate utf8ValidationDelegate )
149
149
{
150
150
string [ ] badSequences = {
151
151
"\xC3 \x28 " ,
@@ -225,21 +225,21 @@ public void BadSequencesScalar()
225
225
// BadSequences(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
226
226
// }
227
227
228
- [ Fact ]
229
228
[ Trait ( "Category" , "avx" ) ]
229
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
230
230
public void BadSequencesAVX ( )
231
231
{
232
232
BadSequences ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
233
233
}
234
234
235
235
// this was in the C++ code
236
- public void Node48995Test ( Utf8ValidationDelegate utf8ValidationDelegate )
236
+ private void Node48995Test ( Utf8ValidationDelegate utf8ValidationDelegate )
237
237
{
238
238
byte [ ] bad = new byte [ ] { 0x80 } ;
239
239
Assert . False ( ValidateUtf8 ( bad , utf8ValidationDelegate ) ) ;
240
240
}
241
241
242
- public void NoError ( Utf8ValidationDelegate utf8ValidationDelegate )
242
+ private void NoError ( Utf8ValidationDelegate utf8ValidationDelegate )
243
243
{
244
244
foreach ( int outputLength in outputLengths )
245
245
{
@@ -295,14 +295,14 @@ public void NoErrorScalar()
295
295
// NoError(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
296
296
// }
297
297
298
- [ Fact ]
299
298
[ Trait ( "Category" , "avx" ) ]
299
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
300
300
public void NoErrorAVX ( )
301
301
{
302
302
NoError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
303
303
}
304
304
305
- public void NoErrorSpecificByteCount ( Utf8ValidationDelegate utf8ValidationDelegate )
305
+ private void NoErrorSpecificByteCount ( Utf8ValidationDelegate utf8ValidationDelegate )
306
306
{
307
307
RunTestForByteLength ( 1 , utf8ValidationDelegate ) ;
308
308
RunTestForByteLength ( 2 , utf8ValidationDelegate ) ;
@@ -366,14 +366,14 @@ public void NoErrorSpecificByteCountScalar()
366
366
// NoErrorSpecificByteCount(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
367
367
// }
368
368
369
- [ Fact ]
370
369
[ Trait ( "Category" , "avx" ) ]
370
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
371
371
public void NoErrorSpecificByteCountAVX ( )
372
372
{
373
373
NoErrorSpecificByteCount ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
374
374
}
375
375
376
- public void NoErrorIncompleteThenASCII ( Utf8ValidationDelegate utf8ValidationDelegate )
376
+ private void NoErrorIncompleteThenASCII ( Utf8ValidationDelegate utf8ValidationDelegate )
377
377
{
378
378
foreach ( int outputLength in outputLengths ) {
379
379
for ( int trial = 0 ; trial < NumTrials ; trial ++ )
@@ -442,20 +442,19 @@ public void NoErrorIncompleteThenASCIIScalar()
442
442
// NoErrorIncompleteThenASCII(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
443
443
// }
444
444
445
- [ Fact ]
446
445
[ Trait ( "Category" , "avx" ) ]
446
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
447
447
public void NoErrorIncompleteThenASCIIAVX ( )
448
448
{
449
449
NoErrorIncompleteThenASCII ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
450
450
}
451
451
452
452
453
453
454
- public void NoErrorIncompleteAt256Vector ( Utf8ValidationDelegate utf8ValidationDelegate )
454
+ private void NoErrorIncompleteAt256Vector ( Utf8ValidationDelegate utf8ValidationDelegate )
455
455
{
456
- // foreach (int outputLength in outputLengths)
456
+ foreach ( int outputLength in outputLengths )
457
457
{
458
- int outputLength = 256 ;
459
458
for ( int trial = 0 ; trial < NumTrials ; trial ++ )
460
459
{
461
460
@@ -519,14 +518,14 @@ public void NoErrorIncompleteAt256VectorScalar()
519
518
// NoErrorIncompleteAt256Vector(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
520
519
// }
521
520
522
- [ Fact ]
523
521
[ Trait ( "Category" , "avx" ) ]
522
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
524
523
public void NoErrorIncompleteAt256VectorAVX ( )
525
524
{
526
525
NoErrorIncompleteAt256Vector ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
527
526
}
528
527
529
- public void BadHeaderBits ( Utf8ValidationDelegate utf8ValidationDelegate )
528
+ private void BadHeaderBits ( Utf8ValidationDelegate utf8ValidationDelegate )
530
529
{
531
530
foreach ( int outputLength in outputLengths )
532
531
{
@@ -594,14 +593,14 @@ public void BadHeaderBitsScalar()
594
593
// NoErrorSpecificByteCount(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
595
594
// }
596
595
597
- [ Fact ]
598
596
[ Trait ( "Category" , "avx" ) ]
597
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
599
598
public void BadHeaderBitsAVX ( )
600
599
{
601
600
BadHeaderBits ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
602
601
}
603
602
604
- public void TooShortError ( Utf8ValidationDelegate utf8ValidationDelegate )
603
+ private void TooShortError ( Utf8ValidationDelegate utf8ValidationDelegate )
605
604
{
606
605
foreach ( int outputLength in outputLengths )
607
606
{
@@ -667,14 +666,14 @@ public void TooShortErrorScalar()
667
666
// TooShortError(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
668
667
// }
669
668
670
- [ Fact ]
671
669
[ Trait ( "Category" , "avx" ) ]
670
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
672
671
public void TooShortErrorAVX ( )
673
672
{
674
673
TooShortError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
675
674
}
676
675
677
- public void TooLongError ( Utf8ValidationDelegate utf8ValidationDelegate )
676
+ private void TooLongError ( Utf8ValidationDelegate utf8ValidationDelegate )
678
677
{
679
678
680
679
foreach ( int outputLength in outputLengths )
@@ -740,14 +739,14 @@ public void TooLongErrorScalar()
740
739
// TooLongError(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
741
740
// }
742
741
743
- [ Fact ]
744
742
[ Trait ( "Category" , "avx" ) ]
743
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
745
744
public void TooLongErrorAVX ( )
746
745
{
747
746
TooLongError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
748
747
}
749
748
750
- public void OverlongError ( Utf8ValidationDelegate utf8ValidationDelegate )
749
+ private void OverlongError ( Utf8ValidationDelegate utf8ValidationDelegate )
751
750
{
752
751
for ( int trial = 0 ; trial < NumTrials ; trial ++ )
753
752
{
@@ -822,15 +821,15 @@ public void OverlongErrorScalar()
822
821
// OverlongError(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
823
822
// }
824
823
825
- [ Fact ]
826
824
[ Trait ( "Category" , "avx" ) ]
825
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
827
826
public void OverlongErrorAVX ( )
828
827
{
829
828
OverlongError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
830
829
}
831
830
832
831
833
- public void TooShortErrorAtEnd ( Utf8ValidationDelegate utf8ValidationDelegate )
832
+ private void TooShortErrorAtEnd ( Utf8ValidationDelegate utf8ValidationDelegate )
834
833
{
835
834
for ( int trial = 0 ; trial < NumTrials ; trial ++ )
836
835
{
@@ -909,22 +908,23 @@ public void TooShortErrorAtEndScalar()
909
908
// TooShortErrorAtEnd(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
910
909
// }
911
910
912
- [ Fact ]
913
911
[ Trait ( "Category" , "avx" ) ]
912
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
914
913
public void TooShortErrorAtEndAVX ( )
915
914
{
916
915
TooShortErrorAtEnd ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
917
916
}
918
917
919
- [ Fact ]
918
+ [ Trait ( "Category" , "avx" ) ]
919
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
920
920
public void TooShortErrorAtEndAvx2 ( )
921
921
{
922
922
TooShortErrorAtEnd ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
923
923
}
924
924
925
925
926
926
//corresponds to condition 5.4.1 in the paper
927
- public void Invalid0xf50xff ( Utf8ValidationDelegate utf8ValidationDelegate )
927
+ private void Invalid0xf50xff ( Utf8ValidationDelegate utf8ValidationDelegate )
928
928
{
929
929
930
930
var invalidBytes = Enumerable . Range ( 0xF5 , 0x100 - 0xF5 ) . Select ( i => ( byte ) i ) . ToArray ( ) ; // 0xF5 to 0xFF
@@ -976,14 +976,15 @@ public void Invalid0xf50xffScalar()
976
976
// Invalid0xf50xff(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
977
977
// }
978
978
979
- [ Fact ]
980
979
[ Trait ( "Category" , "avx" ) ]
980
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
981
981
public void Invalid0xf50xffAVX ( )
982
982
{
983
983
Invalid0xf50xff ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
984
984
}
985
985
986
- [ Fact ]
986
+ [ Trait ( "Category" , "avx" ) ]
987
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
987
988
public void Invalid0xf50xffAvx2 ( )
988
989
{
989
990
Invalid0xf50xff ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
@@ -1053,7 +1054,7 @@ static void PrintHexAndBinary(byte[] bytes, int highlightIndex = -1)
1053
1054
}
1054
1055
1055
1056
1056
- public void TooLargeError ( Utf8ValidationDelegate utf8ValidationDelegate )
1057
+ private void TooLargeError ( Utf8ValidationDelegate utf8ValidationDelegate )
1057
1058
{
1058
1059
foreach ( int outputLength in outputLengths )
1059
1060
{
@@ -1110,15 +1111,15 @@ public void TooLargeErrorScalar()
1110
1111
// TooLargeError(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
1111
1112
// }
1112
1113
1113
- [ Fact ]
1114
1114
[ Trait ( "Category" , "avx" ) ]
1115
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
1115
1116
public void TooLargeErrorAvx ( )
1116
1117
{
1117
1118
TooLargeError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
1118
1119
}
1119
1120
1120
1121
1121
- public void AsciiPlusContinuationAtEndError ( Utf8ValidationDelegate utf8ValidationDelegate )
1122
+ private void AsciiPlusContinuationAtEndError ( Utf8ValidationDelegate utf8ValidationDelegate )
1122
1123
{
1123
1124
foreach ( int outputLength in outputLengths )
1124
1125
{
@@ -1173,20 +1174,21 @@ public void AsciiPlusContinuationAtEndErrorScalar()
1173
1174
// AsciiPlusContinuationAtEndError(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
1174
1175
// }
1175
1176
1176
- [ Fact ]
1177
1177
[ Trait ( "Category" , "avx" ) ]
1178
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
1178
1179
public void AsciiPlusContinuationAtEndErrorAVX ( )
1179
1180
{
1180
1181
AsciiPlusContinuationAtEndError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
1181
1182
}
1182
1183
1183
- [ Fact ]
1184
+ [ Trait ( "Category" , "avx" ) ]
1185
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
1184
1186
public void AsciiPlusContinuationAtEndErrorAvx2 ( )
1185
1187
{
1186
1188
AsciiPlusContinuationAtEndError ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
1187
1189
}
1188
1190
1189
- public void SurrogateErrorTest ( Utf8ValidationDelegate utf8ValidationDelegate )
1191
+ private void SurrogateErrorTest ( Utf8ValidationDelegate utf8ValidationDelegate )
1190
1192
{
1191
1193
foreach ( int outputLength in outputLengths )
1192
1194
{
@@ -1253,15 +1255,15 @@ public void SurrogateErrorTestScalar()
1253
1255
// SurrogateErrorTest(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
1254
1256
// }
1255
1257
1256
- [ Fact ]
1257
1258
[ Trait ( "Category" , "avx" ) ]
1259
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
1258
1260
public void SurrogateErrorTestAVX ( )
1259
1261
{
1260
1262
SurrogateErrorTest ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
1261
1263
}
1262
1264
1263
1265
1264
- public void BruteForceTest ( Utf8ValidationDelegate utf8ValidationDelegate )
1266
+ private void BruteForceTest ( Utf8ValidationDelegate utf8ValidationDelegate )
1265
1267
{
1266
1268
foreach ( int outputLength in outputLengths )
1267
1269
{
@@ -1340,8 +1342,8 @@ public void BruteForceTestScalar()
1340
1342
// BruteForceTest(SimdUnicode.UTF8.GetPointerToFirstInvalidByteArm64);
1341
1343
// }
1342
1344
1343
- [ Fact ]
1344
1345
[ Trait ( "Category" , "avx" ) ]
1346
+ [ FactOnSystemRequirementAttribute ( TestSystemRequirements . X64Avx2 ) ]
1345
1347
public void BruteForceTestAVX ( )
1346
1348
{
1347
1349
BruteForceTest ( SimdUnicode . UTF8 . GetPointerToFirstInvalidByteAvx2 ) ;
0 commit comments