-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
78 changed files
with
8,263 additions
and
2,588 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. | ||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp | ||
// List of extensions which should be recommended for users of this workspace. | ||
"recommendations": [ | ||
"bmpenuelas.systemverilog-formatter-vscode", | ||
"Gruntfuggly.todo-tree", | ||
"mshr-h.veriloghdl", | ||
"mhutchie.git-graph" | ||
], | ||
// List of extensions recommended by VS Code that should not be recommended for users of this workspace. | ||
"unwantedRecommendations": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"verilog.linting.linter": "verilator", | ||
"verilog.linting.iverilog.arguments": "", | ||
"verilog.logging.enabled": true, | ||
"verilog.linting.verilator.arguments": "-Isrc -Isrc/vsrc -Isrc/vsrc/pipeline/1_fetch -Wall -DCPU_2CMT", | ||
"todo-tree.filtering.includeGlobs": [ | ||
"**/*.sv", | ||
"**/*.v" | ||
], | ||
"todo-tree.regex.regex": "((\\s|^)($TAGS):)", | ||
"todo-tree.regex.enableMultiLine": false, | ||
"todo-tree.regex.regexCaseSensitive": true, | ||
"todo-tree.general.debug": false, | ||
"todo-tree.general.enableFileWatcher": true, | ||
"todo-tree.filtering.includeHiddenFiles": true, | ||
"todo-tree.filtering.includedWorkspaces": [ | ||
"**/*" | ||
], | ||
"todo-tree.filtering.useBuiltInExcludes": "file and search excludes", | ||
"systemverilogFormatter.veribleBuild": "Ubuntu-20.04-focal-x86_64", | ||
"systemverilogFormatter.commandLineArguments": "--indentation_spaces 4", | ||
"editor.formatOnSave": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# 对接Chiplab文档 | ||
|
||
## CPU核模块 | ||
此处是指CPU内核部分的模块 | ||
|
||
一般来说包含: | ||
- 流水线,ALU等核心部件 | ||
- AXI控制器 | ||
- 差分测试相关DPI | ||
|
||
一般来说不包含: | ||
- 仿真/综合/调试/chiplab等可能用到的各种RAM | ||
- 各种AXI桥和AXI Slave | ||
|
||
Chiplab要求的模块端口,接口均写死在Chiplab,如果要更改需要修改Chiplab的配置或源码 | ||
|
||
例外:双发射Chiplab有提供支持,参考最下面 | ||
|
||
```verilog | ||
module cpu_top( | ||
input aclk, | ||
input aresetn, | ||
input [ 7:0] intrpt, | ||
//AXI interface | ||
//read reqest | ||
output [ 3:0] arid, | ||
output [31:0] araddr, | ||
output [ 7:0] arlen, | ||
output [ 2:0] arsize, | ||
output [ 1:0] arburst, | ||
output [ 1:0] arlock, | ||
output [ 3:0] arcache, | ||
output [ 2:0] arprot, | ||
output arvalid, | ||
input arready, | ||
//read back | ||
input [ 3:0] rid, | ||
input [31:0] rdata, | ||
input [ 1:0] rresp, | ||
input rlast, | ||
input rvalid, | ||
output rready, | ||
//write request | ||
output [ 3:0] awid, | ||
output [31:0] awaddr, | ||
output [ 7:0] awlen, | ||
output [ 2:0] awsize, | ||
output [ 1:0] awburst, | ||
output [ 1:0] awlock, | ||
output [ 3:0] awcache, | ||
output [ 2:0] awprot, | ||
output awvalid, | ||
input awready, | ||
//write data | ||
output [ 3:0] wid, | ||
output [31:0] wdata, | ||
output [ 3:0] wstrb, | ||
output wlast, | ||
output wvalid, | ||
input wready, | ||
//write back | ||
input [ 3:0] bid, | ||
input [ 1:0] bresp, | ||
input bvalid, | ||
output bready, | ||
//debug info | ||
output [31:0] debug0_wb_pc, | ||
output [ 3:0] debug0_wb_rf_wen, | ||
output [ 4:0] debug0_wb_rf_wnum, | ||
output [31:0] debug0_wb_rf_wdata | ||
#ifdef CPU_2CMT | ||
, | ||
output [31:0] debug1_wb_pc, | ||
output [ 3:0] debug1_wb_rf_wen, | ||
output [ 4:0] debug1_wb_rf_wnum, | ||
output [31:0] debug1_wb_rf_wdata | ||
#endif | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# 代码规范 | ||
|
||
## 缩进 | ||
|
||
统一使用 VS Code 插件 `bmpenuelas.systemverilog-formatter-vscode` 对代码进行自动格式化 | ||
|
||
注意使用`--indentation_spaces 4` | ||
|
||
还应将`.v`文件关联到`SystemVerilog`以获得自动格式化,具体方法是点击VS Code右下角的`Verilog`,然后在弹出的窗口选择`Configure File Association for '.v'` | ||
|
||
## 模块(module) | ||
|
||
### 模块命名 | ||
|
||
使用蛇形命名,形如`aaa_bbb_ccc` | ||
|
||
### 模块端口命名 | ||
|
||
一般来讲分为三个部分,每个部分之间通过下划线连接: | ||
- 连接到的模块简称,如`icache` | ||
- 信号线的含义,如`data` | ||
- 信号的方向,`o`或`i` | ||
|
||
全部连起来如`icache_data_o` | ||
|
||
### 模块端口类型(SystemVerilog) | ||
|
||
如果使用了SystemVerilog,那么尽量把意义相近的信号打包成struct,定义在头文件中,然后作为端口的类型 | ||
|
||
## 信号 | ||
|
||
### 信号命名 | ||
|
||
使用蛇形命名,在模块内部,不添加后缀`o`或`i` | ||
|
||
### 状态机(SystemVerilog) | ||
|
||
如果使用SystemVerilog,那么状态机的状态要求使用`enum` | ||
|
||
如: | ||
```verilog | ||
enum int unsigned { | ||
ACCEPT_ADDR = 0, | ||
IN_TRANSACTION_1 = 1, | ||
IN_TRANSACTION_2 = 2 | ||
} | ||
``` | ||
|
||
### 模块间连线信号命名 | ||
|
||
约定实例化的模块间连接用的信号使用以下三部分命名: | ||
- 起始模块名 | ||
- 到达模块名 | ||
- 信号含义 | ||
|
||
例如`frontend_icache_addr` | ||
|
||
如果有多输出的信号,使用`multi`代替到达模块名 | ||
|
||
例如`ctrl_multi_stall` | ||
|
||
注意无需`o`或`i` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# 流水线前端设计 | ||
|
||
**目前实现的跳转不正确!!!** | ||
|
||
## ICache 信号 | ||
|
||
## Instruction Buffer 信号 | ||
|
||
## 后端信号 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Instruction Buffer 设计 | ||
|
||
## 整体设计 | ||
|
||
使用类似状态机的写法,使用一个长度为`BUFFER_SIZE`的寄存器`buffer_queue`保存当前状态。 | ||
使用`read_ptr`和`write_ptr`记录后端和前端的读写位置。 | ||
|
||
更新逻辑: | ||
|
||
根据后端当拍返回的可接受的指令,确定`read_ptr`的更新和`buffer_queue`对应位置的重置。 | ||
|
||
根据前端给出的指令更新`write_ptr`和对应位置的更新。 | ||
|
||
根据当前的两个ptr给出前端停顿的指令 | ||
|
||
|
||
## 前端信号 | ||
|
||
```verilog | ||
// <-> Frontend | ||
input instr_buffer_info_t frontend_instr_i[IF_WIDTH], | ||
output logic frontend_stallreq_o, // Require frontend to stop | ||
``` | ||
接受前端的两条指令,当拍给出`frontend_stallreq_o` | ||
|
||
要求前端停顿时完全保持输入的两条指令不变 | ||
|
||
如果前端给出的两条指令不是都有效,那么要求有效的必须都在低位,而且保证指令的顺序关系,即低位对应指令流中靠前的指令。 | ||
|
||
## 后端信号 | ||
|
||
```verilog | ||
// <-> Backend | ||
input logic [ID_WIDTH-1:0] backend_accept_i, // Backend can accept 0 or more instructions, must return in current cycle! | ||
input logic backend_flush_i, // Backend require flush, maybe branch miss | ||
output instr_buffer_info_t backend_instr_o[ID_WIDTH] | ||
``` | ||
|
||
将`buffer_queue`的对应位置直接接到`backend_instr_o`,不保证两条指令都有效,甚至可能都无效(如初始时) | ||
|
||
要求当拍返回`backend_accept_i`信号,如果接受指令,意思即这条指令会进入下一级,如果接受,返回的接受信号必须都在低位。 | ||
|
||
下一周期接受的指令将会被重置,然后顺序移动指令,即如果接受接受指令1,拒绝指令2,下一周期指令2将变为指令1,指令2为新的指令。 | ||
|
||
后端或ctrl 输入`backend_flush_i`的下一周期将全部`buffer_queue`刷空,因为`backend_instr_o`是直接接在`buffer_queue`上的,因此下一周期也变为空。 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# 每日一个 Verilog 小技巧 | ||
|
||
## $clog2() 是可综合的 | ||
|
||
`$clog2()`是ceil(log2(x))的意思,2的对数的向上取整,常用于已知寻址范围,确定索引信号的位宽。 | ||
|
||
虽然看起来是一个系统调用,但是由于实在是过于好用,大部分的仿真和综合工具都支持处理这个函数。 | ||
|
||
## always块中最后一个赋值覆盖前面的 | ||
|
||
这很有用,如果想要实现带有优先级的组合逻辑,可以避免使用超级长的if-else判断,而是利用越后面的赋值优先级越高来代替if-else | ||
|
||
当然,这可能带来高的延迟。 |
Binary file not shown.
Oops, something went wrong.