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

◆ NarrowUtf16ToAscii_Sse2()

static unsafe nuint System.Text.ASCIIUtility.NarrowUtf16ToAscii_Sse2 ( char * pUtf16Buffer,
byte * pAsciiBuffer,
nuint elementCount )
inlinestaticprivate

Definition at line 699 of file ASCIIUtility.cs.

700 {
701 uint num = (uint)Unsafe.SizeOf<Vector128<byte>>();
702 nuint num2 = num - 1;
703 Vector128<short> right = Vector128.Create((short)(-128));
704 Vector128<ushort> right2 = Vector128.Create((ushort)32640);
705 Vector128<short> vector = Sse2.LoadVector128((short*)pUtf16Buffer);
706 if (Sse41.IsSupported)
707 {
708 if (!Sse41.TestZ(vector, right))
709 {
710 return 0u;
711 }
712 }
713 else if (((uint)Sse2.MoveMask(Sse2.AddSaturate(vector.AsUInt16(), right2).AsByte()) & 0xAAAAu) != 0)
714 {
715 return 0u;
716 }
717 Vector128<byte> vector2 = Sse2.PackUnsignedSaturate(vector, vector);
718 Sse2.StoreScalar((ulong*)pAsciiBuffer, vector2.AsUInt64());
719 nuint num3 = num / 2;
720 if (((uint)(int)pAsciiBuffer & (num / 2)) != 0)
721 {
722 goto IL_00e7;
723 }
724 vector = Sse2.LoadVector128((short*)(pUtf16Buffer + num3));
725 if (Sse41.IsSupported)
726 {
727 if (Sse41.TestZ(vector, right))
728 {
729 goto IL_00ca;
730 }
731 }
732 else if ((Sse2.MoveMask(Sse2.AddSaturate(vector.AsUInt16(), right2).AsByte()) & 0xAAAA) == 0)
733 {
734 goto IL_00ca;
735 }
736 goto IL_0183;
737 IL_0183:
738 return num3;
739 IL_00ca:
740 vector2 = Sse2.PackUnsignedSaturate(vector, vector);
741 Sse2.StoreScalar((ulong*)(pAsciiBuffer + num3), vector2.AsUInt64());
742 goto IL_00e7;
743 IL_00e7:
744 num3 = num - ((nuint)pAsciiBuffer & num2);
745 nuint num4 = elementCount - num;
746 do
747 {
748 vector = Sse2.LoadVector128((short*)(pUtf16Buffer + num3));
749 Vector128<short> right3 = Sse2.LoadVector128((short*)(pUtf16Buffer + num3 + num / 2));
750 Vector128<short> vector3 = Sse2.Or(vector, right3);
751 if (Sse41.IsSupported)
752 {
753 if (Sse41.TestZ(vector3, right))
754 {
755 goto IL_015b;
756 }
757 }
758 else if ((Sse2.MoveMask(Sse2.AddSaturate(vector3.AsUInt16(), right2).AsByte()) & 0xAAAA) == 0)
759 {
760 goto IL_015b;
761 }
762 if (Sse41.IsSupported)
763 {
764 if (!Sse41.TestZ(vector, right))
765 {
766 break;
767 }
768 }
769 else if (((uint)Sse2.MoveMask(Sse2.AddSaturate(vector.AsUInt16(), right2).AsByte()) & 0xAAAAu) != 0)
770 {
771 break;
772 }
773 vector2 = Sse2.PackUnsignedSaturate(vector, vector);
774 Sse2.StoreScalar((ulong*)(pAsciiBuffer + num3), vector2.AsUInt64());
775 num3 += num / 2;
776 break;
777 IL_015b:
778 vector2 = Sse2.PackUnsignedSaturate(vector, right3);
779 Sse2.StoreAligned(pAsciiBuffer + num3, vector2);
780 num3 += num;
781 }
782 while (num3 <= num4);
783 goto IL_0183;
784 }
static Vector128< byte > Create(byte value)
Definition Vector128.cs:138
static unsafe Vector128< sbyte > LoadVector128(sbyte *address)
Definition Sse2.cs:582
static int MoveMask(Vector128< sbyte > value)
Definition Sse2.cs:772
static unsafe void StoreScalar(double *address, Vector128< double > source)
Definition Sse2.cs:1172
static Vector128< byte > PackUnsignedSaturate(Vector128< short > left, Vector128< short > right)
Definition Sse2.cs:892
static Vector128< byte > Or(Vector128< byte > left, Vector128< byte > right)
Definition Sse2.cs:837
static Vector128< sbyte > AddSaturate(Vector128< sbyte > left, Vector128< sbyte > right)
Definition Sse2.cs:112
static unsafe void StoreAligned(sbyte *address, Vector128< sbyte > source)
Definition Sse2.cs:1197
static bool TestZ(Vector128< sbyte > left, Vector128< sbyte > right)
Definition Sse41.cs:692

References System.Runtime.Intrinsics.X86.Sse2.AddSaturate(), System.Runtime.Intrinsics.Vector128< T >.Create(), System.Runtime.Intrinsics.X86.Sse41.IsSupported, System.Runtime.Intrinsics.X86.Sse2.LoadVector128(), System.Runtime.Intrinsics.X86.Sse2.MoveMask(), System.Runtime.Intrinsics.X86.Sse2.Or(), System.Runtime.Intrinsics.X86.Sse2.PackUnsignedSaturate(), System.Runtime.Intrinsics.X86.Sse2.StoreAligned(), System.Runtime.Intrinsics.X86.Sse2.StoreScalar(), and System.Runtime.Intrinsics.X86.Sse41.TestZ().

Referenced by System.Text.ASCIIUtility.NarrowUtf16ToAscii().