Rollup merge of #52391 - Amanieu:volatile_unaligned, r=alexcrichton
Add unaligned volatile intrinsics Surprisingly enough, it turns out that unaligned volatile loads are actually useful for certain (very niche) types of lock-free code. I included unaligned volatile stores for completeness, but I currently do not know of any use cases for them. These are only exposed as intrinsics for now. If they turn out to be useful in practice, we can work towards stabilizing them. r? @alexcrichton
This commit is contained in:
commit
06ba69d043
6 changed files with 44 additions and 8 deletions
|
@ -54,6 +54,7 @@ bitflags! {
|
|||
pub struct MemFlags: u8 {
|
||||
const VOLATILE = 1 << 0;
|
||||
const NONTEMPORAL = 1 << 1;
|
||||
const UNALIGNED = 1 << 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -602,7 +603,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let ptr = self.check_store(val, ptr);
|
||||
unsafe {
|
||||
let store = llvm::LLVMBuildStore(self.llbuilder, val, ptr);
|
||||
llvm::LLVMSetAlignment(store, align.abi() as c_uint);
|
||||
let align = if flags.contains(MemFlags::UNALIGNED) {
|
||||
1
|
||||
} else {
|
||||
align.abi() as c_uint
|
||||
};
|
||||
llvm::LLVMSetAlignment(store, align);
|
||||
if flags.contains(MemFlags::VOLATILE) {
|
||||
llvm::LLVMSetVolatile(store, llvm::True);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue