ISA & Assembly
The standard RISC-V calling convention requires sp to be a multiple of 16 bytes on function entry. What is the main reason?
- ABecause the OS will not boot unless the stack size is a multiple of 16 bytes
- BBecause the low 4 bits of sp record the function number
- CSo that data up to 16 bytes placed on the stack can be accessed efficiently without crossing alignment boundaries
Show answer and explanation
Answer: C. So that data up to 16 bytes placed on the stack can be accessed efficiently without crossing alignment boundaries
Data placed at an address that is a multiple of its size (aligned) can be accessed in one operation without crossing a boundary. Keeping sp a multiple of 16 preserves alignment for 8-byte doubles or 16-byte long doubles placed on the stack. So functions allocate frames in multiples of 16 bytes, using "addi sp, sp, -16" even if they save only one register.
- A. It has nothing to do with booting the OS.
- B. No information is stored in the low bits of sp.
- C. Correct. It keeps double-precision and 128-bit data aligned.