assemblymasm

Why does MASM return an error when using the XACQUIRE and XRELEASE prefixes?


I'm experimenting with the Intel x86 Hardware Lock Elision feature using assembly language and the MASM Assembler. I'm getting the following errors;

error A2008: syntax error : MOV error A2008: syntax error : RET

The code is;

COMMENT '

 Hardware Lock Elision Test 1.

'

.686P
.MMX
.MODEL FLAT

.CODE

_main:

XACQUIRE MOV EAX, 10h

XRELEASE RET

END

It compiles fine without the XACQUIRE and XRELEASE prefixes.


Solution

  • Neither MOV EAX, 10h nor RET take HLE prefixes. Even if some assembler lets you write that code and assembles it to the expected byte sequences, processors will not interpret them in a useful way. In the case of xrelease ret, the machine code f3 c3 (which is what it would assemble to if it wasn't rejected by the assembler) would mean rep ret which is sometimes used as a workaround for an (obsolete) AMD quirk, but the rep prefix really means nothing in this context and is only used as padding.

    XAQUIRE and XRELEASE only make sense in combinations with some select instructions, as quoted from the Intel SDM:

    The XACQUIRE prefix hint can only be used with the following instructions (these instructions are also referred to as XACQUIRE-enabled when used with the XACQUIRE prefix):

    • Instructions with an explicit LOCK prefix (F0H) prepended to forms of the instruction where the destination operand is a memory operand: ADD, ADC, AND, BTC, BTR, BTS, CMPXCHG, CMPXCHG8B, DEC, INC, NEG, NOT, OR, SBB, SUB, XOR, XADD, and XCHG.
    • The XCHG instruction either with or without the presence of the LOCK prefix.

    The XRELEASE prefix hint can only be used with the following instructions (also referred to as XRELEASE-enabled when used with the XRELEASE prefix):

    • Instructions with an explicit LOCK prefix (F0H) prepended to forms of the instruction where the destination operand is a memory operand: ADD, ADC, AND, BTC, BTR, BTS, CMPXCHG, CMPXCHG8B, DEC, INC, NEG, NOT, OR, SBB, SUB, XOR, XADD, and XCHG.
    • The XCHG instruction either with or without the presence of the LOCK prefix.
    • The “MOV mem, reg” (Opcode 88H/89H) and “MOV mem, imm” (Opcode C6H/C7H) instructions. In these cases, the XRELEASE is recognized without the presence of the LOCK prefix.

    Note also that HLE is essentially dead: not supported by new processors ("not supported" in the context of HLE means that the prefixes do nothing, not that they fault, such compatibility is why those prefixes were chosen) and disabled by a microcode update for older processors. You can use the prefixes if you want, but typically they will do nothing.