Hardware or Software, and the Cost of a Late Change
Any function of a chip can be a block of logic or a few lines of program. Learn what each choice costs, and why the date of a change matters most.
You Will Be Able To
- Count the clock cycles of one function built as software and as hardware.
- Choose between the two from how often the function runs and how settled it is.
- Say what a change costs before tape-out, and after it.
- Lesson
- S1.9
- Time
- 22 min
- Runs on
- Your browser
- Check
- 5 questions
A block counts the 1 bits of a word in one clock cycle, a hundred times faster than the program it replaced. A year later the rule changes, and the slow program is the one still in use.
Before You Start
You need Amdahl's law from S1.5, and the price of cells from S1.8. You need tape-out and firmware from S1.4.
| Question | |
|---|---|
| 1 | What does it mean to build a function as hardware, or as software? |
| 2 | What does each way cost? |
| 3 | Which functions belong in hardware? |
| 4 | What does a change cost after the chip is made? |
| 5 | How can hardware keep some of the freedom of software? |
The Idea: The Same Function, Two Places to Put It
An SoC has a processor, so it can compute anything, given time. It also has room for blocks of logic that each do one job quickly. Every function of the product must go to one or the other.
Deciding this for every function is called the hardware and software partition. The architect makes it early, in the architecture stage of S1.4.
The two sides differ in speed, as you would expect. They differ more in something else. Software can be changed after the chip is made. Hardware cannot. So the partition also decides which mistakes can still be repaired.
New Words
| Word | Meaning |
|---|---|
| Partition | The decision, for each function, whether a block of logic does it or the program does it. |
| Accelerator | A block built to do one function much faster than the processor could in software. |
| Workaround | A change in software that avoids a fault in hardware. |
| Respin | Making a chip again from a corrected physical layout. |
| Mask | A word whose 1 bits choose which bits of another word take part. |
| Processor time | The share of its clock cycles that the processor spends on one job. |
One Picture: Two Ways
- Pads
- Processor
- Peripheral
- Memory
- Power
- The function
The answer must be the same whichever way it is built. Only the cost differs.
- As software
The processor runs a loop of four instructions for each bit. It needs no new silicon, and it takes 129 cycles.
- As hardware
A block adds the 32 bits side by side. It answers in one cycle, and it costs cells on every chip made.
- The rule changes: software
Someone edits one number in the program and loads it again. Chips already sold can take the change.
- The rule changes: hardware
The block is fixed in silicon. A change means a new physical layout, a new tape-out and new chips.
Read the diagram as text
- One function: count the bits of a word that are 1
- As software: a loop that the processor runs, one instruction at a time
- As hardware: a block of logic that answers in one cycle
- Edit the program: a change takes days, on chips already sold
- Make a new chip: a change takes months, and old chips stay as they are
- One function → As software: 129 cycles
- One function → As hardware: 1 cycle
- As software → Edit the program: the rule changes
- As hardware → Make a new chip: the rule changes
The cycle counts are the recorded counts of the lab on this page.
The Smallest Example, Worked by Hand: Count the Ones
The function is small: count the bits of a 32-bit word that are 1. First as software. The loop looks at one bit in each pass.
| Part | Instructions | How often | Clock cycles at one cycle each |
|---|---|---|---|
| Set up the loop | 1 | once | 1 |
| Take the lowest bit, add it, shift, branch back | 4 | 32 times | 128 |
| Total | 129 |
One clock cycle for each instruction is a simple model. Module S2 measures a real processor.
As hardware, 32 small adders work side by side, and the answer is ready in one cycle. With the 10 ns clock of S1.5, one call takes 10 ns in place of 1290 ns.
Is that worth a block? Amdahl's law of S1.5 says: ask for the share. It depends on how often the function runs.
| Calls in each second | Sum | Processor time used | Verdict |
|---|---|---|---|
| 10 | 10 x 1290 ns | 12,900 ns of each second | Nothing. Keep it in software. |
| 100,000 | 100,000 x 1290 ns | 0.129 second of each second | About 13 percent of the processor. A block is worth a look. |
Exercise rates.
The Rules
Rule 1: Any function can be built either way.
The answer is the same. The time, the area and the freedom to change it differ.
Rule 2: Hardware is paid for on every chip.
An accelerator costs cells and power on each die made, even in products that never use it.
Rule 3: Software is paid for in processor time.
It needs no new silicon. It is worth replacing only if it takes a large share of the time.
Rule 4: Software can change after tape-out, and hardware cannot.
A program can be loaded again, even on chips already sold. A block needs a respin.
Rule 5: Put in hardware what must be fast and is settled.
Keep in software what is rare, or may still change. When both matter, split the function.
Sources for These Rules
These five rules are common practice in architecture work. They are not taken from a library source.
The share argument is Amdahl's law: Patterson and Hennessy, Computer Organization and Design, ARM edition, section 1.10.
That nothing can be edited after tape-out is rule 5 of S1.4.
Now Run It: Then Change the Rule
The lab at the end of this page builds the function both ways and counts cycles. Then it changes the rule, as a customer might a year later. Rule A counts all 32 bits. Rule B counts the low 16 bits only.
word=00f00113
rule A, all 32 bits. software: ones=8 in 129 cycles
rule A, all 32 bits. hardware: ones=8 in 1 cycle
rule B, low 16 bits. software: ones=4 in 65 cycles (one number changed)
rule B, low 16 bits. hardware: ones=8 in 1 cycle (the chip still counts 32 bits)Rows 2 and 3 are rule 1 at work, and the hand count above: both ways find 8 ones. Software needs 129 cycles and hardware 1.
Row 4 is rule 4 at work. For rule B, someone changed one number in the program, from 32 to 16. The loop now finds 4 ones, and it even runs faster.
Row 5 is the other half of rule 4. The block still counts all 32 bits and still says 8. It is not broken. It does exactly what it was built to do, and that is no longer wanted.
The lab leaves things out. Its software is test code that charges one cycle for each instruction. A real call of the block also costs a bus access, as in S1.2.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| A function in software | A block for it | No silicon, and it can change after the chips are sold. It takes processor time on every call. |
| A function in hardware | A loop for it | A large speed-up of that function. Cells on every die, and no change after tape-out. |
| Hardware with a setting in a register | Hardware with the rule fixed | Software can adjust the block later. The register and its logic cost a few more cells. |
The third row is the common answer. Here it would be a mask register in front of the counter. Software writes which bits to count. Rule B then needs one register write, and no respin.
The Trap: Building the Rule into the Silicon
Return to the opening. The team measured a speed-up of more than a hundred on the function and built the block. Nobody asked how settled the rule was.
The cost of that question grows with the date. Before the RTL is written, a change is a line in a document. Before tape-out, it is new RTL and new tests. After tape-out, it is a respin: months, and a new set of chips.
Ask who can change the rule
A standard that is still being written, or a customer who has not decided, means the rule is not settled.
Keep the changing part in software
Let hardware do the heavy, fixed part. Let software choose what to feed it.
Leave a way out
A register bit that switches a block off lets software take the function back.
At Scale
This section looks ahead. The lab moved one small function. A phone chip makes this choice for hundreds of functions.
Accelerators for the heavy, settled work
Video, pictures and radio follow fixed standards and never rest. They get blocks. S10.6 follows a picture through several.
Software for everything else
Start-up, settings and rare events stay in firmware, where a fault can be repaired by an update.
Workarounds are planned for
Teams expect some hardware faults after tape-out. They add switch-off bits so that firmware can avoid a faulty block.
Try It
Run the lab. Check the count of ones in 00F0_0113 by hand.
Change the word so that its top 16 bits are 1 and the rest are 0. Predict all four rows before you run it.
Give the hardware a 32-bit mask input, and count only the bits where the mask is 1. Make rule B pass.
word=00f00113 rule A, all 32 bits. software: ones=8 in 129 cycles rule A, all 32 bits. hardware: ones=8 in 1 cycle rule B, low 16 bits. software: ones=4 in 65 cycles (one number changed) rule B, low 16 bits. hardware: ones=8 in 1 cycle (the chip still counts 32 bits)Check Yourself
Common Mistakes
Wrong Build a block because it is a hundred times faster.
The speed-up of a function matters only by its share of the time.
Fix Work out the share first, with Amdahl's law.
Wrong Fix a rule in hardware while it is still being argued.
After tape-out the block cannot follow a change.
Fix Keep the rule in software, or in a register that software sets.
Wrong Call the block broken when the rule changes.
It does what its specification said.
Fix Treat it as a requirement that moved, and plan the workaround.
Remember
- Any function can be built as hardware or as software.
- Hardware costs cells on every die; software costs processor time.
- Only a function with a large share of the time is worth an accelerator.
- Software can change after tape-out; hardware needs a respin.
- A register setting gives a hardware block part of the freedom of software.