I'm trying to find an alternative way to express the following Verilog code. You can use…
- User
I'm trying to find an alternative way to express the following Verilog code. You can use functions or any other method as long as the logic remains the same.
always_comb begin case(R_count[1:0]) 2'b00: begin STROBE = 16'h000F; rdata = {96'b0,axi_r_if.rdata}; end 2'b01: begin STROBE = 16'h00F0; rdata = {64'b0,axi_r_if.rdata,32'b0}; end 2'b10: begin STROBE = 16'h0F00; rdata = {32'b0,axi_r_if.rdata,64'b0}; end 2'b11: begin STROBE = 16'hF000; rdata = {axi_r_if.rdata,96'b0}; end endcase end
- Assistant
You can express the given Verilog
always_combblock using a Verilog function to encapsulate the case statement and reduce redundancy. Here is how you can do it:- Define a function to handle the case statement logic.
- Use this function in the
always_combblock.
function automatic [15:0] get_strobe(input [1:0] R_count); case(R_count) 2'b00: get_strobe = 16'h000F; 2'b01: get_strobe = 16'h00F0; 2'b10: get_strobe = 16'h0F00; 2'b11: get_strobe = 16'hF000; endcase endfunction function automatic [127:0] get_rdata(input [1:0] R_count, input [31:0] axi_rdata); case(R_count) 2'b00: get_rdata = {96'b0, axi_rdata}; 2'b01: get_rdata = {64'b0, axi_rdata, 32'b0}; 2'b10: get_rdata = {32'b0, axi_rdata, 64'b0}; 2'b11: get_rdata = {axi_rdata, 96'b0}; endcase endfunction always_comb begin STROBE = get_strobe(R_count[1:0]); rdata = get_rdata(R_count[1:0], axi_r_if.rdata); endIn this modified version:
- The function generates the value based on the input .
- User
I would like to remove "STROBE" and replace it with a better alternative.
reg [BUF_DW/8-1:0] STROBE; function automatic [15:0] get_strobe(input [1:0] R_count); case(R_count) 2'b00: get_strobe = 16'h000F; 2'b01: get_strobe = 16'h00F0; 2'b10: get_strobe = 16'h0F00; 2'b11: get_strobe = 16'hF000; endcase endfunction
function automatic [127:0] get_rdata(input [1:0] R_count, input [31:0] axi_rdata); case(R_count) 2'b00: get_rdata = {96'b0, axi_rdata}; 2'b01: get_rdata = {64'b0, axi_rdata, 32'b0}; 2'b10: get_rdata = {32'b0, axi_rdata, 64'b0}; 2'b11: get_rdata = {axi_rdata, 96'b0}; endcase endfunction
always_comb begin STROBE = get_strobe(R_count[1:0]); rdata = get_rdata(R_count[1:0], axi_r_if.rdata); end
assign buf_a_wbyteenable_o = STROBE; assign buf_b_wbyteenable_o = STROBE;
- Assistant
To remove the
STROBEregister and directly assign the strobe values tobuf_a_wbyteenable_oandbuf_b_wbyteenable_o, you can modify the code as follows:- Remove the
STROBEregister. - Directly use the
get_strobefunction in the assignments forbuf_a_wbyteenable_oandbuf_b_wbyteenable_o.
Here's the updated code:
function automatic [15:0] get_strobe(input [1:0] R_count); case(R_count) 2'b00: get_strobe = 16'h000F; 2'b01: get_strobe = 16'h00F0; 2'b10: get_strobe = 16'h0F00; 2'b11: get_strobe = 16'hF000; endcase endfunction function automatic [127:0] get_rdata(input [1:0] R_count, input [31:0] axi_rdata); case(R_count) 2'b00: get_rdata = {96'b0, axi_rdata}; 2'b01: get_rdata = {64'b0, axi_rdata, 32'b0}; 2'b10: get_rdata = {32'b0, axi_rdata, 64'b0}; 2'b11: get_rdata = {axi_rdata, 96'b0}; endcase endfunction always_comb begin rdata = get_rdata(R_count[1:0], axi_r_if.rdata); end assign buf_a_wbyteenable_o = get_strobe(R_count[1:0]); assign buf_b_wbyteenable_o = get_strobe(R_count[1:0]); - Remove the
- User
- Assistant