driver: add --hash-seed

This commit is contained in:
Emil J. Tywoniak 2024-10-01 16:02:41 +02:00
parent ea0be3b403
commit fdcca7c165
3 changed files with 16 additions and 1 deletions

View File

@ -18,6 +18,7 @@
*/ */
#include "kernel/yosys.h" #include "kernel/yosys.h"
#include "kernel/hashlib.h"
#include "libs/sha1/sha1.h" #include "libs/sha1/sha1.h"
#include "libs/cxxopts/include/cxxopts.hpp" #include "libs/cxxopts/include/cxxopts.hpp"
#include <iostream> #include <iostream>
@ -276,6 +277,8 @@ int main(int argc, char **argv)
options.add_options("developer") options.add_options("developer")
("X,trace", "enable tracing of core data structure changes. for debugging") ("X,trace", "enable tracing of core data structure changes. for debugging")
("M,randomize-pointers", "will slightly randomize allocated pointer addresses. 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<uint64_t>(), "<seed>")
("A,abort", "will call abort() at the end of the script. for debugging") ("A,abort", "will call abort() at the end of the script. for debugging")
("x,experimental", "do not print warnings for the experimental <feature>", ("x,experimental", "do not print warnings for the experimental <feature>",
cxxopts::value<std::vector<std::string>>(), "<feature>") cxxopts::value<std::vector<std::string>>(), "<feature>")
@ -427,6 +430,10 @@ int main(int argc, char **argv)
if (result.count("infile")) { if (result.count("infile")) {
frontend_files = result["infile"].as<std::vector<std::string>>(); frontend_files = result["infile"].as<std::vector<std::string>>();
} }
if (result.count("hash-seed")) {
int seed = result["hash-seed"].as<uint64_t>();
Hasher::set_fudge((Hasher::hash_t)seed);
}
if (log_errfile == NULL) { if (log_errfile == NULL) {
log_files.push_back(stdout); log_files.push_back(stdout);

View File

@ -81,13 +81,20 @@ class Hasher {
// traditionally 5381 is used as starting value for the djb2 hash // traditionally 5381 is used as starting value for the djb2 hash
state = 5381; state = 5381;
} }
static void set_fudge(uint32_t f) {
fudge = f;
}
private: private:
uint32_t state; uint32_t state;
static uint32_t fudge;
// The XOR version of DJB2 // The XOR version of DJB2
[[nodiscard]] [[nodiscard]]
static uint32_t mkhash(uint32_t a, uint32_t b) { 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: public:
void hash32(uint32_t i) { void hash32(uint32_t i) {

View File

@ -92,6 +92,7 @@ std::set<std::string> yosys_input_files, yosys_output_files;
bool memhasher_active = false; bool memhasher_active = false;
uint32_t memhasher_rng = 123456; uint32_t memhasher_rng = 123456;
std::vector<void*> memhasher_store; std::vector<void*> memhasher_store;
uint32_t Hasher::fudge = 0;
std::string yosys_share_dirname; std::string yosys_share_dirname;
std::string yosys_abc_executable; std::string yosys_abc_executable;