Advertisement
petrdynin

Untitled

Dec 5th, 2023 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   module riscv_imm_gen (
  2.     input  logic        clk,
  3.     input  logic        aresetn,
  4.     input  logic [31:0] instr,
  5.     output logic [31:0] i_imm,
  6.     output logic [31:0] s_imm,
  7.     output logic [31:0] b_imm,
  8.     output logic [31:0] u_imm,
  9.     output logic [31:0] j_imm
  10. );
  11.  
  12.     logic [31:0] i_imm_w;
  13.     logic [31:0] s_imm_w;
  14.     logic [31:0] b_imm_w;
  15.     logic [31:0] u_imm_w;
  16.     logic [31:0] j_imm_w;
  17.  
  18.     //assign i_imm_w = { { ( 20 ){ instr[31] } }, instr[30:20] };
  19.     //assign s_imm_w = { { ( 20 ){ instr[31] } }, instr[7], instr[30:25], instr[11:8],  1'b0 };
  20.     //assign b_imm_w = { { ( 21 ){ instr[31] } }, instr[30:25], instr[11:8],  instr[7] };
  21.     //assign u_imm_w = { instr[31:12], { ( 11 ){ 1'b0 } } };
  22.     //assign j_imm_w = { { ( 20 ){ instr[31] } }, instr[19:12], instr[20], instr[24:21], 1'b0 };
  23.  
  24.     assign i_imm_w = { { ( 21 ){ instr[31] } }, instr[30:20] };
  25.     assign b_imm_w = { { ( 20 ){ instr[31] } }, instr[7], instr[30:25], instr[11:8],  1'b0 };
  26.     assign s_imm_w = { { ( 21 ){ instr[31] } }, instr[30:25], instr[11:8],  instr[7] };
  27.     assign u_imm_w = { instr[31:12], { ( 12 ){ 1'b0 } } };
  28.     assign j_imm_w = { { ( 12 ){ instr[31] } }, instr[19:12],  instr[20], instr[30:25], instr[24:21], 1'b0 };
  29.  
  30.     logic [31:0] i_imm_ff;
  31.     logic [31:0] s_imm_ff;
  32.     logic [31:0] b_imm_ff;
  33.     logic [31:0] u_imm_ff;
  34.     logic [31:0] j_imm_ff;
  35.  
  36.     always_ff @( posedge clk or negedge aresetn ) begin
  37.         if(!aresetn) begin
  38.             i_imm_ff <= 32'b0;
  39.             s_imm_ff <= 32'b0;
  40.             b_imm_ff <= 32'b0;
  41.             u_imm_ff <= 32'b0;
  42.             j_imm_ff <= 32'b0;
  43.         end
  44.         else begin
  45.             i_imm_ff <= i_imm_w;
  46.             s_imm_ff <= s_imm_w;
  47.             b_imm_ff <= b_imm_w;
  48.             u_imm_ff <= u_imm_w;
  49.             j_imm_ff <= j_imm_w;
  50.         end
  51.     end
  52.  
  53.     assign i_imm = i_imm_ff;
  54.     assign s_imm = s_imm_ff;
  55.     assign b_imm = b_imm_ff;
  56.     assign u_imm = u_imm_ff;
  57.     assign j_imm = j_imm_ff;
  58.  
  59. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement