if a target didn't support i8
or i16
is that ok to use i32
instructions .
I mean if you use sc.w
to implement i8
store operation, you may overwrite some data.
https://msyksphinz-self.github.io/riscv-isadoc/html/rva.html#sc-w
If you do lr.w and then sc.w on the same address, with the bytes that need to stay the same unchanged, then there will be no overwite with a different value than the correct one as the sc.w would fail if another thread overwrites the other bytes.
At least that is how I understand it. You can always look at what LLVM does.
@bjorn3 my main concern is if only alloc 2 bytes for i16 , I do sc.w
may overwirte arbitrary data.
This is how LLVM codegens it: https://rust.godbolt.org/z/hb8s9EWYT
As long as you preserve the top two bytes and then re-write them, it should work out. Here's what llvm does: https://godbolt.org/z/eW8Gv115o
I think LLVM also does some trickery to exactly align the load and store to a 32bit boundary as necessary for performance (unaligned atomics may need to be emulated by machine mode) and correctness (oversized memory accesses may cause erroneous page faults if the memory are at the end of a page) reasons.
This is the actual code in LLVM that does the atomic rmw handling: https://github.com/llvm/llvm-project/blob/ce381281940fb6a9cc2fa1a16fa36bf0911f43f1/llvm/lib/Target/RISCV/RISCVExpandAtomicPseudoInsts.cpp#L341
@bjorn3 thanks.
yang yu has marked this topic as resolved.
Last updated: Nov 22 2024 at 16:03 UTC