mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-19 20:01:20 +00:00
Initial working implementation of I32AtomicRmwAnd!
Adds the ability to reserve a specific temp-gpr register. Needed for CMPXCHG which always uses RAX.
This commit is contained in:
@ -5661,14 +5661,14 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
|
||||
)[0];
|
||||
self.value_stack.push(ret);
|
||||
|
||||
let compare = self.machine.reserve_temp_gpr(GPR::RAX);
|
||||
let value = if loc == Location::GPR(GPR::R14) { GPR::R13 } else { GPR::R14 };
|
||||
a.emit_push(Size::S64, Location::GPR(value));
|
||||
a.emit_mov(Size::S32, loc, Location::GPR(value));
|
||||
|
||||
let retry = a.get_label();
|
||||
|
||||
let value = self.machine.acquire_temp_gpr().unwrap();
|
||||
let compare = GPR::RAX;
|
||||
|
||||
a.emit_label(retry);
|
||||
|
||||
a.emit_mov(Size::S32, loc, Location::GPR(value));
|
||||
Self::emit_memory_op(
|
||||
module_info,
|
||||
&self.config,
|
||||
@ -5679,32 +5679,21 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
|
||||
true,
|
||||
4,
|
||||
|a, _m, addr| {
|
||||
a.emit_mov(Size::S32, Location::Memory(addr, 0), Location::GPR(compare))
|
||||
},
|
||||
);
|
||||
a.emit_mov(Size::S32, Location::Memory(addr, 0), Location::GPR(compare));
|
||||
a.emit_mov(Size::S32, Location::GPR(compare), ret);
|
||||
a.emit_and(Size::S32, Location::GPR(compare), Location::GPR(value));
|
||||
Self::emit_memory_op(
|
||||
module_info,
|
||||
&self.config,
|
||||
a,
|
||||
&mut self.machine,
|
||||
target,
|
||||
memarg,
|
||||
true,
|
||||
4,
|
||||
|a, _m, addr| {
|
||||
a.emit_lock_cmpxchg(
|
||||
Size::S32,
|
||||
Location::GPR(value),
|
||||
Location::Memory(addr, 0),
|
||||
)
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
a.emit_jmp(Condition::NotEqual, retry);
|
||||
|
||||
a.emit_mov(Size::S32, Location::GPR(value), ret);
|
||||
self.machine.release_temp_gpr(value);
|
||||
a.emit_pop(Size::S64, Location::GPR(value));
|
||||
self.machine.release_temp_gpr(compare);
|
||||
}
|
||||
_ => {
|
||||
return Err(CodegenError {
|
||||
|
@ -83,7 +83,14 @@ impl Machine {
|
||||
|
||||
/// Releases a temporary GPR.
|
||||
pub fn release_temp_gpr(&mut self, gpr: GPR) {
|
||||
assert_eq!(self.used_gprs.remove(&gpr), true);
|
||||
assert!(self.used_gprs.remove(&gpr));
|
||||
}
|
||||
|
||||
/// Specify that a given register is in use.
|
||||
pub fn reserve_temp_gpr(&mut self, gpr: GPR) -> GPR {
|
||||
assert!(!self.used_gprs.contains(&gpr));
|
||||
self.used_gprs.insert(gpr);
|
||||
gpr
|
||||
}
|
||||
|
||||
/// Picks an unused XMM register.
|
||||
|
Reference in New Issue
Block a user