assemblygdbx86-64cpu-registersavx512

What is the purpose of the k0, k1, ... k7 registers?


I am debugging a simple program that prints the string "Hello, world!" three times. In the information about the registers that the gdb program gives, with the command info register, appear the registers k0, k1, k3, ... k7.
The native architecture of my processor is x86 64-bit.


Solution

  • They're AVX-512 SIMD mask registers, 64 bits each on CPUs with AVX-512BW.
    (Otherwise only 16 bits on Xeon Phi, the only CPUs to have AVX-512F without AVX-512BW.)
    They don't exist on CPUs without AVX-512.

    https://en.wikipedia.org/wiki/AVX-512#Opmask_registers

    Merge-masking instructions like vpaddb ymm0{k1}, ymm1, ymm2 keep the old value of YMM0 in elements where the mask register had a 0 bit.
    Zero-masking instructions like vpaddb ymm0{k1}{z}, ymm1, ymm2 zero those elements, so no input dependency on the old value of ymm0.

    k0 isn't usable for actual masking of other operations (its register-number means no masking in that context). It is usable as a destination or as a normal source for instructions like kxnor k1, k0, k0 to set k1 to all-ones (e.g. before using it as a scatter or gather mask), or like vpcmpltd k0, zmm0, zmm1 / vpmovm2d zmm2, k0 (to emulate SSE2/AVX2-style compare-into-vector, which you'd normally try to avoid with AVX-512. Or if working with 128 or 256-bit vectors, just use the AVX2 instruction unless you need e.g. unsigned-less or greater compare which only AVX-512 has.)


    For more details and example uses, see


    Also, a web search for "x86 register k0" finds several pages that would point you in the right direction toward AVX-512: