Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1.         public static unsafe void ToUtf16(int source, byte* dest)
  2.         {
  3.             var intVector = Sse41.ConvertToVector128Int32(Vector128.CreateScalarUnsafe(source).AsByte());
  4.             var hi = Sse2.ShiftRightLogical(intVector, 4);
  5.             var lo = Ssse3.Shuffle(intVector.AsByte(),
  6.                 Vector128.Create(
  7.                     0xFF, 0xFF, 0x00, 0xFF,
  8.                     0xFF, 0xFF, 0x04, 0xFF,
  9.                     0xFF, 0xFF, 0x08, 0xFF,
  10.                     0xFF, 0xFF, 0x0C, 0xFF));
  11.             var asciiMask = Sse2.And(Sse2.Or(hi.AsByte(), lo), Vector128.Create((byte) 0x0F));
  12.  
  13.             var dirtyAsciiBytes = Ssse3.Shuffle(
  14.                 Vector128.Create((byte) 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102),
  15.                 asciiMask);
  16.             var utf16Bytes = Sse2.And(
  17.                 dirtyAsciiBytes,
  18.                 Vector128.Create(
  19.                     0xFF, 0x00, 0xFF, 0x00,
  20.                     0xFF, 0x00, 0xFF, 0x00,
  21.                     0xFF, 0x00, 0xFF, 0x00,
  22.                     0xFF, 0x00, 0xFF, 0x00));
  23.             Sse2.Store(dest, utf16Bytes);
  24.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement