Put a big-endian or little-endian store on a byte-invariant 64-bit bus, and take a load back off it, byte by byte.
Hardware context: A register block receiving byte writes. Implement the store and load lane mapping of a big-endian or little-endian manager on a byte-invariant bus.
Lesson P2.9 showed that AXI never swaps bytes: lane n always carries the byte at word + n. A big-endian processor still has to get its values onto those lanes. Its bus interface does the swap, and it is easy to swap the wrong thing.
Write two functions for a manager on a 64-bit bus. store_lanes turns one store into WDATA and WSTRB. load_value takes the RDATA of one beat and returns the value a load sees.
A big-endian manager puts the most significant byte of a value at the lowest address. A little-endian one puts the least significant byte there. Either way, each byte travels in the lane of its own address.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
op | 2 | input of each check |
addr | 32 | input of each check |
Full specification
// le = 1: a little-endian manager; le = 0: a big-endian one (BE8 order: the most significant byte
// of the value goes to the lowest address). size: 0 = 1 byte, 1 = 2 bytes, 2 = 4 bytes, 3 = 8 bytes.
// The value is right-aligned in its 64 bits. The bus is 64 bits wide with byte-invariant lanes.
function automatic logic [79:0] store_lanes(input logic le, input logic [31:0] addr, input logic [1:0] size, input logic [63:0] value);
// return {8'b0, wstrb[7:0], wdata[63:0]}
endfunction
function automatic logic [79:0] load_value(input logic le, input logic [31:0] addr, input logic [1:0] size, input logic [63:0] rdata);
// return {16'b0, value[63:0]}, the value right-aligned
endfunction
| Store of n = 2^size bytes at addr | What goes on the bus |
|---|---|
| Lanes | Memory byte addr + i travels in lane (addr + i) mod 8, for i = 0 to n - 1. WSTRB has exactly those lanes set. |
| Little-endian | Memory byte addr + i is value byte i (value[8i+7:8i]). |
| Big-endian | Memory byte addr + i is value byte n - 1 - i. |
| Other lanes | WDATA is 0 on every lane whose strobe is 0. |
load_value is the inverse: it rebuilds the value from the lanes of its bytes in RDATA, in the manager's byte order. Every address is aligned to its size, so one beat holds the whole access.
Examples
Example 1
A Big-Endian Word in the Upper Half- Input
big-endian word store of 0x11223344 at 0x1004
- Output
wstrb = 'b11110000, data = 0x4433221100000000
The word at 0x1004 uses lanes 4 to 7. The big-endian manager puts 11 at 0x1004, so lane 4 carries 11 and lane 7 carries 44. WDATA is 44332211_00000000 and WSTRB is 11110000.
Example 2
A Big-Endian Halfword in Lanes 6 and 7- Input
big-endian halfword store of 0xa1b2 at 0x1006
- Output
wstrb = 'b11000000, data = 0xb2a1000000000000
a1 goes to 0x1006 in lane 6 and b2 to 0x1007 in lane 7. WDATA is b2a10000_00000000: the bus word is printed with lane 7 on the left.
Example 3
The Same Halfword, Little-Endian- Input
little-endian halfword store of 0xa1b2 at 0x1006
- Output
wstrb = 'b11000000, data = 0xa1b2000000000000
Now b2, the low byte, goes to 0x1006. The lanes and the strobe are the same as before; only the byte order inside the halfword changed.
Constraints and Contract
- Keep the function names, arguments and return widths. Fill the unused top bits with 0.
- Both functions are pure: no state, no clock.
Hints
Hint 1
Loop over the n bytes of memory, not over the lanes of the bus.
Hint 2
For memory byte i, the lane depends only on the address. The value byte depends only on the endianness.
Hint 3
A single-byte access is the same in both endiannesses. Check that your code agrees.
What the grader checks: Your functions run on eleven directed stores and loads and six seeded ones, in both endiannesses and all four sizes. An independent model checks every result. Passing shows the lane and byte-order rules hold for aligned single-beat accesses.
17 checks on Icarus · browser samples / server checks. 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