ArticleslgStudy

computer science

Multiply–accumulate operation

Multiply–accumulate operation 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 Multiply–accumulate operation rather than just read about it. In short: In computing, especially digital signal processing, the multiply–accumulate (MAC) or multiply–add (MAD) operation is a common step that computes the product of two numbers and adds that product to an accumulator. The hardware unit that performs the operation is known as a multiplier–accumulator (MAC unit); the operation itself is also often called a MAC or a MAD operation.

Key takeaways

  • Multiply–accumulate operation 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 Multiply–accumulate operation to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Multiply–accumulate operation from memory before moving on to harder problems.

Reference excerpt

In computing, especially digital signal processing, the multiply–accumulate (MAC) or multiply–add (MAD) operation is a common step that computes the product of two numbers and adds that product to an accumulator. The hardware unit that performs the operation is known as a multiplier–accumulator (MAC unit); the operation itself is also often called a MAC or a MAD operation. The MAC operation modifies an accumulator a:

a ← a + ( b × c ) {\displaystyle a\gets a+(b\times c)}

When done with floating-point numbers, it might be performed with two roundings (typical in many DSPs), or with a single rounding. When performed with a single rounding, it is called a fused multiply–add (FMA) or fused multiply–accumulate (FMAC). Modern computers may contain a dedicated MAC, consisting of a multiplier implemented in combinational logic followed by an adder and an accumulator register that stores the result. The output of the register is fed back to one input of the adder, so that on each clock cycle, the output of the multiplier is added to the register. Combinational multipliers require a large amount of logic, but can compute a product much more quickly than the method of shifting and adding typical of earlier computers. Percy Ludgate was the first to conceive a MAC in his Analytical Machine of 1909, and the first to exploit a MAC for division (using multiplication seeded by reciprocal, via the convergent series (1+x)−1). The first modern processors to be equipped with MAC units were digital signal processors, but the technique is now also common in general-purpose processors.

In floating-point arithmetic When done with integers, the operation is typically exact (computed modulo some power of two). However, floating-point numbers have only a certain amount of mathematical precision. That is, digital floating-point arithmetic is generally not associative or distributive. (See Floating-point arithmetic § Accuracy problems.) Therefore, it makes a difference to the result whether the multiply–add is performed with two roundings, or in one operation with a single rounding (a fused multiply–add). IEEE 754-2008 specifies that it must be performed with one rounding, yielding a more accurate result.

Fused multiply–add A fused multiply–add (FMA or fmadd) is a floating-point multiply–add operation performed in one step (fused operation), with a single rounding. That is, where an unfused multiply–add would compute the product b × c, round it to N significant bits, add the result to a, and round back to N significant bits, a fused multiply–add would compute the entire expression a + (b × c) to its full precision before rounding the final result down to N significant bits. A fast FMA can speed up and improve the accuracy of many computations that involve the accumulation of products:

Dot product Matrix multiplication Polynomial evaluation (e.g., with Horner's rule) Newton's method for evaluating functions (from the inverse function) Convolution Neural network Multiplication in double-double arithmetic Fused multiply–add can usually be relied on to give more accurate results. However, William Kahan has pointed out that it can give problems if used unthinkingly. If x2 − y2 is evaluated as ((x × x) − y × y) (following Kahan's suggested notation in which redundant parentheses direct the compiler to round the (x × x) term first) using fused multiply–add, then the result may be negative even when x = y due to the first multiplication discarding low significance bits. This could then lead to an error if, for instance, the square root of the result is then evaluated. When implemented inside a microprocessor, an FMA can be faster than a multiply operation followed by an add. However, standard industrial implementations based on the original IBM RS/6000 design require a 2N-bit adder to compute the sum properly. Another benefit of including this instruction is that it allows an efficient software implementation of division (see division algorithm) and square root (see methods of computing square roots) operations, thus eliminating the need for dedicated hardware for those operations.

Dot-product instruction Some machines combine multiple fused multiply add operations into a single step, e.g. performing a four-element dot-product on two 128-bit SIMD registers a0×b0 + a1×b1 + a2×b2 + a3×b3 with single cycle throughput.

Support The FMA operation is included in IEEE 754-2008. The 1999 standard of the C programming language supports the FMA operation through the fma() standard math library function and the automatic transformation of a multiplication followed by an addition (contraction of floating-point expressions), which can be explicitly enabled or disabled with standard pragmas (#pragma STDC FP_CONTRACT). The GCC and Clang C compilers do such transformations by default for processor architectures that support FMA instructions. With GCC, which does not support the aforementioned pragma, this can be globally controlled by the -ffp-contract command line option. The fused multiply–add operation was introduced as "multiply–add fused" in the IBM POWER1 (1990) processor, but has been added to numerous processors:

IBM POWER1 (1990) HP PA-8000 (1996) and above Hitachi SuperH SH-4 (1998) IBM z/Architecture (since 1998) SCE-Toshiba Emotion Engine (1999) Intel Itanium (2001) STI Cell (2006) Fujitsu SPARC64 VI (2007) and above (MIPS-compatible) Loongson-2F (2008) RISC-V instruction set (2010) ARM processors with VFPv4 and/or NEONv2: ARM Cortex-M4F (2010) STM32 Cortex-M33 (VFMA operation) ARM Cortex-A5 (2012) ARM Cortex-A7 (2013) ARM Cortex-A15 (2012) Qualcomm Krait (2012) Apple A6 (2012) All ARMv8 processors Fujitsu A64FX has "Four-operand FMA with Prefix Instruction". x86 processors with FMA3 and/or FMA4 instruction set AMD Bulldozer (2011, FMA4 only) AMD Piledriver (2012, FMA3 and FMA4) Intel Haswell (2013, FMA3 only) AMD Steamroller (2014, FMA3 and FMA4) AMD Excavator (2015, FMA3 and FMA4) Intel Skylake (2015, FMA3 only) AMD Zen (2017, FMA3 only) Elbrus-8SV (2018) GPUs and GPGPU boards:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Multiply–accumulate operation

Start with the simplest possible case. Write down what Multiply–accumulate operation 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 Multiply–accumulate operation 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 Multiply–accumulate operation 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 Multiply–accumulate operation

In research
Multiply–accumulate operation 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 Multiply–accumulate operation 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
Multiply–accumulate operation is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer arithmetic, Digital signal processing, so understanding it makes those chapters shorter.
In everyday life
Look for Multiply–accumulate operation 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 “Multiply–accumulate operation” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Multiply–accumulate operation in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Multiply–accumulate operation 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 Multiply–accumulate operation out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Multiply–accumulate operation in simple terms?

In computing, especially digital signal processing, the multiply–accumulate (MAC) or multiply–add (MAD) operation is a common step that computes the product of two numbers and adds that product to an accumulator. The hardware unit that performs the operation is known as a multiplier–accumulator (MA…

Why does Multiply–accumulate operation 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 Multiply–accumulate operation?

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 Multiply–accumulate operation.

Tags

  • Computer arithmetic
  • Digital signal processing

Keep exploring