2.6 Load and Store Instructions
The base ISA supports misaligned accesses,
2.2 Base Instruction Formats
Except for the 5-bit immediates used in CSR instructions (Section 2.8), immediates are always sign-extended,
#1 The ISA does not not allow misaligned memory accesses. However it seems unlikely GCC would generate code that relies on misaligned accesses. As that would break those implementations that do not support misaligned accesses.
#2 Only write the relevant bits. So an SB only writes 8bits of data.
Richard
--
You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+un...@groups.riscv.org.
To post to this group, send email to sw-...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/sw-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/0ff9d3b0-f880-4cf7-b6c8-b0a1c65823eb%40groups.riscv.org.
The SW, SH, and SB instructions store 32-bit, 16-bit, and 8-bit values from the low bits of register rs2 to memory.
The ISA does not not allow misaligned memory accesses.
However it seems unlikely GCC would generate code that relies on misaligned accesses. As that would break those implementations that do not support misaligned accesses.
hi all,I am developing the RISC-V 32 bit processor implementation. For my undergraduate bachelors FYP.1) Should I make the architecture to support misaligned Data memory access is there any possibility that RISC-V tool chain compiler generating code that requires misaligned access?
2) For SB , SH instructions should we take the 8 bit or 16 bit data and 0 extend to 32 bit and write as 32bit value to the memory or write to only the specified 8bits or 16bits?
On 23 Aug 2017, at 13:17, Bruce Hoult <br...@hoult.org> wrote:
>
> gcc will never create code that generates a misaligned access unless the user explicitly casts integers to pointers.
Unless GCC’s behaviour is *very* different from LLVM’s here, I do not believe that this is true.
There are basically two possibilities for a compiler:
- Assume all accesses are correctly aligned[1] and emit instructions assuming that the processor can handle the case where they’re not.
what does handling the misaligned instruction with software trap means?Does it means that an interrupt occurs when a misaligned read/write found and ISR will have the code to do it in an aligned manner?
--
You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+unsubscribe@groups.riscv.org.
To post to this group, send email to sw-...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/sw-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/2aa7780c-d7d6-44f6-b06a-5715bcc49d3a%40groups.riscv.org.
On 23 Aug 2017, at 13:17, Bruce Hoult <br...@hoult.org> wrote:
>
> gcc will never create code that generates a misaligned access unless the user explicitly casts integers to pointers.
Unless GCC’s behaviour is *very* different from LLVM’s here, I do not believe that this is true.
There are basically two possibilities for a compiler:
- Assume all accesses are correctly aligned[1] and emit instructions assuming that the processor can handle the case where they’re not.
- Assume all accesses are misaligned unless they can be proven to be aligned and emit a sequence of smaller loads / stores to guarantee correct alignment[2].
For most input code, the former assumption will generate noticeable faster binaries, even if you have to trap-and-emulate for all unaligned accesses, because the penalty for unaligned loads (even if you have a MIPS-style lwl / lwr, which RISC-V lacks) is very high, even just in terms of increased i-cache usage.
For CHERI, we made the processor handle all unaligned loads and stores within a cache line and only trap for ones that span a cache line boundary. The traps are very rare and we get a big win in both performance and binary size compared to our earlier approach of not generating unaligned accesses in the compiler.
David
[1] Technically, if they are not and the source language is C, then it’s undefined behaviour.
[2] Assuming 100% correct source code with no undefined behaviour - even with this strategy, things such as casting an unaligned buffer to void* then casting it to int* and loading it may generate misaligned accesses.
--
You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+un...@groups.riscv.org.
To post to this group, send email to sw-...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/sw-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/7B9C1811-5769-4D88-9A90-BB780B0E41A6%40cl.cam.ac.uk.