Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
stdc++: migrate nall::hashset uses to std::unordered_map
  • Loading branch information
rasky committed Oct 2, 2025
commit 1f49d0689d6db819ea573e35c19d096d99abeefc
22 changes: 9 additions & 13 deletions ares/ares/node/debugger/tracer/instruction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Instruction : Tracer {

auto setMask(bool mask) -> void {
_mask = mask;
_masks.reset();
_masks.clear();
}

auto setDepth(u32 depth) -> void {
Expand All @@ -34,9 +34,9 @@ struct Instruction : Tracer {
address >>= _addressMask; //clip unneeded alignment bits (to reduce _masks size)

if(_mask) {
auto mask = _masks.find(address);
if(!mask) mask = _masks.insert(address);
if(mask->visit(address)) return false; //do not trace twice
auto key = address >> 6;
auto [it, inserted] = _masks.try_emplace(key);
if(it->second.visit(address)) return false;
}

if(_depth) {
Expand All @@ -62,8 +62,9 @@ struct Instruction : Tracer {
address &= ~0ull >> (64 - _addressBits);
address >>= _addressMask;

auto mask = _masks.find(address);
if(mask) mask->unvisit(address);
auto key = address >> 6;
auto it = _masks.find(key);
if(it != _masks.end()) it->second.unvisit(address);
}
}

Expand Down Expand Up @@ -107,10 +108,6 @@ struct Instruction : Tracer {

protected:
struct VisitMask {
VisitMask(u64 address) : upper(address >> 6), mask(0) {}
auto operator==(const VisitMask& source) const -> bool { return upper == source.upper; }
auto hash() const -> u32 { return upper; }

auto visit(u64 address) -> bool {
const u64 bit = 1ull << (address & 0x3f);
if(mask & bit) return true;
Expand All @@ -124,8 +121,7 @@ struct Instruction : Tracer {
}

private:
u64 upper;
u64 mask;
u64 mask = 0;
};

u32 _addressBits = 32;
Expand All @@ -137,5 +133,5 @@ struct Instruction : Tracer {
n64 _address = 0;
n64 _omitted = 0;
std::vector<u64> _history;
hashset<VisitMask> _masks;
std::unordered_map<u64, VisitMask> _masks;
};
12 changes: 5 additions & 7 deletions ares/component/processor/sh2/recompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,20 @@ auto SH2::Recompiler::block(u32 address) -> Block* {
auto size = measure(address);
auto hashcode = hash(address, size);

BlockHashPair pair;
pair.hashcode = hashcode;
if(auto result = blocks.find(pair)) {
auto it = blocks.find(hashcode);
if(it != blocks.end()) {
memory::jitprotect(false);
pool(address)->blocks[address >> 1 & 0x7f] = result->block;
pool(address)->blocks[address >> 1 & 0x7f] = it->second;
memory::jitprotect(true);
return result->block;
return it->second;
}

auto block = emit(address);
assert(block->size == size);
pool(address)->blocks[address >> 1 & 0x7f] = block;
memory::jitprotect(true);

pair.block = block;
blocks.insert(pair);
blocks.emplace(hashcode, block);

return block;
}
Expand Down
12 changes: 3 additions & 9 deletions ares/component/processor/sh2/sh2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,11 @@ struct SH2 {
Block* blocks[1 << 7];
};

struct BlockHashPair {
auto operator==(const BlockHashPair& source) const -> bool { return hashcode == source.hashcode; }
auto hash() const -> u32 { return hashcode; }

Block* block;
u64 hashcode;
};


auto reset() -> void {
generation = 0;
blocks.reset();
blocks.clear();
pools.resize(1 << 24);
std::ranges::fill(pools, nullptr);
}
Expand Down Expand Up @@ -310,7 +304,7 @@ struct SH2 {
bool inDelaySlot;
u32 generation;
bump_allocator allocator;
hashset<BlockHashPair> blocks;
std::unordered_map<u64, Block*> blocks;
u16 instructions[1 << 7];
std::vector<Pool*> pools;
} recompiler{*this};
Expand Down
13 changes: 4 additions & 9 deletions ares/n64/rsp/recompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,15 @@ auto RSP::Recompiler::block(u12 address) -> Block* {
auto hashcode = hash(address, size);
hashcode ^= self.pipeline.hash();

BlockHashPair pair;
pair.hashcode = hashcode;
if(auto result = blocks.find(pair)) {
return context[address >> 2] = result->block;
}
auto it = blocks.find(hashcode);
if(it != blocks.end()) return context[address >> 2] = it->second;

auto block = emit(address);
assert(block->size == size);
memory::jitprotect(true);

pair.block = block;
if(auto result = blocks.insert(pair)) {
return context[address >> 2] = result->block;
}
blocks.emplace(hashcode, block);
return context[address >> 2] = block;

throw; //should never occur
}
Expand Down
13 changes: 3 additions & 10 deletions ares/n64/rsp/rsp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,18 +523,11 @@ struct RSP : Thread, Memory::RCP<RSP> {
Pipeline pipeline; //state at *end* of block excepting taken branch stall
};

struct BlockHashPair {
auto operator==(const BlockHashPair& source) const -> bool { return hashcode == source.hashcode; }
auto operator< (const BlockHashPair& source) const -> bool { return hashcode < source.hashcode; }
auto hash() const -> u32 { return hashcode; }

Block* block;
u64 hashcode;
};


auto reset() -> void {
context.fill();
blocks.reset();
blocks.clear();
dirty = 0;
}

Expand Down Expand Up @@ -573,7 +566,7 @@ struct RSP : Thread, Memory::RCP<RSP> {
Pipeline pipeline;
bump_allocator allocator;
array<Block*[1024]> context;
hashset<BlockHashPair> blocks;
std::unordered_map<u64, Block*> blocks;
u64 dirty;
} recompiler{*this};

Expand Down