@@ -23,7 +23,6 @@ public static class UTF8
2323
2424 for ( int i = 0 ; i <= howFarBack ; i ++ )
2525 {
26- // Console.WriteLine("Activiting main backup:" + i);
2726 byte candidateByte = buf [ 0 - i ] ;
2827 foundLeadingBytes = ( candidateByte & 0b11000000 ) != 0b10000000 ;
2928 if ( foundLeadingBytes )
@@ -200,7 +199,7 @@ public unsafe static (int totalbyteadjustment,int backedupByHowMuch,int ascii,in
200199 return ( 0 , i , - 1 , 0 , 0 ) ; // We must have that i == 1
201200 }
202201 if ( ( pInputBuffer [ - i ] & 0b11100000 ) == 0b11000000 ) {
203- return ( 2 - i , i , 0 , - 1 , 0 ) ; // We have that i == 1 or i == 2, if i == 1, we are missing one byte.
202+ return ( 2 - i , i , 0 , 0 , 0 ) ; // We have that i == 1 or i == 2, if i == 1, we are missing one byte.
204203 }
205204 if ( ( pInputBuffer [ - i ] & 0b11110000 ) == 0b11100000 ) {
206205 return ( 3 - i , i , 0 , 0 , 0 ) ; // We have that i == 1 or i == 2 or i == 3, if i == 1, we are missing two bytes, if i == 2, we are missing one byte.
@@ -211,12 +210,16 @@ public unsafe static (int totalbyteadjustment,int backedupByHowMuch,int ascii,in
211210
212211 public static ( int utfadjust , int scalaradjust ) CalculateN2N3FinalSIMDAdjustments ( int asciibytes , int n4 , int contbytes , int totalbyte )
213212 {
214- // Console.WriteLine("CalculateN2N3FinalSIMDAdjustments's input debug. This is ascii count:" + asciibytes + " n4: " + n4 + " contbytes:" + contbytes + " totalbytes:" + totalbyte);
213+ Console . WriteLine ( "---------" ) ;
214+ Console . WriteLine ( "CalculateN2N3FinalSIMDAdjustments's input debug. This is ascii count:" + asciibytes + " n4: " + n4 + " contbytes:" + contbytes + " totalbytes:" + totalbyte ) ;
215215 int n3 = asciibytes - 2 * n4 + 2 * contbytes - totalbyte ;
216216 int n2 = - 2 * asciibytes + n4 - 3 * contbytes + 2 * totalbyte ;
217217 int utfadjust = - 2 * n4 - 2 * n3 - n2 ;
218218 int scalaradjust = - n4 ;
219219
220+ Console . WriteLine ( "CalculateN2N3FinalSIMDAdjustments's output debug. This is n3 count:" + n3 + " n2: " + n2 + " utfadjust:" + utfadjust + " scalaradjust:" + scalaradjust ) ;
221+
222+
220223 return ( utfadjust , scalaradjust ) ;
221224 }
222225
@@ -392,6 +395,7 @@ public unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust(
392395
393396 public unsafe static byte * GetPointerToFirstInvalidByteAvx2 ( byte * pInputBuffer , int inputLength , out int utf16CodeUnitCountAdjustment , out int scalarCountAdjustment )
394397 {
398+ Console . WriteLine ( "-------------------------------------" ) ;
395399 int processedLength = 0 ;
396400 int TempUtf16CodeUnitCountAdjustment = 0 ;
397401 int TempScalarCountAdjustment = 0 ;
@@ -544,7 +548,7 @@ public unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust(
544548 //
545549 if ( ! Avx2 . TestZ ( prevIncomplete , prevIncomplete ) )
546550 {
547- // TODO : this path is not explicitly tested, write tests
551+ // TODO : this path is not explicitly tested, write tests
548552 int totalbyteasciierror = processedLength - start_point ;
549553 var ( utfadjustasciierror , scalaradjustasciierror ) = CalculateN2N3FinalSIMDAdjustments ( asciibytes , n4 , contbytes , totalbyteasciierror ) ;
550554
@@ -577,6 +581,7 @@ public unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust(
577581 Vector256 < byte > error = Avx2 . Xor ( must23As80 , sc ) ;
578582 if ( ! Avx2 . TestZ ( error , error ) )
579583 {
584+ Console . WriteLine ( "--Error!" ) ;
580585 int totalbyteasciierror = processedLength - start_point ;
581586 var ( utfadjustasciierror , scalaradjustasciierror ) = calculateErrorPathadjust ( start_point , processedLength , pInputBuffer , asciibytes , n4 , contbytes ) ;
582587
@@ -605,6 +610,8 @@ public unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust(
605610 processedLength -= i ;
606611 n4 += tempn4 ;
607612 contbytes += tempcont ;
613+ Console . WriteLine ( $ "Unterminated! Backing up by { i } ") ;
614+
608615 }
609616
610617 // No errors! Updating the variables we keep track of
@@ -631,7 +638,6 @@ public unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust(
631638
632639 utf16CodeUnitCountAdjustment = utf16adjust ;
633640 scalarCountAdjustment = scalaradjust ;
634-
635641 }
636642
637643
0 commit comments