瀏覽代碼

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 年之前
父節點
當前提交
da417c5ed7
共有 5 個文件被更改,包括 5 次插入4 次删除
  1. 二進制
      fpga/output_files/max80.jbc
  2. 二進制
      fpga/output_files/max80.jic
  3. 二進制
      fpga/output_files/max80.pof
  4. 二進制
      fpga/output_files/max80.sof
  5. 5 4
      fpga/rng.sv

二進制
fpga/output_files/max80.jbc


二進制
fpga/output_files/max80.jic


二進制
fpga/output_files/max80.pof


二進制
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