#512 bit vpshufb only acting on first 128

1 messages · Page 1 of 1 (latest)

fresh sail
#

As @shuffle requires a comptime known mask, attempting to shuffle as follows:

const ByteVector = @vector(std.simd.suggestVectorLength(u8) orelse @panic(), u8);

fn shuffle(src: Byte~~Vector, mask: ByteVector) ByteVector {
    std.debug.print(~~"\nmask={}\n", .{mask});
    std.debug.print("src={}\n", .{src});

    const res = asm ("vpshufb %[mask], %[src], %[dst]"
        : [dst] "=x" (-> ByteVector),
        : [src] "x" (src),
          [mask] "x" (mask),
    );

    std.debug.print("shuffled={}\n", .{res});

    return res;
}

On my device, the suggested vector length is 64 bytes, which makes sense as my cpu is supporting AVX512, and std.Target.x86.featureSetHas(builtin.cpu.features, .avx512f) returns true

However, this is an example output of the above shuffle:

mask={ 0, 13, 10, 13, 0, 13, 0, 13, 0, 13, 10, 13, 0, 13, 0, 13, 0, 13, 10, 13, 0, 13, 0, 13, 0, 13, 10, 13, 0, 13, 0, 13, 0, 13, 10, 13, 0, 13, 0, 13, 0, 13, 10, 13, 0, 13, 0, 13, 0, 13, 10, 13, 0, 13, 0, 13, 0, 13, 10, 13, 0, 13, 0, 13 }
src={ 65, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 239, 32, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
shuffled={ 65, 71, 252, 71, 65, 71, 65, 71, 65, 71, 252, 71, 65, 71, 65, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

The shuffle only operated on the first 16 bytes, not the full 64

godbolt confirms that the above function should generate a 512 bit shuffle if avx512 is supported as can see use of zmmword: https://godbolt.org/z/jGG7Mr7oY

Anyone have any idea as to what the issue is here? been stuck on this for a while now

signal bramble
#

I mean that's just how x86_64 works

#

a 512-bit vshufb is identical to 4 parallel 128-bit vshufb operations

fresh sail
#

but it has only done 1 128bit op here, not 4? or am i misunderstanding

signal bramble
#

the input of the other 3 operations was all zeros, so the output must therefore be all zeros

fresh sail
#

oh i get it

#

ok need to just broadcast the first 16 bytes then

#

thanks