forked from github/verilator
3069860fdf
Fixes #3872. Testing this is a bit tricky, as the front-end fixes up the operand widths in shifts to match, and we need V3Const to introduce a mismatched one by reducing `4'd2 ** x` (with x being 2 2-bit wide signal) to `4'd1 << x`, but t_dfg_peephole runs with V3Const disabled exactly because it makes it hard to write tests. Rather than fixing this one case in V3Const (which we should do systematically at some point), I fixed DFG to accept these just in case V3Const generates more of them. The assertions were there only because of paranoia (as I thought these were not possible inputs), the code otherwise works.
61 lines
1.3 KiB
C++
61 lines
1.3 KiB
C++
//
|
|
// DESCRIPTION: Verilator: DFG optimizer equivalence testing
|
|
//
|
|
// This file ONLY is placed under the Creative Commons Public Domain, for
|
|
// any use, without warranty, 2022 by Geza Lore.
|
|
// SPDX-License-Identifier: CC0-1.0
|
|
//
|
|
|
|
#include <verilated.h>
|
|
#include <verilated_cov.h>
|
|
|
|
#include <Vopt.h>
|
|
#include <Vref.h>
|
|
#include <iostream>
|
|
|
|
void rngUpdate(uint64_t& x) {
|
|
x ^= x << 13;
|
|
x ^= x >> 7;
|
|
x ^= x << 17;
|
|
}
|
|
|
|
int main(int, char**) {
|
|
// Create contexts
|
|
VerilatedContext ctx;
|
|
|
|
// Create models
|
|
Vref ref{&ctx};
|
|
Vopt opt{&ctx};
|
|
|
|
uint64_t rand_a = 0x5aef0c8dd70a4497;
|
|
uint64_t rand_b = 0xf0c0a8dd75ae4497;
|
|
uint64_t srand_a = 0x00fa8dcc7ae4957;
|
|
uint64_t srand_b = 0x0fa8dc7ae3c9574;
|
|
|
|
for (size_t n = 0; n < 200000; ++n) {
|
|
// Update rngs
|
|
rngUpdate(rand_a);
|
|
rngUpdate(rand_b);
|
|
rngUpdate(srand_a);
|
|
rngUpdate(srand_b);
|
|
|
|
// Assign inputs
|
|
ref.rand_a = opt.rand_a = rand_a;
|
|
ref.rand_b = opt.rand_b = rand_b;
|
|
ref.srand_a = opt.srand_a = srand_a;
|
|
ref.srand_b = opt.srand_b = srand_b;
|
|
|
|
// Evaluate both models
|
|
ref.eval();
|
|
opt.eval();
|
|
|
|
// Check equivalence
|
|
#include "checks.h"
|
|
|
|
// increment time
|
|
ctx.timeInc(1);
|
|
}
|
|
|
|
std::cout << "*-* All Finished *-*\n";
|
|
}
|