• This repository has been archived on 01/Jan/2021
  • Stars
    star
    166
  • Rank 227,748 (Top 5 %)
  • Language Verilog
  • License
    GNU General Publi...
  • Created over 8 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

浙江大学计算机体系结构课程实验

浙江大学计算机体系结构课程实验

张海

本项目是我按照课程要求独立完成的 MIPS 流水线 CPU 实现。目前已实现 31 条指令和 Stall/Forwarding。

本项目的开发使用 Nexys 3 开发板进行,但应当可以很简单地移植到其他开发板。

本项目的二进制 .bit 文件可以在 Releases 中下载。

原因

课程提供的代码在结构、命名和排版上都有诸多不清晰和不一致之处,使得编码和调试时很不舒服。

  • 命名不统一:大部分线路名采用模块名作为前缀以指示归属,但仍有部分代码存在问题。线路名称中有些前缀后加_区别,有些不加,命名不一致。模块对内和对外的线路命名可以不同,但有时加前缀,有时不加,难以一眼确定线路归属,令人困惑。

  • 结构不清晰:流水线寄存器本来应当与各个执行阶段在同一个级别之上,按顺序依次传递数据。但是,代码中将流水线寄存器放在执行阶段模块的代码之中,这正是使得变量命名混乱和代码逻辑不清晰的根源。同时,甚至有将某个多路选择器逻辑放置在流水线寄存器模块代码之中的做法,这令我很难接受。

因此,我选择了自己重新实现。

至于选择开源,是想要给这门课程的实验提供一份清晰且一致的代码实现,也希望能够有助于同学们更加直观地理解流水线 CPU 的具体实现。

希望前人所走过的弯路后人都不必再走,这是我对开源的信念之一。

特点

  • 基于课程提供的电路原理图,符合课程要求和实践。原线路命名与项目中线路命名对应关系在执行阶段模块的声明中以注释的方式给出。

    流水线 CPU 原理图

  • 使用 VGA 显示大量调试信息。

    得益于 VGA 较大的信息量,可以将许多有利于调试或教学的信息都打印在屏幕上实时更新。利用一个组合电路的反汇编器,可以看到当前阶段正在执行指令的汇编源代码。VGA 模块中控制显示相关的长段代码也由 Python 脚本生成,可以通过读取用文本文档记录的设计,快速进行修改。

    VGA 调试设计图

    VGA 调试实现效果

  • 合理的代码组织方式。

    在 CPU 模块之下,PC、各个流水线寄存器和各个执行阶段模块依次连接,尽力实现代码组织的合理和明确。

    CPU 代码组织结构

  • 统一的代码风格和排版。

    经过权衡,项目代码采用了较长的命名,是为了将原本意义不明显、需要常常查看注释或原理图的变量名称,转变为清晰、不容易出错的名称,由此项目编码过程中未出现过代码逻辑错误。

    命名规则的统一使得线路功能和归属清晰可靠,而代码中的缩进、空行分块和前后顺序等排版也尽量追寻体现代码之间的逻辑关系,便于阅读和维护。

    项目代码始终尽量采用推荐的 Verilog 实践,例如新的模块声明方式。

  • 自动生成部分模块和模块连线代码。

    得益于统一的命名风格和代码组织,流水线寄存器模块和各模块之间连线的代码可以按照特定规则生成。本项目采用 Python 脚本完成了数百行的代码生成,避免大量繁杂和容易出错的工作,同时由此以后修改接口时也可以更为简单。

    流水线寄存器代码生成脚本

    本项目中大部分代码逻辑都在 *Stage.v 中,而 *Registers.vCpu.v 均为生成的代码。

许可

Copyright (c) 2016 Zhang Hai <[email protected]>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see
<http://www.gnu.org/licenses/>.

More Repositories

1

MaterialFiles

Material Design file manager for Android
Kotlin
5,968
star
2

Douya

开源的 Material Design 豆瓣客户端(A Material Design app for douban.com)
Java
4,548
star
3

MaterialProgressBar

Material Design ProgressBar with consistent appearance
Java
2,215
star
4

