当前位置: 首页 > news >正文

单周期Risc-V指令拆分与datapath绘制

功能性单周期Risc-V 处理器设计

目标:
对照risc-v手册,实现并调试自研单、多周期处理器

本次实验要实现下面指令:
在这里插入图片描述

单周期实验目标模块

注意
Risc-V的指令构成与MIPS指令并不一样:
I-Type 指令:
在这里插入图片描述

根据这个表来扩展立即数
在这里插入图片描述

查看文献总结37条指令执行公式:

  • 通过I-type格式的特殊化来实现常数位移操作(Shifts by a constant)。
    • rs1 是被操作数,imm 是位移量,shift mount 在 imm 的低 5 位中。
    • The right shift type is encoded in a high bit of the I-immediate.
    • 0 表示逻辑右移(逻辑右移是在高位补 0),1 表示算术右移(算术右移是在高位补符号位)。

I-type 指令执行公式:

  1. ADDI : rd = rs1 + imm (sign_extend);
  2. SLTI :rd = rs1 < imm (sign_extend)? 1 : 0;
  3. SLTIU: rd = rs1 < imm (unsign_extend)? 1 : 0;
  4. ANDI : rd = rs1 & imm (sign_extend);
  5. ORI : rd = rs1 | imm (sign_extend);
  6. XORI : rd = rs1 ^ imm (sign_extend);(rs1 ^ -1 会得到 ~rs1)
  7. SLLI : rd = rs1 << imm[4:0] (sign_extend);
  8. SRLI : rd = rs1 >> imm[4:0] (sign_extend);

right shift type is encoded in the high bit of the I-immediate.

  1. SRAI : rd = rs1 >>> imm[4:0] (sign_extend);

the original sign bit is copied into the vacated upper bits

U-type 指令执行公式:
10. LUI : rd = imm[31:12] << 12 (sign_extend);

LUI places the U-immediate value in the top 20 bits of the destination register rd, filling in the lowest 12 bits with zeros.

  1. AUIPC : rd = imm + PC (sign_extend);
    在这里插入图片描述

R-type : rd = rs1 op rs2 (sign_extend);

All operations read the rs1 and rs2 registers as source operands and write the result into register rd.The funct7 and funct3 fields select thetype of operation.

  1. ADD: rd = rs1 + rs2 (sign_extend);
  2. SUB: rd = rs1 - rs2 (sign_extend);
  3. SLT: rd = rs1 < rs2 (sign_extend)? 1 : 0;
  4. SLTU : rd = rs1 < rs2 (unsign_extend)? 1 : 0;
  5. AND: rd = rs1 & rs2 (sign_extend);
  6. OR: rd = rs1 | rs2 (sign_extend);
  7. XOR: rd = rs1 ^ rs2 (sign_extend);
  8. SLL: rd = rs1 << rs2[4:0] (sign_extend);
  9. SRL: rd = rs1 >> rs2[4:0] (sign_extend);
  10. SRA: rd = rs1 >>> rs2[4:0] (sign_extend);

SLL, SRL, and SRA perform logical left, logical right, and arithmetic right shifts on the value in register rs1 by the shift amount held in the lower 5 bits of register rs2.
J-type 指令执行公式:

  1. JAL : rd = PC + 4; Target PC = imm + PC (sign_extend);

通过 immimmimm 扩展到 32 位,然后左移 1 位,与当前 PCPCPC 相加得到下一个 PCPCPC,就是目标跳转地址。
然后当前 PC+4PC+4PC+4 存储在 rdrdrd 寄存器中。

  1. JALR : rd = PC + 4; PC = (rs1 + imm)&~1 (sign_extend); I-type Instruction 间接跳转指令

