Skip to content

Commit

Permalink
driver: add --hash-seed
Browse files Browse the repository at this point in the history
  • Loading branch information
widlarizer committed Oct 1, 2024
1 parent 68e40d8 commit e6f6c7d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions kernel/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "kernel/yosys.h"
#include "kernel/hashlib.h"
#include "libs/sha1/sha1.h"
#include "libs/cxxopts/include/cxxopts.hpp"
#include <iostream>
Expand Down Expand Up @@ -269,6 +270,8 @@ int main(int argc, char **argv)
options.add_options("developer")
("X,trace", "enable tracing of core data structure changes. for debugging")
("M,randomize-pointers", "will slightly randomize allocated pointer addresses. for debugging")
("hash-seed", "mix up hashing values with <seed>, for extreme optimization and testing",
cxxopts::value<int>(), "<seed>")
("A,abort", "will call abort() at the end of the script. for debugging")
("x,experimental", "do not print warnings for the experimental <feature>",
cxxopts::value<std::vector<std::string>>(), "<feature>")
Expand Down Expand Up @@ -415,6 +418,10 @@ int main(int argc, char **argv)
if (result.count("infile")) {
frontend_files = result["infile"].as<std::vector<std::string>>();
}
if (result.count("hash-seed")) {
int seed = result["hash-seed"].as<int>();
Hasher::set_fudge(seed);
}

if (log_errfile == NULL) {
log_files.push_back(stdout);
Expand Down
9 changes: 8 additions & 1 deletion kernel/hashlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,20 @@ class Hasher {
// traditionally 5381 is used as starting value for the djb2 hash
state = 5381;
}
static void set_fudge(uint32_t f) {
fudge = f;
}

private:
uint32_t state;
static uint32_t fudge;
// The XOR version of DJB2
[[nodiscard]]
static uint32_t mkhash(uint32_t a, uint32_t b) {
return ((a << 5) + a) ^ b;
uint32_t hash = ((a << 5) + a) ^ b;
if (fudge)
hash = fudge ^ mkhash_xorshift(hash);
return hash;
}
public:
void hash32(uint32_t i) {
Expand Down
1 change: 1 addition & 0 deletions kernel/yosys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ std::set<std::string> yosys_input_files, yosys_output_files;
bool memhasher_active = false;
uint32_t memhasher_rng = 123456;
std::vector<void*> memhasher_store;
uint32_t Hasher::fudge = 0;

std::string yosys_share_dirname;
std::string yosys_abc_executable;
Expand Down

0 comments on commit e6f6c7d

Please sign in to comment.