hdlbits Cs450/gshare

Cs450/counter 2bc

根据state大小判断拿的程度。

module top_module(
    input clk,
    input areset,
    input train_valid,
    input train_taken,
    output [1:0] state
);
//00没拿,01weak没拿,10weak拿了,11拿了
    always@(posedge clk or posedge areset)
        if(areset)
            state<=2'b01;
    else if(train_valid & train_taken) //拿了+1
        if(state==2'd3)
            state<=state;
        else
        	state<=state+2'b1;
    else if(train_valid & ~train_taken)//没拿-1
        if(state==0)
        	state<=state;
        else
            state<=state-2'b1;
        
endmodule

Cs450/history shift

判断是否拿预测值。

module top_module(
    input clk,
    input areset,

    input predict_valid,
    input predict_taken,
    output [31:0] predict_history,

    input train_mispredicted,
    input train_taken,
    input [31:0] train_history
);

    always@(posedge clk or posedge areset)
        if(areset)
            predict_history<=0;
    	else if(train_mispredicted)
            predict_history<={train_history[30:0],train_taken}; //预测错误,实际输入
        else if(predict_valid)
        	predict_history<={predict_history[30:0],predict_taken};//预测正确,用预测值

endmodule

Cs450/gshare

train_taken决定PTH里的值加或者减。//2‘b11 taken 2‘b10 weak-taken 2‘b01 weak-not-taken 2‘b00 not-taken;
train_valid决定用train_history[5:0],train_taken;
predict_valid决定用predict_history[5:0],PHT高位;

PTH的输入输出

module top_module(
    input clk,
    input areset,

    input  predict_valid,
    input  [6:0] predict_pc,
    output predict_taken,
    output [6:0] predict_history,

    input train_valid,
    input train_taken,
    input train_mispredicted,
    input [6:0] train_history,
    input [6:0] train_pc
);
    //11 taken 10 weak-taken 01 weak-not-taken 00 not-taken
    reg pht1[127:0];//taken
    reg pht0[127:0];//w-taken
    wire [6:0]ad,ad2;

 	assign ad=train_history^train_pc;
 	assign ad2=predict_history^predict_pc;
    integer i;
    always@(posedge clk or posedge areset)
        if(areset)
            for (i=0; i<128; i=i+1) begin 
                pht1[i] <= 1'b0; 
                pht0[i] <= 1'b1; 
            end
    	else if(train_valid & train_taken)begin
        	if({pht1[ad],pht0[ad]}==2'b11)
            	{pht1[ad],pht0[ad]}<=2'b11;
        	else
        		{pht1[ad],pht0[ad]}<={pht1[ad],pht0[ad]}+2'b1;  //拿了很多次
   	 	end
    	else if(train_valid & ~train_taken)begin
        	if({pht1[ad],pht0[ad]}==0)
        		{pht1[ad],pht0[ad]}<=0;
        	else
            	{pht1[ad],pht0[ad]}<={pht1[ad],pht0[ad]}-2'b1;  //拿了次数减少
    	end
     	
    assign predict_taken=pht1[ad2];  //根据pht1[], hash概率taken
    always@(posedge clk or posedge areset)
        if(areset)
            predict_history<=7'b0;
    	else if(train_valid&train_mispredicted)
            predict_history<={train_history[5:0],train_taken};//用计算结果
        else if(predict_valid)
            predict_history<={predict_history[5:0],predict_taken};//用预测结果
    	
endmodule

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值