蜂鸟e203处理器核的ALU包括5个模块:普通ALU模块、地址生成单元模块、分支预测解析模块、CSR读写控制模块、多周期乘除模块。
普通ALU模块:普通ALU模块主要负责常规的ALU计算(逻辑运算、加减法和移位等)
地址单元生成模块(AGU):AGU模块主要负责Load、store和A扩展指令地址的生成
分支解析预测模块(BJP):BJP模块主要负责分支和跳转指令的解析和执行
CSR读写控制模块(CSR-ctrol):负责CSR读写指令(包括csrrw\csrrs\csrrc等)的执行
多周期乘除模块:负责多周期乘除法指令的执行
所有模块共享数据通路,运算数据通路是真正进行数据计算的模块,普通ALU模块主要负责常规的ALU计算(逻辑运算、加减法和移位等),此模块完全由组合逻辑构成,其主要逻辑是根据普通ALU的指令类型,发起对共享数据通路的操作请求,并且从共享的运算数据通路中取回计算结果。
以下是普通ALU模块的源码以及注释
/*
Copyright 2018-2020 Nuclei System Technology, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.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.
*/
//=====================================================================
//
// Designer : Bob Hu
//
// Description:
// This module to implement the regular ALU instructions
//
//
// ====================================================================
`include "e203_defines.v"
module e203_exu_alu_rglr(
//
//
// The Handshake Interface
//【
input alu_i_valid, // Handshake valid
output alu_i_ready, // Handshake ready
//输入数据,由派遣模块输入
input [`E203_XLEN-1:0] alu_i_rs1,
input [`E203_XLEN-1:0] alu_i_rs2,
input [`E203_XLEN-1:0] alu_i_imm,
input [`E203_PC_SIZE-1:0] alu_i_pc,
input [`E203_DECINFO_ALU_WIDTH-1:0] alu_i_info,
//
//
// The ALU Write-back/Commit Interface
output alu_o_valid, // Handshake valid
input alu_o_ready, // Handshake ready
// The Write-Back Interface for Special (unaligned ldst and AMO instructions)
output [`E203_XLEN-1:0] alu_o_wbck_wdat,
output alu_o_wbck_err,
output alu_o_cmt_ecall,
output alu_o_cmt_ebreak,
output alu_o_cmt_wfi,
//
//
// To share the ALU datapath
//
// The operands and info to ALU
output alu_req_alu_add ,
output alu_req_alu_sub ,
output alu_req_alu_xor ,
output alu_req_alu_sll ,
output alu_req_alu_srl ,
output alu_req_alu_sra ,
output alu_req_alu_or ,
output alu_req_alu_and ,
output alu_req_alu_slt ,
output alu_req_alu_sltu,
output alu_req_alu_lui ,
output [`E203_XLEN-1:0] alu_req_alu_op1,
output [`E203_XLEN-1:0] alu_req_alu_op2,
input [`E203_XLEN-1:0] alu_req_alu_res,
input clk,
input rst_n
);
//从信息总线中提取出相关信息
wire op2imm = alu_i_info [`E203_DECINFO_ALU_OP2IMM ]; //本指令的第二个源操作数是否使用立即数
wire op1pc = alu_i_info [`E203_DECINFO_ALU_OP1PC ]; //本指令的第一个操作数是否使用PC
assign alu_req_alu_op1 = op1pc ? alu_i_pc : alu_i_rs1; //将第一个源操作数(PC或者寄存器源操作数)发送给数据通路
assign alu_req_alu_op2 = op2imm ? alu_i_imm : alu_i_rs2; //将第二个源操作数(立即数或者寄存器操作数)发送给数据通路
wire nop = alu_i_info [`E203_DECINFO_ALU_NOP ] ;
wire ecall = alu_i_info [`E203_DECINFO_ALU_ECAL ];
wire ebreak = alu_i_info [`E203_DECINFO_ALU_EBRK ];
wire wfi = alu_i_info [`E203_DECINFO_ALU_WFI ];
//根据指令类型,产生相应的操作类型,并将其发送给运算数据通路
// The NOP is encoded as ADDI, so need to uncheck it
assign alu_req_alu_add = alu_i_info [`E203_DECINFO_ALU_ADD ] & (~nop);
assign alu_req_alu_sub = alu_i_info [`E203_DECINFO_ALU_SUB ];
assign alu_req_alu_xor = alu_i_info [`E203_DECINFO_ALU_XOR ];
assign alu_req_alu_sll = alu_i_info [`E203_DECINFO_ALU_SLL ];
assign alu_req_alu_srl = alu_i_info [`E203_DECINFO_ALU_SRL ];
assign alu_req_alu_sra = alu_i_info [`E203_DECINFO_ALU_SRA ];
assign alu_req_alu_or = alu_i_info [`E203_DECINFO_ALU_OR ];
assign alu_req_alu_and = alu_i_info [`E203_DECINFO_ALU_AND ];
assign alu_req_alu_slt = alu_i_info [`E203_DECINFO_ALU_SLT ];
assign alu_req_alu_sltu = alu_i_info [`E203_DECINFO_ALU_SLTU];
assign alu_req_alu_lui = alu_i_info [`E203_DECINFO_ALU_LUI ];
assign alu_o_valid = alu_i_valid;
assign alu_i_ready = alu_o_ready;
assign alu_o_wbck_wdat = alu_req_alu_res;
assign alu_o_cmt_ecall = ecall;
assign alu_o_cmt_ebreak = ebreak;
assign alu_o_cmt_wfi = wfi;
//将数据通路的运算结果取回
// The exception or error result cannot write-back
assign alu_o_wbck_err = alu_o_cmt_ecall | alu_o_cmt_ebreak | alu_o_cmt_wfi;
endmodule