mirror of
https://github.com/ljgibbslf/SM3_core.git
synced 2024-08-18 19:54:12 +08:00
fix expnd bug with 64bit
This commit is contained in:
parent
29c1ee24e5
commit
777b545c58
@ -342,11 +342,20 @@ always @(posedge clk or negedge rst_n) begin
|
||||
end
|
||||
`ifdef SM3_EXPND_PRE_LOAD_REG
|
||||
else if(word_buff_rpd_shft_ena)begin : buff_rpd_shift //快速移位阶段
|
||||
word_buff[15] <= pad_inpt_d_i;
|
||||
word_buff[14] <= word_buff_nb_pre[3];
|
||||
word_buff[13] <= word_buff_nb_pre[2];
|
||||
word_buff[12] <= word_buff_nb_pre[1];
|
||||
word_buff[11] <= word_buff_nb_pre[0];
|
||||
`ifdef SM3_INPT_DW_32
|
||||
word_buff[15] <= pad_inpt_d_i;
|
||||
word_buff[14] <= word_buff_nb_pre[3];
|
||||
word_buff[13] <= word_buff_nb_pre[2];
|
||||
word_buff[12] <= word_buff_nb_pre[1];
|
||||
word_buff[11] <= word_buff_nb_pre[0];
|
||||
`elsif SM3_INPT_DW_64
|
||||
{word_buff[14],word_buff[15]} <= pad_inpt_d_i;
|
||||
word_buff[13] <= word_buff_nb_pre[2];
|
||||
word_buff[12] <= word_buff_nb_pre[3];
|
||||
word_buff[11] <= word_buff_nb_pre[0];
|
||||
word_buff[10] <= word_buff_nb_pre[1];
|
||||
`endif
|
||||
|
||||
end
|
||||
`endif
|
||||
end
|
||||
@ -372,10 +381,18 @@ assign word_buff_shft_ena = (state == IDLE && pad_inpt_v
|
||||
end
|
||||
else if(word_buff_nb_pre_shft_ena)begin : pre_buff_shift // wnb0 <- wnb1....wnb3 <- input
|
||||
integer i;
|
||||
for ( i = PRE_BUFF_N - 1 ; i > 0 ; i = i - 1) begin
|
||||
word_buff_nb_pre[i-1] <= word_buff_nb_pre[i];
|
||||
end
|
||||
word_buff_nb_pre[PRE_BUFF_N - 1] <= pad_inpt_d_i;
|
||||
`ifdef SM3_INPT_DW_32
|
||||
for ( i = PRE_BUFF_N - 1 ; i > 0 ; i = i - 1) begin
|
||||
word_buff_nb_pre[i-1] <= word_buff_nb_pre[i];
|
||||
end
|
||||
word_buff_nb_pre[PRE_BUFF_N - 1] <= pad_inpt_d_i;
|
||||
`elsif SM3_INPT_DW_64
|
||||
for ( i = (PRE_BUFF_N / INPT_WORD_NUM)- 1 ; i > 0 ; i = i - 1) begin
|
||||
word_buff_nb_pre[2*i-1] <= word_buff_nb_pre[2*i+1];
|
||||
word_buff_nb_pre[2*(i-1)] <= word_buff_nb_pre[2*i];
|
||||
end
|
||||
{word_buff_nb_pre[PRE_BUFF_N - 1], word_buff_nb_pre[PRE_BUFF_N - 2]} <= pad_inpt_d_i;
|
||||
`endif
|
||||
end
|
||||
end
|
||||
|
||||
@ -410,7 +427,7 @@ assign pad_inpt_rdy_o = pad_inpt_d_inpt_rdy; //反
|
||||
`ifdef SM3_INPT_DW_32
|
||||
$display("LOG: EXPND WORD %8h | %8h", expnd_otpt_wj_o[31:0],expnd_otpt_wjj_o[31:0],);
|
||||
`elsif SM3_INPT_DW_64
|
||||
$display("LOG: EXPND WORD wj[63:22]:%8h | wj[31:0]:%8h | wjj[63:22]:%8h | wjj[31:0]:%8h"
|
||||
$display("LOG: EXPND WORD wj[63:32]:%8h | wj[31:0]:%8h | wjj[63:32]:%8h | wjj[31:0]:%8h"
|
||||
,expnd_otpt_wj_o[63:32]
|
||||
,expnd_otpt_wj_o[31:0]
|
||||
,expnd_otpt_wjj_o[63:32]
|
||||
|
@ -12,7 +12,8 @@
|
||||
// inc/sm3_cfg.v
|
||||
// Revision:
|
||||
// Revision 0.01 - File Created
|
||||
// Revision 0.02 - Pass two SM3 example
|
||||
// Revision 0.02 - Pass two SM3 example (32bit)
|
||||
// Revision 0.03 - Pass two SM3 example (64bit)
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
module tb_sm3_cmprss_top (
|
||||
);
|
||||
@ -73,7 +74,7 @@ initial begin
|
||||
// sm3_inpt_byte_num = $urandom % (64*100) + 1;
|
||||
|
||||
@(posedge sm3if.clk);
|
||||
task_pad_inpt_gntr_exmpl1();
|
||||
task_pad_inpt_gntr_exmpl1_64();
|
||||
@(posedge sm3if.clk);
|
||||
end
|
||||
|
||||
@ -122,7 +123,7 @@ task automatic task_pad_inpt_gntr(
|
||||
endtask //automatic
|
||||
|
||||
//产生填充模块输入,采用示例输入 'abc'
|
||||
task automatic task_pad_inpt_gntr_exmpl0();
|
||||
task automatic task_pad_inpt_gntr_exmpl0_32();
|
||||
|
||||
|
||||
sm3if.msg_inpt_vld = 1'b1;
|
||||
@ -136,8 +137,23 @@ task automatic task_pad_inpt_gntr_exmpl0();
|
||||
|
||||
endtask //automatic
|
||||
|
||||
//产生填充模块输入,采用示例输入 'abc'
|
||||
task automatic task_pad_inpt_gntr_exmpl0_64();
|
||||
|
||||
|
||||
sm3if.msg_inpt_vld = 1'b1;
|
||||
sm3if.msg_inpt_lst = 1'b1;
|
||||
sm3if.msg_inpt_d = 64'h6162_6300_0000_0000;
|
||||
sm3if.msg_inpt_vld_byte = 8'b1110_0000;
|
||||
@(posedge sm3if.clk);
|
||||
sm3if.msg_inpt_vld = 1'b0;
|
||||
sm3if.msg_inpt_lst = 1'b0;
|
||||
sm3if.msg_inpt_d = DATA_INIT_PTTRN;
|
||||
|
||||
endtask //automatic
|
||||
|
||||
//产生填充模块输入,采用示例输入 512bit 重复的 'abcd'
|
||||
task automatic task_pad_inpt_gntr_exmpl1();
|
||||
task automatic task_pad_inpt_gntr_exmpl1_32();
|
||||
|
||||
sm3if.msg_inpt_vld = 1'b1;
|
||||
sm3if.msg_inpt_d = 32'h6162_6364;
|
||||
@ -153,94 +169,22 @@ task automatic task_pad_inpt_gntr_exmpl1();
|
||||
|
||||
endtask //automatic
|
||||
|
||||
//产生用于比较的图样,最后 512bit 输出
|
||||
function automatic void golden_pttrn_gntr(
|
||||
input bit [60:0] byte_num
|
||||
);
|
||||
|
||||
int unsigned lst_blk_byte_num;
|
||||
int unsigned lst_blk_word_num;
|
||||
int unsigned unalign_byte_num;
|
||||
int unsigned lst_blk_pad_00_byte_num;//最后一块中的填充数量
|
||||
int unsigned lst_blk_pad_10_byte_num;
|
||||
longint unsigned bit_num;
|
||||
|
||||
bit [31:0] lst_inpt_data;
|
||||
//产生填充模块输入,采用示例输入 512bit 重复的 'abcd'
|
||||
task automatic task_pad_inpt_gntr_exmpl1_64();
|
||||
|
||||
bit flg_new_pad_blk;
|
||||
|
||||
// bit [`INPT_BYTE_DW1:0] vld_byte_mask;
|
||||
unalign_byte_num = byte_num[1:0];
|
||||
|
||||
lst_blk_byte_num = byte_num[5:0];
|
||||
lst_blk_byte_num = lst_blk_byte_num == 0 ? (byte_num == 0 ? 0 : 64): lst_blk_byte_num;
|
||||
|
||||
//最后一数据块中字的数量
|
||||
bit_num = byte_num * 8;
|
||||
lst_blk_word_num = unalign_byte_num == 0 ? lst_blk_byte_num[31:2] : lst_blk_byte_num[31:2] + 1'b1;
|
||||
|
||||
|
||||
//计算填充的字节数量
|
||||
if(unalign_byte_num == 0)begin //对齐
|
||||
lst_blk_pad_10_byte_num = 1;
|
||||
if(lst_blk_word_num < 14) begin
|
||||
lst_blk_pad_00_byte_num = 16 - 2 - lst_blk_pad_10_byte_num - lst_blk_word_num;
|
||||
flg_new_pad_blk = 0;
|
||||
end else if(lst_blk_word_num == 16)begin//lst_blk_word_num == 16
|
||||
lst_blk_pad_00_byte_num = 13;
|
||||
flg_new_pad_blk = 1;
|
||||
end else begin//lst_blk_word_num == 14/15
|
||||
lst_blk_pad_00_byte_num = 14;
|
||||
flg_new_pad_blk = 1;
|
||||
end
|
||||
end else begin // 非对齐
|
||||
lst_blk_pad_10_byte_num = 0;
|
||||
if(lst_blk_word_num < 15) begin
|
||||
flg_new_pad_blk = 0;
|
||||
lst_blk_pad_00_byte_num = 16 - 2 - lst_blk_word_num;
|
||||
end else begin//lst_blk_word_num == 15/16
|
||||
flg_new_pad_blk = 1;
|
||||
lst_blk_pad_00_byte_num = 14;
|
||||
end
|
||||
sm3if.msg_inpt_vld = 1'b1;
|
||||
sm3if.msg_inpt_d = 64'h6162_6364_6162_6364;
|
||||
sm3if.msg_inpt_vld_byte = 8'b1111_1111;
|
||||
repeat(7)begin
|
||||
@(posedge sm3if.clk);
|
||||
end
|
||||
|
||||
//最后一个周期的数据
|
||||
lst_inpt_data = unalign_byte_num == 2'd0 ? {DATA_INIT_PTTRN}
|
||||
: unalign_byte_num == 2'd1 ? {DATA_INIT_PTTRN[31-: 8],1'b1, 23'd0}
|
||||
: unalign_byte_num == 2'd2 ? {DATA_INIT_PTTRN[31-:16],1'b1, 15'd0}
|
||||
: unalign_byte_num == 2'd3 ? {DATA_INIT_PTTRN[31-:24],1'b1, 7'd0}
|
||||
: DATA_INIT_PTTRN;
|
||||
|
||||
|
||||
//填充pattern
|
||||
foreach(gldn_pttrn[i])
|
||||
if(flg_new_pad_blk)begin//增加填充块的情况
|
||||
if (i == 0 && lst_blk_pad_00_byte_num == 13)
|
||||
gldn_pttrn[i] = 32'h8000_0000;
|
||||
else if (i == 14)
|
||||
gldn_pttrn[i] = bit_num[63-:32];
|
||||
else if (i == 15)
|
||||
gldn_pttrn[i] = bit_num[31-:32];
|
||||
else
|
||||
gldn_pttrn[i] = 32'h0000_0000;
|
||||
end else begin//在原有最后一块的基础上填充
|
||||
if(i < lst_blk_word_num - 1)
|
||||
gldn_pttrn[i] = DATA_INIT_PTTRN[31:0];
|
||||
else if (i < lst_blk_word_num)
|
||||
gldn_pttrn[i] = lst_inpt_data;
|
||||
else if (i < lst_blk_word_num + lst_blk_pad_10_byte_num)
|
||||
gldn_pttrn[i] = 32'h8000_0000;
|
||||
else if (i < lst_blk_word_num + lst_blk_pad_10_byte_num + lst_blk_pad_00_byte_num)
|
||||
gldn_pttrn[i] = 32'h0000_0000;
|
||||
else if (i == 14)
|
||||
gldn_pttrn[i] = bit_num[63-:32];
|
||||
else if (i == 15)
|
||||
gldn_pttrn[i] = bit_num[31-:32];
|
||||
else
|
||||
gldn_pttrn[i] = 32'hFFFF_FFFF;
|
||||
end
|
||||
|
||||
endfunction
|
||||
sm3if.msg_inpt_lst = 1'b1;
|
||||
@(posedge sm3if.clk);
|
||||
sm3if.msg_inpt_vld = 1'b0;
|
||||
sm3if.msg_inpt_lst = 1'b0;
|
||||
sm3if.msg_inpt_d = DATA_INIT_PTTRN;
|
||||
|
||||
endtask //automatic
|
||||
|
||||
//32bit 生成最后一个周期数据
|
||||
`ifdef SM3_INPT_DW_32
|
||||
|
Loading…
x
Reference in New Issue
Block a user