Compare commits
2 Commits
af0dca06b2
...
4e22943ba7
Author | SHA1 | Date | |
---|---|---|---|
4e22943ba7 | |||
734d24e639 |
@ -8,6 +8,7 @@ option(DISSASEMBLY "Enable dissasembly" OFF)
|
||||
list(APPEND TEST_SUBDIRS
|
||||
itype
|
||||
rtype
|
||||
imm
|
||||
)
|
||||
|
||||
foreach(TEST_SUBDIR IN LISTS TEST_SUBDIRS)
|
||||
|
27
fw/test/imm/main.s
Normal file
27
fw/test/imm/main.s
Normal file
@ -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
|
||||
|
@ -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
|
@ -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
|
||||
)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user