[XMA] Cleanup in XmaDecoder::WriteRegister

- Replaced manual for loop with C++20 countr_zero standard call
This commit is contained in:
Gliniak
2025-12-23 23:28:13 +01:00
parent ac66db337b
commit 547226fc0b

View File

@@ -339,16 +339,15 @@ void XmaDecoder::WriteRegister(uint32_t addr, uint32_t value) {
// XMAEnableContext // XMAEnableContext
// The context ID is a bit in the range of the entire context array. // The context ID is a bit in the range of the entire context array.
uint32_t base_context_id = (r - XmaRegister::Context0Kick) * 32; const uint32_t base_context_id = (r - XmaRegister::Context0Kick) * 32;
for (int i = 0; value && i < 32; ++i, value >>= 1) { while (value) {
if (value & 1) { const uint32_t context_id = base_context_id + std::countr_zero(value);
uint32_t context_id = base_context_id + i; auto& context = *contexts_[context_id];
auto& context = *contexts_[context_id]; context.Enable();
context.Enable(); if (!cvars::use_dedicated_xma_thread) {
if (!cvars::use_dedicated_xma_thread) { context.Work();
context.Work();
}
} }
value &= value - 1;
} }
// Signal the decoder thread to start processing. // Signal the decoder thread to start processing.
work_event_->SetBoostPriority(); work_event_->SetBoostPriority();
@@ -356,27 +355,26 @@ void XmaDecoder::WriteRegister(uint32_t addr, uint32_t value) {
// Context lock command. // Context lock command.
// This requests a lock by flagging the context. // This requests a lock by flagging the context.
// XMADisableContext // XMADisableContext
uint32_t base_context_id = (r - XmaRegister::Context0Lock) * 32; const uint32_t base_context_id = (r - XmaRegister::Context0Lock) * 32;
for (int i = 0; value && i < 32; ++i, value >>= 1) { while (value) {
if (value & 1) { const uint32_t context_id = base_context_id + std::countr_zero(value);
uint32_t context_id = base_context_id + i; auto& context = *contexts_[context_id];
auto& context = *contexts_[context_id]; context.Disable();
context.Disable(); value &= value - 1;
}
} }
// Signal the decoder thread to start processing. // Signal the decoder thread to start processing.
// work_event_->Set(); // work_event_->Set();
} else if (r >= XmaRegister::Context0Clear && } else if (r >= XmaRegister::Context0Clear &&
r <= XmaRegister::Context9Clear) { r <= XmaRegister::Context9Clear) {
// Context clear command. // Context clear command.
// This will reset the given hardware contexts. // This will reset the given hardware contexts.
uint32_t base_context_id = (r - XmaRegister::Context0Clear) * 32; const uint32_t base_context_id = (r - XmaRegister::Context0Clear) * 32;
for (int i = 0; value && i < 32; ++i, value >>= 1) { while (value) {
if (value & 1) { const uint32_t context_id = base_context_id + std::countr_zero(value);
uint32_t context_id = base_context_id + i; auto& context = *contexts_[context_id];
XmaContext& context = *contexts_[context_id]; context.Clear();
context.Clear(); value &= value - 1;
}
} }
} else { } else {
// 0601h (1804h) is written to with 0x02000000 and 0x03000000 around a lock // 0601h (1804h) is written to with 0x02000000 and 0x03000000 around a lock