Compare commits

...

3 Commits

Author SHA1 Message Date
37e0c938a3 Update sandbox
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-03-02 18:16:41 -03:00
524f8d7dde Merge branch 'main' of https://git.1159.cl/Mario1159/RVSCC 2023-03-02 17:53:49 -03:00
54b3083319 Fix cache memory test 2023-03-02 17:20:10 -03:00
8 changed files with 29 additions and 28 deletions

View File

@ -5,10 +5,14 @@ set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
include(CTest)
include(ExternalProject)
option(TEST "Enable test firmware compilation" ON)
option(SANDBOX_ASM "Enable sandbox compilation using ASM language" OFF)
option(SANDBOX_C "Enable sandbox compilation using C language" OFF)
ExternalProject_Add(firmware
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/fw
BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build/fw
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/cmake/riscv-toolchain.cmake
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/cmake/riscv-toolchain.cmake -DTEST=${TEST} -DSANDBOX_ASM=${SANDBOX_ASM} -DSANDBOX_C=${SANDBOX_C}
INSTALL_COMMAND ""
)

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)
project(firmware)
project(firmware C ASM)
option(TEST "Enable test firmware compilation" ON)
option(SANDBOX_ASM "Enable sandbox compilation using ASM language" OFF)

View File

@ -1,7 +1,4 @@
cmake_minimum_required(VERSION 3.10)
project(sandbox_asm ASM)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/utils.cmake)
include(${PROJECT_SOURCE_DIR}/../cmake/utils.cmake)
set(SOURCE_FILES main.s)

View File

@ -1,7 +1,4 @@
cmake_minimum_required(VERSION 3.10)
project(sandbox_c C)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/utils.cmake)
include(${PROJECT_SOURCE_DIR}/../cmake/utils.cmake)
set(SOURCE_FILES
main.c

View File

@ -22,21 +22,21 @@ module cache_memory #(
localparam int WaySize = $clog2(NUM_WAYS);
localparam int SetSize = $clog2(NUM_SETS);
localparam int TagSize = ADDR_SIZE - SetSize - ByteOffsetSize;
logic [NUM_WAYS - 1:0] hits;
logic [WaySize-1:0] way;
logic [WaySize-1:0] read_way;
priority_encoder #(.N(WaySize)) read_way_encoder (
priority_encoder #(
.N(WaySize)
) read_way_encoder (
.data_in(hits),
.data_out(read_way),
.valid(hit)
);
always_comb begin
if(write_enable)
way = write_way;
else
way = read_way;
if (write_enable) way = write_way;
else way = read_way;
end
typedef struct packed {
@ -66,7 +66,7 @@ module cache_memory #(
ways[way][set].valid <= 1;
end
end
logic [NUM_WAYS - 1:0] valid_flags;
always_comb begin
for (int i = 0; i < NUM_WAYS; i++) begin
@ -74,10 +74,12 @@ module cache_memory #(
hits[i] = ways[i][set].valid && (tag == ways[i][set].tag);
end
end
priority_encoder #(.N(WaySize)) populate_way_encoder (
.data_in(valid_flags),
.data_out(populate_way),
.valid('dz)
priority_encoder #(
.N(WaySize)
) populate_way_encoder (
.data_in(valid_flags),
.data_out(populate_way),
.valid()
);
endmodule

View File

@ -9,7 +9,7 @@ module priority_encoder #(
output logic valid
);
always_comb begin
data_out = 3'dx;
data_out = N'('dx);
for (int i = 0; i < 2 ** N; i++) begin
if (data_in[i]) data_out = i[N-1:0];
end

View File

@ -101,5 +101,6 @@ rvscc_add_test(
NAME cache-memory
TOP test_cache_memory
SOURCES ${PROJECT_SOURCE_DIR}/rtl/cache_memory.sv
${PROJECT_SOURCE_DIR}/rtl/priority_encoder.sv
${PROJECT_SOURCE_DIR}/test/test_cache_memory.sv
)

View File

@ -10,7 +10,7 @@ module test_cache_memory ();
logic write_enable;
logic [31:0] write_data;
logic [31:0] read_data;
logic read_valid;
logic hit;
logic [dut.WaySize-1:0] populate_way;
cache_memory #(
.ADDR_SIZE (32),
@ -26,7 +26,7 @@ module test_cache_memory ();
.write_enable(write_enable),
.write_data(write_data),
.read_data(read_data),
.read_valid(read_valid),
.hit(hit),
.populate_way(populate_way)
);
@ -51,12 +51,12 @@ module test_cache_memory ();
write_enable = 0;
tag += 1;
#1;
assert (read_valid == 0)
assert (hit == 0)
else $error("Valid flags does not match");
#ClockCycle;
tag -= 1;
#1;
assert (read_valid == 1)
assert (hit == 1)
else $error("Valid flags does not match");
$finish;
end