Instruction
LGS
Loads a far pointer from memory into a register and GS.
- Extensions
- Forms
- 1 (1 Legacy)
- Data
- Intel XED v2026.08.23
LGS loads a far pointer from memory, an offset and then a 16-bit selector, into a general register and GS. It is LFS with GS for FS, opcode 0F B5 for 0F B4, and that page covers the pointer’s sizes, the checks of the selector and the REX.W form, where Intel’s manual reads an 80-bit pointer and AMD’s supports none; Zen 5 read 48 bits. Zen 5 recorded the same results for LGS as for LFS: the same selectors loaded and the same four raised #GP.
The active base only
A selector load takes GS’s base from the descriptor, 32 bits with bits 63:32 cleared. Zen 5, given random 64-bit bases, had a GS base of 0 after LGS loaded 2Bh, Linux’s user data segment, and the FS base unchanged. In 64-bit mode two GS bases exist: the active one and the IA32_KERNEL_GS_BASE MSR, which SWAPGS exchanges on the way into the kernel and out. LGS, like MOV to GS, writes only the active one. Intel added LKGS for the other: it checks a selector the same way but puts the descriptor’s base in IA32_KERNEL_GS_BASE; it came with FRED, which makes the swap itself.
In user space
Linux’s documentation leaves GS to the program, where FS belongs to the
threading library, and gives WRGSBASE and
arch_prctl(ARCH_SET_GS, ...) to set its base; an LGS replaces it with
a descriptor’s base, 0 for 2Bh. GCC 14 and Clang 23 do not use LGS for
their __seg_gs address space: they put a GS prefix on the access,
mov eax, dword ptr gs:[rdi+0xc], and leave the base to whoever set
it.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
LGS r16/32/64, m16:16/32/64
LGS_GPRv_MEMp2 | 0F B5 /r | Base instruction set |
Latency and throughput
| Model | r16, m16:16/32/64r32, m16:16/32/64r64, m16:16/32/64 |
|---|---|
| Sandy Bridge | 100 / 0.33p015 |
| Haswell, Broadwell, Skylake, Skylake-SP, Ice Lake, Alder Lake, Sapphire Rapids | 100 / 0.25p0156 |
| Lunar Lake | 100 / 0.17p012345 |
| Bonnell | 100 / 0.5p1 |
| Silvermont | 100 / 1FPC0 |
| Piledriver | 100 / 0.5EX0 EX1 |
| Zen, Zen 2 | 100 / 0.25 |
| Zen 3, Zen 4 | 100 / 25ALU0 ALU1 ALU2 ALU3 |
| Jaguar | 100 / 0.5ALU0 ALU1 |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
n = OSIZE # the offset's size
if OSIZE == 64: # REX.W: m16:64 on Intel's (SDM
# Volume 2A, LDS/LES/LFS/LGS/LSS,
# rev. 093)
if AMD:
n = 32 # no m16:64, but m16:32 (APM Volume
# 3, LFS and Table B-1, rev. 3.36;
# Zen 5)
off = load(src.address, n) # the offset, then the selector
sel = load(src.address + n // 8, 16)
load_segment(gs, sel) # checks the descriptor it names,
# whose base GS takes
dest.write(off) # REX.W on AMD's: bits 63:32 cleared
Run on AMD Zen 5 (EPYC 9645): 18 cases. Its branches for Intel's processors were not run: no Intel processor ran these forms.
Operands
| Operand | Kind | Action |
|---|---|---|
LGS r16/32/64, m16:16/32/64 | ||
r16/32/64 | explicit | write |
m16:16/32/64 | explicit | read |
GS | implicit | write |
Flags
None: XED records no flag that the forms test or change.
Attributes
What else XED records about the forms. How to read.
- All forms
- may abort a TSX transaction
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.
| ISA set | CPUID | Processors |
|---|---|---|
I386 | 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
Sources
- Intel XED v2026.08.23 (commit
0bcb6237345c): forms, encodings, operands, flags, exception classes, attributes, ISA sets, CPUID bits and chip model. - The CPU data of x86-64.net: Zen 3 to Zen 6, from GCC’s
-marchfeature sets and AMD’s Processor Programming References, which the page of each processor cites. - LLVM 23.1.2's x86 scheduling models (commit
85ac56026243): the latency, reciprocal throughput and ports of each form, as llvm-mca reports them. - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2A, page 3-540 (LDS/
LES/ LFS/ LGS/ LSS) - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3 (325384-093, September 2026)
- AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.39, October 2026)
- Linux kernel documentation: Using FS and GS segments in user space applications
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 timings come from LLVM's scheduling models, part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.