MaterialRatingBar

Material Design RatingBar with better appearance
Java
1,961
star
5

MaterialColdStart

Utilize the window background during cold start time to make your app look faster.
Shell
1,225
star
6

AndroidFastScroll

Fast scroll for Android RecyclerView and more
Java
701
star
7

PatternLock

Material Design Pattern Lock with auth flow implementation
Java
689
star
8

CustomTabsHelper

Custom tabs, made easy.
Java
386
star
9

Untracker

App to help you remove tracking information before sharing links
Kotlin
366
star
10

ComposePreference

Preference implementation for Jetpack Compose Material 3
Kotlin
182
star
11

AppIconLoader

Android app icon loader from AOSP iconloaderlib
Java
162
star
12

MaterialEditText

Material Design EditText with a delightful linear ripple in background
Java
146
star
13

zju-csse-undergraduate-design-latex-template

浙江大学计算机科学与技术、软件工程专业本科毕业设计 LaTeX 模板
TeX
138
star
14

SystemUiHelper

Helper for dealing with Android System UI visibility
Java
117
star
15

BeeShell

Java REPL on Android with BeanShell
Kotlin
107
star
16

EffortlessPermissions

An Android permission library extending Google's EasyPermissions with convenient additions.
Java
86
star
17

TextSelectionWebSearch

Add web search to text selection toolbar on Android
Java
84
star
18

gnome-shell-extension-transparent-top-bar

GNOME Shell extension that brings back the transparent top bar when free-floating in GNOME Shell 3.32
JavaScript
77
star
19

DouyaApiKey

豆芽 API Key 设置向导
Java
69
star
20

DoubanYearProgress

Year progress for Douban
JavaScript
63
star
21

AndroidUtil

Utilities to make the life of an Android developer easier
Java
59
star
22

libarchive-android

libarchive as an Android library
C
56
star
23

AndroidSVGScripts

Bash scripts to automate and extend the process of using SVG as Android image asset
Shell
56
star
24

AndroidRetroFile

Backport of java.nio.file API (JSR 203) for Android
Java
47
star
25

mipsasm

MIPS assembler and IDE
Java
46
star
26

MaterialPlayPauseDrawable

Material Design play/pause Drawable with animation
Java
37
star
27

libselinux-android

libselinux as an Android library
C
24
star
28

join-screenshots.zhanghai.me

Join screenshots with HTML5
HTML
23
star
29

opengl-c-solarsystem

Animated solar system model implemented with OpenGL and FreeGLUT in C
C
22
star
30

orgexp

Computer Organization Experiment, Shi Qingsong, Zhejiang University.
Verilog
21
star
31

pykeymacs

Emacs style keyboard macros implemented in Python
Python
20
star
32

vntools

Tools for working with visual novels
C++
18
star
33

filesystem-kt

Multiplatform Kotlin library for accessing files and file systems
Kotlin
17
star
34

deadbeef-gnome-mmkeys

Add GNOME multimedia keys support in DeadBeef player using DBus
C
16
star
35

collision-detection-bubbles

A collision detection and resolution experiment with Two.js
JavaScript
16
star
36

gtkmmproject

Gtkmm CLion Project
CMake
12
star
37

linenoise-android

Linenoise as an Android library
C
12
star
38

qt5project

Qt 5 CLion project
C++
10
star
39

Reflected

Java library for easy-to-use reflection
Java
9
star
40

AndroidLibraryTemplate

Android library template
9
star
41

SeekBarPreference

A Preference that shows a dialog with a SeekBar widget.
Java
9
star
42

Bytecoder

Android gradle plugin to generate bytecode for accessing any method or field
Java
9
star
43

Functional

Java library for JavaScript-like functional methods
Java
8
star
44

zhsh

A minimal interactive shell written in C.
C
8
star
45

DouyaCiBuilds

豆芽 CI 构建版本仓库
8
star
46

Palette

Sample application to showcase android.support.v7.graphics.Palette
Java
6
star
47

twitter-unwanted-follower-remover

Semi-automatic command line tool for removing unwanted followers on Twitter
JavaScript
5
star
48

