Skip to content

Commit

Permalink
Jit: Threads: Add RmwCmpxchg
Browse files Browse the repository at this point in the history
Signed-off-by: Máté Tokodi [email protected]
  • Loading branch information
matetokodi committed Aug 26, 2024
1 parent 78d0d9a commit 812262f
Show file tree
Hide file tree
Showing 2 changed files with 277 additions and 26 deletions.
45 changes: 42 additions & 3 deletions src/jit/ByteCodeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ static bool isFloatGlobal(uint32_t globalIndex, Module* module)
#endif /* SLJIT_32BIT_ARCHITECTURE */

#if defined(ENABLE_EXTENDED_FEATURES)
#define OPERAND_TYPE_LIST_EXTENDED \
OL5(OTAtomicRmwI32, /* SSDTT */ I32, I32, I32 | TMP, PTR, I32 | S1) \
OL5(OTAtomicRmwI64, /* SSDTT */ I32, I64, I64 | TMP, PTR, I64 | S1)
#define OPERAND_TYPE_LIST_EXTENDED \
OL5(OTAtomicRmwI32, /* SSDTT */ I32, I32, I32 | TMP, PTR, I32 | S1) \
OL5(OTAtomicRmwI64, /* SSDTT */ I32, I64, I64 | TMP, PTR, I64 | S1) \
OL6(OTAtomicRmwCmpxchgI32, /* SSSDTT */ I32, I32, I32, I32 | TMP, PTR, I32 | S1) \
OL6(OTAtomicRmwCmpxchgI64, /* SSSDTT */ I32, I64, I64, I64 | TMP, PTR, I64 | S1)
#else /* !ENABLE_EXTENDED_FEATURES */
#define OPERAND_TYPE_LIST_EXTENDED
#endif /* ENABLE_EXTENDED_FEATURES */
Expand Down Expand Up @@ -327,6 +329,8 @@ static bool isFloatGlobal(uint32_t globalIndex, Module* module)
o1, o2, o3, o4, 0,
#define OL5(name, o1, o2, o3, o4, o5) \
o1, o2, o3, o4, o5, 0,
#define OL6(name, o1, o2, o3, o4, o5, o6) \
o1, o2, o3, o4, o5, o6, 0,

const uint8_t Instruction::m_operandDescriptors[] = {
0,
Expand All @@ -340,6 +344,7 @@ const uint8_t Instruction::m_operandDescriptors[] = {
#undef OL3
#undef OL4
#undef OL5
#undef OL6

// Besides the list names, these macros define enum
// types with ByteN suffix. These are unused.
Expand All @@ -354,6 +359,8 @@ const uint8_t Instruction::m_operandDescriptors[] = {
name, name##Byte1, name##Byte2, name##Byte3, name##Byte4,
#define OL5(name, o1, o2, o3, o4, o5) \
name, name##Byte1, name##Byte2, name##Byte3, name##Byte4, name##Byte5,
#define OL6(name, o1, o2, o3, o4, o5, o6) \
name, name##Byte1, name##Byte2, name##Byte3, name##Byte4, name##Byte5, name##Byte6,

enum OperandTypes : uint32_t {
OTNone,
Expand All @@ -369,6 +376,7 @@ enum OperandTypes : uint32_t {
#undef OL3
#undef OL4
#undef OL5
#undef OL6

enum ParamTypes {
NoParam,
Expand Down Expand Up @@ -1973,6 +1981,37 @@ static void compileFunction(JITCompiler* compiler)
operands[2] = STACK_OFFSET(atomicRmw->dstOffset());
break;
}
case ByteCode::I32AtomicRmwCmpxchgOpcode:
case ByteCode::I32AtomicRmw8CmpxchgUOpcode:
case ByteCode::I32AtomicRmw16CmpxchgUOpcode: {
info = Instruction::kIs32Bit;
requiredInit = OTAtomicRmwCmpxchgI32;
FALLTHROUGH;
}
case ByteCode::I64AtomicRmwCmpxchgOpcode: {
#if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
if (info == 0) {
info = Instruction::kIsCallback;
}
#endif /* SLJIT_32BIT_ARCHITECTURE */
FALLTHROUGH;
}
case ByteCode::I64AtomicRmw8CmpxchgUOpcode:
case ByteCode::I64AtomicRmw16CmpxchgUOpcode:
case ByteCode::I64AtomicRmw32CmpxchgUOpcode: {
Instruction* instr = compiler->append(byteCode, Instruction::Atomic, opcode, 3, 1);
instr->addInfo(info);

AtomicRmwCmpxchg* atomicRmwCmpxchg = reinterpret_cast<AtomicRmwCmpxchg*>(byteCode);
Operand* operands = instr->operands();
instr->setRequiredRegsDescriptor(requiredInit != OTNone ? requiredInit : OTAtomicRmwCmpxchgI64);

operands[0] = STACK_OFFSET(atomicRmwCmpxchg->src0Offset());
operands[1] = STACK_OFFSET(atomicRmwCmpxchg->src1Offset());
operands[2] = STACK_OFFSET(atomicRmwCmpxchg->src2Offset());
operands[3] = STACK_OFFSET(atomicRmwCmpxchg->dstOffset());
break;
}
#endif /* ENABLE_EXTENDED_FEATURES */
default: {
ASSERT_NOT_REACHED();
Expand Down
Loading

0 comments on commit 812262f

Please sign in to comment.