Instruction
FPREM1
Stores in ST(0) the partial IEEE 754 remainder of ST(0) divided by ST(1), with the quotient rounded to nearest; C2 says whether to repeat.
- Extensions
- Forms
- 1 (1 Legacy)
- Data
- Intel XED v2026.08.23
FPREM1 replaces ST(0) by the remainder of ST(0) divided by ST(1), with
the quotient rounded to the nearest integer and ties going to the even
one: the remainder of IEEE 754, C’s remainder. Its magnitude is at
most half of ST(1)’s, and its sign is whichever makes it so, not the
dividend’s; only a zero remainder keeps the dividend’s sign.
FPREM truncates the quotient instead, as the 8087 and
the 287 did, C’s fmod. Its page covers what they share: the partial
remainder with C2 set, the loop that finishes it, and the low quotient
bits in C0, C3 and C1.
Rounding the quotient
On Zen 5:
| Operands | FPREM1 | Quotient |
|---|---|---|
| 7 by 2 | -1 | 4 |
| 5 by 2 | 1 | 2, the even one of 2 and 3 |
| 7.5 by 1 | -0.5 | 8 |
| 6.5 by 1 | 0.5 | 6 |
| 10 by 0.1, the nearest 80-bit number | about -1.4 * 10^-19 | 100 |
Where FPREM’s results are all positive here, FPREM1’s are as close to zero as the quotient allows. In the last row FPREM1 shows how far 10 is from a multiple of the divisor, where FPREM would give almost a whole 0.1. RC plays no part: the remainder is exact, so it never sets PE, and 1.5 by 1 gave -0.5 under rounding toward zero too.
From C
GCC 14 at -O2 compiles remainderl(x, y) on a long double, and
remainder on a double, to the loop of fprem1,
FNSTSW AX, test ah, 4 and a jne back, calling the
library only when the result is a NaN, for errno; with -ffast-math
the call goes. Clang 23 calls the library in both cases.
Tiny remainders
The remainder of two normal numbers can be a denormal: 1.5 * 2^-16382 by 2^-16382 gave -2^-16383, exact and without UE while UE was masked. With UE unmasked, Zen 5 left the remainder with its exponent raised by 24576, -2^8193 in place of -2^-16383, set UE and raised #MF.
AMD’s Zen 5 guide lists FPREM1 like FPREM: two macro-ops, of which a core starts one every nine cycles at most.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
FPREM1
FPREM1 | D9 F5 | FPU |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
c2 = 0 # first: an exception leaves it 0
if empty(st0) or empty(st1):
underflow() # IE, SF, C1 = 0
st0 = INDEFINITE # C0 and C3 stay
else:
r = prem1(st0, st1) # ST(0) - q * ST(1), exact, with q =
# ST(0) / ST(1) to the nearest integer,
# even on a tie: IEEE's remainder
st0 = r
c1 = r.quotient & 1 # q's low three bits: C0, C3, C1
if r.partial: # the exponents were 64 or more apart:
c2 = 1 # q had only the quotient's top 32 to
c0 = c3 = 0 # 63 bits, truncated; run it again
elif not is_nan(r): # a NaN leaves C0 and C3
c3 = r.quotient >> 1 & 1
c0 = r.quotient >> 2 & 1Run on AMD Zen 5 (EPYC 9645): 34 cases.
Operands
| Operand | Kind | Action |
|---|---|---|
FPREM1 | ||
ST(0) | implicit | read, write |
ST(1) | implicit | read |
x87 status word | implicit | write |
Flags
| C0 | C1 | C2 | C3 |
|---|---|---|---|
| All forms | |||
| M | M | M | M |
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 |
|---|---|---|
X87 | FPU | Every x86-64 processor in XED’s model and Zen 3 to Zen 6 |
More x87 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. - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2A, page 3-368 (FPREM1)
- Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1 (253665-093, September 2026)
- AMD64 Architecture Programmer's Manual, Volume 5: 64-Bit Media and x87 Floating-Point Instructions (26569, rev. 3.16, November 2021), Wayback Machine copy of AMD's PDF
- Software Optimization Guide for the AMD Zen5 Microarchitecture (58455, rev. 1.00, August 2024), Wayback Machine copy of AMD's ZIP
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 text is our own.