实现一个 32 位 LoongArch CPU,支持 LoongArch-C3 指令集的 25 条指令:ADDI.W, ADD.W, SUB.W, LU12I.W, PCADDU12I, OR, ORI, ANDI, AND, XOR, SRLI.W, SLLI.W, JIRL, B, BEQ, BNE, BL, ST.W, LD.W, ST.B, LD.B, MUL.W, SLTI, SRL.W, BLTU
。
该 CPU 为经典五级流水线 CPU,包括取指、译码、执行、访存和写回五个阶段;单发射,无 Cache,无分支预测,无乱序执行。
碍于笔者暑期时间有限且事务繁忙,投入龙芯杯个人赛开发的时间较少,该 CPU 表现一般,架构上也存在诸多可以改进的地方。希望后来者能借此有所启发。
.
├── .ci-scripts/ # CI 脚本(由发布包提供)
├── asm/ # 决赛使用的汇编代码
├── judge/ # 比赛使用的评测代码
├── thinpad_top.srcs/ # Vivado 项目文件
│ ├── constrs_1/new/thinpad_top.xdc # 约束文件
│ ├── sim_1/ # 仿真所需文件(由发布包提供)
│ └── sources_1/ # 源码文件
│ ├── ip/ # IP 核(由 Vivado 自动生成)
│ ├── new/ # Verilog 源码(由发布包提供)
│ └── xucpu/ # XuCPU 源码
├── .gitignore # Git 忽略文件(由发布包提供)
├── .gitlab-ci.yml # GitLab CI 配置文件(由发布包提供)
├── .gitmodules # Git 子模块配置文件(由发布包提供)
├── LICENSE # 开源许可证(GPLv3)
├── README.md # 本文件
└── thinpad_top.xpr # Vivado 项目文件(由发布包提供)
Freq | STREAM | MATRIX | CRYPTONIGHT | Final |
---|---|---|---|---|
50MHz | 0.126s | 0.197s | 0.493s | |
55MHz | 0.114s | 0.179s | 0.448s | |
56MHz | 0.112s | 0.176s | 0.440s | |
57MHz | 0.110s | 0.173s | 0.432s | 0.097s |
编号 | Normal Name | LP64 Name |
---|---|---|
0x0 |
$r0 |
$zero |
0x1 |
$r1 |
$ra |
0x2 |
$r2 |
$tp |
0x3 |
$r3 |
$sp |
0x4 |
$r4 |
$a0 |
0x5 |
$r5 |
$a1 |
0x6 |
$r6 |
$a2 |
0x7 |
$r7 |
$a3 |
0x8 |
$r8 |
$a4 |
0x9 |
$r9 |
$a5 |
0xa |
$r10 |
$a6 |
0xb |
$r11 |
$a7 |
0xc |
$r12 |
$t0 |
0xd |
$r13 |
$t1 |
0xe |
$r14 |
$t2 |
0xf |
$r15 |
$t3 |
0x10 |
$r16 |
$t4 |
0x11 |
$r17 |
$t5 |
0x12 |
$r18 |
$t6 |
0x13 |
$r19 |
$t7 |
0x14 |
$r20 |
$t8 |
0x15 |
$r21 |
$x |
0x16 |
$r22 |
$fp |
0x17 |
$r23 |
$s0 |
0x18 |
$r24 |
$s1 |
0x19 |
$r25 |
$s2 |
0x1a |
$r26 |
$s3 |
0x1b |
$r27 |
$s4 |
0x1c |
$r28 |
$s5 |
0x1d |
$r29 |
$s6 |
0x1e |
$r30 |
$s7 |
0x1f |
$r31 |
$s8 |
指令码 | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 09 | 08 | 07 | 06 | 05 | 04 | 03 | 02 | 01 | 00 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ADDI.W | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | si12 | rj | rd | |||||||||||||||||||
ADD.W | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | rk | rj | rd | ||||||||||||
SUB.W | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | rk | rj | rd | ||||||||||||
LU12I.W | 0 | 0 | 0 | 1 | 0 | 1 | 0 | si20 | rd | |||||||||||||||||||||||
PCADDU12I | 0 | 0 | 0 | 1 | 1 | 1 | 0 | si20 | rd | |||||||||||||||||||||||
OR | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | rk | rj | rd | ||||||||||||
ORI | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | si12 | rj | rd | |||||||||||||||||||
ANDI | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | si12 | rj | rd | |||||||||||||||||||
AND | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | rk | rj | rd | ||||||||||||
XOR | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | rk | rj | rd | ||||||||||||
SRLI.W | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | ui5 | rj | rd | ||||||||||||
SLLI.W | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | ui5 | rj | rd | ||||||||||||
JIRL | 0 | 1 | 0 | 0 | 1 | 1 | offs[15:0] | rj | rd | |||||||||||||||||||||||
B | 0 | 1 | 0 | 1 | 0 | 0 | offs[15:0] | offs[25:16] | ||||||||||||||||||||||||
BEQ | 0 | 1 | 0 | 1 | 1 | 0 | offs[15:0] | rj | rd | |||||||||||||||||||||||
BNE | 0 | 1 | 0 | 1 | 1 | 1 | offs[15:0] | rj | rd | |||||||||||||||||||||||
BL | 0 | 1 | 1 | 0 | 0 | 0 | offs[15:0] | offs[25:16] | ||||||||||||||||||||||||
ST.W | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | si12 | rj | rd | |||||||||||||||||||
LD.W | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | si12 | rj | rd | |||||||||||||||||||
ST.B | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | si12 | rj | rd | |||||||||||||||||||
LD.B | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | si12 | rj | rd | |||||||||||||||||||
MUL.W | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | rk | rj | rd | ||||||||||||
SLTI | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | si12 | rj | rd | |||||||||||||||||||
SRL.W | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | rk | rj | rd | ||||||||||||
BLTU | 0 | 1 | 1 | 0 | 1 | 0 | offs[15:0] | rj | rd |