Lab 28: Does Your CPU Have an FPU?
Time: ~40 minutes | Prerequisites: Lab 27 | Hardware: Pico 2
Ask the chip before you trust it
Five minutes of probing beats four attempts at debugging. An earlier version of this course spent enormous effort on assembly that could never run — because nobody asked the silicon first.
What You'll Build
A capability probe that reads the CPU's own registers, then tests what the assembler will actually emit.
Learning Objectives
- Query the CPUID register to identify the core
- Read MVFR0 to detect floating-point hardware
- Distinguish what the chip implements from what the assembler exposes
- Explain why the previous generation of this course could never have worked
- Gate later work on a capability check
Concepts Introduced
| ID | Concept |
|---|---|
| 478 | Instruction Set Architecture |
| 479 | ARMv6-M |
| 480 | ARMv7-M |
| 481 | ARMv8-M |
| 482 | Cortex M0 Plus |
| 483 | FPU Presence Detection |
| 484 | MVFR0 Register |
| 485 | FPv5-SP Unit |
| 486 | Capability Probing |
| 487 | Hardware Feature Gate |
| 488 | Portability Constraint |
| 489 | Failure Root Cause |
Procedure
Open 28-fpu-check.py and work through it section by section:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
Each part builds on the last, and the comments in the file explain the reasoning as you go. Run it, read it, then change something and run it again.
Predict before you measure
Wherever this lab reports a speedup, write your guess down before you
run it. Every quantitative prediction made while building this course
turned out to be optimistic — being wrong on paper is how you find out
what the machine really does.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
unsupported Thumb instruction |
The assembler lacks that mnemonic | Check Lab 28's probe; see Lab 33 for the workaround |
| Assembly returns nonsense | Wrong argument order | Arguments arrive in r0, r1, r2, r3 |
| Results differ between runs | No warm-up, or heap state | Discard a warm-up; build objects before measuring (Labs 26, 32) |
| Variant looks slower than baseline | Measurement artifact | Re-run with everything allocated up front |
MemoryError |
Too many variants alive | gc.collect() between sections |
Check Your Understanding
- What does this lab measure, and what does it deliberately exclude?
- Which result surprised you most against your prediction, and why?
- What would you change to make the effect larger?
- Where would this technique NOT be worth the complexity?
Onward
You know what your silicon can do, and you asked it rather than assuming. Now we can write assembly with confidence.