ArticleslgStudy

computer science

FMA instruction set

FMA instruction set is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand FMA instruction set rather than just read about it. In short: The FMA instruction set is an extension to the x86 microprocessor instruction set to perform fused multiply–add (FMA) operations on 128-bit and 256-bit operands. These operations were extended to 512-bit operands by the AVX-512 extension introduced by Intel and later supported by AMD.

Key takeaways

  • FMA instruction set belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect FMA instruction set to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of FMA instruction set from memory before moving on to harder problems.

Reference excerpt

The FMA instruction set is an extension to the x86 microprocessor instruction set to perform fused multiply–add (FMA) operations on 128-bit and 256-bit operands. These operations were extended to 512-bit operands by the AVX-512 extension introduced by Intel and later supported by AMD. There are two incompatible variants of the FMA instruction set. They have the same operations but differ in the number of operands:

FMA4 is the four-operand variant (three source operands and a destination register). AMD added FMA4 with the Bulldozer (2011) architecture. Zen 1 (2017) processors still execute FMA4 instructions but do not report them as supported through CPUID, and Zen 2 (2019) removed them. Intel originally specified FMA4 in 2008, but changed its design to three operands later that year. FMA3 is the three-operand variant (three source operands, one of which is also the destination). AMD added FMA3 with the Piledriver (2012) architecture, for compatibility with Intel's planned Haswell processors. Intel added FMA3, alongside AVX2, with Haswell (2013) processors. Earlier processors, including AMD's Bulldozer and Intel's Sandy Bridge and Ivy Bridge, do not support it. AVX-512 adds 512-bit forms of the FMA3 instructions.

Operations An FMA operation has the form d=round⁡(±a⋅b±c), where the operands are floating-point scalars or SIMD vectors. The exact value of ±a⋅b±c is rounded only once to the precision of the destination format (i.e. single or double precision). In the IEEE 754-2008 standard for floating-point arithmetic, the operation is called fusedMultiplyAdd and conforming implementations must provide it. The result is usually more accurate than that of separate multiply and add instructions. FMA3 and FMA4 have the same six operations. The operations differ only in the signs of the product and of c.

The two alternating operations exist only for vectors. Vector elements are numbered from 0.

Compatibility Although FMA3 and FMA4 have the same operations, their instructions differ in operands and encoding. Their instructions have different opcodes in different opcode maps. An instruction of one variant is an invalid opcode on a processor that supports only the other. Each variant has its own CPUID feature flag: FMA for FMA3 and FMA4 for FMA4. Their operands differ as follows:

FMA4 instructions have a destination and three sources. Their operands a, b, c, and d can be four different registers. Either of the last two sources can be in memory. The fourth register is encoded in an extra byte. Each FMA4 instruction is one byte longer than the matching FMA3 instruction. FMA3 instructions have three operands. The result is written over the first operand. The destination d is therefore the same register as a, b, or c. Only the third operand can be in memory. Each FMA3 operation has three operand orders numbered 132, 213, and 231. The orders differ in whether the overwritten register and the memory operand are factors or the summand. The input to be overwritten must first be copied to another register if all three inputs are still needed afterwards. The examples below contain such copies. The split between FMA3 and FMA4 followed changes of plan by Intel and AMD. AMD Fellow Dave Christie wrote in May 2009 that AMD could not adopt Intel's December 2008 change of FMA from four to three operands without unacceptable risk to its product schedules. AMD therefore kept the four-operand form from Intel's earlier specification. Josh Walrath of PC Perspective wrote in 2009 that it was "unfortunate that AMD and Intel cannot work together a bit better on these things". Agner Fog wrote in 2009 that Intel, AMD, and VIA "are assigning different codes to identical or equivalent instructions because each keep their innovations secret for as long as possible". In 2011, he listed FMA3 and FMA4 among several pairs of AMD and Intel instructions with incompatible encodings. He wrote that Intel had given its own VEX encodings to instructions that AMD had first defined in the XOP encoding.

Naming Intel and AMD define the same FMA3 mnemonics in their instruction-set manuals. The FMA4 mnemonics are defined only in AMD's manual. Each FMA mnemonic consists of a stem from the table above and a postfix for the data format:

PS: packed single precision PD: packed double precision SS: scalar single precision SD: scalar double precision In a packed instruction, the operation is applied to every element of a vector. In a scalar instruction, it is applied only to the lowest element. An FMA4 mnemonic is the stem followed directly by the postfix, as in VFMADDPS. In an FMA3 mnemonic, the operand order 132, 213, or 231 comes between the stem and the postfix, as in VFMADD213PS.

Rounding

The exact intermediate value of an FMA instruction exists only inside the processor and cannot be examined by software. FMA results are rounded in the rounding mode set in the processor's MXCSR control and status register. For AVX-512 instructions, a rounding mode can instead be encoded in the 512-bit and scalar forms whose operands are all registers. Under IEEE 754-2008, overflow, underflow, and inexact exceptions in a fused multiply–add can arise only from the addition and not from the multiplication. With separate multiply and add instructions, the product is rounded before the addition. The result is then rounded twice: round⁡(round⁡(a⋅b)+c). On x86 processors without FMA3 or FMA4, a result rounded only once is still available from the C fma function. Intel describes its own implementation as having some cost in speed.

Contraction by C compilers In the C programming language, since the 1999 revision, an expression such as a * b + c may be contracted into a single fused operation. Whether contraction is allowed is controlled by the STDC FP_CONTRACT pragma, and its default status is implementation-defined. When compiling for a processor with FMA instructions:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with FMA instruction set

Start with the simplest possible case. Write down what FMA instruction set claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to FMA instruction set before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about FMA instruction set ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of FMA instruction set

In research
FMA instruction set appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses FMA instruction set in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
FMA instruction set is common in secondary-school and first-year university syllabi. It links to neighbouring topics AMD technologies, Instruction set extensions, SIMD computing, so understanding it makes those chapters shorter.
In everyday life
Look for FMA instruction set outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “FMA instruction set” →

How to study FMA instruction set in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what FMA instruction set means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain FMA instruction set out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is FMA instruction set in simple terms?

The FMA instruction set is an extension to the x86 microprocessor instruction set to perform fused multiply–add (FMA) operations on 128-bit and 256-bit operands. These operations were extended to 512-bit operands by the AVX-512 extension introduced by Intel and later supported by AMD.

Why does FMA instruction set matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study FMA instruction set?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on FMA instruction set.

Tags

  • AMD technologies
  • Instruction set extensions
  • SIMD computing
  • X86 instructions

Keep exploring