ADCX

Unsigned Integer Addition of Two Operands With Carry Flag

stableVMJITAOTinstruction

Encodings

OpcodeInstructionOp/En64-bitCompat/LegacyDescription
66 0F 38 F6 /rADCX r32, r/m32RMValidValidUnsigned addition of r32 with CF, r/m32 to r32, writes CF.
66 REX.w 0F 38 F6 /rADCX r64, r/m64RMValidNot encodableUnsigned addition of r64 with CF, r/m64 to r64, writes CF.

Operand encoding

Each mode is a value of the Op/En column above. It says which field of the encoded instruction carries each operand, in the order they are written, and whether the instruction reads it, writes it or both.

RM

  1. modrm.reg lectura y escrituraModRM byte, reg field (bits 5-3)
  2. modrm.rm lecturaModRM byte, r/m field (bits 2-0); with the SIB byte and the displacement when the mod field asks for them

Measured cost

Loading measurements from arch-data...

Flags named

Description

Performs an unsigned addition of the destination operand (first operand), the source operand (second operand) and the carry-flag (CF) and stores the result in the destination operand. The destination operand is a generalpurpose register, whereas the source operand can be a general-purpose register or memory location. The state of CF can represent a carry from a previous addition. The instruction sets the CF flag with the carry generated by the unsigned addition of the operands.

The ADCX instruction is executed in the context of multi-precision addition, where we add a series of operands with a carry-chain. At the beginning of a chain of additions, we need to make sure the CF is in a desired initial state. Often, this initial state needs to be 0, which can be achieved with an instruction to zero the CF (e.g., XOR).

This instruction is supported in real mode and virtual-8086 mode. The operand size is always 32 bits if not in 64-bit mode.

In 64-bit mode, the default operation size is 32 bits. Using a REX Prefix in the form of REX.R permits access to additional registers (R8-15). Using REX Prefix in the form of REX.W promotes operation to 64 bits.

ADCX executes normally either inside or outside a transaction region. Note: ADCX defines the OF flag differently than the ADD/ADC instructions as defined in the Intel(R) 64 and IA-32 Architectures Software Developer's Manual, Volume 2A.

Operation

IF OperandSize is 64-bit

    THEN CF:DEST[63:0] := DEST[63:0] + SRC[63:0] + CF;
    ELSE CF:DEST[31:0] := DEST[31:0] + SRC[31:0] + CF;
FI;

Flags affected

CF is updated based on result. OF, SF, ZF, AF, and PF flags are unmodified.

Intel C/C++ compiler intrinsics

unsigned char _addcarryx_u32 (unsigned char c_in, unsigned int src1, unsigned int src2, unsigned int *sum_out);
unsigned char _addcarryx_u64 (unsigned char c_in, unsigned __int64 src1, unsigned __int64 src2, unsigned __int64 *sum_out);

SIMD Floating-Point Exceptions

None.

Exceptions

Protected mode
#UDIf the LOCK prefix is used. If CPUID.07H.00H:EBX.ADX[19] = 0.
#SS(0)For an illegal address in the SS segment.
#GP(0)For an illegal memory operand effective address in the CS, DS, ES, FS or GS segments. If the DS, ES, FS, or GS register is used to access memory and it contains a null segment selector. #PF(fault-code) For a page fault.
#AC(0)If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.
Real address mode
#UDIf the LOCK prefix is used. If CPUID.07H.00H:EBX.AVX[19] = 0.
#SS(0)For an illegal address in the SS segment.
#GP(0)If any part of the operand lies outside the effective address space from 0 to FFFFH.
Virtual-8086 mode
#UDIf the LOCK prefix is used. If CPUID.07H.00H:EBX.AVX[19] = 0.
#SS(0)For an illegal address in the SS segment.
#GP(0)If any part of the operand lies outside the effective address space from 0 to FFFFH. #PF(fault-code) For a page fault.
#AC(0)If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.
Compatibility mode
Same exceptions as in protected mode.
64-bit mode
#UDIf the LOCK prefix is used. If CPUID.07H.00H:EBX.AVX[19] = 0.
#SS(0)If a memory address referencing the SS segment is in a non-canonical form.
#GP(0)If the memory address is in a non-canonical form. #PF(fault-code) For a page fault.
#AC(0)If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.

Sources