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

◆ NarrowUtf16ToLatin1_Sse2()

static unsafe nuint System.Text.Latin1Utility.NarrowUtf16ToLatin1_Sse2 ( char * pUtf16Buffer,
byte * pLatin1Buffer,
nuint elementCount )
inlinestaticprivate

Definition at line 397 of file Latin1Utility.cs.

398 {
399 uint num = (uint)Unsafe.SizeOf<Vector128<byte>>();
400 nuint num2 = num - 1;
401 Vector128<short> right = Vector128.Create((short)(-256));
402 Vector128<ushort> right2 = Vector128.Create((ushort)32512);
403 Vector128<short> vector = Sse2.LoadVector128((short*)pUtf16Buffer);
404 if (Sse41.IsSupported)
405 {
406 if (!Sse41.TestZ(vector, right))
407 {
408 return 0u;
409 }
410 }
411 else if (((uint)Sse2.MoveMask(Sse2.AddSaturate(vector.AsUInt16(), right2).AsByte()) & 0xAAAAu) != 0)
412 {
413 return 0u;
414 }
415 Vector128<byte> vector2 = Sse2.PackUnsignedSaturate(vector, vector);
416 Sse2.StoreScalar((ulong*)pLatin1Buffer, vector2.AsUInt64());
417 nuint num3 = num / 2;
418 if (((uint)(int)pLatin1Buffer & (num / 2)) != 0)
419 {
420 goto IL_00ea;
421 }
422 vector = Sse2.LoadVector128((short*)(pUtf16Buffer + num3));
423 if (Sse41.IsSupported)
424 {
425 if (Sse41.TestZ(vector, right))
426 {
427 goto IL_00cd;
428 }
429 }
430 else if ((Sse2.MoveMask(Sse2.AddSaturate(vector.AsUInt16(), right2).AsByte()) & 0xAAAA) == 0)
431 {
432 goto IL_00cd;
433 }
434 goto IL_0186;
435 IL_0186:
436 return num3;
437 IL_00cd:
438 vector2 = Sse2.PackUnsignedSaturate(vector, vector);
439 Sse2.StoreScalar((ulong*)(pLatin1Buffer + num3), vector2.AsUInt64());
440 goto IL_00ea;
441 IL_00ea:
442 num3 = num - ((nuint)pLatin1Buffer & num2);
443 nuint num4 = elementCount - num;
444 do
445 {
446 vector = Sse2.LoadVector128((short*)(pUtf16Buffer + num3));
447 Vector128<short> right3 = Sse2.LoadVector128((short*)(pUtf16Buffer + num3 + num / 2));
448 Vector128<short> vector3 = Sse2.Or(vector, right3);
449 if (Sse41.IsSupported)
450 {
451 if (Sse41.TestZ(vector3, right))
452 {
453 goto IL_015e;
454 }
455 }
456 else if ((Sse2.MoveMask(Sse2.AddSaturate(vector3.AsUInt16(), right2).AsByte()) & 0xAAAA) == 0)
457 {
458 goto IL_015e;
459 }
460 if (Sse41.IsSupported)
461 {
462 if (!Sse41.TestZ(vector, right))
463 {
464 break;
465 }
466 }
467 else if (((uint)Sse2.MoveMask(Sse2.AddSaturate(vector.AsUInt16(), right2).AsByte()) & 0xAAAAu) != 0)
468 {
469 break;
470 }
471 vector2 = Sse2.PackUnsignedSaturate(vector, vector);
472 Sse2.StoreScalar((ulong*)(pLatin1Buffer + num3), vector2.AsUInt64());
473 num3 += num / 2;
474 break;
475 IL_015e:
476 vector2 = Sse2.PackUnsignedSaturate(vector, right3);
477 Sse2.StoreAligned(pLatin1Buffer + num3, vector2);
478 num3 += num;
479 }
480 while (num3 <= num4);
481 goto IL_0186;
482 }
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.Latin1Utility.NarrowUtf16ToLatin1().