Skip to content

new Vector<T> for byte, short emits vpbroadcastd thus needs an imul #67038

@gfoidl

Description

@gfoidl
public Vector<byte> Bad(byte val) => new Vector<byte>(val);

generates on x64 with AVX2 supported:

C.Bad(Byte)
    L0000: vzeroupper
    L0003: movzx eax, r8b
    L0007: imul eax, 0x1010101
    L000d: vmovd xmm0, eax
    L0011: vpbroadcastd ymm0, xmm0
    L0016: vmovupd [rdx], ymm0
    L001a: mov rax, rdx
    L001d: vzeroupper
    L0020: ret

The imul isn't needed when instead of vpbroadcastd the vpbroadcastb is used, as it's done by

public Vector256<byte> Good(byte val) => Vector256.Create(val);
C.Good(Byte)
    L0000: vzeroupper
    L0003: movzx eax, r8b
    L0007: vmovd xmm0, eax
    L000b: vpbroadcastb ymm0, xmm0
    L0010: vmovupd [rdx], ymm0
    L0014: mov rax, rdx
    L0017: vzeroupper
    L001a: ret
Type actual should be
byte, sbyte imul + vpbroadcastd vpbroadcastb
ushort, short imul + vpbroadcastd vpbroadcastw
uint, int vpbroadcastd ✔️
ulong, long vpbroadcastq ✔️

For more see sharplab
I see the same on .NET 7 Preview 2.

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions