Browse Source

rng: better LSFR handling

Slightly saner handling of the LSFR: use the LSBs as the output bits,
and, for the (undesirable) case of width > poly_width, don't erase
the MSBs by xoring with itself, i.e. make the x^poly_width polynomial
term implicit.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
H. Peter Anvin 3 years ago
parent
commit
da417c5ed7

BIN
fpga/output_files/max80.jbc


BIN
fpga/output_files/max80.jic


BIN
fpga/output_files/max80.pof


BIN
fpga/output_files/max80.sof


+ 5 - 4
fpga/rng.sv

@@ -47,9 +47,10 @@ module rng
    // LFSR randomness accumulator
 
    // See http://users.ece.cmu.edu/~koopman/crc/crc36.html for
-   // choice of polynomial.
+   // choice of polynomial. The x^poly_width term in the polynomial
+   // is implicit.
    localparam poly_width = 33;
-   localparam [poly_width:0] poly = 34'h2_0000_009d;
+   localparam [poly_width-1:0] poly = 33'h0_0000_009d;
 
    localparam lsfr_max = width > poly_width ? width-1 : poly_width-1;
 
@@ -57,7 +58,7 @@ module rng
 
    always @(posedge sys_clk)
      lsfr <= {lsfr[lsfr_max-1:0], ^sclocks} ^
-	     (lsfr[lsfr_max-1] ? poly : {poly_width{1'b0}});
+	     {{(lsfr_max+1){lsfr[poly_width-1]}} & poly};
 
-   assign q = lsfr[lsfr_max:lsfr_max-width+1];
+   assign q = lsfr[width-1:0];
 endmodule // rng