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:
Nick Lewycky
2019-09-23 14:52:05 -07:00
parent 6937019b65
commit cd1d06f5a5
2 changed files with 19 additions and 23 deletions

View File

@ -5661,28 +5661,14 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
)[0]; )[0];
self.value_stack.push(ret); 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 retry = a.get_label();
let value = self.machine.acquire_temp_gpr().unwrap();
let compare = GPR::RAX;
a.emit_label(retry); a.emit_label(retry);
a.emit_mov(Size::S32, loc, Location::GPR(value));
Self::emit_memory_op(
module_info,
&self.config,
a,
&mut self.machine,
target,
memarg,
true,
4,
|a, _m, addr| {
a.emit_mov(Size::S32, Location::Memory(addr, 0), Location::GPR(compare))
},
);
a.emit_and(Size::S32, Location::GPR(compare), Location::GPR(value));
Self::emit_memory_op( Self::emit_memory_op(
module_info, module_info,
&self.config, &self.config,
@ -5693,18 +5679,21 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
true, true,
4, 4,
|a, _m, addr| { |a, _m, addr| {
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));
a.emit_lock_cmpxchg( a.emit_lock_cmpxchg(
Size::S32, Size::S32,
Location::GPR(value), Location::GPR(value),
Location::Memory(addr, 0), Location::Memory(addr, 0),
) );
}, },
); );
a.emit_jmp(Condition::NotEqual, retry); a.emit_jmp(Condition::NotEqual, retry);
a.emit_mov(Size::S32, Location::GPR(value), ret); a.emit_pop(Size::S64, Location::GPR(value));
self.machine.release_temp_gpr(value); self.machine.release_temp_gpr(compare);
} }
_ => { _ => {
return Err(CodegenError { return Err(CodegenError {

View File

@ -83,7 +83,14 @@ impl Machine {
/// Releases a temporary GPR. /// Releases a temporary GPR.
pub fn release_temp_gpr(&mut self, gpr: 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. /// Picks an unused XMM register.