Skip to content

Commit f6e40c8

Browse files
committed
All tests working save Bruteforce/toolong error
1 parent 0c758c9 commit f6e40c8

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/UTF8.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,12 @@ public unsafe static (int totalbyteadjustment,int backedupByHowMuch,int ascii,in
257257
{
258258
if ((pInputBuffer[-i] & 0b11000000) != 0b10000000)
259259
{
260+
string binaryString = Convert.ToString(pInputBuffer[-i], 2).PadLeft(8, '0');
261+
// Console.WriteLine($"Stopping at byte {binaryString}"); //debug
260262
break;
261263
}
262264
contbyteadjust -= 1;
263-
265+
264266
}
265267
if ((pInputBuffer[-i] & 0b10000000) == 0) {
266268
return (0,i,-1,contbyteadjust,0); // We must have that i == 1
@@ -277,14 +279,14 @@ public unsafe static (int totalbyteadjustment,int backedupByHowMuch,int ascii,in
277279

278280
public static (int utfadjust, int scalaradjust) CalculateN2N3FinalSIMDAdjustments(int asciibytes, int n4, int contbytes, int totalbyte)
279281
{
280-
Console.WriteLine("---------"); //debug
281-
Console.WriteLine("CalculateN2N3FinalSIMDAdjustments's input debug. This is ascii count:" + asciibytes + " n4: " + n4 + " contbytes:" + contbytes + " totalbytes:" + totalbyte);//debug
282+
// Console.WriteLine("---------"); //debug
283+
// Console.WriteLine("CalculateN2N3FinalSIMDAdjustments's input debug. This is ascii count:" + asciibytes + " n4: " + n4 + " contbytes:" + contbytes + " totalbytes:" + totalbyte);//debug
282284
int n3 = asciibytes - 2 * n4 + 2 * contbytes - totalbyte;
283285
int n2 = -2 * asciibytes + n4 - 3 * contbytes + 2 * totalbyte;
284286
int utfadjust = -2 * n4 - 2 * n3 - n2;
285287
int scalaradjust = -n4;
286288

287-
Console.WriteLine("CalculateN2N3FinalSIMDAdjustments's output debug. This is n3 count:" + n3 + " n2: " + n2 + " utfadjust:" + utfadjust + " scalaradjust:" + scalaradjust);//debug
289+
// Console.WriteLine("CalculateN2N3FinalSIMDAdjustments's output debug. This is n3 count:" + n3 + " n2: " + n2 + " utfadjust:" + utfadjust + " scalaradjust:" + scalaradjust);//debug
288290

289291
return (utfadjust, scalaradjust);
290292
}
@@ -301,7 +303,9 @@ public unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust(
301303
(adjusttotalbyte, backedupByHowMuch ,adjustascii, adjustcont, adjustn4) = adjustmentFactor(pInputBuffer + processedLength);
302304
}
303305

304-
var (utfadjust,scalaradjust) = CalculateN2N3FinalSIMDAdjustments( asciibytes + adjustascii, n4 + adjustn4, contbytes + adjustcont, totalbyte + adjusttotalbyte);
306+
// var (utfadjust,scalaradjust) = CalculateN2N3FinalSIMDAdjustments( asciibytes + adjustascii, n4 + adjustn4, contbytes + adjustcont, totalbyte + adjusttotalbyte);
307+
var (utfadjust,scalaradjust) = CalculateN2N3FinalSIMDAdjustments( asciibytes, n4 , contbytes , totalbyte + adjusttotalbyte);
308+
305309

306310
return (utfadjust, scalaradjust);
307311
}
@@ -461,9 +465,9 @@ public unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust(
461465

462466
public unsafe static byte* GetPointerToFirstInvalidByteAvx2(byte* pInputBuffer, int inputLength,out int utf16CodeUnitCountAdjustment, out int scalarCountAdjustment)
463467
{
464-
Console.ForegroundColor = ConsoleColor.Blue; //debug
465-
Console.WriteLine("-------------------------------------");//debug
466-
Console.ResetColor();//debug
468+
// Console.ForegroundColor = ConsoleColor.Blue; //debug
469+
// Console.WriteLine("-------------------------------------");//debug
470+
// Console.ResetColor();//debug
467471

468472
int processedLength = 0;
469473
int TempUtf16CodeUnitCountAdjustment= 0 ;
@@ -657,7 +661,7 @@ public unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust(
657661
Vector256<byte> error = Avx2.Xor(must23As80, sc);
658662
if (!Avx2.TestZ(error, error))
659663
{
660-
Console.WriteLine($"--Error! @ {processedLength} bytes");//debug
664+
// Console.WriteLine($"--Error! @ {processedLength} bytes");//debug
661665
int totalbyteasciierror = processedLength - start_point;
662666
var (utfadjustasciierror, scalaradjustasciierror) = calculateErrorPathadjust(start_point, processedLength, pInputBuffer, asciibytes, n4, contbytes);
663667

@@ -686,7 +690,7 @@ public unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust(
686690
processedLength -= i;
687691
n4 += tempn4;// this is + because the adjustment function returns something negative already
688692
contbytes +=tempcont;
689-
Console.WriteLine($"Unterminated! @ {processedLength} Backing up by {i}"); //debug
693+
// Console.WriteLine($"Unterminated! @ {processedLength} Backing up by {i}"); //debug
690694
}
691695

692696

@@ -740,8 +744,8 @@ public unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust(
740744
int totalbyte = processedLength - start_point;
741745
var (utf16adjust, scalaradjust) = CalculateN2N3FinalSIMDAdjustments( asciibytes, n4, contbytes, totalbyte);
742746

743-
utf16CodeUnitCountAdjustment = utf16adjust;
744-
scalarCountAdjustment = scalaradjust;
747+
TempUtf16CodeUnitCountAdjustment = utf16adjust;
748+
TempScalarCountAdjustment = scalaradjust;
745749
}
746750

747751

0 commit comments

Comments
 (0)