One function can be a loop in the program or a block on the chip. Count cycles, then weigh what a late change costs.
Hardware context: A job in two parts, one of them a slow unit that can be made faster. Architecture trade-off studies
A function counts the bits of a 32-bit word that are 1. The team can write it as a loop or build it as a block.
This worksheet uses named constants. The first three entries show how to record your decisions.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
| Way | Cost of one call | After the chip is made |
|---|---|---|
| Software (code 1) | one instruction to set up, then four for each bit; one clock cycle for each instruction | a change takes 2 days |
| Hardware (code 2) | one clock cycle to count, and three more to read the result over the bus | a change needs a new chip: 90 days |
The days are exercise numbers.
| Entry | Your decision |
|---|---|
| SW_CYCLES | How many clock cycles does one software call take? |
| HW_CYCLES | How many clock cycles does one hardware call take, with the read? |
| RATIO | How many times faster is the hardware call? Round down. |
| AT_BOOT | The function runs once when the chip starts, and its rule may still change. Enter 1 or 2. |
| EACH_SAMPLE | A result is needed within 10 clock cycles of each sample. Enter 1 or 2. |
| RULE_OPEN | The rule is still being argued when the chip goes to the factory. Speed is not a problem. Enter 1 or 2. |
| SW_FIT | How many whole software calls fit in 1000 clock cycles? |
| HW_FIT | How many whole hardware calls fit in 100 clock cycles? |
| TWENTY | Twenty calls are needed in every 1000 clock cycles. Enter 1 or 2. |
| DAYS_LOST | The rule changes after the chip is made. How many more days does the hardware choice cost? |
| MIXED | A mixed design masks the word in software with one instruction, then calls the block. Clock cycles for one call? |
| CHOICE_AT_CALLS | The function must run CALLS times in every 1000 clock cycles. Enter 1 if the software version fits, or 2 if hardware is needed. |
Examples
Example 1
SW CYCLES- Input
How many clock cycles does one software call take?
- Output
matches = 1
Four cycles for each of 32 bits, and one to set up.
Example 2
HW CYCLES- Input
How many clock cycles does one hardware call take, with the read?
- Output
matches = 1
One to count and three to read the result.
Example 3
RATIO- Input
How many times faster is the hardware call? Round down.
- Output
matches = 1
Divide 129 by 4 and drop the fraction.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For CHOICE_AT_CALLS, enter a constant expression using CALLS. Only this entry changes with the parameter. The supported integer range is 1 through 12, inclusive.
Hints
Hint 1
Work out one call of each way before comparing.
Hint 2
A way that misses the time limit is out.
Hint 3
If the rule may change after the chip is made, keep that part in software.
What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.
12 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 3 problems on this path