@@ -10,12 +10,6 @@ namespace SimdUnicode
1010 public static class UTF8
1111 {
1212
13- public static void ToString ( Vector128 < byte > v )
14- {
15- Span < byte > b = stackalloc byte [ 16 ] ;
16- v . CopyTo ( b ) ;
17- // Console .WriteLine(Convert.ToHexString(b));
18- }
1913
2014 // Returns &inputBuffer[inputLength] if the input buffer is valid.
2115 /// <summary>
@@ -42,11 +36,10 @@ public static void ToString(Vector128<byte> v)
4236 {
4337 return GetPointerToFirstInvalidByteAvx512(pInputBuffer, inputLength);
4438 }*/
45- // if (Ssse3.IsSupported)
46- // {
47- // return GetPointerToFirstInvalidByteSse(pInputBuffer, inputLength);
48- // }
49- // return GetPointerToFirstInvalidByteScalar(pInputBuffer, inputLength);
39+ if ( Ssse3 . IsSupported )
40+ {
41+ return GetPointerToFirstInvalidByteSse ( pInputBuffer , inputLength , out Utf16CodeUnitCountAdjustment , out ScalarCodeUnitCountAdjustment ) ;
42+ }
5043
5144 return GetPointerToFirstInvalidByteScalar ( pInputBuffer , inputLength , out Utf16CodeUnitCountAdjustment , out ScalarCodeUnitCountAdjustment ) ;
5245
@@ -480,7 +473,6 @@ private unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust
480473
481474 public unsafe static byte * GetPointerToFirstInvalidByteSse ( byte * pInputBuffer , int inputLength , out int utf16CodeUnitCountAdjustment , out int scalarCountAdjustment )
482475 {
483- // Console .WriteLine("-------------------Calling function--------------------");
484476 int processedLength = 0 ;
485477 if ( pInputBuffer == null || inputLength <= 0 )
486478 {
@@ -510,7 +502,6 @@ private unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust
510502
511503 if ( processedLength + 16 < inputLength )
512504 {
513- // Console .WriteLine("-------SIMD kicking in-------");
514505 Vector128 < byte > prevInputBlock = Vector128 < byte > . Zero ;
515506
516507 Vector128 < byte > maxValue = Vector128 . Create (
@@ -591,23 +582,17 @@ private unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust
591582 int n4 = 0 ; // number of 4-byte sequences that start in this block
592583 for ( ; processedLength + 16 <= inputLength ; processedLength += 16 )
593584 {
594- // Console .WriteLine($"Processing {processedLength} bytes", processedLength);
595585
596586 Vector128 < byte > currentBlock = Avx . LoadVector128 ( pInputBuffer + processedLength ) ;
597587 int mask = Sse42 . MoveMask ( currentBlock ) ;
598- // ToString (currentBlock);
599- // // Console .WriteLine($"{mask}");
600588 if ( mask == 0 )
601589 {
602590 // We have an ASCII block, no need to process it, but
603591 // we need to check if the previous block was incomplete.
604592 //
605593
606- // Console .WriteLine("Found all ASCII");
607- // ToString(prevIncomplete);
608594 if ( ! Sse41 . TestZ ( prevIncomplete , prevIncomplete ) )
609595 {
610- // // Console .WriteLine($"Found all-ascii but previous is incomplete.Triggering Rewind");
611596 int off = processedLength >= 3 ? processedLength - 3 : processedLength ;
612597 byte * invalidBytePointer = SimdUnicode . UTF8 . SimpleRewindAndValidateWithErrors ( 16 - 3 , pInputBuffer + processedLength - 3 , inputLength - processedLength + 3 ) ;
613598 // So the code is correct up to invalidBytePointer
@@ -627,7 +612,6 @@ private unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust
627612 }
628613 else // Contains non-ASCII characters, we need to do non-trivial processing
629614 {
630- // Console .WriteLine("Contains ASCII characters, firing standard SIMD routine");
631615 // Use SubtractSaturate to effectively compare if bytes in block are greater than markers.
632616 // Contains non-ASCII characters, we need to do non-trivial processing
633617 Vector128 < byte > prev1 = Ssse3 . AlignRight ( currentBlock , prevInputBlock , ( byte ) ( 16 - 1 ) ) ;
@@ -638,8 +622,6 @@ private unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust
638622 Vector128 < byte > prev2 = Ssse3 . AlignRight ( currentBlock , prevInputBlock , ( byte ) ( 16 - 2 ) ) ;
639623 Vector128 < byte > prev3 = Ssse3 . AlignRight ( currentBlock , prevInputBlock , ( byte ) ( 16 - 3 ) ) ;
640624 prevInputBlock = currentBlock ;
641- // // Console .WriteLine("PrevIncomplete:");
642- // ToString(prevIncomplete);
643625
644626 Vector128 < byte > isThirdByte = Sse2 . SubtractSaturate ( prev2 , thirdByte ) ;
645627 Vector128 < byte > isFourthByte = Sse2 . SubtractSaturate ( prev3 , fourthByte ) ;
@@ -649,7 +631,6 @@ private unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust
649631
650632 if ( ! Sse42 . TestZ ( error , error ) )
651633 {
652- // Console .WriteLine($"Found error! rewinding...");
653634
654635 byte * invalidBytePointer ;
655636 if ( processedLength == 0 )
@@ -686,7 +667,6 @@ private unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust
686667 asciibytes += ( int ) ( 16 - Popcnt . PopCount ( ( uint ) mask ) ) ;
687668 }
688669
689- // Console .WriteLine($"-----SIMD finished , calling scalar:");
690670
691671 // We may still have an error.
692672 if ( processedLength < inputLength || ! Sse42 . TestZ ( prevIncomplete , prevIncomplete ) )
0 commit comments