Predict how many loads and stores reach the bus for small register fragments. Compare them with and without volatile, as the RISC-V compiler builds them.
Hardware context: A host-native model of the UART0 transmit register and status word of ap_soc. Predicting the bus traffic a compiled register access really makes.
Recorded with riscv64-unknown-elf-gcc (14.2.0+19) 14.2.0 (-march=rv32i_zicsr -mabi=ilp32 -O2 -ffreestanding -nostdlib). IN_P and OUT_P are plain pointers to GPIO IN and OUT; IN_V and OUT_V are the same addresses through volatile pointers.
This worksheet uses named constants. The first three entries show how to record your decisions.
Replace each unresolved value of 255 with your result.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
| Name | C fragment |
|---|---|
| blink_plain | void blink_plain(void) { OUT_P = 1; OUT_P = 0; OUT_P = 1; } |
| blink_vol | void blink_vol(void) { OUT_V = 1; OUT_V = 0; OUT_V = 1; } |
| twice_plain | uint32_t twice_plain(void) { uint32_t a = IN_P; uint32_t b = IN_P; return a + b; } |
| twice_vol | uint32_t twice_vol(void) { uint32_t a = IN_V; uint32_t b = IN_V; return a + b; } |
| discard_plain | void discard_plain(void) { (void)IN_P; } |
| discard_vol | void discard_vol(void) { (void)IN_V; } |
| rmw_vol | void rmw_vol(void) { OUT_V |= 4u; } |
| rmw2_plain | void rmw2_plain(void) { OUT_P |= 4u; OUT_P |= 8u; } |
| rmw2_vol | void rmw2_vol(void) { OUT_V |= 4u; OUT_V |= 8u; } |
| wait_vol | void wait_vol(void) { while ((IN_V & 8u) == 0) { } } |
Count bus accesses the program makes when it runs, not lines of assembly. A load (lw) reads the bus once; a store (sw) writes it once.
| Entry | Your decision |
|---|---|
| BLINK_PLAIN_STORES | Stores made by blink_plain. |
| BLINK_VOL_STORES | Stores made by blink_vol. |
| TWICE_VOL_LOADS | Loads made by twice_vol. |
| TWICE_PLAIN_LOADS | Loads made by twice_plain. |
| DISCARD_PLAIN_LOADS | Loads made by discard_plain. |
| DISCARD_VOL_LOADS | Loads made by discard_vol. |
| RMW_VOL | Bus accesses made by rmw_vol. |
| RMW2_PLAIN | Bus accesses made by rmw2_plain. |
| RMW2_VOL | Bus accesses made by rmw2_vol. |
| WAIT_VOL_HIGH5 | Loads made by wait_vol when pin 3 first reads high on the fifth read. |
| LOOP_ACCESSES | Bus accesses made when this runs: for (unsigned i = 0; i < N; i++) OUT_V |= 1u << i; |
Examples
Example 1
BLINK PLAIN STORES- Input
Stores made by blink_plain.
- Output
matches = 1
The compiler keeps only the last store: OUT_P = 1.
Example 2
BLINK VOL STORES- Input
Stores made by blink_vol.
- Output
matches = 1
volatile forbids merging: 1, 0, 1 all reach the bus.
Example 3
TWICE VOL LOADS- Input
Loads made by twice_vol.
- Output
matches = 1
Two volatile reads, two loads.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For LOOP_ACCESSES, enter a constant expression using N. Only this entry changes with the parameter. The supported integer range is 1 through 8, inclusive.
Hints
Hint 1
It may merge, move or delete accesses it can prove are not needed in C.
Hint 2
Every volatile access in the source happens, in order.
Hint 3
A loop with one load in its body makes one load per pass.
What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.
15 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 2 problems on this path