Write a program generator whose programs stay alive and reach all eight hazard bins, for every seed, within 40 records. A program that dies, runs long or repeats itself for every seed does not count.
Hardware context: Random programs of the chip's lockstep gate on ap_soc v1.5, with real interrupt lines. A C generator whose program survives and fills every bin for every seed.
A random program is worth something only if it survives and reaches the corners you care about. This one must do both. Your generate() writes one program a seed. The bench loads it at 0x8000_0000 and runs it on the model of ap_rv32 from reset, alone.
For every seed, the program must reach its jump to itself with no trap, within 40 records. It must hit each of the eight bins below at least once. Programs for neighbouring seeds must differ: the seed has to change something.
The bins are those of lesson V5.4. They are properties of the retire records, so the bench counts them on the model. Your programs never run on the chip here. In lockstep the chip's records would be the same, so the bins would be too.
Problem V5.4.2 asks for one program, written by hand. Here no single program counts: every seed's program must survive, which is what guard rails are for.
Full specification
| Bit | Bin | Hit when |
|---|---|---|
| 0 | raw1 | An instruction reads a register (not x0) that the record just before it wrote |
| 1 | raw2 | It reads a register written two records before, and not by the record just before |
| 2 | load_use | It reads the register that a load just before it wrote |
| 3 | load_store | A store's data register (rs2) is the one a load just before it wrote |
| 4 | store_load | A load reads the word a store just before it wrote |
| 5 | branch_raw | A branch compares a register the record just before it wrote |
| 6 | csr_raw | A CSR instruction accesses the CSR the record just before it wrote |
| 7 | x0_write | An arithmetic instruction writes x0 (not the nop addi x0, x0, 0), and the next one reads x0 |
Pairs are consecutive records that did not trap; a trap ends the program anyway. Only ROM and SRAM exist for this bench: any other access answers with a bus error. The model starts with every register at 0.
The budget counts the records up to and including the jump to itself. Measured with this bench: the reference program takes 18 records for every seed. Padding the program with nops takes 48, over the budget. A nop after each load takes 20, inside it, but misses load_use and load_store.
Examples
Example 1
Seed 1: Alive, Inside the Budget, Every Bin- Input
generate(1, ...)
- Output
alive = 1, within_budget = 1, bins = 0xff
3FF: the program ended alive, inside the budget, and hit all eight bins.
Example 2
Seed 2: Alive, Inside the Budget, Every Bin- Input
generate(2, ...)
- Output
alive = 1, within_budget = 1, bins = 0xff
The same for another seed: other registers and values, the same eight pairs.
Example 3
Seed 3: Alive, Inside the Budget, Every Bin- Input
generate(3, ...)
- Output
alive = 1, within_budget = 1, bins = 0xff
A third seed: a generator with guard rails survives every draw.
Example 4
Seeds 1 and 2 Give Different Programs- Input
generate(1, ...) and generate(2, ...)
- Output
programs_differ = 1
1: the two programs differ, so the seed reaches the program.
Constraints and Contract
- One file, gen.c, with generate() of gen.h. Use the encoders of gen.h and rnd(); write at most max_words words (256).
- Each case runs one seed and returns alive << 9 | within the budget << 8 | the bins hit. 0x3FF is a pass.
- Hidden cases run other seeds.
Hints
Hint 1
Which registers must a random choice never take? Think of x0 and of any register that holds an address.
Hint 2
Each bin is a pair of neighbouring records. Write the pair on purpose, then randomise its registers and values.
Hint 3
Does anything in your program jump or load from an address the program did not set up?
What the grader checks: Each case runs your generator for one seed on the model of ap_rv32 v1.2, at most 400 records. It checks that the program ends with no trap, inside 40 records, and hits all eight bins. It checks that two seeds give different programs. It does not run the programs on the chip, where these bins cannot be counted yet. It does not rate how random they are either.
10 checks on Verilator + your C over DPI · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 3 problems on this path