Open
Description
When using a static ReadOnlySpan<byte>
, such as this:
internal static ReadOnlySpan<byte> Mask0 => new byte[] {
0x00, 0x00, 0x00, 0x00, // 0 -> 0
0xFF, 0xFF, 0xFF, 0xFF, // 1 -> -1
0xFF, 0xFF, 0xFF, 0xFF, // 2 -> -1
0xFF, 0xFF, 0xFF, 0xFF, // 3 -> -1
0xFF, 0xFF, 0xFF, 0xFF, // 4 -> -1
0xFF, 0xFF, 0xFF, 0xFF, // 5 -> -1
0xFF, 0xFF, 0xFF, 0xFF, // 6 -> -1
0xFF, 0xFF, 0xFF, 0xFF, // 7 -> -1
};
The JIT hard-codes the address in the generated code as expected,
However, when using a fixed statement to load this byte array with an AVX intrinsic (for example):
fixed (byte* bp = &Mask0.GetPinnableReference()) {
mask0 = LoadDquVector256(bp).AsInt32();
}
The JIT generated a superflous store onto the stack for the fixed
statement:
L000e: mov rax, 0x27ff5fb0970
L0018: mov [rsp+0x30], rax ; Why?
L001d: vlddqu ymm0, [rax]
Full listing + asm here
category:cq
theme:pinning
skill-level:beginner
cost:small