Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetIndexOfFirstByteToEncodeSsse3()

unsafe nuint System.Text.Encodings.Web.OptimizedInboxTextEncoder.GetIndexOfFirstByteToEncodeSsse3 ( byte * pData,
nuint lengthInBytes )
inlineprivate

Definition at line 426 of file OptimizedInboxTextEncoder.cs.

427 {
429 Vector128<byte> right = Vector128.Create((byte)7);
430 Vector128<byte> value = Vector128.Create(1, 2, 4, 8, 16, 32, 64, 128, 0, 0, 0, 0, 0, 0, 0, 0);
432 nuint num = 0u;
433 if (lengthInBytes < 16)
434 {
435 goto IL_00b3;
436 }
437 nuint num2 = lengthInBytes & unchecked((nuint)(-16));
438 int num3;
439 while (true)
440 {
441 Vector128<byte> vector = Sse2.LoadVector128(pData + num);
442 Vector128<byte> left = Ssse3.Shuffle(asVector, vector);
443 Vector128<byte> right2 = Ssse3.Shuffle(value, Sse2.And(Sse2.ShiftRightLogical(vector.AsUInt32(), 4).AsByte(), right));
444 Vector128<byte> left2 = Sse2.And(left, right2);
445 num3 = Sse2.MoveMask(Sse2.CompareEqual(left2, zero));
446 if (((uint)num3 & 0xFFFFu) != 0)
447 {
448 break;
449 }
450 if ((num += 16) < num2)
451 {
452 continue;
453 }
454 goto IL_00b3;
455 }
456 goto IL_01af;
457 IL_00b3:
458 if ((lengthInBytes & 8) != 0)
459 {
460 Vector128<byte> vector2 = Sse2.LoadScalarVector128((ulong*)(pData + num)).AsByte();
461 Vector128<byte> left3 = Ssse3.Shuffle(asVector, vector2);
462 Vector128<byte> right3 = Ssse3.Shuffle(value, Sse2.And(Sse2.ShiftRightLogical(vector2.AsUInt32(), 4).AsByte(), right));
463 Vector128<byte> left4 = Sse2.And(left3, right3);
464 num3 = Sse2.MoveMask(Sse2.CompareEqual(left4, zero));
465 if ((byte)num3 != 0)
466 {
467 goto IL_01af;
468 }
469 num += 8;
470 }
471 if ((lengthInBytes & 4) != 0)
472 {
473 Vector128<byte> vector3 = Sse2.LoadScalarVector128((uint*)(pData + num)).AsByte();
474 Vector128<byte> left5 = Ssse3.Shuffle(asVector, vector3);
475 Vector128<byte> right4 = Ssse3.Shuffle(value, Sse2.And(Sse2.ShiftRightLogical(vector3.AsUInt32(), 4).AsByte(), right));
476 Vector128<byte> left6 = Sse2.And(left5, right4);
477 num3 = Sse2.MoveMask(Sse2.CompareEqual(left6, zero));
478 if (((uint)num3 & 0xFu) != 0)
479 {
480 goto IL_01af;
481 }
482 num += 4;
483 }
484 if ((lengthInBytes & 3) != 0)
485 {
486 while (_allowedAsciiCodePoints.IsAllowedAsciiCodePoint(pData[num]) && ++num != lengthInBytes)
487 {
488 }
489 }
490 goto IL_01ac;
491 IL_01af:
492 num += (uint)BitOperations.TrailingZeroCount(num3);
493 goto IL_01ac;
494 IL_01ac:
495 return num;
496 }
static int TrailingZeroCount(int value)
static Vector128< byte > Create(byte value)
Definition Vector128.cs:138
static unsafe Vector128< sbyte > LoadVector128(sbyte *address)
Definition Sse2.cs:582
static unsafe Vector128< double > LoadScalarVector128(double *address)
Definition Sse2.cs:627
static int MoveMask(Vector128< sbyte > value)
Definition Sse2.cs:772
static Vector128< sbyte > CompareEqual(Vector128< sbyte > left, Vector128< sbyte > right)
Definition Sse2.cs:232
static Vector128< byte > And(Vector128< byte > left, Vector128< byte > right)
Definition Sse2.cs:132
static Vector128< short > ShiftRightLogical(Vector128< short > value, Vector128< short > count)
Definition Sse2.cs:1057
static Vector128< sbyte > Shuffle(Vector128< sbyte > value, Vector128< sbyte > mask)
Definition Ssse3.cs:112

References System.Text.Encodings.Web.OptimizedInboxTextEncoder._allowedAsciiCodePoints, System.Runtime.Intrinsics.X86.Sse2.And(), System.Text.Encodings.Web.OptimizedInboxTextEncoder.AllowedAsciiCodePoints.AsVector, System.Runtime.Intrinsics.X86.Sse2.CompareEqual(), System.Runtime.Intrinsics.Vector128< T >.Create(), System.Text.Encodings.Web.OptimizedInboxTextEncoder.AllowedAsciiCodePoints.IsAllowedAsciiCodePoint(), System.Runtime.Intrinsics.X86.Sse2.LoadScalarVector128(), System.Runtime.Intrinsics.X86.Sse2.LoadVector128(), System.Runtime.Intrinsics.X86.Sse2.MoveMask(), System.Runtime.Intrinsics.X86.Sse2.ShiftRightLogical(), System.Runtime.Intrinsics.X86.Ssse3.Shuffle(), System.Numerics.BitOperations.TrailingZeroCount(), System.Text.Encodings.Web.value, and System.Runtime.Intrinsics.Vector128< T >.Zero.

Referenced by System.Text.Encodings.Web.OptimizedInboxTextEncoder.GetIndexOfFirstByteToEncode().