particle-system-campfire

A particle system experiment with Two.js
HTML
5
star
49

AimBackend

Another Instant Messager app, backend.
JavaScript
5
star
50

AimAndroid

Another Instant Messager app, Android.
Java
5
star
51

kiscript

ECMAScript, kept simple.
C
5
star
52

ColorPicker

Android color picker from AOSP
Java
5
star
53

markdown-template

Zhang Hai's markdown template
JavaScript
4
star
54

gnome-shell-extension-es6-class-codemod

A jscodeshift transform that helps migrating GNOME Shell extensions to 3.32
JavaScript
4
star
55

Promise

Java library for JavaScript-like Promise
Java
4
star
56

ZJUWLANAutoLogin

A chrome extesion that enables auto login when redirected to login page on ZJUWLAN
JavaScript
4
star
57

resume.zhanghai.me

Zhang Hai's resume
HTML
4
star
58

gettext-po-parser

Gettext PO file parser
4
star
59

xkeymacs

X11 KEYboard MACroS
C
4
star
60

fpga-life-game

Conway's game of life implemented on FPGA with combinational logic
Verilog
3
star
61

zhclib

A C library written by me
C
3
star
62

translations.zhanghai.me

Search translations in open source projects
HTML
3
star
63

stone.zhanghai.me

(Zhang Hai's) The story of the stone
HTML
3
star
64

douya-website

Source of Zhang Hai's Douya project home
JavaScript
3
star
65

SsidTester

SSID tester for identifying ZJUWLAN difficulty. Also serves as a sample application for beginners.
Java
3
star
66

course_linux_programming

Linux programming course
C
3
star
67

zh-conf-backup

Backup script for Zhang Hai's configuration
Shell
3
star
68

Labyrinth

Labyrinth game with OpenGL
Java
3
star
69

resume-legacy

Source of Zhang Hai's resume, legacy version
CSS
2
star
70

slides.zhanghai.me

Zhang Hai's slides
HTML
2
star
71

douya.zhanghai.me

Zhang Hai's Douya
ApacheConf
2
star
72

api-functions-worth-calling

API - Functions worth calling
HTML
2
star
73

optical-system-mfc

Optical System with MFC
C
2
star
74

ExpressionEvaluator

Expression evaluator written in Java
Java
2
star
75

AimFrontend

Another Instant Messager app, frontend.
Vue
2
star
76

zh-minecraft-saves

My Minecraft saves.
Shell
2
star
77

FxPaint

Paint app written with JavaFx
Java
2
star
78

projects.zhanghai.me

Zhang Hai's projects
HTML
2
star
79

calc

C Topic Project - A calculator based on operator precedence
C
2
star
80

www.zhanghai.me

Zhang Hai's main site
HTML
2
star
81

aoe4-mod-superweapon-pvp

Add Siege Camp in campaign as a superweapon for the game (PvP version)
1
star
82

lms

C Topic Project - A simple Library Management System
C
1
star
83

SePolicyInject

Android library to inject rules into binary SELinux kernel policies
CMake
1
star
84

DataStructure

An object oriented implementation of fundamental data structures (and algorithms) using C++11
C++
1
star
85

WordList

A simple android application to display specially annotated English word lists
Java
1
star
86

optical-system-qt

Optical System with Qt
C
1
star
87

seafile-server-github-actions-build

Seafile Server built by GitHub Actions
1
star
88

reveal-md-template

Reveal.js template with reveal-md
Makefile
1
star
89

reveal-js-template

Zhang Hai's reveal.js template
Shell
1
star
90

ShowcaseView

A fork from legacy branch of https://github.com/amlcurran/ShowcaseView
Java
1
star
91

blog.zhanghai.me

Zhang Hai's blog
HTML
1
star
92

sevenzipjbind

Mirrored from git://sevenzipjbind.git.sourceforge.net/gitroot/sevenzipjbind/sevenzipjbind
C++
1
star
93

translations-index.zhanghai.me

Translations index
1
star
94

abnf-kt

ABNF parser generator for Kotlin
Kotlin
1
star