#!/usr/bin/python3 ################################## # wally-I-PIPELINE.py # # David_Harris@hmc.edu 27 October 2021 # # Generate directed and random test vectors for RISC-V Design Validation. ################################## ################################## # libraries ################################## from datetime import datetime from random import randint from random import seed from random import getrandbits ################################## # functions ################################## def twoscomp(a): amsb = a >> (xlen-1) alsbs = ((1 << (xlen-1)) - 1) & a if (amsb): asigned = a - (1<> 32) + "\n" r.write(line) testnum = testnum+1 ################################## # main body ################################## # change these to suite your tests instrs = ["ADD", "SUB", "SLT", "SLTU", "XOR", "OR", "AND"] author = "David_Harris@hmc.edu" xlens = [32, 64] numrand = 100 # setup seed(0) # make tests reproducible # generate files for each test for xlen in xlens: formatstrlen = str(int(xlen/4)) formatstr = "0x{:0" + formatstrlen + "x}" # format as xlen-bit hexadecimal number formatrefstr = "{:08x}" # format as xlen-bit hexadecimal number with no leading 0x if (xlen == 32): storecmd = "sw" wordsize = 4 else: storecmd = "sd" wordsize = 8 pathname = "../wally-riscv-arch-test/riscv-test-suite/rv" + str(xlen) + "i_m/I/" fname = pathname + "src/WALLY-PIPELINE.S" testnum = 0 # print custom header part f = open(fname, "w") # r = open(refname, "w") line = "///////////////////////////////////////////\n" f.write(line) lines="// "+fname+ "\n// " + author + "\n" f.write(lines) line ="// Created " + str(datetime.now()) f.write(line) # insert generic header h = open("testgen_header.S", "r") for line in h: f.write(line) # print directed and random test vectors # for a in corners: # for b in corners: # writeVector(a, b, storecmd, xlen) # for i in range(0,numrand): # a = getrandbits(xlen) # b = getrandbits(xlen) # writeVector(a, b, storecmd, xlen) # print footer h = open("testgen_footer.S", "r") for line in h: f.write(line) # Finish # lines = ".fill " + str(testnum) + ", " + str(wordsize) + ", -1\n" # lines = lines + "\nRV_COMPLIANCE_DATA_END\n" f.write(lines) f.close() # r.close()