#Masked stores

1 messages · Page 1 of 1 (latest)

junior stone
#

I've been trying to massage my simd code to generate an avx2 masked store (vmaskmovps) but llvm simply won't do it. Is there any known way to do this with the llvm backend,
and if not is there a proposal to add a masked store builtin?

#

The closest I've got is this but it still generates a load which isn't tenable.

fn maskedStore(base: *@Vector(8, u32), values: @Vector(8, u32), mask: @Vector(8, bool)) void {
    base.* = @select(u32, mask, values, base.*); 
}
#

I can always drop down to inline assembly but it would be nice to do this portably

upper dawn
#

What instruction do you want to get? If you want vmovmskps this doc does not seem to be similar to the zig code you wrote.

junior stone
#

I'm trying to get vmaskmovps

#

there's no way to write it directly in the semantics of zig

#

so I just did wrote a load+select+store thing but llvm didn't optimize it into the masked store

#

again I could do inline assembly but gcc inline assembly syntax is incomprehensible

junior stone
#
.LCPI1_0:
        .short  1
        .short  1
        .short  1
        .short  1
        .short  1
        .short  1
        .short  1
        .short  1
; my shoddy attempt at inline assembly, I don't know why it has to and the mask with this constant but whatever
maskedStoreAsm2:
        vpand   xmm1, xmm1, xmmword ptr [rip + .LCPI1_0]
        vpmovzxwd       ymm1, xmm1
        vmaskmovps      ymmword ptr [rdi], ymm0, ymm1
        vzeroupper
        ret

; This is the best that the llvm backend could do
maskedStore: 
        vpmovzxwd       ymm1, xmm1
        vpslld  ymm1, ymm1, 31
        vmovaps ymm2, ymmword ptr [rdi]
        vblendvps       ymm0, ymm2, ymm0, ymm1
        vmovaps ymmword ptr [rdi], ymm0
        vzeroupper
        ret
#

I think maybe it would be nice if there was a masked store builtin in zig but this will probably do for now

lusty tinsel