92 lines
1.5 KiB
C++
92 lines
1.5 KiB
C++
#include <memory>
|
|
#include <limits>
|
|
#include <cstdint>
|
|
#include <iostream>
|
|
#include <verilated.h>
|
|
#include "Vboothmul.h"
|
|
|
|
using word = int16_t;
|
|
using dword = int32_t;
|
|
|
|
constexpr word minint = std::numeric_limits<word>::min();
|
|
constexpr word maxint = std::numeric_limits<word>::max();
|
|
|
|
uint32_t main_time = 0;
|
|
|
|
double sc_time_stamp() {
|
|
return main_time;
|
|
}
|
|
|
|
Vboothmul *mod;
|
|
|
|
static void run_clock() {
|
|
mod->clk = !mod->clk;
|
|
mod->eval();
|
|
main_time++;
|
|
|
|
mod->clk = !mod->clk;
|
|
mod->eval();
|
|
main_time++;
|
|
}
|
|
|
|
static void run(word i, word j, bool reset_in_middle) {
|
|
// Processor is twos-compliment
|
|
mod->a1 = i;
|
|
mod->a2 = j;
|
|
mod->arm = 1;
|
|
|
|
if (!reset_in_middle) {
|
|
while (!mod->fin)
|
|
run_clock();
|
|
} else {
|
|
int i = 0;
|
|
while (!mod->fin) {
|
|
if (i == 10) {
|
|
mod->rst_L = 0;
|
|
} else if (i == 20) {
|
|
mod->rst_L = 1;
|
|
}
|
|
run_clock();
|
|
i++;
|
|
}
|
|
}
|
|
|
|
dword expected = (dword) i * (dword) j;
|
|
if (mod->outn != expected) {
|
|
std::cout << i << "*" << j << "=" << expected
|
|
<< "(" << mod->outn << ")" << std::endl;
|
|
}
|
|
|
|
mod->arm = 0;
|
|
run_clock();
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
Verilated::commandArgs(argc, argv);
|
|
// Verilated::traceEverOn(true);
|
|
mod = new Vboothmul;
|
|
|
|
mod->clk = 0;
|
|
mod->arm = 0;
|
|
mod->rst_L = 1;
|
|
run_clock();
|
|
|
|
run(minint, minint, false);
|
|
run(minint, maxint, false);
|
|
run(maxint, minint, false);
|
|
run(maxint, maxint, false);
|
|
|
|
for (word i = -40; i < 40; i++) {
|
|
for (word j = - 40; j < 40; j++) {
|
|
run(i, j, rand() % 1);
|
|
}
|
|
}
|
|
|
|
mod->final();
|
|
|
|
delete mod;
|
|
std::cout << "done" << std::endl;
|
|
|
|
return 0;
|
|
}
|