Merge pull request #1280 from TheAggie/perf/recompiler-bda-note-load

perf(recompiler): load the written-page slot before the CAS
This commit is contained in:
Adrià
2026-10-10 01:18:05 +02:00
committed by GitHub
@@ -153,10 +153,16 @@ static std::uint32_t DefineBdaNoteWrite(SpirvEmitterState& state) {
state.module.AddFunction(spv::OpBranchConditional, searching, body, merge);
EmitLabel(state, body);
const auto slot = binary(spv::OpIAdd, u32, constant(BdaAbi::WrittenSlotsWord), binary(spv::OpBitwiseAnd, u32, binary(spv::OpIAdd, u32, hash, probe), constant(BdaAbi::WrittenPageSlots - 1u)));
const auto previous = state.module.AllocateId();
state.module.AddFunction(spv::OpAtomicCompareExchange, u32, previous, BdaWord(state, state.faultBufferVariable, slot), scope, relaxed, relaxed, page, constant(0u));
const auto taken = binary(spv::OpLogicalOr, boolean, binary(spv::OpIEqual, boolean, previous, constant(0u)), binary(spv::OpIEqual, boolean, previous, page));
state.module.AddFunction(spv::OpStore, done, taken);
const auto current = state.module.AllocateId();
state.module.AddFunction(spv::OpAtomicLoad, u32, current, BdaWord(state, state.faultBufferVariable, slot), scope, relaxed);
const auto held = binary(spv::OpIEqual, boolean, current, page);
state.module.AddFunction(spv::OpStore, done, held);
EmitIfCondition(state, Unary(state, spv::OpLogicalNot, boolean, held), [&] {
const auto previous = state.module.AllocateId();
state.module.AddFunction(spv::OpAtomicCompareExchange, u32, previous, BdaWord(state, state.faultBufferVariable, slot), scope, relaxed, relaxed, page, constant(0u));
const auto taken = binary(spv::OpLogicalOr, boolean, binary(spv::OpIEqual, boolean, previous, constant(0u)), binary(spv::OpIEqual, boolean, previous, page));
state.module.AddFunction(spv::OpStore, done, taken);
});
state.module.AddFunction(spv::OpBranch, continuation);
EmitLabel(state, continuation);
state.module.AddFunction(spv::OpStore, counter, binary(spv::OpIAdd, u32, probe, constant(1u)));