xorshift.sv (638B)
1 // Copyright 2020, Brian Swetland <swetland@frotz.net> 2 // Licensed under the Apache License, Version 2.0. 3 4 `default_nettype none 5 6 module xorshift32 #( 7 parameter INITVAL = 32'hebd5a728 8 ) ( 9 input wire clk, 10 input wire next, 11 input wire reset, 12 output reg [31:0]data = INITVAL 13 ); 14 15 // $ echo -n xorshiftrulz | sha256sum | cut -c 1-8 16 // ebd5a728 17 18 wire [31:0] nxt1 = data ^ { data[18:0], 13'd0 }; 19 wire [31:0] nxt2 = nxt1 ^ { 17'd0, nxt1[31:17] }; 20 wire [31:0] nxt3 = nxt2 ^ { nxt2[26:0], 5'd0 }; 21 22 always_ff @(posedge clk) 23 if (reset) 24 data <= INITVAL; 25 else if (next) 26 data <= nxt3; 27 28 endmodule 29