Rate This Document
Findability
Accuracy
Completeness
Readability

Replacing the x86 pxor Assembly Instruction

Symptom

Error: unknown mnemonic 'pxor' -- 'pxor'

Cause

pxor is an x86 instruction and cannot be used on Kunpeng devices. It is used to perform a bitwise logical exclusive-OR (XOR) operation in either of the following ways:

  • Perform a bitwise XOR operation on the source operand (an xmm2 register or a 128-bit memory location) and the destination operand (xmm1), and store the result in xmm1.
    PXOR xmm1, xmm2/m128
  • Perform a bitwise XOR operation on the source operand (an mm2 register or a 64-bit memory location) and the destination operand (mm1), and store the result in mm1.
    PXOR mm1, mm2/m64 =

For more details, see:

https://c9x.me/x86/html/file_module_x86_id_272.html

Procedure

On the Kunpeng platform, use the NEON instruction EOR and store data in a 64-bit or 128-bit vector register.

EOR Vd.<T>, Vn.<T>, Vm.<T>

Bitwise exclusive OR (vector). Where <T> is 8B or 16B (an assembler should accept any valid arrangement).

Vn and Vm are the registers to be operated, Vd is the destination register, and <T> is the number of bits of the selected register.

The following is a simple process of using the NEON instruction EOR to perform the bitwise XOR operation on data.

/*
* Function: performs a bitwise XOR operation on arrays a and b and stores the result in result.
* The NEON instruction processes 16-byte data each time. Therefore, the data length is an integral multiple of 16 bytes.
 */
void eor_neon_asm(int* result, int* a, int* b, int len)
{
    __asm__("\n\t"
    "1:                               \n\t"
    "ld1 {v0.16b}, [%[a]], #16        \n\t"
    "ld1 {v1.16b}, [%[b]], #16        \n\t"
    "eor v0.16b, v0.16b, v1.16b       \n\t"
    "subs %[len],%[len],#4            \n\t"
    "st1 {v0.16b}, [%[result]], #16   \n\t"
    "bgt 1b                           \n\t"
    :[result]"+r"(result)                     //output
    :[a]"r"(a),[b]"r"(b),[len]"r"(len)        //input
    :"memory","v0","v1"
    );
    return;
}