R32V2020 Big vs Little Endian
Jump to navigation
Jump to search
Historical Context
- There's a long history of endian battles.
Endianness is of interest in computer science because two conflicting and incompatible formats are in common use: words may be represented in big-endian or little-endian format, depending on whether bits or bytes or other components are ordered from the big end (most significant bit) or the little end (least significant bit). - Endianness
- Both big and little endian have advantages and disadvantages.
- Readability.
- Reading memory and swapping around the bytes when displaying them is unnatural.
- Connection to peripherals seems unnatural with bytes on d24-d31, shorts on d16-d31.
- Some are big and some are little endian.
- Readability.
- Software solutions are really big and painful.
- Shifts (by 8), masks, ORs, etc.
- Doing this eliminates much of the need for slow shifting
Solution
- endswap - opcode that swaps the endian of a long
- d0-d7 get moved to d24-d32, d8-d15 get moved to d16-d23, d16-d23 get moved to d8-d15, and d24-d31 get moved to d0-d7
- Relatively easy to implement in the FPGA ALU
Example
- "Natural" data bus connections
- Byte data length peripherals always connect to d0-d7
- Short data length peripherals always connect to d0-d15
- Long data length peripherals connect to d0-d32
- Data memory should be stored in natural sense as well
- 32-bit memory packed with byte data
- [d32..d24|d23..d16|d15..d8|d7..d0]
- Reads in memory dump with most significant byte first
- If you want to send that 32-bit data to an 8-bit peripheral you end up doing shifts/masks with multiple registers
- Much easier to do endswap which flips the order into a register and put out the register one at a time
- Still a use for shl8 and shr8 which shift the 32-bit register by 8 bits
- Less of a need for arbitrary shifts
- Could get by with 8-bit shifts and 1-bit shifts
- 32-bit memory packed with byte data