Tb/clock
这题要求给dut模块一个时钟 。
Tb/tb1
产生指定的波形 ,使用延时语句给信号赋值即可 。
module top_module ( output reg A, output reg B );//
// generate input patterns here
initial begin
A=0;
B=0;
#10 A=1;
#5 B=1;
#5 A=0;
#20 B=0;
end
endmodule
Tb/and
题目要求对一个与门进行测试 ,要求产生波形图中的激励向量 。
module top_module();
reg [1:0]in;
wire out;
initial begin
in = 2b00;
#10 in = 2b01;
#10 in = 2b10;
#10 in = 2b11;
end
andgate u_and(in,out);
endmodule
Tb/tb2
同样是写一个testbench ,但是比上面略复杂一点 。
module top_module();
reg clk;
reg in;
reg [2:0]s;
wire out;
initial begin
clk=0;
in=0;
s=2;
#10 s=6;
#10 in=1;s=2;
#10 in=0;s=7;
#10 in=1;s=0;
#30 in=0;
end
always #5 clk=~clk;
q7 u_q7(clk,in,s,out);
endmodule
Tb/tff
要求验证一个T触发器 ,T触发器在输入t为1时输出不断地发展 。
module top_module ();
reg clk;
reg reset;
reg t;
wire q;
always #5 clk=~clk;
initial begin
clk=0;
reset=1;
t=0;
#10 reset=0;t=1;
end
tff u_t(clk,reset,t,q);
endmodule
Cs450/timer
load信号为1载入data ,load为0电路为一个倒数器 ,当倒计数为0时tc为1 。
module top_module(
input clk,
input load,
input [9:0] data,
output tc
);
reg [9:0]counter;
always@(posedge clk)
begin
if(load)
counter <= data;
else
counter <= (counter!=0)?(counter - 1b1):0;
end
assign tc=(counter==0);
endmodule
Cs450/counter 2bc
这道题要求实现一个分支预测器 ,没学过计算机体系结构 ,百度了一下 ,分支预测器在分支指令执行结束之前猜测哪一路分支将会被运行 ,以提高处理器的指令流水线的性能 。使用分支预测器的目的 ,在于改善指令管线化的流程 。现代使用指令管线化处理器的性能能够提高 ,分支预测器对于现今的指令流水线微处理器获得高性能是非常关键的技术 。
这里其实也不用对分支预测器特别了解,能按照状态转换图写出代码就行了 。
懒得写两个always了 ,直接一个always给实现了 。
module top_module(
input clk,
input areset,
input train_valid,
input train_taken,
output reg[1:0] state
);
parameter SNT=0,WNT=1,WT=2,ST=3;
always@(posedge clk or posedge areset)
begin
if(areset)
state <= WNT;
else if(train_valid)begin
case(state)
SNT:state <= train_taken?WNT:SNT;
WNT:state <= train_taken?WT:SNT;
WT:state <= train_taken?ST:WNT;
ST:state <= train_taken?ST:WT;
endcase
end
end
endmodule
Cs450/history shift
题目很长 ,看了半天也不是特别懂,要写代码的话其实直接看description就行了 。
当predict_valid= 1 ,移入predict_taken到predict_history ,当train_mispredicted= 1则移入train_taken到train_history ,注意misprediction优先级更高 ,所以放在上面的else if中。
module top_module(
input clk,
input areset,
input predict_valid,
input predict_taken,
output reg[31:0] predict_history,
input train_mispredicted,
input train_taken,
input [31:0] train_history
);
always@(posedge clk or posedge areset)
begin
if(areset)
predict_history <= 32d0;
else if(train_mispredicted)begin
predict_history <= {train_history[30:0],train_taken};
end
else if(predict_valid)begin
predict_history <= {predict_history[30:0],predict_taken};
end
end
endmodule
Cs450/gshare
这题是真的彻底看不懂了 ,抄了网上大佬的答案 。链接:http://blog.74ls74.org/2022/03/17/20220317_HDLbits_uwaterloo_cs450/
module top_module(
input clk,
input areset,
input predict_valid,
input [6:0] predict_pc,
output predict_taken,
output reg [6:0] predict_history,
input train_valid,
input train_taken,
input train_mispredicted,
input [6:0] train_history,
input [6:0] train_pc
);
reg [1:0] PHT[127:0];
integer i;
always @(posedge clk, posedge areset) begin
if (areset) begin
predict_history <= 0;
for (i=0; i<128; i=i+1) PHT[i] <= 2b01;
end
else begin
if (train_valid && train_mispredicted)
predict_history <= {train_history[6:0], train_taken};
else if (predict_valid)
predict_history <= {predict_history[6:0], predict_taken};
if (train_valid) begin
if (train_taken)
PHT[train_history ^ train_pc] <= (PHT[train_history ^ train_pc] == 2b11) ? 2b11 : (PHT[train_history ^ train_pc] + 1);
else
PHT[train_history ^ train_pc] <= (PHT[train_history ^ train_pc] == 2b00) ? 2b00 : (PHT[train_history ^ train_pc] - 1);
end
end
end
assign predict_taken = PHT[predict_history ^ predict_pc][1];
endmodule
声明:本站所有文章 ,如无特殊说明或标注 ,均为本站原创发布 。任何个人或组织 ,在未征得本站同意时 ,禁止复制 、盗用 、采集 、发布本站内容到任何网站 、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益 ,可联系我们进行处理 。