Skip to content

Commit 906201f

Browse files
committed
making some of the arm code prettier
1 parent 7bdac73 commit 906201f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/UTF8.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1364,13 +1364,13 @@ private unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust
13641364
{
13651365

13661366
Vector128<byte> currentBlock = AdvSimd.LoadVector128(pInputBuffer + processedLength);
1367-
if (AdvSimd.Arm64.MaxAcross(Vector128.AsUInt32(AdvSimd.And(currentBlock, v80))).ToScalar() == 0)
1367+
if ((currentBlock & v80) == Vector128<byte>.Zero)
13681368
// We could also use (AdvSimd.Arm64.MaxAcross(currentBlock).ToScalar() <= 127) but it is slower on some
13691369
// hardware.
13701370
{
13711371
// We have an ASCII block, no need to process it, but
13721372
// we need to check if the previous block was incomplete.
1373-
if (AdvSimd.Arm64.MaxAcross(prevIncomplete).ToScalar() != 0)
1373+
if (prevIncomplete != Vector128<byte>.Zero)
13741374
{
13751375
int off = processedLength >= 3 ? processedLength - 3 : processedLength;
13761376
byte* invalidBytePointer = SimdUnicode.UTF8.SimpleRewindAndValidateWithErrors(16 - 3, pInputBuffer + processedLength - 3, inputLength - processedLength + 3);
@@ -1404,7 +1404,7 @@ private unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust
14041404
Vector128<byte> block4 = AdvSimd.LoadVector128(pInputBuffer + processedLength + localasciirun + 48);
14051405
Vector128<byte> or = AdvSimd.Or(AdvSimd.Or(block1, block2), AdvSimd.Or(block3, block4));
14061406

1407-
if (AdvSimd.Arm64.MaxAcross(Vector128.AsUInt32(AdvSimd.And(or, v80))).ToScalar() != 0)
1407+
if ((or & v80) != Vector128<byte>.Zero)
14081408
{
14091409
break;
14101410
}
@@ -1435,7 +1435,7 @@ private unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust
14351435
// AdvSimd.Arm64.MaxAcross(error) works, but it might be slower
14361436
// than AdvSimd.Arm64.MaxAcross(Vector128.AsUInt32(error)) on some
14371437
// hardware:
1438-
if (AdvSimd.Arm64.MaxAcross(Vector128.AsUInt32(error)).ToScalar() != 0)
1438+
if (error != Vector128<byte>.Zero)
14391439
{
14401440
byte* invalidBytePointer;
14411441
if (processedLength == 0)
@@ -1461,16 +1461,15 @@ private unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust
14611461
prevIncomplete = AdvSimd.SubtractSaturate(currentBlock, maxValue);
14621462
contbytes += -AdvSimd.Arm64.AddAcross(AdvSimd.CompareLessThanOrEqual(Vector128.AsSByte(currentBlock), largestcont)).ToScalar();
14631463
Vector128<byte> largerthan0f = AdvSimd.CompareGreaterThan(currentBlock, fourthByteMinusOne);
1464-
ulong n4marker = AdvSimd.Arm64.MaxAcross(Vector128.AsUInt32(largerthan0f)).ToScalar();
1465-
if (n4marker != 0)
1464+
if (largerthan0f != Vector128<byte>.Zero)
14661465
{
14671466
byte n4add = (byte)AdvSimd.Arm64.AddAcross(largerthan0f).ToScalar();
14681467
int negn4add = (int)(byte)-n4add;
14691468
n4 += negn4add;
14701469
}
14711470
}
14721471
}
1473-
bool hasIncompete = AdvSimd.Arm64.MaxAcross(Vector128.AsUInt32(prevIncomplete)).ToScalar() != 0;
1472+
bool hasIncompete = (prevIncomplete != Vector128<byte>.Zero);
14741473
if (processedLength < inputLength || hasIncompete)
14751474
{
14761475
byte* invalidBytePointer;

0 commit comments

Comments
 (0)