B-type 指令执行公式(与 Zero 相关 ):
24. BEQ : if (rs1 == rs2) then PC = PC + imm else PC = PC + 4 (sign_extend and unsigned);
25. BNE : if (rs1 != rs2) then PC = PC + imm else PC = PC + 4 (sign and unsign_extend);
26. BLT : if (rs1 < rs2) then PC = PC + imm else PC = PC + 4 (sign_extend);
27. BGE : if (rs1 >= rs2) then PC = PC + imm else PC = PC + 4 (sign_extend;
28. BLTU : if (rs1 < rs2) then PC = PC + imm else PC = PC + 4 (unsign_extend);
29. BGEU : if (rs1 >= rs2) then PC = PC + imm else PC = PC + 4 (unsign_extend);

Note, BGT, BGTU, BLE, and BLEU can be synthesized by reversing the operands to BLT, BLTU, BGE, and BGEU, respectively.

Load and Store Instructions

Load and store instructions transfer a value between the registers and memory.
Loads are encoded in the I-type format and stores are S-type.
Loads copy a value from memory to register rd. Stores copy the value in register rs2 to memory.

Effective Address=rs1+SignExtend(12-bit offset)\text{Effective Address} = rs1 + \text{SignExtend}(\text{12-bit offset})Effective Address=rs1+SignExtend(12-bit offset)

  1. LW: rd = mem[rs1 + imm] ; 数据无需扩展
  2. LH: rd = mem[rs1 + imm] ; 数据符号扩展到32位
  3. LB: rd = mem[rs1 + imm] ; 符号扩展到32位
  4. LHU: rd = mem[rs1 + imm] ; 数据零扩展到32位
  5. LBU: rd = mem[rs1 + imm] ; 数据零扩展到32位
  6. SW: mem[rs1 + imm] = rs2 ; 数据无需扩展
  7. SH: mem[rs1 + imm] = rs2[15:0];
  8. SB: mem[rs1 + imm] = rs2[7:0] ;

simple-cpu 流程图
在这里插入图片描述

很早就绘制好了这个datapath,现在再复盘发现还是要花点时间的,所以按照指令绘制datapath会提高写verilog代码的效率,如果只看图会乱。研究过指令后再看图会好一点。

http://www.dtcms.com/a/609207.html

相关文章:

  • Java+EasyExcel 打造学习平台视频学习时长统计系统
  • 【PHP】使用buildsql构造子查询
  • 防火墙主要有哪些类型?如何保护网络安全?
  • 在线商城网站制作如东住房和城乡建设局网站
  • Java 与 PHP 开发核心良好习惯笔记(含通用+语言特有)
  • AI 电影制作迈入新阶段:谷歌云Veo 3.1模型发布,实现音频全覆盖与精细化创意剪辑
  • C++函数式策略模式中配置修改
  • [MCP][]快速入门MCP开发
  • 为食堂写个网站建设免费毕业设计的网站建设
  • 云原生数据平台(cloudeon)--核心服务组件扩展
  • 字典或者列表常用方法介绍
  • 计算机网络中的地址体系全解析(包含 A/B/C 类地址 + 私有地址 + CIDR)
  • SpringBoot教程(三十四)| SpringBoot集成本地缓存Caffeine
  • 专业摄影网站推荐专业做卖菜的网站
  • Hadess V1.2.5版本发布,新增推送规则、制品扫描等,有效保障制品质量与安全
  • 华清远见25072班单片机高级学习day1
  • Apache Flink运行环境搭建
  • Node.js(v16.13.2版本)安装及环境配置教程
  • Flutter 每日库: device_info_plus获取设备详细信息
  • 小马网站建设网站备案好
  • 做某网站的设计与实现网页设计代码案例
  • 生产级 Rust Web 应用架构:使用 Axum 实现模块化设计与健壮的错误处理
  • 大模型三阶段训练:预训练、SFT、RLHF解决的核心问题
  • 记/基准] RELIABLE AND DIVERSE EVALUATION OF LLM MEDICAL KNOWLEDGE MASTERY
  • TensorFlow深度学习实战(9)——卷积神经网络应用
  • LeetCode 分类刷题:203. 移除链表元素
  • 【Qt开发】Qt窗口(一) -> 菜单栏
  • Python的json模块和jsonpath模块
  • Crawl4ai 框架的学习与使用
  • hadoop节点扩容和缩容操作流程