Skip to content

Commit

Permalink
trying to reduce the cost of the 4-byte char
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Jun 25, 2024
1 parent bd4a55a commit 1cce4a6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/UTF8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,8 @@ private unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust
Vector128<byte> fourthByte = Vector128.Create((byte)(0b11110000u - 0x80));
Vector128<byte> v0f = Vector128.Create((byte)0x0F);
Vector128<byte> v80 = Vector128.Create((byte)0x80);
Vector128<byte> fourthByteMinusOne = Vector128.Create((byte)(0b11110000u - 1));
Vector128<sbyte> largestcont = Vector128.Create((sbyte)-65); // -65 => 0b10111111
// Performance note: we could process 64 bytes at a time for better speed in some cases.
int start_point = processedLength;

Expand Down Expand Up @@ -1457,15 +1459,15 @@ private unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust
return invalidBytePointer;
}
prevIncomplete = AdvSimd.SubtractSaturate(currentBlock, maxValue);
Vector128<sbyte> largestcont = Vector128.Create((sbyte)-65); // -65 => 0b10111111
contbytes += -AdvSimd.Arm64.AddAcross(AdvSimd.CompareLessThanOrEqual(Vector128.AsSByte(currentBlock), largestcont)).ToScalar();

// computing n4 is more expensive than we would like:
Vector128<byte> fourthByteMinusOne = Vector128.Create((byte)(0b11110000u - 1));
Vector128<byte> largerthan0f = AdvSimd.CompareGreaterThan(currentBlock, fourthByteMinusOne);
byte n4add = (byte)AdvSimd.Arm64.AddAcross(largerthan0f).ToScalar();
int negn4add = (int)(byte)-n4add;
n4 += negn4add;
ulong n4marker = AdvSimd.Arm64.MaxAcross(Vector128.AsUInt32(largerthan0f)).ToScalar();
if (n4marker != 0)
{
byte n4add = (byte)AdvSimd.Arm64.AddAcross(largerthan0f).ToScalar();
int negn4add = (int)(byte)-n4add;
n4 += negn4add;
}
}
}
bool hasIncompete = AdvSimd.Arm64.MaxAcross(Vector128.AsUInt32(prevIncomplete)).ToScalar() != 0;
Expand Down

0 comments on commit 1cce4a6

Please sign in to comment.