Keep every answer of a parameterized rotate and bring it from 39 levels of logic under a budget of 6.
Hardware context: A rotate-left block for words of 8 to 32 bits with an amount that can pass the width; and an endian swap for a write channel with byte strobes. Bring the rotate from 39 levels under the budget of 6 without changing an answer.
A hash unit rotates a word left by a programmable amount in every round. The block is parameterized: the same file serves words of 8, 12, 24 and 32 bits. The shipped version rotates one place at a time. It is correct. At 24 bits its longest path is 39 levels of logic, and that path sets the clock of the whole unit.
This is an Optimize problem. The design below passes every test already. Make it pass the budget as well, without changing a single answer.
Mind the widths that are not powers of two. amt has $clog2(WIDTH) bits, so at WIDTH 24 it can be 24 to 31. The brief says the rotation is then amt mod WIDTH.
Brief: parameter WIDTH, 8 to 32. Ports d[WIDTH-1:0] and amt[$clog2(WIDTH)-1:0] in, y[WIDTH-1:0] out. The block is combinational. y is d rotated left by amt mod WIDTH places. No latch. At most 6 levels of logic on this flow at the default WIDTH of 24. Synthesis check: the design must build on the site's synthesis flow with no latch. The cell and level counts come from an open-source flow and are a proxy for area and depth, not a foundry result.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
word | 32 | input of each check |
amount | 5 | input of each check |
Full specification
module rotl #(parameter int WIDTH = 24) (
input logic [WIDTH-1:0] d,
input logic [$clog2(WIDTH)-1:0] amt, // rotate left by amt mod WIDTH places
output logic [WIDTH-1:0] y
);
// your design
endmodule
| Check | Rule |
|---|---|
| answers | y = d rotated left by (amt mod WIDTH), at WIDTH 8, 12, 24 and 32 |
| budget | levels of logic on the pinned flow at or under 6, measured at WIDTH = 24. The reference measures 5 and the shipped design 39. |
| latches | none |
| WIDTH | amt bits | amt range | Places rotated |
|---|---|---|---|
| 8 | 3 | 0 to 7 | amt |
| 12 | 4 | 0 to 15 | amt for 0 to 11; amt - 12 for 12 to 15 |
| 24 | 5 | 0 to 31 | amt for 0 to 23; amt - 24 for 24 to 31 |
| 32 | 5 | 0 to 31 | amt |
Four copies share one 32-bit word and one 5-bit amount. Each copy takes the low WIDTH bits of the word and the low bits of the amount. The result shows y8, y12, y24 and y32.
Examples
Example 1
Amount 0- Input
d = 0x89abcdef (each copy takes its low bits), amt = 0
- Output
y8 = 0xef, y12 = 0xdef, y24 = 0xabcdef, y32 = 0x89abcdef
Every copy returns its own low bits of the word unchanged.
Example 2
Amount 1- Input
d = 0x80808081 (each copy takes its low bits), amt = 1
- Output
y8 = 0x3, y12 = 0x102, y24 = 0x10103, y32 = 0x1010103
Each copy moves its bits up one place. The top bit of each copy comes back in at bit 0.
Example 3
Amount 12- Input
d = 0x00abc123 (each copy takes its low bits), amt = 12
- Output
y8 = 0x32, y12 = 0x123, y24 = 0x123abc, y32 = 0xbc12300a
At WIDTH 12 this is a full turn, so y12 equals its input. At WIDTH 8 the copy sees only the low three bits of amt, which are 4.
Constraints and Contract
- Inputs are known 0/1 values. Each case holds one word and one amount for a nanosecond and reads y at its end.
- Keep the module name, the parameter and the ports. The synthesis check uses the default WIDTH of 24.
Hints
Hint 1
Count the stages you need. Any amount is a sum of powers of two, one for each bit of amt.
Hint 2
A rotate by a constant is wiring. Make each stage a choice between its input and that input rotated by a constant.
Hint 3
Rotations add up modulo WIDTH by themselves. At WIDTH 24, a stage that rotates by 16 and one that rotates by 8 give a full turn. You do not need to compute amt mod WIDTH.
What the grader checks: Ten directed and fourteen seeded cases apply one word and one amount to four copies, at WIDTH 8, 12, 24 and 32. All four outputs are compared with an independent model. The cases include amounts at and above WIDTH for the widths that are not powers of two. The synthesis check measures levels at WIDTH 24 only.
The submitted design must synthesize with 0 latches and no combinational loop. It must use at most 6 logic levels; a result equal to the limit passes. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.
24 checks on Icarus Verilog + Yosys · 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 2 steps and the final capstone