Speeding Up Matrix Multiplication and Chapter Three's Key Lessons

Matrix multiplication is one of the most common and performance-critical operations in scientific computing and machine learning. This article shows how subword parallelism accelerates this operation in practice, then closes out the arithmetic chapter by addressing common misconceptions about computer arithmetic and summarizing the core lessons from addition through floating point.

Matrix Multiplication PerformanceArithmetic FallaciesChapter Three Summary

~3 min read · Updated Sep 6, 2026

Why Matrix Multiplication Is a Natural Fit for Parallelism

Matrix multiplication involves computing many independent sums of products, where each output element is calculated from a row of one matrix and a column of another. Because these individual calculations do not depend on each other, this operation is an ideal candidate for the kind of data-level parallelism discussed earlier in this series.

Applying Subword Parallelism to Matrix Multiply

Instead of computing each multiplication and addition in a matrix one at a time, a processor using Subword Parallelism can pack multiple values from a row and a column into a single wide register and perform several multiply-and-add operations simultaneously within one instruction.

Instead of:
result += a[0]*b[0]
result += a[1]*b[1]
result += a[2]*b[2]
result += a[3]*b[3]
(4 separate multiply-add steps)

Using subword parallelism:
One instruction multiplies and adds
all 4 pairs simultaneously

This significantly reduces the number of instructions needed for a computation that is repeated an enormous number of times in workloads such as neural network training, physics simulations, and graphics rendering, making it one of the most practically important applications of the ideas covered throughout this chapter.

Common Fallacies About Computer Arithmetic

A few persistent misunderstandings about arithmetic hardware are worth addressing directly.

  • Assuming floating-point numbers can represent every real number exactly — as covered earlier, most fractional values are rounded to the nearest representable approximation.
  • Assuming multiplication and division always take the same amount of time as addition — in reality, these operations require substantially more hardware steps, as detailed earlier in this series.
  • Assuming overflow is automatically caught and reported by hardware in every case — RISC-V, as discussed, leaves signed overflow detection largely to software rather than trapping automatically.

Common Pitfalls in Arithmetic-Heavy Code

Beyond outright misunderstandings, certain coding patterns commonly cause subtle problems.

  • Comparing floating-point values for exact equality instead of checking whether they fall within a small acceptable tolerance of each other.
  • Mixing signed and unsigned values in the same comparison or calculation without accounting for how differently they interpret the same bit pattern.
  • Overlooking the performance cost of unnecessary division inside loops that execute a very large number of times.

Chapter Summary: From Bits to Real-World Numbers

This chapter traced arithmetic hardware from its simplest form to its most demanding: addition and subtraction sharing a single circuit through two's complement representation, multiplication and division built from repeated simpler steps, floating point encoding an enormous range of real numbers into a fixed number of bits, and subword parallelism applying the same operation to many values at once for practical performance gains. Together, these mechanisms allow the small set of hardware operations covered in the previous chapter to support everything from basic counting to scientific simulation and machine learning.

Written & researched by Dr. Shahin Siami

Related Articles

A Unified Framework for Understanding Every Memory Hierarchy Level

Caches and virtual memory appear at first glance to be very different systems, yet both are answering the exact same four fundamental questions. This article shows how those four questions unify block placement, block identification, block replacement, and write handling across every level of the memory hierarchy, from tiny caches to disk-backed virtual memory.

Continue

Virtual Memory: Giving Every Program Its Own Private Address Space

Programs behave as if they have access to a huge, private block of memory, even though physical RAM is limited and shared among many running processes. This article explains how virtual memory creates this illusion through address translation, how page tables and the TLB make translation fast, and what happens when needed data is not currently in physical memory.

Continue

Virtual Machines: Running Multiple Isolated Systems on One Computer

A single physical computer can appear to run several completely separate operating systems at once, each unaware of the others' existence. This article explains what a virtual machine actually is, how a hypervisor manages this illusion, and why this technology matters for both server consolidation and system security.

Continue

Dependable Memory: How Hardware Detects and Corrects Data Errors

Memory hardware is not perfectly reliable; electrical noise and physical defects can silently flip stored bits. This article explains how error detection and correction codes let hardware notice, and in many cases automatically fix, these corrupted values before they cause incorrect program behavior.

Continue

Measuring and Improving Cache Performance

Not all cache misses are the same, and understanding their causes is the first step toward improving performance. This article covers how to calculate the real performance impact of caching using miss rate and miss penalty, classifies the three common causes of cache misses, and explains practical strategies for reducing each type.

Continue

Cache Fundamentals: How Small, Fast Memory Predicts What You Need Next

A cache works because programs tend to access the same or nearby data repeatedly rather than randomly. This article explains the principle of locality that makes caching effective, how a direct-mapped cache locates data using an address, and what happens on a cache hit versus a cache miss.

Continue