Extensions
Forms
1 (1 Legacy)
Data
Intel XED v2026.08.23

BSWAP reverses the order of the bytes in a 32- or 64-bit register. That converts a value between little-endian, the order in which x86 keeps integers in memory, and big-endian, the order of network protocols and many file formats. GCC 14 and Clang 23 at -O2 compile __builtin_bswap32 and __builtin_bswap64 to it, and find it in plain C too: a 32-bit value assembled from four bytes, most significant first, as in p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3], becomes a 4-byte load and bswap eax.

16 bits

Both manuals leave BSWAP of a 16-bit register undefined and suggest an XCHG of its two bytes instead. On this site’s Zen 5, every 16-bit case recorded cleared the low 16 bits and kept bits 63:16. Compilers use neither: both compile __builtin_bswap16 to rol ax, 8, a ROL of the word by 8, which swaps its bytes.

Register only

BSWAP has no memory operand: its register is coded in the low three bits of the opcode, 0F C8 to 0F CF, with REX.B reaching R8 to R15 and REX.W choosing 64 bits. The 32-bit form clears bits 63:32 like any 32-bit write, so bswap eax is not half of a 64-bit swap.

MOVBE swaps the bytes as part of a load or a store. With -march=x86-64-v3, a level that includes it, both compilers turn the big-endian load above into a single movbe eax, dword ptr [rdi].

For arrays, Intel’s optimization manual prefers PSHUFB with a constant pattern, which reverses four doublewords at once: about twice as fast as BSWAP on the Intel Core microarchitecture, by its account (Section 6.6.5).

Forms

Every encoding of BSWAP that Intel XED knows, one row per XED instruction form (iform). How to read the notation.
InstructionEncodingRequires
BSWAP r16/32/64 BSWAP_GPRv0F C8+rBase instruction set

Latency and throughput

What the scheduling models of LLVM 23.1.2 give for each form, not measurements: latency / reciprocal throughput in cycles, the ports under them. A row is a model, or models that agree; a dash, a form that its processors lack. Memory forms: latency from the address, ports without the load and store units. Which processors each model covers.
Modelr32r64
Sandy Bridge1 / 1p12 / 1p015
Haswell, Broadwell, Skylake, Skylake-SP, Ice Lake1 / 0.5p152 / 0.5p0156
Alder Lake, Sapphire Rapids1 / 1p12 / 1p016
Lunar Lake1 / 0.33p1352 / 0.67p135
Bonnell1 / 1p01 / 1p0
Silvermont1 / 0.5IEC0 IEC11 / 0.5IEC0 IEC1
Piledriver1 / 0.5EX0 EX11 / 0.5EX0 EX1
Zen, Zen 21 / 1ALU0 ALU1 ALU2 ALU31 / 1ALU0 ALU1 ALU2 ALU3
Zen 3, Zen 41 / 0.25ALU0 ALU1 ALU2 ALU31 / 0.25ALU0 ALU1 ALU2 ALU3
Jaguar1 / 0.5ALU0 ALU11 / 0.5ALU0 ALU1

Operation

What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.

v = dest.read()
if OSIZE == 16:
    dest.write(UNDEFINED)        # the manuals leave the result undefined;
                                 # Zen 5 writes 0 and keeps bits 63:16
else:
    r = 0
    for i in range(OSIZE // 8):
        r = r << 8 | (v >> 8 * i & 0xFF)   # the bytes in reverse order
    dest.write(r)                # a 32-bit register: bits 63:32 cleared

Run on AMD Zen 5 (EPYC 9645): 18 cases.

Operands

What each form reads and writes, as Intel XED records it: the operands of its syntax, in order, and the implicit ones that the syntax does not name. How to read.
OperandKindAction
BSWAP r16/32/64
r16/32/64explicitread, write

Flags

None: XED records no flag that the forms test or change.

Intrinsics

The C intrinsics of Clang 23.1.2 that compile to BSWAP, each with the form it compiles to and the Clang options it needs. The forms come from compiling every intrinsic and decoding the result with Intel XED; all intrinsics A–Z explains the method.

IntrinsicCompiles to
_bswap int _bswap(int __A)

BSWAP r16/32/64 Legacy

_bswap64 long long _bswap64(long long A)

BSWAP r16/32/64 Legacy

__bswapd int __bswapd(int __A)

BSWAP r16/32/64 Legacy

__bswapq long long __bswapq(long long __A)

BSWAP r16/32/64 Legacy

CPUID and processors

Each form belongs to an XED ISA set. A form can be used when the processor reports every CPUID bit of one of its ISA set's alternatives.

CPUID requirements and processors of the XED ISA sets above. Alternatives are separated by “or”; processors follow XED’s chip model, whose AMD processors end with Zen 2, and the CPU data of this site for Zen 3 to Zen 6.
ISA setCPUIDProcessors
I486REAL

No CPUID bit: part of the base instruction set.

Every x86-64 processor in XED’s model and Zen 3 to Zen 6

More General-purpose instructions

All 109 General-purpose instructions

Sources

  1. Intel XED v2026.08.23 (commit 0bcb6237345c): forms, encodings, operands, flags, exception classes, attributes, ISA sets, CPUID bits and chip model.
  2. The CPU data of x86-64.net: Zen 3 to Zen 6, from GCC’s -march feature sets and AMD’s Processor Programming References, which the page of each processor cites.
  3. Clang's x86 intrinsic headers, LLVM 23.1.2 (commit 85ac56026243): the intrinsics, their signatures and doc comments, and the Clang of that release, which compiled each of them.
  4. LLVM 23.1.2's x86 scheduling models (commit 85ac56026243): the latency, reciprocal throughput and ports of each form, as llvm-mca reports them.
  5. Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2A, page 3-111 (BSWAP)
  6. AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.39, October 2026)
  7. Intel 64 and IA-32 Architectures Optimization Reference Manual, Volume 1 (248966-051, October 2026)

The tables are derived from Intel XED, Copyright Intel Corporation, licensed under the Apache License 2.0; x86-64.net converted and reformatted them. The intrinsics and their signatures come from Clang and the timings from LLVM's scheduling models, both part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.