The preferred solution is to have LFSR2
reset value be a constant. A parameter could be an expression of constants/parameters or a function with constants/parameters as inputs. It might be a bit of effort to change you code but this is what needs to be done to get "optimal implementation in terms of area, power and performance".
parameter LFSR2_INIT = initial_LFSR2_func(RNTI,NCELL_ID,nss,nf);
always @(posedge scr_clk or posedge scr_rst) begin
if (scr_rst) begin
LFSR2 <= LFSR2_INIT;
end
else begin
LFSR2 <= next_LFSR2;
end
end
If you absolutely must have your reset value determined by combinational logic, then there is a last resort option. It is "sub-optimal implementation in terms of area, power and performance" compared to the parameter solution, but probably will be better than what you currently have. Be warned, the more complex the logic on init
, the more "sub-optimal" it will be.
This likely will not work if you are targeting for FPGA; as they tend to have limited support for flops with asynchronous set/reset. You did tag the question with xilinx which is for FPGAs. You really need to figure out why you need asynchronous set/reset at all. Try to get your code to work with only synchronous flops (no async set/reset). If you need async set/reset, then spend the extra effort to figure out how to make parameter approach work.
Because this is a last resort option, it will not be displayed by default.
Uniquify each flop of with individual async set and reset signals.
wire [LFSR2_WIDTH-1:0] lfsr2_set = {LFSR2_WIDTH{src_rst}} & init;
wire [LFSR2_WIDTH-1:0] lfsr2_rst = {LFSR2_WIDTH{src_rst}} & ~init;
genvar gidx;
generate
for(gidx=0; gidx<LFSR2_WIDTH; gidx=gidx+1) begin : LFSR2_genblk
always @(posedge src_clk, posedge lfsr2_rst[gidx], posedge lfsr2_set[gidx]) begin
if (lfsr2_rst[gidx]) begin
LFSR2[gidx] <= 1'b0;
end
else if (lfsr2_set[gidx]) begin
LFSR2[gidx] <= 1'b1;
end
else begin
LFSR2[gidx] <= next_LFSR2[gidx];
end
end
end
endgenerate
The logic will add area. The extra routing and time to stabilize with impact performance. Stabilize time will also impact power. Power and performance will get worse if init
toggles a with intermediate values while src_rst
is high.