Created
January 30, 2023 10:50
-
-
Save MiloszKrajewski/fc4a1f43ecebf74128fe59876b37d28a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UnpackTest | |
{ | |
byte[] _source; | |
byte[] _target; | |
public UnpackTest() | |
{ | |
int size = 1000 * Vector128<byte>.Count; | |
var source = new byte[size]; | |
var target = new byte[size * 2]; | |
new Random(0).NextBytes(source); | |
_source = source; | |
_target = target; | |
} | |
unsafe void TestA() | |
{ | |
var length = _source.Length; | |
fixed (byte* s0 = _source) | |
fixed (byte* t0 = _target) | |
{ | |
var s = s0; | |
var t = t0; | |
var l = s + length; | |
while (s < l) | |
{ | |
UnpackA(s, t); | |
s += 16; | |
t += 32; | |
} | |
} | |
} | |
unsafe void TestB() | |
{ | |
var length = _source.Length; | |
fixed (byte* s0 = _source) | |
fixed (byte* t0 = _target) | |
{ | |
var s = s0; | |
var t = t0; | |
var l = s + length; | |
var z = Vector128<byte>.Zero; | |
while (s < l) | |
{ | |
UnpackB(s, t, z); | |
s += 16; | |
t += 32; | |
} | |
} | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
static unsafe void UnpackA(byte* source, byte* target) | |
{ | |
var vector = Sse2.LoadVector128(source); | |
Sse2.Store(target + 0x00, Sse2.UnpackLow(vector, Vector128<byte>.Zero)); | |
Sse2.Store(target + 0x10, Sse2.UnpackHigh(vector, Vector128<byte>.Zero)); | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
static unsafe void UnpackB(byte* source, byte* target, Vector128<byte> zero) | |
{ | |
var vector = Sse2.LoadVector128(source); | |
Sse2.Store(target + 0x00, Sse2.UnpackLow(vector, zero)); | |
Sse2.Store(target + 0x10, Sse2.UnpackHigh(vector, zero)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment