Modernize `std::fill` with ranges

In DSPCore.cpp, there were two `std::fill` uses that could be simplified using `std::fill_n`. Due to their proximity with other `std::fill` algorithms being modernized with ranges, I chose to make these examples into the rare `std::ranges::fill_n`.
This commit is contained in:
mitaclaw 2024-08-22 19:16:36 -07:00
parent a7160c7b38
commit 9bd1dae41d
8 changed files with 20 additions and 20 deletions

View File

@ -143,20 +143,20 @@ bool SDSP::Initialize(const DSPInitOptions& opts)
std::memset(&r, 0, sizeof(r));
std::fill(std::begin(reg_stack_ptrs), std::end(reg_stack_ptrs), 0);
std::ranges::fill(reg_stack_ptrs, 0);
for (auto& stack : reg_stacks)
std::fill(std::begin(stack), std::end(stack), 0);
std::ranges::fill(stack, 0);
// Fill IRAM with HALT opcodes.
std::fill(iram, iram + DSP_IRAM_SIZE, 0x0021);
std::ranges::fill_n(iram, DSP_IRAM_SIZE, 0x0021);
// Just zero out DRAM.
std::fill(dram, dram + DSP_DRAM_SIZE, 0);
std::ranges::fill_n(dram, DSP_DRAM_SIZE, 0);
// Copied from a real console after the custom UCode has been loaded.
// These are the indexing wrapping registers.
std::fill(std::begin(r.wr), std::end(r.wr), 0xffff);
std::ranges::fill(r.wr, 0xffff);
r.sr |= SR_INT_ENABLE;
r.sr |= SR_EXT_INT_ENABLE;
@ -172,7 +172,7 @@ bool SDSP::Initialize(const DSPInitOptions& opts)
void SDSP::Reset()
{
pc = DSP_RESET_VECTOR;
std::fill(std::begin(r.wr), std::end(r.wr), 0xffff);
std::ranges::fill(r.wr, 0xffff);
}
void SDSP::Shutdown()

View File

@ -40,7 +40,7 @@ DSPEmitter::DSPEmitter(DSPCore& dsp)
m_stub_entry_point = CompileStub();
// Clear all of the block references
std::fill(m_blocks.begin(), m_blocks.end(), (DSPCompiledCode)m_stub_entry_point);
std::ranges::fill(m_blocks, (DSPCompiledCode)m_stub_entry_point);
}
DSPEmitter::~DSPEmitter()

View File

@ -240,8 +240,8 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
m_Ram.resize(memory.GetRamSize());
m_ExRam.resize(memory.GetExRamSize());
std::fill(m_Ram.begin(), m_Ram.end(), 0);
std::fill(m_ExRam.begin(), m_ExRam.end(), 0);
std::ranges::fill(m_Ram, 0);
std::ranges::fill(m_ExRam, 0);
m_File->SetIsWii(m_system.IsWii());

View File

@ -452,7 +452,7 @@ bool Wiimote::ProcessReadDataRequest()
reply.address = Common::swap16(m_read_request.address);
// Pre-fill with zeros in case of read-error or read < 16-bytes:
std::fill(std::begin(reply.data), std::end(reply.data), 0x00);
std::ranges::fill(reply.data, 0x00);
ErrorCode error_code = ErrorCode::Success;

View File

@ -100,9 +100,9 @@ void Cache::Reset()
valid.fill(0);
plru.fill(0);
modified.fill(0);
std::fill(lookup_table.begin(), lookup_table.end(), 0xFF);
std::fill(lookup_table_ex.begin(), lookup_table_ex.end(), 0xFF);
std::fill(lookup_table_vmem.begin(), lookup_table_vmem.end(), 0xFF);
std::ranges::fill(lookup_table, 0xFF);
std::ranges::fill(lookup_table_ex, 0xFF);
std::ranges::fill(lookup_table_vmem, 0xFF);
}
void InstructionCache::Reset(JitInterface& jit_interface)

View File

@ -128,10 +128,10 @@ void PowerPCManager::DoState(PointerWrap& p)
void PowerPCManager::ResetRegisters()
{
std::fill(std::begin(m_ppc_state.ps), std::end(m_ppc_state.ps), PairedSingle{});
std::fill(std::begin(m_ppc_state.sr), std::end(m_ppc_state.sr), 0U);
std::fill(std::begin(m_ppc_state.gpr), std::end(m_ppc_state.gpr), 0U);
std::fill(std::begin(m_ppc_state.spr), std::end(m_ppc_state.spr), 0U);
std::ranges::fill(m_ppc_state.ps, PairedSingle{});
std::ranges::fill(m_ppc_state.sr, 0U);
std::ranges::fill(m_ppc_state.gpr, 0U);
std::ranges::fill(m_ppc_state.spr, 0U);
// Gamecube:
// 0x00080200 = lonestar 2.0

View File

@ -183,7 +183,7 @@ Joystick::Joystick(const LPDIRECTINPUTDEVICE8 device) : m_device(device)
// Set hats to center:
// "The center position is normally reported as -1" -MSDN
std::fill(std::begin(m_state_in.rgdwPOV), std::end(m_state_in.rgdwPOV), -1);
std::ranges::fill(m_state_in.rgdwPOV, -1);
}
Joystick::~Joystick()

View File

@ -764,9 +764,9 @@ bool FramebufferManager::CreateReadbackFramebuffer()
}
m_efb_color_cache.tiles.resize(total_tiles);
std::fill(m_efb_color_cache.tiles.begin(), m_efb_color_cache.tiles.end(), EFBCacheTile{false, 0});
std::ranges::fill(m_efb_color_cache.tiles, EFBCacheTile{false, 0});
m_efb_depth_cache.tiles.resize(total_tiles);
std::fill(m_efb_depth_cache.tiles.begin(), m_efb_depth_cache.tiles.end(), EFBCacheTile{false, 0});
std::ranges::fill(m_efb_depth_cache.tiles, EFBCacheTile{false, 0});
return true;
}