实验4 单功能流水线调度机构模拟
一、实验目的
结合数据结构的相关知识,编写流水线调度模拟程序。
二、实验内容
本实验选取四段单功能流水线浮点加作为例子,通过模拟单功能流水线调度过程,掌握流水线技术,学会计算流水线的吞吐率、加速比、效率。
三、实验代码
#include <iostream>
#include <string>
using namespace std;
const int SPACE = 4;// 功能部件数目
const int NUM = 5;// 需要流水处理的浮点加指令数目
const int TIME = NUM+SPACE-1;// 存储不同时间段各个功能部件内指令值
// ED:求阶差 EA:对阶MA:尾数加 NL:规格化
const string INSTRUCTIONS[] = {"NL", "MA", "EA", "ED"};
int ts[SPACE][TIME] = {0};// 初始化时空图
void print();// 输出时空图
void pipeline(int ts[SPACE][TIME]);// 流水线中指令状态转换算法
int main () {
cout << "Pipeline begins" << endl << endl;
pipeline(ts);
print();
cout << endl << "Pipeline ends" << endl << endl;
cout << "The Through Put of the pipeline is " << (double)NUM/TIME << "t" << endl;
cout << "The Speedup of the pipeline is " << ((double)NUM*SPACE)/TIME << endl;
cout << "The Efficiency of the pipeline is " << ((double)NUM*SPACE)/(TIME*SPACE) << endl;
return 0;
}
void print() {
for (int i = 0; i < TIME; ++i) {
cout << "After time slice "<< i+1 << endl;
for (int j = 0 ; j < SPACE; ++j) {
if (i < NUM && ts[j][i] == 0) {
cout << endl;
} else {
for (int k = 0; k < i+1; ++k) {
if (ts[j][k] != 0) {
cout << INSTRUCTIONS[j]<<ts[j][k];
}
cout << "\t";
}
cout << endl;
}
}
}
}
void pipeline(int ts[SPACE][TIME]) {
int tempSpace = 0;// 记录处理的指令号
int tempTime = 0;// 记录时间轴的变化
for (int s = SPACE-1; s >= 0; s--) {
tempSpace = 1;
for (int t = tempTime; t < TIME; t++) {
ts[s][t] = tempSpace++;
}
tempTime++;
}
}
分类:
大学实验
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!