From 734d24e63993277095365d0e1b4499b514ab554b Mon Sep 17 00:00:00 2001 From: Mario Romero Date: Sat, 18 Feb 2023 17:48:02 -0300 Subject: [PATCH] Redo immediate extend test --- fw/test/CMakeLists.txt | 1 + fw/test/imm/main.s | 27 +++++++++++++ rtl/{Extend.sv => ImmExtend.sv} | 2 +- test/CMakeLists.txt | 7 +++- test/Test_DataMemory.sv | 2 + test/Test_ImmExtend.sv | 72 ++++++++++++++++++++++++--------- 6 files changed, 90 insertions(+), 21 deletions(-) create mode 100644 fw/test/imm/main.s rename rtl/{Extend.sv => ImmExtend.sv} (93%) diff --git a/fw/test/CMakeLists.txt b/fw/test/CMakeLists.txt index 7779492..5336a81 100644 --- a/fw/test/CMakeLists.txt +++ b/fw/test/CMakeLists.txt @@ -8,6 +8,7 @@ option(DISSASEMBLY "Enable dissasembly" OFF) list(APPEND TEST_SUBDIRS itype rtype + imm ) foreach(TEST_SUBDIR IN LISTS TEST_SUBDIRS) diff --git a/fw/test/imm/main.s b/fw/test/imm/main.s new file mode 100644 index 0000000..0b15b71 --- /dev/null +++ b/fw/test/imm/main.s @@ -0,0 +1,27 @@ +.section .text +.global main + +main: + # Assert -1..1 edge case + + # I-type + addi x1, zero, 1 + addi x1, zero, 0 + addi x1, zero, -1 + + # Try extension for the other types + + # S-type (can not be negative) + sw x2, 0x7FA(zero) + + # B-type + bne x3, x4, dummy_label + + # J-type + j 0x0007FA + # Negative jump doesn't fit + # j 0x10DA60 + +dummy_label: + nop + diff --git a/rtl/Extend.sv b/rtl/ImmExtend.sv similarity index 93% rename from rtl/Extend.sv rename to rtl/ImmExtend.sv index c625c3b..880b76b 100644 --- a/rtl/Extend.sv +++ b/rtl/ImmExtend.sv @@ -1,6 +1,6 @@ `timescale 1ns / 1ps -module Extend ( +module ImmExtend ( input logic [ 1:0] imm_src, input logic [31:7] instr, output logic [31:0] imm_ext diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bb4959e..f66279c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -24,7 +24,7 @@ function(rvscc_add_test) verilate(${TEST_TARGET_NAME} SOURCES ${TEST_SOURCES} TRACE - VERILATOR_ARGS --timing + VERILATOR_ARGS --timing --assert ) list(GET TEST_SOURCES 0 TEST_TOP_MODULE) get_filename_component(TEST_TOP_MODULE_NAME ${TEST_TOP_MODULE} NAME_WE) @@ -49,3 +49,8 @@ rvscc_add_test(NAME data-memory SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test_DataMemory.sv ${CMAKE_CURRENT_SOURCE_DIR}/../rtl/DataMemory.sv ) + +rvscc_add_test(NAME imm-extend + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test_ImmExtend.sv + ${CMAKE_CURRENT_SOURCE_DIR}/../rtl/ImmExtend.sv +) diff --git a/test/Test_DataMemory.sv b/test/Test_DataMemory.sv index fb38337..a10f90e 100644 --- a/test/Test_DataMemory.sv +++ b/test/Test_DataMemory.sv @@ -46,10 +46,12 @@ module Test_DataMemory (); end // Read and compare the same range of values write_enable = 0; + #4; for (int i = 0; i < 16; i++) begin addr = start_addr + i; assert (read_data == write_values[i]) else $error("Read failed at address %h", addr); + #2; end $finish; end diff --git a/test/Test_ImmExtend.sv b/test/Test_ImmExtend.sv index 389d89c..15a3bbf 100644 --- a/test/Test_ImmExtend.sv +++ b/test/Test_ImmExtend.sv @@ -1,23 +1,57 @@ `timescale 1ns / 1ps -module Test_ImmExtend(); - logic[1:0] imm_src; - logic[31:0] instr; - logic[31:0] imm_ext; - - Extend imm_extend( - .imm_src(imm_src), - .instr(instr[31:7]), - .imm_ext(imm_ext) - ); - - initial begin - instr='h00a00893; - #20 - imm_src='d0; - #20 - imm_src='d1; - #20 - imm_src='d2; +module Test_ImmExtend (); + logic [ 1:0] imm_src; + logic [31:0] instr; + logic [31:0] imm_ext; + + ImmExtend DUT ( + .imm_src(imm_src), + .instr (instr[31:7]), + .imm_ext(imm_ext) + ); + + logic [7:0] mem[16*4]; + + typedef struct packed { + bit [1:0] imm_src; + bit [31:0] assert_imm_ext_value; + } instr_info_t; + + instr_info_t [5:0] instr_info; + typedef logic [31:0] instr_t; + function static instr_t get_instr(int i); + return {mem[i*4], mem[i*4+1], mem[i*4+2], mem[i*4+3]}; + endfunction + + initial begin + $dumpfile("test-imm-extend.vcd"); + $dumpvars(1, DUT); + + $readmemh("../fw/test/test-imm.mem", mem); + instr_info = '{ + // instr_info_t'{2'h3, 32'hFFFF_FFE2}, + instr_info_t +'{2'h3, 32'h0000_07E6}, + instr_info_t'{2'h2, 32'h0000_0008}, + instr_info_t'{2'h1, 32'h0000_07FA}, + instr_info_t'{2'h0, 32'hFFFF_FFFF}, + instr_info_t'{2'h0, 32'h0000_0000}, + instr_info_t'{2'h0, 32'h0000_0001} + }; + + #1; + assert (mem[0] !== 8'dx) + else $error("Test firmware not loaded"); + + for (int i = 0; i < 6; i++) begin + instr = get_instr(i); + imm_src = instr_info[i].imm_src; + #1; + assert (instr_info[i].assert_imm_ext_value == imm_ext) + else $error("Failed at instruction %d", i + 1); + #1; end + $finish; + end endmodule