Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static unsafe void ToUtf16(int source, byte* dest)
- {
- var intVector = Sse41.ConvertToVector128Int32(Vector128.CreateScalarUnsafe(source).AsByte());
- var hi = Sse2.ShiftRightLogical(intVector, 4);
- var lo = Ssse3.Shuffle(intVector.AsByte(),
- Vector128.Create(
- 0xFF, 0xFF, 0x00, 0xFF,
- 0xFF, 0xFF, 0x04, 0xFF,
- 0xFF, 0xFF, 0x08, 0xFF,
- 0xFF, 0xFF, 0x0C, 0xFF));
- var asciiMask = Sse2.And(Sse2.Or(hi.AsByte(), lo), Vector128.Create((byte) 0x0F));
- var dirtyAsciiBytes = Ssse3.Shuffle(
- Vector128.Create((byte) 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102),
- asciiMask);
- var utf16Bytes = Sse2.And(
- dirtyAsciiBytes,
- Vector128.Create(
- 0xFF, 0x00, 0xFF, 0x00,
- 0xFF, 0x00, 0xFF, 0x00,
- 0xFF, 0x00, 0xFF, 0x00,
- 0xFF, 0x00, 0xFF, 0x00));
- Sse2.Store(dest, utf16Bytes);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement