Skip to content

Commit

Permalink
updated to newer version
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter-Herrmann committed Jun 21, 2024
1 parent edba758 commit 3486745
Show file tree
Hide file tree
Showing 21 changed files with 766 additions and 332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ name: RISC-V Arch Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
setup:
runs-on: ubuntu-20.04
timeout-minutes: 90

steps:
- name: Checkout code
Expand All @@ -19,6 +17,19 @@ jobs:
- name: Install OSS-CAD-Suite
uses: YosysHQ/setup-oss-cad-suite@v3

- name: Run Verilator Lint
run: |
make lint_verilator
- name: Run Icarus Verilog Lint
run: |
make lint_iverilog
- name: Compile Simulation Model
run: |
cd sim
make compile
- name: Setup Python 3.6
uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -52,8 +63,7 @@ jobs:
run: |
mkdir -p c_emulator/
tar -xzvf bin/riscv_sim_RV64.tar.gz -C c_emulator/ riscv_sim_RV64
echo "TODO - Gather bare minimum binaries for c_emulator/riscv_sim_RV64 on x64 Ubuntu 20.04 and install into ${{ github.workspace }}"
- name: Verify Dependency Installations
run: |
export PATH=$PATH:${{ github.workspace }}/rv64-gcc/riscv/bin:${{ github.workspace }}/c_emulator/riscv_sim_RV64
Expand All @@ -69,26 +79,26 @@ jobs:
source venv/bin/activate
riscof run --no-browser --config=config.ini --suite=${{ github.workspace }}/riscv-arch-test/riscv-test-suite/ --env=${{ github.workspace }}/riscv-arch-test/riscv-test-suite/env
- name: Generate Reports
run: |
echo "Merging Coverage Data..."
cd riscof_work
verilator_coverage --write-info coverage.info rv64i_m/*/src/*/dut/coverage.dat
echo "Generating HTML Coverage Report..."
genhtml coverage.info -s --legend -o coverage
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: reports
path: |
riscof_work/report.html
riscof_work/style.css
riscof_work/coverage/
sim/log.txt
sim/output.vcd
# - name: Generate Reports
# if: always()
# run: |
# echo "Merging Coverage Data..."
# cd riscof_work
# verilator_coverage --write-info coverage.info rv64i_m/*/src/*/dut/coverage.dat
# echo "Generating HTML Coverage Report..."
# genhtml coverage.info -s --legend -o coverage

- name: Logs
if: failure()
run: |
tree
# - name: Upload Artifacts
# if: always()
# uses: actions/upload-artifact@v4
# with:
# name: reports
# path: |
# riscof_work/report.html
# riscof_work/style.css
# riscof_work/coverage/
# riscof_work/rv64i_m/*/src/*/dut/log.txt
# riscof_work/rv64i_m/*/src/*/dut/DUT-Lucid64.signature
# riscof_work/rv64i_m/*/src/*/ref/*.signature
# riscof_work/rv64i_m/*/src/*/ref/*.disass
# riscof_work/rv64i_m/*/src/*/ref/*.log
24 changes: 0 additions & 24 deletions .github/workflows/lint.yml

This file was deleted.

21 changes: 12 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
results/
obj_dir/
sim/log.txt
sim/main.elf
sim/main.hex
riscof_work/
sim/obj_dir/
venv/
sim/tmp.bin
sim/tmp_reversed.bin
sim/my.elf
**/__pycache__/
c_emulator/riscv_sim_RV64
sim/dut.disass
sim/test.hex
sim/coverage.dat
sim/DUT-Lucid64.signature
plugin-sail_cSim/__pycache__/
plugin-Lucid64/__pycache__/
riscof_work/
sim/log.txt
sim/output.vcd
sim/tmp_reversed.bin
formal/**/config/
358 changes: 157 additions & 201 deletions LICENSE

Large diffs are not rendered by default.

26 changes: 19 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
SHELL := /bin/bash

IVERILOG = iverilog
IVERILOG_FLAGS = -Wall -tnull -Isrc/

VERILATOR = verilator
VERILATOR_FLAGS = --language 1364-2005 --lint-only -Wall -Isrc/

Expand All @@ -16,19 +19,28 @@ GREEN = \033[1;32m
BLUE = \033[1;34m
NC = \033[0m # No Color

.PHONY: all lint synth always
.PHONY: all lint_verilator lint_iverilog lint_all synth always

all: lint synth finish
all: lint_all synth finish

lint:
lint_verilator:
@printf "\n${BLUE}%79s${NC}\n\n" "======================== Linting With Verilator ========================"
@$(MAKE) -s $(VERILOG_SOURCES:%=%.lint)
@$(MAKE) -s $(VERILOG_SOURCES:%=%.lint_verilator)

lint_iverilog:
@printf "\n${BLUE}%79s${NC}\n\n" "======================== Linting With Iverilog ========================="
@printf "Linting full design with Iverilog"
@{ $(IVERILOG) $(IVERILOG_FLAGS) $(VERILOG_SOURCES) > /dev/null 2>&1 && printf "${GREEN}%10s${NC}\n" "PASSED"; } \
|| { printf "${RED}%10s${NC}\n" "FAILED" && $(IVERILOG) $(IVERILOG_FLAGS) $(VERILOG_SOURCES); }

lint_all: lint_verilator lint_iverilog
@echo "Completed linting with both Verilator and Iverilog."

synth:
synth:
@printf "\n${BLUE}%79s${NC}\n\n" "======================= Synthesizing with Yosys ========================"
@$(MAKE) -s $(VERILOG_TOP:%=results/synth/%.synth.log)

%.lint: %
%.lint_verilator: %
@printf "Linting %-47s" "$<"
@{ $(VERILATOR) $(VERILATOR_FLAGS) $< > /dev/null 2>&1 && printf "${GREEN}%10s${NC}\n" "PASSED"; } \
|| { printf "${RED}%10s${NC}\n" "FAILED" && $(VERILATOR) $(VERILATOR_FLAGS) $<; }
Expand All @@ -42,4 +54,4 @@ results/synth/%.synth.log: % always
always: ;

finish: always
@echo ""
@echo ""
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Lucid64-Verif
[![RISC-V Arch Tests](https://github.com/Peter-Herrmann/Lucid64-Verif/actions/workflows/build-ubuntu.yml/badge.svg)](https://github.com/Peter-Herrmann/Lucid64-Verif/actions/workflows/build-ubuntu.yml) [![Lint](https://github.com/Peter-Herrmann/Lucid64-Verif/actions/workflows/lint.yml/badge.svg)](https://github.com/Peter-Herrmann/Lucid64-Verif/actions/workflows/lint.yml) [![Synthesis](https://github.com/Peter-Herrmann/Lucid64-Verif/actions/workflows/synthesis.yml/badge.svg)](https://github.com/Peter-Herrmann/Lucid64-Verif/actions/workflows/synthesis.yml)

This repository contains the design verification for the Lucid64 RV64 core. The github actions associated with this repository run the RISCOF Architecture tests, as well as linting and additional tests (as they are created). The actions can be run on any Ubuntu 20.04 x86-64 machine, including Github's `ubuntu-20.04` runners.
This repository contains the design verification for the Lucid64 RV64IMCU_Zicsr_Zifencei core. The github actions associated with this repository run the RISCOF Architecture tests, as well as linting and additional tests (as they are created). The actions can be run on any Ubuntu 20.04 x86-64 machine, including Github's `ubuntu-20.04` runners.

## Test Reports

Coverage and ISA spec reports are attached as artifacts on each [RISC-V Architecture Test run](https://github.com/Peter-Herrmann/Lucid64-Verif/actions/workflows/build-ubuntu.yml).


## Licensing

This project is offered with the Creative Commons Attribution Non Commercial No Derivatives 4.0 International license, which is very permissive for academic and personal use. If you wish to use the design under another license, let me know.
155 changes: 155 additions & 0 deletions formal/M_alu/M_alu_ref.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// //
// Module Name: M_alu_ref //
// Description: Arithmetic and Logic Unit (ALU) for the M extension (integer multiplication and //
// division) of a RV64I processor. //
// Author : Peter Herrmann //
// //
// SPDX-License-Identifier: CC-BY-NC-ND-4.0 //
// //
///////////////////////////////////////////////////////////////////////////////////////////////////
`include "Lucid64.vh"


module M_alu_ref (
input clk_i,
input rst_ni,

input [`XLEN-1:0] a_i,
input [`XLEN-1:0] b_i,

input [5:0] alu_operation_i,

output [`XLEN-1:0] alu_result_oa,
output reg stall_o
);


///////////////////////////////////////////////////////////////////////////////////////////////
// Timing Control //
///////////////////////////////////////////////////////////////////////////////////////////////

reg [`XLEN-1:0] a_r, b_r;
reg op_mul_r;

// TODO - This is total bogus to test the M extension - need to pipeline this
// Also, need to understand the carry_su thing
always @(*) begin
a_r = a_i;
b_r = b_i;
op_mul_r = (alu_operation_i == `ALU_OP_MUL ||
alu_operation_i == `ALU_OP_MULH ||
alu_operation_i == `ALU_OP_MULHSU||
alu_operation_i == `ALU_OP_MULHU ||
alu_operation_i == `ALU_OP_MULW );
stall_o = 'b0;
end

wire signed [`XLEN-1:0] a_sr = $signed(a_r);
wire signed [`XLEN-1:0] b_sr = $signed(b_r);
wire [31:0] a_32 = a_r[31:0];
wire [31:0] b_32 = b_r[31:0];
wire signed [31:0] a_s32 = a_sr[31:0];
wire signed [31:0] b_s32 = b_sr[31:0];


///////////////////////////////////////////////////////////////////////////////////////////////
// Multiplication //
///////////////////////////////////////////////////////////////////////////////////////////////

reg [((2*`XLEN)-1):0] product_u, product_s, product_su_u;
reg signed [`XLEN-1:0] product_su, product_hsu, abs_a, carry_su;
reg [`XLEN-1:0] mul_res_a, product_wu;

always @(*) begin
product_s = a_sr * b_sr;
product_u = a_r * b_r;
product_wu = a_32 * b_32;

// MULHSU calculation: if a is negative, negate and multiply unsigned, then negate result
// if a is positive or 0, result is same as unsigned MULHU
abs_a = a_sr[`XLEN-1] ? -a_sr : a_sr;
product_su_u = abs_a * b_r;
product_su = $signed(product_su_u[((2*`XLEN)-1):`XLEN]);
carry_su = (product_su_u[`XLEN-1:0] == 'b0) ? 'b1 : 'b0;
product_hsu = a_sr[`XLEN-1] ? ~product_su + carry_su : product_su;

case (alu_operation_i)
`ALU_OP_MUL : mul_res_a = product_u[`XLEN-1:0];
`ALU_OP_MULH : mul_res_a = product_s[((2*`XLEN)-1):`XLEN];
`ALU_OP_MULHSU : mul_res_a = product_hsu;
`ALU_OP_MULHU : mul_res_a = product_u[((2*`XLEN)-1):`XLEN];
`ALU_OP_MULW : mul_res_a = { {32{product_wu[31]}}, product_wu[31:0] };
default : mul_res_a = 'b0;
endcase
end

// Resolve this when pipelining!
wire _unused = &{clk_i, rst_ni, product_s[`XLEN-1:0], product_su_u[`XLEN-1:0], product_wu[`XLEN-1:32]};


///////////////////////////////////////////////////////////////////////////////////////////////
// Division //
///////////////////////////////////////////////////////////////////////////////////////////////

reg [`XLEN-1:0] quotient_u, rem_u;
reg signed [`XLEN-1:0] quotient_s, rem_s;
reg [31:0] quotient_wu, rem_wu;
reg signed [31:0] quotient_ws, rem_ws;
reg [`XLEN-1:0] div_res_a;

always @(*) begin
quotient_s = (b_sr == 0) ? $signed(`NEGATIVE_1) : a_sr / b_sr;
quotient_u = (b_r == 0) ? `NEGATIVE_1 : a_r / b_r;
quotient_ws = (b_32 == 0) ? $signed(`NEGATIVE_1_W) : a_s32 / b_s32;
quotient_wu = (b_32 == 0) ? `NEGATIVE_1_W : a_32 / b_32;
rem_s = (b_sr == 0) ? a_sr : a_sr % b_sr;
rem_u = (b_r == 0) ? a_r : a_r % b_r;
rem_ws = (b_32 == 0) ? a_s32 : a_s32 % b_s32;
rem_wu = (b_32 == 0) ? a_32 : a_32 % b_32;

// Check for signed division overflow (64-bit)
if ( (a_sr == `DIV_MOST_NEG_INT) && (b_sr == `NEGATIVE_1) ) begin
quotient_s = $signed(`DIV_MOST_NEG_INT);
rem_s = 'b0;
end

// Check for signed division overflow (32-bit)
if ( (a_s32 == `DIV_MOST_NEG_INT_W) && (b_s32 == `NEGATIVE_1_W) ) begin
quotient_ws = `DIV_MOST_NEG_INT_W;
rem_ws = 'b0;
end

case (alu_operation_i)
`ALU_OP_DIV : div_res_a = quotient_s;
`ALU_OP_DIVU : div_res_a = quotient_u;
`ALU_OP_REM : div_res_a = rem_s;
`ALU_OP_REMU : div_res_a = rem_u;
`ALU_OP_DIVW : div_res_a = { {32{quotient_ws[31]}}, quotient_ws };
`ALU_OP_DIVUW : div_res_a = { {32{quotient_wu[31]}}, quotient_wu };
`ALU_OP_REMW : div_res_a = { {32{rem_ws[31]}}, rem_ws };
`ALU_OP_REMUW : div_res_a = { {32{rem_wu[31]}}, rem_wu };
default : div_res_a = 'b0;
endcase
end

assign alu_result_oa = op_mul_r ? mul_res_a : div_res_a;

endmodule


///////////////////////////////////////////////////////////////////////////////////////////////////
//// Copyright 2024 Peter Herrmann ////
//// ////
//// Licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 ////
//// International License (the "License"); you may not use this file except in compliance ////
//// with the License. You may obtain a copy of the License at ////
//// ////
//// https://creativecommons.org/licenses/by-nc-nd/4.0/ ////
//// ////
//// Unless required by applicable law or agreed to in writing, software ////
//// distributed under the License is distributed on an "AS IS" BASIS, ////
//// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ////
//// See the License for the specific language governing permissions and ////
//// limitations under the License. ////
///////////////////////////////////////////////////////////////////////////////////////////////////
Loading

0 comments on commit 3486745

Please sign in to comment.