binutils Newspaper
NOVEMBER 30, 2026
x86/apx — Proposed

x86/APX: optimize {nf} forms of OR/XOR with small immediates

Optimizes OR/XOR instructions in gas for x86 APX to use smaller immediate forms for size reduction.

This patch optimizes the assembly of OR and XOR instructions in the gas assembler for x86 APX targets when used with small immediates. It leverages the behavior of non-EVEX.ND byte/word operations which leave upper bits unaltered. The optimization transforms larger forms of these instructions into their smaller byte or word equivalents, aiming to reduce code size, particularly when optimizing for space (-Os).

In the Thread 1 participant
  1. Jan Beulich <jbeulich@suse.com> proposer

    Proposes an optimization for OR/XOR instructions with small immediates in the x86 APX gas assembler. The change transforms instructions into smaller byte/word forms to reduce code size when optimizing for space.

    “These can be expressed with byte or word forms, leveraging that non- EVEX.ND byte/word operations leave the upper bits unaltered. Since - word forms incur length-changing-prefix effects, - byte and word forms can incur partial register stalls, restrict transforming those to merely size optimization.”

In Details

This patch targets the x86 instruction emitter in gas, specifically for the APX (Advanced Performance Extensions) instruction set. It optimizes the encoding of non-fused (nf) forms of OR and XOR instructions when a small immediate operand is used. The optimization leverages the fact that byte and word operations on registers (e.g., ORb, ORw) only affect the lower bits, and any upper bits in the destination register are zeroed or preserved depending on the instruction's mode. This allows larger immediates (up to 16-bit) to be encoded using their 8-bit forms where possible, and 64-bit f…

For Context
x86/APX
Refers to the x86 instruction set architecture with Advanced Performance Extensions, a set of newer instructions for Intel processors designed to improve performance.
gas
The GNU Assembler, part of the GNU Binutils project, responsible for converting assembly code into machine code.
OR/XOR
Bitwise logical operations. OR sets a bit if it is set in either operand; XOR sets a bit if it is set in one operand but not both.
immediate
A constant value embedded directly within an instruction, rather than being stored in a register or memory location.
EVEX.ND
Encoding for advanced vector extensions (AVX-512 and later) in x86. 'ND' likely refers to 'not-downconverted' or a similar encoding detail relevant to operation size and masking.
-Os
A compiler optimization flag that instructs the compiler to optimize for code size.
Filed Under: x86assembleroptimizationcode size