RISC-V: R-type 算术指令

终於进到 R-type 指令了!
指令实作已经有固定流程了,很单纯,
另外花了一点时间修改昨天的 Exception。

R-type

指令格式如下:

|31     25|24   20|19   15|14    12|11   7|6       0|
+---------------------------------------------------+
|  func7  |  rs2  |  rs1  | funct3 |  rd  | opcode  |
+---------------------------------------------------+

ADD

rd = rs1 + rs2

|31         25|24   20|19   15|14    12|11   7|6       0|
+-------------------------------------------------------+
|   0000000   |  rs2  |  rs1  |  000   |  rd  | 0110011 |
+-------------------------------------------------------+

SUB

rd = rs1 - rs2

|31         25|24   20|19   15|14    12|11   7|6       0|
+-------------------------------------------------------+
|   0100000   |  rs2  |  rs1  |  000   |  rd  | 0110011 |
+-------------------------------------------------------+

实际程序

github 页面 Tag: ITDay22

兰尼斯特猴来还债了!
昨天只是简单的在 ECALLEBREAK 的时候结束模拟,
相信也有读者注意到 LOAD/STORE、JUMP/BRANCH Exception 都没有处理,
没做的原因是因为当时还要处理 Memory 和 Program Counter 设计的问题,
必须让自己专注在当下最重要的事情上,於是把 Exception 相关的议题延後处理。

Exception Handling 并不属於 Executor 的功能,
这次先转交给 CPU,为之後的 Exception/Interrupt 实作做一点准备,
Cause 先简单处理,之後再补上各个 Exception 的编号。

//executor.cpp
...
void EXECUTOR::ECALL_E()
{
	const int cause = 11;
	cpu->raise_exception(cause);
}

void EXECUTOR::EBREAK_E()
{
	const int cause = 3;
	cpu->raise_exception(cause);
}
...

指令部分相对单纯,
这次一样用 ADD 当范例,实作如下:

//executor.cpp
...
void EXECUTOR::reg_dispatch()
{
	switch (instruction_decoder->get_func3()) {
		case INSTRUCTION_DECODER_INTERFACE::ADDI_FN3: //SUB_FN3 is the same
			switch (instruction_decoder->get_func7()) {
				case INSTRUCTION_DECODER_INTERFACE::ADD_FN7:
					ADD_E();
					break;
...
void EXECUTOR::ADD_E()
{
	auto rd = instruction_decoder->get_rd();
	auto rs1 = instruction_decoder->get_rs1();
	auto rs2 = instruction_decoder->get_rs2();

	auto value = register_file->get_value_integer(rs1) + register_file->get_value_integer(rs2);
	register_file->set_value_integer(rd, value);
}
...
//instructionDecoderInterface.h
...
		REG_OP = 0b0110011,
...
		ADD_FN3 = 0b000,
...
		ADD_FN7 = 0b0000000,
...

<<:  # Day 27 Page Migration (二)

>>:  【第21天】训练模型-模型组合与辨识isnull(二)

Day 23 - Sort3

大家好,我是长风青云。今天是铁人赛的23天。快结束了,希望我能讲完我想讲的演算法。 ...

Day 34 (MySQL)

1.除错 MySQL02影片00:01 2.MAD利用命令列进入MySQL $ % = 终端机 (1...

Day 8 - 导入 Google Fonts

昨天讲了文字使用,今天来讲讲字体。在默认情况下,Tailwind 提供了三种字体系列:font-sa...

Gulp Babel ES6 编译(2) DAY84

昨天我们已经介绍 babel编译 与 concat合并成一支档案 但我们还没介绍 Source Ma...

Day 16 - 卷积神经网络 CNN (1)-壹页AI战国史

历史重要性 CNN历史已发生,为何要花时间了解它?个人认为了解CNN历史可以让我们选择以同方式解决不...