Commit 48a8489d authored by Junliang Yan's avatar Junliang Yan Committed by V8 LUCI CQ

ppc: refactor atomic exchange

Change-Id: I01c4a68377a70cfed425b3cd1ed56b120c9b5056
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3174627Reviewed-by: 's avatarMilad Fa <mfarazma@redhat.com>
Commit-Queue: Junliang Yan <junyan@redhat.com>
Cr-Commit-Position: refs/heads/main@{#76992}
parent 8d3f02e4
......@@ -395,6 +395,17 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
sync();
}
template <class _type>
void AtomicExchange(MemOperand dst, Register new_value, Register output) {
Label exchange;
lwsync();
bind(&exchange);
LoadReserve<_type>(output, dst);
StoreConditional<_type>(new_value, dst);
bne(&exchange, cr0);
sync();
}
template <class _type, class bin_op>
void AtomicOps(MemOperand dst, Register value, Register output,
Register scratch, bin_op op) {
......
......@@ -1981,24 +1981,34 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kAtomicLoadInt16:
UNREACHABLE();
case kAtomicExchangeInt8:
ASSEMBLE_ATOMIC_EXCHANGE_INTEGER(lbarx, stbcx);
__ extsb(i.OutputRegister(0), i.OutputRegister(0));
__ AtomicExchange<int8_t>(
MemOperand(i.InputRegister(0), i.InputRegister(1)),
i.InputRegister(2), i.OutputRegister());
break;
case kPPC_AtomicExchangeUint8:
ASSEMBLE_ATOMIC_EXCHANGE_INTEGER(lbarx, stbcx);
__ AtomicExchange<uint8_t>(
MemOperand(i.InputRegister(0), i.InputRegister(1)),
i.InputRegister(2), i.OutputRegister());
break;
case kAtomicExchangeInt16:
ASSEMBLE_ATOMIC_EXCHANGE_INTEGER(lharx, sthcx);
__ extsh(i.OutputRegister(0), i.OutputRegister(0));
__ AtomicExchange<int16_t>(
MemOperand(i.InputRegister(0), i.InputRegister(1)),
i.InputRegister(2), i.OutputRegister());
break;
case kPPC_AtomicExchangeUint16:
ASSEMBLE_ATOMIC_EXCHANGE_INTEGER(lharx, sthcx);
__ AtomicExchange<uint16_t>(
MemOperand(i.InputRegister(0), i.InputRegister(1)),
i.InputRegister(2), i.OutputRegister());
break;
case kPPC_AtomicExchangeWord32:
ASSEMBLE_ATOMIC_EXCHANGE_INTEGER(lwarx, stwcx);
__ AtomicExchange<uint32_t>(
MemOperand(i.InputRegister(0), i.InputRegister(1)),
i.InputRegister(2), i.OutputRegister());
break;
case kPPC_AtomicExchangeWord64:
ASSEMBLE_ATOMIC_EXCHANGE_INTEGER(ldarx, stdcx);
__ AtomicExchange<uint64_t>(
MemOperand(i.InputRegister(0), i.InputRegister(1)),
i.InputRegister(2), i.OutputRegister());
break;
case kAtomicCompareExchangeInt8:
__ AtomicCompareExchange<int8_t>(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment