Search is not available for this dataset
content
stringlengths
0
376M
/* * * Clock, reset generation unit for ML501 board * * Implements clock generation according to design defines * */ ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2009, 2010 Authors and OPENCORES.ORG //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// module clkgen ( // Main clocks in, depending on board sys_clk_in_p, sys_clk_in_n, // Core clock and reset out core_clk_o, core_rst_o, // Asynchronous, active low reset in rst_n_pad_i ); input sys_clk_in_p,sys_clk_in_n; output core_rst_o; output core_clk_o; `ifdef JTAG_DEBUG input tck_pad_i; output dbg_tck_o; `endif // Asynchronous, active low reset (pushbutton, typically) input rst_n_pad_i; // First, deal with the asychronous reset wire async_rst; wire async_rst_n; // Xilinx synthesis tools appear cluey enough to instantiate buffers when and // where they're needed, so we do simple assigns for this tech. assign async_rst_n = rst_n_pad_i; // Everyone likes active-high reset signals... assign async_rst = ~async_rst_n; // // Declare synchronous reset wires here // // An active-low synchronous reset signal (usually a PLL lock signal) wire sync_rst_n; // An active-low synchronous reset from ethernet PLL wire sync_eth_rst_n; `ifdef SYNTHESIS wire sys_clk_in_200; /* DCM0 wires */ wire dcm0_clk0_prebufg, dcm0_clk0; wire dcm0_clkfx_prebufg, dcm0_clkfx; wire dcm0_clkdv_prebufg, dcm0_clkdv; wire dcm0_locked; /* Differential input buffer for 200MHz board clock, generate SE 200MHz */ IBUFGDS_LVPECL_25 sys_clk_in_ibufds ( .O(sys_clk_in_200), .I(sys_clk_in_p), .IB(sys_clk_in_n)); /* DCM providing main system/Wishbone clock */ DCM_BASE dcm0 ( // Outputs .CLK0 (dcm0_clk0_prebufg), .CLK180 (), .CLK270 (), .CLK2X180 (), .CLK2X (), .CLK90 (), .CLKDV (dcm0_clkdv_prebufg), .CLKFX180 (), .CLKFX (dcm0_clkfx_prebufg), .LOCKED (dcm0_locked), // Inputs .CLKFB (dcm0_clk0), .CLKIN (sys_clk_in_200), .RST (1'b0)); // Generate 200 MHz from CLKFX defparam dcm0.CLKFX_MULTIPLY = 3; defparam dcm0.CLKFX_DIVIDE = 4; // Generate 50 MHz from CLKDV defparam dcm0.CLKDV_DIVIDE = 4; BUFG dcm0_clk0_bufg (// Outputs .O (dcm0_clk0), // Inputs .I (dcm0_clk0_prebufg)); BUFG dcm0_clkfx_bufg (// Outputs .O (dcm0_clkfx), // Inputs .I (dcm0_clkfx_prebufg)); BUFG dcm0_clkdv_bufg (// Outputs .O (dcm0_clkdv), // Inputs .I (dcm0_clkdv_prebufg)); assign core_clk_o = dcm0_clkdv; assign sync_rst_n = dcm0_locked; `else assign core_clk_o = sys_clk_in_p; assign sync_rst_n = 1'b1; `endif // // Reset generation // // // Reset generation for wishbone reg [15:0] wb_rst_shr; always @(posedge core_clk_o or posedge async_rst) if (async_rst) wb_rst_shr <= 16'hffff; else wb_rst_shr <= {wb_rst_shr[14:0], ~(sync_rst_n)}; assign core_rst_o = wb_rst_shr[15]; endmodule // clkgen
///////////////////////////////////////////////////////////////////// //// //// //// CRP //// //// DES Crypt Module //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module crp(P, R, K_sub); /* verilator lint_off LITENDIAN */ output [1:32] P; input [1:32] R; input [1:48] K_sub; wire [1:48] E; wire [1:48] X; wire [1:32] S; /* verilator lint_on LITENDIAN */ assign E[1:48] = { R[32], R[1], R[2], R[3], R[4], R[5], R[4], R[5], R[6], R[7], R[8], R[9], R[8], R[9], R[10], R[11], R[12], R[13], R[12], R[13], R[14], R[15], R[16], R[17], R[16], R[17], R[18], R[19], R[20], R[21], R[20], R[21], R[22], R[23], R[24], R[25], R[24], R[25], R[26], R[27], R[28], R[29], R[28], R[29], R[30], R[31], R[32], R[1]}; assign X = E ^ K_sub; sbox1 u0( .addr(X[01:06]), .dout(S[01:04]) ); sbox2 u1( .addr(X[07:12]), .dout(S[05:08]) ); sbox3 u2( .addr(X[13:18]), .dout(S[09:12]) ); sbox4 u3( .addr(X[19:24]), .dout(S[13:16]) ); sbox5 u4( .addr(X[25:30]), .dout(S[17:20]) ); sbox6 u5( .addr(X[31:36]), .dout(S[21:24]) ); sbox7 u6( .addr(X[37:42]), .dout(S[25:28]) ); sbox8 u7( .addr(X[43:48]), .dout(S[29:32]) ); assign P[1:32] = { S[16], S[7], S[20], S[21], S[29], S[12], S[28], S[17], S[1], S[15], S[23], S[26], S[5], S[18], S[31], S[10], S[2], S[8], S[24], S[14], S[32], S[27], S[3], S[9], S[19], S[13], S[30], S[6], S[22], S[11], S[4], S[25]}; endmodule
///////////////////////////////////////////////////////////////////// //// //// //// DES //// //// DES Top Level module //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module des3(desOut, out_valid, start, desIn, key1, key2, key3, decrypt, clk); output reg[63:0] desOut; output out_valid; input start; input [63:0] desIn; input [55:0] key1; input [55:0] key2; input [55:0] key3; input decrypt; input clk; /* verilator lint_off LITENDIAN */ wire [1:48] K_sub; wire [1:64] IP, FP; reg [1:64] FP_R; reg [1:32] L, R; wire [1:32] Xin; wire [1:32] Lout; wire [1:32] Rout; wire [1:32] out; /* verilator lint_on LITENDIAN */ reg [5:0] roundSel; reg start_r; always @(posedge clk) begin start_r <= start; end wire start_posedge = start & ~start_r; reg [7:0] validCounter; wire [63:0] des; always @ (posedge clk) begin if(start_posedge) begin roundSel <= 6'h00; end else if(~out_valid) begin roundSel <= roundSel +1; end end assign out_valid = (roundSel == 6'h30); always @ (posedge clk) begin if(!out_valid) begin desOut <= des; end end crp u0( .P(out), .R(Lout), .K_sub(K_sub)); // Select a subkey from key. key_sel3 u1( .K_sub(K_sub), .key1(key1), .key2(key2), .key3(key3), .roundSel(roundSel), .decrypt(decrypt) ); assign Lout = (roundSel == 0) ? IP[33:64] : ((roundSel == 16) ? FP_R[33:64] : ((roundSel == 32) ? FP_R[33:64] : R)); assign Xin = (roundSel == 0) ? IP[01:32] : ((roundSel == 16) ? FP_R[01:32] : ((roundSel == 32) ? FP_R[01:32] : L)); always @(posedge clk) FP_R <= FP; assign Rout = Xin ^ out; assign FP = { Rout, Lout}; always @(posedge clk) L <= Lout; always @(posedge clk) R <= Rout; // Perform initial permutation assign IP[1:64] = {desIn[06], desIn[14], desIn[22], desIn[30], desIn[38], desIn[46], desIn[54], desIn[62], desIn[04], desIn[12], desIn[20], desIn[28], desIn[36], desIn[44], desIn[52], desIn[60], desIn[02], desIn[10], desIn[18], desIn[26], desIn[34], desIn[42], desIn[50], desIn[58], desIn[00], desIn[08], desIn[16], desIn[24], desIn[32], desIn[40], desIn[48], desIn[56], desIn[07], desIn[15], desIn[23], desIn[31], desIn[39], desIn[47], desIn[55], desIn[63], desIn[05], desIn[13], desIn[21], desIn[29], desIn[37], desIn[45], desIn[53], desIn[61], desIn[03], desIn[11], desIn[19], desIn[27], desIn[35], desIn[43], desIn[51], desIn[59], desIn[01], desIn[09], desIn[17], desIn[25], desIn[33], desIn[41], desIn[49], desIn[57] }; // Perform final permutation assign des = {FP[40], FP[08], FP[48], FP[16], FP[56], FP[24], FP[64], FP[32], FP[39], FP[07], FP[47], FP[15], FP[55], FP[23], FP[63], FP[31], FP[38], FP[06], FP[46], FP[14], FP[54], FP[22], FP[62], FP[30], FP[37], FP[05], FP[45], FP[13], FP[53], FP[21], FP[61], FP[29], FP[36], FP[04], FP[44], FP[12], FP[52], FP[20], FP[60], FP[28], FP[35], FP[03], FP[43], FP[11], FP[51], FP[19], FP[59], FP[27], FP[34], FP[02], FP[42], FP[10], FP[50], FP[18], FP[58], FP[26], FP[33], FP[01], FP[41], FP[09], FP[49], FP[17], FP[57], FP[25] }; endmodule
///////////////////////////////////////////////////////////////////// //// //// //// DES TEST BENCH //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module test; reg clk; reg [319:0] x[512:0]; reg [319:0] tmp; reg [5:0] cnt; integer select; integer decrypt; wire [63:0] desOut; wire [63:0] des_in; wire [63:0] exp_out; wire [55:0] key1; wire [55:0] key2; wire [55:0] key3; integer ZZZ; initial begin $display("\n\n"); $display("*********************************************************"); $display("* Area Optimized DES core simulation started ... *"); $display("*********************************************************"); $display("\n"); //`ifdef WAVES // $shm_open("waves"); // $shm_probe("AS",test,"AS"); // $display("INFO: Signal dump enabled ...\n\n"); //`endif if(1) begin $dumpfile("./iverilog/test.vcd"); $dumpvars(0,test); end clk=0; ZZZ=0; // key1 key2 key3 Test data Out data x[0]=320'h0101010101010101_0101010101010101_0101010101010101_95F8A5E5DD31D900_8000000000000000; x[1]=320'h0101010101010101_0101010101010101_0101010101010101_9D64555A9A10B852_0000001000000000; x[2]=320'h3849674C2602319E_3849674C2602319E_3849674C2602319E_51454B582DDF440A_7178876E01F19B2A; x[3]=320'h04B915BA43FEB5B6_04B915BA43FEB5B6_04B915BA43FEB5B6_42FD443059577FA2_AF37FB421F8C4095; x[4]=320'h0123456789ABCDEF_0123456789ABCDEF_0123456789ABCDEF_736F6D6564617461_3D124FE2198BA318; x[5]=320'h0123456789ABCDEF_5555555555555555_0123456789ABCDEF_736F6D6564617461_FBABA1FF9D05E9B1; x[6]=320'h0123456789ABCDEF_5555555555555555_FEDCBA9876543210_736F6D6564617461_18d748e563620572; x[7]=320'h0352020767208217_8602876659082198_64056ABDFEA93457_7371756967676C65_c07d2a0fa566fa30; x[8]=320'h0101010101010101_8001010101010101_0101010101010102_0000000000000000_e6e6dd5b7e722974; x[9]=320'h1046103489988020_9107D01589190101_19079210981A0101_0000000000000000_e1ef62c332fe825b; decrypt = 0; @(posedge clk); $display(""); $display("**************************************"); $display("* Starting DES Test ... *"); $display("**************************************"); $display(""); for(decrypt=0;decrypt<2;decrypt=decrypt+1) begin if(decrypt) $display("Running Encrypt test ...\n"); else $display("Running Decrypt test ...\n"); for(select=0;select<16;select=select+1) begin tmp=x[select]; for(cnt=0;cnt<47;cnt=cnt+1) @(posedge clk); #10; if((exp_out !== desOut) | (^exp_out===1'bx) | (^desOut===1'bx)) $display("ERROR: (%0d) Expected %x Got %x", select, exp_out, desOut); else $display("PASS : (%0d) Expected %x Got %x", select, exp_out, desOut); //#2 $display("%h %h %h %h %h", key3, key2, key1, des_in, exp_out); @(posedge clk); end end $display(""); $display("**************************************"); $display("* DES Test done ... *"); $display("**************************************"); $display(""); $finish; end // end of innitial always #100 clk=~clk; assign #1 key1 = {tmp[319:313],tmp[311:305],tmp[303:297],tmp[295:289], tmp[287:281],tmp[279:273],tmp[271:265],tmp[263:257]}; assign #1 key2 = {tmp[255:249],tmp[247:241],tmp[239:233],tmp[231:225], tmp[223:217],tmp[215:209],tmp[207:201],tmp[199:193]}; assign #1 key3 = {tmp[191:185],tmp[183:177],tmp[175:169],tmp[167:161], tmp[159:153],tmp[151:145],tmp[143:137],tmp[135:129]}; assign #1 des_in = decrypt[0] ? tmp[63:0] : tmp[127:64]; assign exp_out = decrypt[0] ? tmp[127:64] : tmp[63:0]; des3 u0( .clk( clk ), .desOut( desOut ), .desIn( des_in ), .key1( key1 ), .key2( key2 ), .key3( key3 ), .roundSel( cnt ), .decrypt( decrypt[0] ) ); endmodule
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : des3_top.v // Project : Common Evaluation Platform (CEP) // Description : This file provides a wishbone based-DES3 core // module des3_top #( parameter remove_parity_bits=0) ( wb_adr_i, wb_cyc_i, wb_dat_i, wb_sel_i, wb_stb_i, wb_we_i, wb_ack_o, wb_err_o, wb_dat_o, wb_clk_i, wb_rst_i, int_o ); parameter dw = 32; parameter aw = 32; input [aw-1:0] wb_adr_i; input wb_cyc_i; input [dw-1:0] wb_dat_i; input [3:0] wb_sel_i; input wb_stb_i; input wb_we_i; output wb_ack_o; output wb_err_o; output reg [dw-1:0] wb_dat_o; output int_o; input wb_clk_i; input wb_rst_i; assign wb_err_o = 1'b0; assign int_o = 1'b0; // Internal registers reg start, start_r; reg decrypt; reg [31:0] desIn [0:1]; reg [31:0] key [0:5]; reg wb_stb_i_r; wire [63:0] des_in={desIn[0], desIn[1]}; wire [55:0] key_1; wire [55:0] key_2; wire [55:0] key_3; wire [63:0] ct; wire ct_valid; // The following generate logic is to used to remove the parity bits from the key // This was performed in the C test code that loaded vectors genvar i; generate if (remove_parity_bits == 1) begin for (i = 0; i < 4; i = i + 1) begin assign key_1[34 + i*7:28 + i*7] = key[0][i*8+1 + 6:i*8+1]; assign key_1[ 6 + i*7: i*7] = key[1][i*8+1 + 6:i*8+1]; assign key_2[34 + i*7:28 + i*7] = key[2][i*8+1 + 6:i*8+1]; assign key_2[ 6 + i*7: i*7] = key[3][i*8+1 + 6:i*8+1]; assign key_3[34 + i*7:28 + i*7] = key[4][i*8+1 + 6:i*8+1]; assign key_3[ 6 + i*7: i*7] = key[5][i*8+1 + 6:i*8+1]; end // generate for (i = 0; i < 4; i = i + 1) end else begin assign key_1 = {key[0][27:0], key[1][27:0]}; assign key_2 = {key[2][27:0], key[3][27:0]}; assign key_3 = {key[4][27:0], key[5][27:0]}; end // end else endgenerate // Generate the acknowledgement signal assign wb_ack_o = wb_stb_i_r && wb_stb_i; // Implement MD5 I/O memory map interface // Write side always @(posedge wb_clk_i) begin if(wb_rst_i) begin start <= 0; start_r <= 0; decrypt <= 0; desIn[1] <= 0; desIn[0] <= 0; key[5] <= 0; key[4] <= 0; key[3] <= 0; key[2] <= 0; key[1] <= 0; key[0] <= 0; wb_stb_i_r <= 1'b0; end else begin // Generate registered versions of start start_r <= start; // Generate a registered version of the write strobe wb_stb_i_r <= wb_stb_i; // Peform a write if(wb_stb_i & wb_we_i) begin case(wb_adr_i[5:2]) 0: start <= wb_dat_i[0]; 1: decrypt <= wb_dat_i[0]; 2: desIn[1]<= wb_dat_i; 3: desIn[0]<= wb_dat_i; 4: key[5] <= wb_dat_i; 5: key[4] <= wb_dat_i; 6: key[3] <= wb_dat_i; 7: key[2] <= wb_dat_i; 8: key[1] <= wb_dat_i; 9: key[0] <= wb_dat_i; default: ; endcase end else begin // if wb_stb_i & wb_we_i start <= 1'b0; end end // else end // always @ (posedge wb_clk_i) // Implement MD5 I/O memory map interface // Read side always @(*) begin case(wb_adr_i[5:2]) 2: wb_dat_o = desIn[1]; 3: wb_dat_o = desIn[0]; 4: wb_dat_o = key[5]; 5: wb_dat_o = key[4]; 6: wb_dat_o = key[3]; 7: wb_dat_o = key[2]; 8: wb_dat_o = key[1]; 9: wb_dat_o = key[0]; 10: wb_dat_o = {31'b0, ct_valid}; 11: wb_dat_o = ct[63:32]; 12: wb_dat_o = ct[31:0]; default: wb_dat_o = 32'b0; endcase end // always @ (*) des3 des3( .desOut(ct), .out_valid(ct_valid), .start(start && ~start_r), .desIn(des_in), .key1(key_1), .key2(key_2), .key3(key_3), .decrypt(decrypt), .clk(wb_clk_i)); endmodule
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : des3_top_axi4lite.v // Project : Common Evaluation Platform (CEP) // Description : This file provides an axi4-lite wrapper for the wishbone based-DES3 core // module des3_top_axi4lite ( // Clock & Reset input logic clk_i, input logic rst_ni, // AXI4-Lite Slave Interface AXI_LITE.Slave slave ); // DES3 wishbone slave wires wire wb_clk; wire wb_rst; wire wb_rst_n; wire [slave.AXI_ADDR_WIDTH - 1:0] wbs_d_des3_adr_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_des3_dat_i; wire [3:0] wbs_d_des3_sel_i; wire wbs_d_des3_we_i; wire wbs_d_des3_cyc_i; wire wbs_d_des3_stb_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_des3_dat_o; wire wbs_d_des3_ack_o; // Instantiate the AXI4Lite to Wishbone bridge bonfire_axi4l2wb #( .ADRWIDTH (slave.AXI_ADDR_WIDTH), .FAST_READ_TERM (1'd0) ) bonfire_axi4l2wb_inst ( .S_AXI_ACLK (clk_i), .S_AXI_ARESETN (rst_ni), .S_AXI_AWADDR (slave.aw_addr), .S_AXI_AWVALID (slave.aw_valid), .S_AXI_AWREADY (slave.aw_ready), .S_AXI_WDATA (slave.w_data), .S_AXI_WSTRB (slave.w_strb), .S_AXI_WVALID (slave.w_valid), .S_AXI_WREADY (slave.w_ready), .S_AXI_ARADDR (slave.ar_addr), .S_AXI_ARVALID (slave.ar_valid), .S_AXI_ARREADY (slave.ar_ready), .S_AXI_RDATA (slave.r_data), .S_AXI_RRESP (slave.r_resp), .S_AXI_RVALID (slave.r_valid), .S_AXI_RREADY (slave.r_ready), .S_AXI_BRESP (slave.b_resp), .S_AXI_BVALID (slave.b_valid), .S_AXI_BREADY (slave.b_ready), .wb_clk_o (wb_clk), .wb_rst_o (wb_rst), .wb_addr_o (wbs_d_des3_adr_i), .wb_dat_o (wbs_d_des3_dat_i), .wb_we_o (wbs_d_des3_we_i), .wb_sel_o (wbs_d_des3_sel_i), .wb_stb_o (wbs_d_des3_stb_i), .wb_cyc_o (wbs_d_des3_cyc_i), .wb_dat_i (wbs_d_des3_dat_o), .wb_ack_i (wbs_d_des3_ack_o) ); // Instantiate the wishbone-based AES Core des3_top #( .remove_parity_bits(1) ) des3 ( // Wishbone Slave interface .wb_clk_i (wb_clk), .wb_rst_i (wb_rst), .wb_dat_i (wbs_d_des3_dat_i), .wb_adr_i (wbs_d_des3_adr_i), .wb_sel_i (wbs_d_des3_sel_i[3:0]), .wb_we_i (wbs_d_des3_we_i), .wb_cyc_i (wbs_d_des3_cyc_i), .wb_stb_i (wbs_d_des3_stb_i), .wb_dat_o (wbs_d_des3_dat_o), .wb_err_o (), .wb_ack_o (wbs_d_des3_ack_o), // Processor interrupt .int_o () ); endmodule // end aes_top_axi4lite
///////////////////////////////////////////////////////////////////// //// //// //// KEY_SEL //// //// Select one of 16 sub-keys for round //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module key_sel3(K_sub, key1, key2, key3, roundSel, decrypt); /* verilator lint_off LITENDIAN */ output [1:48] K_sub; /* verilator lint_on LITENDIAN */ input [55:0] key1, key2, key3; input [5:0] roundSel; input decrypt; wire decrypt_int; reg [55:0] K; reg [1:48] K_sub; /* verilator lint_off LITENDIAN */ wire [1:48] K1, K2, K3, K4, K5, K6, K7, K8, K9; wire [1:48] K10, K11, K12, K13, K14, K15, K16; /* verilator lint_on LITENDIAN */ always @(roundSel or decrypt or key1 or key2 or key3) case ({decrypt, roundSel[5:4]}) // synopsys full_case parallel_case 3'b0_00: K = key1; 3'b0_01: K = key2; 3'b0_10: K = key3; 3'b1_00: K = key3; 3'b1_01: K = key2; 3'b1_10: K = key1; 3'b0_11: K = 56'b0; 3'b1_11: K = 56'b0; endcase assign decrypt_int = (roundSel[5:4]==2'h1) ? !decrypt : decrypt; always @(K1 or K2 or K3 or K4 or K5 or K6 or K7 or K8 or K9 or K10 or K11 or K12 or K13 or K14 or K15 or K16 or roundSel) case(roundSel[3:0]) // synopsys full_case parallel_case 0: K_sub = K1; 1: K_sub = K2; 2: K_sub = K3; 3: K_sub = K4; 4: K_sub = K5; 5: K_sub = K6; 6: K_sub = K7; 7: K_sub = K8; 8: K_sub = K9; 9: K_sub = K10; 10: K_sub = K11; 11: K_sub = K12; 12: K_sub = K13; 13: K_sub = K14; 14: K_sub = K15; 15: K_sub = K16; endcase assign K16[1] = decrypt_int ? K[47] : K[40]; assign K16[2] = decrypt_int ? K[11] : K[4]; assign K16[3] = decrypt_int ? K[26] : K[19]; assign K16[4] = decrypt_int ? K[3] : K[53]; assign K16[5] = decrypt_int ? K[13] : K[6]; assign K16[6] = decrypt_int ? K[41] : K[34]; assign K16[7] = decrypt_int ? K[27] : K[20]; assign K16[8] = decrypt_int ? K[6] : K[24]; assign K16[9] = decrypt_int ? K[54] : K[47]; assign K16[10] = decrypt_int ? K[48] : K[41]; assign K16[11] = decrypt_int ? K[39] : K[32]; assign K16[12] = decrypt_int ? K[19] : K[12]; assign K16[13] = decrypt_int ? K[53] : K[46]; assign K16[14] = decrypt_int ? K[25] : K[18]; assign K16[15] = decrypt_int ? K[33] : K[26]; assign K16[16] = decrypt_int ? K[34] : K[27]; assign K16[17] = decrypt_int ? K[17] : K[10]; assign K16[18] = decrypt_int ? K[5] : K[55]; assign K16[19] = decrypt_int ? K[4] : K[54]; assign K16[20] = decrypt_int ? K[55] : K[48]; assign K16[21] = decrypt_int ? K[24] : K[17]; assign K16[22] = decrypt_int ? K[32] : K[25]; assign K16[23] = decrypt_int ? K[40] : K[33]; assign K16[24] = decrypt_int ? K[20] : K[13]; assign K16[25] = decrypt_int ? K[36] : K[29]; assign K16[26] = decrypt_int ? K[31] : K[51]; assign K16[27] = decrypt_int ? K[21] : K[14]; assign K16[28] = decrypt_int ? K[8] : K[1]; assign K16[29] = decrypt_int ? K[23] : K[16]; assign K16[30] = decrypt_int ? K[52] : K[45]; assign K16[31] = decrypt_int ? K[14] : K[7]; assign K16[32] = decrypt_int ? K[29] : K[22]; assign K16[33] = decrypt_int ? K[51] : K[44]; assign K16[34] = decrypt_int ? K[9] : K[2]; assign K16[35] = decrypt_int ? K[35] : K[28]; assign K16[36] = decrypt_int ? K[30] : K[23]; assign K16[37] = decrypt_int ? K[2] : K[50]; assign K16[38] = decrypt_int ? K[37] : K[30]; assign K16[39] = decrypt_int ? K[22] : K[15]; assign K16[40] = decrypt_int ? K[0] : K[52]; assign K16[41] = decrypt_int ? K[42] : K[35]; assign K16[42] = decrypt_int ? K[38] : K[31]; assign K16[43] = decrypt_int ? K[16] : K[9]; assign K16[44] = decrypt_int ? K[43] : K[36]; assign K16[45] = decrypt_int ? K[44] : K[37]; assign K16[46] = decrypt_int ? K[1] : K[49]; assign K16[47] = decrypt_int ? K[7] : K[0]; assign K16[48] = decrypt_int ? K[28] : K[21]; assign K15[1] = decrypt_int ? K[54] : K[33]; assign K15[2] = decrypt_int ? K[18] : K[54]; assign K15[3] = decrypt_int ? K[33] : K[12]; assign K15[4] = decrypt_int ? K[10] : K[46]; assign K15[5] = decrypt_int ? K[20] : K[24]; assign K15[6] = decrypt_int ? K[48] : K[27]; assign K15[7] = decrypt_int ? K[34] : K[13]; assign K15[8] = decrypt_int ? K[13] : K[17]; assign K15[9] = decrypt_int ? K[4] : K[40]; assign K15[10] = decrypt_int ? K[55] : K[34]; assign K15[11] = decrypt_int ? K[46] : K[25]; assign K15[12] = decrypt_int ? K[26] : K[5]; assign K15[13] = decrypt_int ? K[3] : K[39]; assign K15[14] = decrypt_int ? K[32] : K[11]; assign K15[15] = decrypt_int ? K[40] : K[19]; assign K15[16] = decrypt_int ? K[41] : K[20]; assign K15[17] = decrypt_int ? K[24] : K[3]; assign K15[18] = decrypt_int ? K[12] : K[48]; assign K15[19] = decrypt_int ? K[11] : K[47]; assign K15[20] = decrypt_int ? K[5] : K[41]; assign K15[21] = decrypt_int ? K[6] : K[10]; assign K15[22] = decrypt_int ? K[39] : K[18]; assign K15[23] = decrypt_int ? K[47] : K[26]; assign K15[24] = decrypt_int ? K[27] : K[6]; assign K15[25] = decrypt_int ? K[43] : K[22]; assign K15[26] = decrypt_int ? K[38] : K[44]; assign K15[27] = decrypt_int ? K[28] : K[7]; assign K15[28] = decrypt_int ? K[15] : K[49]; assign K15[29] = decrypt_int ? K[30] : K[9]; assign K15[30] = decrypt_int ? K[0] : K[38]; assign K15[31] = decrypt_int ? K[21] : K[0]; assign K15[32] = decrypt_int ? K[36] : K[15]; assign K15[33] = decrypt_int ? K[31] : K[37]; assign K15[34] = decrypt_int ? K[16] : K[50]; assign K15[35] = decrypt_int ? K[42] : K[21]; assign K15[36] = decrypt_int ? K[37] : K[16]; assign K15[37] = decrypt_int ? K[9] : K[43]; assign K15[38] = decrypt_int ? K[44] : K[23]; assign K15[39] = decrypt_int ? K[29] : K[8]; assign K15[40] = decrypt_int ? K[7] : K[45]; assign K15[41] = decrypt_int ? K[49] : K[28]; assign K15[42] = decrypt_int ? K[45] : K[51]; assign K15[43] = decrypt_int ? K[23] : K[2]; assign K15[44] = decrypt_int ? K[50] : K[29]; assign K15[45] = decrypt_int ? K[51] : K[30]; assign K15[46] = decrypt_int ? K[8] : K[42]; assign K15[47] = decrypt_int ? K[14] : K[52]; assign K15[48] = decrypt_int ? K[35] : K[14]; assign K14[1] = decrypt_int ? K[11] : K[19]; assign K14[2] = decrypt_int ? K[32] : K[40]; assign K14[3] = decrypt_int ? K[47] : K[55]; assign K14[4] = decrypt_int ? K[24] : K[32]; assign K14[5] = decrypt_int ? K[34] : K[10]; assign K14[6] = decrypt_int ? K[5] : K[13]; assign K14[7] = decrypt_int ? K[48] : K[24]; assign K14[8] = decrypt_int ? K[27] : K[3]; assign K14[9] = decrypt_int ? K[18] : K[26]; assign K14[10] = decrypt_int ? K[12] : K[20]; assign K14[11] = decrypt_int ? K[3] : K[11]; assign K14[12] = decrypt_int ? K[40] : K[48]; assign K14[13] = decrypt_int ? K[17] : K[25]; assign K14[14] = decrypt_int ? K[46] : K[54]; assign K14[15] = decrypt_int ? K[54] : K[5]; assign K14[16] = decrypt_int ? K[55] : K[6]; assign K14[17] = decrypt_int ? K[13] : K[46]; assign K14[18] = decrypt_int ? K[26] : K[34]; assign K14[19] = decrypt_int ? K[25] : K[33]; assign K14[20] = decrypt_int ? K[19] : K[27]; assign K14[21] = decrypt_int ? K[20] : K[53]; assign K14[22] = decrypt_int ? K[53] : K[4]; assign K14[23] = decrypt_int ? K[4] : K[12]; assign K14[24] = decrypt_int ? K[41] : K[17]; assign K14[25] = decrypt_int ? K[2] : K[8]; assign K14[26] = decrypt_int ? K[52] : K[30]; assign K14[27] = decrypt_int ? K[42] : K[52]; assign K14[28] = decrypt_int ? K[29] : K[35]; assign K14[29] = decrypt_int ? K[44] : K[50]; assign K14[30] = decrypt_int ? K[14] : K[51]; assign K14[31] = decrypt_int ? K[35] : K[45]; assign K14[32] = decrypt_int ? K[50] : K[1]; assign K14[33] = decrypt_int ? K[45] : K[23]; assign K14[34] = decrypt_int ? K[30] : K[36]; assign K14[35] = decrypt_int ? K[1] : K[7]; assign K14[36] = decrypt_int ? K[51] : K[2]; assign K14[37] = decrypt_int ? K[23] : K[29]; assign K14[38] = decrypt_int ? K[31] : K[9]; assign K14[39] = decrypt_int ? K[43] : K[49]; assign K14[40] = decrypt_int ? K[21] : K[31]; assign K14[41] = decrypt_int ? K[8] : K[14]; assign K14[42] = decrypt_int ? K[0] : K[37]; assign K14[43] = decrypt_int ? K[37] : K[43]; assign K14[44] = decrypt_int ? K[9] : K[15]; assign K14[45] = decrypt_int ? K[38] : K[16]; assign K14[46] = decrypt_int ? K[22] : K[28]; assign K14[47] = decrypt_int ? K[28] : K[38]; assign K14[48] = decrypt_int ? K[49] : K[0]; assign K13[1] = decrypt_int ? K[25] : K[5]; assign K13[2] = decrypt_int ? K[46] : K[26]; assign K13[3] = decrypt_int ? K[4] : K[41]; assign K13[4] = decrypt_int ? K[13] : K[18]; assign K13[5] = decrypt_int ? K[48] : K[53]; assign K13[6] = decrypt_int ? K[19] : K[24]; assign K13[7] = decrypt_int ? K[5] : K[10]; assign K13[8] = decrypt_int ? K[41] : K[46]; assign K13[9] = decrypt_int ? K[32] : K[12]; assign K13[10] = decrypt_int ? K[26] : K[6]; assign K13[11] = decrypt_int ? K[17] : K[54]; assign K13[12] = decrypt_int ? K[54] : K[34]; assign K13[13] = decrypt_int ? K[6] : K[11]; assign K13[14] = decrypt_int ? K[3] : K[40]; assign K13[15] = decrypt_int ? K[11] : K[48]; assign K13[16] = decrypt_int ? K[12] : K[17]; assign K13[17] = decrypt_int ? K[27] : K[32]; assign K13[18] = decrypt_int ? K[40] : K[20]; assign K13[19] = decrypt_int ? K[39] : K[19]; assign K13[20] = decrypt_int ? K[33] : K[13]; assign K13[21] = decrypt_int ? K[34] : K[39]; assign K13[22] = decrypt_int ? K[10] : K[47]; assign K13[23] = decrypt_int ? K[18] : K[55]; assign K13[24] = decrypt_int ? K[55] : K[3]; assign K13[25] = decrypt_int ? K[16] : K[49]; assign K13[26] = decrypt_int ? K[7] : K[16]; assign K13[27] = decrypt_int ? K[1] : K[38]; assign K13[28] = decrypt_int ? K[43] : K[21]; assign K13[29] = decrypt_int ? K[31] : K[36]; assign K13[30] = decrypt_int ? K[28] : K[37]; assign K13[31] = decrypt_int ? K[49] : K[31]; assign K13[32] = decrypt_int ? K[9] : K[42]; assign K13[33] = decrypt_int ? K[0] : K[9]; assign K13[34] = decrypt_int ? K[44] : K[22]; assign K13[35] = decrypt_int ? K[15] : K[52]; assign K13[36] = decrypt_int ? K[38] : K[43]; assign K13[37] = decrypt_int ? K[37] : K[15]; assign K13[38] = decrypt_int ? K[45] : K[50]; assign K13[39] = decrypt_int ? K[2] : K[35]; assign K13[40] = decrypt_int ? K[35] : K[44]; assign K13[41] = decrypt_int ? K[22] : K[0]; assign K13[42] = decrypt_int ? K[14] : K[23]; assign K13[43] = decrypt_int ? K[51] : K[29]; assign K13[44] = decrypt_int ? K[23] : K[1]; assign K13[45] = decrypt_int ? K[52] : K[2]; assign K13[46] = decrypt_int ? K[36] : K[14]; assign K13[47] = decrypt_int ? K[42] : K[51]; assign K13[48] = decrypt_int ? K[8] : K[45]; assign K12[1] = decrypt_int ? K[39] : K[48]; assign K12[2] = decrypt_int ? K[3] : K[12]; assign K12[3] = decrypt_int ? K[18] : K[27]; assign K12[4] = decrypt_int ? K[27] : K[4]; assign K12[5] = decrypt_int ? K[5] : K[39]; assign K12[6] = decrypt_int ? K[33] : K[10]; assign K12[7] = decrypt_int ? K[19] : K[53]; assign K12[8] = decrypt_int ? K[55] : K[32]; assign K12[9] = decrypt_int ? K[46] : K[55]; assign K12[10] = decrypt_int ? K[40] : K[17]; assign K12[11] = decrypt_int ? K[6] : K[40]; assign K12[12] = decrypt_int ? K[11] : K[20]; assign K12[13] = decrypt_int ? K[20] : K[54]; assign K12[14] = decrypt_int ? K[17] : K[26]; assign K12[15] = decrypt_int ? K[25] : K[34]; assign K12[16] = decrypt_int ? K[26] : K[3]; assign K12[17] = decrypt_int ? K[41] : K[18]; assign K12[18] = decrypt_int ? K[54] : K[6]; assign K12[19] = decrypt_int ? K[53] : K[5]; assign K12[20] = decrypt_int ? K[47] : K[24]; assign K12[21] = decrypt_int ? K[48] : K[25]; assign K12[22] = decrypt_int ? K[24] : K[33]; assign K12[23] = decrypt_int ? K[32] : K[41]; assign K12[24] = decrypt_int ? K[12] : K[46]; assign K12[25] = decrypt_int ? K[30] : K[35]; assign K12[26] = decrypt_int ? K[21] : K[2]; assign K12[27] = decrypt_int ? K[15] : K[51]; assign K12[28] = decrypt_int ? K[2] : K[7]; assign K12[29] = decrypt_int ? K[45] : K[22]; assign K12[30] = decrypt_int ? K[42] : K[23]; assign K12[31] = decrypt_int ? K[8] : K[44]; assign K12[32] = decrypt_int ? K[23] : K[28]; assign K12[33] = decrypt_int ? K[14] : K[50]; assign K12[34] = decrypt_int ? K[31] : K[8]; assign K12[35] = decrypt_int ? K[29] : K[38]; assign K12[36] = decrypt_int ? K[52] : K[29]; assign K12[37] = decrypt_int ? K[51] : K[1]; assign K12[38] = decrypt_int ? K[0] : K[36]; assign K12[39] = decrypt_int ? K[16] : K[21]; assign K12[40] = decrypt_int ? K[49] : K[30]; assign K12[41] = decrypt_int ? K[36] : K[45]; assign K12[42] = decrypt_int ? K[28] : K[9]; assign K12[43] = decrypt_int ? K[38] : K[15]; assign K12[44] = decrypt_int ? K[37] : K[42]; assign K12[45] = decrypt_int ? K[7] : K[43]; assign K12[46] = decrypt_int ? K[50] : K[0]; assign K12[47] = decrypt_int ? K[1] : K[37]; assign K12[48] = decrypt_int ? K[22] : K[31]; assign K11[1] = decrypt_int ? K[53] : K[34]; assign K11[2] = decrypt_int ? K[17] : K[55]; assign K11[3] = decrypt_int ? K[32] : K[13]; assign K11[4] = decrypt_int ? K[41] : K[47]; assign K11[5] = decrypt_int ? K[19] : K[25]; assign K11[6] = decrypt_int ? K[47] : K[53]; assign K11[7] = decrypt_int ? K[33] : K[39]; assign K11[8] = decrypt_int ? K[12] : K[18]; assign K11[9] = decrypt_int ? K[3] : K[41]; assign K11[10] = decrypt_int ? K[54] : K[3]; assign K11[11] = decrypt_int ? K[20] : K[26]; assign K11[12] = decrypt_int ? K[25] : K[6]; assign K11[13] = decrypt_int ? K[34] : K[40]; assign K11[14] = decrypt_int ? K[6] : K[12]; assign K11[15] = decrypt_int ? K[39] : K[20]; assign K11[16] = decrypt_int ? K[40] : K[46]; assign K11[17] = decrypt_int ? K[55] : K[4]; assign K11[18] = decrypt_int ? K[11] : K[17]; assign K11[19] = decrypt_int ? K[10] : K[48]; assign K11[20] = decrypt_int ? K[4] : K[10]; assign K11[21] = decrypt_int ? K[5] : K[11]; assign K11[22] = decrypt_int ? K[13] : K[19]; assign K11[23] = decrypt_int ? K[46] : K[27]; assign K11[24] = decrypt_int ? K[26] : K[32]; assign K11[25] = decrypt_int ? K[44] : K[21]; assign K11[26] = decrypt_int ? K[35] : K[43]; assign K11[27] = decrypt_int ? K[29] : K[37]; assign K11[28] = decrypt_int ? K[16] : K[52]; assign K11[29] = decrypt_int ? K[0] : K[8]; assign K11[30] = decrypt_int ? K[1] : K[9]; assign K11[31] = decrypt_int ? K[22] : K[30]; assign K11[32] = decrypt_int ? K[37] : K[14]; assign K11[33] = decrypt_int ? K[28] : K[36]; assign K11[34] = decrypt_int ? K[45] : K[49]; assign K11[35] = decrypt_int ? K[43] : K[51]; assign K11[36] = decrypt_int ? K[7] : K[15]; assign K11[37] = decrypt_int ? K[38] : K[42]; assign K11[38] = decrypt_int ? K[14] : K[22]; assign K11[39] = decrypt_int ? K[30] : K[7]; assign K11[40] = decrypt_int ? K[8] : K[16]; assign K11[41] = decrypt_int ? K[50] : K[31]; assign K11[42] = decrypt_int ? K[42] : K[50]; assign K11[43] = decrypt_int ? K[52] : K[1]; assign K11[44] = decrypt_int ? K[51] : K[28]; assign K11[45] = decrypt_int ? K[21] : K[29]; assign K11[46] = decrypt_int ? K[9] : K[45]; assign K11[47] = decrypt_int ? K[15] : K[23]; assign K11[48] = decrypt_int ? K[36] : K[44]; assign K10[1] = decrypt_int ? K[10] : K[20]; assign K10[2] = decrypt_int ? K[6] : K[41]; assign K10[3] = decrypt_int ? K[46] : K[24]; assign K10[4] = decrypt_int ? K[55] : K[33]; assign K10[5] = decrypt_int ? K[33] : K[11]; assign K10[6] = decrypt_int ? K[4] : K[39]; assign K10[7] = decrypt_int ? K[47] : K[25]; assign K10[8] = decrypt_int ? K[26] : K[4]; assign K10[9] = decrypt_int ? K[17] : K[27]; assign K10[10] = decrypt_int ? K[11] : K[46]; assign K10[11] = decrypt_int ? K[34] : K[12]; assign K10[12] = decrypt_int ? K[39] : K[17]; assign K10[13] = decrypt_int ? K[48] : K[26]; assign K10[14] = decrypt_int ? K[20] : K[55]; assign K10[15] = decrypt_int ? K[53] : K[6]; assign K10[16] = decrypt_int ? K[54] : K[32]; assign K10[17] = decrypt_int ? K[12] : K[47]; assign K10[18] = decrypt_int ? K[25] : K[3]; assign K10[19] = decrypt_int ? K[24] : K[34]; assign K10[20] = decrypt_int ? K[18] : K[53]; assign K10[21] = decrypt_int ? K[19] : K[54]; assign K10[22] = decrypt_int ? K[27] : K[5]; assign K10[23] = decrypt_int ? K[3] : K[13]; assign K10[24] = decrypt_int ? K[40] : K[18]; assign K10[25] = decrypt_int ? K[31] : K[7]; assign K10[26] = decrypt_int ? K[49] : K[29]; assign K10[27] = decrypt_int ? K[43] : K[23]; assign K10[28] = decrypt_int ? K[30] : K[38]; assign K10[29] = decrypt_int ? K[14] : K[49]; assign K10[30] = decrypt_int ? K[15] : K[50]; assign K10[31] = decrypt_int ? K[36] : K[16]; assign K10[32] = decrypt_int ? K[51] : K[0]; assign K10[33] = decrypt_int ? K[42] : K[22]; assign K10[34] = decrypt_int ? K[0] : K[35]; assign K10[35] = decrypt_int ? K[2] : K[37]; assign K10[36] = decrypt_int ? K[21] : K[1]; assign K10[37] = decrypt_int ? K[52] : K[28]; assign K10[38] = decrypt_int ? K[28] : K[8]; assign K10[39] = decrypt_int ? K[44] : K[52]; assign K10[40] = decrypt_int ? K[22] : K[2]; assign K10[41] = decrypt_int ? K[9] : K[44]; assign K10[42] = decrypt_int ? K[1] : K[36]; assign K10[43] = decrypt_int ? K[7] : K[42]; assign K10[44] = decrypt_int ? K[38] : K[14]; assign K10[45] = decrypt_int ? K[35] : K[15]; assign K10[46] = decrypt_int ? K[23] : K[31]; assign K10[47] = decrypt_int ? K[29] : K[9]; assign K10[48] = decrypt_int ? K[50] : K[30]; assign K9[1] = decrypt_int ? K[24] : K[6]; assign K9[2] = decrypt_int ? K[20] : K[27]; assign K9[3] = decrypt_int ? K[3] : K[10]; assign K9[4] = decrypt_int ? K[12] : K[19]; assign K9[5] = decrypt_int ? K[47] : K[54]; assign K9[6] = decrypt_int ? K[18] : K[25]; assign K9[7] = decrypt_int ? K[4] : K[11]; assign K9[8] = decrypt_int ? K[40] : K[47]; assign K9[9] = decrypt_int ? K[6] : K[13]; assign K9[10] = decrypt_int ? K[25] : K[32]; assign K9[11] = decrypt_int ? K[48] : K[55]; assign K9[12] = decrypt_int ? K[53] : K[3]; assign K9[13] = decrypt_int ? K[5] : K[12]; assign K9[14] = decrypt_int ? K[34] : K[41]; assign K9[15] = decrypt_int ? K[10] : K[17]; assign K9[16] = decrypt_int ? K[11] : K[18]; assign K9[17] = decrypt_int ? K[26] : K[33]; assign K9[18] = decrypt_int ? K[39] : K[46]; assign K9[19] = decrypt_int ? K[13] : K[20]; assign K9[20] = decrypt_int ? K[32] : K[39]; assign K9[21] = decrypt_int ? K[33] : K[40]; assign K9[22] = decrypt_int ? K[41] : K[48]; assign K9[23] = decrypt_int ? K[17] : K[24]; assign K9[24] = decrypt_int ? K[54] : K[4]; assign K9[25] = decrypt_int ? K[45] : K[52]; assign K9[26] = decrypt_int ? K[8] : K[15]; assign K9[27] = decrypt_int ? K[2] : K[9]; assign K9[28] = decrypt_int ? K[44] : K[51]; assign K9[29] = decrypt_int ? K[28] : K[35]; assign K9[30] = decrypt_int ? K[29] : K[36]; assign K9[31] = decrypt_int ? K[50] : K[2]; assign K9[32] = decrypt_int ? K[38] : K[45]; assign K9[33] = decrypt_int ? K[1] : K[8]; assign K9[34] = decrypt_int ? K[14] : K[21]; assign K9[35] = decrypt_int ? K[16] : K[23]; assign K9[36] = decrypt_int ? K[35] : K[42]; assign K9[37] = decrypt_int ? K[7] : K[14]; assign K9[38] = decrypt_int ? K[42] : K[49]; assign K9[39] = decrypt_int ? K[31] : K[38]; assign K9[40] = decrypt_int ? K[36] : K[43]; assign K9[41] = decrypt_int ? K[23] : K[30]; assign K9[42] = decrypt_int ? K[15] : K[22]; assign K9[43] = decrypt_int ? K[21] : K[28]; assign K9[44] = decrypt_int ? K[52] : K[0]; assign K9[45] = decrypt_int ? K[49] : K[1]; assign K9[46] = decrypt_int ? K[37] : K[44]; assign K9[47] = decrypt_int ? K[43] : K[50]; assign K9[48] = decrypt_int ? K[9] : K[16]; assign K8[1] = decrypt_int ? K[6] : K[24]; assign K8[2] = decrypt_int ? K[27] : K[20]; assign K8[3] = decrypt_int ? K[10] : K[3]; assign K8[4] = decrypt_int ? K[19] : K[12]; assign K8[5] = decrypt_int ? K[54] : K[47]; assign K8[6] = decrypt_int ? K[25] : K[18]; assign K8[7] = decrypt_int ? K[11] : K[4]; assign K8[8] = decrypt_int ? K[47] : K[40]; assign K8[9] = decrypt_int ? K[13] : K[6]; assign K8[10] = decrypt_int ? K[32] : K[25]; assign K8[11] = decrypt_int ? K[55] : K[48]; assign K8[12] = decrypt_int ? K[3] : K[53]; assign K8[13] = decrypt_int ? K[12] : K[5]; assign K8[14] = decrypt_int ? K[41] : K[34]; assign K8[15] = decrypt_int ? K[17] : K[10]; assign K8[16] = decrypt_int ? K[18] : K[11]; assign K8[17] = decrypt_int ? K[33] : K[26]; assign K8[18] = decrypt_int ? K[46] : K[39]; assign K8[19] = decrypt_int ? K[20] : K[13]; assign K8[20] = decrypt_int ? K[39] : K[32]; assign K8[21] = decrypt_int ? K[40] : K[33]; assign K8[22] = decrypt_int ? K[48] : K[41]; assign K8[23] = decrypt_int ? K[24] : K[17]; assign K8[24] = decrypt_int ? K[4] : K[54]; assign K8[25] = decrypt_int ? K[52] : K[45]; assign K8[26] = decrypt_int ? K[15] : K[8]; assign K8[27] = decrypt_int ? K[9] : K[2]; assign K8[28] = decrypt_int ? K[51] : K[44]; assign K8[29] = decrypt_int ? K[35] : K[28]; assign K8[30] = decrypt_int ? K[36] : K[29]; assign K8[31] = decrypt_int ? K[2] : K[50]; assign K8[32] = decrypt_int ? K[45] : K[38]; assign K8[33] = decrypt_int ? K[8] : K[1]; assign K8[34] = decrypt_int ? K[21] : K[14]; assign K8[35] = decrypt_int ? K[23] : K[16]; assign K8[36] = decrypt_int ? K[42] : K[35]; assign K8[37] = decrypt_int ? K[14] : K[7]; assign K8[38] = decrypt_int ? K[49] : K[42]; assign K8[39] = decrypt_int ? K[38] : K[31]; assign K8[40] = decrypt_int ? K[43] : K[36]; assign K8[41] = decrypt_int ? K[30] : K[23]; assign K8[42] = decrypt_int ? K[22] : K[15]; assign K8[43] = decrypt_int ? K[28] : K[21]; assign K8[44] = decrypt_int ? K[0] : K[52]; assign K8[45] = decrypt_int ? K[1] : K[49]; assign K8[46] = decrypt_int ? K[44] : K[37]; assign K8[47] = decrypt_int ? K[50] : K[43]; assign K8[48] = decrypt_int ? K[16] : K[9]; assign K7[1] = decrypt_int ? K[20] : K[10]; assign K7[2] = decrypt_int ? K[41] : K[6]; assign K7[3] = decrypt_int ? K[24] : K[46]; assign K7[4] = decrypt_int ? K[33] : K[55]; assign K7[5] = decrypt_int ? K[11] : K[33]; assign K7[6] = decrypt_int ? K[39] : K[4]; assign K7[7] = decrypt_int ? K[25] : K[47]; assign K7[8] = decrypt_int ? K[4] : K[26]; assign K7[9] = decrypt_int ? K[27] : K[17]; assign K7[10] = decrypt_int ? K[46] : K[11]; assign K7[11] = decrypt_int ? K[12] : K[34]; assign K7[12] = decrypt_int ? K[17] : K[39]; assign K7[13] = decrypt_int ? K[26] : K[48]; assign K7[14] = decrypt_int ? K[55] : K[20]; assign K7[15] = decrypt_int ? K[6] : K[53]; assign K7[16] = decrypt_int ? K[32] : K[54]; assign K7[17] = decrypt_int ? K[47] : K[12]; assign K7[18] = decrypt_int ? K[3] : K[25]; assign K7[19] = decrypt_int ? K[34] : K[24]; assign K7[20] = decrypt_int ? K[53] : K[18]; assign K7[21] = decrypt_int ? K[54] : K[19]; assign K7[22] = decrypt_int ? K[5] : K[27]; assign K7[23] = decrypt_int ? K[13] : K[3]; assign K7[24] = decrypt_int ? K[18] : K[40]; assign K7[25] = decrypt_int ? K[7] : K[31]; assign K7[26] = decrypt_int ? K[29] : K[49]; assign K7[27] = decrypt_int ? K[23] : K[43]; assign K7[28] = decrypt_int ? K[38] : K[30]; assign K7[29] = decrypt_int ? K[49] : K[14]; assign K7[30] = decrypt_int ? K[50] : K[15]; assign K7[31] = decrypt_int ? K[16] : K[36]; assign K7[32] = decrypt_int ? K[0] : K[51]; assign K7[33] = decrypt_int ? K[22] : K[42]; assign K7[34] = decrypt_int ? K[35] : K[0]; assign K7[35] = decrypt_int ? K[37] : K[2]; assign K7[36] = decrypt_int ? K[1] : K[21]; assign K7[37] = decrypt_int ? K[28] : K[52]; assign K7[38] = decrypt_int ? K[8] : K[28]; assign K7[39] = decrypt_int ? K[52] : K[44]; assign K7[40] = decrypt_int ? K[2] : K[22]; assign K7[41] = decrypt_int ? K[44] : K[9]; assign K7[42] = decrypt_int ? K[36] : K[1]; assign K7[43] = decrypt_int ? K[42] : K[7]; assign K7[44] = decrypt_int ? K[14] : K[38]; assign K7[45] = decrypt_int ? K[15] : K[35]; assign K7[46] = decrypt_int ? K[31] : K[23]; assign K7[47] = decrypt_int ? K[9] : K[29]; assign K7[48] = decrypt_int ? K[30] : K[50]; assign K6[1] = decrypt_int ? K[34] : K[53]; assign K6[2] = decrypt_int ? K[55] : K[17]; assign K6[3] = decrypt_int ? K[13] : K[32]; assign K6[4] = decrypt_int ? K[47] : K[41]; assign K6[5] = decrypt_int ? K[25] : K[19]; assign K6[6] = decrypt_int ? K[53] : K[47]; assign K6[7] = decrypt_int ? K[39] : K[33]; assign K6[8] = decrypt_int ? K[18] : K[12]; assign K6[9] = decrypt_int ? K[41] : K[3]; assign K6[10] = decrypt_int ? K[3] : K[54]; assign K6[11] = decrypt_int ? K[26] : K[20]; assign K6[12] = decrypt_int ? K[6] : K[25]; assign K6[13] = decrypt_int ? K[40] : K[34]; assign K6[14] = decrypt_int ? K[12] : K[6]; assign K6[15] = decrypt_int ? K[20] : K[39]; assign K6[16] = decrypt_int ? K[46] : K[40]; assign K6[17] = decrypt_int ? K[4] : K[55]; assign K6[18] = decrypt_int ? K[17] : K[11]; assign K6[19] = decrypt_int ? K[48] : K[10]; assign K6[20] = decrypt_int ? K[10] : K[4]; assign K6[21] = decrypt_int ? K[11] : K[5]; assign K6[22] = decrypt_int ? K[19] : K[13]; assign K6[23] = decrypt_int ? K[27] : K[46]; assign K6[24] = decrypt_int ? K[32] : K[26]; assign K6[25] = decrypt_int ? K[21] : K[44]; assign K6[26] = decrypt_int ? K[43] : K[35]; assign K6[27] = decrypt_int ? K[37] : K[29]; assign K6[28] = decrypt_int ? K[52] : K[16]; assign K6[29] = decrypt_int ? K[8] : K[0]; assign K6[30] = decrypt_int ? K[9] : K[1]; assign K6[31] = decrypt_int ? K[30] : K[22]; assign K6[32] = decrypt_int ? K[14] : K[37]; assign K6[33] = decrypt_int ? K[36] : K[28]; assign K6[34] = decrypt_int ? K[49] : K[45]; assign K6[35] = decrypt_int ? K[51] : K[43]; assign K6[36] = decrypt_int ? K[15] : K[7]; assign K6[37] = decrypt_int ? K[42] : K[38]; assign K6[38] = decrypt_int ? K[22] : K[14]; assign K6[39] = decrypt_int ? K[7] : K[30]; assign K6[40] = decrypt_int ? K[16] : K[8]; assign K6[41] = decrypt_int ? K[31] : K[50]; assign K6[42] = decrypt_int ? K[50] : K[42]; assign K6[43] = decrypt_int ? K[1] : K[52]; assign K6[44] = decrypt_int ? K[28] : K[51]; assign K6[45] = decrypt_int ? K[29] : K[21]; assign K6[46] = decrypt_int ? K[45] : K[9]; assign K6[47] = decrypt_int ? K[23] : K[15]; assign K6[48] = decrypt_int ? K[44] : K[36]; assign K5[1] = decrypt_int ? K[48] : K[39]; assign K5[2] = decrypt_int ? K[12] : K[3]; assign K5[3] = decrypt_int ? K[27] : K[18]; assign K5[4] = decrypt_int ? K[4] : K[27]; assign K5[5] = decrypt_int ? K[39] : K[5]; assign K5[6] = decrypt_int ? K[10] : K[33]; assign K5[7] = decrypt_int ? K[53] : K[19]; assign K5[8] = decrypt_int ? K[32] : K[55]; assign K5[9] = decrypt_int ? K[55] : K[46]; assign K5[10] = decrypt_int ? K[17] : K[40]; assign K5[11] = decrypt_int ? K[40] : K[6]; assign K5[12] = decrypt_int ? K[20] : K[11]; assign K5[13] = decrypt_int ? K[54] : K[20]; assign K5[14] = decrypt_int ? K[26] : K[17]; assign K5[15] = decrypt_int ? K[34] : K[25]; assign K5[16] = decrypt_int ? K[3] : K[26]; assign K5[17] = decrypt_int ? K[18] : K[41]; assign K5[18] = decrypt_int ? K[6] : K[54]; assign K5[19] = decrypt_int ? K[5] : K[53]; assign K5[20] = decrypt_int ? K[24] : K[47]; assign K5[21] = decrypt_int ? K[25] : K[48]; assign K5[22] = decrypt_int ? K[33] : K[24]; assign K5[23] = decrypt_int ? K[41] : K[32]; assign K5[24] = decrypt_int ? K[46] : K[12]; assign K5[25] = decrypt_int ? K[35] : K[30]; assign K5[26] = decrypt_int ? K[2] : K[21]; assign K5[27] = decrypt_int ? K[51] : K[15]; assign K5[28] = decrypt_int ? K[7] : K[2]; assign K5[29] = decrypt_int ? K[22] : K[45]; assign K5[30] = decrypt_int ? K[23] : K[42]; assign K5[31] = decrypt_int ? K[44] : K[8]; assign K5[32] = decrypt_int ? K[28] : K[23]; assign K5[33] = decrypt_int ? K[50] : K[14]; assign K5[34] = decrypt_int ? K[8] : K[31]; assign K5[35] = decrypt_int ? K[38] : K[29]; assign K5[36] = decrypt_int ? K[29] : K[52]; assign K5[37] = decrypt_int ? K[1] : K[51]; assign K5[38] = decrypt_int ? K[36] : K[0]; assign K5[39] = decrypt_int ? K[21] : K[16]; assign K5[40] = decrypt_int ? K[30] : K[49]; assign K5[41] = decrypt_int ? K[45] : K[36]; assign K5[42] = decrypt_int ? K[9] : K[28]; assign K5[43] = decrypt_int ? K[15] : K[38]; assign K5[44] = decrypt_int ? K[42] : K[37]; assign K5[45] = decrypt_int ? K[43] : K[7]; assign K5[46] = decrypt_int ? K[0] : K[50]; assign K5[47] = decrypt_int ? K[37] : K[1]; assign K5[48] = decrypt_int ? K[31] : K[22]; assign K4[1] = decrypt_int ? K[5] : K[25]; assign K4[2] = decrypt_int ? K[26] : K[46]; assign K4[3] = decrypt_int ? K[41] : K[4]; assign K4[4] = decrypt_int ? K[18] : K[13]; assign K4[5] = decrypt_int ? K[53] : K[48]; assign K4[6] = decrypt_int ? K[24] : K[19]; assign K4[7] = decrypt_int ? K[10] : K[5]; assign K4[8] = decrypt_int ? K[46] : K[41]; assign K4[9] = decrypt_int ? K[12] : K[32]; assign K4[10] = decrypt_int ? K[6] : K[26]; assign K4[11] = decrypt_int ? K[54] : K[17]; assign K4[12] = decrypt_int ? K[34] : K[54]; assign K4[13] = decrypt_int ? K[11] : K[6]; assign K4[14] = decrypt_int ? K[40] : K[3]; assign K4[15] = decrypt_int ? K[48] : K[11]; assign K4[16] = decrypt_int ? K[17] : K[12]; assign K4[17] = decrypt_int ? K[32] : K[27]; assign K4[18] = decrypt_int ? K[20] : K[40]; assign K4[19] = decrypt_int ? K[19] : K[39]; assign K4[20] = decrypt_int ? K[13] : K[33]; assign K4[21] = decrypt_int ? K[39] : K[34]; assign K4[22] = decrypt_int ? K[47] : K[10]; assign K4[23] = decrypt_int ? K[55] : K[18]; assign K4[24] = decrypt_int ? K[3] : K[55]; assign K4[25] = decrypt_int ? K[49] : K[16]; assign K4[26] = decrypt_int ? K[16] : K[7]; assign K4[27] = decrypt_int ? K[38] : K[1]; assign K4[28] = decrypt_int ? K[21] : K[43]; assign K4[29] = decrypt_int ? K[36] : K[31]; assign K4[30] = decrypt_int ? K[37] : K[28]; assign K4[31] = decrypt_int ? K[31] : K[49]; assign K4[32] = decrypt_int ? K[42] : K[9]; assign K4[33] = decrypt_int ? K[9] : K[0]; assign K4[34] = decrypt_int ? K[22] : K[44]; assign K4[35] = decrypt_int ? K[52] : K[15]; assign K4[36] = decrypt_int ? K[43] : K[38]; assign K4[37] = decrypt_int ? K[15] : K[37]; assign K4[38] = decrypt_int ? K[50] : K[45]; assign K4[39] = decrypt_int ? K[35] : K[2]; assign K4[40] = decrypt_int ? K[44] : K[35]; assign K4[41] = decrypt_int ? K[0] : K[22]; assign K4[42] = decrypt_int ? K[23] : K[14]; assign K4[43] = decrypt_int ? K[29] : K[51]; assign K4[44] = decrypt_int ? K[1] : K[23]; assign K4[45] = decrypt_int ? K[2] : K[52]; assign K4[46] = decrypt_int ? K[14] : K[36]; assign K4[47] = decrypt_int ? K[51] : K[42]; assign K4[48] = decrypt_int ? K[45] : K[8]; assign K3[1] = decrypt_int ? K[19] : K[11]; assign K3[2] = decrypt_int ? K[40] : K[32]; assign K3[3] = decrypt_int ? K[55] : K[47]; assign K3[4] = decrypt_int ? K[32] : K[24]; assign K3[5] = decrypt_int ? K[10] : K[34]; assign K3[6] = decrypt_int ? K[13] : K[5]; assign K3[7] = decrypt_int ? K[24] : K[48]; assign K3[8] = decrypt_int ? K[3] : K[27]; assign K3[9] = decrypt_int ? K[26] : K[18]; assign K3[10] = decrypt_int ? K[20] : K[12]; assign K3[11] = decrypt_int ? K[11] : K[3]; assign K3[12] = decrypt_int ? K[48] : K[40]; assign K3[13] = decrypt_int ? K[25] : K[17]; assign K3[14] = decrypt_int ? K[54] : K[46]; assign K3[15] = decrypt_int ? K[5] : K[54]; assign K3[16] = decrypt_int ? K[6] : K[55]; assign K3[17] = decrypt_int ? K[46] : K[13]; assign K3[18] = decrypt_int ? K[34] : K[26]; assign K3[19] = decrypt_int ? K[33] : K[25]; assign K3[20] = decrypt_int ? K[27] : K[19]; assign K3[21] = decrypt_int ? K[53] : K[20]; assign K3[22] = decrypt_int ? K[4] : K[53]; assign K3[23] = decrypt_int ? K[12] : K[4]; assign K3[24] = decrypt_int ? K[17] : K[41]; assign K3[25] = decrypt_int ? K[8] : K[2]; assign K3[26] = decrypt_int ? K[30] : K[52]; assign K3[27] = decrypt_int ? K[52] : K[42]; assign K3[28] = decrypt_int ? K[35] : K[29]; assign K3[29] = decrypt_int ? K[50] : K[44]; assign K3[30] = decrypt_int ? K[51] : K[14]; assign K3[31] = decrypt_int ? K[45] : K[35]; assign K3[32] = decrypt_int ? K[1] : K[50]; assign K3[33] = decrypt_int ? K[23] : K[45]; assign K3[34] = decrypt_int ? K[36] : K[30]; assign K3[35] = decrypt_int ? K[7] : K[1]; assign K3[36] = decrypt_int ? K[2] : K[51]; assign K3[37] = decrypt_int ? K[29] : K[23]; assign K3[38] = decrypt_int ? K[9] : K[31]; assign K3[39] = decrypt_int ? K[49] : K[43]; assign K3[40] = decrypt_int ? K[31] : K[21]; assign K3[41] = decrypt_int ? K[14] : K[8]; assign K3[42] = decrypt_int ? K[37] : K[0]; assign K3[43] = decrypt_int ? K[43] : K[37]; assign K3[44] = decrypt_int ? K[15] : K[9]; assign K3[45] = decrypt_int ? K[16] : K[38]; assign K3[46] = decrypt_int ? K[28] : K[22]; assign K3[47] = decrypt_int ? K[38] : K[28]; assign K3[48] = decrypt_int ? K[0] : K[49]; assign K2[1] = decrypt_int ? K[33] : K[54]; assign K2[2] = decrypt_int ? K[54] : K[18]; assign K2[3] = decrypt_int ? K[12] : K[33]; assign K2[4] = decrypt_int ? K[46] : K[10]; assign K2[5] = decrypt_int ? K[24] : K[20]; assign K2[6] = decrypt_int ? K[27] : K[48]; assign K2[7] = decrypt_int ? K[13] : K[34]; assign K2[8] = decrypt_int ? K[17] : K[13]; assign K2[9] = decrypt_int ? K[40] : K[4]; assign K2[10] = decrypt_int ? K[34] : K[55]; assign K2[11] = decrypt_int ? K[25] : K[46]; assign K2[12] = decrypt_int ? K[5] : K[26]; assign K2[13] = decrypt_int ? K[39] : K[3]; assign K2[14] = decrypt_int ? K[11] : K[32]; assign K2[15] = decrypt_int ? K[19] : K[40]; assign K2[16] = decrypt_int ? K[20] : K[41]; assign K2[17] = decrypt_int ? K[3] : K[24]; assign K2[18] = decrypt_int ? K[48] : K[12]; assign K2[19] = decrypt_int ? K[47] : K[11]; assign K2[20] = decrypt_int ? K[41] : K[5]; assign K2[21] = decrypt_int ? K[10] : K[6]; assign K2[22] = decrypt_int ? K[18] : K[39]; assign K2[23] = decrypt_int ? K[26] : K[47]; assign K2[24] = decrypt_int ? K[6] : K[27]; assign K2[25] = decrypt_int ? K[22] : K[43]; assign K2[26] = decrypt_int ? K[44] : K[38]; assign K2[27] = decrypt_int ? K[7] : K[28]; assign K2[28] = decrypt_int ? K[49] : K[15]; assign K2[29] = decrypt_int ? K[9] : K[30]; assign K2[30] = decrypt_int ? K[38] : K[0]; assign K2[31] = decrypt_int ? K[0] : K[21]; assign K2[32] = decrypt_int ? K[15] : K[36]; assign K2[33] = decrypt_int ? K[37] : K[31]; assign K2[34] = decrypt_int ? K[50] : K[16]; assign K2[35] = decrypt_int ? K[21] : K[42]; assign K2[36] = decrypt_int ? K[16] : K[37]; assign K2[37] = decrypt_int ? K[43] : K[9]; assign K2[38] = decrypt_int ? K[23] : K[44]; assign K2[39] = decrypt_int ? K[8] : K[29]; assign K2[40] = decrypt_int ? K[45] : K[7]; assign K2[41] = decrypt_int ? K[28] : K[49]; assign K2[42] = decrypt_int ? K[51] : K[45]; assign K2[43] = decrypt_int ? K[2] : K[23]; assign K2[44] = decrypt_int ? K[29] : K[50]; assign K2[45] = decrypt_int ? K[30] : K[51]; assign K2[46] = decrypt_int ? K[42] : K[8]; assign K2[47] = decrypt_int ? K[52] : K[14]; assign K2[48] = decrypt_int ? K[14] : K[35]; assign K1[1] = decrypt_int ? K[40] : K[47]; assign K1[2] = decrypt_int ? K[4] : K[11]; assign K1[3] = decrypt_int ? K[19] : K[26]; assign K1[4] = decrypt_int ? K[53] : K[3]; assign K1[5] = decrypt_int ? K[6] : K[13]; assign K1[6] = decrypt_int ? K[34] : K[41]; assign K1[7] = decrypt_int ? K[20] : K[27]; assign K1[8] = decrypt_int ? K[24] : K[6]; assign K1[9] = decrypt_int ? K[47] : K[54]; assign K1[10] = decrypt_int ? K[41] : K[48]; assign K1[11] = decrypt_int ? K[32] : K[39]; assign K1[12] = decrypt_int ? K[12] : K[19]; assign K1[13] = decrypt_int ? K[46] : K[53]; assign K1[14] = decrypt_int ? K[18] : K[25]; assign K1[15] = decrypt_int ? K[26] : K[33]; assign K1[16] = decrypt_int ? K[27] : K[34]; assign K1[17] = decrypt_int ? K[10] : K[17]; assign K1[18] = decrypt_int ? K[55] : K[5]; assign K1[19] = decrypt_int ? K[54] : K[4]; assign K1[20] = decrypt_int ? K[48] : K[55]; assign K1[21] = decrypt_int ? K[17] : K[24]; assign K1[22] = decrypt_int ? K[25] : K[32]; assign K1[23] = decrypt_int ? K[33] : K[40]; assign K1[24] = decrypt_int ? K[13] : K[20]; assign K1[25] = decrypt_int ? K[29] : K[36]; assign K1[26] = decrypt_int ? K[51] : K[31]; assign K1[27] = decrypt_int ? K[14] : K[21]; assign K1[28] = decrypt_int ? K[1] : K[8]; assign K1[29] = decrypt_int ? K[16] : K[23]; assign K1[30] = decrypt_int ? K[45] : K[52]; assign K1[31] = decrypt_int ? K[7] : K[14]; assign K1[32] = decrypt_int ? K[22] : K[29]; assign K1[33] = decrypt_int ? K[44] : K[51]; assign K1[34] = decrypt_int ? K[2] : K[9]; assign K1[35] = decrypt_int ? K[28] : K[35]; assign K1[36] = decrypt_int ? K[23] : K[30]; assign K1[37] = decrypt_int ? K[50] : K[2]; assign K1[38] = decrypt_int ? K[30] : K[37]; assign K1[39] = decrypt_int ? K[15] : K[22]; assign K1[40] = decrypt_int ? K[52] : K[0]; assign K1[41] = decrypt_int ? K[35] : K[42]; assign K1[42] = decrypt_int ? K[31] : K[38]; assign K1[43] = decrypt_int ? K[9] : K[16]; assign K1[44] = decrypt_int ? K[36] : K[43]; assign K1[45] = decrypt_int ? K[37] : K[44]; assign K1[46] = decrypt_int ? K[49] : K[1]; assign K1[47] = decrypt_int ? K[0] : K[7]; assign K1[48] = decrypt_int ? K[21] : K[28]; endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox1(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 14; 1: dout = 4; 2: dout = 13; 3: dout = 1; 4: dout = 2; 5: dout = 15; 6: dout = 11; 7: dout = 8; 8: dout = 3; 9: dout = 10; 10: dout = 6; 11: dout = 12; 12: dout = 5; 13: dout = 9; 14: dout = 0; 15: dout = 7; 16: dout = 0; 17: dout = 15; 18: dout = 7; 19: dout = 4; 20: dout = 14; 21: dout = 2; 22: dout = 13; 23: dout = 1; 24: dout = 10; 25: dout = 6; 26: dout = 12; 27: dout = 11; 28: dout = 9; 29: dout = 5; 30: dout = 3; 31: dout = 8; 32: dout = 4; 33: dout = 1; 34: dout = 14; 35: dout = 8; 36: dout = 13; 37: dout = 6; 38: dout = 2; 39: dout = 11; 40: dout = 15; 41: dout = 12; 42: dout = 9; 43: dout = 7; 44: dout = 3; 45: dout = 10; 46: dout = 5; 47: dout = 0; 48: dout = 15; 49: dout = 12; 50: dout = 8; 51: dout = 2; 52: dout = 4; 53: dout = 9; 54: dout = 1; 55: dout = 7; 56: dout = 5; 57: dout = 11; 58: dout = 3; 59: dout = 14; 60: dout = 10; 61: dout = 0; 62: dout = 6; 63: dout = 13; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox2(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 15; 1: dout = 1; 2: dout = 8; 3: dout = 14; 4: dout = 6; 5: dout = 11; 6: dout = 3; 7: dout = 4; 8: dout = 9; 9: dout = 7; 10: dout = 2; 11: dout = 13; 12: dout = 12; 13: dout = 0; 14: dout = 5; 15: dout = 10; 16: dout = 3; 17: dout = 13; 18: dout = 4; 19: dout = 7; 20: dout = 15; 21: dout = 2; 22: dout = 8; 23: dout = 14; 24: dout = 12; 25: dout = 0; 26: dout = 1; 27: dout = 10; 28: dout = 6; 29: dout = 9; 30: dout = 11; 31: dout = 5; 32: dout = 0; 33: dout = 14; 34: dout = 7; 35: dout = 11; 36: dout = 10; 37: dout = 4; 38: dout = 13; 39: dout = 1; 40: dout = 5; 41: dout = 8; 42: dout = 12; 43: dout = 6; 44: dout = 9; 45: dout = 3; 46: dout = 2; 47: dout = 15; 48: dout = 13; 49: dout = 8; 50: dout = 10; 51: dout = 1; 52: dout = 3; 53: dout = 15; 54: dout = 4; 55: dout = 2; 56: dout = 11; 57: dout = 6; 58: dout = 7; 59: dout = 12; 60: dout = 0; 61: dout = 5; 62: dout = 14; 63: dout = 9; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox3(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 10; 1: dout = 0; 2: dout = 9; 3: dout = 14; 4: dout = 6; 5: dout = 3; 6: dout = 15; 7: dout = 5; 8: dout = 1; 9: dout = 13; 10: dout = 12; 11: dout = 7; 12: dout = 11; 13: dout = 4; 14: dout = 2; 15: dout = 8; 16: dout = 13; 17: dout = 7; 18: dout = 0; 19: dout = 9; 20: dout = 3; 21: dout = 4; 22: dout = 6; 23: dout = 10; 24: dout = 2; 25: dout = 8; 26: dout = 5; 27: dout = 14; 28: dout = 12; 29: dout = 11; 30: dout = 15; 31: dout = 1; 32: dout = 13; 33: dout = 6; 34: dout = 4; 35: dout = 9; 36: dout = 8; 37: dout = 15; 38: dout = 3; 39: dout = 0; 40: dout = 11; 41: dout = 1; 42: dout = 2; 43: dout = 12; 44: dout = 5; 45: dout = 10; 46: dout = 14; 47: dout = 7; 48: dout = 1; 49: dout = 10; 50: dout = 13; 51: dout = 0; 52: dout = 6; 53: dout = 9; 54: dout = 8; 55: dout = 7; 56: dout = 4; 57: dout = 15; 58: dout = 14; 59: dout = 3; 60: dout = 11; 61: dout = 5; 62: dout = 2; 63: dout = 12; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox4(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 7; 1: dout = 13; 2: dout = 14; 3: dout = 3; 4: dout = 0; 5: dout = 6; 6: dout = 9; 7: dout = 10; 8: dout = 1; 9: dout = 2; 10: dout = 8; 11: dout = 5; 12: dout = 11; 13: dout = 12; 14: dout = 4; 15: dout = 15; 16: dout = 13; 17: dout = 8; 18: dout = 11; 19: dout = 5; 20: dout = 6; 21: dout = 15; 22: dout = 0; 23: dout = 3; 24: dout = 4; 25: dout = 7; 26: dout = 2; 27: dout = 12; 28: dout = 1; 29: dout = 10; 30: dout = 14; 31: dout = 9; 32: dout = 10; 33: dout = 6; 34: dout = 9; 35: dout = 0; 36: dout = 12; 37: dout = 11; 38: dout = 7; 39: dout = 13; 40: dout = 15; 41: dout = 1; 42: dout = 3; 43: dout = 14; 44: dout = 5; 45: dout = 2; 46: dout = 8; 47: dout = 4; 48: dout = 3; 49: dout = 15; 50: dout = 0; 51: dout = 6; 52: dout = 10; 53: dout = 1; 54: dout = 13; 55: dout = 8; 56: dout = 9; 57: dout = 4; 58: dout = 5; 59: dout = 11; 60: dout = 12; 61: dout = 7; 62: dout = 2; 63: dout = 14; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox5(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 2; 1: dout = 12; 2: dout = 4; 3: dout = 1; 4: dout = 7; 5: dout = 10; 6: dout = 11; 7: dout = 6; 8: dout = 8; 9: dout = 5; 10: dout = 3; 11: dout = 15; 12: dout = 13; 13: dout = 0; 14: dout = 14; 15: dout = 9; 16: dout = 14; 17: dout = 11; 18: dout = 2; 19: dout = 12; 20: dout = 4; 21: dout = 7; 22: dout = 13; 23: dout = 1; 24: dout = 5; 25: dout = 0; 26: dout = 15; 27: dout = 10; 28: dout = 3; 29: dout = 9; 30: dout = 8; 31: dout = 6; 32: dout = 4; 33: dout = 2; 34: dout = 1; 35: dout = 11; 36: dout = 10; 37: dout = 13; 38: dout = 7; 39: dout = 8; 40: dout = 15; 41: dout = 9; 42: dout = 12; 43: dout = 5; 44: dout = 6; 45: dout = 3; 46: dout = 0; 47: dout = 14; 48: dout = 11; 49: dout = 8; 50: dout = 12; 51: dout = 7; 52: dout = 1; 53: dout = 14; 54: dout = 2; 55: dout = 13; 56: dout = 6; 57: dout = 15; 58: dout = 0; 59: dout = 9; 60: dout = 10; 61: dout = 4; 62: dout = 5; 63: dout = 3; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox6(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 12; 1: dout = 1; 2: dout = 10; 3: dout = 15; 4: dout = 9; 5: dout = 2; 6: dout = 6; 7: dout = 8; 8: dout = 0; 9: dout = 13; 10: dout = 3; 11: dout = 4; 12: dout = 14; 13: dout = 7; 14: dout = 5; 15: dout = 11; 16: dout = 10; 17: dout = 15; 18: dout = 4; 19: dout = 2; 20: dout = 7; 21: dout = 12; 22: dout = 9; 23: dout = 5; 24: dout = 6; 25: dout = 1; 26: dout = 13; 27: dout = 14; 28: dout = 0; 29: dout = 11; 30: dout = 3; 31: dout = 8; 32: dout = 9; 33: dout = 14; 34: dout = 15; 35: dout = 5; 36: dout = 2; 37: dout = 8; 38: dout = 12; 39: dout = 3; 40: dout = 7; 41: dout = 0; 42: dout = 4; 43: dout = 10; 44: dout = 1; 45: dout = 13; 46: dout = 11; 47: dout = 6; 48: dout = 4; 49: dout = 3; 50: dout = 2; 51: dout = 12; 52: dout = 9; 53: dout = 5; 54: dout = 15; 55: dout = 10; 56: dout = 11; 57: dout = 14; 58: dout = 1; 59: dout = 7; 60: dout = 6; 61: dout = 0; 62: dout = 8; 63: dout = 13; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox7(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 4; 1: dout = 11; 2: dout = 2; 3: dout = 14; 4: dout = 15; 5: dout = 0; 6: dout = 8; 7: dout = 13; 8: dout = 3; 9: dout = 12; 10: dout = 9; 11: dout = 7; 12: dout = 5; 13: dout = 10; 14: dout = 6; 15: dout = 1; 16: dout = 13; 17: dout = 0; 18: dout = 11; 19: dout = 7; 20: dout = 4; 21: dout = 9; 22: dout = 1; 23: dout = 10; 24: dout = 14; 25: dout = 3; 26: dout = 5; 27: dout = 12; 28: dout = 2; 29: dout = 15; 30: dout = 8; 31: dout = 6; 32: dout = 1; 33: dout = 4; 34: dout = 11; 35: dout = 13; 36: dout = 12; 37: dout = 3; 38: dout = 7; 39: dout = 14; 40: dout = 10; 41: dout = 15; 42: dout = 6; 43: dout = 8; 44: dout = 0; 45: dout = 5; 46: dout = 9; 47: dout = 2; 48: dout = 6; 49: dout = 11; 50: dout = 13; 51: dout = 8; 52: dout = 1; 53: dout = 4; 54: dout = 10; 55: dout = 7; 56: dout = 9; 57: dout = 5; 58: dout = 0; 59: dout = 15; 60: dout = 14; 61: dout = 2; 62: dout = 3; 63: dout = 12; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox8(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 13; 1: dout = 2; 2: dout = 8; 3: dout = 4; 4: dout = 6; 5: dout = 15; 6: dout = 11; 7: dout = 1; 8: dout = 10; 9: dout = 9; 10: dout = 3; 11: dout = 14; 12: dout = 5; 13: dout = 0; 14: dout = 12; 15: dout = 7; 16: dout = 1; 17: dout = 15; 18: dout = 13; 19: dout = 8; 20: dout = 10; 21: dout = 3; 22: dout = 7; 23: dout = 4; 24: dout = 12; 25: dout = 5; 26: dout = 6; 27: dout = 11; 28: dout = 0; 29: dout = 14; 30: dout = 9; 31: dout = 2; 32: dout = 7; 33: dout = 11; 34: dout = 4; 35: dout = 1; 36: dout = 9; 37: dout = 12; 38: dout = 14; 39: dout = 2; 40: dout = 0; 41: dout = 6; 42: dout = 10; 43: dout = 13; 44: dout = 15; 45: dout = 3; 46: dout = 5; 47: dout = 8; 48: dout = 2; 49: dout = 1; 50: dout = 14; 51: dout = 7; 52: dout = 4; 53: dout = 10; 54: dout = 8; 55: dout = 13; 56: dout = 15; 57: dout = 12; 58: dout = 9; 59: dout = 0; 60: dout = 3; 61: dout = 5; 62: dout = 6; 63: dout = 11; endcase end endmodule
/* * This source file contains a Verilog description of an IP core * automatically generated by the SPIRAL HDL Generator. * * This product includes a hardware design developed by Carnegie Mellon University. * * Copyright (c) 2005-2011 by Peter A. Milder for the SPIRAL Project, * Carnegie Mellon University * * For more information, see the SPIRAL project website at: * http://www.spiral.net * * This design is provided for internal, non-commercial research use only * and is not for redistribution, with or without modifications. * * You may not use the name "Carnegie Mellon University" or derivations * thereof to endorse or promote products derived from this software. * * THE SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY WARRANTY OF ANY KIND, EITHER * EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO ANY WARRANTY * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS OR BE ERROR-FREE AND ANY * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, * TITLE, OR NON-INFRINGEMENT. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY * BE LIABLE FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO DIRECT, INDIRECT, * SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, OR IN * ANY WAY CONNECTED WITH THIS SOFTWARE (WHETHER OR NOT BASED UPON WARRANTY, * CONTRACT, TORT OR OTHERWISE). * */ // Input/output stream: 2 complex words per cycle // Throughput: one transform every 32 cycles // Latency: 332 cycles // Resources required: // 20 multipliers (16 x 16 bit) // 34 adders (16 x 16 bit) // 4 RAMs (16 words, 32 bits per word) // 4 RAMs (8 words, 32 bits per word) // 12 RAMs (64 words, 32 bits per word) // 4 RAMs (32 words, 32 bits per word) // 2 ROMs (32 words, 16 bits per word) // 2 ROMs (8 words, 16 bits per word) // 12 ROMs (32 words, 5 bits per word) // 2 ROMs (16 words, 16 bits per word) // Generated on Tue Sep 04 00:43:02 EDT 2018 // Latency: 332 clock cycles // Throughput: 1 transform every 32 cycles // We use an interleaved complex data format. X0 represents the // real portion of the first input, and X1 represents the imaginary // portion. The X variables are system inputs and the Y variables // are system outputs. // The design uses a system of flag signals to indicate the // beginning of the input and output data streams. The 'next' // input (asserted high), is used to instruct the system that the // input stream will begin on the following cycle. // This system has a 'gap' of 32 cycles. This means that // 32 cycles must elapse between the beginning of the input // vectors. // The output signal 'next_out' (also asserted high) indicates // that the output vector will begin streaming out of the system // on the following cycle. // The system has a latency of 332 cycles. This means that // the 'next_out' will be asserted 332 cycles after the user // asserts 'next'. // The simple testbench below will demonstrate the timing for loading // and unloading data vectors. // The system reset signal is asserted high. // Please note: when simulating floating point code, you must include // Xilinx's DSP slice simulation module. // Latency: 332 // Gap: 32 // module_name_is:dft_top module dft_top(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [15:0] t0_0; wire [15:0] t0_1; wire [15:0] t0_2; wire [15:0] t0_3; wire next_0; wire [15:0] t1_0; wire [15:0] t1_1; wire [15:0] t1_2; wire [15:0] t1_3; wire next_1; wire [15:0] t2_0; wire [15:0] t2_1; wire [15:0] t2_2; wire [15:0] t2_3; wire next_2; wire [15:0] t3_0; wire [15:0] t3_1; wire [15:0] t3_2; wire [15:0] t3_3; wire next_3; wire [15:0] t4_0; wire [15:0] t4_1; wire [15:0] t4_2; wire [15:0] t4_3; wire next_4; wire [15:0] t5_0; wire [15:0] t5_1; wire [15:0] t5_2; wire [15:0] t5_3; wire next_5; wire [15:0] t6_0; wire [15:0] t6_1; wire [15:0] t6_2; wire [15:0] t6_3; wire next_6; wire [15:0] t7_0; wire [15:0] t7_1; wire [15:0] t7_2; wire [15:0] t7_3; wire next_7; wire [15:0] t8_0; wire [15:0] t8_1; wire [15:0] t8_2; wire [15:0] t8_3; wire next_8; wire [15:0] t9_0; wire [15:0] t9_1; wire [15:0] t9_2; wire [15:0] t9_3; wire next_9; wire [15:0] t10_0; wire [15:0] t10_1; wire [15:0] t10_2; wire [15:0] t10_3; wire next_10; wire [15:0] t11_0; wire [15:0] t11_1; wire [15:0] t11_2; wire [15:0] t11_3; wire next_11; wire [15:0] t12_0; wire [15:0] t12_1; wire [15:0] t12_2; wire [15:0] t12_3; wire next_12; wire [15:0] t13_0; wire [15:0] t13_1; wire [15:0] t13_2; wire [15:0] t13_3; wire next_13; wire [15:0] t14_0; wire [15:0] t14_1; wire [15:0] t14_2; wire [15:0] t14_3; wire next_14; wire [15:0] t15_0; wire [15:0] t15_1; wire [15:0] t15_2; wire [15:0] t15_3; wire next_15; wire [15:0] t16_0; wire [15:0] t16_1; wire [15:0] t16_2; wire [15:0] t16_3; wire next_16; wire [15:0] t17_0; wire [15:0] t17_1; wire [15:0] t17_2; wire [15:0] t17_3; wire next_17; wire [15:0] t18_0; wire [15:0] t18_1; wire [15:0] t18_2; wire [15:0] t18_3; wire next_18; assign t0_0 = X0; assign Y0 = t18_0; assign t0_1 = X1; assign Y1 = t18_1; assign t0_2 = X2; assign Y2 = t18_2; assign t0_3 = X3; assign Y3 = t18_3; assign next_0 = next; assign next_out = next_18; // latency=68, gap=32 rc82445 stage0(.clk(clk), .reset(reset), .next(next_0), .next_out(next_1), .X0(t0_0), .Y0(t1_0), .X1(t0_1), .Y1(t1_1), .X2(t0_2), .Y2(t1_2), .X3(t0_3), .Y3(t1_3)); // latency=2, gap=32 codeBlock82447 stage1(.clk(clk), .reset(reset), .next_in(next_1), .next_out(next_2), .X0_in(t1_0), .Y0(t2_0), .X1_in(t1_1), .Y1(t2_1), .X2_in(t1_2), .Y2(t2_2), .X3_in(t1_3), .Y3(t2_3)); // latency=8, gap=32 rc82529 stage2(.clk(clk), .reset(reset), .next(next_2), .next_out(next_3), .X0(t2_0), .Y0(t3_0), .X1(t2_1), .Y1(t3_1), .X2(t2_2), .Y2(t3_2), .X3(t2_3), .Y3(t3_3)); // latency=8, gap=32 DirSum_82710 stage3(.next(next_3), .clk(clk), .reset(reset), .next_out(next_4), .X0(t3_0), .Y0(t4_0), .X1(t3_1), .Y1(t4_1), .X2(t3_2), .Y2(t4_2), .X3(t3_3), .Y3(t4_3)); // latency=2, gap=32 codeBlock82713 stage4(.clk(clk), .reset(reset), .next_in(next_4), .next_out(next_5), .X0_in(t4_0), .Y0(t5_0), .X1_in(t4_1), .Y1(t5_1), .X2_in(t4_2), .Y2(t5_2), .X3_in(t4_3), .Y3(t5_3)); // latency=12, gap=32 rc82795 stage5(.clk(clk), .reset(reset), .next(next_5), .next_out(next_6), .X0(t5_0), .Y0(t6_0), .X1(t5_1), .Y1(t6_1), .X2(t5_2), .Y2(t6_2), .X3(t5_3), .Y3(t6_3)); // latency=8, gap=32 DirSum_82984 stage6(.next(next_6), .clk(clk), .reset(reset), .next_out(next_7), .X0(t6_0), .Y0(t7_0), .X1(t6_1), .Y1(t7_1), .X2(t6_2), .Y2(t7_2), .X3(t6_3), .Y3(t7_3)); // latency=2, gap=32 codeBlock82987 stage7(.clk(clk), .reset(reset), .next_in(next_7), .next_out(next_8), .X0_in(t7_0), .Y0(t8_0), .X1_in(t7_1), .Y1(t8_1), .X2_in(t7_2), .Y2(t8_2), .X3_in(t7_3), .Y3(t8_3)); // latency=20, gap=32 rc83069 stage8(.clk(clk), .reset(reset), .next(next_8), .next_out(next_9), .X0(t8_0), .Y0(t9_0), .X1(t8_1), .Y1(t9_1), .X2(t8_2), .Y2(t9_2), .X3(t8_3), .Y3(t9_3)); // latency=8, gap=32 DirSum_83274 stage9(.next(next_9), .clk(clk), .reset(reset), .next_out(next_10), .X0(t9_0), .Y0(t10_0), .X1(t9_1), .Y1(t10_1), .X2(t9_2), .Y2(t10_2), .X3(t9_3), .Y3(t10_3)); // latency=2, gap=32 codeBlock83277 stage10(.clk(clk), .reset(reset), .next_in(next_10), .next_out(next_11), .X0_in(t10_0), .Y0(t11_0), .X1_in(t10_1), .Y1(t11_1), .X2_in(t10_2), .Y2(t11_2), .X3_in(t10_3), .Y3(t11_3)); // latency=36, gap=32 rc83359 stage11(.clk(clk), .reset(reset), .next(next_11), .next_out(next_12), .X0(t11_0), .Y0(t12_0), .X1(t11_1), .Y1(t12_1), .X2(t11_2), .Y2(t12_2), .X3(t11_3), .Y3(t12_3)); // latency=8, gap=32 DirSum_83596 stage12(.next(next_12), .clk(clk), .reset(reset), .next_out(next_13), .X0(t12_0), .Y0(t13_0), .X1(t12_1), .Y1(t13_1), .X2(t12_2), .Y2(t13_2), .X3(t12_3), .Y3(t13_3)); // latency=2, gap=32 codeBlock83599 stage13(.clk(clk), .reset(reset), .next_in(next_13), .next_out(next_14), .X0_in(t13_0), .Y0(t14_0), .X1_in(t13_1), .Y1(t14_1), .X2_in(t13_2), .Y2(t14_2), .X3_in(t13_3), .Y3(t14_3)); // latency=68, gap=32 rc83681 stage14(.clk(clk), .reset(reset), .next(next_14), .next_out(next_15), .X0(t14_0), .Y0(t15_0), .X1(t14_1), .Y1(t15_1), .X2(t14_2), .Y2(t15_2), .X3(t14_3), .Y3(t15_3)); // latency=8, gap=32 DirSum_83981 stage15(.next(next_15), .clk(clk), .reset(reset), .next_out(next_16), .X0(t15_0), .Y0(t16_0), .X1(t15_1), .Y1(t16_1), .X2(t15_2), .Y2(t16_2), .X3(t15_3), .Y3(t16_3)); // latency=2, gap=32 codeBlock83984 stage16(.clk(clk), .reset(reset), .next_in(next_16), .next_out(next_17), .X0_in(t16_0), .Y0(t17_0), .X1_in(t16_1), .Y1(t17_1), .X2_in(t16_2), .Y2(t17_2), .X3_in(t16_3), .Y3(t17_3)); // latency=68, gap=32 rc84066 stage17(.clk(clk), .reset(reset), .next(next_17), .next_out(next_18), .X0(t17_0), .Y0(t18_0), .X1(t17_1), .Y1(t18_1), .X2(t17_2), .Y2(t18_2), .X3(t17_3), .Y3(t18_3)); endmodule // Latency: 68 // Gap: 32 module rc82445(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm82443 instPerm85011(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet82443(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [4:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 5'd0: control <= 1'b1; 5'd1: control <= 1'b1; 5'd2: control <= 1'b1; 5'd3: control <= 1'b1; 5'd4: control <= 1'b1; 5'd5: control <= 1'b1; 5'd6: control <= 1'b1; 5'd7: control <= 1'b1; 5'd8: control <= 1'b1; 5'd9: control <= 1'b1; 5'd10: control <= 1'b1; 5'd11: control <= 1'b1; 5'd12: control <= 1'b1; 5'd13: control <= 1'b1; 5'd14: control <= 1'b1; 5'd15: control <= 1'b1; 5'd16: control <= 1'b0; 5'd17: control <= 1'b0; 5'd18: control <= 1'b0; 5'd19: control <= 1'b0; 5'd20: control <= 1'b0; 5'd21: control <= 1'b0; 5'd22: control <= 1'b0; 5'd23: control <= 1'b0; 5'd24: control <= 1'b0; 5'd25: control <= 1'b0; 5'd26: control <= 1'b0; 5'd27: control <= 1'b0; 5'd28: control <= 1'b0; 5'd29: control <= 1'b0; 5'd30: control <= 1'b0; 5'd31: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 68 // Gap: 32 module perm82443(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 32; parameter addrbits = 5; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm0; assign tm0 = 0; shiftRegFIFO #(3, 1) shiftFIFO_85016(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85017(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); nextReg #(31, 5) nextReg_85028(.X(next), .Y(next2), .reset(reset), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_85029(.X(next2), .Y(next3), .clk(clk)); nextReg #(32, 5) nextReg_85032(.X(next3), .Y(next4), .reset(reset), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85033(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(31, 1) shiftFIFO_85036(.X(tm0), .Y(tm0_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_85039(.X(tm0_d), .Y(tm0_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 5) shiftFIFO_85044(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm0_d, s1rdloc}) {1'd0, 5'd0}: s1rd0 <= 16; {1'd0, 5'd1}: s1rd0 <= 24; {1'd0, 5'd2}: s1rd0 <= 20; {1'd0, 5'd3}: s1rd0 <= 28; {1'd0, 5'd4}: s1rd0 <= 18; {1'd0, 5'd5}: s1rd0 <= 26; {1'd0, 5'd6}: s1rd0 <= 22; {1'd0, 5'd7}: s1rd0 <= 30; {1'd0, 5'd8}: s1rd0 <= 17; {1'd0, 5'd9}: s1rd0 <= 25; {1'd0, 5'd10}: s1rd0 <= 21; {1'd0, 5'd11}: s1rd0 <= 29; {1'd0, 5'd12}: s1rd0 <= 19; {1'd0, 5'd13}: s1rd0 <= 27; {1'd0, 5'd14}: s1rd0 <= 23; {1'd0, 5'd15}: s1rd0 <= 31; {1'd0, 5'd16}: s1rd0 <= 0; {1'd0, 5'd17}: s1rd0 <= 8; {1'd0, 5'd18}: s1rd0 <= 4; {1'd0, 5'd19}: s1rd0 <= 12; {1'd0, 5'd20}: s1rd0 <= 2; {1'd0, 5'd21}: s1rd0 <= 10; {1'd0, 5'd22}: s1rd0 <= 6; {1'd0, 5'd23}: s1rd0 <= 14; {1'd0, 5'd24}: s1rd0 <= 1; {1'd0, 5'd25}: s1rd0 <= 9; {1'd0, 5'd26}: s1rd0 <= 5; {1'd0, 5'd27}: s1rd0 <= 13; {1'd0, 5'd28}: s1rd0 <= 3; {1'd0, 5'd29}: s1rd0 <= 11; {1'd0, 5'd30}: s1rd0 <= 7; {1'd0, 5'd31}: s1rd0 <= 15; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm0_d, s1rdloc}) {1'd0, 5'd0}: s1rd1 <= 0; {1'd0, 5'd1}: s1rd1 <= 8; {1'd0, 5'd2}: s1rd1 <= 4; {1'd0, 5'd3}: s1rd1 <= 12; {1'd0, 5'd4}: s1rd1 <= 2; {1'd0, 5'd5}: s1rd1 <= 10; {1'd0, 5'd6}: s1rd1 <= 6; {1'd0, 5'd7}: s1rd1 <= 14; {1'd0, 5'd8}: s1rd1 <= 1; {1'd0, 5'd9}: s1rd1 <= 9; {1'd0, 5'd10}: s1rd1 <= 5; {1'd0, 5'd11}: s1rd1 <= 13; {1'd0, 5'd12}: s1rd1 <= 3; {1'd0, 5'd13}: s1rd1 <= 11; {1'd0, 5'd14}: s1rd1 <= 7; {1'd0, 5'd15}: s1rd1 <= 15; {1'd0, 5'd16}: s1rd1 <= 16; {1'd0, 5'd17}: s1rd1 <= 24; {1'd0, 5'd18}: s1rd1 <= 20; {1'd0, 5'd19}: s1rd1 <= 28; {1'd0, 5'd20}: s1rd1 <= 18; {1'd0, 5'd21}: s1rd1 <= 26; {1'd0, 5'd22}: s1rd1 <= 22; {1'd0, 5'd23}: s1rd1 <= 30; {1'd0, 5'd24}: s1rd1 <= 17; {1'd0, 5'd25}: s1rd1 <= 25; {1'd0, 5'd26}: s1rd1 <= 21; {1'd0, 5'd27}: s1rd1 <= 29; {1'd0, 5'd28}: s1rd1 <= 19; {1'd0, 5'd29}: s1rd1 <= 27; {1'd0, 5'd30}: s1rd1 <= 23; {1'd0, 5'd31}: s1rd1 <= 31; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet82443 sw(tm0_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm0_dd, writeCycle}) {1'd0, 5'd0}: s2wr0 <= 16; {1'd0, 5'd1}: s2wr0 <= 17; {1'd0, 5'd2}: s2wr0 <= 18; {1'd0, 5'd3}: s2wr0 <= 19; {1'd0, 5'd4}: s2wr0 <= 20; {1'd0, 5'd5}: s2wr0 <= 21; {1'd0, 5'd6}: s2wr0 <= 22; {1'd0, 5'd7}: s2wr0 <= 23; {1'd0, 5'd8}: s2wr0 <= 24; {1'd0, 5'd9}: s2wr0 <= 25; {1'd0, 5'd10}: s2wr0 <= 26; {1'd0, 5'd11}: s2wr0 <= 27; {1'd0, 5'd12}: s2wr0 <= 28; {1'd0, 5'd13}: s2wr0 <= 29; {1'd0, 5'd14}: s2wr0 <= 30; {1'd0, 5'd15}: s2wr0 <= 31; {1'd0, 5'd16}: s2wr0 <= 0; {1'd0, 5'd17}: s2wr0 <= 1; {1'd0, 5'd18}: s2wr0 <= 2; {1'd0, 5'd19}: s2wr0 <= 3; {1'd0, 5'd20}: s2wr0 <= 4; {1'd0, 5'd21}: s2wr0 <= 5; {1'd0, 5'd22}: s2wr0 <= 6; {1'd0, 5'd23}: s2wr0 <= 7; {1'd0, 5'd24}: s2wr0 <= 8; {1'd0, 5'd25}: s2wr0 <= 9; {1'd0, 5'd26}: s2wr0 <= 10; {1'd0, 5'd27}: s2wr0 <= 11; {1'd0, 5'd28}: s2wr0 <= 12; {1'd0, 5'd29}: s2wr0 <= 13; {1'd0, 5'd30}: s2wr0 <= 14; {1'd0, 5'd31}: s2wr0 <= 15; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm0_dd, writeCycle}) {1'd0, 5'd0}: s2wr1 <= 0; {1'd0, 5'd1}: s2wr1 <= 1; {1'd0, 5'd2}: s2wr1 <= 2; {1'd0, 5'd3}: s2wr1 <= 3; {1'd0, 5'd4}: s2wr1 <= 4; {1'd0, 5'd5}: s2wr1 <= 5; {1'd0, 5'd6}: s2wr1 <= 6; {1'd0, 5'd7}: s2wr1 <= 7; {1'd0, 5'd8}: s2wr1 <= 8; {1'd0, 5'd9}: s2wr1 <= 9; {1'd0, 5'd10}: s2wr1 <= 10; {1'd0, 5'd11}: s2wr1 <= 11; {1'd0, 5'd12}: s2wr1 <= 12; {1'd0, 5'd13}: s2wr1 <= 13; {1'd0, 5'd14}: s2wr1 <= 14; {1'd0, 5'd15}: s2wr1 <= 15; {1'd0, 5'd16}: s2wr1 <= 16; {1'd0, 5'd17}: s2wr1 <= 17; {1'd0, 5'd18}: s2wr1 <= 18; {1'd0, 5'd19}: s2wr1 <= 19; {1'd0, 5'd20}: s2wr1 <= 20; {1'd0, 5'd21}: s2wr1 <= 21; {1'd0, 5'd22}: s2wr1 <= 22; {1'd0, 5'd23}: s2wr1 <= 23; {1'd0, 5'd24}: s2wr1 <= 24; {1'd0, 5'd25}: s2wr1 <= 25; {1'd0, 5'd26}: s2wr1 <= 26; {1'd0, 5'd27}: s2wr1 <= 27; {1'd0, 5'd28}: s2wr1 <= 28; {1'd0, 5'd29}: s2wr1 <= 29; {1'd0, 5'd30}: s2wr1 <= 30; {1'd0, 5'd31}: s2wr1 <= 31; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule module memMod(in, out, inAddr, outAddr, writeSel, clk); parameter depth=1024, width=16, logDepth=10; input [width-1:0] in; input [logDepth-1:0] inAddr, outAddr; input writeSel, clk; output [width-1:0] out; reg [width-1:0] out; // synthesis attribute ram_style of mem is block reg [width-1:0] mem[depth-1:0]; always @(posedge clk) begin out <= mem[outAddr]; if (writeSel) mem[inAddr] <= in; end endmodule module memMod_dist(in, out, inAddr, outAddr, writeSel, clk); parameter depth=1024, width=16, logDepth=10; input [width-1:0] in; input [logDepth-1:0] inAddr, outAddr; input writeSel, clk; output [width-1:0] out; reg [width-1:0] out; // synthesis attribute ram_style of mem is distributed reg [width-1:0] mem[depth-1:0]; always @(posedge clk) begin out <= mem[outAddr]; if (writeSel) mem[inAddr] <= in; end endmodule module shiftRegFIFO(X, Y, clk); parameter depth=1, width=1; output [width-1:0] Y; input [width-1:0] X; input clk; reg [width-1:0] mem [depth-1:0]; integer index; assign Y = mem[depth-1]; always @ (posedge clk) begin for(index=1;index<depth;index=index+1) begin mem[index] <= mem[index-1]; end mem[0]<=X; end endmodule module nextReg(X, Y, reset, clk); parameter depth=2, logDepth=1; output Y; input X; input clk, reset; reg [logDepth:0] count; reg active; assign Y = (count == depth) ? 1 : 0; always @ (posedge clk) begin if (reset == 1) begin count <= 0; active <= 0; end else if (X == 1) begin active <= 1; count <= 1; end else if (count == depth) begin count <= 0; active <= 0; end else if (active) count <= count+1; end endmodule // Latency: 2 // Gap: 1 module codeBlock82447(clk, reset, next_in, next_out, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(1, 1) shiftFIFO_85051(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a309; wire signed [15:0] a310; wire signed [15:0] a311; wire signed [15:0] a312; wire signed [15:0] t141; wire signed [15:0] t142; wire signed [15:0] t143; wire signed [15:0] t144; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; assign a309 = X0; assign a310 = X2; assign a311 = X1; assign a312 = X3; assign Y0 = t141; assign Y1 = t142; assign Y2 = t143; assign Y3 = t144; addfxp #(16, 1) add82459(.a(a309), .b(a310), .clk(clk), .q(t141)); // 0 addfxp #(16, 1) add82474(.a(a311), .b(a312), .clk(clk), .q(t142)); // 0 subfxp #(16, 1) sub82489(.a(a309), .b(a310), .clk(clk), .q(t143)); // 0 subfxp #(16, 1) sub82504(.a(a311), .b(a312), .clk(clk), .q(t144)); // 0 always @(posedge clk) begin if (reset == 1) begin end else begin X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; end end endmodule // Latency: 8 // Gap: 2 module rc82529(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm82527 instPerm85052(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet82527(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [0:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 1'd0: control <= 1'b1; 1'd1: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 8 // Gap: 2 module perm82527(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 2; parameter addrbits = 1; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm1; assign tm1 = 0; shiftRegFIFO #(3, 1) shiftFIFO_85057(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85058(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); shiftRegFIFO #(1, 1) shiftFIFO_85067(.X(next), .Y(next2), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_85068(.X(next2), .Y(next3), .clk(clk)); shiftRegFIFO #(2, 1) shiftFIFO_85069(.X(next3), .Y(next4), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85070(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85073(.X(tm1), .Y(tm1_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_85076(.X(tm1_d), .Y(tm1_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 1) shiftFIFO_85081(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm1_d, s1rdloc}) {1'd0, 1'd0}: s1rd0 <= 1; {1'd0, 1'd1}: s1rd0 <= 0; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm1_d, s1rdloc}) {1'd0, 1'd0}: s1rd1 <= 0; {1'd0, 1'd1}: s1rd1 <= 1; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet82527 sw(tm1_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm1_dd, writeCycle}) {1'd0, 1'd0}: s2wr0 <= 1; {1'd0, 1'd1}: s2wr0 <= 0; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm1_dd, writeCycle}) {1'd0, 1'd0}: s2wr1 <= 0; {1'd0, 1'd1}: s2wr1 <= 1; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule // Latency: 8 // Gap: 2 module DirSum_82710(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; reg [0:0] i5; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; always @(posedge clk) begin if (reset == 1) begin i5 <= 0; end else begin if (next == 1) i5 <= 0; else if (i5 == 1) i5 <= 0; else i5 <= i5 + 1; end end codeBlock82532 codeBlockIsnt85082(.clk(clk), .reset(reset), .next_in(next), .next_out(next_out), .i5_in(i5), .X0_in(X0), .Y0(Y0), .X1_in(X1), .Y1(Y1), .X2_in(X2), .Y2(Y2), .X3_in(X3), .Y3(Y3)); endmodule module D18_82700(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [0:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h4000; 1: out3 <= 16'h0; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule module D20_82708(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [0:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h0; 1: out3 <= 16'hc000; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule // Latency: 8 // Gap: 1 module codeBlock82532(clk, reset, next_in, next_out, i5_in, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [0:0] i5_in; reg [0:0] i5; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(7, 1) shiftFIFO_85085(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a293; wire signed [15:0] a282; wire signed [15:0] a296; wire signed [15:0] a286; wire signed [15:0] a297; wire signed [15:0] a298; reg signed [15:0] tm137; reg signed [15:0] tm141; reg signed [15:0] tm153; reg signed [15:0] tm160; reg signed [15:0] tm138; reg signed [15:0] tm142; reg signed [15:0] tm154; reg signed [15:0] tm161; wire signed [15:0] tm4; wire signed [15:0] a287; wire signed [15:0] tm5; wire signed [15:0] a289; reg signed [15:0] tm139; reg signed [15:0] tm143; reg signed [15:0] tm155; reg signed [15:0] tm162; reg signed [15:0] tm31; reg signed [15:0] tm32; reg signed [15:0] tm140; reg signed [15:0] tm144; reg signed [15:0] tm156; reg signed [15:0] tm163; reg signed [15:0] tm157; reg signed [15:0] tm164; wire signed [15:0] a288; wire signed [15:0] a290; wire signed [15:0] a291; wire signed [15:0] a292; reg signed [15:0] tm158; reg signed [15:0] tm165; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; reg signed [15:0] tm159; reg signed [15:0] tm166; assign a293 = X0; assign a282 = a293; assign a296 = X1; assign a286 = a296; assign a297 = X2; assign a298 = X3; assign a287 = tm4; assign a289 = tm5; assign Y0 = tm159; assign Y1 = tm166; D18_82700 instD18inst0_82700(.addr(i5[0:0]), .out(tm4), .clk(clk)); D20_82708 instD20inst0_82708(.addr(i5[0:0]), .out(tm5), .clk(clk)); multfix #(16, 2) m82631(.a(tm31), .b(tm140), .clk(clk), .q_sc(a288), .q_unsc(), .rst(reset)); multfix #(16, 2) m82653(.a(tm32), .b(tm144), .clk(clk), .q_sc(a290), .q_unsc(), .rst(reset)); multfix #(16, 2) m82671(.a(tm32), .b(tm140), .clk(clk), .q_sc(a291), .q_unsc(), .rst(reset)); multfix #(16, 2) m82682(.a(tm31), .b(tm144), .clk(clk), .q_sc(a292), .q_unsc(), .rst(reset)); subfxp #(16, 1) sub82660(.a(a288), .b(a290), .clk(clk), .q(Y2)); // 6 addfxp #(16, 1) add82689(.a(a291), .b(a292), .clk(clk), .q(Y3)); // 6 always @(posedge clk) begin if (reset == 1) begin tm31 <= 0; tm140 <= 0; tm32 <= 0; tm144 <= 0; tm32 <= 0; tm140 <= 0; tm31 <= 0; tm144 <= 0; end else begin i5 <= i5_in; X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; tm137 <= a297; tm141 <= a298; tm153 <= a282; tm160 <= a286; tm138 <= tm137; tm142 <= tm141; tm154 <= tm153; tm161 <= tm160; tm139 <= tm138; tm143 <= tm142; tm155 <= tm154; tm162 <= tm161; tm31 <= a287; tm32 <= a289; tm140 <= tm139; tm144 <= tm143; tm156 <= tm155; tm163 <= tm162; tm157 <= tm156; tm164 <= tm163; tm158 <= tm157; tm165 <= tm164; tm159 <= tm158; tm166 <= tm165; end end endmodule // Latency: 2 // Gap: 1 module codeBlock82713(clk, reset, next_in, next_out, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(1, 1) shiftFIFO_85088(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a249; wire signed [15:0] a250; wire signed [15:0] a251; wire signed [15:0] a252; wire signed [15:0] t117; wire signed [15:0] t118; wire signed [15:0] t119; wire signed [15:0] t120; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; assign a249 = X0; assign a250 = X2; assign a251 = X1; assign a252 = X3; assign Y0 = t117; assign Y1 = t118; assign Y2 = t119; assign Y3 = t120; addfxp #(16, 1) add82725(.a(a249), .b(a250), .clk(clk), .q(t117)); // 0 addfxp #(16, 1) add82740(.a(a251), .b(a252), .clk(clk), .q(t118)); // 0 subfxp #(16, 1) sub82755(.a(a249), .b(a250), .clk(clk), .q(t119)); // 0 subfxp #(16, 1) sub82770(.a(a251), .b(a252), .clk(clk), .q(t120)); // 0 always @(posedge clk) begin if (reset == 1) begin end else begin X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; end end endmodule // Latency: 12 // Gap: 4 module rc82795(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm82793 instPerm85089(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet82793(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [1:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 2'd0: control <= 1'b1; 2'd1: control <= 1'b1; 2'd2: control <= 1'b0; 2'd3: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 12 // Gap: 4 module perm82793(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 4; parameter addrbits = 2; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm6; assign tm6 = 0; shiftRegFIFO #(3, 1) shiftFIFO_85094(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85095(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); shiftRegFIFO #(3, 1) shiftFIFO_85104(.X(next), .Y(next2), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_85105(.X(next2), .Y(next3), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_85106(.X(next3), .Y(next4), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85107(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_85110(.X(tm6), .Y(tm6_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_85113(.X(tm6_d), .Y(tm6_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 2) shiftFIFO_85118(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm6_d, s1rdloc}) {1'd0, 2'd0}: s1rd0 <= 2; {1'd0, 2'd1}: s1rd0 <= 3; {1'd0, 2'd2}: s1rd0 <= 0; {1'd0, 2'd3}: s1rd0 <= 1; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm6_d, s1rdloc}) {1'd0, 2'd0}: s1rd1 <= 0; {1'd0, 2'd1}: s1rd1 <= 1; {1'd0, 2'd2}: s1rd1 <= 2; {1'd0, 2'd3}: s1rd1 <= 3; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet82793 sw(tm6_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm6_dd, writeCycle}) {1'd0, 2'd0}: s2wr0 <= 2; {1'd0, 2'd1}: s2wr0 <= 3; {1'd0, 2'd2}: s2wr0 <= 0; {1'd0, 2'd3}: s2wr0 <= 1; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm6_dd, writeCycle}) {1'd0, 2'd0}: s2wr1 <= 0; {1'd0, 2'd1}: s2wr1 <= 1; {1'd0, 2'd2}: s2wr1 <= 2; {1'd0, 2'd3}: s2wr1 <= 3; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule // Latency: 8 // Gap: 4 module DirSum_82984(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; reg [1:0] i4; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; always @(posedge clk) begin if (reset == 1) begin i4 <= 0; end else begin if (next == 1) i4 <= 0; else if (i4 == 3) i4 <= 0; else i4 <= i4 + 1; end end codeBlock82798 codeBlockIsnt85119(.clk(clk), .reset(reset), .next_in(next), .next_out(next_out), .i4_in(i4), .X0_in(X0), .Y0(Y0), .X1_in(X1), .Y1(Y1), .X2_in(X2), .Y2(Y2), .X3_in(X3), .Y3(Y3)); endmodule module D14_82970(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [1:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h4000; 1: out3 <= 16'h2d41; 2: out3 <= 16'h0; 3: out3 <= 16'hd2bf; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule module D16_82982(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [1:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h0; 1: out3 <= 16'hd2bf; 2: out3 <= 16'hc000; 3: out3 <= 16'hd2bf; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule // Latency: 8 // Gap: 1 module codeBlock82798(clk, reset, next_in, next_out, i4_in, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [1:0] i4_in; reg [1:0] i4; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(7, 1) shiftFIFO_85122(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a233; wire signed [15:0] a222; wire signed [15:0] a236; wire signed [15:0] a226; wire signed [15:0] a237; wire signed [15:0] a238; reg signed [15:0] tm167; reg signed [15:0] tm171; reg signed [15:0] tm183; reg signed [15:0] tm190; reg signed [15:0] tm168; reg signed [15:0] tm172; reg signed [15:0] tm184; reg signed [15:0] tm191; wire signed [15:0] tm9; wire signed [15:0] a227; wire signed [15:0] tm10; wire signed [15:0] a229; reg signed [15:0] tm169; reg signed [15:0] tm173; reg signed [15:0] tm185; reg signed [15:0] tm192; reg signed [15:0] tm39; reg signed [15:0] tm40; reg signed [15:0] tm170; reg signed [15:0] tm174; reg signed [15:0] tm186; reg signed [15:0] tm193; reg signed [15:0] tm187; reg signed [15:0] tm194; wire signed [15:0] a228; wire signed [15:0] a230; wire signed [15:0] a231; wire signed [15:0] a232; reg signed [15:0] tm188; reg signed [15:0] tm195; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; reg signed [15:0] tm189; reg signed [15:0] tm196; assign a233 = X0; assign a222 = a233; assign a236 = X1; assign a226 = a236; assign a237 = X2; assign a238 = X3; assign a227 = tm9; assign a229 = tm10; assign Y0 = tm189; assign Y1 = tm196; D14_82970 instD14inst0_82970(.addr(i4[1:0]), .out(tm9), .clk(clk)); D16_82982 instD16inst0_82982(.addr(i4[1:0]), .out(tm10), .clk(clk)); multfix #(16, 2) m82897(.a(tm39), .b(tm170), .clk(clk), .q_sc(a228), .q_unsc(), .rst(reset)); multfix #(16, 2) m82919(.a(tm40), .b(tm174), .clk(clk), .q_sc(a230), .q_unsc(), .rst(reset)); multfix #(16, 2) m82937(.a(tm40), .b(tm170), .clk(clk), .q_sc(a231), .q_unsc(), .rst(reset)); multfix #(16, 2) m82948(.a(tm39), .b(tm174), .clk(clk), .q_sc(a232), .q_unsc(), .rst(reset)); subfxp #(16, 1) sub82926(.a(a228), .b(a230), .clk(clk), .q(Y2)); // 6 addfxp #(16, 1) add82955(.a(a231), .b(a232), .clk(clk), .q(Y3)); // 6 always @(posedge clk) begin if (reset == 1) begin tm39 <= 0; tm170 <= 0; tm40 <= 0; tm174 <= 0; tm40 <= 0; tm170 <= 0; tm39 <= 0; tm174 <= 0; end else begin i4 <= i4_in; X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; tm167 <= a237; tm171 <= a238; tm183 <= a222; tm190 <= a226; tm168 <= tm167; tm172 <= tm171; tm184 <= tm183; tm191 <= tm190; tm169 <= tm168; tm173 <= tm172; tm185 <= tm184; tm192 <= tm191; tm39 <= a227; tm40 <= a229; tm170 <= tm169; tm174 <= tm173; tm186 <= tm185; tm193 <= tm192; tm187 <= tm186; tm194 <= tm193; tm188 <= tm187; tm195 <= tm194; tm189 <= tm188; tm196 <= tm195; end end endmodule // Latency: 2 // Gap: 1 module codeBlock82987(clk, reset, next_in, next_out, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(1, 1) shiftFIFO_85125(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a189; wire signed [15:0] a190; wire signed [15:0] a191; wire signed [15:0] a192; wire signed [15:0] t93; wire signed [15:0] t94; wire signed [15:0] t95; wire signed [15:0] t96; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; assign a189 = X0; assign a190 = X2; assign a191 = X1; assign a192 = X3; assign Y0 = t93; assign Y1 = t94; assign Y2 = t95; assign Y3 = t96; addfxp #(16, 1) add82999(.a(a189), .b(a190), .clk(clk), .q(t93)); // 0 addfxp #(16, 1) add83014(.a(a191), .b(a192), .clk(clk), .q(t94)); // 0 subfxp #(16, 1) sub83029(.a(a189), .b(a190), .clk(clk), .q(t95)); // 0 subfxp #(16, 1) sub83044(.a(a191), .b(a192), .clk(clk), .q(t96)); // 0 always @(posedge clk) begin if (reset == 1) begin end else begin X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; end end endmodule // Latency: 20 // Gap: 8 module rc83069(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm83067 instPerm85126(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet83067(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [2:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 3'd0: control <= 1'b1; 3'd1: control <= 1'b1; 3'd2: control <= 1'b1; 3'd3: control <= 1'b1; 3'd4: control <= 1'b0; 3'd5: control <= 1'b0; 3'd6: control <= 1'b0; 3'd7: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 20 // Gap: 8 module perm83067(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 8; parameter addrbits = 3; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm11; assign tm11 = 0; shiftRegFIFO #(3, 1) shiftFIFO_85131(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85132(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); shiftRegFIFO #(7, 1) shiftFIFO_85141(.X(next), .Y(next2), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_85142(.X(next2), .Y(next3), .clk(clk)); shiftRegFIFO #(8, 1) shiftFIFO_85143(.X(next3), .Y(next4), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85144(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(7, 1) shiftFIFO_85147(.X(tm11), .Y(tm11_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_85150(.X(tm11_d), .Y(tm11_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 3) shiftFIFO_85155(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm11_d, s1rdloc}) {1'd0, 3'd0}: s1rd0 <= 4; {1'd0, 3'd1}: s1rd0 <= 5; {1'd0, 3'd2}: s1rd0 <= 6; {1'd0, 3'd3}: s1rd0 <= 7; {1'd0, 3'd4}: s1rd0 <= 0; {1'd0, 3'd5}: s1rd0 <= 1; {1'd0, 3'd6}: s1rd0 <= 2; {1'd0, 3'd7}: s1rd0 <= 3; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm11_d, s1rdloc}) {1'd0, 3'd0}: s1rd1 <= 0; {1'd0, 3'd1}: s1rd1 <= 1; {1'd0, 3'd2}: s1rd1 <= 2; {1'd0, 3'd3}: s1rd1 <= 3; {1'd0, 3'd4}: s1rd1 <= 4; {1'd0, 3'd5}: s1rd1 <= 5; {1'd0, 3'd6}: s1rd1 <= 6; {1'd0, 3'd7}: s1rd1 <= 7; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet83067 sw(tm11_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm11_dd, writeCycle}) {1'd0, 3'd0}: s2wr0 <= 4; {1'd0, 3'd1}: s2wr0 <= 5; {1'd0, 3'd2}: s2wr0 <= 6; {1'd0, 3'd3}: s2wr0 <= 7; {1'd0, 3'd4}: s2wr0 <= 0; {1'd0, 3'd5}: s2wr0 <= 1; {1'd0, 3'd6}: s2wr0 <= 2; {1'd0, 3'd7}: s2wr0 <= 3; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm11_dd, writeCycle}) {1'd0, 3'd0}: s2wr1 <= 0; {1'd0, 3'd1}: s2wr1 <= 1; {1'd0, 3'd2}: s2wr1 <= 2; {1'd0, 3'd3}: s2wr1 <= 3; {1'd0, 3'd4}: s2wr1 <= 4; {1'd0, 3'd5}: s2wr1 <= 5; {1'd0, 3'd6}: s2wr1 <= 6; {1'd0, 3'd7}: s2wr1 <= 7; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule // Latency: 8 // Gap: 8 module DirSum_83274(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; reg [2:0] i3; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; always @(posedge clk) begin if (reset == 1) begin i3 <= 0; end else begin if (next == 1) i3 <= 0; else if (i3 == 7) i3 <= 0; else i3 <= i3 + 1; end end codeBlock83072 codeBlockIsnt85156(.clk(clk), .reset(reset), .next_in(next), .next_out(next_out), .i3_in(i3), .X0_in(X0), .Y0(Y0), .X1_in(X1), .Y1(Y1), .X2_in(X2), .Y2(Y2), .X3_in(X3), .Y3(Y3)); endmodule module D10_83252(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [2:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h4000; 1: out3 <= 16'h3b21; 2: out3 <= 16'h2d41; 3: out3 <= 16'h187e; 4: out3 <= 16'h0; 5: out3 <= 16'he782; 6: out3 <= 16'hd2bf; 7: out3 <= 16'hc4df; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule module D12_83272(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [2:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h0; 1: out3 <= 16'he782; 2: out3 <= 16'hd2bf; 3: out3 <= 16'hc4df; 4: out3 <= 16'hc000; 5: out3 <= 16'hc4df; 6: out3 <= 16'hd2bf; 7: out3 <= 16'he782; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule // Latency: 8 // Gap: 1 module codeBlock83072(clk, reset, next_in, next_out, i3_in, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [2:0] i3_in; reg [2:0] i3; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(7, 1) shiftFIFO_85159(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a173; wire signed [15:0] a162; wire signed [15:0] a176; wire signed [15:0] a166; wire signed [15:0] a177; wire signed [15:0] a178; reg signed [15:0] tm197; reg signed [15:0] tm201; reg signed [15:0] tm213; reg signed [15:0] tm220; reg signed [15:0] tm198; reg signed [15:0] tm202; reg signed [15:0] tm214; reg signed [15:0] tm221; wire signed [15:0] tm14; wire signed [15:0] a167; wire signed [15:0] tm15; wire signed [15:0] a169; reg signed [15:0] tm199; reg signed [15:0] tm203; reg signed [15:0] tm215; reg signed [15:0] tm222; reg signed [15:0] tm47; reg signed [15:0] tm48; reg signed [15:0] tm200; reg signed [15:0] tm204; reg signed [15:0] tm216; reg signed [15:0] tm223; reg signed [15:0] tm217; reg signed [15:0] tm224; wire signed [15:0] a168; wire signed [15:0] a170; wire signed [15:0] a171; wire signed [15:0] a172; reg signed [15:0] tm218; reg signed [15:0] tm225; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; reg signed [15:0] tm219; reg signed [15:0] tm226; assign a173 = X0; assign a162 = a173; assign a176 = X1; assign a166 = a176; assign a177 = X2; assign a178 = X3; assign a167 = tm14; assign a169 = tm15; assign Y0 = tm219; assign Y1 = tm226; D10_83252 instD10inst0_83252(.addr(i3[2:0]), .out(tm14), .clk(clk)); D12_83272 instD12inst0_83272(.addr(i3[2:0]), .out(tm15), .clk(clk)); multfix #(16, 2) m83171(.a(tm47), .b(tm200), .clk(clk), .q_sc(a168), .q_unsc(), .rst(reset)); multfix #(16, 2) m83193(.a(tm48), .b(tm204), .clk(clk), .q_sc(a170), .q_unsc(), .rst(reset)); multfix #(16, 2) m83211(.a(tm48), .b(tm200), .clk(clk), .q_sc(a171), .q_unsc(), .rst(reset)); multfix #(16, 2) m83222(.a(tm47), .b(tm204), .clk(clk), .q_sc(a172), .q_unsc(), .rst(reset)); subfxp #(16, 1) sub83200(.a(a168), .b(a170), .clk(clk), .q(Y2)); // 6 addfxp #(16, 1) add83229(.a(a171), .b(a172), .clk(clk), .q(Y3)); // 6 always @(posedge clk) begin if (reset == 1) begin tm47 <= 0; tm200 <= 0; tm48 <= 0; tm204 <= 0; tm48 <= 0; tm200 <= 0; tm47 <= 0; tm204 <= 0; end else begin i3 <= i3_in; X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; tm197 <= a177; tm201 <= a178; tm213 <= a162; tm220 <= a166; tm198 <= tm197; tm202 <= tm201; tm214 <= tm213; tm221 <= tm220; tm199 <= tm198; tm203 <= tm202; tm215 <= tm214; tm222 <= tm221; tm47 <= a167; tm48 <= a169; tm200 <= tm199; tm204 <= tm203; tm216 <= tm215; tm223 <= tm222; tm217 <= tm216; tm224 <= tm223; tm218 <= tm217; tm225 <= tm224; tm219 <= tm218; tm226 <= tm225; end end endmodule // Latency: 2 // Gap: 1 module codeBlock83277(clk, reset, next_in, next_out, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(1, 1) shiftFIFO_85162(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a129; wire signed [15:0] a130; wire signed [15:0] a131; wire signed [15:0] a132; wire signed [15:0] t69; wire signed [15:0] t70; wire signed [15:0] t71; wire signed [15:0] t72; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; assign a129 = X0; assign a130 = X2; assign a131 = X1; assign a132 = X3; assign Y0 = t69; assign Y1 = t70; assign Y2 = t71; assign Y3 = t72; addfxp #(16, 1) add83289(.a(a129), .b(a130), .clk(clk), .q(t69)); // 0 addfxp #(16, 1) add83304(.a(a131), .b(a132), .clk(clk), .q(t70)); // 0 subfxp #(16, 1) sub83319(.a(a129), .b(a130), .clk(clk), .q(t71)); // 0 subfxp #(16, 1) sub83334(.a(a131), .b(a132), .clk(clk), .q(t72)); // 0 always @(posedge clk) begin if (reset == 1) begin end else begin X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; end end endmodule // Latency: 36 // Gap: 16 module rc83359(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm83357 instPerm85163(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet83357(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [3:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 4'd0: control <= 1'b1; 4'd1: control <= 1'b1; 4'd2: control <= 1'b1; 4'd3: control <= 1'b1; 4'd4: control <= 1'b1; 4'd5: control <= 1'b1; 4'd6: control <= 1'b1; 4'd7: control <= 1'b1; 4'd8: control <= 1'b0; 4'd9: control <= 1'b0; 4'd10: control <= 1'b0; 4'd11: control <= 1'b0; 4'd12: control <= 1'b0; 4'd13: control <= 1'b0; 4'd14: control <= 1'b0; 4'd15: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 36 // Gap: 16 module perm83357(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 16; parameter addrbits = 4; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm16; assign tm16 = 0; shiftRegFIFO #(3, 1) shiftFIFO_85168(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85169(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); nextReg #(15, 4) nextReg_85180(.X(next), .Y(next2), .reset(reset), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_85181(.X(next2), .Y(next3), .clk(clk)); nextReg #(16, 4) nextReg_85184(.X(next3), .Y(next4), .reset(reset), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85185(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(15, 1) shiftFIFO_85188(.X(tm16), .Y(tm16_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_85191(.X(tm16_d), .Y(tm16_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 4) shiftFIFO_85196(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm16_d, s1rdloc}) {1'd0, 4'd0}: s1rd0 <= 8; {1'd0, 4'd1}: s1rd0 <= 9; {1'd0, 4'd2}: s1rd0 <= 10; {1'd0, 4'd3}: s1rd0 <= 11; {1'd0, 4'd4}: s1rd0 <= 12; {1'd0, 4'd5}: s1rd0 <= 13; {1'd0, 4'd6}: s1rd0 <= 14; {1'd0, 4'd7}: s1rd0 <= 15; {1'd0, 4'd8}: s1rd0 <= 0; {1'd0, 4'd9}: s1rd0 <= 1; {1'd0, 4'd10}: s1rd0 <= 2; {1'd0, 4'd11}: s1rd0 <= 3; {1'd0, 4'd12}: s1rd0 <= 4; {1'd0, 4'd13}: s1rd0 <= 5; {1'd0, 4'd14}: s1rd0 <= 6; {1'd0, 4'd15}: s1rd0 <= 7; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm16_d, s1rdloc}) {1'd0, 4'd0}: s1rd1 <= 0; {1'd0, 4'd1}: s1rd1 <= 1; {1'd0, 4'd2}: s1rd1 <= 2; {1'd0, 4'd3}: s1rd1 <= 3; {1'd0, 4'd4}: s1rd1 <= 4; {1'd0, 4'd5}: s1rd1 <= 5; {1'd0, 4'd6}: s1rd1 <= 6; {1'd0, 4'd7}: s1rd1 <= 7; {1'd0, 4'd8}: s1rd1 <= 8; {1'd0, 4'd9}: s1rd1 <= 9; {1'd0, 4'd10}: s1rd1 <= 10; {1'd0, 4'd11}: s1rd1 <= 11; {1'd0, 4'd12}: s1rd1 <= 12; {1'd0, 4'd13}: s1rd1 <= 13; {1'd0, 4'd14}: s1rd1 <= 14; {1'd0, 4'd15}: s1rd1 <= 15; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet83357 sw(tm16_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm16_dd, writeCycle}) {1'd0, 4'd0}: s2wr0 <= 8; {1'd0, 4'd1}: s2wr0 <= 9; {1'd0, 4'd2}: s2wr0 <= 10; {1'd0, 4'd3}: s2wr0 <= 11; {1'd0, 4'd4}: s2wr0 <= 12; {1'd0, 4'd5}: s2wr0 <= 13; {1'd0, 4'd6}: s2wr0 <= 14; {1'd0, 4'd7}: s2wr0 <= 15; {1'd0, 4'd8}: s2wr0 <= 0; {1'd0, 4'd9}: s2wr0 <= 1; {1'd0, 4'd10}: s2wr0 <= 2; {1'd0, 4'd11}: s2wr0 <= 3; {1'd0, 4'd12}: s2wr0 <= 4; {1'd0, 4'd13}: s2wr0 <= 5; {1'd0, 4'd14}: s2wr0 <= 6; {1'd0, 4'd15}: s2wr0 <= 7; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm16_dd, writeCycle}) {1'd0, 4'd0}: s2wr1 <= 0; {1'd0, 4'd1}: s2wr1 <= 1; {1'd0, 4'd2}: s2wr1 <= 2; {1'd0, 4'd3}: s2wr1 <= 3; {1'd0, 4'd4}: s2wr1 <= 4; {1'd0, 4'd5}: s2wr1 <= 5; {1'd0, 4'd6}: s2wr1 <= 6; {1'd0, 4'd7}: s2wr1 <= 7; {1'd0, 4'd8}: s2wr1 <= 8; {1'd0, 4'd9}: s2wr1 <= 9; {1'd0, 4'd10}: s2wr1 <= 10; {1'd0, 4'd11}: s2wr1 <= 11; {1'd0, 4'd12}: s2wr1 <= 12; {1'd0, 4'd13}: s2wr1 <= 13; {1'd0, 4'd14}: s2wr1 <= 14; {1'd0, 4'd15}: s2wr1 <= 15; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule // Latency: 8 // Gap: 16 module DirSum_83596(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; reg [3:0] i2; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; always @(posedge clk) begin if (reset == 1) begin i2 <= 0; end else begin if (next == 1) i2 <= 0; else if (i2 == 15) i2 <= 0; else i2 <= i2 + 1; end end codeBlock83362 codeBlockIsnt85201(.clk(clk), .reset(reset), .next_in(next), .next_out(next_out), .i2_in(i2), .X0_in(X0), .Y0(Y0), .X1_in(X1), .Y1(Y1), .X2_in(X2), .Y2(Y2), .X3_in(X3), .Y3(Y3)); endmodule module D6_83558(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [3:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h4000; 1: out3 <= 16'h3ec5; 2: out3 <= 16'h3b21; 3: out3 <= 16'h3537; 4: out3 <= 16'h2d41; 5: out3 <= 16'h238e; 6: out3 <= 16'h187e; 7: out3 <= 16'hc7c; 8: out3 <= 16'h0; 9: out3 <= 16'hf384; 10: out3 <= 16'he782; 11: out3 <= 16'hdc72; 12: out3 <= 16'hd2bf; 13: out3 <= 16'hcac9; 14: out3 <= 16'hc4df; 15: out3 <= 16'hc13b; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule module D8_83594(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [3:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h0; 1: out3 <= 16'hf384; 2: out3 <= 16'he782; 3: out3 <= 16'hdc72; 4: out3 <= 16'hd2bf; 5: out3 <= 16'hcac9; 6: out3 <= 16'hc4df; 7: out3 <= 16'hc13b; 8: out3 <= 16'hc000; 9: out3 <= 16'hc13b; 10: out3 <= 16'hc4df; 11: out3 <= 16'hcac9; 12: out3 <= 16'hd2bf; 13: out3 <= 16'hdc72; 14: out3 <= 16'he782; 15: out3 <= 16'hf384; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule // Latency: 8 // Gap: 1 module codeBlock83362(clk, reset, next_in, next_out, i2_in, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [3:0] i2_in; reg [3:0] i2; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(7, 1) shiftFIFO_85204(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a113; wire signed [15:0] a102; wire signed [15:0] a116; wire signed [15:0] a106; wire signed [15:0] a117; wire signed [15:0] a118; reg signed [15:0] tm227; reg signed [15:0] tm231; reg signed [15:0] tm243; reg signed [15:0] tm250; reg signed [15:0] tm228; reg signed [15:0] tm232; reg signed [15:0] tm244; reg signed [15:0] tm251; wire signed [15:0] tm19; wire signed [15:0] a107; wire signed [15:0] tm20; wire signed [15:0] a109; reg signed [15:0] tm229; reg signed [15:0] tm233; reg signed [15:0] tm245; reg signed [15:0] tm252; reg signed [15:0] tm55; reg signed [15:0] tm56; reg signed [15:0] tm230; reg signed [15:0] tm234; reg signed [15:0] tm246; reg signed [15:0] tm253; reg signed [15:0] tm247; reg signed [15:0] tm254; wire signed [15:0] a108; wire signed [15:0] a110; wire signed [15:0] a111; wire signed [15:0] a112; reg signed [15:0] tm248; reg signed [15:0] tm255; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; reg signed [15:0] tm249; reg signed [15:0] tm256; assign a113 = X0; assign a102 = a113; assign a116 = X1; assign a106 = a116; assign a117 = X2; assign a118 = X3; assign a107 = tm19; assign a109 = tm20; assign Y0 = tm249; assign Y1 = tm256; D6_83558 instD6inst0_83558(.addr(i2[3:0]), .out(tm19), .clk(clk)); D8_83594 instD8inst0_83594(.addr(i2[3:0]), .out(tm20), .clk(clk)); multfix #(16, 2) m83461(.a(tm55), .b(tm230), .clk(clk), .q_sc(a108), .q_unsc(), .rst(reset)); multfix #(16, 2) m83483(.a(tm56), .b(tm234), .clk(clk), .q_sc(a110), .q_unsc(), .rst(reset)); multfix #(16, 2) m83501(.a(tm56), .b(tm230), .clk(clk), .q_sc(a111), .q_unsc(), .rst(reset)); multfix #(16, 2) m83512(.a(tm55), .b(tm234), .clk(clk), .q_sc(a112), .q_unsc(), .rst(reset)); subfxp #(16, 1) sub83490(.a(a108), .b(a110), .clk(clk), .q(Y2)); // 6 addfxp #(16, 1) add83519(.a(a111), .b(a112), .clk(clk), .q(Y3)); // 6 always @(posedge clk) begin if (reset == 1) begin tm55 <= 0; tm230 <= 0; tm56 <= 0; tm234 <= 0; tm56 <= 0; tm230 <= 0; tm55 <= 0; tm234 <= 0; end else begin i2 <= i2_in; X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; tm227 <= a117; tm231 <= a118; tm243 <= a102; tm250 <= a106; tm228 <= tm227; tm232 <= tm231; tm244 <= tm243; tm251 <= tm250; tm229 <= tm228; tm233 <= tm232; tm245 <= tm244; tm252 <= tm251; tm55 <= a107; tm56 <= a109; tm230 <= tm229; tm234 <= tm233; tm246 <= tm245; tm253 <= tm252; tm247 <= tm246; tm254 <= tm253; tm248 <= tm247; tm255 <= tm254; tm249 <= tm248; tm256 <= tm255; end end endmodule // Latency: 2 // Gap: 1 module codeBlock83599(clk, reset, next_in, next_out, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(1, 1) shiftFIFO_85207(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a69; wire signed [15:0] a70; wire signed [15:0] a71; wire signed [15:0] a72; wire signed [15:0] t45; wire signed [15:0] t46; wire signed [15:0] t47; wire signed [15:0] t48; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; assign a69 = X0; assign a70 = X2; assign a71 = X1; assign a72 = X3; assign Y0 = t45; assign Y1 = t46; assign Y2 = t47; assign Y3 = t48; addfxp #(16, 1) add83611(.a(a69), .b(a70), .clk(clk), .q(t45)); // 0 addfxp #(16, 1) add83626(.a(a71), .b(a72), .clk(clk), .q(t46)); // 0 subfxp #(16, 1) sub83641(.a(a69), .b(a70), .clk(clk), .q(t47)); // 0 subfxp #(16, 1) sub83656(.a(a71), .b(a72), .clk(clk), .q(t48)); // 0 always @(posedge clk) begin if (reset == 1) begin end else begin X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; end end endmodule // Latency: 68 // Gap: 32 module rc83681(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm83679 instPerm85208(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet83679(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [4:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 5'd0: control <= 1'b1; 5'd1: control <= 1'b1; 5'd2: control <= 1'b1; 5'd3: control <= 1'b1; 5'd4: control <= 1'b1; 5'd5: control <= 1'b1; 5'd6: control <= 1'b1; 5'd7: control <= 1'b1; 5'd8: control <= 1'b1; 5'd9: control <= 1'b1; 5'd10: control <= 1'b1; 5'd11: control <= 1'b1; 5'd12: control <= 1'b1; 5'd13: control <= 1'b1; 5'd14: control <= 1'b1; 5'd15: control <= 1'b1; 5'd16: control <= 1'b0; 5'd17: control <= 1'b0; 5'd18: control <= 1'b0; 5'd19: control <= 1'b0; 5'd20: control <= 1'b0; 5'd21: control <= 1'b0; 5'd22: control <= 1'b0; 5'd23: control <= 1'b0; 5'd24: control <= 1'b0; 5'd25: control <= 1'b0; 5'd26: control <= 1'b0; 5'd27: control <= 1'b0; 5'd28: control <= 1'b0; 5'd29: control <= 1'b0; 5'd30: control <= 1'b0; 5'd31: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 68 // Gap: 32 module perm83679(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 32; parameter addrbits = 5; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm21; assign tm21 = 0; shiftRegFIFO #(3, 1) shiftFIFO_85213(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85214(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); nextReg #(31, 5) nextReg_85225(.X(next), .Y(next2), .reset(reset), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_85226(.X(next2), .Y(next3), .clk(clk)); nextReg #(32, 5) nextReg_85229(.X(next3), .Y(next4), .reset(reset), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85230(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(31, 1) shiftFIFO_85233(.X(tm21), .Y(tm21_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_85236(.X(tm21_d), .Y(tm21_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 5) shiftFIFO_85241(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm21_d, s1rdloc}) {1'd0, 5'd0}: s1rd0 <= 16; {1'd0, 5'd1}: s1rd0 <= 17; {1'd0, 5'd2}: s1rd0 <= 18; {1'd0, 5'd3}: s1rd0 <= 19; {1'd0, 5'd4}: s1rd0 <= 20; {1'd0, 5'd5}: s1rd0 <= 21; {1'd0, 5'd6}: s1rd0 <= 22; {1'd0, 5'd7}: s1rd0 <= 23; {1'd0, 5'd8}: s1rd0 <= 24; {1'd0, 5'd9}: s1rd0 <= 25; {1'd0, 5'd10}: s1rd0 <= 26; {1'd0, 5'd11}: s1rd0 <= 27; {1'd0, 5'd12}: s1rd0 <= 28; {1'd0, 5'd13}: s1rd0 <= 29; {1'd0, 5'd14}: s1rd0 <= 30; {1'd0, 5'd15}: s1rd0 <= 31; {1'd0, 5'd16}: s1rd0 <= 0; {1'd0, 5'd17}: s1rd0 <= 1; {1'd0, 5'd18}: s1rd0 <= 2; {1'd0, 5'd19}: s1rd0 <= 3; {1'd0, 5'd20}: s1rd0 <= 4; {1'd0, 5'd21}: s1rd0 <= 5; {1'd0, 5'd22}: s1rd0 <= 6; {1'd0, 5'd23}: s1rd0 <= 7; {1'd0, 5'd24}: s1rd0 <= 8; {1'd0, 5'd25}: s1rd0 <= 9; {1'd0, 5'd26}: s1rd0 <= 10; {1'd0, 5'd27}: s1rd0 <= 11; {1'd0, 5'd28}: s1rd0 <= 12; {1'd0, 5'd29}: s1rd0 <= 13; {1'd0, 5'd30}: s1rd0 <= 14; {1'd0, 5'd31}: s1rd0 <= 15; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm21_d, s1rdloc}) {1'd0, 5'd0}: s1rd1 <= 0; {1'd0, 5'd1}: s1rd1 <= 1; {1'd0, 5'd2}: s1rd1 <= 2; {1'd0, 5'd3}: s1rd1 <= 3; {1'd0, 5'd4}: s1rd1 <= 4; {1'd0, 5'd5}: s1rd1 <= 5; {1'd0, 5'd6}: s1rd1 <= 6; {1'd0, 5'd7}: s1rd1 <= 7; {1'd0, 5'd8}: s1rd1 <= 8; {1'd0, 5'd9}: s1rd1 <= 9; {1'd0, 5'd10}: s1rd1 <= 10; {1'd0, 5'd11}: s1rd1 <= 11; {1'd0, 5'd12}: s1rd1 <= 12; {1'd0, 5'd13}: s1rd1 <= 13; {1'd0, 5'd14}: s1rd1 <= 14; {1'd0, 5'd15}: s1rd1 <= 15; {1'd0, 5'd16}: s1rd1 <= 16; {1'd0, 5'd17}: s1rd1 <= 17; {1'd0, 5'd18}: s1rd1 <= 18; {1'd0, 5'd19}: s1rd1 <= 19; {1'd0, 5'd20}: s1rd1 <= 20; {1'd0, 5'd21}: s1rd1 <= 21; {1'd0, 5'd22}: s1rd1 <= 22; {1'd0, 5'd23}: s1rd1 <= 23; {1'd0, 5'd24}: s1rd1 <= 24; {1'd0, 5'd25}: s1rd1 <= 25; {1'd0, 5'd26}: s1rd1 <= 26; {1'd0, 5'd27}: s1rd1 <= 27; {1'd0, 5'd28}: s1rd1 <= 28; {1'd0, 5'd29}: s1rd1 <= 29; {1'd0, 5'd30}: s1rd1 <= 30; {1'd0, 5'd31}: s1rd1 <= 31; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet83679 sw(tm21_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm21_dd, writeCycle}) {1'd0, 5'd0}: s2wr0 <= 16; {1'd0, 5'd1}: s2wr0 <= 17; {1'd0, 5'd2}: s2wr0 <= 18; {1'd0, 5'd3}: s2wr0 <= 19; {1'd0, 5'd4}: s2wr0 <= 20; {1'd0, 5'd5}: s2wr0 <= 21; {1'd0, 5'd6}: s2wr0 <= 22; {1'd0, 5'd7}: s2wr0 <= 23; {1'd0, 5'd8}: s2wr0 <= 24; {1'd0, 5'd9}: s2wr0 <= 25; {1'd0, 5'd10}: s2wr0 <= 26; {1'd0, 5'd11}: s2wr0 <= 27; {1'd0, 5'd12}: s2wr0 <= 28; {1'd0, 5'd13}: s2wr0 <= 29; {1'd0, 5'd14}: s2wr0 <= 30; {1'd0, 5'd15}: s2wr0 <= 31; {1'd0, 5'd16}: s2wr0 <= 0; {1'd0, 5'd17}: s2wr0 <= 1; {1'd0, 5'd18}: s2wr0 <= 2; {1'd0, 5'd19}: s2wr0 <= 3; {1'd0, 5'd20}: s2wr0 <= 4; {1'd0, 5'd21}: s2wr0 <= 5; {1'd0, 5'd22}: s2wr0 <= 6; {1'd0, 5'd23}: s2wr0 <= 7; {1'd0, 5'd24}: s2wr0 <= 8; {1'd0, 5'd25}: s2wr0 <= 9; {1'd0, 5'd26}: s2wr0 <= 10; {1'd0, 5'd27}: s2wr0 <= 11; {1'd0, 5'd28}: s2wr0 <= 12; {1'd0, 5'd29}: s2wr0 <= 13; {1'd0, 5'd30}: s2wr0 <= 14; {1'd0, 5'd31}: s2wr0 <= 15; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm21_dd, writeCycle}) {1'd0, 5'd0}: s2wr1 <= 0; {1'd0, 5'd1}: s2wr1 <= 1; {1'd0, 5'd2}: s2wr1 <= 2; {1'd0, 5'd3}: s2wr1 <= 3; {1'd0, 5'd4}: s2wr1 <= 4; {1'd0, 5'd5}: s2wr1 <= 5; {1'd0, 5'd6}: s2wr1 <= 6; {1'd0, 5'd7}: s2wr1 <= 7; {1'd0, 5'd8}: s2wr1 <= 8; {1'd0, 5'd9}: s2wr1 <= 9; {1'd0, 5'd10}: s2wr1 <= 10; {1'd0, 5'd11}: s2wr1 <= 11; {1'd0, 5'd12}: s2wr1 <= 12; {1'd0, 5'd13}: s2wr1 <= 13; {1'd0, 5'd14}: s2wr1 <= 14; {1'd0, 5'd15}: s2wr1 <= 15; {1'd0, 5'd16}: s2wr1 <= 16; {1'd0, 5'd17}: s2wr1 <= 17; {1'd0, 5'd18}: s2wr1 <= 18; {1'd0, 5'd19}: s2wr1 <= 19; {1'd0, 5'd20}: s2wr1 <= 20; {1'd0, 5'd21}: s2wr1 <= 21; {1'd0, 5'd22}: s2wr1 <= 22; {1'd0, 5'd23}: s2wr1 <= 23; {1'd0, 5'd24}: s2wr1 <= 24; {1'd0, 5'd25}: s2wr1 <= 25; {1'd0, 5'd26}: s2wr1 <= 26; {1'd0, 5'd27}: s2wr1 <= 27; {1'd0, 5'd28}: s2wr1 <= 28; {1'd0, 5'd29}: s2wr1 <= 29; {1'd0, 5'd30}: s2wr1 <= 30; {1'd0, 5'd31}: s2wr1 <= 31; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule // Latency: 8 // Gap: 32 module DirSum_83981(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; reg [4:0] i1; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; always @(posedge clk) begin if (reset == 1) begin i1 <= 0; end else begin if (next == 1) i1 <= 0; else if (i1 == 31) i1 <= 0; else i1 <= i1 + 1; end end codeBlock83683 codeBlockIsnt85246(.clk(clk), .reset(reset), .next_in(next), .next_out(next_out), .i1_in(i1), .X0_in(X0), .Y0(Y0), .X1_in(X1), .Y1(Y1), .X2_in(X2), .Y2(Y2), .X3_in(X3), .Y3(Y3)); endmodule module D2_83911(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [4:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h4000; 1: out3 <= 16'h3fb1; 2: out3 <= 16'h3ec5; 3: out3 <= 16'h3d3f; 4: out3 <= 16'h3b21; 5: out3 <= 16'h3871; 6: out3 <= 16'h3537; 7: out3 <= 16'h3179; 8: out3 <= 16'h2d41; 9: out3 <= 16'h289a; 10: out3 <= 16'h238e; 11: out3 <= 16'h1e2b; 12: out3 <= 16'h187e; 13: out3 <= 16'h1294; 14: out3 <= 16'hc7c; 15: out3 <= 16'h646; 16: out3 <= 16'h0; 17: out3 <= 16'hf9ba; 18: out3 <= 16'hf384; 19: out3 <= 16'hed6c; 20: out3 <= 16'he782; 21: out3 <= 16'he1d5; 22: out3 <= 16'hdc72; 23: out3 <= 16'hd766; 24: out3 <= 16'hd2bf; 25: out3 <= 16'hce87; 26: out3 <= 16'hcac9; 27: out3 <= 16'hc78f; 28: out3 <= 16'hc4df; 29: out3 <= 16'hc2c1; 30: out3 <= 16'hc13b; 31: out3 <= 16'hc04f; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule module D4_83979(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [4:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h0; 1: out3 <= 16'hf9ba; 2: out3 <= 16'hf384; 3: out3 <= 16'hed6c; 4: out3 <= 16'he782; 5: out3 <= 16'he1d5; 6: out3 <= 16'hdc72; 7: out3 <= 16'hd766; 8: out3 <= 16'hd2bf; 9: out3 <= 16'hce87; 10: out3 <= 16'hcac9; 11: out3 <= 16'hc78f; 12: out3 <= 16'hc4df; 13: out3 <= 16'hc2c1; 14: out3 <= 16'hc13b; 15: out3 <= 16'hc04f; 16: out3 <= 16'hc000; 17: out3 <= 16'hc04f; 18: out3 <= 16'hc13b; 19: out3 <= 16'hc2c1; 20: out3 <= 16'hc4df; 21: out3 <= 16'hc78f; 22: out3 <= 16'hcac9; 23: out3 <= 16'hce87; 24: out3 <= 16'hd2bf; 25: out3 <= 16'hd766; 26: out3 <= 16'hdc72; 27: out3 <= 16'he1d5; 28: out3 <= 16'he782; 29: out3 <= 16'hed6c; 30: out3 <= 16'hf384; 31: out3 <= 16'hf9ba; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule // Latency: 8 // Gap: 1 module codeBlock83683(clk, reset, next_in, next_out, i1_in, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [4:0] i1_in; reg [4:0] i1; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(7, 1) shiftFIFO_85249(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a53; wire signed [15:0] a42; wire signed [15:0] a56; wire signed [15:0] a46; wire signed [15:0] a57; wire signed [15:0] a58; reg signed [15:0] tm257; reg signed [15:0] tm261; reg signed [15:0] tm273; reg signed [15:0] tm280; reg signed [15:0] tm258; reg signed [15:0] tm262; reg signed [15:0] tm274; reg signed [15:0] tm281; wire signed [15:0] tm24; wire signed [15:0] a47; wire signed [15:0] tm25; wire signed [15:0] a49; reg signed [15:0] tm259; reg signed [15:0] tm263; reg signed [15:0] tm275; reg signed [15:0] tm282; reg signed [15:0] tm63; reg signed [15:0] tm64; reg signed [15:0] tm260; reg signed [15:0] tm264; reg signed [15:0] tm276; reg signed [15:0] tm283; reg signed [15:0] tm277; reg signed [15:0] tm284; wire signed [15:0] a48; wire signed [15:0] a50; wire signed [15:0] a51; wire signed [15:0] a52; reg signed [15:0] tm278; reg signed [15:0] tm285; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; reg signed [15:0] tm279; reg signed [15:0] tm286; assign a53 = X0; assign a42 = a53; assign a56 = X1; assign a46 = a56; assign a57 = X2; assign a58 = X3; assign a47 = tm24; assign a49 = tm25; assign Y0 = tm279; assign Y1 = tm286; D2_83911 instD2inst0_83911(.addr(i1[4:0]), .out(tm24), .clk(clk)); D4_83979 instD4inst0_83979(.addr(i1[4:0]), .out(tm25), .clk(clk)); multfix #(16, 2) m83782(.a(tm63), .b(tm260), .clk(clk), .q_sc(a48), .q_unsc(), .rst(reset)); multfix #(16, 2) m83804(.a(tm64), .b(tm264), .clk(clk), .q_sc(a50), .q_unsc(), .rst(reset)); multfix #(16, 2) m83822(.a(tm64), .b(tm260), .clk(clk), .q_sc(a51), .q_unsc(), .rst(reset)); multfix #(16, 2) m83833(.a(tm63), .b(tm264), .clk(clk), .q_sc(a52), .q_unsc(), .rst(reset)); subfxp #(16, 1) sub83811(.a(a48), .b(a50), .clk(clk), .q(Y2)); // 6 addfxp #(16, 1) add83840(.a(a51), .b(a52), .clk(clk), .q(Y3)); // 6 always @(posedge clk) begin if (reset == 1) begin tm63 <= 0; tm260 <= 0; tm64 <= 0; tm264 <= 0; tm64 <= 0; tm260 <= 0; tm63 <= 0; tm264 <= 0; end else begin i1 <= i1_in; X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; tm257 <= a57; tm261 <= a58; tm273 <= a42; tm280 <= a46; tm258 <= tm257; tm262 <= tm261; tm274 <= tm273; tm281 <= tm280; tm259 <= tm258; tm263 <= tm262; tm275 <= tm274; tm282 <= tm281; tm63 <= a47; tm64 <= a49; tm260 <= tm259; tm264 <= tm263; tm276 <= tm275; tm283 <= tm282; tm277 <= tm276; tm284 <= tm283; tm278 <= tm277; tm285 <= tm284; tm279 <= tm278; tm286 <= tm285; end end endmodule // Latency: 2 // Gap: 1 module codeBlock83984(clk, reset, next_in, next_out, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(1, 1) shiftFIFO_85252(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a9; wire signed [15:0] a10; wire signed [15:0] a11; wire signed [15:0] a12; wire signed [15:0] t21; wire signed [15:0] t22; wire signed [15:0] t23; wire signed [15:0] t24; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; assign a9 = X0; assign a10 = X2; assign a11 = X1; assign a12 = X3; assign Y0 = t21; assign Y1 = t22; assign Y2 = t23; assign Y3 = t24; addfxp #(16, 1) add83996(.a(a9), .b(a10), .clk(clk), .q(t21)); // 0 addfxp #(16, 1) add84011(.a(a11), .b(a12), .clk(clk), .q(t22)); // 0 subfxp #(16, 1) sub84026(.a(a9), .b(a10), .clk(clk), .q(t23)); // 0 subfxp #(16, 1) sub84041(.a(a11), .b(a12), .clk(clk), .q(t24)); // 0 always @(posedge clk) begin if (reset == 1) begin end else begin X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; end end endmodule // Latency: 68 // Gap: 32 module rc84066(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm84064 instPerm85253(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet84064(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [4:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 5'd0: control <= 1'b1; 5'd1: control <= 1'b1; 5'd2: control <= 1'b1; 5'd3: control <= 1'b1; 5'd4: control <= 1'b1; 5'd5: control <= 1'b1; 5'd6: control <= 1'b1; 5'd7: control <= 1'b1; 5'd8: control <= 1'b1; 5'd9: control <= 1'b1; 5'd10: control <= 1'b1; 5'd11: control <= 1'b1; 5'd12: control <= 1'b1; 5'd13: control <= 1'b1; 5'd14: control <= 1'b1; 5'd15: control <= 1'b1; 5'd16: control <= 1'b0; 5'd17: control <= 1'b0; 5'd18: control <= 1'b0; 5'd19: control <= 1'b0; 5'd20: control <= 1'b0; 5'd21: control <= 1'b0; 5'd22: control <= 1'b0; 5'd23: control <= 1'b0; 5'd24: control <= 1'b0; 5'd25: control <= 1'b0; 5'd26: control <= 1'b0; 5'd27: control <= 1'b0; 5'd28: control <= 1'b0; 5'd29: control <= 1'b0; 5'd30: control <= 1'b0; 5'd31: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 68 // Gap: 32 module perm84064(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 32; parameter addrbits = 5; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm26; assign tm26 = 0; shiftRegFIFO #(3, 1) shiftFIFO_85258(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85259(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); nextReg #(31, 5) nextReg_85270(.X(next), .Y(next2), .reset(reset), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_85271(.X(next2), .Y(next3), .clk(clk)); nextReg #(32, 5) nextReg_85274(.X(next3), .Y(next4), .reset(reset), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_85275(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(31, 1) shiftFIFO_85278(.X(tm26), .Y(tm26_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_85281(.X(tm26_d), .Y(tm26_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 5) shiftFIFO_85286(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm26_d, s1rdloc}) {1'd0, 5'd0}: s1rd0 <= 1; {1'd0, 5'd1}: s1rd0 <= 3; {1'd0, 5'd2}: s1rd0 <= 5; {1'd0, 5'd3}: s1rd0 <= 7; {1'd0, 5'd4}: s1rd0 <= 9; {1'd0, 5'd5}: s1rd0 <= 11; {1'd0, 5'd6}: s1rd0 <= 13; {1'd0, 5'd7}: s1rd0 <= 15; {1'd0, 5'd8}: s1rd0 <= 17; {1'd0, 5'd9}: s1rd0 <= 19; {1'd0, 5'd10}: s1rd0 <= 21; {1'd0, 5'd11}: s1rd0 <= 23; {1'd0, 5'd12}: s1rd0 <= 25; {1'd0, 5'd13}: s1rd0 <= 27; {1'd0, 5'd14}: s1rd0 <= 29; {1'd0, 5'd15}: s1rd0 <= 31; {1'd0, 5'd16}: s1rd0 <= 0; {1'd0, 5'd17}: s1rd0 <= 2; {1'd0, 5'd18}: s1rd0 <= 4; {1'd0, 5'd19}: s1rd0 <= 6; {1'd0, 5'd20}: s1rd0 <= 8; {1'd0, 5'd21}: s1rd0 <= 10; {1'd0, 5'd22}: s1rd0 <= 12; {1'd0, 5'd23}: s1rd0 <= 14; {1'd0, 5'd24}: s1rd0 <= 16; {1'd0, 5'd25}: s1rd0 <= 18; {1'd0, 5'd26}: s1rd0 <= 20; {1'd0, 5'd27}: s1rd0 <= 22; {1'd0, 5'd28}: s1rd0 <= 24; {1'd0, 5'd29}: s1rd0 <= 26; {1'd0, 5'd30}: s1rd0 <= 28; {1'd0, 5'd31}: s1rd0 <= 30; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm26_d, s1rdloc}) {1'd0, 5'd0}: s1rd1 <= 0; {1'd0, 5'd1}: s1rd1 <= 2; {1'd0, 5'd2}: s1rd1 <= 4; {1'd0, 5'd3}: s1rd1 <= 6; {1'd0, 5'd4}: s1rd1 <= 8; {1'd0, 5'd5}: s1rd1 <= 10; {1'd0, 5'd6}: s1rd1 <= 12; {1'd0, 5'd7}: s1rd1 <= 14; {1'd0, 5'd8}: s1rd1 <= 16; {1'd0, 5'd9}: s1rd1 <= 18; {1'd0, 5'd10}: s1rd1 <= 20; {1'd0, 5'd11}: s1rd1 <= 22; {1'd0, 5'd12}: s1rd1 <= 24; {1'd0, 5'd13}: s1rd1 <= 26; {1'd0, 5'd14}: s1rd1 <= 28; {1'd0, 5'd15}: s1rd1 <= 30; {1'd0, 5'd16}: s1rd1 <= 1; {1'd0, 5'd17}: s1rd1 <= 3; {1'd0, 5'd18}: s1rd1 <= 5; {1'd0, 5'd19}: s1rd1 <= 7; {1'd0, 5'd20}: s1rd1 <= 9; {1'd0, 5'd21}: s1rd1 <= 11; {1'd0, 5'd22}: s1rd1 <= 13; {1'd0, 5'd23}: s1rd1 <= 15; {1'd0, 5'd24}: s1rd1 <= 17; {1'd0, 5'd25}: s1rd1 <= 19; {1'd0, 5'd26}: s1rd1 <= 21; {1'd0, 5'd27}: s1rd1 <= 23; {1'd0, 5'd28}: s1rd1 <= 25; {1'd0, 5'd29}: s1rd1 <= 27; {1'd0, 5'd30}: s1rd1 <= 29; {1'd0, 5'd31}: s1rd1 <= 31; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet84064 sw(tm26_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm26_dd, writeCycle}) {1'd0, 5'd0}: s2wr0 <= 16; {1'd0, 5'd1}: s2wr0 <= 17; {1'd0, 5'd2}: s2wr0 <= 18; {1'd0, 5'd3}: s2wr0 <= 19; {1'd0, 5'd4}: s2wr0 <= 20; {1'd0, 5'd5}: s2wr0 <= 21; {1'd0, 5'd6}: s2wr0 <= 22; {1'd0, 5'd7}: s2wr0 <= 23; {1'd0, 5'd8}: s2wr0 <= 24; {1'd0, 5'd9}: s2wr0 <= 25; {1'd0, 5'd10}: s2wr0 <= 26; {1'd0, 5'd11}: s2wr0 <= 27; {1'd0, 5'd12}: s2wr0 <= 28; {1'd0, 5'd13}: s2wr0 <= 29; {1'd0, 5'd14}: s2wr0 <= 30; {1'd0, 5'd15}: s2wr0 <= 31; {1'd0, 5'd16}: s2wr0 <= 0; {1'd0, 5'd17}: s2wr0 <= 1; {1'd0, 5'd18}: s2wr0 <= 2; {1'd0, 5'd19}: s2wr0 <= 3; {1'd0, 5'd20}: s2wr0 <= 4; {1'd0, 5'd21}: s2wr0 <= 5; {1'd0, 5'd22}: s2wr0 <= 6; {1'd0, 5'd23}: s2wr0 <= 7; {1'd0, 5'd24}: s2wr0 <= 8; {1'd0, 5'd25}: s2wr0 <= 9; {1'd0, 5'd26}: s2wr0 <= 10; {1'd0, 5'd27}: s2wr0 <= 11; {1'd0, 5'd28}: s2wr0 <= 12; {1'd0, 5'd29}: s2wr0 <= 13; {1'd0, 5'd30}: s2wr0 <= 14; {1'd0, 5'd31}: s2wr0 <= 15; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm26_dd, writeCycle}) {1'd0, 5'd0}: s2wr1 <= 0; {1'd0, 5'd1}: s2wr1 <= 1; {1'd0, 5'd2}: s2wr1 <= 2; {1'd0, 5'd3}: s2wr1 <= 3; {1'd0, 5'd4}: s2wr1 <= 4; {1'd0, 5'd5}: s2wr1 <= 5; {1'd0, 5'd6}: s2wr1 <= 6; {1'd0, 5'd7}: s2wr1 <= 7; {1'd0, 5'd8}: s2wr1 <= 8; {1'd0, 5'd9}: s2wr1 <= 9; {1'd0, 5'd10}: s2wr1 <= 10; {1'd0, 5'd11}: s2wr1 <= 11; {1'd0, 5'd12}: s2wr1 <= 12; {1'd0, 5'd13}: s2wr1 <= 13; {1'd0, 5'd14}: s2wr1 <= 14; {1'd0, 5'd15}: s2wr1 <= 15; {1'd0, 5'd16}: s2wr1 <= 16; {1'd0, 5'd17}: s2wr1 <= 17; {1'd0, 5'd18}: s2wr1 <= 18; {1'd0, 5'd19}: s2wr1 <= 19; {1'd0, 5'd20}: s2wr1 <= 20; {1'd0, 5'd21}: s2wr1 <= 21; {1'd0, 5'd22}: s2wr1 <= 22; {1'd0, 5'd23}: s2wr1 <= 23; {1'd0, 5'd24}: s2wr1 <= 24; {1'd0, 5'd25}: s2wr1 <= 25; {1'd0, 5'd26}: s2wr1 <= 26; {1'd0, 5'd27}: s2wr1 <= 27; {1'd0, 5'd28}: s2wr1 <= 28; {1'd0, 5'd29}: s2wr1 <= 29; {1'd0, 5'd30}: s2wr1 <= 30; {1'd0, 5'd31}: s2wr1 <= 31; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule module multfix(clk, rst, a, b, q_sc, q_unsc); parameter WIDTH=35, CYCLES=6; input signed [WIDTH-1:0] a,b; output [WIDTH-1:0] q_sc; output [WIDTH-1:0] q_unsc; input clk, rst; reg signed [2*WIDTH-1:0] q[CYCLES-1:0]; wire signed [2*WIDTH-1:0] res; integer i; assign res = q[CYCLES-1]; assign q_unsc = res[WIDTH-1:0]; assign q_sc = {res[2*WIDTH-1], res[2*WIDTH-4:WIDTH-2]}; always @(posedge clk) begin q[0] <= a * b; for (i = 1; i < CYCLES; i=i+1) begin q[i] <= q[i-1]; end end endmodule module addfxp(a, b, q, clk); parameter width = 16, cycles=1; input signed [width-1:0] a, b; input clk; output signed [width-1:0] q; reg signed [width-1:0] res[cycles-1:0]; assign q = res[cycles-1]; integer i; always @(posedge clk) begin res[0] <= a+b; for (i=1; i < cycles; i = i+1) res[i] <= res[i-1]; end endmodule module subfxp(a, b, q, clk); parameter width = 16, cycles=1; input signed [width-1:0] a, b; input clk; output signed [width-1:0] q; reg signed [width-1:0] res[cycles-1:0]; assign q = res[cycles-1]; integer i; always @(posedge clk) begin res[0] <= a-b; for (i=1; i < cycles; i = i+1) res[i] <= res[i-1]; end endmodule
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : dft_top_axi4lite.v // Project : Common Evaluation Platform (CEP) // Description : This file provides an axi4-lite wrapper for the wishbone based-DFT core // module dft_top_axi4lite ( // Clock & Reset input logic clk_i, input logic rst_ni, // AXI4-Lite Slave Interface AXI_LITE.Slave slave ); // AES wishbone slave wires wire wb_clk; wire wb_rst; wire wb_rst_n; wire [slave.AXI_ADDR_WIDTH - 1:0] wbs_d_dft_adr_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_dft_dat_i; wire [3:0] wbs_d_dft_sel_i; wire wbs_d_dft_we_i; wire wbs_d_dft_cyc_i; wire wbs_d_dft_stb_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_dft_dat_o; wire wbs_d_dft_ack_o; // Instantiate the AXI4Lite to Wishbone bridge bonfire_axi4l2wb #( .ADRWIDTH (slave.AXI_ADDR_WIDTH), .FAST_READ_TERM (1'd0) ) bonfire_axi4l2wb_inst ( .S_AXI_ACLK (clk_i), .S_AXI_ARESETN (rst_ni), .S_AXI_AWADDR (slave.aw_addr), .S_AXI_AWVALID (slave.aw_valid), .S_AXI_AWREADY (slave.aw_ready), .S_AXI_WDATA (slave.w_data), .S_AXI_WSTRB (slave.w_strb), .S_AXI_WVALID (slave.w_valid), .S_AXI_WREADY (slave.w_ready), .S_AXI_ARADDR (slave.ar_addr), .S_AXI_ARVALID (slave.ar_valid), .S_AXI_ARREADY (slave.ar_ready), .S_AXI_RDATA (slave.r_data), .S_AXI_RRESP (slave.r_resp), .S_AXI_RVALID (slave.r_valid), .S_AXI_RREADY (slave.r_ready), .S_AXI_BRESP (slave.b_resp), .S_AXI_BVALID (slave.b_valid), .S_AXI_BREADY (slave.b_ready), .wb_clk_o (wb_clk), .wb_rst_o (wb_rst), .wb_addr_o (wbs_d_dft_adr_i), .wb_dat_o (wbs_d_dft_dat_i), .wb_we_o (wbs_d_dft_we_i), .wb_sel_o (wbs_d_dft_sel_i), .wb_stb_o (wbs_d_dft_stb_i), .wb_cyc_o (wbs_d_dft_cyc_i), .wb_dat_i (wbs_d_dft_dat_o), .wb_ack_i (wbs_d_dft_ack_o) ); // Instantiate the wishbone-based DFT Core dft_top_top dft_top_top_inst ( // Wishbone Slave interface .wb_clk_i (wb_clk), .wb_rst_i (wb_rst), .wb_dat_i (wbs_d_dft_dat_i), .wb_adr_i (wbs_d_dft_adr_i), .wb_sel_i (wbs_d_dft_sel_i[3:0]), .wb_we_i (wbs_d_dft_we_i), .wb_cyc_i (wbs_d_dft_cyc_i), .wb_stb_i (wbs_d_dft_stb_i), .wb_dat_o (wbs_d_dft_dat_o), .wb_err_o (), .wb_ack_o (wbs_d_dft_ack_o), // Processor interrupt .int_o () ); endmodule // end aes_top_axi4lite
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : dft_top_top.v // Project : Common Evaluation Platform (CEP) // Description : This file provides a wishbone based-DFT core // module dft_top_top( wb_adr_i, wb_cyc_i, wb_dat_i, wb_sel_i, wb_stb_i, wb_we_i, wb_ack_o, wb_err_o, wb_dat_o, wb_clk_i, wb_rst_i, int_o ); parameter dw = 32; parameter aw = 32; input [aw-1:0] wb_adr_i; input wb_cyc_i; input [dw-1:0] wb_dat_i; input [3:0] wb_sel_i; input wb_stb_i; input wb_we_i; output wb_ack_o; output wb_err_o; output reg [dw-1:0] wb_dat_o; output int_o; input wb_clk_i; input wb_rst_i; assign wb_ack_o = 1'b1; assign wb_err_o = 1'b0; assign int_o = 1'b0; // Internal registers reg next; reg [63:0] dataX [0:31]; reg [63:0] dataY [0:31]; reg [5:0] xSel; reg [5:0] ySel; wire [63:0] dataIn, dataOut, dataR_Out; reg [63:0] data_In_data, data_In_addr, data_Out_addr; reg data_valid, data_In_write; wire next_out, next_posedge; // Implement MD5 I/O memory map interface // Write side always @(posedge wb_clk_i) begin if(wb_rst_i) begin next <= 0; data_In_write <= 0; data_In_addr <= 0; data_In_data[31:0] <= 0; data_In_data[63:32]<= 0; end else if(wb_stb_i & wb_we_i) case(wb_adr_i[5:2]) 0: next <= wb_dat_i[0]; 1: data_In_write <= wb_dat_i[0]; 2: data_In_addr <= wb_dat_i; 3: data_In_data[31:0] <= wb_dat_i; 4: data_In_data[63:32]<= wb_dat_i; 5: data_Out_addr <= wb_dat_i; default: ; endcase end // always @ (posedge wb_clk_i) // Implement MD5 I/O memory map interface // Read side always @(*) begin case(wb_adr_i[5:2]) 0: wb_dat_o = {31'b0, next}; 1: wb_dat_o = {31'b0, data_In_write}; 2: wb_dat_o = data_In_addr; 3: wb_dat_o = data_In_data[31:0]; 4: wb_dat_o = data_In_data[63:32]; 5: wb_dat_o = data_Out_addr; 6: wb_dat_o = dataR_Out[31:0]; 7: wb_dat_o = dataR_Out[63:32]; 8: wb_dat_o = {31'b0, data_valid}; default: wb_dat_o = 32'b0; endcase end // always @ (*) dft_top dft_top( .clk(wb_clk_i), .reset(wb_rst_i), .next(next_posedge), .next_out(next_out), .X0(dataIn[15:0]), .X1(dataIn[31:16]), .X2(dataIn[47:32]), .X3(dataIn[63:48]), .Y0(dataOut[15:0]), .Y1(dataOut[31:16]), .Y2(dataOut[47:32]), .Y3(dataOut[63:48])); reg data_In_write_r; always @(posedge wb_clk_i) begin data_In_write_r <= data_In_write; end wire data_In_write_posedge = data_In_write & ~data_In_write_r; always @ (posedge wb_clk_i) begin if(data_In_write_posedge) begin dataX[data_In_addr] <= data_In_data; end end assign dataR_Out=dataY[data_Out_addr]; reg next_r; always @(posedge wb_clk_i) begin next_r <= next; end assign next_posedge = next & ~next_r; always @ (posedge wb_clk_i) begin if(next_posedge) begin xSel <= 6'h00; end else if(xSel<6'b100000) begin xSel <= xSel +1; end end assign dataIn = dataX[xSel]; reg next_out_r; always @(posedge wb_clk_i) begin next_out_r <= next_out; end wire next_out_posedge = next_out & ~next_out_r; always @ (posedge wb_clk_i) begin if(next_out_posedge) begin ySel <= 6'h00; end else if(ySel<6'b100000) begin ySel <= ySel +1; dataY[ySel] = dataOut; end end always @ (posedge wb_clk_i) begin if(next_posedge) begin data_valid <= 0; end else if(next_out_posedge) begin data_valid <= 1; end end endmodule
/*------------------------------------------------------------------------------ * This code was generated by Spiral IIR Filter Generator, www.spiral.net * Copyright (c) 2006, Carnegie Mellon University * All rights reserved. * The code is distributed under a BSD style license * (see http://www.opensource.org/licenses/bsd-license.php) *------------------------------------------------------------------------------ */ /* ./iirGen.pl -A 256 0 378 0 179 0 32 0 2 0 0 0 -B 0 -4 22 -68 136 -191 191 -136 68 -22 4 0 -moduleName FIR_filter -fractionalBits 8 -bitWidth 32 -inData inData -inReg -outReg -outData outData -clk clk -reset reset -reset_edge negedge -filterForm 1 -debug -outFile ../outputs/filter_1536037053.v */ /* Warning: zero-valued filter taps have been optimized away. */ module FIR_filter ( inData, clk, outData, reset ); // Port mode declarations: input [31:0] inData; input clk; output [31:0] outData; input reset; //registerIn reg [31:0] inData_in; always@(posedge clk or negedge reset) begin if(~reset) begin inData_in <= 32'h00000000; end else begin inData_in <= inData; end end //registerOut reg [31:0] outData; wire [31:0] outData_in; always@(posedge clk or negedge reset) begin if(~reset) begin outData <= 32'h00000000; end else begin outData <= outData_in; end end wire [31:0] leftOut, rightOut; FIR_filter_firBlock_left my_FIR_filter_firBlock_left( .X(inData_in), .Y(leftOut), .clk(clk), .reset(reset) ); FIR_filter_firBlock_right my_FIR_filter_firBlock_right( .X(outData_in), .Y(rightOut), .clk(clk), .reset(reset) ); assign outData_in = leftOut + rightOut; // adder(32) //FIR_filter area estimate = 113925.875962894; endmodule //FIR_filter module FIR_filter_firBlock_left_MultiplyBlock ( X, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11 ); // Port mode declarations: input signed [31:0] X; output signed [31:0] Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11; wire [31:0] Y [0:10]; assign Y1 = Y[0]; assign Y2 = Y[1]; assign Y3 = Y[2]; assign Y4 = Y[3]; assign Y5 = Y[4]; assign Y6 = Y[5]; assign Y7 = Y[6]; assign Y8 = Y[7]; assign Y9 = Y[8]; assign Y10 = Y[9]; assign Y11 = Y[10]; //Multipliers: wire signed [39:0] w1, w0, w16, w17, w4, w3, w8, w11, w192, w191, w22, w22_, w68, w136, w136_, w191_, w68_, w4_; assign w1 = X; assign w0 = 0; assign w11 = w3 + w8; //2195.42405790882 = adderArea(3,34) assign w136 = w17 << 3; //shl(3,39) assign w136_ = -1 * w136; //1669.85284613971 = negArea(3,39) assign w16 = w1 << 4; //shl(4,35) assign w17 = w1 + w16; //2195.42405790882 = adderArea(4,35) assign w191 = w192 - w1; //2561.32791574853 = subArea(6,39) assign w191_ = -1 * w191; //1809.56165059559 = negArea(0,39) assign w192 = w3 << 6; //shl(6,39) assign w22 = w11 << 1; //shl(1,36) assign w22_ = -1 * w22; //1623.28324465441 = negArea(1,36) assign w3 = w4 - w1; //2408.3135227603 = subArea(2,33) assign w4 = w1 << 2; //shl(2,33) assign w4_ = -1 * w4; //1437.00483871323 = negArea(2,33) assign w68 = w17 << 2; //shl(2,38) assign w68_ = -1 * w68; //1669.85284613971 = negArea(2,38) assign w8 = w1 << 3; //shl(3,34) assign Y[0] = w4[39:8]; //BitwidthUsed(0, 25) assign Y[1] = w22_[39:8]; //BitwidthUsed(0, 28) assign Y[2] = w68[39:8]; //BitwidthUsed(0, 30) assign Y[3] = w136_[39:8]; //BitwidthUsed(0, 31) assign Y[4] = w191[39:8]; //BitwidthUsed(0, 31) assign Y[5] = w191_[39:8]; //BitwidthUsed(0, 31) assign Y[6] = w136[39:8]; //BitwidthUsed(0, 31) assign Y[7] = w68_[39:8]; //BitwidthUsed(0, 30) assign Y[8] = w22[39:8]; //BitwidthUsed(0, 28) assign Y[9] = w4_[39:8]; //BitwidthUsed(0, 25) assign Y[10] = w0[39:8]; //BitwidthUsed(none) //FIR_filter_firBlock_left_MultiplyBlock area estimate = 17570.0449805691; endmodule //FIR_filter_firBlock_left_MultiplyBlock module FIR_filter_firBlock_left ( X, clk, Y, reset ); // Port mode declarations: input [31:0] X; input clk; output [31:0] Y; input reset; //registerOut reg [31:0] Y; wire [31:0] Y_in; always@(posedge clk or negedge reset) begin if(~reset) begin Y <= 32'h00000000; end else begin Y <= Y_in; end end wire [31:0] multProducts [0:10]; FIR_filter_firBlock_left_MultiplyBlock my_FIR_filter_firBlock_left_MultiplyBlock( .X(X), .Y1(multProducts[0]), .Y2(multProducts[1]), .Y3(multProducts[2]), .Y4(multProducts[3]), .Y5(multProducts[4]), .Y6(multProducts[5]), .Y7(multProducts[6]), .Y8(multProducts[7]), .Y9(multProducts[8]), .Y10(multProducts[9]), .Y11(multProducts[10]) ); reg [31:0] firStep[0:9]; always@(posedge clk or negedge reset) begin if(~reset) begin firStep[0] <= 32'h00000000; firStep[1] <= 32'h00000000; firStep[2] <= 32'h00000000; firStep[3] <= 32'h00000000; firStep[4] <= 32'h00000000; firStep[5] <= 32'h00000000; firStep[6] <= 32'h00000000; firStep[7] <= 32'h00000000; firStep[8] <= 32'h00000000; firStep[9] <= 32'h00000000; end else begin firStep[0] <= multProducts[0]; // 2448.23046908235 = flop(0, 31) firStep[1] <= firStep[0] + multProducts[1]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[2] <= firStep[1] + multProducts[2]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[3] <= firStep[2] + multProducts[3]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[4] <= firStep[3] + multProducts[4]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[5] <= firStep[4] + multProducts[5]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[6] <= firStep[5] + multProducts[6]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[7] <= firStep[6] + multProducts[7]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[8] <= firStep[7] + multProducts[8]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[9] <= firStep[8] + multProducts[9]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) end end assign Y_in = firStep[9]+ multProducts[10];// 0 = adder(none) //FIR_filter_firBlock_left area estimate = 64259.3966616544; endmodule //FIR_filter_firBlock_left /* Warning: zero-valued filter taps have been optimized away. */ module FIR_filter_firBlock_right_MultiplyBlock ( X, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8 ); // Port mode declarations: input signed [31:0] X; output signed [31:0] Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8; wire [31:0] Y [0:7]; assign Y1 = Y[0]; assign Y2 = Y[1]; assign Y3 = Y[2]; assign Y4 = Y[3]; assign Y5 = Y[4]; assign Y6 = Y[5]; assign Y7 = Y[6]; assign Y8 = Y[7]; //Multipliers: wire signed [39:0] w1, w0, w4, w3, w192, w189, w5, w10, w179, w2, w2_, w32, w32_, w179_, w378, w378_; assign w1 = X; assign w0 = 0; assign w10 = w5 << 1; //shl(1,35) assign w179 = w189 - w10; //2943.86389821912 = subArea(1,39) assign w179_ = -1 * w179; //1809.56165059559 = negArea(0,39) assign w189 = w192 - w3; //2484.82071925441 = subArea(6,38) assign w192 = w3 << 6; //shl(6,38) assign w2 = w1 << 1; //shl(1,32) assign w2_ = -1 * w2; //1437.00483871323 = negArea(1,32) assign w3 = w4 - w1; //2331.80632626618 = subArea(2,32) assign w32 = w1 << 5; //shl(5,36) assign w32_ = -1 * w32; //1437.00483871323 = negArea(5,36) assign w378 = w189 << 1; //shl(1,39) assign w378_ = -1 * w378; //1762.99204911029 = negArea(1,39) assign w4 = w1 << 2; //shl(2,32) assign w5 = w1 + w4; //2195.42405790882 = adderArea(2,33) assign Y[0] = w2_[39:8]; //BitwidthUsed(0, 24) assign Y[1] = w0[39:8]; //BitwidthUsed(none) assign Y[2] = w32_[39:8]; //BitwidthUsed(0, 28) assign Y[3] = w0[39:8]; //BitwidthUsed(none) assign Y[4] = w179_[39:8]; //BitwidthUsed(0, 31) assign Y[5] = w0[39:8]; //BitwidthUsed(none) assign Y[6] = w378_[39:8]; //BitwidthUsed(0, 31) assign Y[7] = w0[39:8]; //BitwidthUsed(none) //FIR_filter_firBlock_right_MultiplyBlock area estimate = 16402.4783787809; endmodule //FIR_filter_firBlock_right_MultiplyBlock module FIR_filter_firBlock_right ( X, clk, Y, reset ); // Port mode declarations: input [31:0] X; input clk; output [31:0] Y; input reset; //registerOut reg [31:0] Y; wire [31:0] Y_in; always@(posedge clk or negedge reset) begin if(~reset) begin Y <= 32'h00000000; end else begin Y <= Y_in; end end wire [31:0] multProducts [0:7]; FIR_filter_firBlock_right_MultiplyBlock my_FIR_filter_firBlock_right_MultiplyBlock( .X(X), .Y1(multProducts[0]), .Y2(multProducts[1]), .Y3(multProducts[2]), .Y4(multProducts[3]), .Y5(multProducts[4]), .Y6(multProducts[5]), .Y7(multProducts[6]), .Y8(multProducts[7]) ); reg [31:0] firStep[0:6]; always@(posedge clk or negedge reset) begin if(~reset) begin firStep[0] <= 32'h00000000; firStep[1] <= 32'h00000000; firStep[2] <= 32'h00000000; firStep[3] <= 32'h00000000; firStep[4] <= 32'h00000000; firStep[5] <= 32'h00000000; firStep[6] <= 32'h00000000; end else begin firStep[0] <= multProducts[0]; // 2448.23046908235 = flop(0, 31) firStep[1] <= firStep[0] + multProducts[1]; // 2448.23046908235 = flop(0, 31) + adder(none) firStep[2] <= firStep[1] + multProducts[2]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[3] <= firStep[2] + multProducts[3]; // 2448.23046908235 = flop(0, 31) + adder(none) firStep[4] <= firStep[3] + multProducts[4]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[5] <= firStep[4] + multProducts[5]; // 2448.23046908235 = flop(0, 31) + adder(none) firStep[6] <= firStep[5] + multProducts[6]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) end end assign Y_in = firStep[6]+ multProducts[7];// 0 = adder(none) //FIR_filter_firBlock_right area estimate = 42574.5943051662; endmodule //FIR_filter_firBlock_right
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : fir_top.v // Project : Common Evaluation Platform (CEP) // Description : This file provides a wishbone based-FIR core // module fir_top( wb_adr_i, wb_cyc_i, wb_dat_i, wb_sel_i, wb_stb_i, wb_we_i, wb_ack_o, wb_err_o, wb_dat_o, wb_clk_i, wb_rst_i, int_o ); parameter dw = 32; parameter aw = 32; input [aw-1:0] wb_adr_i; input wb_cyc_i; input [dw-1:0] wb_dat_i; input [3:0] wb_sel_i; input wb_stb_i; input wb_we_i; output wb_ack_o; output wb_err_o; output reg [dw-1:0] wb_dat_o; output int_o; input wb_clk_i; input wb_rst_i; assign wb_ack_o = 1'b1; assign wb_err_o = 1'b0; assign int_o = 1'b0; // Internal registers reg next; reg [31:0] dataX [0:31]; reg [31:0] dataY [0:31]; reg [5:0] xSel=6'b0; reg [5:0] ySel=6'b0; reg [5:0] count; wire [31:0] dataIn, dataOut, data_Out; reg [31:0] data_In_data, data_In_addr, data_Out_addr; reg data_valid, data_In_write; wire next_out; // Implement MD5 I/O memory map interface // Write side always @(posedge wb_clk_i) begin if(wb_rst_i) begin next <= 0; data_In_write <= 0; data_In_addr <= 0; data_In_data <= 0; end else if(wb_stb_i & wb_we_i) case(wb_adr_i[5:2]) 0: next <= wb_dat_i[0]; 1: data_In_write <= wb_dat_i[0]; 2: data_In_addr <= wb_dat_i; 3: data_In_data <= wb_dat_i; 4: data_Out_addr <= wb_dat_i; default: ; endcase end // always @ (posedge wb_clk_i) // Implement MD5 I/O memory map interface // Read side always @(*) begin case(wb_adr_i[5:2]) 0: wb_dat_o = {31'b0, next}; 1: wb_dat_o = {31'b0, data_In_write}; 2: wb_dat_o = data_In_addr; 3: wb_dat_o = data_In_data; 4: wb_dat_o = data_Out_addr; 5: wb_dat_o = data_Out; 6: wb_dat_o = {31'b0, data_valid}; default: wb_dat_o = 32'b0; endcase end // always @ (*) FIR_filter FIR_filter( .clk(wb_clk_i), .reset(~wb_rst_i), .inData(dataIn), .outData(dataOut)); reg data_In_write_r; always @(posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) data_In_write_r <= 0; else data_In_write_r <= data_In_write; end wire data_In_write_posedge = data_In_write & ~data_In_write_r; reg [15:0] i; always @ (posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) for (i = 0; i < 32; i = i + 1) dataX[i] <= 0; else dataX[data_In_addr] <= data_In_data; end assign data_Out = dataY[data_Out_addr]; reg next_r; always @(posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) next_r <= 0; else next_r <= next; end wire next_posedge = next & ~next_r; always @ (posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) xSel <= 0; else if(next_posedge) xSel <= 6'h00; else if(xSel<6'b100000) xSel <= xSel + 1; end assign dataIn = (xSel<6'b100000) ? dataX[xSel] : 32'b0; always @ (posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) count <= 0; else if(next_posedge) begin count <= 6'h00; end else if(xSel<4'b1010) begin count <= count +1; end end assign next_out = (count == 4'b1000); reg next_out_r; always @(posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) next_out_r <= 0; else next_out_r <= next_out; end wire next_out_posedge = next_out & ~next_out_r; always @ (posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) begin ySel <= 0; for (i = 0; i < 32; i = i + 1) dataY[i] <= 0; end else if(next_out_posedge) begin ySel <= 6'h00; end else if(ySel<6'b100000) begin ySel <= ySel +1; dataY[ySel] = dataOut; end end always @ (posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) data_valid <= 0; else if(next_posedge) begin data_valid <= 0; end else if(next_out_posedge) begin data_valid <= 1; end end endmodule
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : fir_top_axi4lite.v // Project : Common Evaluation Platform (CEP) // Description : This file provides an axi4-lite wrapper for the wishbone based-FIR core // module fir_top_axi4lite ( // Clock & Reset input logic clk_i, input logic rst_ni, // AXI4-Lite Slave Interface AXI_LITE.Slave slave ); // AES wishbone slave wires wire wb_clk; wire wb_rst; wire wb_rst_n; wire [slave.AXI_ADDR_WIDTH - 1:0] wbs_d_fir_adr_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_fir_dat_i; wire [3:0] wbs_d_fir_sel_i; wire wbs_d_fir_we_i; wire wbs_d_fir_cyc_i; wire wbs_d_fir_stb_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_fir_dat_o; wire wbs_d_fir_ack_o; // Instantiate the AXI4Lite to Wishbone bridge bonfire_axi4l2wb #( .ADRWIDTH (slave.AXI_ADDR_WIDTH), .FAST_READ_TERM (1'd0) ) bonfire_axi4l2wb_inst ( .S_AXI_ACLK (clk_i), .S_AXI_ARESETN (rst_ni), .S_AXI_AWADDR (slave.aw_addr), .S_AXI_AWVALID (slave.aw_valid), .S_AXI_AWREADY (slave.aw_ready), .S_AXI_WDATA (slave.w_data), .S_AXI_WSTRB (slave.w_strb), .S_AXI_WVALID (slave.w_valid), .S_AXI_WREADY (slave.w_ready), .S_AXI_ARADDR (slave.ar_addr), .S_AXI_ARVALID (slave.ar_valid), .S_AXI_ARREADY (slave.ar_ready), .S_AXI_RDATA (slave.r_data), .S_AXI_RRESP (slave.r_resp), .S_AXI_RVALID (slave.r_valid), .S_AXI_RREADY (slave.r_ready), .S_AXI_BRESP (slave.b_resp), .S_AXI_BVALID (slave.b_valid), .S_AXI_BREADY (slave.b_ready), .wb_clk_o (wb_clk), .wb_rst_o (wb_rst), .wb_addr_o (wbs_d_fir_adr_i), .wb_dat_o (wbs_d_fir_dat_i), .wb_we_o (wbs_d_fir_we_i), .wb_sel_o (wbs_d_fir_sel_i), .wb_stb_o (wbs_d_fir_stb_i), .wb_cyc_o (wbs_d_fir_cyc_i), .wb_dat_i (wbs_d_fir_dat_o), .wb_ack_i (wbs_d_fir_ack_o) ); // Instantiate the wishbone-based FIR Core fir_top fir_top_inst ( // Wishbone Slave interface .wb_clk_i (wb_clk), .wb_rst_i (wb_rst), .wb_dat_i (wbs_d_fir_dat_i), .wb_adr_i (wbs_d_fir_adr_i), .wb_sel_i (wbs_d_fir_sel_i[3:0]), .wb_we_i (wbs_d_fir_we_i), .wb_cyc_i (wbs_d_fir_cyc_i), .wb_stb_i (wbs_d_fir_stb_i), .wb_dat_o (wbs_d_fir_dat_o), .wb_err_o (), .wb_ack_o (wbs_d_fir_ack_o), // Processor interrupt .int_o () ); endmodule // end aes_top_axi4lite
/* * This source file contains a Verilog description of an IP core * automatically generated by the SPIRAL HDL Generator. * * This product includes a hardware design developed by Carnegie Mellon University. * * Copyright (c) 2005-2011 by Peter A. Milder for the SPIRAL Project, * Carnegie Mellon University * * For more information, see the SPIRAL project website at: * http://www.spiral.net * * This design is provided for internal, non-commercial research use only * and is not for redistribution, with or without modifications. * * You may not use the name "Carnegie Mellon University" or derivations * thereof to endorse or promote products derived from this software. * * THE SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY WARRANTY OF ANY KIND, EITHER * EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO ANY WARRANTY * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS OR BE ERROR-FREE AND ANY * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, * TITLE, OR NON-INFRINGEMENT. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY * BE LIABLE FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO DIRECT, INDIRECT, * SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, OR IN * ANY WAY CONNECTED WITH THIS SOFTWARE (WHETHER OR NOT BASED UPON WARRANTY, * CONTRACT, TORT OR OTHERWISE). * */ // Input/output stream: 2 complex words per cycle // Throughput: one transform every 32 cycles // Latency: 332 cycles // Resources required: // 20 multipliers (16 x 16 bit) // 34 adders (16 x 16 bit) // 4 RAMs (16 words, 32 bits per word) // 4 RAMs (8 words, 32 bits per word) // 12 RAMs (64 words, 32 bits per word) // 4 RAMs (32 words, 32 bits per word) // 2 ROMs (32 words, 16 bits per word) // 2 ROMs (8 words, 16 bits per word) // 12 ROMs (32 words, 5 bits per word) // 2 ROMs (16 words, 16 bits per word) // Generated on Tue Sep 04 00:36:47 EDT 2018 // Latency: 332 clock cycles // Throughput: 1 transform every 32 cycles // We use an interleaved complex data format. X0 represents the // real portion of the first input, and X1 represents the imaginary // portion. The X variables are system inputs and the Y variables // are system outputs. // The design uses a system of flag signals to indicate the // beginning of the input and output data streams. The 'next' // input (asserted high), is used to instruct the system that the // input stream will begin on the following cycle. // This system has a 'gap' of 32 cycles. This means that // 32 cycles must elapse between the beginning of the input // vectors. // The output signal 'next_out' (also asserted high) indicates // that the output vector will begin streaming out of the system // on the following cycle. // The system has a latency of 332 cycles. This means that // the 'next_out' will be asserted 332 cycles after the user // asserts 'next'. // The simple testbench below will demonstrate the timing for loading // and unloading data vectors. // The system reset signal is asserted high. // Please note: when simulating floating point code, you must include // Xilinx's DSP slice simulation module. // Latency: 332 // Gap: 32 // module_name_is:dft_top module idft_top(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [15:0] t0_0; wire [15:0] t0_1; wire [15:0] t0_2; wire [15:0] t0_3; wire next_0; wire [15:0] t1_0; wire [15:0] t1_1; wire [15:0] t1_2; wire [15:0] t1_3; wire next_1; wire [15:0] t2_0; wire [15:0] t2_1; wire [15:0] t2_2; wire [15:0] t2_3; wire next_2; wire [15:0] t3_0; wire [15:0] t3_1; wire [15:0] t3_2; wire [15:0] t3_3; wire next_3; wire [15:0] t4_0; wire [15:0] t4_1; wire [15:0] t4_2; wire [15:0] t4_3; wire next_4; wire [15:0] t5_0; wire [15:0] t5_1; wire [15:0] t5_2; wire [15:0] t5_3; wire next_5; wire [15:0] t6_0; wire [15:0] t6_1; wire [15:0] t6_2; wire [15:0] t6_3; wire next_6; wire [15:0] t7_0; wire [15:0] t7_1; wire [15:0] t7_2; wire [15:0] t7_3; wire next_7; wire [15:0] t8_0; wire [15:0] t8_1; wire [15:0] t8_2; wire [15:0] t8_3; wire next_8; wire [15:0] t9_0; wire [15:0] t9_1; wire [15:0] t9_2; wire [15:0] t9_3; wire next_9; wire [15:0] t10_0; wire [15:0] t10_1; wire [15:0] t10_2; wire [15:0] t10_3; wire next_10; wire [15:0] t11_0; wire [15:0] t11_1; wire [15:0] t11_2; wire [15:0] t11_3; wire next_11; wire [15:0] t12_0; wire [15:0] t12_1; wire [15:0] t12_2; wire [15:0] t12_3; wire next_12; wire [15:0] t13_0; wire [15:0] t13_1; wire [15:0] t13_2; wire [15:0] t13_3; wire next_13; wire [15:0] t14_0; wire [15:0] t14_1; wire [15:0] t14_2; wire [15:0] t14_3; wire next_14; wire [15:0] t15_0; wire [15:0] t15_1; wire [15:0] t15_2; wire [15:0] t15_3; wire next_15; wire [15:0] t16_0; wire [15:0] t16_1; wire [15:0] t16_2; wire [15:0] t16_3; wire next_16; wire [15:0] t17_0; wire [15:0] t17_1; wire [15:0] t17_2; wire [15:0] t17_3; wire next_17; wire [15:0] t18_0; wire [15:0] t18_1; wire [15:0] t18_2; wire [15:0] t18_3; wire next_18; assign t0_0 = X0; assign Y0 = t18_0; assign t0_1 = X1; assign Y1 = t18_1; assign t0_2 = X2; assign Y2 = t18_2; assign t0_3 = X3; assign Y3 = t18_3; assign next_0 = next; assign next_out = next_18; // latency=68, gap=32 rc7079 stage0(.clk(clk), .reset(reset), .next(next_0), .next_out(next_1), .X0(t0_0), .Y0(t1_0), .X1(t0_1), .Y1(t1_1), .X2(t0_2), .Y2(t1_2), .X3(t0_3), .Y3(t1_3)); // latency=2, gap=32 codeBlock7081 stage1(.clk(clk), .reset(reset), .next_in(next_1), .next_out(next_2), .X0_in(t1_0), .Y0(t2_0), .X1_in(t1_1), .Y1(t2_1), .X2_in(t1_2), .Y2(t2_2), .X3_in(t1_3), .Y3(t2_3)); // latency=8, gap=32 rc7163 stage2(.clk(clk), .reset(reset), .next(next_2), .next_out(next_3), .X0(t2_0), .Y0(t3_0), .X1(t2_1), .Y1(t3_1), .X2(t2_2), .Y2(t3_2), .X3(t2_3), .Y3(t3_3)); // latency=8, gap=32 DirSum_7344 stage3(.next(next_3), .clk(clk), .reset(reset), .next_out(next_4), .X0(t3_0), .Y0(t4_0), .X1(t3_1), .Y1(t4_1), .X2(t3_2), .Y2(t4_2), .X3(t3_3), .Y3(t4_3)); // latency=2, gap=32 codeBlock7347 stage4(.clk(clk), .reset(reset), .next_in(next_4), .next_out(next_5), .X0_in(t4_0), .Y0(t5_0), .X1_in(t4_1), .Y1(t5_1), .X2_in(t4_2), .Y2(t5_2), .X3_in(t4_3), .Y3(t5_3)); // latency=12, gap=32 rc7429 stage5(.clk(clk), .reset(reset), .next(next_5), .next_out(next_6), .X0(t5_0), .Y0(t6_0), .X1(t5_1), .Y1(t6_1), .X2(t5_2), .Y2(t6_2), .X3(t5_3), .Y3(t6_3)); // latency=8, gap=32 DirSum_7618 stage6(.next(next_6), .clk(clk), .reset(reset), .next_out(next_7), .X0(t6_0), .Y0(t7_0), .X1(t6_1), .Y1(t7_1), .X2(t6_2), .Y2(t7_2), .X3(t6_3), .Y3(t7_3)); // latency=2, gap=32 codeBlock7621 stage7(.clk(clk), .reset(reset), .next_in(next_7), .next_out(next_8), .X0_in(t7_0), .Y0(t8_0), .X1_in(t7_1), .Y1(t8_1), .X2_in(t7_2), .Y2(t8_2), .X3_in(t7_3), .Y3(t8_3)); // latency=20, gap=32 rc7703 stage8(.clk(clk), .reset(reset), .next(next_8), .next_out(next_9), .X0(t8_0), .Y0(t9_0), .X1(t8_1), .Y1(t9_1), .X2(t8_2), .Y2(t9_2), .X3(t8_3), .Y3(t9_3)); // latency=8, gap=32 DirSum_7908 stage9(.next(next_9), .clk(clk), .reset(reset), .next_out(next_10), .X0(t9_0), .Y0(t10_0), .X1(t9_1), .Y1(t10_1), .X2(t9_2), .Y2(t10_2), .X3(t9_3), .Y3(t10_3)); // latency=2, gap=32 codeBlock7911 stage10(.clk(clk), .reset(reset), .next_in(next_10), .next_out(next_11), .X0_in(t10_0), .Y0(t11_0), .X1_in(t10_1), .Y1(t11_1), .X2_in(t10_2), .Y2(t11_2), .X3_in(t10_3), .Y3(t11_3)); // latency=36, gap=32 rc7993 stage11(.clk(clk), .reset(reset), .next(next_11), .next_out(next_12), .X0(t11_0), .Y0(t12_0), .X1(t11_1), .Y1(t12_1), .X2(t11_2), .Y2(t12_2), .X3(t11_3), .Y3(t12_3)); // latency=8, gap=32 DirSum_8230 stage12(.next(next_12), .clk(clk), .reset(reset), .next_out(next_13), .X0(t12_0), .Y0(t13_0), .X1(t12_1), .Y1(t13_1), .X2(t12_2), .Y2(t13_2), .X3(t12_3), .Y3(t13_3)); // latency=2, gap=32 codeBlock8233 stage13(.clk(clk), .reset(reset), .next_in(next_13), .next_out(next_14), .X0_in(t13_0), .Y0(t14_0), .X1_in(t13_1), .Y1(t14_1), .X2_in(t13_2), .Y2(t14_2), .X3_in(t13_3), .Y3(t14_3)); // latency=68, gap=32 rc8315 stage14(.clk(clk), .reset(reset), .next(next_14), .next_out(next_15), .X0(t14_0), .Y0(t15_0), .X1(t14_1), .Y1(t15_1), .X2(t14_2), .Y2(t15_2), .X3(t14_3), .Y3(t15_3)); // latency=8, gap=32 DirSum_8615 stage15(.next(next_15), .clk(clk), .reset(reset), .next_out(next_16), .X0(t15_0), .Y0(t16_0), .X1(t15_1), .Y1(t16_1), .X2(t15_2), .Y2(t16_2), .X3(t15_3), .Y3(t16_3)); // latency=2, gap=32 codeBlock8618 stage16(.clk(clk), .reset(reset), .next_in(next_16), .next_out(next_17), .X0_in(t16_0), .Y0(t17_0), .X1_in(t16_1), .Y1(t17_1), .X2_in(t16_2), .Y2(t17_2), .X3_in(t16_3), .Y3(t17_3)); // latency=68, gap=32 rc8700 stage17(.clk(clk), .reset(reset), .next(next_17), .next_out(next_18), .X0(t17_0), .Y0(t18_0), .X1(t17_1), .Y1(t18_1), .X2(t17_2), .Y2(t18_2), .X3(t17_3), .Y3(t18_3)); endmodule // Latency: 68 // Gap: 32 module rc7079(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm7077 instPerm9645(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet7077(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [4:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 5'd0: control <= 1'b1; 5'd1: control <= 1'b1; 5'd2: control <= 1'b1; 5'd3: control <= 1'b1; 5'd4: control <= 1'b1; 5'd5: control <= 1'b1; 5'd6: control <= 1'b1; 5'd7: control <= 1'b1; 5'd8: control <= 1'b1; 5'd9: control <= 1'b1; 5'd10: control <= 1'b1; 5'd11: control <= 1'b1; 5'd12: control <= 1'b1; 5'd13: control <= 1'b1; 5'd14: control <= 1'b1; 5'd15: control <= 1'b1; 5'd16: control <= 1'b0; 5'd17: control <= 1'b0; 5'd18: control <= 1'b0; 5'd19: control <= 1'b0; 5'd20: control <= 1'b0; 5'd21: control <= 1'b0; 5'd22: control <= 1'b0; 5'd23: control <= 1'b0; 5'd24: control <= 1'b0; 5'd25: control <= 1'b0; 5'd26: control <= 1'b0; 5'd27: control <= 1'b0; 5'd28: control <= 1'b0; 5'd29: control <= 1'b0; 5'd30: control <= 1'b0; 5'd31: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 68 // Gap: 32 module perm7077(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 32; parameter addrbits = 5; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm0; assign tm0 = 0; shiftRegFIFO #(3, 1) shiftFIFO_9650(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9651(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); nextReg #(31, 5) nextReg_9662(.X(next), .Y(next2), .reset(reset), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_9663(.X(next2), .Y(next3), .clk(clk)); nextReg #(32, 5) nextReg_9666(.X(next3), .Y(next4), .reset(reset), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9667(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(31, 1) shiftFIFO_9670(.X(tm0), .Y(tm0_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_9673(.X(tm0_d), .Y(tm0_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 5) shiftFIFO_9678(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm0_d, s1rdloc}) {1'd0, 5'd0}: s1rd0 <= 16; {1'd0, 5'd1}: s1rd0 <= 24; {1'd0, 5'd2}: s1rd0 <= 20; {1'd0, 5'd3}: s1rd0 <= 28; {1'd0, 5'd4}: s1rd0 <= 18; {1'd0, 5'd5}: s1rd0 <= 26; {1'd0, 5'd6}: s1rd0 <= 22; {1'd0, 5'd7}: s1rd0 <= 30; {1'd0, 5'd8}: s1rd0 <= 17; {1'd0, 5'd9}: s1rd0 <= 25; {1'd0, 5'd10}: s1rd0 <= 21; {1'd0, 5'd11}: s1rd0 <= 29; {1'd0, 5'd12}: s1rd0 <= 19; {1'd0, 5'd13}: s1rd0 <= 27; {1'd0, 5'd14}: s1rd0 <= 23; {1'd0, 5'd15}: s1rd0 <= 31; {1'd0, 5'd16}: s1rd0 <= 0; {1'd0, 5'd17}: s1rd0 <= 8; {1'd0, 5'd18}: s1rd0 <= 4; {1'd0, 5'd19}: s1rd0 <= 12; {1'd0, 5'd20}: s1rd0 <= 2; {1'd0, 5'd21}: s1rd0 <= 10; {1'd0, 5'd22}: s1rd0 <= 6; {1'd0, 5'd23}: s1rd0 <= 14; {1'd0, 5'd24}: s1rd0 <= 1; {1'd0, 5'd25}: s1rd0 <= 9; {1'd0, 5'd26}: s1rd0 <= 5; {1'd0, 5'd27}: s1rd0 <= 13; {1'd0, 5'd28}: s1rd0 <= 3; {1'd0, 5'd29}: s1rd0 <= 11; {1'd0, 5'd30}: s1rd0 <= 7; {1'd0, 5'd31}: s1rd0 <= 15; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm0_d, s1rdloc}) {1'd0, 5'd0}: s1rd1 <= 0; {1'd0, 5'd1}: s1rd1 <= 8; {1'd0, 5'd2}: s1rd1 <= 4; {1'd0, 5'd3}: s1rd1 <= 12; {1'd0, 5'd4}: s1rd1 <= 2; {1'd0, 5'd5}: s1rd1 <= 10; {1'd0, 5'd6}: s1rd1 <= 6; {1'd0, 5'd7}: s1rd1 <= 14; {1'd0, 5'd8}: s1rd1 <= 1; {1'd0, 5'd9}: s1rd1 <= 9; {1'd0, 5'd10}: s1rd1 <= 5; {1'd0, 5'd11}: s1rd1 <= 13; {1'd0, 5'd12}: s1rd1 <= 3; {1'd0, 5'd13}: s1rd1 <= 11; {1'd0, 5'd14}: s1rd1 <= 7; {1'd0, 5'd15}: s1rd1 <= 15; {1'd0, 5'd16}: s1rd1 <= 16; {1'd0, 5'd17}: s1rd1 <= 24; {1'd0, 5'd18}: s1rd1 <= 20; {1'd0, 5'd19}: s1rd1 <= 28; {1'd0, 5'd20}: s1rd1 <= 18; {1'd0, 5'd21}: s1rd1 <= 26; {1'd0, 5'd22}: s1rd1 <= 22; {1'd0, 5'd23}: s1rd1 <= 30; {1'd0, 5'd24}: s1rd1 <= 17; {1'd0, 5'd25}: s1rd1 <= 25; {1'd0, 5'd26}: s1rd1 <= 21; {1'd0, 5'd27}: s1rd1 <= 29; {1'd0, 5'd28}: s1rd1 <= 19; {1'd0, 5'd29}: s1rd1 <= 27; {1'd0, 5'd30}: s1rd1 <= 23; {1'd0, 5'd31}: s1rd1 <= 31; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet7077 sw(tm0_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm0_dd, writeCycle}) {1'd0, 5'd0}: s2wr0 <= 16; {1'd0, 5'd1}: s2wr0 <= 17; {1'd0, 5'd2}: s2wr0 <= 18; {1'd0, 5'd3}: s2wr0 <= 19; {1'd0, 5'd4}: s2wr0 <= 20; {1'd0, 5'd5}: s2wr0 <= 21; {1'd0, 5'd6}: s2wr0 <= 22; {1'd0, 5'd7}: s2wr0 <= 23; {1'd0, 5'd8}: s2wr0 <= 24; {1'd0, 5'd9}: s2wr0 <= 25; {1'd0, 5'd10}: s2wr0 <= 26; {1'd0, 5'd11}: s2wr0 <= 27; {1'd0, 5'd12}: s2wr0 <= 28; {1'd0, 5'd13}: s2wr0 <= 29; {1'd0, 5'd14}: s2wr0 <= 30; {1'd0, 5'd15}: s2wr0 <= 31; {1'd0, 5'd16}: s2wr0 <= 0; {1'd0, 5'd17}: s2wr0 <= 1; {1'd0, 5'd18}: s2wr0 <= 2; {1'd0, 5'd19}: s2wr0 <= 3; {1'd0, 5'd20}: s2wr0 <= 4; {1'd0, 5'd21}: s2wr0 <= 5; {1'd0, 5'd22}: s2wr0 <= 6; {1'd0, 5'd23}: s2wr0 <= 7; {1'd0, 5'd24}: s2wr0 <= 8; {1'd0, 5'd25}: s2wr0 <= 9; {1'd0, 5'd26}: s2wr0 <= 10; {1'd0, 5'd27}: s2wr0 <= 11; {1'd0, 5'd28}: s2wr0 <= 12; {1'd0, 5'd29}: s2wr0 <= 13; {1'd0, 5'd30}: s2wr0 <= 14; {1'd0, 5'd31}: s2wr0 <= 15; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm0_dd, writeCycle}) {1'd0, 5'd0}: s2wr1 <= 0; {1'd0, 5'd1}: s2wr1 <= 1; {1'd0, 5'd2}: s2wr1 <= 2; {1'd0, 5'd3}: s2wr1 <= 3; {1'd0, 5'd4}: s2wr1 <= 4; {1'd0, 5'd5}: s2wr1 <= 5; {1'd0, 5'd6}: s2wr1 <= 6; {1'd0, 5'd7}: s2wr1 <= 7; {1'd0, 5'd8}: s2wr1 <= 8; {1'd0, 5'd9}: s2wr1 <= 9; {1'd0, 5'd10}: s2wr1 <= 10; {1'd0, 5'd11}: s2wr1 <= 11; {1'd0, 5'd12}: s2wr1 <= 12; {1'd0, 5'd13}: s2wr1 <= 13; {1'd0, 5'd14}: s2wr1 <= 14; {1'd0, 5'd15}: s2wr1 <= 15; {1'd0, 5'd16}: s2wr1 <= 16; {1'd0, 5'd17}: s2wr1 <= 17; {1'd0, 5'd18}: s2wr1 <= 18; {1'd0, 5'd19}: s2wr1 <= 19; {1'd0, 5'd20}: s2wr1 <= 20; {1'd0, 5'd21}: s2wr1 <= 21; {1'd0, 5'd22}: s2wr1 <= 22; {1'd0, 5'd23}: s2wr1 <= 23; {1'd0, 5'd24}: s2wr1 <= 24; {1'd0, 5'd25}: s2wr1 <= 25; {1'd0, 5'd26}: s2wr1 <= 26; {1'd0, 5'd27}: s2wr1 <= 27; {1'd0, 5'd28}: s2wr1 <= 28; {1'd0, 5'd29}: s2wr1 <= 29; {1'd0, 5'd30}: s2wr1 <= 30; {1'd0, 5'd31}: s2wr1 <= 31; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule module memMod(in, out, inAddr, outAddr, writeSel, clk); parameter depth=1024, width=16, logDepth=10; input [width-1:0] in; input [logDepth-1:0] inAddr, outAddr; input writeSel, clk; output [width-1:0] out; reg [width-1:0] out; // synthesis attribute ram_style of mem is block reg [width-1:0] mem[depth-1:0]; always @(posedge clk) begin out <= mem[outAddr]; if (writeSel) mem[inAddr] <= in; end endmodule module memMod_dist(in, out, inAddr, outAddr, writeSel, clk); parameter depth=1024, width=16, logDepth=10; input [width-1:0] in; input [logDepth-1:0] inAddr, outAddr; input writeSel, clk; output [width-1:0] out; reg [width-1:0] out; // synthesis attribute ram_style of mem is distributed reg [width-1:0] mem[depth-1:0]; always @(posedge clk) begin out <= mem[outAddr]; if (writeSel) mem[inAddr] <= in; end endmodule module shiftRegFIFO(X, Y, clk); parameter depth=1, width=1; output [width-1:0] Y; input [width-1:0] X; input clk; reg [width-1:0] mem [depth-1:0]; integer index; assign Y = mem[depth-1]; always @ (posedge clk) begin for(index=1;index<depth;index=index+1) begin mem[index] <= mem[index-1]; end mem[0]<=X; end endmodule module nextReg(X, Y, reset, clk); parameter depth=2, logDepth=1; output Y; input X; input clk, reset; reg [logDepth:0] count; reg active; assign Y = (count == depth) ? 1 : 0; always @ (posedge clk) begin if (reset == 1) begin count <= 0; active <= 0; end else if (X == 1) begin active <= 1; count <= 1; end else if (count == depth) begin count <= 0; active <= 0; end else if (active) count <= count+1; end endmodule // Latency: 2 // Gap: 1 module codeBlock7081(clk, reset, next_in, next_out, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(1, 1) shiftFIFO_9685(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a309; wire signed [15:0] a310; wire signed [15:0] a311; wire signed [15:0] a312; wire signed [15:0] t141; wire signed [15:0] t142; wire signed [15:0] t143; wire signed [15:0] t144; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; assign a309 = X0; assign a310 = X2; assign a311 = X1; assign a312 = X3; assign Y0 = t141; assign Y1 = t142; assign Y2 = t143; assign Y3 = t144; addfxp #(16, 1) add7093(.a(a309), .b(a310), .clk(clk), .q(t141)); // 0 addfxp #(16, 1) add7108(.a(a311), .b(a312), .clk(clk), .q(t142)); // 0 subfxp #(16, 1) sub7123(.a(a309), .b(a310), .clk(clk), .q(t143)); // 0 subfxp #(16, 1) sub7138(.a(a311), .b(a312), .clk(clk), .q(t144)); // 0 always @(posedge clk) begin if (reset == 1) begin end else begin X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; end end endmodule // Latency: 8 // Gap: 2 module rc7163(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm7161 instPerm9686(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet7161(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [0:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 1'd0: control <= 1'b1; 1'd1: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 8 // Gap: 2 module perm7161(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 2; parameter addrbits = 1; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm1; assign tm1 = 0; shiftRegFIFO #(3, 1) shiftFIFO_9691(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9692(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); shiftRegFIFO #(1, 1) shiftFIFO_9701(.X(next), .Y(next2), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_9702(.X(next2), .Y(next3), .clk(clk)); shiftRegFIFO #(2, 1) shiftFIFO_9703(.X(next3), .Y(next4), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9704(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9707(.X(tm1), .Y(tm1_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_9710(.X(tm1_d), .Y(tm1_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 1) shiftFIFO_9715(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm1_d, s1rdloc}) {1'd0, 1'd0}: s1rd0 <= 1; {1'd0, 1'd1}: s1rd0 <= 0; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm1_d, s1rdloc}) {1'd0, 1'd0}: s1rd1 <= 0; {1'd0, 1'd1}: s1rd1 <= 1; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet7161 sw(tm1_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm1_dd, writeCycle}) {1'd0, 1'd0}: s2wr0 <= 1; {1'd0, 1'd1}: s2wr0 <= 0; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm1_dd, writeCycle}) {1'd0, 1'd0}: s2wr1 <= 0; {1'd0, 1'd1}: s2wr1 <= 1; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule // Latency: 8 // Gap: 2 module DirSum_7344(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; reg [0:0] i5; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; always @(posedge clk) begin if (reset == 1) begin i5 <= 0; end else begin if (next == 1) i5 <= 0; else if (i5 == 1) i5 <= 0; else i5 <= i5 + 1; end end codeBlock7166 codeBlockIsnt9716(.clk(clk), .reset(reset), .next_in(next), .next_out(next_out), .i5_in(i5), .X0_in(X0), .Y0(Y0), .X1_in(X1), .Y1(Y1), .X2_in(X2), .Y2(Y2), .X3_in(X3), .Y3(Y3)); endmodule module D18_7334(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [0:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h4000; 1: out3 <= 16'h0; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule module D20_7342(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [0:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h0; 1: out3 <= 16'h4000; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule // Latency: 8 // Gap: 1 module codeBlock7166(clk, reset, next_in, next_out, i5_in, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [0:0] i5_in; reg [0:0] i5; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(7, 1) shiftFIFO_9719(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a293; wire signed [15:0] a282; wire signed [15:0] a296; wire signed [15:0] a286; wire signed [15:0] a297; wire signed [15:0] a298; reg signed [15:0] tm137; reg signed [15:0] tm141; reg signed [15:0] tm153; reg signed [15:0] tm160; reg signed [15:0] tm138; reg signed [15:0] tm142; reg signed [15:0] tm154; reg signed [15:0] tm161; wire signed [15:0] tm4; wire signed [15:0] a287; wire signed [15:0] tm5; wire signed [15:0] a289; reg signed [15:0] tm139; reg signed [15:0] tm143; reg signed [15:0] tm155; reg signed [15:0] tm162; reg signed [15:0] tm31; reg signed [15:0] tm32; reg signed [15:0] tm140; reg signed [15:0] tm144; reg signed [15:0] tm156; reg signed [15:0] tm163; reg signed [15:0] tm157; reg signed [15:0] tm164; wire signed [15:0] a288; wire signed [15:0] a290; wire signed [15:0] a291; wire signed [15:0] a292; reg signed [15:0] tm158; reg signed [15:0] tm165; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; reg signed [15:0] tm159; reg signed [15:0] tm166; assign a293 = X0; assign a282 = a293; assign a296 = X1; assign a286 = a296; assign a297 = X2; assign a298 = X3; assign a287 = tm4; assign a289 = tm5; assign Y0 = tm159; assign Y1 = tm166; D18_7334 instD18inst0_7334(.addr(i5[0:0]), .out(tm4), .clk(clk)); D20_7342 instD20inst0_7342(.addr(i5[0:0]), .out(tm5), .clk(clk)); multfix #(16, 2) m7265(.a(tm31), .b(tm140), .clk(clk), .q_sc(a288), .q_unsc(), .rst(reset)); multfix #(16, 2) m7287(.a(tm32), .b(tm144), .clk(clk), .q_sc(a290), .q_unsc(), .rst(reset)); multfix #(16, 2) m7305(.a(tm32), .b(tm140), .clk(clk), .q_sc(a291), .q_unsc(), .rst(reset)); multfix #(16, 2) m7316(.a(tm31), .b(tm144), .clk(clk), .q_sc(a292), .q_unsc(), .rst(reset)); subfxp #(16, 1) sub7294(.a(a288), .b(a290), .clk(clk), .q(Y2)); // 6 addfxp #(16, 1) add7323(.a(a291), .b(a292), .clk(clk), .q(Y3)); // 6 always @(posedge clk) begin if (reset == 1) begin tm31 <= 0; tm140 <= 0; tm32 <= 0; tm144 <= 0; tm32 <= 0; tm140 <= 0; tm31 <= 0; tm144 <= 0; end else begin i5 <= i5_in; X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; tm137 <= a297; tm141 <= a298; tm153 <= a282; tm160 <= a286; tm138 <= tm137; tm142 <= tm141; tm154 <= tm153; tm161 <= tm160; tm139 <= tm138; tm143 <= tm142; tm155 <= tm154; tm162 <= tm161; tm31 <= a287; tm32 <= a289; tm140 <= tm139; tm144 <= tm143; tm156 <= tm155; tm163 <= tm162; tm157 <= tm156; tm164 <= tm163; tm158 <= tm157; tm165 <= tm164; tm159 <= tm158; tm166 <= tm165; end end endmodule // Latency: 2 // Gap: 1 module codeBlock7347(clk, reset, next_in, next_out, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(1, 1) shiftFIFO_9722(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a249; wire signed [15:0] a250; wire signed [15:0] a251; wire signed [15:0] a252; wire signed [15:0] t117; wire signed [15:0] t118; wire signed [15:0] t119; wire signed [15:0] t120; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; assign a249 = X0; assign a250 = X2; assign a251 = X1; assign a252 = X3; assign Y0 = t117; assign Y1 = t118; assign Y2 = t119; assign Y3 = t120; addfxp #(16, 1) add7359(.a(a249), .b(a250), .clk(clk), .q(t117)); // 0 addfxp #(16, 1) add7374(.a(a251), .b(a252), .clk(clk), .q(t118)); // 0 subfxp #(16, 1) sub7389(.a(a249), .b(a250), .clk(clk), .q(t119)); // 0 subfxp #(16, 1) sub7404(.a(a251), .b(a252), .clk(clk), .q(t120)); // 0 always @(posedge clk) begin if (reset == 1) begin end else begin X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; end end endmodule // Latency: 12 // Gap: 4 module rc7429(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm7427 instPerm9723(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet7427(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [1:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 2'd0: control <= 1'b1; 2'd1: control <= 1'b1; 2'd2: control <= 1'b0; 2'd3: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 12 // Gap: 4 module perm7427(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 4; parameter addrbits = 2; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm6; assign tm6 = 0; shiftRegFIFO #(3, 1) shiftFIFO_9728(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9729(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); shiftRegFIFO #(3, 1) shiftFIFO_9738(.X(next), .Y(next2), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_9739(.X(next2), .Y(next3), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_9740(.X(next3), .Y(next4), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9741(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_9744(.X(tm6), .Y(tm6_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_9747(.X(tm6_d), .Y(tm6_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 2) shiftFIFO_9752(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm6_d, s1rdloc}) {1'd0, 2'd0}: s1rd0 <= 2; {1'd0, 2'd1}: s1rd0 <= 3; {1'd0, 2'd2}: s1rd0 <= 0; {1'd0, 2'd3}: s1rd0 <= 1; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm6_d, s1rdloc}) {1'd0, 2'd0}: s1rd1 <= 0; {1'd0, 2'd1}: s1rd1 <= 1; {1'd0, 2'd2}: s1rd1 <= 2; {1'd0, 2'd3}: s1rd1 <= 3; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet7427 sw(tm6_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm6_dd, writeCycle}) {1'd0, 2'd0}: s2wr0 <= 2; {1'd0, 2'd1}: s2wr0 <= 3; {1'd0, 2'd2}: s2wr0 <= 0; {1'd0, 2'd3}: s2wr0 <= 1; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm6_dd, writeCycle}) {1'd0, 2'd0}: s2wr1 <= 0; {1'd0, 2'd1}: s2wr1 <= 1; {1'd0, 2'd2}: s2wr1 <= 2; {1'd0, 2'd3}: s2wr1 <= 3; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule // Latency: 8 // Gap: 4 module DirSum_7618(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; reg [1:0] i4; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; always @(posedge clk) begin if (reset == 1) begin i4 <= 0; end else begin if (next == 1) i4 <= 0; else if (i4 == 3) i4 <= 0; else i4 <= i4 + 1; end end codeBlock7432 codeBlockIsnt9753(.clk(clk), .reset(reset), .next_in(next), .next_out(next_out), .i4_in(i4), .X0_in(X0), .Y0(Y0), .X1_in(X1), .Y1(Y1), .X2_in(X2), .Y2(Y2), .X3_in(X3), .Y3(Y3)); endmodule module D14_7604(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [1:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h4000; 1: out3 <= 16'h2d41; 2: out3 <= 16'h0; 3: out3 <= 16'hd2bf; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule module D16_7616(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [1:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h0; 1: out3 <= 16'h2d41; 2: out3 <= 16'h4000; 3: out3 <= 16'h2d41; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule // Latency: 8 // Gap: 1 module codeBlock7432(clk, reset, next_in, next_out, i4_in, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [1:0] i4_in; reg [1:0] i4; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(7, 1) shiftFIFO_9756(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a233; wire signed [15:0] a222; wire signed [15:0] a236; wire signed [15:0] a226; wire signed [15:0] a237; wire signed [15:0] a238; reg signed [15:0] tm167; reg signed [15:0] tm171; reg signed [15:0] tm183; reg signed [15:0] tm190; reg signed [15:0] tm168; reg signed [15:0] tm172; reg signed [15:0] tm184; reg signed [15:0] tm191; wire signed [15:0] tm9; wire signed [15:0] a227; wire signed [15:0] tm10; wire signed [15:0] a229; reg signed [15:0] tm169; reg signed [15:0] tm173; reg signed [15:0] tm185; reg signed [15:0] tm192; reg signed [15:0] tm39; reg signed [15:0] tm40; reg signed [15:0] tm170; reg signed [15:0] tm174; reg signed [15:0] tm186; reg signed [15:0] tm193; reg signed [15:0] tm187; reg signed [15:0] tm194; wire signed [15:0] a228; wire signed [15:0] a230; wire signed [15:0] a231; wire signed [15:0] a232; reg signed [15:0] tm188; reg signed [15:0] tm195; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; reg signed [15:0] tm189; reg signed [15:0] tm196; assign a233 = X0; assign a222 = a233; assign a236 = X1; assign a226 = a236; assign a237 = X2; assign a238 = X3; assign a227 = tm9; assign a229 = tm10; assign Y0 = tm189; assign Y1 = tm196; D14_7604 instD14inst0_7604(.addr(i4[1:0]), .out(tm9), .clk(clk)); D16_7616 instD16inst0_7616(.addr(i4[1:0]), .out(tm10), .clk(clk)); multfix #(16, 2) m7531(.a(tm39), .b(tm170), .clk(clk), .q_sc(a228), .q_unsc(), .rst(reset)); multfix #(16, 2) m7553(.a(tm40), .b(tm174), .clk(clk), .q_sc(a230), .q_unsc(), .rst(reset)); multfix #(16, 2) m7571(.a(tm40), .b(tm170), .clk(clk), .q_sc(a231), .q_unsc(), .rst(reset)); multfix #(16, 2) m7582(.a(tm39), .b(tm174), .clk(clk), .q_sc(a232), .q_unsc(), .rst(reset)); subfxp #(16, 1) sub7560(.a(a228), .b(a230), .clk(clk), .q(Y2)); // 6 addfxp #(16, 1) add7589(.a(a231), .b(a232), .clk(clk), .q(Y3)); // 6 always @(posedge clk) begin if (reset == 1) begin tm39 <= 0; tm170 <= 0; tm40 <= 0; tm174 <= 0; tm40 <= 0; tm170 <= 0; tm39 <= 0; tm174 <= 0; end else begin i4 <= i4_in; X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; tm167 <= a237; tm171 <= a238; tm183 <= a222; tm190 <= a226; tm168 <= tm167; tm172 <= tm171; tm184 <= tm183; tm191 <= tm190; tm169 <= tm168; tm173 <= tm172; tm185 <= tm184; tm192 <= tm191; tm39 <= a227; tm40 <= a229; tm170 <= tm169; tm174 <= tm173; tm186 <= tm185; tm193 <= tm192; tm187 <= tm186; tm194 <= tm193; tm188 <= tm187; tm195 <= tm194; tm189 <= tm188; tm196 <= tm195; end end endmodule // Latency: 2 // Gap: 1 module codeBlock7621(clk, reset, next_in, next_out, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(1, 1) shiftFIFO_9759(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a189; wire signed [15:0] a190; wire signed [15:0] a191; wire signed [15:0] a192; wire signed [15:0] t93; wire signed [15:0] t94; wire signed [15:0] t95; wire signed [15:0] t96; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; assign a189 = X0; assign a190 = X2; assign a191 = X1; assign a192 = X3; assign Y0 = t93; assign Y1 = t94; assign Y2 = t95; assign Y3 = t96; addfxp #(16, 1) add7633(.a(a189), .b(a190), .clk(clk), .q(t93)); // 0 addfxp #(16, 1) add7648(.a(a191), .b(a192), .clk(clk), .q(t94)); // 0 subfxp #(16, 1) sub7663(.a(a189), .b(a190), .clk(clk), .q(t95)); // 0 subfxp #(16, 1) sub7678(.a(a191), .b(a192), .clk(clk), .q(t96)); // 0 always @(posedge clk) begin if (reset == 1) begin end else begin X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; end end endmodule // Latency: 20 // Gap: 8 module rc7703(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm7701 instPerm9760(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet7701(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [2:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 3'd0: control <= 1'b1; 3'd1: control <= 1'b1; 3'd2: control <= 1'b1; 3'd3: control <= 1'b1; 3'd4: control <= 1'b0; 3'd5: control <= 1'b0; 3'd6: control <= 1'b0; 3'd7: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 20 // Gap: 8 module perm7701(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 8; parameter addrbits = 3; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm11; assign tm11 = 0; shiftRegFIFO #(3, 1) shiftFIFO_9765(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9766(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); shiftRegFIFO #(7, 1) shiftFIFO_9775(.X(next), .Y(next2), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_9776(.X(next2), .Y(next3), .clk(clk)); shiftRegFIFO #(8, 1) shiftFIFO_9777(.X(next3), .Y(next4), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9778(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(7, 1) shiftFIFO_9781(.X(tm11), .Y(tm11_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_9784(.X(tm11_d), .Y(tm11_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 3) shiftFIFO_9789(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm11_d, s1rdloc}) {1'd0, 3'd0}: s1rd0 <= 4; {1'd0, 3'd1}: s1rd0 <= 5; {1'd0, 3'd2}: s1rd0 <= 6; {1'd0, 3'd3}: s1rd0 <= 7; {1'd0, 3'd4}: s1rd0 <= 0; {1'd0, 3'd5}: s1rd0 <= 1; {1'd0, 3'd6}: s1rd0 <= 2; {1'd0, 3'd7}: s1rd0 <= 3; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm11_d, s1rdloc}) {1'd0, 3'd0}: s1rd1 <= 0; {1'd0, 3'd1}: s1rd1 <= 1; {1'd0, 3'd2}: s1rd1 <= 2; {1'd0, 3'd3}: s1rd1 <= 3; {1'd0, 3'd4}: s1rd1 <= 4; {1'd0, 3'd5}: s1rd1 <= 5; {1'd0, 3'd6}: s1rd1 <= 6; {1'd0, 3'd7}: s1rd1 <= 7; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet7701 sw(tm11_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm11_dd, writeCycle}) {1'd0, 3'd0}: s2wr0 <= 4; {1'd0, 3'd1}: s2wr0 <= 5; {1'd0, 3'd2}: s2wr0 <= 6; {1'd0, 3'd3}: s2wr0 <= 7; {1'd0, 3'd4}: s2wr0 <= 0; {1'd0, 3'd5}: s2wr0 <= 1; {1'd0, 3'd6}: s2wr0 <= 2; {1'd0, 3'd7}: s2wr0 <= 3; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm11_dd, writeCycle}) {1'd0, 3'd0}: s2wr1 <= 0; {1'd0, 3'd1}: s2wr1 <= 1; {1'd0, 3'd2}: s2wr1 <= 2; {1'd0, 3'd3}: s2wr1 <= 3; {1'd0, 3'd4}: s2wr1 <= 4; {1'd0, 3'd5}: s2wr1 <= 5; {1'd0, 3'd6}: s2wr1 <= 6; {1'd0, 3'd7}: s2wr1 <= 7; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule // Latency: 8 // Gap: 8 module DirSum_7908(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; reg [2:0] i3; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; always @(posedge clk) begin if (reset == 1) begin i3 <= 0; end else begin if (next == 1) i3 <= 0; else if (i3 == 7) i3 <= 0; else i3 <= i3 + 1; end end codeBlock7706 codeBlockIsnt9790(.clk(clk), .reset(reset), .next_in(next), .next_out(next_out), .i3_in(i3), .X0_in(X0), .Y0(Y0), .X1_in(X1), .Y1(Y1), .X2_in(X2), .Y2(Y2), .X3_in(X3), .Y3(Y3)); endmodule module D10_7886(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [2:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h4000; 1: out3 <= 16'h3b21; 2: out3 <= 16'h2d41; 3: out3 <= 16'h187e; 4: out3 <= 16'h0; 5: out3 <= 16'he782; 6: out3 <= 16'hd2bf; 7: out3 <= 16'hc4df; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule module D12_7906(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [2:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h0; 1: out3 <= 16'h187e; 2: out3 <= 16'h2d41; 3: out3 <= 16'h3b21; 4: out3 <= 16'h4000; 5: out3 <= 16'h3b21; 6: out3 <= 16'h2d41; 7: out3 <= 16'h187e; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule // Latency: 8 // Gap: 1 module codeBlock7706(clk, reset, next_in, next_out, i3_in, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [2:0] i3_in; reg [2:0] i3; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(7, 1) shiftFIFO_9793(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a173; wire signed [15:0] a162; wire signed [15:0] a176; wire signed [15:0] a166; wire signed [15:0] a177; wire signed [15:0] a178; reg signed [15:0] tm197; reg signed [15:0] tm201; reg signed [15:0] tm213; reg signed [15:0] tm220; reg signed [15:0] tm198; reg signed [15:0] tm202; reg signed [15:0] tm214; reg signed [15:0] tm221; wire signed [15:0] tm14; wire signed [15:0] a167; wire signed [15:0] tm15; wire signed [15:0] a169; reg signed [15:0] tm199; reg signed [15:0] tm203; reg signed [15:0] tm215; reg signed [15:0] tm222; reg signed [15:0] tm47; reg signed [15:0] tm48; reg signed [15:0] tm200; reg signed [15:0] tm204; reg signed [15:0] tm216; reg signed [15:0] tm223; reg signed [15:0] tm217; reg signed [15:0] tm224; wire signed [15:0] a168; wire signed [15:0] a170; wire signed [15:0] a171; wire signed [15:0] a172; reg signed [15:0] tm218; reg signed [15:0] tm225; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; reg signed [15:0] tm219; reg signed [15:0] tm226; assign a173 = X0; assign a162 = a173; assign a176 = X1; assign a166 = a176; assign a177 = X2; assign a178 = X3; assign a167 = tm14; assign a169 = tm15; assign Y0 = tm219; assign Y1 = tm226; D10_7886 instD10inst0_7886(.addr(i3[2:0]), .out(tm14), .clk(clk)); D12_7906 instD12inst0_7906(.addr(i3[2:0]), .out(tm15), .clk(clk)); multfix #(16, 2) m7805(.a(tm47), .b(tm200), .clk(clk), .q_sc(a168), .q_unsc(), .rst(reset)); multfix #(16, 2) m7827(.a(tm48), .b(tm204), .clk(clk), .q_sc(a170), .q_unsc(), .rst(reset)); multfix #(16, 2) m7845(.a(tm48), .b(tm200), .clk(clk), .q_sc(a171), .q_unsc(), .rst(reset)); multfix #(16, 2) m7856(.a(tm47), .b(tm204), .clk(clk), .q_sc(a172), .q_unsc(), .rst(reset)); subfxp #(16, 1) sub7834(.a(a168), .b(a170), .clk(clk), .q(Y2)); // 6 addfxp #(16, 1) add7863(.a(a171), .b(a172), .clk(clk), .q(Y3)); // 6 always @(posedge clk) begin if (reset == 1) begin tm47 <= 0; tm200 <= 0; tm48 <= 0; tm204 <= 0; tm48 <= 0; tm200 <= 0; tm47 <= 0; tm204 <= 0; end else begin i3 <= i3_in; X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; tm197 <= a177; tm201 <= a178; tm213 <= a162; tm220 <= a166; tm198 <= tm197; tm202 <= tm201; tm214 <= tm213; tm221 <= tm220; tm199 <= tm198; tm203 <= tm202; tm215 <= tm214; tm222 <= tm221; tm47 <= a167; tm48 <= a169; tm200 <= tm199; tm204 <= tm203; tm216 <= tm215; tm223 <= tm222; tm217 <= tm216; tm224 <= tm223; tm218 <= tm217; tm225 <= tm224; tm219 <= tm218; tm226 <= tm225; end end endmodule // Latency: 2 // Gap: 1 module codeBlock7911(clk, reset, next_in, next_out, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(1, 1) shiftFIFO_9796(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a129; wire signed [15:0] a130; wire signed [15:0] a131; wire signed [15:0] a132; wire signed [15:0] t69; wire signed [15:0] t70; wire signed [15:0] t71; wire signed [15:0] t72; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; assign a129 = X0; assign a130 = X2; assign a131 = X1; assign a132 = X3; assign Y0 = t69; assign Y1 = t70; assign Y2 = t71; assign Y3 = t72; addfxp #(16, 1) add7923(.a(a129), .b(a130), .clk(clk), .q(t69)); // 0 addfxp #(16, 1) add7938(.a(a131), .b(a132), .clk(clk), .q(t70)); // 0 subfxp #(16, 1) sub7953(.a(a129), .b(a130), .clk(clk), .q(t71)); // 0 subfxp #(16, 1) sub7968(.a(a131), .b(a132), .clk(clk), .q(t72)); // 0 always @(posedge clk) begin if (reset == 1) begin end else begin X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; end end endmodule // Latency: 36 // Gap: 16 module rc7993(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm7991 instPerm9797(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet7991(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [3:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 4'd0: control <= 1'b1; 4'd1: control <= 1'b1; 4'd2: control <= 1'b1; 4'd3: control <= 1'b1; 4'd4: control <= 1'b1; 4'd5: control <= 1'b1; 4'd6: control <= 1'b1; 4'd7: control <= 1'b1; 4'd8: control <= 1'b0; 4'd9: control <= 1'b0; 4'd10: control <= 1'b0; 4'd11: control <= 1'b0; 4'd12: control <= 1'b0; 4'd13: control <= 1'b0; 4'd14: control <= 1'b0; 4'd15: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 36 // Gap: 16 module perm7991(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 16; parameter addrbits = 4; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm16; assign tm16 = 0; shiftRegFIFO #(3, 1) shiftFIFO_9802(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9803(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); nextReg #(15, 4) nextReg_9814(.X(next), .Y(next2), .reset(reset), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_9815(.X(next2), .Y(next3), .clk(clk)); nextReg #(16, 4) nextReg_9818(.X(next3), .Y(next4), .reset(reset), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9819(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(15, 1) shiftFIFO_9822(.X(tm16), .Y(tm16_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_9825(.X(tm16_d), .Y(tm16_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 4) shiftFIFO_9830(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm16_d, s1rdloc}) {1'd0, 4'd0}: s1rd0 <= 8; {1'd0, 4'd1}: s1rd0 <= 9; {1'd0, 4'd2}: s1rd0 <= 10; {1'd0, 4'd3}: s1rd0 <= 11; {1'd0, 4'd4}: s1rd0 <= 12; {1'd0, 4'd5}: s1rd0 <= 13; {1'd0, 4'd6}: s1rd0 <= 14; {1'd0, 4'd7}: s1rd0 <= 15; {1'd0, 4'd8}: s1rd0 <= 0; {1'd0, 4'd9}: s1rd0 <= 1; {1'd0, 4'd10}: s1rd0 <= 2; {1'd0, 4'd11}: s1rd0 <= 3; {1'd0, 4'd12}: s1rd0 <= 4; {1'd0, 4'd13}: s1rd0 <= 5; {1'd0, 4'd14}: s1rd0 <= 6; {1'd0, 4'd15}: s1rd0 <= 7; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm16_d, s1rdloc}) {1'd0, 4'd0}: s1rd1 <= 0; {1'd0, 4'd1}: s1rd1 <= 1; {1'd0, 4'd2}: s1rd1 <= 2; {1'd0, 4'd3}: s1rd1 <= 3; {1'd0, 4'd4}: s1rd1 <= 4; {1'd0, 4'd5}: s1rd1 <= 5; {1'd0, 4'd6}: s1rd1 <= 6; {1'd0, 4'd7}: s1rd1 <= 7; {1'd0, 4'd8}: s1rd1 <= 8; {1'd0, 4'd9}: s1rd1 <= 9; {1'd0, 4'd10}: s1rd1 <= 10; {1'd0, 4'd11}: s1rd1 <= 11; {1'd0, 4'd12}: s1rd1 <= 12; {1'd0, 4'd13}: s1rd1 <= 13; {1'd0, 4'd14}: s1rd1 <= 14; {1'd0, 4'd15}: s1rd1 <= 15; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet7991 sw(tm16_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm16_dd, writeCycle}) {1'd0, 4'd0}: s2wr0 <= 8; {1'd0, 4'd1}: s2wr0 <= 9; {1'd0, 4'd2}: s2wr0 <= 10; {1'd0, 4'd3}: s2wr0 <= 11; {1'd0, 4'd4}: s2wr0 <= 12; {1'd0, 4'd5}: s2wr0 <= 13; {1'd0, 4'd6}: s2wr0 <= 14; {1'd0, 4'd7}: s2wr0 <= 15; {1'd0, 4'd8}: s2wr0 <= 0; {1'd0, 4'd9}: s2wr0 <= 1; {1'd0, 4'd10}: s2wr0 <= 2; {1'd0, 4'd11}: s2wr0 <= 3; {1'd0, 4'd12}: s2wr0 <= 4; {1'd0, 4'd13}: s2wr0 <= 5; {1'd0, 4'd14}: s2wr0 <= 6; {1'd0, 4'd15}: s2wr0 <= 7; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm16_dd, writeCycle}) {1'd0, 4'd0}: s2wr1 <= 0; {1'd0, 4'd1}: s2wr1 <= 1; {1'd0, 4'd2}: s2wr1 <= 2; {1'd0, 4'd3}: s2wr1 <= 3; {1'd0, 4'd4}: s2wr1 <= 4; {1'd0, 4'd5}: s2wr1 <= 5; {1'd0, 4'd6}: s2wr1 <= 6; {1'd0, 4'd7}: s2wr1 <= 7; {1'd0, 4'd8}: s2wr1 <= 8; {1'd0, 4'd9}: s2wr1 <= 9; {1'd0, 4'd10}: s2wr1 <= 10; {1'd0, 4'd11}: s2wr1 <= 11; {1'd0, 4'd12}: s2wr1 <= 12; {1'd0, 4'd13}: s2wr1 <= 13; {1'd0, 4'd14}: s2wr1 <= 14; {1'd0, 4'd15}: s2wr1 <= 15; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule // Latency: 8 // Gap: 16 module DirSum_8230(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; reg [3:0] i2; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; always @(posedge clk) begin if (reset == 1) begin i2 <= 0; end else begin if (next == 1) i2 <= 0; else if (i2 == 15) i2 <= 0; else i2 <= i2 + 1; end end codeBlock7996 codeBlockIsnt9835(.clk(clk), .reset(reset), .next_in(next), .next_out(next_out), .i2_in(i2), .X0_in(X0), .Y0(Y0), .X1_in(X1), .Y1(Y1), .X2_in(X2), .Y2(Y2), .X3_in(X3), .Y3(Y3)); endmodule module D6_8192(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [3:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h4000; 1: out3 <= 16'h3ec5; 2: out3 <= 16'h3b21; 3: out3 <= 16'h3537; 4: out3 <= 16'h2d41; 5: out3 <= 16'h238e; 6: out3 <= 16'h187e; 7: out3 <= 16'hc7c; 8: out3 <= 16'h0; 9: out3 <= 16'hf384; 10: out3 <= 16'he782; 11: out3 <= 16'hdc72; 12: out3 <= 16'hd2bf; 13: out3 <= 16'hcac9; 14: out3 <= 16'hc4df; 15: out3 <= 16'hc13b; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule module D8_8228(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [3:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h0; 1: out3 <= 16'hc7c; 2: out3 <= 16'h187e; 3: out3 <= 16'h238e; 4: out3 <= 16'h2d41; 5: out3 <= 16'h3537; 6: out3 <= 16'h3b21; 7: out3 <= 16'h3ec5; 8: out3 <= 16'h4000; 9: out3 <= 16'h3ec5; 10: out3 <= 16'h3b21; 11: out3 <= 16'h3537; 12: out3 <= 16'h2d41; 13: out3 <= 16'h238e; 14: out3 <= 16'h187e; 15: out3 <= 16'hc7c; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule // Latency: 8 // Gap: 1 module codeBlock7996(clk, reset, next_in, next_out, i2_in, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [3:0] i2_in; reg [3:0] i2; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(7, 1) shiftFIFO_9838(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a113; wire signed [15:0] a102; wire signed [15:0] a116; wire signed [15:0] a106; wire signed [15:0] a117; wire signed [15:0] a118; reg signed [15:0] tm227; reg signed [15:0] tm231; reg signed [15:0] tm243; reg signed [15:0] tm250; reg signed [15:0] tm228; reg signed [15:0] tm232; reg signed [15:0] tm244; reg signed [15:0] tm251; wire signed [15:0] tm19; wire signed [15:0] a107; wire signed [15:0] tm20; wire signed [15:0] a109; reg signed [15:0] tm229; reg signed [15:0] tm233; reg signed [15:0] tm245; reg signed [15:0] tm252; reg signed [15:0] tm55; reg signed [15:0] tm56; reg signed [15:0] tm230; reg signed [15:0] tm234; reg signed [15:0] tm246; reg signed [15:0] tm253; reg signed [15:0] tm247; reg signed [15:0] tm254; wire signed [15:0] a108; wire signed [15:0] a110; wire signed [15:0] a111; wire signed [15:0] a112; reg signed [15:0] tm248; reg signed [15:0] tm255; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; reg signed [15:0] tm249; reg signed [15:0] tm256; assign a113 = X0; assign a102 = a113; assign a116 = X1; assign a106 = a116; assign a117 = X2; assign a118 = X3; assign a107 = tm19; assign a109 = tm20; assign Y0 = tm249; assign Y1 = tm256; D6_8192 instD6inst0_8192(.addr(i2[3:0]), .out(tm19), .clk(clk)); D8_8228 instD8inst0_8228(.addr(i2[3:0]), .out(tm20), .clk(clk)); multfix #(16, 2) m8095(.a(tm55), .b(tm230), .clk(clk), .q_sc(a108), .q_unsc(), .rst(reset)); multfix #(16, 2) m8117(.a(tm56), .b(tm234), .clk(clk), .q_sc(a110), .q_unsc(), .rst(reset)); multfix #(16, 2) m8135(.a(tm56), .b(tm230), .clk(clk), .q_sc(a111), .q_unsc(), .rst(reset)); multfix #(16, 2) m8146(.a(tm55), .b(tm234), .clk(clk), .q_sc(a112), .q_unsc(), .rst(reset)); subfxp #(16, 1) sub8124(.a(a108), .b(a110), .clk(clk), .q(Y2)); // 6 addfxp #(16, 1) add8153(.a(a111), .b(a112), .clk(clk), .q(Y3)); // 6 always @(posedge clk) begin if (reset == 1) begin tm55 <= 0; tm230 <= 0; tm56 <= 0; tm234 <= 0; tm56 <= 0; tm230 <= 0; tm55 <= 0; tm234 <= 0; end else begin i2 <= i2_in; X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; tm227 <= a117; tm231 <= a118; tm243 <= a102; tm250 <= a106; tm228 <= tm227; tm232 <= tm231; tm244 <= tm243; tm251 <= tm250; tm229 <= tm228; tm233 <= tm232; tm245 <= tm244; tm252 <= tm251; tm55 <= a107; tm56 <= a109; tm230 <= tm229; tm234 <= tm233; tm246 <= tm245; tm253 <= tm252; tm247 <= tm246; tm254 <= tm253; tm248 <= tm247; tm255 <= tm254; tm249 <= tm248; tm256 <= tm255; end end endmodule // Latency: 2 // Gap: 1 module codeBlock8233(clk, reset, next_in, next_out, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(1, 1) shiftFIFO_9841(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a69; wire signed [15:0] a70; wire signed [15:0] a71; wire signed [15:0] a72; wire signed [15:0] t45; wire signed [15:0] t46; wire signed [15:0] t47; wire signed [15:0] t48; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; assign a69 = X0; assign a70 = X2; assign a71 = X1; assign a72 = X3; assign Y0 = t45; assign Y1 = t46; assign Y2 = t47; assign Y3 = t48; addfxp #(16, 1) add8245(.a(a69), .b(a70), .clk(clk), .q(t45)); // 0 addfxp #(16, 1) add8260(.a(a71), .b(a72), .clk(clk), .q(t46)); // 0 subfxp #(16, 1) sub8275(.a(a69), .b(a70), .clk(clk), .q(t47)); // 0 subfxp #(16, 1) sub8290(.a(a71), .b(a72), .clk(clk), .q(t48)); // 0 always @(posedge clk) begin if (reset == 1) begin end else begin X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; end end endmodule // Latency: 68 // Gap: 32 module rc8315(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm8313 instPerm9842(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet8313(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [4:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 5'd0: control <= 1'b1; 5'd1: control <= 1'b1; 5'd2: control <= 1'b1; 5'd3: control <= 1'b1; 5'd4: control <= 1'b1; 5'd5: control <= 1'b1; 5'd6: control <= 1'b1; 5'd7: control <= 1'b1; 5'd8: control <= 1'b1; 5'd9: control <= 1'b1; 5'd10: control <= 1'b1; 5'd11: control <= 1'b1; 5'd12: control <= 1'b1; 5'd13: control <= 1'b1; 5'd14: control <= 1'b1; 5'd15: control <= 1'b1; 5'd16: control <= 1'b0; 5'd17: control <= 1'b0; 5'd18: control <= 1'b0; 5'd19: control <= 1'b0; 5'd20: control <= 1'b0; 5'd21: control <= 1'b0; 5'd22: control <= 1'b0; 5'd23: control <= 1'b0; 5'd24: control <= 1'b0; 5'd25: control <= 1'b0; 5'd26: control <= 1'b0; 5'd27: control <= 1'b0; 5'd28: control <= 1'b0; 5'd29: control <= 1'b0; 5'd30: control <= 1'b0; 5'd31: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 68 // Gap: 32 module perm8313(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 32; parameter addrbits = 5; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm21; assign tm21 = 0; shiftRegFIFO #(3, 1) shiftFIFO_9847(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9848(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); nextReg #(31, 5) nextReg_9859(.X(next), .Y(next2), .reset(reset), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_9860(.X(next2), .Y(next3), .clk(clk)); nextReg #(32, 5) nextReg_9863(.X(next3), .Y(next4), .reset(reset), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9864(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(31, 1) shiftFIFO_9867(.X(tm21), .Y(tm21_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_9870(.X(tm21_d), .Y(tm21_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 5) shiftFIFO_9875(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm21_d, s1rdloc}) {1'd0, 5'd0}: s1rd0 <= 16; {1'd0, 5'd1}: s1rd0 <= 17; {1'd0, 5'd2}: s1rd0 <= 18; {1'd0, 5'd3}: s1rd0 <= 19; {1'd0, 5'd4}: s1rd0 <= 20; {1'd0, 5'd5}: s1rd0 <= 21; {1'd0, 5'd6}: s1rd0 <= 22; {1'd0, 5'd7}: s1rd0 <= 23; {1'd0, 5'd8}: s1rd0 <= 24; {1'd0, 5'd9}: s1rd0 <= 25; {1'd0, 5'd10}: s1rd0 <= 26; {1'd0, 5'd11}: s1rd0 <= 27; {1'd0, 5'd12}: s1rd0 <= 28; {1'd0, 5'd13}: s1rd0 <= 29; {1'd0, 5'd14}: s1rd0 <= 30; {1'd0, 5'd15}: s1rd0 <= 31; {1'd0, 5'd16}: s1rd0 <= 0; {1'd0, 5'd17}: s1rd0 <= 1; {1'd0, 5'd18}: s1rd0 <= 2; {1'd0, 5'd19}: s1rd0 <= 3; {1'd0, 5'd20}: s1rd0 <= 4; {1'd0, 5'd21}: s1rd0 <= 5; {1'd0, 5'd22}: s1rd0 <= 6; {1'd0, 5'd23}: s1rd0 <= 7; {1'd0, 5'd24}: s1rd0 <= 8; {1'd0, 5'd25}: s1rd0 <= 9; {1'd0, 5'd26}: s1rd0 <= 10; {1'd0, 5'd27}: s1rd0 <= 11; {1'd0, 5'd28}: s1rd0 <= 12; {1'd0, 5'd29}: s1rd0 <= 13; {1'd0, 5'd30}: s1rd0 <= 14; {1'd0, 5'd31}: s1rd0 <= 15; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm21_d, s1rdloc}) {1'd0, 5'd0}: s1rd1 <= 0; {1'd0, 5'd1}: s1rd1 <= 1; {1'd0, 5'd2}: s1rd1 <= 2; {1'd0, 5'd3}: s1rd1 <= 3; {1'd0, 5'd4}: s1rd1 <= 4; {1'd0, 5'd5}: s1rd1 <= 5; {1'd0, 5'd6}: s1rd1 <= 6; {1'd0, 5'd7}: s1rd1 <= 7; {1'd0, 5'd8}: s1rd1 <= 8; {1'd0, 5'd9}: s1rd1 <= 9; {1'd0, 5'd10}: s1rd1 <= 10; {1'd0, 5'd11}: s1rd1 <= 11; {1'd0, 5'd12}: s1rd1 <= 12; {1'd0, 5'd13}: s1rd1 <= 13; {1'd0, 5'd14}: s1rd1 <= 14; {1'd0, 5'd15}: s1rd1 <= 15; {1'd0, 5'd16}: s1rd1 <= 16; {1'd0, 5'd17}: s1rd1 <= 17; {1'd0, 5'd18}: s1rd1 <= 18; {1'd0, 5'd19}: s1rd1 <= 19; {1'd0, 5'd20}: s1rd1 <= 20; {1'd0, 5'd21}: s1rd1 <= 21; {1'd0, 5'd22}: s1rd1 <= 22; {1'd0, 5'd23}: s1rd1 <= 23; {1'd0, 5'd24}: s1rd1 <= 24; {1'd0, 5'd25}: s1rd1 <= 25; {1'd0, 5'd26}: s1rd1 <= 26; {1'd0, 5'd27}: s1rd1 <= 27; {1'd0, 5'd28}: s1rd1 <= 28; {1'd0, 5'd29}: s1rd1 <= 29; {1'd0, 5'd30}: s1rd1 <= 30; {1'd0, 5'd31}: s1rd1 <= 31; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet8313 sw(tm21_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm21_dd, writeCycle}) {1'd0, 5'd0}: s2wr0 <= 16; {1'd0, 5'd1}: s2wr0 <= 17; {1'd0, 5'd2}: s2wr0 <= 18; {1'd0, 5'd3}: s2wr0 <= 19; {1'd0, 5'd4}: s2wr0 <= 20; {1'd0, 5'd5}: s2wr0 <= 21; {1'd0, 5'd6}: s2wr0 <= 22; {1'd0, 5'd7}: s2wr0 <= 23; {1'd0, 5'd8}: s2wr0 <= 24; {1'd0, 5'd9}: s2wr0 <= 25; {1'd0, 5'd10}: s2wr0 <= 26; {1'd0, 5'd11}: s2wr0 <= 27; {1'd0, 5'd12}: s2wr0 <= 28; {1'd0, 5'd13}: s2wr0 <= 29; {1'd0, 5'd14}: s2wr0 <= 30; {1'd0, 5'd15}: s2wr0 <= 31; {1'd0, 5'd16}: s2wr0 <= 0; {1'd0, 5'd17}: s2wr0 <= 1; {1'd0, 5'd18}: s2wr0 <= 2; {1'd0, 5'd19}: s2wr0 <= 3; {1'd0, 5'd20}: s2wr0 <= 4; {1'd0, 5'd21}: s2wr0 <= 5; {1'd0, 5'd22}: s2wr0 <= 6; {1'd0, 5'd23}: s2wr0 <= 7; {1'd0, 5'd24}: s2wr0 <= 8; {1'd0, 5'd25}: s2wr0 <= 9; {1'd0, 5'd26}: s2wr0 <= 10; {1'd0, 5'd27}: s2wr0 <= 11; {1'd0, 5'd28}: s2wr0 <= 12; {1'd0, 5'd29}: s2wr0 <= 13; {1'd0, 5'd30}: s2wr0 <= 14; {1'd0, 5'd31}: s2wr0 <= 15; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm21_dd, writeCycle}) {1'd0, 5'd0}: s2wr1 <= 0; {1'd0, 5'd1}: s2wr1 <= 1; {1'd0, 5'd2}: s2wr1 <= 2; {1'd0, 5'd3}: s2wr1 <= 3; {1'd0, 5'd4}: s2wr1 <= 4; {1'd0, 5'd5}: s2wr1 <= 5; {1'd0, 5'd6}: s2wr1 <= 6; {1'd0, 5'd7}: s2wr1 <= 7; {1'd0, 5'd8}: s2wr1 <= 8; {1'd0, 5'd9}: s2wr1 <= 9; {1'd0, 5'd10}: s2wr1 <= 10; {1'd0, 5'd11}: s2wr1 <= 11; {1'd0, 5'd12}: s2wr1 <= 12; {1'd0, 5'd13}: s2wr1 <= 13; {1'd0, 5'd14}: s2wr1 <= 14; {1'd0, 5'd15}: s2wr1 <= 15; {1'd0, 5'd16}: s2wr1 <= 16; {1'd0, 5'd17}: s2wr1 <= 17; {1'd0, 5'd18}: s2wr1 <= 18; {1'd0, 5'd19}: s2wr1 <= 19; {1'd0, 5'd20}: s2wr1 <= 20; {1'd0, 5'd21}: s2wr1 <= 21; {1'd0, 5'd22}: s2wr1 <= 22; {1'd0, 5'd23}: s2wr1 <= 23; {1'd0, 5'd24}: s2wr1 <= 24; {1'd0, 5'd25}: s2wr1 <= 25; {1'd0, 5'd26}: s2wr1 <= 26; {1'd0, 5'd27}: s2wr1 <= 27; {1'd0, 5'd28}: s2wr1 <= 28; {1'd0, 5'd29}: s2wr1 <= 29; {1'd0, 5'd30}: s2wr1 <= 30; {1'd0, 5'd31}: s2wr1 <= 31; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule // Latency: 8 // Gap: 32 module DirSum_8615(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; reg [4:0] i1; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; always @(posedge clk) begin if (reset == 1) begin i1 <= 0; end else begin if (next == 1) i1 <= 0; else if (i1 == 31) i1 <= 0; else i1 <= i1 + 1; end end codeBlock8317 codeBlockIsnt9880(.clk(clk), .reset(reset), .next_in(next), .next_out(next_out), .i1_in(i1), .X0_in(X0), .Y0(Y0), .X1_in(X1), .Y1(Y1), .X2_in(X2), .Y2(Y2), .X3_in(X3), .Y3(Y3)); endmodule module D2_8545(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [4:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h4000; 1: out3 <= 16'h3fb1; 2: out3 <= 16'h3ec5; 3: out3 <= 16'h3d3f; 4: out3 <= 16'h3b21; 5: out3 <= 16'h3871; 6: out3 <= 16'h3537; 7: out3 <= 16'h3179; 8: out3 <= 16'h2d41; 9: out3 <= 16'h289a; 10: out3 <= 16'h238e; 11: out3 <= 16'h1e2b; 12: out3 <= 16'h187e; 13: out3 <= 16'h1294; 14: out3 <= 16'hc7c; 15: out3 <= 16'h646; 16: out3 <= 16'h0; 17: out3 <= 16'hf9ba; 18: out3 <= 16'hf384; 19: out3 <= 16'hed6c; 20: out3 <= 16'he782; 21: out3 <= 16'he1d5; 22: out3 <= 16'hdc72; 23: out3 <= 16'hd766; 24: out3 <= 16'hd2bf; 25: out3 <= 16'hce87; 26: out3 <= 16'hcac9; 27: out3 <= 16'hc78f; 28: out3 <= 16'hc4df; 29: out3 <= 16'hc2c1; 30: out3 <= 16'hc13b; 31: out3 <= 16'hc04f; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule module D4_8613(addr, out, clk); input clk; output [15:0] out; reg [15:0] out, out2, out3; input [4:0] addr; always @(posedge clk) begin out2 <= out3; out <= out2; case(addr) 0: out3 <= 16'h0; 1: out3 <= 16'h646; 2: out3 <= 16'hc7c; 3: out3 <= 16'h1294; 4: out3 <= 16'h187e; 5: out3 <= 16'h1e2b; 6: out3 <= 16'h238e; 7: out3 <= 16'h289a; 8: out3 <= 16'h2d41; 9: out3 <= 16'h3179; 10: out3 <= 16'h3537; 11: out3 <= 16'h3871; 12: out3 <= 16'h3b21; 13: out3 <= 16'h3d3f; 14: out3 <= 16'h3ec5; 15: out3 <= 16'h3fb1; 16: out3 <= 16'h4000; 17: out3 <= 16'h3fb1; 18: out3 <= 16'h3ec5; 19: out3 <= 16'h3d3f; 20: out3 <= 16'h3b21; 21: out3 <= 16'h3871; 22: out3 <= 16'h3537; 23: out3 <= 16'h3179; 24: out3 <= 16'h2d41; 25: out3 <= 16'h289a; 26: out3 <= 16'h238e; 27: out3 <= 16'h1e2b; 28: out3 <= 16'h187e; 29: out3 <= 16'h1294; 30: out3 <= 16'hc7c; 31: out3 <= 16'h646; default: out3 <= 0; endcase end // synthesis attribute rom_style of out3 is "block" endmodule // Latency: 8 // Gap: 1 module codeBlock8317(clk, reset, next_in, next_out, i1_in, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [4:0] i1_in; reg [4:0] i1; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(7, 1) shiftFIFO_9883(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a53; wire signed [15:0] a42; wire signed [15:0] a56; wire signed [15:0] a46; wire signed [15:0] a57; wire signed [15:0] a58; reg signed [15:0] tm257; reg signed [15:0] tm261; reg signed [15:0] tm273; reg signed [15:0] tm280; reg signed [15:0] tm258; reg signed [15:0] tm262; reg signed [15:0] tm274; reg signed [15:0] tm281; wire signed [15:0] tm24; wire signed [15:0] a47; wire signed [15:0] tm25; wire signed [15:0] a49; reg signed [15:0] tm259; reg signed [15:0] tm263; reg signed [15:0] tm275; reg signed [15:0] tm282; reg signed [15:0] tm63; reg signed [15:0] tm64; reg signed [15:0] tm260; reg signed [15:0] tm264; reg signed [15:0] tm276; reg signed [15:0] tm283; reg signed [15:0] tm277; reg signed [15:0] tm284; wire signed [15:0] a48; wire signed [15:0] a50; wire signed [15:0] a51; wire signed [15:0] a52; reg signed [15:0] tm278; reg signed [15:0] tm285; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; reg signed [15:0] tm279; reg signed [15:0] tm286; assign a53 = X0; assign a42 = a53; assign a56 = X1; assign a46 = a56; assign a57 = X2; assign a58 = X3; assign a47 = tm24; assign a49 = tm25; assign Y0 = tm279; assign Y1 = tm286; D2_8545 instD2inst0_8545(.addr(i1[4:0]), .out(tm24), .clk(clk)); D4_8613 instD4inst0_8613(.addr(i1[4:0]), .out(tm25), .clk(clk)); multfix #(16, 2) m8416(.a(tm63), .b(tm260), .clk(clk), .q_sc(a48), .q_unsc(), .rst(reset)); multfix #(16, 2) m8438(.a(tm64), .b(tm264), .clk(clk), .q_sc(a50), .q_unsc(), .rst(reset)); multfix #(16, 2) m8456(.a(tm64), .b(tm260), .clk(clk), .q_sc(a51), .q_unsc(), .rst(reset)); multfix #(16, 2) m8467(.a(tm63), .b(tm264), .clk(clk), .q_sc(a52), .q_unsc(), .rst(reset)); subfxp #(16, 1) sub8445(.a(a48), .b(a50), .clk(clk), .q(Y2)); // 6 addfxp #(16, 1) add8474(.a(a51), .b(a52), .clk(clk), .q(Y3)); // 6 always @(posedge clk) begin if (reset == 1) begin tm63 <= 0; tm260 <= 0; tm64 <= 0; tm264 <= 0; tm64 <= 0; tm260 <= 0; tm63 <= 0; tm264 <= 0; end else begin i1 <= i1_in; X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; tm257 <= a57; tm261 <= a58; tm273 <= a42; tm280 <= a46; tm258 <= tm257; tm262 <= tm261; tm274 <= tm273; tm281 <= tm280; tm259 <= tm258; tm263 <= tm262; tm275 <= tm274; tm282 <= tm281; tm63 <= a47; tm64 <= a49; tm260 <= tm259; tm264 <= tm263; tm276 <= tm275; tm283 <= tm282; tm277 <= tm276; tm284 <= tm283; tm278 <= tm277; tm285 <= tm284; tm279 <= tm278; tm286 <= tm285; end end endmodule // Latency: 2 // Gap: 1 module codeBlock8618(clk, reset, next_in, next_out, X0_in, Y0, X1_in, Y1, X2_in, Y2, X3_in, Y3); output next_out; input clk, reset, next_in; reg next; input [15:0] X0_in, X1_in, X2_in, X3_in; reg [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; shiftRegFIFO #(1, 1) shiftFIFO_9886(.X(next), .Y(next_out), .clk(clk)); wire signed [15:0] a9; wire signed [15:0] a10; wire signed [15:0] a11; wire signed [15:0] a12; wire signed [15:0] t21; wire signed [15:0] t22; wire signed [15:0] t23; wire signed [15:0] t24; wire signed [15:0] Y0; wire signed [15:0] Y1; wire signed [15:0] Y2; wire signed [15:0] Y3; assign a9 = X0; assign a10 = X2; assign a11 = X1; assign a12 = X3; assign Y0 = t21; assign Y1 = t22; assign Y2 = t23; assign Y3 = t24; addfxp #(16, 1) add8630(.a(a9), .b(a10), .clk(clk), .q(t21)); // 0 addfxp #(16, 1) add8645(.a(a11), .b(a12), .clk(clk), .q(t22)); // 0 subfxp #(16, 1) sub8660(.a(a9), .b(a10), .clk(clk), .q(t23)); // 0 subfxp #(16, 1) sub8675(.a(a11), .b(a12), .clk(clk), .q(t24)); // 0 always @(posedge clk) begin if (reset == 1) begin end else begin X0 <= X0_in; X1 <= X1_in; X2 <= X2_in; X3 <= X3_in; next <= next_in; end end endmodule // Latency: 68 // Gap: 32 module rc8700(clk, reset, next, next_out, X0, Y0, X1, Y1, X2, Y2, X3, Y3); output next_out; input clk, reset, next; input [15:0] X0, X1, X2, X3; output [15:0] Y0, Y1, Y2, Y3; wire [31:0] t0; wire [31:0] s0; assign t0 = {X0, X1}; wire [31:0] t1; wire [31:0] s1; assign t1 = {X2, X3}; assign Y0 = s0[31:16]; assign Y1 = s0[15:0]; assign Y2 = s1[31:16]; assign Y3 = s1[15:0]; perm8698 instPerm9887(.x0(t0), .y0(s0), .x1(t1), .y1(s1), .clk(clk), .next(next), .next_out(next_out), .reset(reset) ); endmodule module swNet8698(itr, clk, ct , x0, y0 , x1, y1 ); parameter width = 32; input [4:0] ct; input clk; input [0:0] itr; input [width-1:0] x0; output reg [width-1:0] y0; input [width-1:0] x1; output reg [width-1:0] y1; wire [width-1:0] t0_0, t0_1; reg [width-1:0] t1_0, t1_1; reg [0:0] control; always @(posedge clk) begin case(ct) 5'd0: control <= 1'b1; 5'd1: control <= 1'b1; 5'd2: control <= 1'b1; 5'd3: control <= 1'b1; 5'd4: control <= 1'b1; 5'd5: control <= 1'b1; 5'd6: control <= 1'b1; 5'd7: control <= 1'b1; 5'd8: control <= 1'b1; 5'd9: control <= 1'b1; 5'd10: control <= 1'b1; 5'd11: control <= 1'b1; 5'd12: control <= 1'b1; 5'd13: control <= 1'b1; 5'd14: control <= 1'b1; 5'd15: control <= 1'b1; 5'd16: control <= 1'b0; 5'd17: control <= 1'b0; 5'd18: control <= 1'b0; 5'd19: control <= 1'b0; 5'd20: control <= 1'b0; 5'd21: control <= 1'b0; 5'd22: control <= 1'b0; 5'd23: control <= 1'b0; 5'd24: control <= 1'b0; 5'd25: control <= 1'b0; 5'd26: control <= 1'b0; 5'd27: control <= 1'b0; 5'd28: control <= 1'b0; 5'd29: control <= 1'b0; 5'd30: control <= 1'b0; 5'd31: control <= 1'b0; endcase end // synthesis attribute rom_style of control is "distributed" reg [0:0] control0; always @(posedge clk) begin control0 <= control; end assign t0_0 = x0; assign t0_1 = x1; always @(posedge clk) begin t1_0 <= (control0[0] == 0) ? t0_0 : t0_1; t1_1 <= (control0[0] == 0) ? t0_1 : t0_0; end always @(posedge clk) begin y0 <= t1_0; y1 <= t1_1; end endmodule // Latency: 68 // Gap: 32 module perm8698(clk, next, reset, next_out, x0, y0, x1, y1); parameter width = 32; parameter depth = 32; parameter addrbits = 5; parameter muxbits = 1; input [width-1:0] x0; output [width-1:0] y0; wire [width-1:0] t0; wire [width-1:0] s0; input [width-1:0] x1; output [width-1:0] y1; wire [width-1:0] t1; wire [width-1:0] s1; input next, reset, clk; output next_out; reg [addrbits-1:0] s1rdloc, s2rdloc; reg [addrbits-1:0] s1wr0; reg [addrbits-1:0] s1rd0, s2wr0, s2rd0; reg [addrbits-1:0] s1rd1, s2wr1, s2rd1; reg s1wr_en, state1, state2, state3; wire next2, next3, next4; reg inFlip0, outFlip0_z, outFlip1; wire inFlip1, outFlip0; wire [0:0] tm26; assign tm26 = 0; shiftRegFIFO #(3, 1) shiftFIFO_9892(.X(outFlip0), .Y(inFlip1), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9893(.X(outFlip0_z), .Y(outFlip0), .clk(clk)); // shiftRegFIFO #(2, 1) inFlip1Reg(outFlip0, inFlip1, clk); // shiftRegFIFO #(1, 1) outFlip0Reg(outFlip0_z, outFlip0, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem0(x0, t0, {inFlip0, s1wr0}, {outFlip0, s1rd0}, s1wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s1mem1(x1, t1, {inFlip0, s1wr0}, {outFlip0, s1rd1}, s1wr_en, clk); nextReg #(31, 5) nextReg_9904(.X(next), .Y(next2), .reset(reset), .clk(clk)); shiftRegFIFO #(4, 1) shiftFIFO_9905(.X(next2), .Y(next3), .clk(clk)); nextReg #(32, 5) nextReg_9908(.X(next3), .Y(next4), .reset(reset), .clk(clk)); shiftRegFIFO #(1, 1) shiftFIFO_9909(.X(next4), .Y(next_out), .clk(clk)); shiftRegFIFO #(31, 1) shiftFIFO_9912(.X(tm26), .Y(tm26_d), .clk(clk)); shiftRegFIFO #(3, 1) shiftFIFO_9915(.X(tm26_d), .Y(tm26_dd), .clk(clk)); wire [addrbits-1:0] muxCycle, writeCycle; assign muxCycle = s1rdloc; shiftRegFIFO #(3, 5) shiftFIFO_9920(.X(muxCycle), .Y(writeCycle), .clk(clk)); wire readInt, s2wr_en; assign readInt = (state2 == 1); shiftRegFIFO #(4, 1) writeIntReg(readInt, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem0(s0, y0, {inFlip1, s2wr0}, {outFlip1, s2rdloc}, s2wr_en, clk); memMod_dist #(depth*2, width, addrbits+1) s2mem1(s1, y1, {inFlip1, s2wr1}, {outFlip1, s2rdloc}, s2wr_en, clk); always @(posedge clk) begin if (reset == 1) begin state1 <= 0; inFlip0 <= 0; s1wr0 <= 0; end else if (next == 1) begin s1wr0 <= 0; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end else begin case(state1) 0: begin s1wr0 <= 0; state1 <= 0; s1wr_en <= 0; inFlip0 <= inFlip0; end 1: begin s1wr0 <= (s1wr0 == depth-1) ? 0 : s1wr0 + 1; state1 <= 1; s1wr_en <= 1; inFlip0 <= (s1wr0 == depth-1) ? ~inFlip0 : inFlip0; end endcase end end always @(posedge clk) begin if (reset == 1) begin state2 <= 0; outFlip0_z <= 0; end else if (next2 == 1) begin s1rdloc <= 0; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end else begin case(state2) 0: begin s1rdloc <= 0; state2 <= 0; outFlip0_z <= outFlip0_z; end 1: begin s1rdloc <= (s1rdloc == depth-1) ? 0 : s1rdloc + 1; state2 <= 1; outFlip0_z <= (s1rdloc == depth-1) ? ~outFlip0_z : outFlip0_z; end endcase end end always @(posedge clk) begin if (reset == 1) begin state3 <= 0; outFlip1 <= 0; end else if (next4 == 1) begin s2rdloc <= 0; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end else begin case(state3) 0: begin s2rdloc <= 0; state3 <= 0; outFlip1 <= outFlip1; end 1: begin s2rdloc <= (s2rdloc == depth-1) ? 0 : s2rdloc + 1; state3 <= 1; outFlip1 <= (s2rdloc == depth-1) ? ~outFlip1 : outFlip1; end endcase end end always @(posedge clk) begin case({tm26_d, s1rdloc}) {1'd0, 5'd0}: s1rd0 <= 1; {1'd0, 5'd1}: s1rd0 <= 3; {1'd0, 5'd2}: s1rd0 <= 5; {1'd0, 5'd3}: s1rd0 <= 7; {1'd0, 5'd4}: s1rd0 <= 9; {1'd0, 5'd5}: s1rd0 <= 11; {1'd0, 5'd6}: s1rd0 <= 13; {1'd0, 5'd7}: s1rd0 <= 15; {1'd0, 5'd8}: s1rd0 <= 17; {1'd0, 5'd9}: s1rd0 <= 19; {1'd0, 5'd10}: s1rd0 <= 21; {1'd0, 5'd11}: s1rd0 <= 23; {1'd0, 5'd12}: s1rd0 <= 25; {1'd0, 5'd13}: s1rd0 <= 27; {1'd0, 5'd14}: s1rd0 <= 29; {1'd0, 5'd15}: s1rd0 <= 31; {1'd0, 5'd16}: s1rd0 <= 0; {1'd0, 5'd17}: s1rd0 <= 2; {1'd0, 5'd18}: s1rd0 <= 4; {1'd0, 5'd19}: s1rd0 <= 6; {1'd0, 5'd20}: s1rd0 <= 8; {1'd0, 5'd21}: s1rd0 <= 10; {1'd0, 5'd22}: s1rd0 <= 12; {1'd0, 5'd23}: s1rd0 <= 14; {1'd0, 5'd24}: s1rd0 <= 16; {1'd0, 5'd25}: s1rd0 <= 18; {1'd0, 5'd26}: s1rd0 <= 20; {1'd0, 5'd27}: s1rd0 <= 22; {1'd0, 5'd28}: s1rd0 <= 24; {1'd0, 5'd29}: s1rd0 <= 26; {1'd0, 5'd30}: s1rd0 <= 28; {1'd0, 5'd31}: s1rd0 <= 30; endcase end // synthesis attribute rom_style of s1rd0 is "block" always @(posedge clk) begin case({tm26_d, s1rdloc}) {1'd0, 5'd0}: s1rd1 <= 0; {1'd0, 5'd1}: s1rd1 <= 2; {1'd0, 5'd2}: s1rd1 <= 4; {1'd0, 5'd3}: s1rd1 <= 6; {1'd0, 5'd4}: s1rd1 <= 8; {1'd0, 5'd5}: s1rd1 <= 10; {1'd0, 5'd6}: s1rd1 <= 12; {1'd0, 5'd7}: s1rd1 <= 14; {1'd0, 5'd8}: s1rd1 <= 16; {1'd0, 5'd9}: s1rd1 <= 18; {1'd0, 5'd10}: s1rd1 <= 20; {1'd0, 5'd11}: s1rd1 <= 22; {1'd0, 5'd12}: s1rd1 <= 24; {1'd0, 5'd13}: s1rd1 <= 26; {1'd0, 5'd14}: s1rd1 <= 28; {1'd0, 5'd15}: s1rd1 <= 30; {1'd0, 5'd16}: s1rd1 <= 1; {1'd0, 5'd17}: s1rd1 <= 3; {1'd0, 5'd18}: s1rd1 <= 5; {1'd0, 5'd19}: s1rd1 <= 7; {1'd0, 5'd20}: s1rd1 <= 9; {1'd0, 5'd21}: s1rd1 <= 11; {1'd0, 5'd22}: s1rd1 <= 13; {1'd0, 5'd23}: s1rd1 <= 15; {1'd0, 5'd24}: s1rd1 <= 17; {1'd0, 5'd25}: s1rd1 <= 19; {1'd0, 5'd26}: s1rd1 <= 21; {1'd0, 5'd27}: s1rd1 <= 23; {1'd0, 5'd28}: s1rd1 <= 25; {1'd0, 5'd29}: s1rd1 <= 27; {1'd0, 5'd30}: s1rd1 <= 29; {1'd0, 5'd31}: s1rd1 <= 31; endcase end // synthesis attribute rom_style of s1rd1 is "block" swNet8698 sw(tm26_d, clk, muxCycle, t0, s0, t1, s1); always @(posedge clk) begin case({tm26_dd, writeCycle}) {1'd0, 5'd0}: s2wr0 <= 16; {1'd0, 5'd1}: s2wr0 <= 17; {1'd0, 5'd2}: s2wr0 <= 18; {1'd0, 5'd3}: s2wr0 <= 19; {1'd0, 5'd4}: s2wr0 <= 20; {1'd0, 5'd5}: s2wr0 <= 21; {1'd0, 5'd6}: s2wr0 <= 22; {1'd0, 5'd7}: s2wr0 <= 23; {1'd0, 5'd8}: s2wr0 <= 24; {1'd0, 5'd9}: s2wr0 <= 25; {1'd0, 5'd10}: s2wr0 <= 26; {1'd0, 5'd11}: s2wr0 <= 27; {1'd0, 5'd12}: s2wr0 <= 28; {1'd0, 5'd13}: s2wr0 <= 29; {1'd0, 5'd14}: s2wr0 <= 30; {1'd0, 5'd15}: s2wr0 <= 31; {1'd0, 5'd16}: s2wr0 <= 0; {1'd0, 5'd17}: s2wr0 <= 1; {1'd0, 5'd18}: s2wr0 <= 2; {1'd0, 5'd19}: s2wr0 <= 3; {1'd0, 5'd20}: s2wr0 <= 4; {1'd0, 5'd21}: s2wr0 <= 5; {1'd0, 5'd22}: s2wr0 <= 6; {1'd0, 5'd23}: s2wr0 <= 7; {1'd0, 5'd24}: s2wr0 <= 8; {1'd0, 5'd25}: s2wr0 <= 9; {1'd0, 5'd26}: s2wr0 <= 10; {1'd0, 5'd27}: s2wr0 <= 11; {1'd0, 5'd28}: s2wr0 <= 12; {1'd0, 5'd29}: s2wr0 <= 13; {1'd0, 5'd30}: s2wr0 <= 14; {1'd0, 5'd31}: s2wr0 <= 15; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr0 is "block" always @(posedge clk) begin case({tm26_dd, writeCycle}) {1'd0, 5'd0}: s2wr1 <= 0; {1'd0, 5'd1}: s2wr1 <= 1; {1'd0, 5'd2}: s2wr1 <= 2; {1'd0, 5'd3}: s2wr1 <= 3; {1'd0, 5'd4}: s2wr1 <= 4; {1'd0, 5'd5}: s2wr1 <= 5; {1'd0, 5'd6}: s2wr1 <= 6; {1'd0, 5'd7}: s2wr1 <= 7; {1'd0, 5'd8}: s2wr1 <= 8; {1'd0, 5'd9}: s2wr1 <= 9; {1'd0, 5'd10}: s2wr1 <= 10; {1'd0, 5'd11}: s2wr1 <= 11; {1'd0, 5'd12}: s2wr1 <= 12; {1'd0, 5'd13}: s2wr1 <= 13; {1'd0, 5'd14}: s2wr1 <= 14; {1'd0, 5'd15}: s2wr1 <= 15; {1'd0, 5'd16}: s2wr1 <= 16; {1'd0, 5'd17}: s2wr1 <= 17; {1'd0, 5'd18}: s2wr1 <= 18; {1'd0, 5'd19}: s2wr1 <= 19; {1'd0, 5'd20}: s2wr1 <= 20; {1'd0, 5'd21}: s2wr1 <= 21; {1'd0, 5'd22}: s2wr1 <= 22; {1'd0, 5'd23}: s2wr1 <= 23; {1'd0, 5'd24}: s2wr1 <= 24; {1'd0, 5'd25}: s2wr1 <= 25; {1'd0, 5'd26}: s2wr1 <= 26; {1'd0, 5'd27}: s2wr1 <= 27; {1'd0, 5'd28}: s2wr1 <= 28; {1'd0, 5'd29}: s2wr1 <= 29; {1'd0, 5'd30}: s2wr1 <= 30; {1'd0, 5'd31}: s2wr1 <= 31; endcase // case(writeCycle) end // always @ (posedge clk) // synthesis attribute rom_style of s2wr1 is "block" endmodule module multfix(clk, rst, a, b, q_sc, q_unsc); parameter WIDTH=35, CYCLES=6; input signed [WIDTH-1:0] a,b; output [WIDTH-1:0] q_sc; output [WIDTH-1:0] q_unsc; input clk, rst; reg signed [2*WIDTH-1:0] q[CYCLES-1:0]; wire signed [2*WIDTH-1:0] res; integer i; assign res = q[CYCLES-1]; assign q_unsc = res[WIDTH-1:0]; assign q_sc = {res[2*WIDTH-1], res[2*WIDTH-4:WIDTH-2]}; always @(posedge clk) begin q[0] <= a * b; for (i = 1; i < CYCLES; i=i+1) begin q[i] <= q[i-1]; end end endmodule module addfxp(a, b, q, clk); parameter width = 16, cycles=1; input signed [width-1:0] a, b; input clk; output signed [width-1:0] q; reg signed [width-1:0] res[cycles-1:0]; assign q = res[cycles-1]; integer i; always @(posedge clk) begin res[0] <= a+b; for (i=1; i < cycles; i = i+1) res[i] <= res[i-1]; end endmodule module subfxp(a, b, q, clk); parameter width = 16, cycles=1; input signed [width-1:0] a, b; input clk; output signed [width-1:0] q; reg signed [width-1:0] res[cycles-1:0]; assign q = res[cycles-1]; integer i; always @(posedge clk) begin res[0] <= a-b; for (i=1; i < cycles; i = i+1) res[i] <= res[i-1]; end endmodule
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : idft_top_axi4lite.v // Project : Common Evaluation Platform (CEP) // Description : This file provides an axi4-lite wrapper for the wishbone based-IDFT core // module idft_top_axi4lite ( // Clock & Reset input logic clk_i, input logic rst_ni, // AXI4-Lite Slave Interface AXI_LITE.Slave slave ); // AES wishbone slave wires wire wb_clk; wire wb_rst; wire [slave.AXI_ADDR_WIDTH - 1:0] wbs_d_idft_adr_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_idft_dat_i; wire [3:0] wbs_d_idft_sel_i; wire wbs_d_idft_we_i; wire wbs_d_idft_cyc_i; wire wbs_d_idft_stb_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_idft_dat_o; wire wbs_d_idft_ack_o; // Instantiate the AXI4Lite to Wishbone bridge bonfire_axi4l2wb #( .ADRWIDTH (slave.AXI_ADDR_WIDTH), .FAST_READ_TERM (1'd0) ) bonfire_axi4l2wb_inst ( .S_AXI_ACLK (clk_i), .S_AXI_ARESETN (rst_ni), .S_AXI_AWADDR (slave.aw_addr), .S_AXI_AWVALID (slave.aw_valid), .S_AXI_AWREADY (slave.aw_ready), .S_AXI_WDATA (slave.w_data), .S_AXI_WSTRB (slave.w_strb), .S_AXI_WVALID (slave.w_valid), .S_AXI_WREADY (slave.w_ready), .S_AXI_ARADDR (slave.ar_addr), .S_AXI_ARVALID (slave.ar_valid), .S_AXI_ARREADY (slave.ar_ready), .S_AXI_RDATA (slave.r_data), .S_AXI_RRESP (slave.r_resp), .S_AXI_RVALID (slave.r_valid), .S_AXI_RREADY (slave.r_ready), .S_AXI_BRESP (slave.b_resp), .S_AXI_BVALID (slave.b_valid), .S_AXI_BREADY (slave.b_ready), .wb_clk_o (wb_clk), .wb_rst_o (wb_rst), .wb_addr_o (wbs_d_idft_adr_i), .wb_dat_o (wbs_d_idft_dat_i), .wb_we_o (wbs_d_idft_we_i), .wb_sel_o (wbs_d_idft_sel_i), .wb_stb_o (wbs_d_idft_stb_i), .wb_cyc_o (wbs_d_idft_cyc_i), .wb_dat_i (wbs_d_idft_dat_o), .wb_ack_i (wbs_d_idft_ack_o) ); // Instantiate the wishbone-based IDFT Core idft_top_top idft_top_top_inst ( // Wishbone Slave interface .wb_clk_i (wb_clk), .wb_rst_i (wb_rst), .wb_dat_i (wbs_d_idft_dat_i), .wb_adr_i (wbs_d_idft_adr_i), .wb_sel_i (wbs_d_idft_sel_i[3:0]), .wb_we_i (wbs_d_idft_we_i), .wb_cyc_i (wbs_d_idft_cyc_i), .wb_stb_i (wbs_d_idft_stb_i), .wb_dat_o (wbs_d_idft_dat_o), .wb_err_o (), .wb_ack_o (wbs_d_idft_ack_o), // Processor interrupt .int_o () ); endmodule // end aes_top_axi4lite
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : idft_top_top.v // Project : Common Evaluation Platform (CEP) // Description : This file provides a wishbone based-IDFT core // module idft_top_top( wb_adr_i, wb_cyc_i, wb_dat_i, wb_sel_i, wb_stb_i, wb_we_i, wb_ack_o, wb_err_o, wb_dat_o, wb_clk_i, wb_rst_i, int_o ); parameter dw = 32; parameter aw = 32; input [aw-1:0] wb_adr_i; input wb_cyc_i; input [dw-1:0] wb_dat_i; input [3:0] wb_sel_i; input wb_stb_i; input wb_we_i; output wb_ack_o; output wb_err_o; output reg [dw-1:0] wb_dat_o; output int_o; input wb_clk_i; input wb_rst_i; assign wb_ack_o = 1'b1; assign wb_err_o = 1'b0; assign int_o = 1'b0; // Internal registers reg next; reg [63:0] dataX [0:31]; reg [63:0] dataY [0:31]; reg [5:0] xSel; reg [5:0] ySel; wire [63:0] dataIn, dataOut, dataR_Out; reg [63:0] data_In_data, data_In_addr, data_Out_addr; reg data_valid, data_In_write; wire next_out, next_posedge; // Implement MD5 I/O memory map interface // Write side always @(posedge wb_clk_i) begin if(wb_rst_i) begin next <= 0; data_In_write <= 0; data_In_addr <= 0; data_In_data[31:0] <= 0; data_In_data[63:32]<= 0; end else if(wb_stb_i & wb_we_i) case(wb_adr_i[5:2]) 0: next <= wb_dat_i[0]; 1: data_In_write <= wb_dat_i[0]; 2: data_In_addr <= wb_dat_i; 3: data_In_data[31:0] <= wb_dat_i; 4: data_In_data[63:32]<= wb_dat_i; 5: data_Out_addr <= wb_dat_i; default: ; endcase end // always @ (posedge wb_clk_i) // Implement MD5 I/O memory map interface // Read side always @(*) begin case(wb_adr_i[5:2]) 0: wb_dat_o = {31'b0, next}; 1: wb_dat_o = {31'b0, data_In_write}; 2: wb_dat_o = data_In_addr; 3: wb_dat_o = data_In_data[31:0]; 4: wb_dat_o = data_In_data[63:32]; 5: wb_dat_o = data_Out_addr; 6: wb_dat_o = dataR_Out[31:0]; 7: wb_dat_o = dataR_Out[63:32]; 8: wb_dat_o = {31'b0, data_valid}; default: wb_dat_o = 32'b0; endcase end // always @ (*) idft_top idft_top( .clk(wb_clk_i), .reset(wb_rst_i), .next(next_posedge), .next_out(next_out), .X0(dataIn[15:0]), .X1(dataIn[31:16]), .X2(dataIn[47:32]), .X3(dataIn[63:48]), .Y0(dataOut[15:0]), .Y1(dataOut[31:16]), .Y2(dataOut[47:32]), .Y3(dataOut[63:48])); reg data_In_write_r; always @(posedge wb_clk_i) begin data_In_write_r <= data_In_write; end wire data_In_write_posedge = data_In_write & ~data_In_write_r; always @ (posedge wb_clk_i) begin if(data_In_write_posedge) begin dataX[data_In_addr] <= data_In_data; end end assign dataR_Out=dataY[data_Out_addr]; reg next_r; always @(posedge wb_clk_i) begin next_r <= next; end assign next_posedge = next & ~next_r; always @ (posedge wb_clk_i) begin if(next_posedge) begin xSel <= 6'h00; end else if(xSel<6'b100000) begin xSel <= xSel +1; end end assign dataIn = dataX[xSel]; reg next_out_r; always @(posedge wb_clk_i) begin next_out_r <= next_out; end wire next_out_posedge = next_out & ~next_out_r; always @ (posedge wb_clk_i) begin if(next_out_posedge) begin ySel <= 6'h00; end else if(ySel<6'b100000) begin ySel <= ySel +1; dataY[ySel] = dataOut; end end always @ (posedge wb_clk_i) begin if(next_posedge) begin data_valid <= 0; end else if(next_out_posedge) begin data_valid <= 1; end end endmodule
/*------------------------------------------------------------------------------ * This code was generated by Spiral IIR Filter Generator, www.spiral.net * Copyright (c) 2006, Carnegie Mellon University * All rights reserved. * The code is distributed under a BSD style license * (see http://www.opensource.org/licenses/bsd-license.php) *------------------------------------------------------------------------------ */ /* ./iirGen.pl -A 256 0 378 0 179 0 32 0 2 0 0 0 -B 0 4 22 68 136 191 191 136 68 22 4 0 -moduleName IIR_filter -fractionalBits 8 -bitWidth 32 -inData inData -inReg -outReg -outData outData -clk clk -reset reset -reset_edge negedge -filterForm 1 -debug -outFile ../outputs/filter_1536036361.v */ /* Warning: zero-valued filter taps have been optimized away. */ module IIR_filter_firBlock_left_MultiplyBlock ( X, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11 ); // Port mode declarations: input signed [31:0] X; output signed [31:0] Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11; wire [31:0] Y [0:10]; assign Y1 = Y[0]; assign Y2 = Y[1]; assign Y3 = Y[2]; assign Y4 = Y[3]; assign Y5 = Y[4]; assign Y6 = Y[5]; assign Y7 = Y[6]; assign Y8 = Y[7]; assign Y9 = Y[8]; assign Y10 = Y[9]; assign Y11 = Y[10]; //Multipliers: wire signed [39:0] w1, w0, w16, w17, w4, w3, w8, w11, w192, w191, w22, w68, w136; assign w1 = X; assign w0 = 0; assign w11 = w3 + w8; //2195.42405790882 = adderArea(3,34) assign w136 = w17 << 3; //shl(3,39) assign w16 = w1 << 4; //shl(4,35) assign w17 = w1 + w16; //2195.42405790882 = adderArea(4,35) assign w191 = w192 - w1; //2561.32791574853 = subArea(6,39) assign w192 = w3 << 6; //shl(6,39) assign w22 = w11 << 1; //shl(1,36) assign w3 = w4 - w1; //2408.3135227603 = subArea(2,33) assign w4 = w1 << 2; //shl(2,33) assign w68 = w17 << 2; //shl(2,38) assign w8 = w1 << 3; //shl(3,34) assign Y[0] = w4[39:8]; //BitwidthUsed(0, 25) assign Y[1] = w22[39:8]; //BitwidthUsed(0, 28) assign Y[2] = w68[39:8]; //BitwidthUsed(0, 30) assign Y[3] = w136[39:8]; //BitwidthUsed(0, 31) assign Y[4] = w191[39:8]; //BitwidthUsed(0, 31) assign Y[5] = w191[39:8]; //BitwidthUsed(0, 31) assign Y[6] = w136[39:8]; //BitwidthUsed(0, 31) assign Y[7] = w68[39:8]; //BitwidthUsed(0, 30) assign Y[8] = w22[39:8]; //BitwidthUsed(0, 28) assign Y[9] = w4[39:8]; //BitwidthUsed(0, 25) assign Y[10] = w0[39:8]; //BitwidthUsed(none) //IIR_filter_firBlock_left_MultiplyBlock area estimate = 9360.48955432647; endmodule //IIR_filter_firBlock_left_MultiplyBlock module IIR_filter_firBlock_left ( X, clk, Y, reset ); // Port mode declarations: input [31:0] X; input clk; output [31:0] Y; input reset; //registerOut reg [31:0] Y; wire [31:0] Y_in; always@(posedge clk or negedge reset) begin if(~reset) begin Y <= 32'h00000000; end else begin Y <= Y_in; end end wire [31:0] multProducts [0:10]; IIR_filter_firBlock_left_MultiplyBlock my_IIR_filter_firBlock_left_MultiplyBlock( .X(X), .Y1(multProducts[0]), .Y2(multProducts[1]), .Y3(multProducts[2]), .Y4(multProducts[3]), .Y5(multProducts[4]), .Y6(multProducts[5]), .Y7(multProducts[6]), .Y8(multProducts[7]), .Y9(multProducts[8]), .Y10(multProducts[9]), .Y11(multProducts[10]) ); reg [31:0] firStep[0:9]; always@(posedge clk or negedge reset) begin if(~reset) begin firStep[0] <= 32'h00000000; firStep[1] <= 32'h00000000; firStep[2] <= 32'h00000000; firStep[3] <= 32'h00000000; firStep[4] <= 32'h00000000; firStep[5] <= 32'h00000000; firStep[6] <= 32'h00000000; firStep[7] <= 32'h00000000; firStep[8] <= 32'h00000000; firStep[9] <= 32'h00000000; end else begin firStep[0] <= multProducts[0]; // 2448.23046908235 = flop(0, 31) firStep[1] <= firStep[0] + multProducts[1]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[2] <= firStep[1] + multProducts[2]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[3] <= firStep[2] + multProducts[3]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[4] <= firStep[3] + multProducts[4]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[5] <= firStep[4] + multProducts[5]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[6] <= firStep[5] + multProducts[6]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[7] <= firStep[6] + multProducts[7]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[8] <= firStep[7] + multProducts[8]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[9] <= firStep[8] + multProducts[9]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) end end assign Y_in = firStep[9]+ multProducts[10];// 0 = adder(none) //IIR_filter_firBlock_left area estimate = 56049.8412354117; endmodule //IIR_filter_firBlock_left /* Warning: zero-valued filter taps have been optimized away. */ module IIR_filter_firBlock_right_MultiplyBlock ( X, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8 ); // Port mode declarations: input signed [31:0] X; output signed [31:0] Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8; wire [31:0] Y [0:7]; assign Y1 = Y[0]; assign Y2 = Y[1]; assign Y3 = Y[2]; assign Y4 = Y[3]; assign Y5 = Y[4]; assign Y6 = Y[5]; assign Y7 = Y[6]; assign Y8 = Y[7]; //Multipliers: wire signed [39:0] w1, w0, w4, w3, w192, w189, w5, w10, w179, w2, w2_, w32, w32_, w179_, w378, w378_; assign w1 = X; assign w0 = 0; assign w10 = w5 << 1; //shl(1,35) assign w179 = w189 - w10; //2943.86389821912 = subArea(1,39) assign w179_ = -1 * w179; //1809.56165059559 = negArea(0,39) assign w189 = w192 - w3; //2484.82071925441 = subArea(6,38) assign w192 = w3 << 6; //shl(6,38) assign w2 = w1 << 1; //shl(1,32) assign w2_ = -1 * w2; //1437.00483871323 = negArea(1,32) assign w3 = w4 - w1; //2331.80632626618 = subArea(2,32) assign w32 = w1 << 5; //shl(5,36) assign w32_ = -1 * w32; //1437.00483871323 = negArea(5,36) assign w378 = w189 << 1; //shl(1,39) assign w378_ = -1 * w378; //1762.99204911029 = negArea(1,39) assign w4 = w1 << 2; //shl(2,32) assign w5 = w1 + w4; //2195.42405790882 = adderArea(2,33) assign Y[0] = w2_[39:8]; //BitwidthUsed(0, 24) assign Y[1] = w0[39:8]; //BitwidthUsed(none) assign Y[2] = w32_[39:8]; //BitwidthUsed(0, 28) assign Y[3] = w0[39:8]; //BitwidthUsed(none) assign Y[4] = w179_[39:8]; //BitwidthUsed(0, 31) assign Y[5] = w0[39:8]; //BitwidthUsed(none) assign Y[6] = w378_[39:8]; //BitwidthUsed(0, 31) assign Y[7] = w0[39:8]; //BitwidthUsed(none) //IIR_filter_firBlock_right_MultiplyBlock area estimate = 16402.4783787809; endmodule //IIR_filter_firBlock_right_MultiplyBlock module IIR_filter_firBlock_right ( X, clk, Y, reset ); // Port mode declarations: input [31:0] X; input clk; output [31:0] Y; input reset; //registerOut reg [31:0] Y; wire [31:0] Y_in; always@(posedge clk or negedge reset) begin if(~reset) begin Y <= 32'h00000000; end else begin Y <= Y_in; end end wire [31:0] multProducts [0:7]; IIR_filter_firBlock_right_MultiplyBlock my_IIR_filter_firBlock_right_MultiplyBlock( .X(X), .Y1(multProducts[0]), .Y2(multProducts[1]), .Y3(multProducts[2]), .Y4(multProducts[3]), .Y5(multProducts[4]), .Y6(multProducts[5]), .Y7(multProducts[6]), .Y8(multProducts[7]) ); reg [31:0] firStep[0:6]; always@(posedge clk or negedge reset) begin if(~reset) begin firStep[0] <= 32'h00000000; firStep[1] <= 32'h00000000; firStep[2] <= 32'h00000000; firStep[3] <= 32'h00000000; firStep[4] <= 32'h00000000; firStep[5] <= 32'h00000000; firStep[6] <= 32'h00000000; end else begin firStep[0] <= multProducts[0]; // 2448.23046908235 = flop(0, 31) firStep[1] <= firStep[0] + multProducts[1]; // 2448.23046908235 = flop(0, 31) + adder(none) firStep[2] <= firStep[1] + multProducts[2]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[3] <= firStep[2] + multProducts[3]; // 2448.23046908235 = flop(0, 31) + adder(none) firStep[4] <= firStep[3] + multProducts[4]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) firStep[5] <= firStep[4] + multProducts[5]; // 2448.23046908235 = flop(0, 31) + adder(none) firStep[6] <= firStep[5] + multProducts[6]; // 4643.65452699117 = flop(0, 31) + adder(0, 31) end end assign Y_in = firStep[6]+ multProducts[7];// 0 = adder(none) //IIR_filter_firBlock_right area estimate = 42574.5943051662; endmodule //IIR_filter_firBlock_right module IIR_filter ( inData, clk, outData, reset ); // Port mode declarations: input [31:0] inData; input clk; output [31:0] outData; input reset; //registerIn reg [31:0] inData_in; always@(posedge clk or negedge reset) begin if(~reset) begin inData_in <= 32'h00000000; end else begin inData_in <= inData; end end //registerOut reg [31:0] outData; wire [31:0] outData_in; always@(posedge clk or negedge reset) begin if(~reset) begin outData <= 32'h00000000; end else begin outData <= outData_in; end end wire [31:0] leftOut, rightOut; IIR_filter_firBlock_left my_IIR_filter_firBlock_left( .X(inData_in), .Y(leftOut), .clk(clk), .reset(reset) ); IIR_filter_firBlock_right my_IIR_filter_firBlock_right( .X(outData_in), .Y(rightOut), .clk(clk), .reset(reset) ); assign outData_in = leftOut + rightOut; // adder(32) //IIR_filter area estimate = 105716.320536651; endmodule //IIR_filter
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : iir_top.v // Project : Common Evaluation Platform (CEP) // Description : This file provides a wishbone based-IIR core // module iir_top( wb_adr_i, wb_cyc_i, wb_dat_i, wb_sel_i, wb_stb_i, wb_we_i, wb_ack_o, wb_err_o, wb_dat_o, wb_clk_i, wb_rst_i, int_o ); parameter dw = 32; parameter aw = 32; input [aw-1:0] wb_adr_i; input wb_cyc_i; input [dw-1:0] wb_dat_i; input [3:0] wb_sel_i; input wb_stb_i; input wb_we_i; output wb_ack_o; output wb_err_o; output reg [dw-1:0] wb_dat_o; output int_o; input wb_clk_i; input wb_rst_i; assign wb_ack_o = 1'b1; assign wb_err_o = 1'b0; assign int_o = 1'b0; // Internal registers reg next; reg [31:0] dataX [0:31]; reg [31:0] dataY [0:31]; reg [5:0] xSel=6'b0; reg [5:0] ySel=6'b0; reg [5:0] count; wire [31:0] dataIn, dataOut, data_Out; reg [31:0] data_In_data, data_In_addr, data_Out_addr; reg data_valid, data_In_write; wire next_out; // Implement MD5 I/O memory map interface // Write side always @(posedge wb_clk_i) begin if(wb_rst_i) begin next <= 0; data_In_write <= 0; data_In_addr <= 0; data_In_data <= 0; end else if(wb_stb_i & wb_we_i) case(wb_adr_i[5:2]) 0: next <= wb_dat_i[0]; 1: data_In_write <= wb_dat_i[0]; 2: data_In_addr <= wb_dat_i; 3: data_In_data <= wb_dat_i; 4: data_Out_addr <= wb_dat_i; default: ; endcase end // always @ (posedge wb_clk_i) // Implement MD5 I/O memory map interface // Read side always @(*) begin case(wb_adr_i[5:2]) 0: wb_dat_o = {31'b0, next}; 1: wb_dat_o = {31'b0, data_In_write}; 2: wb_dat_o = data_In_addr; 3: wb_dat_o = data_In_data; 4: wb_dat_o = data_Out_addr; 5: wb_dat_o = data_Out; 6: wb_dat_o = {31'b0, data_valid}; default: wb_dat_o = 32'b0; endcase end // always @ (*) IIR_filter IIR_filter( .clk(wb_clk_i), .reset(~wb_rst_i), .inData(dataIn), .outData(dataOut)); reg data_In_write_r; always @(posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) data_In_write_r <= 0; else data_In_write_r <= data_In_write; end wire data_In_write_posedge = data_In_write & ~data_In_write_r; reg [15:0] i; always @ (posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) for (i = 0; i < 32; i = i + 1) dataX[i] <= 0; else dataX[data_In_addr] <= data_In_data; end assign data_Out = dataY[data_Out_addr]; reg next_r; always @(posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) next_r <= 0; else next_r <= next; end wire next_posedge = next & ~next_r; always @ (posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) xSel <= 0; else if(next_posedge) xSel <= 6'h00; else if(xSel<6'b100000) xSel <= xSel + 1; end assign dataIn = (xSel<6'b100000) ? dataX[xSel] : 32'b0; always @ (posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) count <= 0; else if(next_posedge) begin count <= 6'h00; end else if(xSel<4'b1010) begin count <= count +1; end end assign next_out = (count == 4'b1000); reg next_out_r; always @(posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) next_out_r <= 0; else next_out_r <= next_out; end wire next_out_posedge = next_out & ~next_out_r; always @ (posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) begin ySel <= 0; for (i = 0; i < 32; i = i + 1) dataY[i] <= 0; end else if(next_out_posedge) begin ySel <= 6'h00; end else if(ySel<6'b100000) begin ySel <= ySel +1; dataY[ySel] = dataOut; end end always @ (posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) data_valid <= 0; else if(next_posedge) begin data_valid <= 0; end else if(next_out_posedge) begin data_valid <= 1; end end endmodule
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : iir_top_axi4lite.v // Project : Common Evaluation Platform (CEP) // Description : This file provides an axi4-lite wrapper for the wishbone based-IIR core // module iir_top_axi4lite ( // Clock & Reset input logic clk_i, input logic rst_ni, // AXI4-Lite Slave Interface AXI_LITE.Slave slave ); // AES wishbone slave wires wire wb_clk; wire wb_rst; wire [slave.AXI_ADDR_WIDTH - 1:0] wbs_d_iir_adr_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_iir_dat_i; wire [3:0] wbs_d_iir_sel_i; wire wbs_d_iir_we_i; wire wbs_d_iir_cyc_i; wire wbs_d_iir_stb_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_iir_dat_o; wire wbs_d_iir_ack_o; wire wbs_d_iir_err_o; // Instantiate the AXI4Lite to Wishbone bridge bonfire_axi4l2wb #( .ADRWIDTH (slave.AXI_ADDR_WIDTH), .FAST_READ_TERM (1'd0) ) bonfire_axi4l2wb_inst ( .S_AXI_ACLK (clk_i), .S_AXI_ARESETN (rst_ni), .S_AXI_AWADDR (slave.aw_addr), .S_AXI_AWVALID (slave.aw_valid), .S_AXI_AWREADY (slave.aw_ready), .S_AXI_WDATA (slave.w_data), .S_AXI_WSTRB (slave.w_strb), .S_AXI_WVALID (slave.w_valid), .S_AXI_WREADY (slave.w_ready), .S_AXI_ARADDR (slave.ar_addr), .S_AXI_ARVALID (slave.ar_valid), .S_AXI_ARREADY (slave.ar_ready), .S_AXI_RDATA (slave.r_data), .S_AXI_RRESP (slave.r_resp), .S_AXI_RVALID (slave.r_valid), .S_AXI_RREADY (slave.r_ready), .S_AXI_BRESP (slave.b_resp), .S_AXI_BVALID (slave.b_valid), .S_AXI_BREADY (slave.b_ready), .wb_clk_o (wb_clk), .wb_rst_o (wb_rst), .wb_addr_o (wbs_d_iir_adr_i), .wb_dat_o (wbs_d_iir_dat_i), .wb_we_o (wbs_d_iir_we_i), .wb_sel_o (wbs_d_iir_sel_i), .wb_stb_o (wbs_d_iir_stb_i), .wb_cyc_o (wbs_d_iir_cyc_i), .wb_dat_i (wbs_d_iir_dat_o), .wb_ack_i (wbs_d_iir_ack_o) ); // Instantiate the wishbone-based DFT Core iir_top iir_top_inst ( // Wishbone Slave interface .wb_clk_i (wb_clk), .wb_rst_i (wb_rst), .wb_dat_i (wbs_d_iir_dat_i), .wb_adr_i (wbs_d_iir_adr_i), .wb_sel_i (wbs_d_iir_sel_i[3:0]), .wb_we_i (wbs_d_iir_we_i), .wb_cyc_i (wbs_d_iir_cyc_i), .wb_stb_i (wbs_d_iir_stb_i), .wb_dat_o (wbs_d_iir_dat_o), .wb_err_o (), .wb_ack_o (wbs_d_iir_ack_o), // Processor interrupt .int_o () ); endmodule // end aes_top_axi4lite
// Copyright 2017 ETH Zurich and University of Bologna. // Copyright and related rights are licensed under the Solderpad Hardware // License, Version 0.51 (the “License”); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law // or agreed to in writing, software, hardware and materials distributed under // this License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. `ifndef APB_BUS_SV `define APB_BUS_SV `include "config.sv" // SOC PERIPHERALS APB BUS PARAMETRES `define NB_MASTER 9 // MASTER PORT TO CVP `define UART_START_ADDR 32'h1A10_0000 `define UART_END_ADDR 32'h1A10_0FFF // MASTER PORT TO GPIO `define GPIO_START_ADDR 32'h1A10_1000 `define GPIO_END_ADDR 32'h1A10_1FFF // MASTER PORT TO SPI MASTER `define SPI_START_ADDR 32'h1A10_2000 `define SPI_END_ADDR 32'h1A10_2FFF // MASTER PORT TO TIMER `define TIMER_START_ADDR 32'h1A10_3000 `define TIMER_END_ADDR 32'h1A10_3FFF // MASTER PORT TO EVENT UNIT `define EVENT_UNIT_START_ADDR 32'h1A10_4000 `define EVENT_UNIT_END_ADDR 32'h1A10_4FFF // MASTER PORT TO I2C `define I2C_START_ADDR 32'h1A10_5000 `define I2C_END_ADDR 32'h1A10_5FFF // MASTER PORT TO FLL `define FLL_START_ADDR 32'h1A10_6000 `define FLL_END_ADDR 32'h1A10_6FFF // MASTER PORT TO SOC CTRL `define SOC_CTRL_START_ADDR 32'h1A10_7000 `define SOC_CTRL_END_ADDR 32'h1A10_7FFF // MASTER PORT TO DEBUG `define DEBUG_START_ADDR 32'h1A11_0000 `define DEBUG_END_ADDR 32'h1A11_7FFF `define APB_ASSIGN_SLAVE(lhs, rhs) \ assign lhs.paddr = rhs.paddr; \ assign lhs.pwdata = rhs.pwdata; \ assign lhs.pwrite = rhs.pwrite; \ assign lhs.psel = rhs.psel; \ assign lhs.penable = rhs.penable; \ assign rhs.prdata = lhs.prdata; \ assign rhs.pready = lhs.pready; \ assign rhs.pslverr = lhs.pslverr; `define APB_ASSIGN_MASTER(lhs, rhs) `APB_ASSIGN_SLAVE(rhs, lhs) //////////////////////////////////////////////////////////////////////////////// // Only general functions and definitions are defined here // // These functions are not intended to be modified // //////////////////////////////////////////////////////////////////////////////// interface APB_BUS #( parameter APB_ADDR_WIDTH = 32, parameter APB_DATA_WIDTH = 32 ); logic [APB_ADDR_WIDTH-1:0] paddr; logic [APB_DATA_WIDTH-1:0] pwdata; logic pwrite; logic psel; logic penable; logic [APB_DATA_WIDTH-1:0] prdata; logic pready; logic pslverr; // Master Side //*************************************** modport Master ( output paddr, pwdata, pwrite, psel, penable, input prdata, pready, pslverr ); // Slave Side //*************************************** modport Slave ( input paddr, pwdata, pwrite, psel, penable, output prdata, pready, pslverr ); endinterface `endif
// Copyright 2017 ETH Zurich and University of Bologna. // Copyright and related rights are licensed under the Solderpad Hardware // License, Version 0.51 (the “License”); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law // or agreed to in writing, software, hardware and materials distributed under // this License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. //`define SHARED_APU `define APU
// Copyright 2017 ETH Zurich and University of Bologna. // Copyright and related rights are licensed under the Solderpad Hardware // License, Version 0.51 (the “License”); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law // or agreed to in writing, software, hardware and materials distributed under // this License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. `ifndef CONFIG_SV `define CONFIG_SV `define RISCV // always define ASIC when we do a synthesis run `ifndef PULP_FPGA_EMUL `ifdef SYNTHESIS `define ASIC `endif `endif // data and instruction RAM address and word width `define ROM_ADDR_WIDTH 12 `define ROM_START_ADDR 32'h8000 // Simulation only stuff `ifndef SYNTHESIS //`define DATA_STALL_RANDOM //`define INSTR_STALL_RANDOM `endif `endif
// Copyright 2017 ETH Zurich and University of Bologna. // Copyright and related rights are licensed under the Solderpad Hardware // License, Version 0.51 (the “License”); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law // or agreed to in writing, software, hardware and materials distributed under // this License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. `ifndef DEBUG_BUS_SV `define DEBUG_BUS_SV `include "config.sv" interface DEBUG_BUS #( parameter ADDR_WIDTH = 15 ); logic req; logic gnt; logic rvalid; logic [ADDR_WIDTH-1:0] addr; logic we; logic [31: 0] wdata; logic [31: 0] rdata; // Master Side //*************************************** modport Master ( output req, addr, we, wdata, input gnt, rvalid, rdata ); // Slave Side //*************************************** modport Slave ( input req, addr, we, wdata, output gnt, rvalid, rdata ); endinterface `endif
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : md5_top.v // Project : Common Evaluation Platform (CEP) // Description : This file provides a wishbone based-MD5 core // module md5_top( wb_adr_i, wb_cyc_i, wb_dat_i, wb_sel_i, wb_stb_i, wb_we_i, wb_ack_o, wb_err_o, wb_dat_o, wb_clk_i, wb_rst_i, int_o ); parameter dw = 32; parameter aw = 32; input [aw-1:0] wb_adr_i; input wb_cyc_i; input [dw-1:0] wb_dat_i; input [3:0] wb_sel_i; input wb_stb_i; input wb_we_i; output wb_ack_o; output wb_err_o; output reg [dw-1:0] wb_dat_o; output int_o; input wb_clk_i; input wb_rst_i; assign wb_ack_o = 1'b1; assign wb_err_o = 1'b0; assign int_o = 1'b0; // Internal registers reg startHash, startHash_r; reg [31:0] data [15:0]; reg message_reset, message_reset_r; wire [511:0] bigData = {data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15]}; wire [127:0] hash; wire ready; wire hashValid; // Implement MD5 I/O memory map interface // Write side always @(posedge wb_clk_i) begin if(wb_rst_i) begin startHash <= 0; startHash_r <= 0; message_reset <= 0; message_reset_r <= 0; data[0] <= 0; data[1] <= 0; data[2] <= 0; data[3] <= 0; data[4] <= 0; data[5] <= 0; data[6] <= 0; data[7] <= 0; data[8] <= 0; data[9] <= 0; data[10] <= 0; data[11] <= 0; data[12] <= 0; data[13] <= 0; data[14] <= 0; data[15] <= 0; end else begin // Generate a registered versions of startHash and message_reset startHash_r <= startHash; message_reset_r <= message_reset; // Perform a write if(wb_stb_i & wb_we_i) begin case(wb_adr_i[6:2]) 0: startHash <= wb_dat_i[0]; 1: data[15] <= wb_dat_i; 2: data[14] <= wb_dat_i; 3: data[13] <= wb_dat_i; 4: data[12] <= wb_dat_i; 5: data[11] <= wb_dat_i; 6: data[10] <= wb_dat_i; 7: data[9] <= wb_dat_i; 8: data[8] <= wb_dat_i; 9: data[7] <= wb_dat_i; 10: data[6] <= wb_dat_i; 11: data[5] <= wb_dat_i; 12: data[4] <= wb_dat_i; 13: data[3] <= wb_dat_i; 14: data[2] <= wb_dat_i; 15: data[1] <= wb_dat_i; 16: data[0] <= wb_dat_i; 22: message_reset <= wb_dat_i[0]; default: ; endcase end else begin // if(wb_stb_i & wb_we_i) startHash <= 1'b0; message_reset <= 1'b0; end // end else end // else end // end always // Implement MD5 I/O memory map interface // Read side always @(*) begin case(wb_adr_i[6:2]) 0: wb_dat_o = {31'b0, ready}; 1: wb_dat_o = data[15]; 2: wb_dat_o = data[14]; 3: wb_dat_o = data[13]; 4: wb_dat_o = data[12]; 5: wb_dat_o = data[11]; 6: wb_dat_o = data[10]; 7: wb_dat_o = data[9]; 8: wb_dat_o = data[8]; 9: wb_dat_o = data[7]; 10: wb_dat_o = data[6]; 11: wb_dat_o = data[5]; 12: wb_dat_o = data[4]; 13: wb_dat_o = data[3]; 14: wb_dat_o = data[2]; 15: wb_dat_o = data[1]; 16: wb_dat_o = data[0]; 17: wb_dat_o = {31'b0, hashValid}; 21: wb_dat_o = hash[127:96]; 20: wb_dat_o = hash[95:64]; 19: wb_dat_o = hash[63:32]; 18: wb_dat_o = hash[31:0]; default: wb_dat_o = 32'b0; endcase end pancham pancham( .clk(wb_clk_i), .rst(wb_rst_i | (message_reset & ~message_reset_r)), .msg_padded(bigData), .msg_in_valid(startHash && ~startHash_r), .msg_output(hash), .msg_out_valid(hashValid), .ready(ready) ); endmodule
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : md5_top_axi4lite.v // Project : Common Evaluation Platform (CEP) // Description : This file provides an axi4-lite wrapper for the wishbone based-MD5 core // module md5_top_axi4lite ( // Clock & Reset input logic clk_i, input logic rst_ni, // AXI4-Lite Slave Interface AXI_LITE.Slave slave ); // AES wishbone slave wires wire wb_clk; wire wb_rst; wire wb_rst_n; wire [slave.AXI_ADDR_WIDTH - 1:0] wbs_d_md5_adr_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_md5_dat_i; wire [3:0] wbs_d_md5_sel_i; wire wbs_d_md5_we_i; wire wbs_d_md5_cyc_i; wire wbs_d_md5_stb_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_md5_dat_o; wire wbs_d_md5_ack_o; // Instantiate the AXI4Lite to Wishbone bridge bonfire_axi4l2wb #( .ADRWIDTH (slave.AXI_ADDR_WIDTH), .FAST_READ_TERM (1'd0) ) bonfire_axi4l2wb_inst ( .S_AXI_ACLK (clk_i), .S_AXI_ARESETN (rst_ni), .S_AXI_AWADDR (slave.aw_addr), .S_AXI_AWVALID (slave.aw_valid), .S_AXI_AWREADY (slave.aw_ready), .S_AXI_WDATA (slave.w_data), .S_AXI_WSTRB (slave.w_strb), .S_AXI_WVALID (slave.w_valid), .S_AXI_WREADY (slave.w_ready), .S_AXI_ARADDR (slave.ar_addr), .S_AXI_ARVALID (slave.ar_valid), .S_AXI_ARREADY (slave.ar_ready), .S_AXI_RDATA (slave.r_data), .S_AXI_RRESP (slave.r_resp), .S_AXI_RVALID (slave.r_valid), .S_AXI_RREADY (slave.r_ready), .S_AXI_BRESP (slave.b_resp), .S_AXI_BVALID (slave.b_valid), .S_AXI_BREADY (slave.b_ready), .wb_clk_o (wb_clk), .wb_rst_o (wb_rst), .wb_addr_o (wbs_d_md5_adr_i), .wb_dat_o (wbs_d_md5_dat_i), .wb_we_o (wbs_d_md5_we_i), .wb_sel_o (wbs_d_md5_sel_i), .wb_stb_o (wbs_d_md5_stb_i), .wb_cyc_o (wbs_d_md5_cyc_i), .wb_dat_i (wbs_d_md5_dat_o), .wb_ack_i (wbs_d_md5_ack_o) ); // Instantiate the wishbone-based MD5 Core md5_top md5_top_inst ( // Wishbone Slave interface .wb_clk_i (wb_clk), .wb_rst_i (wb_rst), .wb_dat_i (wbs_d_md5_dat_i), .wb_adr_i (wbs_d_md5_adr_i), .wb_sel_i (wbs_d_md5_sel_i[3:0]), .wb_we_i (wbs_d_md5_we_i), .wb_cyc_i (wbs_d_md5_cyc_i), .wb_stb_i (wbs_d_md5_stb_i), .wb_dat_o (wbs_d_md5_dat_o), .wb_err_o (), .wb_ack_o (wbs_d_md5_ack_o), // Processor interrupt .int_o () ); endmodule // end md5_top_axi4lite
/***************************************************************** Pancham is an MD5 compliant IP core for cryptographic applications. Copyright (C) 2003 Swapnajit Mittra, Project VeriPage (Contact email: verilog_tutorial at hotmail.com Website : http://www.angelfire.com/ca/verilog) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc. 59 Temple Place, Suite 330 Boston, MA 02111-1307 USA ******************************************************************/ /* * This is the main module that computes a 128-bit message * digest from a maximum of 512-bit long input message using * MD5 algorithm. * * Modified by Matthew Hicks (mdhicks@gmail.com) * Input from 128-bit to 512-bit * Hold valid outputs * Carry over constants between encryptions * Support for arbitrary size encryption * Address some Verilator warnings * Convert vector direction * */ // ROUNDs `define ROUND1 2'b00 `define ROUND2 2'b01 `define ROUND3 2'b10 `define ROUND4 2'b11 // T_i = 4294967296*abs(sin(i)) `define T_1 32'hd76aa478 `define T_2 32'he8c7b756 `define T_3 32'h242070db `define T_4 32'hc1bdceee `define T_5 32'hf57c0faf `define T_6 32'h4787c62a `define T_7 32'ha8304613 `define T_8 32'hfd469501 `define T_9 32'h698098d8 `define T_10 32'h8b44f7af `define T_11 32'hffff5bb1 `define T_12 32'h895cd7be `define T_13 32'h6b901122 `define T_14 32'hfd987193 `define T_15 32'ha679438e `define T_16 32'h49b40821 `define T_17 32'hf61e2562 `define T_18 32'hc040b340 `define T_19 32'h265e5a51 `define T_20 32'he9b6c7aa `define T_21 32'hd62f105d `define T_22 32'h2441453 `define T_23 32'hd8a1e681 `define T_24 32'he7d3fbc8 `define T_25 32'h21e1cde6 `define T_26 32'hc33707d6 `define T_27 32'hf4d50d87 `define T_28 32'h455a14ed `define T_29 32'ha9e3e905 `define T_30 32'hfcefa3f8 `define T_31 32'h676f02d9 `define T_32 32'h8d2a4c8a `define T_33 32'hfffa3942 `define T_34 32'h8771f681 `define T_35 32'h6d9d6122 `define T_36 32'hfde5380c `define T_37 32'ha4beea44 `define T_38 32'h4bdecfa9 `define T_39 32'hf6bb4b60 `define T_40 32'hbebfbc70 `define T_41 32'h289b7ec6 `define T_42 32'heaa127fa `define T_43 32'hd4ef3085 `define T_44 32'h4881d05 `define T_45 32'hd9d4d039 `define T_46 32'he6db99e5 `define T_47 32'h1fa27cf8 `define T_48 32'hc4ac5665 `define T_49 32'hf4292244 `define T_50 32'h432aff97 `define T_51 32'hab9423a7 `define T_52 32'hfc93a039 `define T_53 32'h655b59c3 `define T_54 32'h8f0ccc92 `define T_55 32'hffeff47d `define T_56 32'h85845dd1 `define T_57 32'h6fa87e4f `define T_58 32'hfe2ce6e0 `define T_59 32'ha3014314 `define T_60 32'h4e0811a1 `define T_61 32'hf7537e82 `define T_62 32'hbd3af235 `define T_63 32'h2ad7d2bb `define T_64 32'heb86d391 /* verilator lint_off UNOPTFLAT */ module pancham ( clk , rst , msg_padded , msg_in_valid , msg_output , msg_out_valid , ready ); //-------------------------------- // // Input/Output declarations // //-------------------------------- input clk; // input clock input rst; // global rst input [511:0] msg_padded; // input message, already padded input msg_in_valid; // input message is valid, active high output [127:0] msg_output; // output message, always 128 bit wide output msg_out_valid; // if asserted, output message is valid output ready; // the core is ready for an input message //-------------------------------- // // Variable declarations // //-------------------------------- // inputs wire clk; wire rst; wire [511:0] msg_padded; wire msg_in_valid; // output wire [127:0] msg_output; reg msg_out_valid; wire ready; // scratch pads reg [1:0] round; reg [31:0] a; reg [31:0] A; reg [31:0] AA; reg [31:0] next_A; reg [31:0] b; reg [31:0] B; reg [31:0] BB; reg [31:0] next_B; reg [31:0] c; reg [31:0] C; reg [31:0] CC; reg [31:0] next_C; reg [31:0] d; reg [31:0] D; reg [31:0] DD; reg [31:0] next_D; reg [31:0] m; reg [31:0] s; reg [31:0] t; reg [3:0] phase; // Counter to determine 16 phases within each round. wire [31:0] next_a; reg [7:0] current_state; reg [7:0] next_state; reg [8*11:1] ascii_state; //-------------------------------- // // Parameter definitions // //-------------------------------- parameter SALT_A = 32'h67452301; parameter SALT_B = 32'hefcdab89; parameter SALT_C = 32'h98badcfe; parameter SALT_D = 32'h10325476; parameter ONE = 72'h1; parameter IDLE_BIT = 0; parameter IDLE = ONE << IDLE_BIT; parameter ROUND1_BIT = 1; parameter ROUND1 = ONE << ROUND1_BIT; parameter ROUND2_BIT = 2; parameter ROUND2 = ONE << ROUND2_BIT; parameter ROUND3_BIT = 3; parameter ROUND3 = ONE << ROUND3_BIT; parameter ROUND4_BIT = 4; parameter ROUND4 = ONE << ROUND4_BIT; parameter FINISH_OFF_BIT = 5; parameter FINISH_OFF = ONE << FINISH_OFF_BIT; parameter TURN_ARND_BIT = 6; parameter TURN_ARND = ONE << TURN_ARND_BIT; //-------------------------------- // // Submodule instantiation // //-------------------------------- pancham_round ROUND ( .a (a ) , .b (b ) , .c (c ) , .d (d ) , .m (m ) , .s (s ) , .t (t ) , .round (round) , .next_a (next_a) ); wire [31:0] m0 = msg_padded[31:0]; wire [31:0] m1 = msg_padded[63:32]; wire [31:0] m2 = msg_padded[95:64]; wire [31:0] m3 = msg_padded[127:96]; wire [31:0] m4 = msg_padded[159:128]; wire [31:0] m5 = msg_padded[191:160]; wire [31:0] m6 = msg_padded[223:192]; wire [31:0] m7 = msg_padded[255:224]; wire [31:0] m8 = msg_padded[287:256]; wire [31:0] m9 = msg_padded[319:288]; wire [31:0] m10 = msg_padded[351:320]; wire [31:0] m11 = msg_padded[383:352]; wire [31:0] m12 = msg_padded[415:384]; wire [31:0] m13 = msg_padded[447:416]; wire [31:0] m14 = msg_padded[479:448]; wire [31:0] m15 = msg_padded[511:480]; //-------------------------------- // // Actual code starts here // //-------------------------------- always @(current_state or msg_in_valid or A or B or C or D or phase or msg_padded or next_a or AA or BB or CC or DD ) begin // { round = `ROUND1; next_A = A; next_B = B; next_C = C; next_D = D; a = 32'h0; b = 32'h0; c = 32'h0; d = 32'h0; m = 32'h0; s = 32'h0; t = 32'h0; next_state = current_state; case (1'b1) // synopsys full_case parallel_case current_state[IDLE_BIT]: begin // { // synopsys translate_off ascii_state = "IDLE"; // synopsys translate_on if (msg_in_valid) next_state = ROUND1[7:0]; end // } //---------------------------------------------------------------- //--------------------------- ROUND 1 ---------------------------- //---------------------------------------------------------------- current_state[ROUND1_BIT]: begin // { // synopsys translate_off ascii_state = "ROUND1"; // synopsys translate_on round = `ROUND1; case (phase) 4'b0000: begin a=A; b=B; c=C; d=D; m=m0; s=32'd07; t= `T_1; next_A=next_a; end 4'b0001: begin a=D; b=A; c=B; d=C; m=m1; s=32'd12; t= `T_2; next_D=next_a; end 4'b0010: begin a=C; b=D; c=A; d=B; m=m2; s=32'd17; t= `T_3; next_C=next_a; end 4'b0011: begin a=B; b=C; c=D; d=A; m=m3; s=32'd22; t= `T_4; next_B=next_a; end 4'b0100: begin a=A; b=B; c=C; d=D; m=m4; s=32'd07; t= `T_5; next_A=next_a; end 4'b0101: begin a=D; b=A; c=B; d=C; m=m5; s=32'd12; t= `T_6; next_D=next_a; end 4'b0110: begin a=C; b=D; c=A; d=B; m=m6; s=32'd17; t= `T_7; next_C=next_a; end 4'b0111: begin a=B; b=C; c=D; d=A; m=m7; s=32'd22; t= `T_8; next_B=next_a; end 4'b1000: begin a=A; b=B; c=C; d=D; m=m8; s=32'd07; t= `T_9; next_A=next_a; end 4'b1001: begin a=D; b=A; c=B; d=C; m=m9; s=32'd12; t=`T_10; next_D=next_a; end 4'b1010: begin a=C; b=D; c=A; d=B; m=m10; s=32'd17; t=`T_11; next_C=next_a; end 4'b1011: begin a=B; b=C; c=D; d=A; m=m11; s=32'd22; t=`T_12; next_B=next_a; end 4'b1100: begin a=A; b=B; c=C; d=D; m=m12; s=32'd7; t=`T_13; next_A=next_a; end 4'b1101: begin a=D; b=A; c=B; d=C; m=m13; s=32'd12; t=`T_14; next_D=next_a; end 4'b1110: begin a=C; b=D; c=A; d=B; m=m14; s=32'd17; t=`T_15; next_C=next_a; end 4'b1111: begin a=B; b=C; c=D; d=A; m=m15; s=32'd22; t=`T_16; next_B=next_a; end endcase if (phase == 4'b1111) next_state = ROUND2[7:0]; end // } //---------------------------------------------------------------- //--------------------------- ROUND 2 ---------------------------- //---------------------------------------------------------------- current_state[ROUND2_BIT]: begin // { // synopsys translate_off ascii_state = "ROUND2"; // synopsys translate_on round = `ROUND2; case (phase) 4'b0000: begin a=A; b=B; c=C; d=D; m=m1; s=32'd05; t=`T_17; next_A=next_a; end 4'b0001: begin a=D; b=A; c=B; d=C; m=m6; s=32'd09; t=`T_18; next_D=next_a; end 4'b0010: begin a=C; b=D; c=A; d=B; m=m11; s=32'd14; t=`T_19; next_C=next_a; end 4'b0011: begin a=B; b=C; c=D; d=A; m=m0; s=32'd20; t=`T_20; next_B=next_a; end 4'b0100: begin a=A; b=B; c=C; d=D; m=m5; s=32'd05; t=`T_21; next_A=next_a; end 4'b0101: begin a=D; b=A; c=B; d=C; m=m10; s=32'd09; t=`T_22; next_D=next_a; end 4'b0110: begin a=C; b=D; c=A; d=B; m=m15; s=32'd14; t=`T_23; next_C=next_a; end 4'b0111: begin a=B; b=C; c=D; d=A; m=m4; s=32'd20; t=`T_24; next_B=next_a; end 4'b1000: begin a=A; b=B; c=C; d=D; m=m9; s=32'd05; t=`T_25; next_A=next_a; end 4'b1001: begin a=D; b=A; c=B; d=C; m=m14; s=32'd9; t=`T_26; next_D=next_a; end 4'b1010: begin a=C; b=D; c=A; d=B; m=m3; s=32'd14; t=`T_27; next_C=next_a; end 4'b1011: begin a=B; b=C; c=D; d=A; m=m8; s=32'd20; t=`T_28; next_B=next_a; end 4'b1100: begin a=A; b=B; c=C; d=D; m=m13; s=32'd05; t=`T_29; next_A=next_a; end 4'b1101: begin a=D; b=A; c=B; d=C; m=m2; s=32'd09; t=`T_30; next_D=next_a; end 4'b1110: begin a=C; b=D; c=A; d=B; m=m7; s=32'd14; t=`T_31; next_C=next_a; end 4'b1111: begin a=B; b=C; c=D; d=A; m=m12; s=32'd20; t=`T_32; next_B=next_a; end endcase if (phase == 4'b1111) next_state = ROUND3[7:0]; end // } //---------------------------------------------------------------- //--------------------------- ROUND 3 ---------------------------- //---------------------------------------------------------------- current_state[ROUND3_BIT]: begin // { // synopsys translate_off ascii_state = "ROUND3"; // synopsys translate_on round = `ROUND3; case (phase) 4'b0000: begin a=A; b=B; c=C; d=D; m=m5; s=32'd04; t=`T_33; next_A=next_a; end 4'b0001: begin a=D; b=A; c=B; d=C; m=m8; s=32'd11; t=`T_34; next_D=next_a; end 4'b0010: begin a=C; b=D; c=A; d=B; m=m11; s=32'd16; t=`T_35; next_C=next_a; end 4'b0011: begin a=B; b=C; c=D; d=A; m=m14; s=32'd23; t=`T_36; next_B=next_a; end 4'b0100: begin a=A; b=B; c=C; d=D; m=m1; s=32'd04; t=`T_37; next_A=next_a; end 4'b0101: begin a=D; b=A; c=B; d=C; m=m4; s=32'd11; t=`T_38; next_D=next_a; end 4'b0110: begin a=C; b=D; c=A; d=B; m=m7; s=32'd16; t=`T_39; next_C=next_a; end 4'b0111: begin a=B; b=C; c=D; d=A; m=m10; s=32'd23; t=`T_40; next_B=next_a; end 4'b1000: begin a=A; b=B; c=C; d=D; m=m13; s=32'd04; t=`T_41; next_A=next_a; end 4'b1001: begin a=D; b=A; c=B; d=C; m=m0; s=32'd11; t=`T_42; next_D=next_a; end 4'b1010: begin a=C; b=D; c=A; d=B; m=m3; s=32'd16; t=`T_43; next_C=next_a; end 4'b1011: begin a=B; b=C; c=D; d=A; m=m6; s=32'd23; t=`T_44; next_B=next_a; end 4'b1100: begin a=A; b=B; c=C; d=D; m=m9; s=32'd04; t=`T_45; next_A=next_a; end 4'b1101: begin a=D; b=A; c=B; d=C; m=m12; s=32'd11; t=`T_46; next_D=next_a; end 4'b1110: begin a=C; b=D; c=A; d=B; m=m15; s=32'd16; t=`T_47; next_C=next_a; end 4'b1111: begin a=B; b=C; c=D; d=A; m=m2; s=32'd23; t=`T_48; next_B=next_a; end endcase if (phase == 4'b1111) next_state = ROUND4[7:0]; end // } //---------------------------------------------------------------- //--------------------------- ROUND 4 ---------------------------- //---------------------------------------------------------------- current_state[ROUND4_BIT]: begin // { // synopsys translate_off ascii_state = "ROUND4"; // synopsys translate_on round = `ROUND4; case (phase) 4'b0000: begin a=A; b=B; c=C; d=D; m=m0; s=32'd06; t=`T_49; next_A=next_a; end 4'b0001: begin a=D; b=A; c=B; d=C; m=m7; s=32'd10; t=`T_50; next_D=next_a; end 4'b0010: begin a=C; b=D; c=A; d=B; m=m14; s=32'd15; t=`T_51; next_C=next_a; end 4'b0011: begin a=B; b=C; c=D; d=A; m=m5; s=32'd21; t=`T_52; next_B=next_a; end 4'b0100: begin a=A; b=B; c=C; d=D; m=m12; s=32'd06; t=`T_53; next_A=next_a; end 4'b0101: begin a=D; b=A; c=B; d=C; m=m3; s=32'd10; t=`T_54; next_D=next_a; end 4'b0110: begin a=C; b=D; c=A; d=B; m=m10; s=32'd15; t=`T_55; next_C=next_a; end 4'b0111: begin a=B; b=C; c=D; d=A; m=m1; s=32'd21; t=`T_56; next_B=next_a; end 4'b1000: begin a=A; b=B; c=C; d=D; m=m8; s=32'd06; t=`T_57; next_A=next_a; end 4'b1001: begin a=D; b=A; c=B; d=C; m=m15; s=32'd10; t=`T_58; next_D=next_a; end 4'b1010: begin a=C; b=D; c=A; d=B; m=m6; s=32'd15; t=`T_59; next_C=next_a; end 4'b1011: begin a=B; b=C; c=D; d=A; m=m13; s=32'd21; t=`T_60; next_B=next_a; end 4'b1100: begin a=A; b=B; c=C; d=D; m=m4; s=32'd06; t=`T_61; next_A=next_a; end 4'b1101: begin a=D; b=A; c=B; d=C; m=m11; s=32'd10; t=`T_62; next_D=next_a; end 4'b1110: begin a=C; b=D; c=A; d=B; m=m2; s=32'd15; t=`T_63; next_C=next_a; end 4'b1111: begin a=B; b=C; c=D; d=A; m=m9; s=32'd21; t=`T_64; next_B=next_a; end endcase if (phase == 4'b1111) next_state = FINISH_OFF[7:0]; end // } //---------------------------------------------------------------- current_state[FINISH_OFF_BIT]: begin // { // synopsys translate_off ascii_state = "FINISH_OFF"; // synopsys translate_on next_A = AA + A; next_B = BB + B; next_C = CC + C; next_D = DD + D; next_state = TURN_ARND[7:0]; end // } //---------------------------------------------------------------- // One cycle for making the system to come to reset state current_state[TURN_ARND_BIT]: begin // { // synopsys translate_off ascii_state = "TURN_ARND"; // synopsys translate_on next_state = IDLE[7:0]; end // } endcase end // } //-------------------------------- // // Flops and other combinatorial // logic definition // //-------------------------------- // Outputs assign msg_output = {{A[7:0], A[15:8], A[23:16], A[31:24]} ,{B[7:0], B[15:8], B[23:16], B[31:24]} ,{C[7:0], C[15:8], C[23:16], C[31:24]} ,{D[7:0], D[15:8], D[23:16], D[31:24]}}; always @(posedge clk) msg_out_valid <= current_state[FINISH_OFF_BIT]; assign ready = current_state[IDLE_BIT]; // Internal scratch pads always @(posedge clk) if (next_state[ROUND1_BIT] && current_state[IDLE_BIT]) begin // { AA <= A; BB <= B; CC <= C; DD <= D; end // } // Initialize A, B, C and D and then compute them always @(posedge clk) if (rst ) begin // { A <= SALT_A; B <= SALT_B; C <= SALT_C; D <= SALT_D; end // } else begin // { A <= next_A; B <= next_B; C <= next_C; D <= next_D; end // } // Determine one of the 16 phases within each round always @(posedge clk) if (rst) phase <= 4'b0; else if (next_state[ROUND1_BIT] && current_state[IDLE_BIT]) phase <= 4'b0; else phase <= phase + 4'b1; // Assign current_state based on rst and the next_state always @(posedge clk) if (rst) current_state <= IDLE[7:0]; else current_state <= next_state; endmodule
/***************************************************************** Pancham is an MD5 compliant IP core for cryptographic applicati -ons. Copyright (C) 2003 Swapnajit Mittra, Project VeriPage (Contact email: verilog_tutorial at hotmail.com Website : http://www.angelfire.com/ca/verilog) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc. 59 Temple Place, Suite 330 Boston, MA 02111-1307 USA ******************************************************************/ /* * pancham_round performs the rounds 1-4 of the MD5 algorithm * described in RFC1321 for a 128-bit long input message. * * Inputs: [abcd m[k] s abs(sin(2*pi*t/64))] as described * in RFC1321.Also the round number (1-4). * * Outputs: the modified 'a' value as describes in RFC1321 * on the left hand side of the round #n equation. * */ `define ROUND1 2'b00 `define ROUND2 2'b01 `define ROUND3 2'b10 `define ROUND4 2'b11 module pancham_round ( a , b , c , d , m , s , t , round , next_a ); input [31:0] a; input [31:0] b; input [31:0] c; input [31:0] d; input [31:0] m; // Note that for a 128-bit long input message, X[k] = M[k] = m input [31:0] s; input [31:0] t; // t-th sample of abs(sin(i)), i = 1, 2, ..., 64 input [1:0] round; // round number (1-4). output [31:0] next_a; wire [31:0] a; // wire [31:0] b; wire [31:0] c; wire [31:0] d; wire [31:0] m; wire [31:0] s; wire [31:0] t; wire [1:0] round; reg [31:0] next_a; reg [31:0] add_result; reg [31:0] rotate_result1; reg [31:0] rotate_result2; always @(a or b or c or d or m or s or t or round) begin // { case (round) `ROUND1: begin // { add_result = (a + F(b,c,d) + m + t); rotate_result1 = add_result << s; rotate_result2 = add_result >> (32-s); next_a = b + (rotate_result1 | rotate_result2); end // } `ROUND2: begin // { add_result = (a + G(b,c,d) + m + t); rotate_result1 = add_result << s; rotate_result2 = add_result >> (32-s); next_a = b + (rotate_result1 | rotate_result2); end // } `ROUND3: begin // { add_result = (a + H(b,c,d) + m + t); rotate_result1 = add_result << s; rotate_result2 = add_result >> (32-s); next_a = b + (rotate_result1 | rotate_result2); end // } `ROUND4: begin // { add_result = (a + I(b,c,d) + m + t); rotate_result1 = add_result << s; rotate_result2 = add_result >> (32-s); next_a = b + (rotate_result1 | rotate_result2); end // } endcase end // } //-------------------------------- // // Function declarations // //-------------------------------- // Step 4 functions F, G, H and I function [31:0] F; input [31:0] x, y, z; begin // { F = (x&y)|((~x)&z); end // } endfunction // } function [31:0] G; input [31:0] x, y, z; begin // { G = (x&z)|(y&(~z)); end // } endfunction function [31:0] H; input [31:0] x, y, z; begin // { H = (x^y^z); end // } endfunction function [31:0] I; input [31:0] x, y, z; begin // { I = (y^(x|(~z))); end // } endfunction endmodule
/* * PicoRV32 -- A Small RISC-V (RV32I) Processor Core * * Copyright (C) 2015 Clifford Wolf <clifford@clifford.at> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ `timescale 1 ns / 1 ps // `default_nettype none // `define DEBUGNETS // `define DEBUGREGS // `define DEBUGASM // `define DEBUG `ifdef DEBUG `define debug(debug_command) debug_command `else `define debug(debug_command) `endif `ifdef FORMAL `define FORMAL_KEEP (* keep *) `define assert(assert_expr) assert(assert_expr) `else `ifdef DEBUGNETS `define FORMAL_KEEP (* keep *) `else `define FORMAL_KEEP `endif `define assert(assert_expr) empty_statement `endif // uncomment this for register file in extra module // `define PICORV32_REGS picorv32_regs // this macro can be used to check if the verilog files in your // design are read in the correct order. `define PICORV32_V /*************************************************************** * picorv32 ***************************************************************/ module picorv32 #( parameter [ 0:0] ENABLE_COUNTERS = 1, parameter [ 0:0] ENABLE_COUNTERS64 = 1, parameter [ 0:0] ENABLE_REGS_16_31 = 1, parameter [ 0:0] ENABLE_REGS_DUALPORT = 1, parameter [ 0:0] LATCHED_MEM_RDATA = 0, parameter [ 0:0] TWO_STAGE_SHIFT = 1, parameter [ 0:0] BARREL_SHIFTER = 0, parameter [ 0:0] TWO_CYCLE_COMPARE = 0, parameter [ 0:0] TWO_CYCLE_ALU = 0, parameter [ 0:0] COMPRESSED_ISA = 0, parameter [ 0:0] CATCH_MISALIGN = 1, parameter [ 0:0] CATCH_ILLINSN = 1, parameter [ 0:0] ENABLE_PCPI = 0, parameter [ 0:0] ENABLE_MUL = 0, parameter [ 0:0] ENABLE_FAST_MUL = 0, parameter [ 0:0] ENABLE_DIV = 0, parameter [ 0:0] ENABLE_IRQ = 0, parameter [ 0:0] ENABLE_IRQ_QREGS = 1, parameter [ 0:0] ENABLE_IRQ_TIMER = 1, parameter [ 0:0] ENABLE_TRACE = 0, parameter [ 0:0] REGS_INIT_ZERO = 0, parameter [31:0] MASKED_IRQ = 32'h 0000_0000, parameter [31:0] LATCHED_IRQ = 32'h ffff_ffff, parameter [31:0] PROGADDR_RESET = 32'h 0000_0000, parameter [31:0] PROGADDR_IRQ = 32'h 0000_0010, parameter [31:0] STACKADDR = 32'h ffff_ffff ) ( input clk, resetn, output reg trap, output reg mem_valid, output reg mem_instr, input mem_ready, output reg [31:0] mem_addr, output reg [31:0] mem_wdata, output reg [ 3:0] mem_wstrb, input [31:0] mem_rdata, // Look-Ahead Interface output mem_la_read, output mem_la_write, output [31:0] mem_la_addr, output reg [31:0] mem_la_wdata, output reg [ 3:0] mem_la_wstrb, // Pico Co-Processor Interface (PCPI) output reg pcpi_valid, output reg [31:0] pcpi_insn, output [31:0] pcpi_rs1, output [31:0] pcpi_rs2, input pcpi_wr, input [31:0] pcpi_rd, input pcpi_wait, input pcpi_ready, // IRQ Interface input [31:0] irq, output reg [31:0] eoi, `ifdef RISCV_FORMAL output reg rvfi_valid, output reg [63:0] rvfi_order, output reg [31:0] rvfi_insn, output reg rvfi_trap, output reg rvfi_halt, output reg rvfi_intr, output reg [ 1:0] rvfi_mode, output reg [ 4:0] rvfi_rs1_addr, output reg [ 4:0] rvfi_rs2_addr, output reg [31:0] rvfi_rs1_rdata, output reg [31:0] rvfi_rs2_rdata, output reg [ 4:0] rvfi_rd_addr, output reg [31:0] rvfi_rd_wdata, output reg [31:0] rvfi_pc_rdata, output reg [31:0] rvfi_pc_wdata, output reg [31:0] rvfi_mem_addr, output reg [ 3:0] rvfi_mem_rmask, output reg [ 3:0] rvfi_mem_wmask, output reg [31:0] rvfi_mem_rdata, output reg [31:0] rvfi_mem_wdata, `endif // Trace Interface output reg trace_valid, output reg [35:0] trace_data ); localparam integer irq_timer = 0; localparam integer irq_ebreak = 1; localparam integer irq_buserror = 2; localparam integer irqregs_offset = ENABLE_REGS_16_31 ? 32 : 16; localparam integer regfile_size = (ENABLE_REGS_16_31 ? 32 : 16) + 4*ENABLE_IRQ*ENABLE_IRQ_QREGS; localparam integer regindex_bits = (ENABLE_REGS_16_31 ? 5 : 4) + ENABLE_IRQ*ENABLE_IRQ_QREGS; localparam WITH_PCPI = ENABLE_PCPI || ENABLE_MUL || ENABLE_FAST_MUL || ENABLE_DIV; localparam [35:0] TRACE_BRANCH = {4'b 0001, 32'b 0}; localparam [35:0] TRACE_ADDR = {4'b 0010, 32'b 0}; localparam [35:0] TRACE_IRQ = {4'b 1000, 32'b 0}; reg [63:0] count_cycle, count_instr; reg [31:0] reg_pc, reg_next_pc, reg_op1, reg_op2, reg_out; reg [4:0] reg_sh; reg [31:0] next_insn_opcode; reg [31:0] dbg_insn_opcode; reg [31:0] dbg_insn_addr; wire dbg_mem_valid = mem_valid; wire dbg_mem_instr = mem_instr; wire dbg_mem_ready = mem_ready; wire [31:0] dbg_mem_addr = mem_addr; wire [31:0] dbg_mem_wdata = mem_wdata; wire [ 3:0] dbg_mem_wstrb = mem_wstrb; wire [31:0] dbg_mem_rdata = mem_rdata; assign pcpi_rs1 = reg_op1; assign pcpi_rs2 = reg_op2; wire [31:0] next_pc; reg irq_delay; reg irq_active; reg [31:0] irq_mask; reg [31:0] irq_pending; reg [31:0] timer; `ifndef PICORV32_REGS reg [31:0] cpuregs [0:regfile_size-1]; integer i; initial begin if (REGS_INIT_ZERO) begin for (i = 0; i < regfile_size; i = i+1) cpuregs[i] = 0; end end `endif task empty_statement; // This task is used by the `assert directive in non-formal mode to // avoid empty statement (which are unsupported by plain Verilog syntax). begin end endtask `ifdef DEBUGREGS wire [31:0] dbg_reg_x0 = 0; wire [31:0] dbg_reg_x1 = cpuregs[1]; wire [31:0] dbg_reg_x2 = cpuregs[2]; wire [31:0] dbg_reg_x3 = cpuregs[3]; wire [31:0] dbg_reg_x4 = cpuregs[4]; wire [31:0] dbg_reg_x5 = cpuregs[5]; wire [31:0] dbg_reg_x6 = cpuregs[6]; wire [31:0] dbg_reg_x7 = cpuregs[7]; wire [31:0] dbg_reg_x8 = cpuregs[8]; wire [31:0] dbg_reg_x9 = cpuregs[9]; wire [31:0] dbg_reg_x10 = cpuregs[10]; wire [31:0] dbg_reg_x11 = cpuregs[11]; wire [31:0] dbg_reg_x12 = cpuregs[12]; wire [31:0] dbg_reg_x13 = cpuregs[13]; wire [31:0] dbg_reg_x14 = cpuregs[14]; wire [31:0] dbg_reg_x15 = cpuregs[15]; wire [31:0] dbg_reg_x16 = cpuregs[16]; wire [31:0] dbg_reg_x17 = cpuregs[17]; wire [31:0] dbg_reg_x18 = cpuregs[18]; wire [31:0] dbg_reg_x19 = cpuregs[19]; wire [31:0] dbg_reg_x20 = cpuregs[20]; wire [31:0] dbg_reg_x21 = cpuregs[21]; wire [31:0] dbg_reg_x22 = cpuregs[22]; wire [31:0] dbg_reg_x23 = cpuregs[23]; wire [31:0] dbg_reg_x24 = cpuregs[24]; wire [31:0] dbg_reg_x25 = cpuregs[25]; wire [31:0] dbg_reg_x26 = cpuregs[26]; wire [31:0] dbg_reg_x27 = cpuregs[27]; wire [31:0] dbg_reg_x28 = cpuregs[28]; wire [31:0] dbg_reg_x29 = cpuregs[29]; wire [31:0] dbg_reg_x30 = cpuregs[30]; wire [31:0] dbg_reg_x31 = cpuregs[31]; `endif // Internal PCPI Cores wire pcpi_mul_wr; wire [31:0] pcpi_mul_rd; wire pcpi_mul_wait; wire pcpi_mul_ready; wire pcpi_div_wr; wire [31:0] pcpi_div_rd; wire pcpi_div_wait; wire pcpi_div_ready; reg pcpi_int_wr; reg [31:0] pcpi_int_rd; reg pcpi_int_wait; reg pcpi_int_ready; generate if (ENABLE_FAST_MUL) begin picorv32_pcpi_fast_mul pcpi_mul ( .clk (clk ), .resetn (resetn ), .pcpi_valid(pcpi_valid ), .pcpi_insn (pcpi_insn ), .pcpi_rs1 (pcpi_rs1 ), .pcpi_rs2 (pcpi_rs2 ), .pcpi_wr (pcpi_mul_wr ), .pcpi_rd (pcpi_mul_rd ), .pcpi_wait (pcpi_mul_wait ), .pcpi_ready(pcpi_mul_ready ) ); end else if (ENABLE_MUL) begin picorv32_pcpi_mul pcpi_mul ( .clk (clk ), .resetn (resetn ), .pcpi_valid(pcpi_valid ), .pcpi_insn (pcpi_insn ), .pcpi_rs1 (pcpi_rs1 ), .pcpi_rs2 (pcpi_rs2 ), .pcpi_wr (pcpi_mul_wr ), .pcpi_rd (pcpi_mul_rd ), .pcpi_wait (pcpi_mul_wait ), .pcpi_ready(pcpi_mul_ready ) ); end else begin assign pcpi_mul_wr = 0; assign pcpi_mul_rd = 32'bx; assign pcpi_mul_wait = 0; assign pcpi_mul_ready = 0; end endgenerate generate if (ENABLE_DIV) begin picorv32_pcpi_div pcpi_div ( .clk (clk ), .resetn (resetn ), .pcpi_valid(pcpi_valid ), .pcpi_insn (pcpi_insn ), .pcpi_rs1 (pcpi_rs1 ), .pcpi_rs2 (pcpi_rs2 ), .pcpi_wr (pcpi_div_wr ), .pcpi_rd (pcpi_div_rd ), .pcpi_wait (pcpi_div_wait ), .pcpi_ready(pcpi_div_ready ) ); end else begin assign pcpi_div_wr = 0; assign pcpi_div_rd = 32'bx; assign pcpi_div_wait = 0; assign pcpi_div_ready = 0; end endgenerate always @* begin pcpi_int_wr = 0; pcpi_int_rd = 32'bx; pcpi_int_wait = |{ENABLE_PCPI && pcpi_wait, (ENABLE_MUL || ENABLE_FAST_MUL) && pcpi_mul_wait, ENABLE_DIV && pcpi_div_wait}; pcpi_int_ready = |{ENABLE_PCPI && pcpi_ready, (ENABLE_MUL || ENABLE_FAST_MUL) && pcpi_mul_ready, ENABLE_DIV && pcpi_div_ready}; (* parallel_case *) case (1'b1) ENABLE_PCPI && pcpi_ready: begin pcpi_int_wr = ENABLE_PCPI ? pcpi_wr : 0; pcpi_int_rd = ENABLE_PCPI ? pcpi_rd : 0; end (ENABLE_MUL || ENABLE_FAST_MUL) && pcpi_mul_ready: begin pcpi_int_wr = pcpi_mul_wr; pcpi_int_rd = pcpi_mul_rd; end ENABLE_DIV && pcpi_div_ready: begin pcpi_int_wr = pcpi_div_wr; pcpi_int_rd = pcpi_div_rd; end endcase end // Memory Interface reg [1:0] mem_state; reg [1:0] mem_wordsize; reg [31:0] mem_rdata_word; reg [31:0] mem_rdata_q; reg mem_do_prefetch; reg mem_do_rinst; reg mem_do_rdata; reg mem_do_wdata; wire mem_xfer; reg mem_la_secondword, mem_la_firstword_reg, last_mem_valid; wire mem_la_firstword = COMPRESSED_ISA && (mem_do_prefetch || mem_do_rinst) && next_pc[1] && !mem_la_secondword; wire mem_la_firstword_xfer = COMPRESSED_ISA && mem_xfer && (!last_mem_valid ? mem_la_firstword : mem_la_firstword_reg); reg prefetched_high_word; reg clear_prefetched_high_word; reg [15:0] mem_16bit_buffer; wire [31:0] mem_rdata_latched_noshuffle; wire [31:0] mem_rdata_latched; wire mem_la_use_prefetched_high_word = COMPRESSED_ISA && mem_la_firstword && prefetched_high_word && !clear_prefetched_high_word; assign mem_xfer = (mem_valid && mem_ready) || (mem_la_use_prefetched_high_word && mem_do_rinst); wire mem_busy = |{mem_do_prefetch, mem_do_rinst, mem_do_rdata, mem_do_wdata}; wire mem_done = resetn && ((mem_xfer && |mem_state && (mem_do_rinst || mem_do_rdata || mem_do_wdata)) || (&mem_state && mem_do_rinst)) && (!mem_la_firstword || (~&mem_rdata_latched[1:0] && mem_xfer)); assign mem_la_write = resetn && !mem_state && mem_do_wdata; assign mem_la_read = resetn && ((!mem_la_use_prefetched_high_word && !mem_state && (mem_do_rinst || mem_do_prefetch || mem_do_rdata)) || (COMPRESSED_ISA && mem_xfer && (!last_mem_valid ? mem_la_firstword : mem_la_firstword_reg) && !mem_la_secondword && &mem_rdata_latched[1:0])); assign mem_la_addr = (mem_do_prefetch || mem_do_rinst) ? {next_pc[31:2] + mem_la_firstword_xfer, 2'b00} : {reg_op1[31:2], 2'b00}; assign mem_rdata_latched_noshuffle = (mem_xfer || LATCHED_MEM_RDATA) ? mem_rdata : mem_rdata_q; assign mem_rdata_latched = COMPRESSED_ISA && mem_la_use_prefetched_high_word ? {16'bx, mem_16bit_buffer} : COMPRESSED_ISA && mem_la_secondword ? {mem_rdata_latched_noshuffle[15:0], mem_16bit_buffer} : COMPRESSED_ISA && mem_la_firstword ? {16'bx, mem_rdata_latched_noshuffle[31:16]} : mem_rdata_latched_noshuffle; always @(posedge clk) begin if (!resetn) begin mem_la_firstword_reg <= 0; last_mem_valid <= 0; end else begin if (!last_mem_valid) mem_la_firstword_reg <= mem_la_firstword; last_mem_valid <= mem_valid && !mem_ready; end end always @* begin (* full_case *) case (mem_wordsize) 0: begin mem_la_wdata = reg_op2; mem_la_wstrb = 4'b1111; mem_rdata_word = mem_rdata; end 1: begin mem_la_wdata = {2{reg_op2[15:0]}}; mem_la_wstrb = reg_op1[1] ? 4'b1100 : 4'b0011; case (reg_op1[1]) 1'b0: mem_rdata_word = {16'b0, mem_rdata[15: 0]}; 1'b1: mem_rdata_word = {16'b0, mem_rdata[31:16]}; endcase end 2: begin mem_la_wdata = {4{reg_op2[7:0]}}; mem_la_wstrb = 4'b0001 << reg_op1[1:0]; case (reg_op1[1:0]) 2'b00: mem_rdata_word = {24'b0, mem_rdata[ 7: 0]}; 2'b01: mem_rdata_word = {24'b0, mem_rdata[15: 8]}; 2'b10: mem_rdata_word = {24'b0, mem_rdata[23:16]}; 2'b11: mem_rdata_word = {24'b0, mem_rdata[31:24]}; endcase end endcase end always @(posedge clk) begin if (mem_xfer) begin mem_rdata_q <= COMPRESSED_ISA ? mem_rdata_latched : mem_rdata; next_insn_opcode <= COMPRESSED_ISA ? mem_rdata_latched : mem_rdata; end if (COMPRESSED_ISA && mem_done && (mem_do_prefetch || mem_do_rinst)) begin case (mem_rdata_latched[1:0]) 2'b00: begin // Quadrant 0 case (mem_rdata_latched[15:13]) 3'b000: begin // C.ADDI4SPN mem_rdata_q[14:12] <= 3'b000; mem_rdata_q[31:20] <= {2'b0, mem_rdata_latched[10:7], mem_rdata_latched[12:11], mem_rdata_latched[5], mem_rdata_latched[6], 2'b00}; end 3'b010: begin // C.LW mem_rdata_q[31:20] <= {5'b0, mem_rdata_latched[5], mem_rdata_latched[12:10], mem_rdata_latched[6], 2'b00}; mem_rdata_q[14:12] <= 3'b 010; end 3'b 110: begin // C.SW {mem_rdata_q[31:25], mem_rdata_q[11:7]} <= {5'b0, mem_rdata_latched[5], mem_rdata_latched[12:10], mem_rdata_latched[6], 2'b00}; mem_rdata_q[14:12] <= 3'b 010; end endcase end 2'b01: begin // Quadrant 1 case (mem_rdata_latched[15:13]) 3'b 000: begin // C.ADDI mem_rdata_q[14:12] <= 3'b000; mem_rdata_q[31:20] <= $signed({mem_rdata_latched[12], mem_rdata_latched[6:2]}); end 3'b 010: begin // C.LI mem_rdata_q[14:12] <= 3'b000; mem_rdata_q[31:20] <= $signed({mem_rdata_latched[12], mem_rdata_latched[6:2]}); end 3'b 011: begin if (mem_rdata_latched[11:7] == 2) begin // C.ADDI16SP mem_rdata_q[14:12] <= 3'b000; mem_rdata_q[31:20] <= $signed({mem_rdata_latched[12], mem_rdata_latched[4:3], mem_rdata_latched[5], mem_rdata_latched[2], mem_rdata_latched[6], 4'b 0000}); end else begin // C.LUI mem_rdata_q[31:12] <= $signed({mem_rdata_latched[12], mem_rdata_latched[6:2]}); end end 3'b100: begin if (mem_rdata_latched[11:10] == 2'b00) begin // C.SRLI mem_rdata_q[31:25] <= 7'b0000000; mem_rdata_q[14:12] <= 3'b 101; end if (mem_rdata_latched[11:10] == 2'b01) begin // C.SRAI mem_rdata_q[31:25] <= 7'b0100000; mem_rdata_q[14:12] <= 3'b 101; end if (mem_rdata_latched[11:10] == 2'b10) begin // C.ANDI mem_rdata_q[14:12] <= 3'b111; mem_rdata_q[31:20] <= $signed({mem_rdata_latched[12], mem_rdata_latched[6:2]}); end if (mem_rdata_latched[12:10] == 3'b011) begin // C.SUB, C.XOR, C.OR, C.AND if (mem_rdata_latched[6:5] == 2'b00) mem_rdata_q[14:12] <= 3'b000; if (mem_rdata_latched[6:5] == 2'b01) mem_rdata_q[14:12] <= 3'b100; if (mem_rdata_latched[6:5] == 2'b10) mem_rdata_q[14:12] <= 3'b110; if (mem_rdata_latched[6:5] == 2'b11) mem_rdata_q[14:12] <= 3'b111; mem_rdata_q[31:25] <= mem_rdata_latched[6:5] == 2'b00 ? 7'b0100000 : 7'b0000000; end end 3'b 110: begin // C.BEQZ mem_rdata_q[14:12] <= 3'b000; { mem_rdata_q[31], mem_rdata_q[7], mem_rdata_q[30:25], mem_rdata_q[11:8] } <= $signed({mem_rdata_latched[12], mem_rdata_latched[6:5], mem_rdata_latched[2], mem_rdata_latched[11:10], mem_rdata_latched[4:3]}); end 3'b 111: begin // C.BNEZ mem_rdata_q[14:12] <= 3'b001; { mem_rdata_q[31], mem_rdata_q[7], mem_rdata_q[30:25], mem_rdata_q[11:8] } <= $signed({mem_rdata_latched[12], mem_rdata_latched[6:5], mem_rdata_latched[2], mem_rdata_latched[11:10], mem_rdata_latched[4:3]}); end endcase end 2'b10: begin // Quadrant 2 case (mem_rdata_latched[15:13]) 3'b000: begin // C.SLLI mem_rdata_q[31:25] <= 7'b0000000; mem_rdata_q[14:12] <= 3'b 001; end 3'b010: begin // C.LWSP mem_rdata_q[31:20] <= {4'b0, mem_rdata_latched[3:2], mem_rdata_latched[12], mem_rdata_latched[6:4], 2'b00}; mem_rdata_q[14:12] <= 3'b 010; end 3'b100: begin if (mem_rdata_latched[12] == 0 && mem_rdata_latched[6:2] == 0) begin // C.JR mem_rdata_q[14:12] <= 3'b000; mem_rdata_q[31:20] <= 12'b0; end if (mem_rdata_latched[12] == 0 && mem_rdata_latched[6:2] != 0) begin // C.MV mem_rdata_q[14:12] <= 3'b000; mem_rdata_q[31:25] <= 7'b0000000; end if (mem_rdata_latched[12] != 0 && mem_rdata_latched[11:7] != 0 && mem_rdata_latched[6:2] == 0) begin // C.JALR mem_rdata_q[14:12] <= 3'b000; mem_rdata_q[31:20] <= 12'b0; end if (mem_rdata_latched[12] != 0 && mem_rdata_latched[6:2] != 0) begin // C.ADD mem_rdata_q[14:12] <= 3'b000; mem_rdata_q[31:25] <= 7'b0000000; end end 3'b110: begin // C.SWSP {mem_rdata_q[31:25], mem_rdata_q[11:7]} <= {4'b0, mem_rdata_latched[8:7], mem_rdata_latched[12:9], 2'b00}; mem_rdata_q[14:12] <= 3'b 010; end endcase end endcase end end always @(posedge clk) begin if (resetn && !trap) begin if (mem_do_prefetch || mem_do_rinst || mem_do_rdata) `assert(!mem_do_wdata); if (mem_do_prefetch || mem_do_rinst) `assert(!mem_do_rdata); if (mem_do_rdata) `assert(!mem_do_prefetch && !mem_do_rinst); if (mem_do_wdata) `assert(!(mem_do_prefetch || mem_do_rinst || mem_do_rdata)); if (mem_state == 2 || mem_state == 3) `assert(mem_valid || mem_do_prefetch); end end always @(posedge clk) begin if (!resetn || trap) begin if (!resetn) mem_state <= 0; if (!resetn || mem_ready) mem_valid <= 0; mem_la_secondword <= 0; prefetched_high_word <= 0; end else begin if (mem_la_read || mem_la_write) begin mem_addr <= mem_la_addr; mem_wstrb <= mem_la_wstrb & {4{mem_la_write}}; end if (mem_la_write) begin mem_wdata <= mem_la_wdata; end case (mem_state) 0: begin if (mem_do_prefetch || mem_do_rinst || mem_do_rdata) begin mem_valid <= !mem_la_use_prefetched_high_word; mem_instr <= mem_do_prefetch || mem_do_rinst; mem_wstrb <= 0; mem_state <= 1; end if (mem_do_wdata) begin mem_valid <= 1; mem_instr <= 0; mem_state <= 2; end end 1: begin `assert(mem_wstrb == 0); `assert(mem_do_prefetch || mem_do_rinst || mem_do_rdata); `assert(mem_valid == !mem_la_use_prefetched_high_word); `assert(mem_instr == (mem_do_prefetch || mem_do_rinst)); if (mem_xfer) begin if (COMPRESSED_ISA && mem_la_read) begin mem_valid <= 1; mem_la_secondword <= 1; if (!mem_la_use_prefetched_high_word) mem_16bit_buffer <= mem_rdata[31:16]; end else begin mem_valid <= 0; mem_la_secondword <= 0; if (COMPRESSED_ISA && !mem_do_rdata) begin if (~&mem_rdata[1:0] || mem_la_secondword) begin mem_16bit_buffer <= mem_rdata[31:16]; prefetched_high_word <= 1; end else begin prefetched_high_word <= 0; end end mem_state <= mem_do_rinst || mem_do_rdata ? 0 : 3; end end end 2: begin `assert(mem_wstrb != 0); `assert(mem_do_wdata); if (mem_xfer) begin mem_valid <= 0; mem_state <= 0; end end 3: begin `assert(mem_wstrb == 0); `assert(mem_do_prefetch); if (mem_do_rinst) begin mem_state <= 0; end end endcase end if (clear_prefetched_high_word) prefetched_high_word <= 0; end // Instruction Decoder reg instr_lui, instr_auipc, instr_jal, instr_jalr; reg instr_beq, instr_bne, instr_blt, instr_bge, instr_bltu, instr_bgeu; reg instr_lb, instr_lh, instr_lw, instr_lbu, instr_lhu, instr_sb, instr_sh, instr_sw; reg instr_addi, instr_slti, instr_sltiu, instr_xori, instr_ori, instr_andi, instr_slli, instr_srli, instr_srai; reg instr_add, instr_sub, instr_sll, instr_slt, instr_sltu, instr_xor, instr_srl, instr_sra, instr_or, instr_and; reg instr_rdcycle, instr_rdcycleh, instr_rdinstr, instr_rdinstrh, instr_ecall_ebreak; reg instr_getq, instr_setq, instr_retirq, instr_maskirq, instr_waitirq, instr_timer; wire instr_trap; reg [regindex_bits-1:0] decoded_rd, decoded_rs1, decoded_rs2; reg [31:0] decoded_imm, decoded_imm_j; reg decoder_trigger; reg decoder_trigger_q; reg decoder_pseudo_trigger; reg decoder_pseudo_trigger_q; reg compressed_instr; reg is_lui_auipc_jal; reg is_lb_lh_lw_lbu_lhu; reg is_slli_srli_srai; reg is_jalr_addi_slti_sltiu_xori_ori_andi; reg is_sb_sh_sw; reg is_sll_srl_sra; reg is_lui_auipc_jal_jalr_addi_add_sub; reg is_slti_blt_slt; reg is_sltiu_bltu_sltu; reg is_beq_bne_blt_bge_bltu_bgeu; reg is_lbu_lhu_lw; reg is_alu_reg_imm; reg is_alu_reg_reg; reg is_compare; assign instr_trap = (CATCH_ILLINSN || WITH_PCPI) && !{instr_lui, instr_auipc, instr_jal, instr_jalr, instr_beq, instr_bne, instr_blt, instr_bge, instr_bltu, instr_bgeu, instr_lb, instr_lh, instr_lw, instr_lbu, instr_lhu, instr_sb, instr_sh, instr_sw, instr_addi, instr_slti, instr_sltiu, instr_xori, instr_ori, instr_andi, instr_slli, instr_srli, instr_srai, instr_add, instr_sub, instr_sll, instr_slt, instr_sltu, instr_xor, instr_srl, instr_sra, instr_or, instr_and, instr_rdcycle, instr_rdcycleh, instr_rdinstr, instr_rdinstrh, instr_getq, instr_setq, instr_retirq, instr_maskirq, instr_waitirq, instr_timer}; wire is_rdcycle_rdcycleh_rdinstr_rdinstrh; assign is_rdcycle_rdcycleh_rdinstr_rdinstrh = |{instr_rdcycle, instr_rdcycleh, instr_rdinstr, instr_rdinstrh}; reg [63:0] new_ascii_instr; `FORMAL_KEEP reg [63:0] dbg_ascii_instr; `FORMAL_KEEP reg [31:0] dbg_insn_imm; `FORMAL_KEEP reg [4:0] dbg_insn_rs1; `FORMAL_KEEP reg [4:0] dbg_insn_rs2; `FORMAL_KEEP reg [4:0] dbg_insn_rd; `FORMAL_KEEP reg [31:0] dbg_rs1val; `FORMAL_KEEP reg [31:0] dbg_rs2val; `FORMAL_KEEP reg dbg_rs1val_valid; `FORMAL_KEEP reg dbg_rs2val_valid; always @* begin new_ascii_instr = ""; if (instr_lui) new_ascii_instr = "lui"; if (instr_auipc) new_ascii_instr = "auipc"; if (instr_jal) new_ascii_instr = "jal"; if (instr_jalr) new_ascii_instr = "jalr"; if (instr_beq) new_ascii_instr = "beq"; if (instr_bne) new_ascii_instr = "bne"; if (instr_blt) new_ascii_instr = "blt"; if (instr_bge) new_ascii_instr = "bge"; if (instr_bltu) new_ascii_instr = "bltu"; if (instr_bgeu) new_ascii_instr = "bgeu"; if (instr_lb) new_ascii_instr = "lb"; if (instr_lh) new_ascii_instr = "lh"; if (instr_lw) new_ascii_instr = "lw"; if (instr_lbu) new_ascii_instr = "lbu"; if (instr_lhu) new_ascii_instr = "lhu"; if (instr_sb) new_ascii_instr = "sb"; if (instr_sh) new_ascii_instr = "sh"; if (instr_sw) new_ascii_instr = "sw"; if (instr_addi) new_ascii_instr = "addi"; if (instr_slti) new_ascii_instr = "slti"; if (instr_sltiu) new_ascii_instr = "sltiu"; if (instr_xori) new_ascii_instr = "xori"; if (instr_ori) new_ascii_instr = "ori"; if (instr_andi) new_ascii_instr = "andi"; if (instr_slli) new_ascii_instr = "slli"; if (instr_srli) new_ascii_instr = "srli"; if (instr_srai) new_ascii_instr = "srai"; if (instr_add) new_ascii_instr = "add"; if (instr_sub) new_ascii_instr = "sub"; if (instr_sll) new_ascii_instr = "sll"; if (instr_slt) new_ascii_instr = "slt"; if (instr_sltu) new_ascii_instr = "sltu"; if (instr_xor) new_ascii_instr = "xor"; if (instr_srl) new_ascii_instr = "srl"; if (instr_sra) new_ascii_instr = "sra"; if (instr_or) new_ascii_instr = "or"; if (instr_and) new_ascii_instr = "and"; if (instr_rdcycle) new_ascii_instr = "rdcycle"; if (instr_rdcycleh) new_ascii_instr = "rdcycleh"; if (instr_rdinstr) new_ascii_instr = "rdinstr"; if (instr_rdinstrh) new_ascii_instr = "rdinstrh"; if (instr_getq) new_ascii_instr = "getq"; if (instr_setq) new_ascii_instr = "setq"; if (instr_retirq) new_ascii_instr = "retirq"; if (instr_maskirq) new_ascii_instr = "maskirq"; if (instr_waitirq) new_ascii_instr = "waitirq"; if (instr_timer) new_ascii_instr = "timer"; end reg [63:0] q_ascii_instr; reg [31:0] q_insn_imm; reg [31:0] q_insn_opcode; reg [4:0] q_insn_rs1; reg [4:0] q_insn_rs2; reg [4:0] q_insn_rd; reg dbg_next; wire launch_next_insn; reg dbg_valid_insn; reg [63:0] cached_ascii_instr; reg [31:0] cached_insn_imm; reg [31:0] cached_insn_opcode; reg [4:0] cached_insn_rs1; reg [4:0] cached_insn_rs2; reg [4:0] cached_insn_rd; always @(posedge clk) begin q_ascii_instr <= dbg_ascii_instr; q_insn_imm <= dbg_insn_imm; q_insn_opcode <= dbg_insn_opcode; q_insn_rs1 <= dbg_insn_rs1; q_insn_rs2 <= dbg_insn_rs2; q_insn_rd <= dbg_insn_rd; dbg_next <= launch_next_insn; if (!resetn || trap) dbg_valid_insn <= 0; else if (launch_next_insn) dbg_valid_insn <= 1; if (decoder_trigger_q) begin cached_ascii_instr <= new_ascii_instr; cached_insn_imm <= decoded_imm; if (&next_insn_opcode[1:0]) cached_insn_opcode <= next_insn_opcode; else cached_insn_opcode <= {16'b0, next_insn_opcode[15:0]}; cached_insn_rs1 <= decoded_rs1; cached_insn_rs2 <= decoded_rs2; cached_insn_rd <= decoded_rd; end if (launch_next_insn) begin dbg_insn_addr <= next_pc; end end always @* begin dbg_ascii_instr = q_ascii_instr; dbg_insn_imm = q_insn_imm; dbg_insn_opcode = q_insn_opcode; dbg_insn_rs1 = q_insn_rs1; dbg_insn_rs2 = q_insn_rs2; dbg_insn_rd = q_insn_rd; if (dbg_next) begin if (decoder_pseudo_trigger_q) begin dbg_ascii_instr = cached_ascii_instr; dbg_insn_imm = cached_insn_imm; dbg_insn_opcode = cached_insn_opcode; dbg_insn_rs1 = cached_insn_rs1; dbg_insn_rs2 = cached_insn_rs2; dbg_insn_rd = cached_insn_rd; end else begin dbg_ascii_instr = new_ascii_instr; if (&next_insn_opcode[1:0]) dbg_insn_opcode = next_insn_opcode; else dbg_insn_opcode = {16'b0, next_insn_opcode[15:0]}; dbg_insn_imm = decoded_imm; dbg_insn_rs1 = decoded_rs1; dbg_insn_rs2 = decoded_rs2; dbg_insn_rd = decoded_rd; end end end `ifdef DEBUGASM always @(posedge clk) begin if (dbg_next) begin $display("debugasm %x %x %s", dbg_insn_addr, dbg_insn_opcode, dbg_ascii_instr ? dbg_ascii_instr : "*"); end end `endif `ifdef DEBUG always @(posedge clk) begin if (dbg_next) begin if (&dbg_insn_opcode[1:0]) $display("DECODE: 0x%08x 0x%08x %-0s", dbg_insn_addr, dbg_insn_opcode, dbg_ascii_instr ? dbg_ascii_instr : "UNKNOWN"); else $display("DECODE: 0x%08x 0x%04x %-0s", dbg_insn_addr, dbg_insn_opcode[15:0], dbg_ascii_instr ? dbg_ascii_instr : "UNKNOWN"); end end `endif always @(posedge clk) begin is_lui_auipc_jal <= |{instr_lui, instr_auipc, instr_jal}; is_lui_auipc_jal_jalr_addi_add_sub <= |{instr_lui, instr_auipc, instr_jal, instr_jalr, instr_addi, instr_add, instr_sub}; is_slti_blt_slt <= |{instr_slti, instr_blt, instr_slt}; is_sltiu_bltu_sltu <= |{instr_sltiu, instr_bltu, instr_sltu}; is_lbu_lhu_lw <= |{instr_lbu, instr_lhu, instr_lw}; is_compare <= |{is_beq_bne_blt_bge_bltu_bgeu, instr_slti, instr_slt, instr_sltiu, instr_sltu}; if (mem_do_rinst && mem_done) begin instr_lui <= mem_rdata_latched[6:0] == 7'b0110111; instr_auipc <= mem_rdata_latched[6:0] == 7'b0010111; instr_jal <= mem_rdata_latched[6:0] == 7'b1101111; instr_jalr <= mem_rdata_latched[6:0] == 7'b1100111 && mem_rdata_latched[14:12] == 3'b000; instr_retirq <= mem_rdata_latched[6:0] == 7'b0001011 && mem_rdata_latched[31:25] == 7'b0000010 && ENABLE_IRQ; instr_waitirq <= mem_rdata_latched[6:0] == 7'b0001011 && mem_rdata_latched[31:25] == 7'b0000100 && ENABLE_IRQ; is_beq_bne_blt_bge_bltu_bgeu <= mem_rdata_latched[6:0] == 7'b1100011; is_lb_lh_lw_lbu_lhu <= mem_rdata_latched[6:0] == 7'b0000011; is_sb_sh_sw <= mem_rdata_latched[6:0] == 7'b0100011; is_alu_reg_imm <= mem_rdata_latched[6:0] == 7'b0010011; is_alu_reg_reg <= mem_rdata_latched[6:0] == 7'b0110011; { decoded_imm_j[31:20], decoded_imm_j[10:1], decoded_imm_j[11], decoded_imm_j[19:12], decoded_imm_j[0] } <= $signed({mem_rdata_latched[31:12], 1'b0}); decoded_rd <= mem_rdata_latched[11:7]; decoded_rs1 <= mem_rdata_latched[19:15]; decoded_rs2 <= mem_rdata_latched[24:20]; if (mem_rdata_latched[6:0] == 7'b0001011 && mem_rdata_latched[31:25] == 7'b0000000 && ENABLE_IRQ && ENABLE_IRQ_QREGS) decoded_rs1[regindex_bits-1] <= 1; // instr_getq if (mem_rdata_latched[6:0] == 7'b0001011 && mem_rdata_latched[31:25] == 7'b0000010 && ENABLE_IRQ) decoded_rs1 <= ENABLE_IRQ_QREGS ? irqregs_offset : 3; // instr_retirq compressed_instr <= 0; if (COMPRESSED_ISA && mem_rdata_latched[1:0] != 2'b11) begin compressed_instr <= 1; decoded_rd <= 0; decoded_rs1 <= 0; decoded_rs2 <= 0; { decoded_imm_j[31:11], decoded_imm_j[4], decoded_imm_j[9:8], decoded_imm_j[10], decoded_imm_j[6], decoded_imm_j[7], decoded_imm_j[3:1], decoded_imm_j[5], decoded_imm_j[0] } <= $signed({mem_rdata_latched[12:2], 1'b0}); case (mem_rdata_latched[1:0]) 2'b00: begin // Quadrant 0 case (mem_rdata_latched[15:13]) 3'b000: begin // C.ADDI4SPN is_alu_reg_imm <= |mem_rdata_latched[12:5]; decoded_rs1 <= 2; decoded_rd <= 8 + mem_rdata_latched[4:2]; end 3'b010: begin // C.LW is_lb_lh_lw_lbu_lhu <= 1; decoded_rs1 <= 8 + mem_rdata_latched[9:7]; decoded_rd <= 8 + mem_rdata_latched[4:2]; end 3'b110: begin // C.SW is_sb_sh_sw <= 1; decoded_rs1 <= 8 + mem_rdata_latched[9:7]; decoded_rs2 <= 8 + mem_rdata_latched[4:2]; end endcase end 2'b01: begin // Quadrant 1 case (mem_rdata_latched[15:13]) 3'b000: begin // C.NOP / C.ADDI is_alu_reg_imm <= 1; decoded_rd <= mem_rdata_latched[11:7]; decoded_rs1 <= mem_rdata_latched[11:7]; end 3'b001: begin // C.JAL instr_jal <= 1; decoded_rd <= 1; end 3'b 010: begin // C.LI is_alu_reg_imm <= 1; decoded_rd <= mem_rdata_latched[11:7]; decoded_rs1 <= 0; end 3'b 011: begin if (mem_rdata_latched[12] || mem_rdata_latched[6:2]) begin if (mem_rdata_latched[11:7] == 2) begin // C.ADDI16SP is_alu_reg_imm <= 1; decoded_rd <= mem_rdata_latched[11:7]; decoded_rs1 <= mem_rdata_latched[11:7]; end else begin // C.LUI instr_lui <= 1; decoded_rd <= mem_rdata_latched[11:7]; decoded_rs1 <= 0; end end end 3'b100: begin if (!mem_rdata_latched[11] && !mem_rdata_latched[12]) begin // C.SRLI, C.SRAI is_alu_reg_imm <= 1; decoded_rd <= 8 + mem_rdata_latched[9:7]; decoded_rs1 <= 8 + mem_rdata_latched[9:7]; decoded_rs2 <= {mem_rdata_latched[12], mem_rdata_latched[6:2]}; end if (mem_rdata_latched[11:10] == 2'b10) begin // C.ANDI is_alu_reg_imm <= 1; decoded_rd <= 8 + mem_rdata_latched[9:7]; decoded_rs1 <= 8 + mem_rdata_latched[9:7]; end if (mem_rdata_latched[12:10] == 3'b011) begin // C.SUB, C.XOR, C.OR, C.AND is_alu_reg_reg <= 1; decoded_rd <= 8 + mem_rdata_latched[9:7]; decoded_rs1 <= 8 + mem_rdata_latched[9:7]; decoded_rs2 <= 8 + mem_rdata_latched[4:2]; end end 3'b101: begin // C.J instr_jal <= 1; end 3'b110: begin // C.BEQZ is_beq_bne_blt_bge_bltu_bgeu <= 1; decoded_rs1 <= 8 + mem_rdata_latched[9:7]; decoded_rs2 <= 0; end 3'b111: begin // C.BNEZ is_beq_bne_blt_bge_bltu_bgeu <= 1; decoded_rs1 <= 8 + mem_rdata_latched[9:7]; decoded_rs2 <= 0; end endcase end 2'b10: begin // Quadrant 2 case (mem_rdata_latched[15:13]) 3'b000: begin // C.SLLI if (!mem_rdata_latched[12]) begin is_alu_reg_imm <= 1; decoded_rd <= mem_rdata_latched[11:7]; decoded_rs1 <= mem_rdata_latched[11:7]; decoded_rs2 <= {mem_rdata_latched[12], mem_rdata_latched[6:2]}; end end 3'b010: begin // C.LWSP if (mem_rdata_latched[11:7]) begin is_lb_lh_lw_lbu_lhu <= 1; decoded_rd <= mem_rdata_latched[11:7]; decoded_rs1 <= 2; end end 3'b100: begin if (mem_rdata_latched[12] == 0 && mem_rdata_latched[11:7] != 0 && mem_rdata_latched[6:2] == 0) begin // C.JR instr_jalr <= 1; decoded_rd <= 0; decoded_rs1 <= mem_rdata_latched[11:7]; end if (mem_rdata_latched[12] == 0 && mem_rdata_latched[6:2] != 0) begin // C.MV is_alu_reg_reg <= 1; decoded_rd <= mem_rdata_latched[11:7]; decoded_rs1 <= 0; decoded_rs2 <= mem_rdata_latched[6:2]; end if (mem_rdata_latched[12] != 0 && mem_rdata_latched[11:7] != 0 && mem_rdata_latched[6:2] == 0) begin // C.JALR instr_jalr <= 1; decoded_rd <= 1; decoded_rs1 <= mem_rdata_latched[11:7]; end if (mem_rdata_latched[12] != 0 && mem_rdata_latched[6:2] != 0) begin // C.ADD is_alu_reg_reg <= 1; decoded_rd <= mem_rdata_latched[11:7]; decoded_rs1 <= mem_rdata_latched[11:7]; decoded_rs2 <= mem_rdata_latched[6:2]; end end 3'b110: begin // C.SWSP is_sb_sh_sw <= 1; decoded_rs1 <= 2; decoded_rs2 <= mem_rdata_latched[6:2]; end endcase end endcase end end if (decoder_trigger && !decoder_pseudo_trigger) begin pcpi_insn <= WITH_PCPI ? mem_rdata_q : 'bx; instr_beq <= is_beq_bne_blt_bge_bltu_bgeu && mem_rdata_q[14:12] == 3'b000; instr_bne <= is_beq_bne_blt_bge_bltu_bgeu && mem_rdata_q[14:12] == 3'b001; instr_blt <= is_beq_bne_blt_bge_bltu_bgeu && mem_rdata_q[14:12] == 3'b100; instr_bge <= is_beq_bne_blt_bge_bltu_bgeu && mem_rdata_q[14:12] == 3'b101; instr_bltu <= is_beq_bne_blt_bge_bltu_bgeu && mem_rdata_q[14:12] == 3'b110; instr_bgeu <= is_beq_bne_blt_bge_bltu_bgeu && mem_rdata_q[14:12] == 3'b111; instr_lb <= is_lb_lh_lw_lbu_lhu && mem_rdata_q[14:12] == 3'b000; instr_lh <= is_lb_lh_lw_lbu_lhu && mem_rdata_q[14:12] == 3'b001; instr_lw <= is_lb_lh_lw_lbu_lhu && mem_rdata_q[14:12] == 3'b010; instr_lbu <= is_lb_lh_lw_lbu_lhu && mem_rdata_q[14:12] == 3'b100; instr_lhu <= is_lb_lh_lw_lbu_lhu && mem_rdata_q[14:12] == 3'b101; instr_sb <= is_sb_sh_sw && mem_rdata_q[14:12] == 3'b000; instr_sh <= is_sb_sh_sw && mem_rdata_q[14:12] == 3'b001; instr_sw <= is_sb_sh_sw && mem_rdata_q[14:12] == 3'b010; instr_addi <= is_alu_reg_imm && mem_rdata_q[14:12] == 3'b000; instr_slti <= is_alu_reg_imm && mem_rdata_q[14:12] == 3'b010; instr_sltiu <= is_alu_reg_imm && mem_rdata_q[14:12] == 3'b011; instr_xori <= is_alu_reg_imm && mem_rdata_q[14:12] == 3'b100; instr_ori <= is_alu_reg_imm && mem_rdata_q[14:12] == 3'b110; instr_andi <= is_alu_reg_imm && mem_rdata_q[14:12] == 3'b111; instr_slli <= is_alu_reg_imm && mem_rdata_q[14:12] == 3'b001 && mem_rdata_q[31:25] == 7'b0000000; instr_srli <= is_alu_reg_imm && mem_rdata_q[14:12] == 3'b101 && mem_rdata_q[31:25] == 7'b0000000; instr_srai <= is_alu_reg_imm && mem_rdata_q[14:12] == 3'b101 && mem_rdata_q[31:25] == 7'b0100000; instr_add <= is_alu_reg_reg && mem_rdata_q[14:12] == 3'b000 && mem_rdata_q[31:25] == 7'b0000000; instr_sub <= is_alu_reg_reg && mem_rdata_q[14:12] == 3'b000 && mem_rdata_q[31:25] == 7'b0100000; instr_sll <= is_alu_reg_reg && mem_rdata_q[14:12] == 3'b001 && mem_rdata_q[31:25] == 7'b0000000; instr_slt <= is_alu_reg_reg && mem_rdata_q[14:12] == 3'b010 && mem_rdata_q[31:25] == 7'b0000000; instr_sltu <= is_alu_reg_reg && mem_rdata_q[14:12] == 3'b011 && mem_rdata_q[31:25] == 7'b0000000; instr_xor <= is_alu_reg_reg && mem_rdata_q[14:12] == 3'b100 && mem_rdata_q[31:25] == 7'b0000000; instr_srl <= is_alu_reg_reg && mem_rdata_q[14:12] == 3'b101 && mem_rdata_q[31:25] == 7'b0000000; instr_sra <= is_alu_reg_reg && mem_rdata_q[14:12] == 3'b101 && mem_rdata_q[31:25] == 7'b0100000; instr_or <= is_alu_reg_reg && mem_rdata_q[14:12] == 3'b110 && mem_rdata_q[31:25] == 7'b0000000; instr_and <= is_alu_reg_reg && mem_rdata_q[14:12] == 3'b111 && mem_rdata_q[31:25] == 7'b0000000; instr_rdcycle <= ((mem_rdata_q[6:0] == 7'b1110011 && mem_rdata_q[31:12] == 'b11000000000000000010) || (mem_rdata_q[6:0] == 7'b1110011 && mem_rdata_q[31:12] == 'b11000000000100000010)) && ENABLE_COUNTERS; instr_rdcycleh <= ((mem_rdata_q[6:0] == 7'b1110011 && mem_rdata_q[31:12] == 'b11001000000000000010) || (mem_rdata_q[6:0] == 7'b1110011 && mem_rdata_q[31:12] == 'b11001000000100000010)) && ENABLE_COUNTERS && ENABLE_COUNTERS64; instr_rdinstr <= (mem_rdata_q[6:0] == 7'b1110011 && mem_rdata_q[31:12] == 'b11000000001000000010) && ENABLE_COUNTERS; instr_rdinstrh <= (mem_rdata_q[6:0] == 7'b1110011 && mem_rdata_q[31:12] == 'b11001000001000000010) && ENABLE_COUNTERS && ENABLE_COUNTERS64; instr_ecall_ebreak <= ((mem_rdata_q[6:0] == 7'b1110011 && !mem_rdata_q[31:21] && !mem_rdata_q[19:7]) || (COMPRESSED_ISA && mem_rdata_q[15:0] == 16'h9002)); instr_getq <= mem_rdata_q[6:0] == 7'b0001011 && mem_rdata_q[31:25] == 7'b0000000 && ENABLE_IRQ && ENABLE_IRQ_QREGS; instr_setq <= mem_rdata_q[6:0] == 7'b0001011 && mem_rdata_q[31:25] == 7'b0000001 && ENABLE_IRQ && ENABLE_IRQ_QREGS; instr_maskirq <= mem_rdata_q[6:0] == 7'b0001011 && mem_rdata_q[31:25] == 7'b0000011 && ENABLE_IRQ; instr_timer <= mem_rdata_q[6:0] == 7'b0001011 && mem_rdata_q[31:25] == 7'b0000101 && ENABLE_IRQ && ENABLE_IRQ_TIMER; is_slli_srli_srai <= is_alu_reg_imm && |{ mem_rdata_q[14:12] == 3'b001 && mem_rdata_q[31:25] == 7'b0000000, mem_rdata_q[14:12] == 3'b101 && mem_rdata_q[31:25] == 7'b0000000, mem_rdata_q[14:12] == 3'b101 && mem_rdata_q[31:25] == 7'b0100000 }; is_jalr_addi_slti_sltiu_xori_ori_andi <= instr_jalr || is_alu_reg_imm && |{ mem_rdata_q[14:12] == 3'b000, mem_rdata_q[14:12] == 3'b010, mem_rdata_q[14:12] == 3'b011, mem_rdata_q[14:12] == 3'b100, mem_rdata_q[14:12] == 3'b110, mem_rdata_q[14:12] == 3'b111 }; is_sll_srl_sra <= is_alu_reg_reg && |{ mem_rdata_q[14:12] == 3'b001 && mem_rdata_q[31:25] == 7'b0000000, mem_rdata_q[14:12] == 3'b101 && mem_rdata_q[31:25] == 7'b0000000, mem_rdata_q[14:12] == 3'b101 && mem_rdata_q[31:25] == 7'b0100000 }; is_lui_auipc_jal_jalr_addi_add_sub <= 0; is_compare <= 0; (* parallel_case *) case (1'b1) instr_jal: decoded_imm <= decoded_imm_j; |{instr_lui, instr_auipc}: decoded_imm <= mem_rdata_q[31:12] << 12; |{instr_jalr, is_lb_lh_lw_lbu_lhu, is_alu_reg_imm}: decoded_imm <= $signed(mem_rdata_q[31:20]); is_beq_bne_blt_bge_bltu_bgeu: decoded_imm <= $signed({mem_rdata_q[31], mem_rdata_q[7], mem_rdata_q[30:25], mem_rdata_q[11:8], 1'b0}); is_sb_sh_sw: decoded_imm <= $signed({mem_rdata_q[31:25], mem_rdata_q[11:7]}); default: decoded_imm <= 1'bx; endcase end if (!resetn) begin is_beq_bne_blt_bge_bltu_bgeu <= 0; is_compare <= 0; instr_beq <= 0; instr_bne <= 0; instr_blt <= 0; instr_bge <= 0; instr_bltu <= 0; instr_bgeu <= 0; instr_addi <= 0; instr_slti <= 0; instr_sltiu <= 0; instr_xori <= 0; instr_ori <= 0; instr_andi <= 0; instr_add <= 0; instr_sub <= 0; instr_sll <= 0; instr_slt <= 0; instr_sltu <= 0; instr_xor <= 0; instr_srl <= 0; instr_sra <= 0; instr_or <= 0; instr_and <= 0; end end // Main State Machine localparam cpu_state_trap = 8'b10000000; localparam cpu_state_fetch = 8'b01000000; localparam cpu_state_ld_rs1 = 8'b00100000; localparam cpu_state_ld_rs2 = 8'b00010000; localparam cpu_state_exec = 8'b00001000; localparam cpu_state_shift = 8'b00000100; localparam cpu_state_stmem = 8'b00000010; localparam cpu_state_ldmem = 8'b00000001; reg [7:0] cpu_state; reg [1:0] irq_state; `FORMAL_KEEP reg [127:0] dbg_ascii_state; always @* begin dbg_ascii_state = ""; if (cpu_state == cpu_state_trap) dbg_ascii_state = "trap"; if (cpu_state == cpu_state_fetch) dbg_ascii_state = "fetch"; if (cpu_state == cpu_state_ld_rs1) dbg_ascii_state = "ld_rs1"; if (cpu_state == cpu_state_ld_rs2) dbg_ascii_state = "ld_rs2"; if (cpu_state == cpu_state_exec) dbg_ascii_state = "exec"; if (cpu_state == cpu_state_shift) dbg_ascii_state = "shift"; if (cpu_state == cpu_state_stmem) dbg_ascii_state = "stmem"; if (cpu_state == cpu_state_ldmem) dbg_ascii_state = "ldmem"; end reg set_mem_do_rinst; reg set_mem_do_rdata; reg set_mem_do_wdata; reg latched_store; reg latched_stalu; reg latched_branch; reg latched_compr; reg latched_trace; reg latched_is_lu; reg latched_is_lh; reg latched_is_lb; reg [regindex_bits-1:0] latched_rd; reg [31:0] current_pc; assign next_pc = latched_store && latched_branch ? reg_out & ~1 : reg_next_pc; reg [3:0] pcpi_timeout_counter; reg pcpi_timeout; reg [31:0] next_irq_pending; reg do_waitirq; reg [31:0] alu_out, alu_out_q; reg alu_out_0, alu_out_0_q; reg alu_wait, alu_wait_2; reg [31:0] alu_add_sub; reg [31:0] alu_shl, alu_shr; reg alu_eq, alu_ltu, alu_lts; generate if (TWO_CYCLE_ALU) begin always @(posedge clk) begin alu_add_sub <= instr_sub ? reg_op1 - reg_op2 : reg_op1 + reg_op2; alu_eq <= reg_op1 == reg_op2; alu_lts <= $signed(reg_op1) < $signed(reg_op2); alu_ltu <= reg_op1 < reg_op2; alu_shl <= reg_op1 << reg_op2[4:0]; alu_shr <= $signed({instr_sra || instr_srai ? reg_op1[31] : 1'b0, reg_op1}) >>> reg_op2[4:0]; end end else begin always @* begin alu_add_sub = instr_sub ? reg_op1 - reg_op2 : reg_op1 + reg_op2; alu_eq = reg_op1 == reg_op2; alu_lts = $signed(reg_op1) < $signed(reg_op2); alu_ltu = reg_op1 < reg_op2; alu_shl = reg_op1 << reg_op2[4:0]; alu_shr = $signed({instr_sra || instr_srai ? reg_op1[31] : 1'b0, reg_op1}) >>> reg_op2[4:0]; end end endgenerate always @* begin alu_out_0 = 'bx; (* parallel_case, full_case *) case (1'b1) instr_beq: alu_out_0 = alu_eq; instr_bne: alu_out_0 = !alu_eq; instr_bge: alu_out_0 = !alu_lts; instr_bgeu: alu_out_0 = !alu_ltu; is_slti_blt_slt && (!TWO_CYCLE_COMPARE || !{instr_beq,instr_bne,instr_bge,instr_bgeu}): alu_out_0 = alu_lts; is_sltiu_bltu_sltu && (!TWO_CYCLE_COMPARE || !{instr_beq,instr_bne,instr_bge,instr_bgeu}): alu_out_0 = alu_ltu; endcase alu_out = 'bx; (* parallel_case, full_case *) case (1'b1) is_lui_auipc_jal_jalr_addi_add_sub: alu_out = alu_add_sub; is_compare: alu_out = alu_out_0; instr_xori || instr_xor: alu_out = reg_op1 ^ reg_op2; instr_ori || instr_or: alu_out = reg_op1 | reg_op2; instr_andi || instr_and: alu_out = reg_op1 & reg_op2; BARREL_SHIFTER && (instr_sll || instr_slli): alu_out = alu_shl; BARREL_SHIFTER && (instr_srl || instr_srli || instr_sra || instr_srai): alu_out = alu_shr; endcase `ifdef RISCV_FORMAL_BLACKBOX_ALU alu_out_0 = $anyseq; alu_out = $anyseq; `endif end reg clear_prefetched_high_word_q; always @(posedge clk) clear_prefetched_high_word_q <= clear_prefetched_high_word; always @* begin clear_prefetched_high_word = clear_prefetched_high_word_q; if (!prefetched_high_word) clear_prefetched_high_word = 0; if (latched_branch || irq_state || !resetn) clear_prefetched_high_word = COMPRESSED_ISA; end reg cpuregs_write; reg [31:0] cpuregs_wrdata; reg [31:0] cpuregs_rs1; reg [31:0] cpuregs_rs2; reg [regindex_bits-1:0] decoded_rs; always @* begin cpuregs_write = 0; cpuregs_wrdata = 'bx; if (cpu_state == cpu_state_fetch) begin (* parallel_case *) case (1'b1) latched_branch: begin cpuregs_wrdata = reg_pc + (latched_compr ? 2 : 4); cpuregs_write = 1; end latched_store && !latched_branch: begin cpuregs_wrdata = latched_stalu ? alu_out_q : reg_out; cpuregs_write = 1; end ENABLE_IRQ && irq_state[0]: begin cpuregs_wrdata = reg_next_pc | latched_compr; cpuregs_write = 1; end ENABLE_IRQ && irq_state[1]: begin cpuregs_wrdata = irq_pending & ~irq_mask; cpuregs_write = 1; end endcase end end `ifndef PICORV32_REGS always @(posedge clk) begin if (resetn && cpuregs_write && latched_rd) cpuregs[latched_rd] <= cpuregs_wrdata; end always @* begin decoded_rs = 'bx; if (ENABLE_REGS_DUALPORT) begin `ifndef RISCV_FORMAL_BLACKBOX_REGS cpuregs_rs1 = decoded_rs1 ? cpuregs[decoded_rs1] : 0; cpuregs_rs2 = decoded_rs2 ? cpuregs[decoded_rs2] : 0; `else cpuregs_rs1 = decoded_rs1 ? $anyseq : 0; cpuregs_rs2 = decoded_rs2 ? $anyseq : 0; `endif end else begin decoded_rs = (cpu_state == cpu_state_ld_rs2) ? decoded_rs2 : decoded_rs1; `ifndef RISCV_FORMAL_BLACKBOX_REGS cpuregs_rs1 = decoded_rs ? cpuregs[decoded_rs] : 0; `else cpuregs_rs1 = decoded_rs ? $anyseq : 0; `endif cpuregs_rs2 = cpuregs_rs1; end end `else wire[31:0] cpuregs_rdata1; wire[31:0] cpuregs_rdata2; wire [5:0] cpuregs_waddr = latched_rd; wire [5:0] cpuregs_raddr1 = ENABLE_REGS_DUALPORT ? decoded_rs1 : decoded_rs; wire [5:0] cpuregs_raddr2 = ENABLE_REGS_DUALPORT ? decoded_rs2 : 0; `PICORV32_REGS cpuregs ( .clk(clk), .wen(resetn && cpuregs_write && latched_rd), .waddr(cpuregs_waddr), .raddr1(cpuregs_raddr1), .raddr2(cpuregs_raddr2), .wdata(cpuregs_wrdata), .rdata1(cpuregs_rdata1), .rdata2(cpuregs_rdata2) ); always @* begin decoded_rs = 'bx; if (ENABLE_REGS_DUALPORT) begin cpuregs_rs1 = decoded_rs1 ? cpuregs_rdata1 : 0; cpuregs_rs2 = decoded_rs2 ? cpuregs_rdata2 : 0; end else begin decoded_rs = (cpu_state == cpu_state_ld_rs2) ? decoded_rs2 : decoded_rs1; cpuregs_rs1 = decoded_rs ? cpuregs_rdata1 : 0; cpuregs_rs2 = cpuregs_rs1; end end `endif assign launch_next_insn = cpu_state == cpu_state_fetch && decoder_trigger && (!ENABLE_IRQ || irq_delay || irq_active || !(irq_pending & ~irq_mask)); always @(posedge clk) begin trap <= 0; reg_sh <= 'bx; reg_out <= 'bx; set_mem_do_rinst = 0; set_mem_do_rdata = 0; set_mem_do_wdata = 0; alu_out_0_q <= alu_out_0; alu_out_q <= alu_out; alu_wait <= 0; alu_wait_2 <= 0; if (launch_next_insn) begin dbg_rs1val <= 'bx; dbg_rs2val <= 'bx; dbg_rs1val_valid <= 0; dbg_rs2val_valid <= 0; end if (WITH_PCPI && CATCH_ILLINSN) begin if (resetn && pcpi_valid && !pcpi_int_wait) begin if (pcpi_timeout_counter) pcpi_timeout_counter <= pcpi_timeout_counter - 1; end else pcpi_timeout_counter <= ~0; pcpi_timeout <= !pcpi_timeout_counter; end if (ENABLE_COUNTERS) begin count_cycle <= resetn ? count_cycle + 1 : 0; if (!ENABLE_COUNTERS64) count_cycle[63:32] <= 0; end else begin count_cycle <= 'bx; count_instr <= 'bx; end next_irq_pending = ENABLE_IRQ ? irq_pending & LATCHED_IRQ : 'bx; if (ENABLE_IRQ && ENABLE_IRQ_TIMER && timer) begin if (timer - 1 == 0) next_irq_pending[irq_timer] = 1; timer <= timer - 1; end if (ENABLE_IRQ) begin next_irq_pending = next_irq_pending | irq; end decoder_trigger <= mem_do_rinst && mem_done; decoder_trigger_q <= decoder_trigger; decoder_pseudo_trigger <= 0; decoder_pseudo_trigger_q <= decoder_pseudo_trigger; do_waitirq <= 0; trace_valid <= 0; if (!ENABLE_TRACE) trace_data <= 'bx; if (!resetn) begin reg_pc <= PROGADDR_RESET; reg_next_pc <= PROGADDR_RESET; if (ENABLE_COUNTERS) count_instr <= 0; latched_store <= 0; latched_stalu <= 0; latched_branch <= 0; latched_trace <= 0; latched_is_lu <= 0; latched_is_lh <= 0; latched_is_lb <= 0; pcpi_valid <= 0; pcpi_timeout <= 0; irq_active <= 0; irq_delay <= 0; irq_mask <= ~0; next_irq_pending = 0; irq_state <= 0; eoi <= 0; timer <= 0; if (~STACKADDR) begin latched_store <= 1; latched_rd <= 2; reg_out <= STACKADDR; end cpu_state <= cpu_state_fetch; end else (* parallel_case, full_case *) case (cpu_state) cpu_state_trap: begin trap <= 1; end cpu_state_fetch: begin mem_do_rinst <= !decoder_trigger && !do_waitirq; mem_wordsize <= 0; current_pc = reg_next_pc; (* parallel_case *) case (1'b1) latched_branch: begin current_pc = latched_store ? (latched_stalu ? alu_out_q : reg_out) & ~1 : reg_next_pc; `debug($display("ST_RD: %2d 0x%08x, BRANCH 0x%08x", latched_rd, reg_pc + (latched_compr ? 2 : 4), current_pc);) end latched_store && !latched_branch: begin `debug($display("ST_RD: %2d 0x%08x", latched_rd, latched_stalu ? alu_out_q : reg_out);) end ENABLE_IRQ && irq_state[0]: begin current_pc = PROGADDR_IRQ; irq_active <= 1; mem_do_rinst <= 1; end ENABLE_IRQ && irq_state[1]: begin eoi <= irq_pending & ~irq_mask; next_irq_pending = next_irq_pending & irq_mask; end endcase if (ENABLE_TRACE && latched_trace) begin latched_trace <= 0; trace_valid <= 1; if (latched_branch) trace_data <= (irq_active ? TRACE_IRQ : 0) | TRACE_BRANCH | (current_pc & 32'hfffffffe); else trace_data <= (irq_active ? TRACE_IRQ : 0) | (latched_stalu ? alu_out_q : reg_out); end reg_pc <= current_pc; reg_next_pc <= current_pc; latched_store <= 0; latched_stalu <= 0; latched_branch <= 0; latched_is_lu <= 0; latched_is_lh <= 0; latched_is_lb <= 0; latched_rd <= decoded_rd; latched_compr <= compressed_instr; if (ENABLE_IRQ && ((decoder_trigger && !irq_active && !irq_delay && |(irq_pending & ~irq_mask)) || irq_state)) begin irq_state <= irq_state == 2'b00 ? 2'b01 : irq_state == 2'b01 ? 2'b10 : 2'b00; latched_compr <= latched_compr; if (ENABLE_IRQ_QREGS) latched_rd <= irqregs_offset | irq_state[0]; else latched_rd <= irq_state[0] ? 4 : 3; end else if (ENABLE_IRQ && (decoder_trigger || do_waitirq) && instr_waitirq) begin if (irq_pending) begin latched_store <= 1; reg_out <= irq_pending; reg_next_pc <= current_pc + (compressed_instr ? 2 : 4); mem_do_rinst <= 1; end else do_waitirq <= 1; end else if (decoder_trigger) begin `debug($display("-- %-0t", $time);) irq_delay <= irq_active; reg_next_pc <= current_pc + (compressed_instr ? 2 : 4); if (ENABLE_TRACE) latched_trace <= 1; if (ENABLE_COUNTERS) begin count_instr <= count_instr + 1; if (!ENABLE_COUNTERS64) count_instr[63:32] <= 0; end if (instr_jal) begin mem_do_rinst <= 1; reg_next_pc <= current_pc + decoded_imm_j; latched_branch <= 1; end else begin mem_do_rinst <= 0; mem_do_prefetch <= !instr_jalr && !instr_retirq; cpu_state <= cpu_state_ld_rs1; end end end cpu_state_ld_rs1: begin reg_op1 <= 'bx; reg_op2 <= 'bx; (* parallel_case *) case (1'b1) (CATCH_ILLINSN || WITH_PCPI) && instr_trap: begin if (WITH_PCPI) begin `debug($display("LD_RS1: %2d 0x%08x", decoded_rs1, cpuregs_rs1);) reg_op1 <= cpuregs_rs1; dbg_rs1val <= cpuregs_rs1; dbg_rs1val_valid <= 1; if (ENABLE_REGS_DUALPORT) begin pcpi_valid <= 1; `debug($display("LD_RS2: %2d 0x%08x", decoded_rs2, cpuregs_rs2);) reg_sh <= cpuregs_rs2; reg_op2 <= cpuregs_rs2; dbg_rs2val <= cpuregs_rs2; dbg_rs2val_valid <= 1; if (pcpi_int_ready) begin mem_do_rinst <= 1; pcpi_valid <= 0; reg_out <= pcpi_int_rd; latched_store <= pcpi_int_wr; cpu_state <= cpu_state_fetch; end else if (CATCH_ILLINSN && (pcpi_timeout || instr_ecall_ebreak)) begin pcpi_valid <= 0; `debug($display("EBREAK OR UNSUPPORTED INSN AT 0x%08x", reg_pc);) if (ENABLE_IRQ && !irq_mask[irq_ebreak] && !irq_active) begin next_irq_pending[irq_ebreak] = 1; cpu_state <= cpu_state_fetch; end else cpu_state <= cpu_state_trap; end end else begin cpu_state <= cpu_state_ld_rs2; end end else begin `debug($display("EBREAK OR UNSUPPORTED INSN AT 0x%08x", reg_pc);) if (ENABLE_IRQ && !irq_mask[irq_ebreak] && !irq_active) begin next_irq_pending[irq_ebreak] = 1; cpu_state <= cpu_state_fetch; end else cpu_state <= cpu_state_trap; end end ENABLE_COUNTERS && is_rdcycle_rdcycleh_rdinstr_rdinstrh: begin (* parallel_case, full_case *) case (1'b1) instr_rdcycle: reg_out <= count_cycle[31:0]; instr_rdcycleh && ENABLE_COUNTERS64: reg_out <= count_cycle[63:32]; instr_rdinstr: reg_out <= count_instr[31:0]; instr_rdinstrh && ENABLE_COUNTERS64: reg_out <= count_instr[63:32]; endcase latched_store <= 1; cpu_state <= cpu_state_fetch; end is_lui_auipc_jal: begin reg_op1 <= instr_lui ? 0 : reg_pc; reg_op2 <= decoded_imm; if (TWO_CYCLE_ALU) alu_wait <= 1; else mem_do_rinst <= mem_do_prefetch; cpu_state <= cpu_state_exec; end ENABLE_IRQ && ENABLE_IRQ_QREGS && instr_getq: begin `debug($display("LD_RS1: %2d 0x%08x", decoded_rs1, cpuregs_rs1);) reg_out <= cpuregs_rs1; dbg_rs1val <= cpuregs_rs1; dbg_rs1val_valid <= 1; latched_store <= 1; cpu_state <= cpu_state_fetch; end ENABLE_IRQ && ENABLE_IRQ_QREGS && instr_setq: begin `debug($display("LD_RS1: %2d 0x%08x", decoded_rs1, cpuregs_rs1);) reg_out <= cpuregs_rs1; dbg_rs1val <= cpuregs_rs1; dbg_rs1val_valid <= 1; latched_rd <= latched_rd | irqregs_offset; latched_store <= 1; cpu_state <= cpu_state_fetch; end ENABLE_IRQ && instr_retirq: begin eoi <= 0; irq_active <= 0; latched_branch <= 1; latched_store <= 1; `debug($display("LD_RS1: %2d 0x%08x", decoded_rs1, cpuregs_rs1);) reg_out <= CATCH_MISALIGN ? (cpuregs_rs1 & 32'h fffffffe) : cpuregs_rs1; dbg_rs1val <= cpuregs_rs1; dbg_rs1val_valid <= 1; cpu_state <= cpu_state_fetch; end ENABLE_IRQ && instr_maskirq: begin latched_store <= 1; reg_out <= irq_mask; `debug($display("LD_RS1: %2d 0x%08x", decoded_rs1, cpuregs_rs1);) irq_mask <= cpuregs_rs1 | MASKED_IRQ; dbg_rs1val <= cpuregs_rs1; dbg_rs1val_valid <= 1; cpu_state <= cpu_state_fetch; end ENABLE_IRQ && ENABLE_IRQ_TIMER && instr_timer: begin latched_store <= 1; reg_out <= timer; `debug($display("LD_RS1: %2d 0x%08x", decoded_rs1, cpuregs_rs1);) timer <= cpuregs_rs1; dbg_rs1val <= cpuregs_rs1; dbg_rs1val_valid <= 1; cpu_state <= cpu_state_fetch; end is_lb_lh_lw_lbu_lhu && !instr_trap: begin `debug($display("LD_RS1: %2d 0x%08x", decoded_rs1, cpuregs_rs1);) reg_op1 <= cpuregs_rs1; dbg_rs1val <= cpuregs_rs1; dbg_rs1val_valid <= 1; cpu_state <= cpu_state_ldmem; mem_do_rinst <= 1; end is_slli_srli_srai && !BARREL_SHIFTER: begin `debug($display("LD_RS1: %2d 0x%08x", decoded_rs1, cpuregs_rs1);) reg_op1 <= cpuregs_rs1; dbg_rs1val <= cpuregs_rs1; dbg_rs1val_valid <= 1; reg_sh <= decoded_rs2; cpu_state <= cpu_state_shift; end is_jalr_addi_slti_sltiu_xori_ori_andi, is_slli_srli_srai && BARREL_SHIFTER: begin `debug($display("LD_RS1: %2d 0x%08x", decoded_rs1, cpuregs_rs1);) reg_op1 <= cpuregs_rs1; dbg_rs1val <= cpuregs_rs1; dbg_rs1val_valid <= 1; reg_op2 <= is_slli_srli_srai && BARREL_SHIFTER ? decoded_rs2 : decoded_imm; if (TWO_CYCLE_ALU) alu_wait <= 1; else mem_do_rinst <= mem_do_prefetch; cpu_state <= cpu_state_exec; end default: begin `debug($display("LD_RS1: %2d 0x%08x", decoded_rs1, cpuregs_rs1);) reg_op1 <= cpuregs_rs1; dbg_rs1val <= cpuregs_rs1; dbg_rs1val_valid <= 1; if (ENABLE_REGS_DUALPORT) begin `debug($display("LD_RS2: %2d 0x%08x", decoded_rs2, cpuregs_rs2);) reg_sh <= cpuregs_rs2; reg_op2 <= cpuregs_rs2; dbg_rs2val <= cpuregs_rs2; dbg_rs2val_valid <= 1; (* parallel_case *) case (1'b1) is_sb_sh_sw: begin cpu_state <= cpu_state_stmem; mem_do_rinst <= 1; end is_sll_srl_sra && !BARREL_SHIFTER: begin cpu_state <= cpu_state_shift; end default: begin if (TWO_CYCLE_ALU || (TWO_CYCLE_COMPARE && is_beq_bne_blt_bge_bltu_bgeu)) begin alu_wait_2 <= TWO_CYCLE_ALU && (TWO_CYCLE_COMPARE && is_beq_bne_blt_bge_bltu_bgeu); alu_wait <= 1; end else mem_do_rinst <= mem_do_prefetch; cpu_state <= cpu_state_exec; end endcase end else cpu_state <= cpu_state_ld_rs2; end endcase end cpu_state_ld_rs2: begin `debug($display("LD_RS2: %2d 0x%08x", decoded_rs2, cpuregs_rs2);) reg_sh <= cpuregs_rs2; reg_op2 <= cpuregs_rs2; dbg_rs2val <= cpuregs_rs2; dbg_rs2val_valid <= 1; (* parallel_case *) case (1'b1) WITH_PCPI && instr_trap: begin pcpi_valid <= 1; if (pcpi_int_ready) begin mem_do_rinst <= 1; pcpi_valid <= 0; reg_out <= pcpi_int_rd; latched_store <= pcpi_int_wr; cpu_state <= cpu_state_fetch; end else if (CATCH_ILLINSN && (pcpi_timeout || instr_ecall_ebreak)) begin pcpi_valid <= 0; `debug($display("EBREAK OR UNSUPPORTED INSN AT 0x%08x", reg_pc);) if (ENABLE_IRQ && !irq_mask[irq_ebreak] && !irq_active) begin next_irq_pending[irq_ebreak] = 1; cpu_state <= cpu_state_fetch; end else cpu_state <= cpu_state_trap; end end is_sb_sh_sw: begin cpu_state <= cpu_state_stmem; mem_do_rinst <= 1; end is_sll_srl_sra && !BARREL_SHIFTER: begin cpu_state <= cpu_state_shift; end default: begin if (TWO_CYCLE_ALU || (TWO_CYCLE_COMPARE && is_beq_bne_blt_bge_bltu_bgeu)) begin alu_wait_2 <= TWO_CYCLE_ALU && (TWO_CYCLE_COMPARE && is_beq_bne_blt_bge_bltu_bgeu); alu_wait <= 1; end else mem_do_rinst <= mem_do_prefetch; cpu_state <= cpu_state_exec; end endcase end cpu_state_exec: begin reg_out <= reg_pc + decoded_imm; if ((TWO_CYCLE_ALU || TWO_CYCLE_COMPARE) && (alu_wait || alu_wait_2)) begin mem_do_rinst <= mem_do_prefetch && !alu_wait_2; alu_wait <= alu_wait_2; end else if (is_beq_bne_blt_bge_bltu_bgeu) begin latched_rd <= 0; latched_store <= TWO_CYCLE_COMPARE ? alu_out_0_q : alu_out_0; latched_branch <= TWO_CYCLE_COMPARE ? alu_out_0_q : alu_out_0; if (mem_done) cpu_state <= cpu_state_fetch; if (TWO_CYCLE_COMPARE ? alu_out_0_q : alu_out_0) begin decoder_trigger <= 0; set_mem_do_rinst = 1; end end else begin latched_branch <= instr_jalr; latched_store <= 1; latched_stalu <= 1; cpu_state <= cpu_state_fetch; end end cpu_state_shift: begin latched_store <= 1; if (reg_sh == 0) begin reg_out <= reg_op1; mem_do_rinst <= mem_do_prefetch; cpu_state <= cpu_state_fetch; end else if (TWO_STAGE_SHIFT && reg_sh >= 4) begin (* parallel_case, full_case *) case (1'b1) instr_slli || instr_sll: reg_op1 <= reg_op1 << 4; instr_srli || instr_srl: reg_op1 <= reg_op1 >> 4; instr_srai || instr_sra: reg_op1 <= $signed(reg_op1) >>> 4; endcase reg_sh <= reg_sh - 4; end else begin (* parallel_case, full_case *) case (1'b1) instr_slli || instr_sll: reg_op1 <= reg_op1 << 1; instr_srli || instr_srl: reg_op1 <= reg_op1 >> 1; instr_srai || instr_sra: reg_op1 <= $signed(reg_op1) >>> 1; endcase reg_sh <= reg_sh - 1; end end cpu_state_stmem: begin if (ENABLE_TRACE) reg_out <= reg_op2; if (!mem_do_prefetch || mem_done) begin if (!mem_do_wdata) begin (* parallel_case, full_case *) case (1'b1) instr_sb: mem_wordsize <= 2; instr_sh: mem_wordsize <= 1; instr_sw: mem_wordsize <= 0; endcase if (ENABLE_TRACE) begin trace_valid <= 1; trace_data <= (irq_active ? TRACE_IRQ : 0) | TRACE_ADDR | ((reg_op1 + decoded_imm) & 32'hffffffff); end reg_op1 <= reg_op1 + decoded_imm; set_mem_do_wdata = 1; end if (!mem_do_prefetch && mem_done) begin cpu_state <= cpu_state_fetch; decoder_trigger <= 1; decoder_pseudo_trigger <= 1; end end end cpu_state_ldmem: begin latched_store <= 1; if (!mem_do_prefetch || mem_done) begin if (!mem_do_rdata) begin (* parallel_case, full_case *) case (1'b1) instr_lb || instr_lbu: mem_wordsize <= 2; instr_lh || instr_lhu: mem_wordsize <= 1; instr_lw: mem_wordsize <= 0; endcase latched_is_lu <= is_lbu_lhu_lw; latched_is_lh <= instr_lh; latched_is_lb <= instr_lb; if (ENABLE_TRACE) begin trace_valid <= 1; trace_data <= (irq_active ? TRACE_IRQ : 0) | TRACE_ADDR | ((reg_op1 + decoded_imm) & 32'hffffffff); end reg_op1 <= reg_op1 + decoded_imm; set_mem_do_rdata = 1; end if (!mem_do_prefetch && mem_done) begin (* parallel_case, full_case *) case (1'b1) latched_is_lu: reg_out <= mem_rdata_word; latched_is_lh: reg_out <= $signed(mem_rdata_word[15:0]); latched_is_lb: reg_out <= $signed(mem_rdata_word[7:0]); endcase decoder_trigger <= 1; decoder_pseudo_trigger <= 1; cpu_state <= cpu_state_fetch; end end end endcase if (CATCH_MISALIGN && resetn && (mem_do_rdata || mem_do_wdata)) begin if (mem_wordsize == 0 && reg_op1[1:0] != 0) begin `debug($display("MISALIGNED WORD: 0x%08x", reg_op1);) if (ENABLE_IRQ && !irq_mask[irq_buserror] && !irq_active) begin next_irq_pending[irq_buserror] = 1; end else cpu_state <= cpu_state_trap; end if (mem_wordsize == 1 && reg_op1[0] != 0) begin `debug($display("MISALIGNED HALFWORD: 0x%08x", reg_op1);) if (ENABLE_IRQ && !irq_mask[irq_buserror] && !irq_active) begin next_irq_pending[irq_buserror] = 1; end else cpu_state <= cpu_state_trap; end end if (CATCH_MISALIGN && resetn && mem_do_rinst && (COMPRESSED_ISA ? reg_pc[0] : |reg_pc[1:0])) begin `debug($display("MISALIGNED INSTRUCTION: 0x%08x", reg_pc);) if (ENABLE_IRQ && !irq_mask[irq_buserror] && !irq_active) begin next_irq_pending[irq_buserror] = 1; end else cpu_state <= cpu_state_trap; end if (!CATCH_ILLINSN && decoder_trigger_q && !decoder_pseudo_trigger_q && instr_ecall_ebreak) begin cpu_state <= cpu_state_trap; end if (!resetn || mem_done) begin mem_do_prefetch <= 0; mem_do_rinst <= 0; mem_do_rdata <= 0; mem_do_wdata <= 0; end if (set_mem_do_rinst) mem_do_rinst <= 1; if (set_mem_do_rdata) mem_do_rdata <= 1; if (set_mem_do_wdata) mem_do_wdata <= 1; irq_pending <= next_irq_pending & ~MASKED_IRQ; if (!CATCH_MISALIGN) begin if (COMPRESSED_ISA) begin reg_pc[0] <= 0; reg_next_pc[0] <= 0; end else begin reg_pc[1:0] <= 0; reg_next_pc[1:0] <= 0; end end current_pc = 'bx; end `ifdef RISCV_FORMAL reg dbg_irq_call; reg dbg_irq_enter; reg [31:0] dbg_irq_ret; always @(posedge clk) begin rvfi_valid <= resetn && (launch_next_insn || trap) && dbg_valid_insn; rvfi_order <= resetn ? rvfi_order + rvfi_valid : 0; rvfi_insn <= dbg_insn_opcode; rvfi_rs1_addr <= dbg_rs1val_valid ? dbg_insn_rs1 : 0; rvfi_rs2_addr <= dbg_rs2val_valid ? dbg_insn_rs2 : 0; rvfi_pc_rdata <= dbg_insn_addr; rvfi_rs1_rdata <= dbg_rs1val_valid ? dbg_rs1val : 0; rvfi_rs2_rdata <= dbg_rs2val_valid ? dbg_rs2val : 0; rvfi_trap <= trap; rvfi_halt <= trap; rvfi_intr <= dbg_irq_enter; rvfi_mode <= 3; if (!resetn) begin dbg_irq_call <= 0; dbg_irq_enter <= 0; end else if (rvfi_valid) begin dbg_irq_call <= 0; dbg_irq_enter <= dbg_irq_call; end else if (irq_state == 1) begin dbg_irq_call <= 1; dbg_irq_ret <= next_pc; end if (!resetn) begin rvfi_rd_addr <= 0; rvfi_rd_wdata <= 0; end else if (cpuregs_write && !irq_state) begin rvfi_rd_addr <= latched_rd; rvfi_rd_wdata <= latched_rd ? cpuregs_wrdata : 0; end else if (rvfi_valid) begin rvfi_rd_addr <= 0; rvfi_rd_wdata <= 0; end casez (dbg_insn_opcode) 32'b 0000000_?????_000??_???_?????_0001011: begin // getq rvfi_rs1_addr <= 0; rvfi_rs1_rdata <= 0; end 32'b 0000001_?????_?????_???_000??_0001011: begin // setq rvfi_rd_addr <= 0; rvfi_rd_wdata <= 0; end 32'b 0000010_?????_00000_???_00000_0001011: begin // retirq rvfi_rs1_addr <= 0; rvfi_rs1_rdata <= 0; end endcase if (!dbg_irq_call) begin if (dbg_mem_instr) begin rvfi_mem_addr <= 0; rvfi_mem_rmask <= 0; rvfi_mem_wmask <= 0; rvfi_mem_rdata <= 0; rvfi_mem_wdata <= 0; end else if (dbg_mem_valid && dbg_mem_ready) begin rvfi_mem_addr <= dbg_mem_addr; rvfi_mem_rmask <= dbg_mem_wstrb ? 0 : ~0; rvfi_mem_wmask <= dbg_mem_wstrb; rvfi_mem_rdata <= dbg_mem_rdata; rvfi_mem_wdata <= dbg_mem_wdata; end end end always @* begin rvfi_pc_wdata = dbg_irq_call ? dbg_irq_ret : dbg_insn_addr; end `endif // Formal Verification `ifdef FORMAL reg [3:0] last_mem_nowait; always @(posedge clk) last_mem_nowait <= {last_mem_nowait, mem_ready || !mem_valid}; // stall the memory interface for max 4 cycles restrict property (|last_mem_nowait || mem_ready || !mem_valid); // resetn low in first cycle, after that resetn high restrict property (resetn != $initstate); // this just makes it much easier to read traces. uncomment as needed. // assume property (mem_valid || !mem_ready); reg ok; always @* begin if (resetn) begin // instruction fetches are read-only if (mem_valid && mem_instr) assert (mem_wstrb == 0); // cpu_state must be valid ok = 0; if (cpu_state == cpu_state_trap) ok = 1; if (cpu_state == cpu_state_fetch) ok = 1; if (cpu_state == cpu_state_ld_rs1) ok = 1; if (cpu_state == cpu_state_ld_rs2) ok = !ENABLE_REGS_DUALPORT; if (cpu_state == cpu_state_exec) ok = 1; if (cpu_state == cpu_state_shift) ok = 1; if (cpu_state == cpu_state_stmem) ok = 1; if (cpu_state == cpu_state_ldmem) ok = 1; assert (ok); end end reg last_mem_la_read = 0; reg last_mem_la_write = 0; reg [31:0] last_mem_la_addr; reg [31:0] last_mem_la_wdata; reg [3:0] last_mem_la_wstrb = 0; always @(posedge clk) begin last_mem_la_read <= mem_la_read; last_mem_la_write <= mem_la_write; last_mem_la_addr <= mem_la_addr; last_mem_la_wdata <= mem_la_wdata; last_mem_la_wstrb <= mem_la_wstrb; if (last_mem_la_read) begin assert(mem_valid); assert(mem_addr == last_mem_la_addr); assert(mem_wstrb == 0); end if (last_mem_la_write) begin assert(mem_valid); assert(mem_addr == last_mem_la_addr); assert(mem_wdata == last_mem_la_wdata); assert(mem_wstrb == last_mem_la_wstrb); end if (mem_la_read || mem_la_write) begin assert(!mem_valid || mem_ready); end end `endif endmodule // This is a simple example implementation of PICORV32_REGS. // Use the PICORV32_REGS mechanism if you want to use custom // memory resources to implement the processor register file. // Note that your implementation must match the requirements of // the PicoRV32 configuration. (e.g. QREGS, etc) module picorv32_regs ( input clk, wen, input [5:0] waddr, input [5:0] raddr1, input [5:0] raddr2, input [31:0] wdata, output [31:0] rdata1, output [31:0] rdata2 ); reg [31:0] regs [0:30]; always @(posedge clk) if (wen) regs[~waddr[4:0]] <= wdata; assign rdata1 = regs[~raddr1[4:0]]; assign rdata2 = regs[~raddr2[4:0]]; endmodule /*************************************************************** * picorv32_pcpi_mul ***************************************************************/ module picorv32_pcpi_mul #( parameter STEPS_AT_ONCE = 1, parameter CARRY_CHAIN = 4 ) ( input clk, resetn, input pcpi_valid, input [31:0] pcpi_insn, input [31:0] pcpi_rs1, input [31:0] pcpi_rs2, output reg pcpi_wr, output reg [31:0] pcpi_rd, output reg pcpi_wait, output reg pcpi_ready ); reg instr_mul, instr_mulh, instr_mulhsu, instr_mulhu; wire instr_any_mul = |{instr_mul, instr_mulh, instr_mulhsu, instr_mulhu}; wire instr_any_mulh = |{instr_mulh, instr_mulhsu, instr_mulhu}; wire instr_rs1_signed = |{instr_mulh, instr_mulhsu}; wire instr_rs2_signed = |{instr_mulh}; reg pcpi_wait_q; wire mul_start = pcpi_wait && !pcpi_wait_q; always @(posedge clk) begin instr_mul <= 0; instr_mulh <= 0; instr_mulhsu <= 0; instr_mulhu <= 0; if (resetn && pcpi_valid && pcpi_insn[6:0] == 7'b0110011 && pcpi_insn[31:25] == 7'b0000001) begin case (pcpi_insn[14:12]) 3'b000: instr_mul <= 1; 3'b001: instr_mulh <= 1; 3'b010: instr_mulhsu <= 1; 3'b011: instr_mulhu <= 1; endcase end pcpi_wait <= instr_any_mul; pcpi_wait_q <= pcpi_wait; end reg [63:0] rs1, rs2, rd, rdx; reg [63:0] next_rs1, next_rs2, this_rs2; reg [63:0] next_rd, next_rdx, next_rdt; reg [6:0] mul_counter; reg mul_waiting; reg mul_finish; integer i, j; // carry save accumulator always @* begin next_rd = rd; next_rdx = rdx; next_rs1 = rs1; next_rs2 = rs2; for (i = 0; i < STEPS_AT_ONCE; i=i+1) begin this_rs2 = next_rs1[0] ? next_rs2 : 0; if (CARRY_CHAIN == 0) begin next_rdt = next_rd ^ next_rdx ^ this_rs2; next_rdx = ((next_rd & next_rdx) | (next_rd & this_rs2) | (next_rdx & this_rs2)) << 1; next_rd = next_rdt; end else begin next_rdt = 0; for (j = 0; j < 64; j = j + CARRY_CHAIN) {next_rdt[j+CARRY_CHAIN-1], next_rd[j +: CARRY_CHAIN]} = next_rd[j +: CARRY_CHAIN] + next_rdx[j +: CARRY_CHAIN] + this_rs2[j +: CARRY_CHAIN]; next_rdx = next_rdt << 1; end next_rs1 = next_rs1 >> 1; next_rs2 = next_rs2 << 1; end end always @(posedge clk) begin mul_finish <= 0; if (!resetn) begin mul_waiting <= 1; end else if (mul_waiting) begin if (instr_rs1_signed) rs1 <= $signed(pcpi_rs1); else rs1 <= $unsigned(pcpi_rs1); if (instr_rs2_signed) rs2 <= $signed(pcpi_rs2); else rs2 <= $unsigned(pcpi_rs2); rd <= 0; rdx <= 0; mul_counter <= (instr_any_mulh ? 63 - STEPS_AT_ONCE : 31 - STEPS_AT_ONCE); mul_waiting <= !mul_start; end else begin rd <= next_rd; rdx <= next_rdx; rs1 <= next_rs1; rs2 <= next_rs2; mul_counter <= mul_counter - STEPS_AT_ONCE; if (mul_counter[6]) begin mul_finish <= 1; mul_waiting <= 1; end end end always @(posedge clk) begin pcpi_wr <= 0; pcpi_ready <= 0; if (mul_finish && resetn) begin pcpi_wr <= 1; pcpi_ready <= 1; pcpi_rd <= instr_any_mulh ? rd >> 32 : rd; end end endmodule module picorv32_pcpi_fast_mul #( parameter EXTRA_MUL_FFS = 0, parameter EXTRA_INSN_FFS = 0, parameter MUL_CLKGATE = 0 ) ( input clk, resetn, input pcpi_valid, input [31:0] pcpi_insn, input [31:0] pcpi_rs1, input [31:0] pcpi_rs2, output pcpi_wr, output [31:0] pcpi_rd, output pcpi_wait, output pcpi_ready ); reg instr_mul, instr_mulh, instr_mulhsu, instr_mulhu; wire instr_any_mul = |{instr_mul, instr_mulh, instr_mulhsu, instr_mulhu}; wire instr_any_mulh = |{instr_mulh, instr_mulhsu, instr_mulhu}; wire instr_rs1_signed = |{instr_mulh, instr_mulhsu}; wire instr_rs2_signed = |{instr_mulh}; reg shift_out; reg [3:0] active; reg [32:0] rs1, rs2, rs1_q, rs2_q; reg [63:0] rd, rd_q; wire pcpi_insn_valid = pcpi_valid && pcpi_insn[6:0] == 7'b0110011 && pcpi_insn[31:25] == 7'b0000001; reg pcpi_insn_valid_q; always @* begin instr_mul = 0; instr_mulh = 0; instr_mulhsu = 0; instr_mulhu = 0; if (resetn && (EXTRA_INSN_FFS ? pcpi_insn_valid_q : pcpi_insn_valid)) begin case (pcpi_insn[14:12]) 3'b000: instr_mul = 1; 3'b001: instr_mulh = 1; 3'b010: instr_mulhsu = 1; 3'b011: instr_mulhu = 1; endcase end end always @(posedge clk) begin pcpi_insn_valid_q <= pcpi_insn_valid; if (!MUL_CLKGATE || active[0]) begin rs1_q <= rs1; rs2_q <= rs2; end if (!MUL_CLKGATE || active[1]) begin rd <= $signed(EXTRA_MUL_FFS ? rs1_q : rs1) * $signed(EXTRA_MUL_FFS ? rs2_q : rs2); end if (!MUL_CLKGATE || active[2]) begin rd_q <= rd; end end always @(posedge clk) begin if (instr_any_mul && !(EXTRA_MUL_FFS ? active[3:0] : active[1:0])) begin if (instr_rs1_signed) rs1 <= $signed(pcpi_rs1); else rs1 <= $unsigned(pcpi_rs1); if (instr_rs2_signed) rs2 <= $signed(pcpi_rs2); else rs2 <= $unsigned(pcpi_rs2); active[0] <= 1; end else begin active[0] <= 0; end active[3:1] <= active; shift_out <= instr_any_mulh; if (!resetn) active <= 0; end assign pcpi_wr = active[EXTRA_MUL_FFS ? 3 : 1]; assign pcpi_wait = 0; assign pcpi_ready = active[EXTRA_MUL_FFS ? 3 : 1]; `ifdef RISCV_FORMAL_ALTOPS assign pcpi_rd = instr_mul ? (pcpi_rs1 + pcpi_rs2) ^ 32'h5876063e : instr_mulh ? (pcpi_rs1 + pcpi_rs2) ^ 32'hf6583fb7 : instr_mulhsu ? (pcpi_rs1 - pcpi_rs2) ^ 32'hecfbe137 : instr_mulhu ? (pcpi_rs1 + pcpi_rs2) ^ 32'h949ce5e8 : 1'bx; `else assign pcpi_rd = shift_out ? (EXTRA_MUL_FFS ? rd_q : rd) >> 32 : (EXTRA_MUL_FFS ? rd_q : rd); `endif endmodule /*************************************************************** * picorv32_pcpi_div ***************************************************************/ module picorv32_pcpi_div ( input clk, resetn, input pcpi_valid, input [31:0] pcpi_insn, input [31:0] pcpi_rs1, input [31:0] pcpi_rs2, output reg pcpi_wr, output reg [31:0] pcpi_rd, output reg pcpi_wait, output reg pcpi_ready ); reg instr_div, instr_divu, instr_rem, instr_remu; wire instr_any_div_rem = |{instr_div, instr_divu, instr_rem, instr_remu}; reg pcpi_wait_q; wire start = pcpi_wait && !pcpi_wait_q; always @(posedge clk) begin instr_div <= 0; instr_divu <= 0; instr_rem <= 0; instr_remu <= 0; if (resetn && pcpi_valid && !pcpi_ready && pcpi_insn[6:0] == 7'b0110011 && pcpi_insn[31:25] == 7'b0000001) begin case (pcpi_insn[14:12]) 3'b100: instr_div <= 1; 3'b101: instr_divu <= 1; 3'b110: instr_rem <= 1; 3'b111: instr_remu <= 1; endcase end pcpi_wait <= instr_any_div_rem && resetn; pcpi_wait_q <= pcpi_wait && resetn; end reg [31:0] dividend; reg [62:0] divisor; reg [31:0] quotient; reg [31:0] quotient_msk; reg running; reg outsign; always @(posedge clk) begin pcpi_ready <= 0; pcpi_wr <= 0; pcpi_rd <= 'bx; if (!resetn) begin running <= 0; end else if (start) begin running <= 1; dividend <= (instr_div || instr_rem) && pcpi_rs1[31] ? -pcpi_rs1 : pcpi_rs1; divisor <= ((instr_div || instr_rem) && pcpi_rs2[31] ? -pcpi_rs2 : pcpi_rs2) << 31; outsign <= (instr_div && (pcpi_rs1[31] != pcpi_rs2[31]) && |pcpi_rs2) || (instr_rem && pcpi_rs1[31]); quotient <= 0; quotient_msk <= 1 << 31; end else if (!quotient_msk && running) begin running <= 0; pcpi_ready <= 1; pcpi_wr <= 1; `ifdef RISCV_FORMAL_ALTOPS case (1) instr_div: pcpi_rd <= (pcpi_rs1 - pcpi_rs2) ^ 32'h7f8529ec; instr_divu: pcpi_rd <= (pcpi_rs1 - pcpi_rs2) ^ 32'h10e8fd70; instr_rem: pcpi_rd <= (pcpi_rs1 - pcpi_rs2) ^ 32'h8da68fa5; instr_remu: pcpi_rd <= (pcpi_rs1 - pcpi_rs2) ^ 32'h3138d0e1; endcase `else if (instr_div || instr_divu) pcpi_rd <= outsign ? -quotient : quotient; else pcpi_rd <= outsign ? -dividend : dividend; `endif end else begin if (divisor <= dividend) begin dividend <= dividend - divisor; quotient <= quotient | quotient_msk; end divisor <= divisor >> 1; `ifdef RISCV_FORMAL_ALTOPS quotient_msk <= quotient_msk >> 5; `else quotient_msk <= quotient_msk >> 1; `endif end end endmodule //*************************************************************** //* picorv32_axi //***************************************************************//* module picoaxi #( parameter [ 0:0] ENABLE_COUNTERS = 1, parameter [ 0:0] ENABLE_COUNTERS64 = 1, parameter [ 0:0] ENABLE_REGS_16_31 = 1, parameter [ 0:0] ENABLE_REGS_DUALPORT = 1, parameter [ 0:0] TWO_STAGE_SHIFT = 1, parameter [ 0:0] BARREL_SHIFTER = 0, parameter [ 0:0] TWO_CYCLE_COMPARE = 0, parameter [ 0:0] TWO_CYCLE_ALU = 0, parameter [ 0:0] COMPRESSED_ISA = 0, parameter [ 0:0] CATCH_MISALIGN = 1, parameter [ 0:0] CATCH_ILLINSN = 1, parameter [ 0:0] ENABLE_PCPI = 0, parameter [ 0:0] ENABLE_MUL = 0, parameter [ 0:0] ENABLE_FAST_MUL = 0, parameter [ 0:0] ENABLE_DIV = 0, parameter [ 0:0] ENABLE_IRQ = 0, parameter [ 0:0] ENABLE_IRQ_QREGS = 1, parameter [ 0:0] ENABLE_IRQ_TIMER = 1, parameter [ 0:0] ENABLE_TRACE = 0, parameter [ 0:0] REGS_INIT_ZERO = 0, parameter [31:0] MASKED_IRQ = 32'h 0000_0000, parameter [31:0] LATCHED_IRQ = 32'h ffff_ffff, parameter [31:0] PROGADDR_RESET = 32'h 0000_0000, parameter [31:0] PROGADDR_IRQ = 32'h 0000_0010, parameter [31:0] STACKADDR = 32'h ffff_ffff ) ( input clk_i, rst_i, output trap, // AXI4-lite master memory interface output mem_axi_awvalid, input mem_axi_awready, output [31:0] mem_axi_awaddr, output [ 2:0] mem_axi_awprot, output mem_axi_wvalid, input mem_axi_wready, output [31:0] mem_axi_wdata, output [ 3:0] mem_axi_wstrb, input mem_axi_bvalid, output mem_axi_bready, output mem_axi_arvalid, input mem_axi_arready, output [31:0] mem_axi_araddr, output [ 2:0] mem_axi_arprot, input mem_axi_rvalid, output mem_axi_rready, input [31:0] mem_axi_rdata, // Pico Co-Processor Interface (PCPI) output pcpi_valid, output [31:0] pcpi_insn, output [31:0] pcpi_rs1, output [31:0] pcpi_rs2, input pcpi_wr, input [31:0] pcpi_rd, input pcpi_wait, input pcpi_ready, // IRQ interface input [31:0] irq, output [31:0] eoi, `ifdef RISCV_FORMAL output rvfi_valid, output [63:0] rvfi_order, output [31:0] rvfi_insn, output rvfi_trap, output rvfi_halt, output rvfi_intr, output [ 4:0] rvfi_rs1_addr, output [ 4:0] rvfi_rs2_addr, output [31:0] rvfi_rs1_rdata, output [31:0] rvfi_rs2_rdata, output [ 4:0] rvfi_rd_addr, output [31:0] rvfi_rd_wdata, output [31:0] rvfi_pc_rdata, output [31:0] rvfi_pc_wdata, output [31:0] rvfi_mem_addr, output [ 3:0] rvfi_mem_rmask, output [ 3:0] rvfi_mem_wmask, output [31:0] rvfi_mem_rdata, output [31:0] rvfi_mem_wdata, `endif // Trace Interface output trace_valid, output [35:0] trace_data ); wire mem_valid; wire [31:0] mem_addr; wire [31:0] mem_wdata; wire [ 3:0] mem_wstrb; wire mem_instr; wire mem_ready; wire [31:0] mem_rdata; picorv32_axi_adapter axi_adapter ( .clk (clk_i ), .resetn (rst_i ), .mem_axi_awvalid(mem_axi_awvalid), .mem_axi_awready(mem_axi_awready), .mem_axi_awaddr (mem_axi_awaddr ), .mem_axi_awprot (mem_axi_awprot ), .mem_axi_wvalid (mem_axi_wvalid ), .mem_axi_wready (mem_axi_wready ), .mem_axi_wdata (mem_axi_wdata ), .mem_axi_wstrb (mem_axi_wstrb ), .mem_axi_bvalid (mem_axi_bvalid ), .mem_axi_bready (mem_axi_bready ), .mem_axi_arvalid(mem_axi_arvalid), .mem_axi_arready(mem_axi_arready), .mem_axi_araddr (mem_axi_araddr ), .mem_axi_arprot (mem_axi_arprot ), .mem_axi_rvalid (mem_axi_rvalid ), .mem_axi_rready (mem_axi_rready ), .mem_axi_rdata (mem_axi_rdata ), .mem_valid (mem_valid ), .mem_instr (mem_instr ), .mem_ready (mem_ready ), .mem_addr (mem_addr ), .mem_wdata (mem_wdata ), .mem_wstrb (mem_wstrb ), .mem_rdata (mem_rdata ) ); picorv32 #( .ENABLE_COUNTERS (ENABLE_COUNTERS ), .ENABLE_COUNTERS64 (ENABLE_COUNTERS64 ), .ENABLE_REGS_16_31 (ENABLE_REGS_16_31 ), .ENABLE_REGS_DUALPORT(ENABLE_REGS_DUALPORT), .TWO_STAGE_SHIFT (TWO_STAGE_SHIFT ), .BARREL_SHIFTER (BARREL_SHIFTER ), .TWO_CYCLE_COMPARE (TWO_CYCLE_COMPARE ), .TWO_CYCLE_ALU (TWO_CYCLE_ALU ), .COMPRESSED_ISA (COMPRESSED_ISA ), .CATCH_MISALIGN (CATCH_MISALIGN ), .CATCH_ILLINSN (CATCH_ILLINSN ), .ENABLE_PCPI (ENABLE_PCPI ), .ENABLE_MUL (ENABLE_MUL ), .ENABLE_FAST_MUL (ENABLE_FAST_MUL ), .ENABLE_DIV (ENABLE_DIV ), .ENABLE_IRQ (ENABLE_IRQ ), .ENABLE_IRQ_QREGS (ENABLE_IRQ_QREGS ), .ENABLE_IRQ_TIMER (ENABLE_IRQ_TIMER ), .ENABLE_TRACE (ENABLE_TRACE ), .REGS_INIT_ZERO (REGS_INIT_ZERO ), .MASKED_IRQ (MASKED_IRQ ), .LATCHED_IRQ (LATCHED_IRQ ), .PROGADDR_RESET (PROGADDR_RESET ), .PROGADDR_IRQ (PROGADDR_IRQ ), .STACKADDR (STACKADDR ) ) picorv32_core ( .clk (clk ), .resetn (resetn), .trap (trap ), .mem_valid(mem_valid), .mem_addr (mem_addr ), .mem_wdata(mem_wdata), .mem_wstrb(mem_wstrb), .mem_instr(mem_instr), .mem_ready(mem_ready), .mem_rdata(mem_rdata), .pcpi_valid(pcpi_valid), .pcpi_insn (pcpi_insn ), .pcpi_rs1 (pcpi_rs1 ), .pcpi_rs2 (pcpi_rs2 ), .pcpi_wr (pcpi_wr ), .pcpi_rd (pcpi_rd ), .pcpi_wait (pcpi_wait ), .pcpi_ready(pcpi_ready), .irq(irq), .eoi(eoi), `ifdef RISCV_FORMAL .rvfi_valid (rvfi_valid ), .rvfi_order (rvfi_order ), .rvfi_insn (rvfi_insn ), .rvfi_trap (rvfi_trap ), .rvfi_halt (rvfi_halt ), .rvfi_intr (rvfi_intr ), .rvfi_rs1_addr (rvfi_rs1_addr ), .rvfi_rs2_addr (rvfi_rs2_addr ), .rvfi_rs1_rdata(rvfi_rs1_rdata), .rvfi_rs2_rdata(rvfi_rs2_rdata), .rvfi_rd_addr (rvfi_rd_addr ), .rvfi_rd_wdata (rvfi_rd_wdata ), .rvfi_pc_rdata (rvfi_pc_rdata ), .rvfi_pc_wdata (rvfi_pc_wdata ), .rvfi_mem_addr (rvfi_mem_addr ), .rvfi_mem_rmask(rvfi_mem_rmask), .rvfi_mem_wmask(rvfi_mem_wmask), .rvfi_mem_rdata(rvfi_mem_rdata), .rvfi_mem_wdata(rvfi_mem_wdata), `endif .trace_valid(trace_valid), .trace_data (trace_data) ); endmodule //*//*************************************************************** // * picorv32_axi_adapter // ***************************************************************//* module picorv32_axi_adapter ( input clk, resetn, // AXI4-lite master memory interface output mem_axi_awvalid, input mem_axi_awready, output [31:0] mem_axi_awaddr, output [ 2:0] mem_axi_awprot, output mem_axi_wvalid, input mem_axi_wready, output [31:0] mem_axi_wdata, output [ 3:0] mem_axi_wstrb, input mem_axi_bvalid, output mem_axi_bready, output mem_axi_arvalid, input mem_axi_arready, output [31:0] mem_axi_araddr, output [ 2:0] mem_axi_arprot, input mem_axi_rvalid, output mem_axi_rready, input [31:0] mem_axi_rdata, // Native PicoRV32 memory interface input mem_valid, input mem_instr, output mem_ready, input [31:0] mem_addr, input [31:0] mem_wdata, input [ 3:0] mem_wstrb, output [31:0] mem_rdata ); reg ack_awvalid; reg ack_arvalid; reg ack_wvalid; reg xfer_done; assign mem_axi_awvalid = mem_valid && |mem_wstrb && !ack_awvalid; assign mem_axi_awaddr = mem_addr; assign mem_axi_awprot = 0; assign mem_axi_arvalid = mem_valid && !mem_wstrb && !ack_arvalid; assign mem_axi_araddr = mem_addr; assign mem_axi_arprot = mem_instr ? 3'b100 : 3'b000; assign mem_axi_wvalid = mem_valid && |mem_wstrb && !ack_wvalid; assign mem_axi_wdata = mem_wdata; assign mem_axi_wstrb = mem_wstrb; assign mem_ready = mem_axi_bvalid || mem_axi_rvalid; assign mem_axi_bready = mem_valid && |mem_wstrb; assign mem_axi_rready = mem_valid && !mem_wstrb; assign mem_rdata = mem_axi_rdata; always @(posedge clk) begin if (!resetn) begin ack_awvalid <= 0; end else begin xfer_done <= mem_valid && mem_ready; if (mem_axi_awready && mem_axi_awvalid) ack_awvalid <= 1; if (mem_axi_arready && mem_axi_arvalid) ack_arvalid <= 1; if (mem_axi_wready && mem_axi_wvalid) ack_wvalid <= 1; if (xfer_done || !mem_valid) begin ack_awvalid <= 0; ack_arvalid <= 0; ack_wvalid <= 0; end end end endmodule //*//*************************************************************** //* picorv32_wb //***************************************************************//* module picorv32_wb #( parameter [ 0:0] ENABLE_COUNTERS = 1, parameter [ 0:0] ENABLE_COUNTERS64 = 1, parameter [ 0:0] ENABLE_REGS_16_31 = 1, parameter [ 0:0] ENABLE_REGS_DUALPORT = 1, parameter [ 0:0] TWO_STAGE_SHIFT = 1, parameter [ 0:0] BARREL_SHIFTER = 0, parameter [ 0:0] TWO_CYCLE_COMPARE = 0, parameter [ 0:0] TWO_CYCLE_ALU = 0, parameter [ 0:0] COMPRESSED_ISA = 0, parameter [ 0:0] CATCH_MISALIGN = 1, parameter [ 0:0] CATCH_ILLINSN = 1, parameter [ 0:0] ENABLE_PCPI = 0, parameter [ 0:0] ENABLE_MUL = 0, parameter [ 0:0] ENABLE_FAST_MUL = 0, parameter [ 0:0] ENABLE_DIV = 0, parameter [ 0:0] ENABLE_IRQ = 0, parameter [ 0:0] ENABLE_IRQ_QREGS = 1, parameter [ 0:0] ENABLE_IRQ_TIMER = 1, parameter [ 0:0] ENABLE_TRACE = 0, parameter [ 0:0] REGS_INIT_ZERO = 0, parameter [31:0] MASKED_IRQ = 32'h 0000_0000, parameter [31:0] LATCHED_IRQ = 32'h ffff_ffff, parameter [31:0] PROGADDR_RESET = 32'h 0000_0000, parameter [31:0] PROGADDR_IRQ = 32'h 0000_0010, parameter [31:0] STACKADDR = 32'h ffff_ffff ) ( output trap, // Wishbone interfaces input wb_rst_i, input wb_clk_i, output reg [31:0] wbm_adr_o, output reg [31:0] wbm_dat_o, input [31:0] wbm_dat_i, output reg wbm_we_o, output reg [3:0] wbm_sel_o, output reg wbm_stb_o, input wbm_ack_i, output reg wbm_cyc_o, // Pico Co-Processor Interface (PCPI) output pcpi_valid, output [31:0] pcpi_insn, output [31:0] pcpi_rs1, output [31:0] pcpi_rs2, input pcpi_wr, input [31:0] pcpi_rd, input pcpi_wait, input pcpi_ready, // IRQ interface input [31:0] irq, output [31:0] eoi, `ifdef RISCV_FORMAL output rvfi_valid, output [63:0] rvfi_order, output [31:0] rvfi_insn, output rvfi_trap, output rvfi_halt, output rvfi_intr, output [ 4:0] rvfi_rs1_addr, output [ 4:0] rvfi_rs2_addr, output [31:0] rvfi_rs1_rdata, output [31:0] rvfi_rs2_rdata, output [ 4:0] rvfi_rd_addr, output [31:0] rvfi_rd_wdata, output [31:0] rvfi_pc_rdata, output [31:0] rvfi_pc_wdata, output [31:0] rvfi_mem_addr, output [ 3:0] rvfi_mem_rmask, output [ 3:0] rvfi_mem_wmask, output [31:0] rvfi_mem_rdata, output [31:0] rvfi_mem_wdata, `endif // Trace Interface output trace_valid, output [35:0] trace_data, output mem_instr ); wire mem_valid; wire [31:0] mem_addr; wire [31:0] mem_wdata; wire [ 3:0] mem_wstrb; reg mem_ready; reg [31:0] mem_rdata; wire clk; wire resetn; assign clk = wb_clk_i; assign resetn = ~wb_rst_i; picorv32 #( .ENABLE_COUNTERS (ENABLE_COUNTERS ), .ENABLE_COUNTERS64 (ENABLE_COUNTERS64 ), .ENABLE_REGS_16_31 (ENABLE_REGS_16_31 ), .ENABLE_REGS_DUALPORT(ENABLE_REGS_DUALPORT), .TWO_STAGE_SHIFT (TWO_STAGE_SHIFT ), .BARREL_SHIFTER (BARREL_SHIFTER ), .TWO_CYCLE_COMPARE (TWO_CYCLE_COMPARE ), .TWO_CYCLE_ALU (TWO_CYCLE_ALU ), .COMPRESSED_ISA (COMPRESSED_ISA ), .CATCH_MISALIGN (CATCH_MISALIGN ), .CATCH_ILLINSN (CATCH_ILLINSN ), .ENABLE_PCPI (ENABLE_PCPI ), .ENABLE_MUL (ENABLE_MUL ), .ENABLE_FAST_MUL (ENABLE_FAST_MUL ), .ENABLE_DIV (ENABLE_DIV ), .ENABLE_IRQ (ENABLE_IRQ ), .ENABLE_IRQ_QREGS (ENABLE_IRQ_QREGS ), .ENABLE_IRQ_TIMER (ENABLE_IRQ_TIMER ), .ENABLE_TRACE (ENABLE_TRACE ), .REGS_INIT_ZERO (REGS_INIT_ZERO ), .MASKED_IRQ (MASKED_IRQ ), .LATCHED_IRQ (LATCHED_IRQ ), .PROGADDR_RESET (PROGADDR_RESET ), .PROGADDR_IRQ (PROGADDR_IRQ ), .STACKADDR (STACKADDR ) ) picorv32_core ( .clk (clk ), .resetn (resetn), .trap (trap ), .mem_valid(mem_valid), .mem_addr (mem_addr ), .mem_wdata(mem_wdata), .mem_wstrb(mem_wstrb), .mem_instr(mem_instr), .mem_ready(mem_ready), .mem_rdata(mem_rdata), .pcpi_valid(pcpi_valid), .pcpi_insn (pcpi_insn ), .pcpi_rs1 (pcpi_rs1 ), .pcpi_rs2 (pcpi_rs2 ), .pcpi_wr (pcpi_wr ), .pcpi_rd (pcpi_rd ), .pcpi_wait (pcpi_wait ), .pcpi_ready(pcpi_ready), .irq(irq), .eoi(eoi), `ifdef RISCV_FORMAL .rvfi_valid (rvfi_valid ), .rvfi_order (rvfi_order ), .rvfi_insn (rvfi_insn ), .rvfi_trap (rvfi_trap ), .rvfi_halt (rvfi_halt ), .rvfi_intr (rvfi_intr ), .rvfi_rs1_addr (rvfi_rs1_addr ), .rvfi_rs2_addr (rvfi_rs2_addr ), .rvfi_rs1_rdata(rvfi_rs1_rdata), .rvfi_rs2_rdata(rvfi_rs2_rdata), .rvfi_rd_addr (rvfi_rd_addr ), .rvfi_rd_wdata (rvfi_rd_wdata ), .rvfi_pc_rdata (rvfi_pc_rdata ), .rvfi_pc_wdata (rvfi_pc_wdata ), .rvfi_mem_addr (rvfi_mem_addr ), .rvfi_mem_rmask(rvfi_mem_rmask), .rvfi_mem_wmask(rvfi_mem_wmask), .rvfi_mem_rdata(rvfi_mem_rdata), .rvfi_mem_wdata(rvfi_mem_wdata), `endif .trace_valid(trace_valid), .trace_data (trace_data) ); localparam IDLE = 2'b00; localparam WBSTART = 2'b01; localparam WBEND = 2'b10; reg [1:0] state; wire we; assign we = (mem_wstrb[0] | mem_wstrb[1] | mem_wstrb[2] | mem_wstrb[3]); always @(posedge wb_clk_i) begin if (wb_rst_i) begin wbm_adr_o <= 0; wbm_dat_o <= 0; wbm_we_o <= 0; wbm_sel_o <= 0; wbm_stb_o <= 0; wbm_cyc_o <= 0; state <= IDLE; end else begin case (state) IDLE: begin if (mem_valid) begin wbm_adr_o <= mem_addr; wbm_dat_o <= mem_wdata; wbm_we_o <= we; wbm_sel_o <= mem_wstrb; wbm_stb_o <= 1'b1; wbm_cyc_o <= 1'b1; state <= WBSTART; end else begin mem_ready <= 1'b0; wbm_stb_o <= 1'b0; wbm_cyc_o <= 1'b0; wbm_we_o <= 1'b0; end end WBSTART:begin if (wbm_ack_i) begin mem_rdata <= wbm_dat_i; mem_ready <= 1'b1; state <= WBEND; wbm_stb_o <= 1'b0; wbm_cyc_o <= 1'b0; wbm_we_o <= 1'b0; end end WBEND: begin mem_ready <= 1'b0; state <= IDLE; end default: state <= IDLE; endcase end end endmodule
module wbram_top_axi4lite #( parameter MEMORY_SIZE = 32'h0002_0000 )( // Clock & Reset input logic clk_i, input logic rst_ni, // AXI4-Lite Slave Interface AXI_LITE.Slave slave ); // Clocks and resets wire wb_clk; wire wb_rst; wire [slave.AXI_ADDR_WIDTH - 1:0] wbs_ram_adr_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_ram_dat_i; wire [3:0] wbs_ram_sel_i; wire wbs_ram_we_i; wire wbs_ram_cyc_i; wire wbs_ram_stb_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_ram_dat_o; wire wbs_ram_ack_o; // Instantiate the AXI4Lite to Wishbone bridge bonfire_axi4l2wb #( .ADRWIDTH (slave.AXI_ADDR_WIDTH), .FAST_READ_TERM (1'd0) ) bonfire_axi4l2wb_inst ( .S_AXI_ACLK (clk_i), .S_AXI_ARESETN (rst_ni), .S_AXI_AWADDR (slave.aw_addr), .S_AXI_AWVALID (slave.aw_valid), .S_AXI_AWREADY (slave.aw_ready), .S_AXI_WDATA (slave.w_data), .S_AXI_WSTRB (slave.w_strb), .S_AXI_WVALID (slave.w_valid), .S_AXI_WREADY (slave.w_ready), .S_AXI_ARADDR (slave.ar_addr), .S_AXI_ARVALID (slave.ar_valid), .S_AXI_ARREADY (slave.ar_ready), .S_AXI_RDATA (slave.r_data), .S_AXI_RRESP (slave.r_resp), .S_AXI_RVALID (slave.r_valid), .S_AXI_RREADY (slave.r_ready), .S_AXI_BRESP (slave.b_resp), .S_AXI_BVALID (slave.b_valid), .S_AXI_BREADY (slave.b_ready), .wb_clk_o (wb_clk), .wb_rst_o (wb_rst), .wb_addr_o (wbs_ram_adr_i), .wb_dat_o (wbs_ram_dat_i), .wb_we_o (wbs_ram_we_i), .wb_sel_o (wbs_ram_sel_i), .wb_stb_o (wbs_ram_stb_i), .wb_cyc_o (wbs_ram_cyc_i), .wb_dat_i (wbs_ram_dat_o), .wb_ack_i (wbs_ram_ack_o) ); // Instantiate the SRAM block `ifndef SRAM_INITIALIZATION_FILE `define SRAM_INITIALIZATION_FILE "sram.vmem" `endif wbram #( .memfile (`SRAM_INITIALIZATION_FILE) ) wbram_inst ( .wb_clk_i (wb_clk), .wb_rst_i (wb_rst), .wb_adr_i (wbs_ram_adr_i), .wb_dat_i (wbs_ram_dat_i), .wb_sel_i (wbs_ram_sel_i), .wb_cyc_i (wbs_ram_cyc_i), .wb_stb_i (wbs_ram_stb_i), .wb_we_i (wbs_ram_we_i), .wb_ack_o (wbs_ram_ack_o), .wb_dat_o (wbs_ram_dat_o) ); endmodule // end aes_top_axi4lite
module wbram #( parameter depth = 256, parameter memfile = "", parameter VERBOSE = 0 ) ( input wb_clk_i, input wb_rst_i, input [31:0] wb_adr_i, input [31:0] wb_dat_i, input [3:0] wb_sel_i, input wb_we_i, input wb_cyc_i, input wb_stb_i, output reg wb_ack_o, output reg [31:0] wb_dat_o ); reg mem_instr; reg tests_passed; reg verbose; initial verbose = $test$plusargs("verbose") || VERBOSE; initial tests_passed = 0; reg [31:0] adr_r; wire valid = wb_cyc_i & wb_stb_i; always @(posedge wb_clk_i) begin adr_r <= wb_adr_i; // Ack generation wb_ack_o <= valid & !wb_ack_o; if (wb_rst_i) begin adr_r <= {32{1'b0}}; wb_ack_o <= 1'b0; end end wire ram_we = wb_we_i & valid & wb_ack_o; wire [31:0] waddr = adr_r[31:2]; wire [31:0] raddr = wb_adr_i[31:2]; wire [3:0] we = {4{ram_we}} & wb_sel_i; wire [$clog2(depth/4)-1:0] raddr2 = raddr[$clog2(depth/4)-1:0]; wire [$clog2(depth/4)-1:0] waddr2 = waddr[$clog2(depth/4)-1:0]; reg [31:0] mem [0:depth/4-1] /* verilator public */; always @(posedge wb_clk_i) begin if (ram_we) begin if (verbose) $display("WR: ADDR=%08x DATA=%08x STRB=%04b", adr_r, wb_dat_i, we); if (adr_r[31:0] == 32'h1000_0000) if (verbose) begin if (32 <= wb_dat_i[7:0] && wb_dat_i[7:0] < 128) $display("OUT: '%c'", wb_dat_i[7:0]); else $display("OUT: %3d", wb_dat_i[7:0]); end else begin $write("%c", wb_dat_i[7:0]); `ifndef VERILATOR $fflush(); `endif end else if (adr_r[31:0] == 32'h2000_0000) if (wb_dat_i[31:0] == 123456789) tests_passed = 1; end end always @(posedge wb_clk_i) begin if (waddr2 < 128 * 1024 / 4) begin if (we[0]) mem[waddr2][7:0] <= wb_dat_i[7:0]; if (we[1]) mem[waddr2][15:8] <= wb_dat_i[15:8]; if (we[2]) mem[waddr2][23:16] <= wb_dat_i[23:16]; if (we[3]) mem[waddr2][31:24] <= wb_dat_i[31:24]; end if (valid & wb_ack_o & !ram_we) if (verbose) $display("RD: ADDR=%08x DATA=%08x%s", adr_r, mem[raddr2], mem_instr ? " INSN" : ""); wb_dat_o <= mem[raddr2]; end initial begin if (memfile != "") $readmemh(memfile, mem); end endmodule
module wbram #( parameter depth = 256, parameter memfile = "", parameter VERBOSE = 0 ) ( input wb_clk_i, input wb_rst_i, input [31:0] wb_adr_i, input [31:0] wb_dat_i, input [3:0] wb_sel_i, input wb_we_i, input wb_cyc_i, input wb_stb_i, output reg wb_ack_o, output reg [31:0] wb_dat_o ); reg mem_instr; reg tests_passed; reg verbose; initial verbose = $test$plusargs("verbose") || VERBOSE; initial tests_passed = 0; reg [31:0] adr_r; wire valid = wb_cyc_i & wb_stb_i; always @(posedge wb_clk_i) begin adr_r <= wb_adr_i; // Ack generation wb_ack_o <= valid & !wb_ack_o; if (wb_rst_i) begin adr_r <= {32{1'b0}}; wb_ack_o <= 1'b0; end end wire ram_we = wb_we_i & valid & wb_ack_o; wire [31:0] waddr = adr_r[31:2]; wire [31:0] raddr = wb_adr_i[31:2]; wire [3:0] we = {4{ram_we}} & wb_sel_i; wire [$clog2(depth/4)-1:0] raddr2 = raddr[$clog2(depth/4)-1:0]; wire [$clog2(depth/4)-1:0] waddr2 = waddr[$clog2(depth/4)-1:0]; reg [31:0] mem [0:depth/4-1] /* verilator public */; always @(posedge wb_clk_i) begin if (ram_we) begin if (verbose) $display("WR: ADDR=%08x DATA=%08x STRB=%04b", adr_r, wb_dat_i, we); if (adr_r[31:0] == 32'h1000_0000) if (verbose) begin if (32 <= wb_dat_i[7:0] && wb_dat_i[7:0] < 128) $display("OUT: '%c'", wb_dat_i[7:0]); else $display("OUT: %3d", wb_dat_i[7:0]); end else begin $write("%c", wb_dat_i[7:0]); `ifndef VERILATOR $fflush(); `endif end else if (adr_r[31:0] == 32'h2000_0000) if (wb_dat_i[31:0] == 123456789) tests_passed = 1; end end always @(posedge wb_clk_i) begin if (waddr2 < 128 * 1024 / 4) begin if (we[0]) mem[waddr2][7:0] <= wb_dat_i[7:0]; if (we[1]) mem[waddr2][15:8] <= wb_dat_i[15:8]; if (we[2]) mem[waddr2][23:16] <= wb_dat_i[23:16]; if (we[3]) mem[waddr2][31:24] <= wb_dat_i[31:24]; end if (valid & wb_ack_o & !ram_we) if (verbose) $display("RD: ADDR=%08x DATA=%08x%s", adr_r, mem[raddr2], mem_instr ? " INSN" : ""); wb_dat_o <= mem[raddr2]; end initial begin if (memfile != "") $readmemh(memfile, mem); end endmodule
module ram_top_axi4lite #( parameter MEMORY_SIZE = 32'h0002_0000 )( // Clock & Reset input logic clk_i, input logic rst_ni, // AXI4-Lite Slave Interface AXI_LITE.Slave slave ); // Clocks and resets wire wb_clk; wire wb_rst; wire [slave.AXI_ADDR_WIDTH - 1:0] wbs_ram_adr_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_ram_dat_i; wire [3:0] wbs_ram_sel_i; wire wbs_ram_we_i; wire wbs_ram_cyc_i; wire wbs_ram_stb_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_ram_dat_o; wire wbs_ram_ack_o; // Instantiate the AXI4Lite to Wishbone bridge bonfire_axi4l2wb #( .ADRWIDTH (slave.AXI_ADDR_WIDTH), .FAST_READ_TERM (1'd0) ) bonfire_axi4l2wb_inst ( .S_AXI_ACLK (clk_i), .S_AXI_ARESETN (rst_ni), .S_AXI_AWADDR (slave.aw_addr), .S_AXI_AWVALID (slave.aw_valid), .S_AXI_AWREADY (slave.aw_ready), .S_AXI_WDATA (slave.w_data), .S_AXI_WSTRB (slave.w_strb), .S_AXI_WVALID (slave.w_valid), .S_AXI_WREADY (slave.w_ready), .S_AXI_ARADDR (slave.ar_addr), .S_AXI_ARVALID (slave.ar_valid), .S_AXI_ARREADY (slave.ar_ready), .S_AXI_RDATA (slave.r_data), .S_AXI_RRESP (slave.r_resp), .S_AXI_RVALID (slave.r_valid), .S_AXI_RREADY (slave.r_ready), .S_AXI_BRESP (slave.b_resp), .S_AXI_BVALID (slave.b_valid), .S_AXI_BREADY (slave.b_ready), .wb_clk_o (wb_clk), .wb_rst_o (wb_rst), .wb_addr_o (wbs_ram_adr_i), .wb_dat_o (wbs_ram_dat_i), .wb_we_o (wbs_ram_we_i), .wb_sel_o (wbs_ram_sel_i), .wb_stb_o (wbs_ram_stb_i), .wb_cyc_o (wbs_ram_cyc_i), .wb_dat_i (wbs_ram_dat_o), .wb_ack_i (wbs_ram_ack_o) ); // Instantiate the SRAM block `ifndef SRAM_INITIALIZATION_FILE `define SRAM_INITIALIZATION_FILE "sram.vmem" `endif wbram #( .memfile (`SRAM_INITIALIZATION_FILE) ) wbram_inst ( .wb_clk_i (wb_clk), .wb_rst_i (wb_rst), .wb_adr_i (wbs_ram_adr_i), .wb_dat_i (wbs_ram_dat_i), .wb_sel_i (wbs_ram_sel_i), .wb_cyc_i (wbs_ram_cyc_i), .wb_stb_i (wbs_ram_stb_i), .wb_we_i (wbs_ram_we_i), .wb_ack_o (wbs_ram_ack_o), .wb_dat_o (wbs_ram_dat_o) ); endmodule // end aes_top_axi4lite
//------------------------------------------------------------------ // Simulator directives. //------------------------------------------------------------------ `timescale 1ns/100ps //------------------------------------------------------------------ // Test module. //------------------------------------------------------------------ module tb_modexp(); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- // Debug output control. parameter DEBUG = 0; parameter VCD = 1; // Clock defines. localparam CLK_HALF_PERIOD = 1; localparam CLK_PERIOD = 2 * CLK_HALF_PERIOD; // Address defines localparam OPERAND_WIDTH = 32; localparam ADDRESS_WIDTH = 8; localparam ADDR_NAME0 = 8'h00; localparam ADDR_NAME1 = 8'h01; localparam ADDR_VERSION = 8'h02; localparam ADDR_CTRL = 8'h08; localparam CTRL_INIT_BIT = 0; localparam CTRL_NEXT_BIT = 1; localparam ADDR_STATUS = 8'h09; localparam STATUS_READY_BIT = 0; localparam ADDR_CYCLES_HIGH = 8'h10; localparam ADDR_CYCLES_LOW = 8'h11; localparam ADDR_MODULUS_LENGTH = 8'h20; localparam ADDR_EXPONENT_LENGTH = 8'h21; localparam ADDR_MODULUS_PTR_RST = 8'h30; localparam ADDR_MODULUS_DATA = 8'h31; localparam ADDR_EXPONENT_PTR_RST = 8'h40; localparam ADDR_EXPONENT_DATA = 8'h41; localparam ADDR_MESSAGE_PTR_RST = 8'h50; localparam ADDR_MESSAGE_DATA = 8'h51; localparam ADDR_RESULT_PTR_RST = 8'h60; localparam ADDR_RESULT_DATA = 8'h61; localparam DEFAULT_MODLENGTH = 8'h80; // 2048 bits. localparam DEFAULT_EXPLENGTH = 8'h80; localparam CORE_NAME0 = 32'h6d6f6465; // "mode" localparam CORE_NAME1 = 32'h78702020; // "xp " localparam CORE_VERSION = 32'h302e3532; // "0.52" //---------------------------------------------------------------- // Register and Wire declarations. //---------------------------------------------------------------- reg [31 : 0] error_ctr; reg [31 : 0] tc_ctr; reg [127 : 0] result_data; reg tb_clk; reg tb_reset_n; reg tb_cs; reg tb_we; reg [31 : 0] tb_address; reg [31 : 0] tb_write_data; wire [31 : 0] tb_read_data; wire tb_error; reg tb_cyc; reg [3 : 0] tb_sel; wire tb_ack; wire tb_err; wire tb_int; reg [31 : 0] pmsg [63 : 0]; reg [31 : 0] cmsg [63 : 0]; reg [31 : 0] gmsg [63 : 0]; integer f1; //---------------------------------------------------------------- // Device Under Test. //---------------------------------------------------------------- modexp dut( .clk(tb_clk), .reset_n(tb_reset_n), .cs(tb_cs), .we(tb_we), .address(tb_address[10:2]), .write_data(tb_write_data), .read_data(tb_read_data)); //---------------------------------------------------------------- // clk_gen // // Always running clock generator process. //---------------------------------------------------------------- always begin : clk_gen #CLK_HALF_PERIOD; tb_clk = !tb_clk; end // clk_gen //---------------------------------------------------------------- // reset_dut() // // Toggle reset to put the DUT into a well known state. //---------------------------------------------------------------- task reset_dut(); begin $display("*** Toggle reset."); tb_reset_n = 0; #(2 * CLK_PERIOD); tb_reset_n = 1; $display(""); end endtask // reset_dut //---------------------------------------------------------------- // init_sim() // // Initialize all counters and testbed functionality as well // as setting the DUT inputs to defined values. //---------------------------------------------------------------- task init_sim(); begin error_ctr = 0; tc_ctr = 0; tb_clk = 0; tb_reset_n = 1; tb_cs = 0; tb_we = 0; tb_address = 32'h00000000; tb_write_data = 32'h00000000; end endtask // init_sim //---------------------------------------------------------------- // read_word() // // Read a data word from the given address in the DUT. //---------------------------------------------------------------- task read_word(input [7 : 0] address); begin tb_address = {22'b0,address,2'b0}; tb_cs = 1; tb_we = 0; #(CLK_PERIOD); tb_cs = 0; if (DEBUG) begin $display("*** (read_word) Reading 0x%08x from 0x%02x.", tb_read_data, address); $display(""); end end endtask // read_word //---------------------------------------------------------------- // write_word() // // Write the given word to the DUT using the DUT interface. //---------------------------------------------------------------- task write_word(input [ 7 : 0] address, input [31 : 0] word); begin if (DEBUG) begin $display("*** (write_word) Writing 0x%08x to 0x%02x.", word, address); $display(""); end tb_address = {22'b0,address,2'b0}; tb_write_data = word; tb_cs = 1; tb_we = 1; #(CLK_PERIOD); tb_cs = 0; tb_we = 0; end endtask // write_word //---------------------------------------------------------------- // wait_ready() // // Wait until the ready flag in the core is set. //---------------------------------------------------------------- task wait_ready(); begin while (tb_read_data != 32'h00000001) read_word(8'h09); if (DEBUG) $display("*** (wait_ready) Ready flag has been set."); end endtask // wait_ready //---------------------------------------------------------------- // assertEquals //---------------------------------------------------------------- function assertEquals( input [31:0] expected, input [31:0] actual ); begin if (expected === actual) begin assertEquals = 1; // success end else begin $display("*** Expected: 0x%08x, got 0x%08x", expected, actual); assertEquals = 0; // failure end end endfunction // assertEquals //---------------------------------------------------------------- // assertSuccess //---------------------------------------------------------------- task assertSuccess(input success); begin if (success !== 1) begin $display("*** Test -> FAILED"); error_ctr = error_ctr + 1; end else $display("*** Test -> passed"); end endtask // assertSuccess //---------------------------------------------------------------- // display_test_results() // // Display the accumulated test results. //---------------------------------------------------------------- task display_test_results(); begin $display(""); if (error_ctr == 0) begin $display("*** All %02d test cases completed successfully", tc_ctr); end else begin $display("*** %02d tests completed - %02d test cases did not complete successfully.", tc_ctr, error_ctr); end end endtask // display_test_results //---------------------------------------------------------------- // exp32bit_mod2048bit_test(); //---------------------------------------------------------------- task exp32bit_mod2048bit_test(); integer i; integer success; reg [31 : 0] read_data; reg [31 : 0] exp [63 : 0]; reg [31 : 0] mod [63 : 0]; reg [31 : 0] msg [63 : 0]; reg [31 : 0] res [63 : 0]; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display(""); $display("Test with e = 65537 and 2048 bit modulus -- Encrypting"); $readmemh("./gen/exp", exp); $readmemh("./gen/mod", mod); $readmemh("./gen/msg", msg); $readmemh("./gen/res", res); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , exp[0]); write_word(ADDR_MODULUS_PTR_RST, 32'h00000000); write_word(ADDR_MODULUS_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MODULUS_DATA, mod[i]); if(DEBUG) $display("writing: %d -> %h", i, mod[i]); end write_word(ADDR_MESSAGE_PTR_RST, 32'h00000000); write_word(ADDR_MESSAGE_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MESSAGE_DATA, msg[i]); if(DEBUG) $display("Writing: %d -> %h", i, msg[i]); end write_word(ADDR_EXPONENT_LENGTH, 32'h00000001); write_word(ADDR_MODULUS_LENGTH , 32'h00000041); // Start processing and wait for ready. write_word(ADDR_CTRL, 32'h00000001); wait_ready(); write_word(ADDR_RESULT_PTR_RST, 32'h00000000); read_word(ADDR_RESULT_DATA); read_data=tb_read_data; success=success&assertEquals(32'h00000000, read_data); for(i=0; i<64; i=i+1) begin read_word(ADDR_RESULT_DATA); read_data=tb_read_data; success=success&assertEquals(res[i], read_data); if(DEBUG) $display("Reading: %d -> %h -> %h", i, res[i], read_data); end if (success !== 1) begin $display("*** ERROR: e65537_2048bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_2048bit_modulus success."); end endtask // e65537_2048bit_modulus //---------------------------------------------------------------- // modexp_encrypt //---------------------------------------------------------------- task modexp_encrypt(); integer i; integer success; reg [31 : 0] pubexp [1]; reg [31 : 0] pubmod [63 : 0]; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display(""); $display("Encrypting -- exp = 65537 and 2048 bit mod"); $readmemh("./gen/pTextHEX", pmsg); $readmemh("./gen/exponent", pubexp); $readmemh("./gen/modulus", pubmod); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , pubexp[0]); if(DEBUG) $display("Writing EXP: %d %h", pubexp[0], pubexp[0]); write_word(ADDR_MODULUS_PTR_RST, 32'h00000000); write_word(ADDR_MODULUS_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MODULUS_DATA, pubmod[i]); if(DEBUG) $display("Writing MOD: %d -> %h", i, pubmod[i]); end write_word(ADDR_MESSAGE_PTR_RST, 32'h00000000); write_word(ADDR_MESSAGE_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MESSAGE_DATA, pmsg[i]); if(DEBUG) $display("Writing MSG: %d -> %h", i, pmsg[i]); end write_word(ADDR_EXPONENT_LENGTH, 32'h00000001); write_word(ADDR_MODULUS_LENGTH , 32'h00000041); // Start processing and wait for ready. write_word(ADDR_CTRL, 32'h00000001); wait_ready(); write_word(ADDR_RESULT_PTR_RST, 32'h00000000); read_word(ADDR_RESULT_DATA); cmsg[0]=tb_read_data; //success=success&assertEquals(32'h00000000, cmsg[0]); f1 = $fopen("./gen/cTextHEX", "w"); for(i=0; i<64; i=i+1) begin read_word(ADDR_RESULT_DATA); cmsg[i]=tb_read_data; if(DEBUG) $display("Reading: %d -> %h ", i, cmsg[i]); $fwrite(f1, "%h\n",cmsg[i]); end $fclose(f1); assertSuccess(success); end endtask // e65537_2048bit_modulus //---------------------------------------------------------------- // modexp_decrypt //---------------------------------------------------------------- task modexp_decrypt(); integer i; integer success; reg [31 : 0] rdata; reg [31 : 0] read_data; reg [31 : 0] priexp [63 : 0]; reg [31 : 0] primod [63 : 0]; begin $display(""); $display("*** Running -> modexp_decrypt()"); $readmemh("./gen/priExponent", priexp); $readmemh("./gen/priModulus", primod); success = 32'h1; tc_ctr = tc_ctr + 1; $display("Decrypting -- 2048 bit exp and 2048 bit mod"); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_EXPONENT_DATA, priexp[i]); if(DEBUG) $display("Writing EXP: %d -> %h", i, priexp[i]); end write_word(ADDR_MODULUS_PTR_RST, 32'h00000000); write_word(ADDR_MODULUS_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MODULUS_DATA, primod[i]); if(DEBUG) $display("Writing MOD: %d -> %h", i, primod[i]); end write_word(ADDR_MESSAGE_PTR_RST, 32'h00000000); write_word(ADDR_MESSAGE_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MESSAGE_DATA, cmsg[i]); if(DEBUG) $display("Writing MSG: %d -> %h", i, cmsg[i]); end write_word(ADDR_EXPONENT_LENGTH, 32'h00000041); write_word(ADDR_MODULUS_LENGTH , 32'h00000041); // Start processing and wait for ready. write_word(ADDR_CTRL, 32'h00000001); wait_ready(); write_word(ADDR_RESULT_PTR_RST, 32'h00000000); read_word(ADDR_RESULT_DATA); rdata=tb_read_data; success=success&assertEquals(32'h00000000, rdata); f1 = $fopen("./gen/gTextHEX", "w"); for(i=0; i<64; i=i+1) begin read_word(ADDR_RESULT_DATA); rdata=tb_read_data; if(DEBUG) $display("Reading: %d -> %h ", i, rdata); $fwrite(f1, "%h\n",rdata); success=success&assertEquals(pmsg[i], rdata); end $fclose(f1); assertSuccess(success); end endtask // e65537_2048bit_modulus //---------------------------------------------------------------- // modexp_32bits //---------------------------------------------------------------- task modexp_32bits(input [31:0] Wmsg, input [31:0] Wexp, input [31:0] Wmod, input [31:0] Wres); reg [31 : 0] Rmsg; reg [31 : 0] Rexp; reg [31 : 0] Rmod; reg [31 : 0] Rres; integer success; begin $display(""); $display("*** Running -> modexp_32bits()"); success = 32'h1; tc_ctr = tc_ctr + 1; $display("*** Writing -> MES: %h EXP: %h MOD: %h", Wmsg, Wexp, Wmod); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , Wexp); write_word(ADDR_MODULUS_PTR_RST , 32'h00000000); write_word(ADDR_MODULUS_DATA , Wmod); write_word(ADDR_MESSAGE_PTR_RST , 32'h00000000); write_word(ADDR_MESSAGE_DATA , Wmsg); write_word(ADDR_EXPONENT_LENGTH , 32'h00000001); write_word(ADDR_MODULUS_LENGTH , 32'h00000001); // Start processing and wait for ready. write_word(ADDR_CTRL , 32'h00000001); wait_ready(); write_word(ADDR_MESSAGE_PTR_RST , 32'h00000000); read_word(ADDR_MESSAGE_DATA); Rmsg=tb_read_data; write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); read_word(ADDR_EXPONENT_DATA); Rexp=tb_read_data; write_word(ADDR_MODULUS_PTR_RST , 32'h00000000); read_word(ADDR_MODULUS_DATA); Rmod=tb_read_data; write_word(ADDR_RESULT_PTR_RST , 32'h00000000); read_word(ADDR_RESULT_DATA); Rres=tb_read_data; $display("*** Reading -> MES: %h EXP: %h MOD: %h RES: %h", Rmsg, Rexp, Rmod, Rres); success=success&assertEquals(Wres, Rres); assertSuccess(success); end endtask // e65537_2048bit_modulus //---------------------------------------------------------------- // main // // The main test functionality. //---------------------------------------------------------------- initial begin : main if(VCD) begin $dumpfile("./iverilog/tb_modexp.vcd"); $dumpvars(0,tb_modexp); //$dumpvars(1,tb_clk, tb_reset_n, tb_cs, tb_we, tb_address, tb_write_data, tb_read_data); end $display(" -= Testbench for modexp started =-"); $display(" ================================="); $display(""); init_sim(); reset_dut(); modexp_32bits(32'h00000001, 32'h00000002, 32'h00000005, 32'h00000001); //msg^exp < mod -> 1^2 < 5 modexp_32bits(32'h00000001, 32'h00000002, 32'h00000003, 32'h00000001); //msg^exp < mod -> 1^2 < 3 modexp_32bits(32'h00000002, 32'h00000002, 32'h00000005, 32'h00000004); //msg^exp < mod -> 2^2 < 5 modexp_32bits(32'h00000002, 32'h00000002, 32'h00000003, 32'h00000001); //msg^exp > mod -> 2^2 > 3 modexp_32bits(32'h00000004, 32'h0000000D, 32'h000001F1, 32'h000001bd); //msg^exp > mod -> 4^13 > 497 modexp_32bits(32'h01234567, 32'h89ABCDEF, 32'h11111111, 32'h0D9EF081); //msg^exp > mod -> 19088743^2309737967 > 286331153 modexp_32bits(32'h30000000, 32'hC0000000, 32'h00A00001, 32'h0000CC3F); //msg^exp > mod -> 805306368^3221225472 > 10485761 <- Passes //modexp_32bits(32'h30000000, 32'hC0000000, 32'h00A00000, 32'h00600000); //msg^exp > mod -> 805306368^3221225472 > 10485760 <- Fails //modexp_32bits(32'h00000002, 32'h00000003, 32'h00000001, 32'h00000000); //mod 1 <- FAILS Does not check /* modexp_32bits(32'h00000001, 32'h00000002, 32'h00000002, 32'h00000001); //1 mod 2 = 1 -> 0 <- FAILS modexp_32bits(32'h00000001, 32'h00000002, 32'h00000003, 32'h00000001); //1 mod 3 = 1 -> 1 <- passes modexp_32bits(32'h00000001, 32'h00000002, 32'h00000004, 32'h00000001); //1 mod 4 = 1 -> 0 <- FAILS modexp_32bits(32'h00000001, 32'h00000002, 32'h00000005, 32'h00000001); //1 mod 5 = 1 -> 1 <- passes modexp_32bits(32'h00000001, 32'h00000002, 32'h00000006, 32'h00000001); //1 mod 6 = 1 -> 4 <- FAILS modexp_32bits(32'h00000002, 32'h00000001, 32'h00000002, 32'h00000000); //2 mod 2 = 0 -> passes modexp_32bits(32'h00000002, 32'h00000001, 32'h00000003, 32'h00000002); //2 mod 3 = 2 -> passes modexp_32bits(32'h00000002, 32'h00000001, 32'h00000004, 32'h00000002); //2 mod 4 = 2 -> 0 <- FAILS modexp_32bits(32'h00000002, 32'h00000001, 32'h00000005, 32'h00000002); //2 mod 5 = 2 -> passes modexp_32bits(32'h00000002, 32'h00000001, 32'h00000006, 32'h00000002); //2 mod 6 = 2 -> passes modexp_32bits(32'h00000003, 32'h00000001, 32'h00000002, 32'h00000001); //3 mod 2 = 1 -> 0 <- FAILS modexp_32bits(32'h00000003, 32'h00000001, 32'h00000003, 32'h00000000); //3 mod 3 = 0 -> 3 <- FAILS modexp_32bits(32'h00000003, 32'h00000001, 32'h00000004, 32'h00000003); //3 mod 4 = 3 -> 0 <- FAILS modexp_32bits(32'h00000003, 32'h00000001, 32'h00000005, 32'h00000003); //3 mod 5 = 3 -> passes modexp_32bits(32'h00000003, 32'h00000001, 32'h00000006, 32'h00000003); //3 mod 6 = 3 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000002, 32'h00000000); //4 mod 2 = 0 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000003, 32'h00000001); //4 mod 3 = 1 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000004, 32'h00000000); //4 mod 4 = 0 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000005, 32'h00000004); //4 mod 5 = 4 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000006, 32'h00000004); //4 mod 6 = 4 -> passes modexp_32bits(32'h00000005, 32'h00000001, 32'h00000002, 32'h00000001); //5 mod 2 = 1 -> 0 <- FAILS modexp_32bits(32'h00000005, 32'h00000001, 32'h00000003, 32'h00000002); //5 mod 3 = 2 -> passes modexp_32bits(32'h00000005, 32'h00000001, 32'h00000004, 32'h00000001); //5 mod 4 = 1 -> 0 <- FAILS modexp_32bits(32'h00000005, 32'h00000001, 32'h00000005, 32'h00000000); //5 mod 5 = 0 -> 5 <- FAILS modexp_32bits(32'h00000005, 32'h00000001, 32'h00000006, 32'h00000005); //5 mod 6 = 5 -> passes modexp_32bits(32'h00000006, 32'h00000001, 32'h00000002, 32'h00000000); //6 mod 2 = 0 -> passes modexp_32bits(32'h00000006, 32'h00000001, 32'h00000003, 32'h00000000); //6 mod 3 = 0 -> 3 <- FAILS modexp_32bits(32'h00000006, 32'h00000001, 32'h00000004, 32'h00000002); //6 mod 4 = 2 -> 0 <- FAILS modexp_32bits(32'h00000006, 32'h00000001, 32'h00000005, 32'h00000001); //6 mod 5 = 1 -> passes modexp_32bits(32'h00000006, 32'h00000001, 32'h00000006, 32'h00000000); //6 mod 6 = 0 -> 1 <- FAILS */ /* modexp_32bits(32'h00000008, 32'h00000006, 32'h00000002, 32'h00000000); //8^6 mod 2 = 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000003, 32'h00000001); //8^6 mod 3 = 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000004, 32'h00000000); //8^6 mod 4 = 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000005, 32'h00000004); //8^6 mod 5 = 4 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000006, 32'h00000004); //8^6 mod 6 = 4 -> 1 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000007, 32'h00000001); //8^6 mod 7 = 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000008, 32'h00000000); //8^6 mod 8 = 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000009, 32'h00000001); //8^6 mod 9 = 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000A, 32'h00000004); //8^6 mod 10= 4 -> 9 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000B, 32'h00000003); //8^6 mod 11= 3 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000C, 32'h00000004); //8^6 mod 12= 4 -> 5 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000D, 32'h0000000C); //8^6 mod 13= 12-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000E, 32'h00000008); //8^6 mod 14= 8 -> 5 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000F, 32'h00000004); //8^6 mod 15= 4 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000010, 32'h00000000); //8^6 mod 16= 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000011, 32'h00000004); //8^6 mod 17= 4 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000012, 32'h0000000A); //8^6 mod 18= 10-> 13<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000013, 32'h00000001); //8^6 mod 19= 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000014, 32'h00000004); //8^6 mod 20= 4 -> 11<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000015, 32'h00000001); //8^6 mod 21= 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000016, 32'h0000000E); //8^6 mod 22= 14-> 1 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000017, 32'h0000000D); //8^6 mod 23= 13-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000018, 32'h00000010); //8^6 mod 24= 16-> 9 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000019, 32'h00000013); //8^6 mod 25= 19-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001A, 32'h0000000C); //8^6 mod 26= 12-> 19<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001B, 32'h00000001); //8^6 mod 27= 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001C, 32'h00000008); //8^6 mod 28= 8 -> 19<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001D, 32'h0000000D); //8^6 mod 29= 13-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001E, 32'h00000004); //8^6 mod 30= 4 -> 13<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001F, 32'h00000008); //8^6 mod 31= 8 -> passes */ //exp32bit_mod2048bit_test(); //modexp_encrypt(); //modexp_decrypt(); display_test_results(); $display(""); $display("*** modexp simulation done. ***"); $finish; end // main endmodule // tb_modexp //====================================================================== // EOF tb_modexp.v //======================================================================
//====================================================================== // // tb_modexp.v // ----------- // Testbench modular exponentiation core. // // // Author: Joachim Strombergson, Peter Magnusson // Copyright (c) 2015, NORDUnet A/S All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // - Neither the name of the NORDUnet nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== //------------------------------------------------------------------ // Simulator directives. //------------------------------------------------------------------ `timescale 1ns/100ps //------------------------------------------------------------------ // Test module. //------------------------------------------------------------------ module tb_modexp(); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- // Debug output control. parameter DEBUG = 0; parameter DEBUG_EI = 0; parameter DEBUG_RESULT = 0; parameter DISPLAY_TEST_CYCLES = 1; // Clock defines. localparam CLK_HALF_PERIOD = 1; localparam CLK_PERIOD = 2 * CLK_HALF_PERIOD; // The DUT address map. localparam GENERAL_PREFIX = 4'h0; localparam ADDR_NAME0 = 8'h00; localparam ADDR_NAME1 = 8'h01; localparam ADDR_VERSION = 8'h02; localparam ADDR_CTRL = 8'h08; localparam CTRL_START_BIT = 0; localparam ADDR_STATUS = 8'h09; localparam STATUS_READY_BIT = 0; localparam ADDR_MODULUS_LENGTH = 8'h20; localparam ADDR_EXPONENT_LENGTH = 8'h21; localparam ADDR_LENGTH = 8'h22; localparam ADDR_MODULUS_PTR_RST = 8'h30; localparam ADDR_MODULUS_DATA = 8'h31; localparam ADDR_EXPONENT_PTR_RST = 8'h40; localparam ADDR_EXPONENT_DATA = 8'h41; localparam ADDR_MESSAGE_PTR_RST = 8'h50; localparam ADDR_MESSAGE_DATA = 8'h51; localparam ADDR_RESULT_PTR_RST = 8'h60; localparam ADDR_RESULT_DATA = 8'h61; //---------------------------------------------------------------- // Register and Wire declarations. //---------------------------------------------------------------- reg [31 : 0] test_cycle_ctr; reg test_cycle_ctr_rst; reg test_cycle_ctr_inc; reg [31 : 0] cycle_ctr; reg [31 : 0] error_ctr; reg [31 : 0] tc_ctr; reg [31 : 0] read_data; reg [127 : 0] result_data; reg tb_clk; reg tb_reset_n; reg tb_cs; reg tb_we; reg [11 : 0] tb_address; reg [31 : 0] tb_write_data; wire [31 : 0] tb_read_data; wire tb_error; //---------------------------------------------------------------- // Device Under Test. //---------------------------------------------------------------- modexp dut( .clk(tb_clk), .reset_n(tb_reset_n), .cs(tb_cs), .we(tb_we), .address(tb_address), .write_data(tb_write_data), .read_data(tb_read_data) ); //---------------------------------------------------------------- // clk_gen // // Always running clock generator process. //---------------------------------------------------------------- always begin : clk_gen #CLK_HALF_PERIOD; tb_clk = !tb_clk; end // clk_gen //---------------------------------------------------------------- // sys_monitor() // // An always running process that creates a cycle counter and // conditionally displays information about the DUT. //---------------------------------------------------------------- always begin : sys_monitor cycle_ctr = cycle_ctr + 1; #(CLK_PERIOD); if (DEBUG) begin dump_dut_state(); end end //---------------------------------------------------------------- // test_cycle_counter // // Used to measure the number of cycles it takes to perform // a given test case. //---------------------------------------------------------------- always @ (posedge tb_clk) begin if (test_cycle_ctr_rst) test_cycle_ctr = 64'h0000000000000000; if (test_cycle_ctr_inc) test_cycle_ctr = test_cycle_ctr + 1; end //---------------------------------------------------------------- // start_test_cycle_ctr // // Reset and start the test cycle counter. //---------------------------------------------------------------- task start_test_cycle_ctr(); begin test_cycle_ctr_rst = 1; #(CLK_PERIOD); test_cycle_ctr_rst = 0; test_cycle_ctr_inc = 1; end endtask // start_test_cycle_ctr() //---------------------------------------------------------------- // stop_test_cycle_ctr() // // Stop the test cycle counter and optionally display the // result. //---------------------------------------------------------------- task stop_test_cycle_ctr(); begin test_cycle_ctr_inc = 0; #(CLK_PERIOD); if (DISPLAY_TEST_CYCLES) $display("*** Number of cycles performed during test: 0x%016x", test_cycle_ctr); end endtask // stop_test_cycle_ctr() //---------------------------------------------------------------- // ei_monitor() // // Displays ei_new, the most important variable for determining // what modexp will do (i.e. should Z=MONTPROD( Z, P, M) be // performed //---------------------------------------------------------------- always @* begin : ei_monitor if (DEBUG_EI) if (dut.modexp_ctrl_reg == dut.CTRL_ITERATE_Z_P) $display("loop counter %d: ei = %d", dut.loop_counter_reg, dut.ei_reg); end //---------------------------------------------------------------- // z_monitor() // // Displays the contents of the result_mem. //---------------------------------------------------------------- always @* begin : result_monitor if (DEBUG_RESULT) $display("result_mem[0][1] = %x %x",dut.result_mem.mem[0],dut.result_mem.mem[1]); end //---------------------------------------------------------------- // dump_dut_state() // // Dump the state of the dump when needed. //---------------------------------------------------------------- task dump_dut_state(); begin $display("cycle: 0x%016x", cycle_ctr); $display("State of DUT"); $display("------------"); $display("Inputs and outputs:"); $display("cs = 0x%01x, we = 0x%01x", tb_cs, tb_we); $display("addr = 0x%08x, read_data = 0x%08x, write_data = 0x%08x", tb_address, tb_read_data, tb_write_data); $display(""); $display("State:"); $display("ready_reg = 0x%01x, start_reg = 0x%01x, start_new = 0x%01x", dut.core_inst.ready_reg, dut.start_reg, dut.start_new); $display("residue_valid = 0x%01x", dut.core_inst.residue_valid_reg); $display("loop_counter_reg = 0x%08x", dut.core_inst.loop_counter_reg); $display("exponent_length_reg = 0x%02x exponent_length_m1 = 0x%02x modulus_length_reg = 0x%02x modulus_length_m1 = 0x%02x", dut.exponent_length_reg, dut.core_inst.exponent_length_m1, dut.modulus_length_reg, dut.core_inst.modulus_length_m1); $display("ctrl_reg = 0x%04x", dut.core_inst.modexp_ctrl_reg); $display(""); end endtask // dump_dut_state //---------------------------------------------------------------- // reset_dut() // // Toggle reset to put the DUT into a well known state. //---------------------------------------------------------------- task reset_dut(); begin $display("*** Toggle reset."); tb_reset_n = 0; #(2 * CLK_PERIOD); tb_reset_n = 1; $display(""); end endtask // reset_dut //---------------------------------------------------------------- // display_test_results() // // Display the accumulated test results. //---------------------------------------------------------------- task display_test_results(); begin if (error_ctr == 0) begin $display("*** All %02d test cases completed successfully", tc_ctr); end else begin $display("*** %02d tests completed - %02d test cases did not complete successfully.", tc_ctr, error_ctr); end end endtask // display_test_results //---------------------------------------------------------------- // init_sim() // // Initialize all counters and testbed functionality as well // as setting the DUT inputs to defined values. //---------------------------------------------------------------- task init_sim(); begin cycle_ctr = 0; error_ctr = 0; tc_ctr = 0; tb_clk = 0; tb_reset_n = 1; tb_cs = 0; tb_we = 0; tb_address = 8'h00; tb_write_data = 32'h00000000; end endtask // init_sim //---------------------------------------------------------------- // read_word() // // Read a data word from the given address in the DUT. // the word read will be available in the global variable // read_data. //---------------------------------------------------------------- task read_word(input [11 : 0] address); begin tb_address = address; tb_cs = 1; tb_we = 0; #(CLK_PERIOD); read_data = tb_read_data; tb_cs = 0; if (DEBUG) begin $display("*** (read_word) Reading 0x%08x from 0x%02x.", read_data, address); $display(""); end end endtask // read_word //---------------------------------------------------------------- // write_word() // // Write the given word to the DUT using the DUT interface. //---------------------------------------------------------------- task write_word(input [11 : 0] address, input [31 : 0] word); begin if (DEBUG) begin $display("*** (write_word) Writing 0x%08x to 0x%02x.", word, address); $display(""); end tb_address = address; tb_write_data = word; tb_cs = 1; tb_we = 1; #(CLK_PERIOD); tb_cs = 0; tb_we = 0; end endtask // write_word //---------------------------------------------------------------- // wait_ready() // // Wait until the ready flag in the core is set. //---------------------------------------------------------------- task wait_ready(); begin while (tb_read_data != 32'h00000001) read_word({GENERAL_PREFIX, ADDR_STATUS}); if (DEBUG) $display("*** (wait_ready) Ready flag has been set."); end endtask // wait_ready //---------------------------------------------------------------- // dump_message_mem() // // Dump the contents of the message memory. //---------------------------------------------------------------- task dump_message_mem(); reg [8 : 0] i; begin $display("Contents of the message memory:"); for (i = 0 ; i < 256 ; i = i + 8) begin $display("message_mem[0x%02x .. 0x%02x] = 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x", i[7 : 0], (i[7 : 0] + 8'h07), dut.core_inst.message_mem.mem[(i[7 : 0] + 0)], dut.core_inst.message_mem.mem[(i[7 : 0] + 1)], dut.core_inst.message_mem.mem[(i[7 : 0] + 2)], dut.core_inst.message_mem.mem[(i[7 : 0] + 3)], dut.core_inst.message_mem.mem[(i[7 : 0] + 4)], dut.core_inst.message_mem.mem[(i[7 : 0] + 5)], dut.core_inst.message_mem.mem[(i[7 : 0] + 6)], dut.core_inst.message_mem.mem[(i[7 : 0] + 7)], ); end $display(""); end endtask // dump_message_mem //---------------------------------------------------------------- // dump_exponent_mem() // // Dump the contents of the exponent memory. //---------------------------------------------------------------- task dump_exponent_mem(); reg [8 : 0] i; begin $display("Contents of the exponent memory:"); for (i = 0 ; i < 256 ; i = i + 8) begin $display("exponent_mem[0x%02x .. 0x%02x] = 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x", i[7 : 0], (i[7 : 0] + 8'h07), dut.core_inst.exponent_mem.mem[(i[7 : 0] + 0)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 1)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 2)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 3)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 4)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 5)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 6)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 7)], ); end $display(""); end endtask // dump_exponent_mem //---------------------------------------------------------------- // dump_modulus_mem() // // Dump the contents of the modulus memory. //---------------------------------------------------------------- task dump_modulus_mem(); reg [8 : 0] i; begin $display("Contents of the modulus memory:"); for (i = 0 ; i < 256 ; i = i + 8) begin $display("modulus_mem[0x%02x .. 0x%02x] = 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x", i[7 : 0], (i[7 : 0] + 8'h07), dut.core_inst.modulus_mem.mem[(i[7 : 0] + 0)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 1)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 2)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 3)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 4)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 5)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 6)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 7)], ); end $display(""); end endtask // dump_modulus_mem //---------------------------------------------------------------- // dump_residue_mem() // // Dump the contents of the residue memory. //---------------------------------------------------------------- task dump_residue_mem(); reg [8 : 0] i; begin $display("Contents of the residue memory:"); for (i = 0 ; i < 256 ; i = i + 8) begin $display("residue_mem[0x%02x .. 0x%02x] = 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x", i[7 : 0], (i[7 : 0] + 8'h07), dut.core_inst.residue_mem.mem[(i[7 : 0] + 0)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 1)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 2)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 3)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 4)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 5)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 6)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 7)], ); end $display(""); end endtask // dump_residue_mem //---------------------------------------------------------------- // dump_result_mem() // // Dump the contents of the result memory. //---------------------------------------------------------------- task dump_result_mem(); reg [8 : 0] i; begin $display("Contents of the result memory:"); for (i = 0 ; i < 256 ; i = i + 8) begin $display("result_mem[0x%02x .. 0x%02x] = 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x", i[7 : 0], (i[7 : 0] + 8'h07), dut.core_inst.result_mem.mem[(i[7 : 0] + 0)], dut.core_inst.result_mem.mem[(i[7 : 0] + 1)], dut.core_inst.result_mem.mem[(i[7 : 0] + 2)], dut.core_inst.result_mem.mem[(i[7 : 0] + 3)], dut.core_inst.result_mem.mem[(i[7 : 0] + 4)], dut.core_inst.result_mem.mem[(i[7 : 0] + 5)], dut.core_inst.result_mem.mem[(i[7 : 0] + 6)], dut.core_inst.result_mem.mem[(i[7 : 0] + 7)], ); end $display(""); end endtask // dump_result_mem //---------------------------------------------------------------- // dump_memories() // // Dump the contents of the memories in the dut. //---------------------------------------------------------------- task dump_memories(); begin dump_message_mem(); dump_exponent_mem(); dump_modulus_mem(); dump_residue_mem(); dump_result_mem(); end endtask // dump_memories //---------------------------------------------------------------- // tc1 // // A first, very simple testcase where we want to do: // c = m ** e % N with the following (decimal) test values: // m = 3 // e = 7 // n = 11 // c = 3 ** 7 % 11 = 9 //---------------------------------------------------------------- task tc1(); reg [31 : 0] read_data; begin tc_ctr = tc_ctr + 1; $display("TC1: Trying to calculate 3**7 mod 11 = 9"); // Write 3 to message memory. write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000003); // Write 7 to exponent memory and set length to one word. write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000007); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); // Write 11 to modulus memory and set length to one word. write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h0000000b); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000001); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); // Read out result word and check result. write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; if (read_data == 32'h00000009) begin $display("*** TC1 successful."); $display(""); end else begin $display("*** ERROR: TC1 NOT successful."); $display("Expected: 0x09, got 0x%08x", read_data); error_ctr = error_ctr + 1; dump_memories(); end end endtask // tc1 //---------------------------------------------------------------- // tc2 // // c = m ** e % N with the following (decimal) test values: // m = 251 // e = 251 // n = 257 // c = 251 ** 251 % 257 = 183 //---------------------------------------------------------------- task tc2(); reg [31 : 0] read_data; begin tc_ctr = tc_ctr + 1; $display("TC2: Trying to calculate 251**251 mod 257 = 183"); // Write 13 to message memory. write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h000000fb); // Write 11 to exponent memory and set length to one word. write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h000000fb); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); // Write 7 to modulus memory and set length to one word. write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000101); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000001); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); // Read out result word and check result. write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; if (read_data == 32'h000000b7) begin $display("*** TC2 successful."); $display(""); end else begin $display("*** ERROR: TC2 NOT successful."); $display("Expected: 0x000000b7, got 0x%08x", read_data); error_ctr = error_ctr + 1; end end endtask // tc2 //---------------------------------------------------------------- // tc3 // // c = m ** e % N with the following (decimal) test values: // m = 0x81 // e = 0x41 // n = 0x87 // c = 0x81 ** 0x41 % 0x87 = 0x36 //---------------------------------------------------------------- task tc3(); reg [31 : 0] read_data; begin tc_ctr = tc_ctr + 1; $display("TC3: Trying to calculate 0x81 ** 0x41 mod 0x87 = 0x36"); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000081); // Write 11 to exponent memory and set length to one word. write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000041); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); // Write 7 to modulus memory and set length to one word. write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000087); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000001); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); // Read out result word and check result. write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; if (read_data == 32'h00000036) begin $display("*** TC3 successful."); $display(""); end else begin $display("*** ERROR: TC3 NOT successful."); $display("Expected: 0x06, got 0x%08x", read_data); error_ctr = error_ctr + 1; end end endtask // tc3 //---------------------------------------------------------------- // assertEquals //---------------------------------------------------------------- function assertEquals( input [31:0] expected, input [31:0] actual ); begin if (expected === actual) begin assertEquals = 1; // success end else begin $display("Expected: 0x%08x, got 0x%08x", expected, actual); assertEquals = 0; // failure end end endfunction // assertEquals integer success; //---------------------------------------------------------------- // autogenerated_BASIC_33bit() // // Task that tests modexp with 33 bit oprerands. //---------------------------------------------------------------- task autogenerated_BASIC_33bit(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("autogenerated_BASIC_33bit: 00000001946473e1 ** h000000010e85e74f mod 0000000170754797 "); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h946473e1); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h0e85e74f); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h70754797); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000002); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000002); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h7761ed4f, read_data); if (success !== 1) begin $display("*** ERROR: autogenerated_BASIC_33bit was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** autogenerated_BASIC_33bit success."); end endtask // autogenerated_BASIC_33bit //---------------------------------------------------------------- // autogenerated_BASIC_128bit() // // Task that tests modexp with 128 bit operands. //---------------------------------------------------------------- task autogenerated_BASIC_128bit(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("autogenerated_BASIC_128bit"); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h3285c343); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h2acbcb0f); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h4d023228); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h2ecc73db); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h29462882); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h12caa2d5); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb80e1c66); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h1006807f); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h267d2f2e); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h51c216a7); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hda752ead); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h48d22d89); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000004); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000005); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h0ddc404d, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h91600596, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h7425a8d8, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha066ca56, read_data); if (success !== 1) begin $display("*** ERROR: autogenerated_BASIC_128bit was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** autogenerated_BASIC_128bit success."); end endtask // autogenerated_BASIC_128bit //---------------------------------------------------------------- // e64bit_64bit_modulus() //---------------------------------------------------------------- task e64bit_64bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with 64 bit exponent and 64 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h12345678); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h97543211); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hfeababab); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hdeadbeef); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffee); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hbeefbeef); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000002); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000003); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'he52c5b9f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h85de87eb, read_data); if (success !== 1) begin $display("*** ERROR: 64 bit exponent and 64 bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** 64 bit exponent and 64 bit modulus success."); end endtask // e64bit_64bit_modulus //---------------------------------------------------------------- // e65537_64bit_modulus() //---------------------------------------------------------------- task e65537_64bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 64 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hf077656f); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h3bf9e69b); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb6684dc3); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h79a5824b); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000003); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h132d8e17, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hdd4d85a4, read_data); if (success !== 1) begin $display("*** ERROR: e65537_64bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_64bit_modulus success."); end endtask // e65537_64bit_modulus //---------------------------------------------------------------- // e65537_64bit_modulus_elength() //---------------------------------------------------------------- task e65537_64bit_modulus_elength(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 64 bit modulus, explicit exponent length."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hf077656f); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h3bf9e69b); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb6684dc3); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h79a5824b); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000003); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h132d8e17, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hdd4d85a4, read_data); if (success !== 1) begin $display("*** ERROR: e65537_64bit_modulus with explicit elength was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_64bit_modulus success."); end endtask // e65537_64bit_modulus_elength //---------------------------------------------------------------- // e65537_128bit_modulus() //---------------------------------------------------------------- task e65537_128bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 128 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hf5e8eee0); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc06b048a); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h964b2105); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h2c36ad6b); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h956e61b3); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h27997bc4); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h94e7e5c9); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb53585cf); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000005); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h9c6d322c, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h25ab8bd3, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4aa80100, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf0f3a02c, read_data); if (success !== 1) begin $display("*** ERROR: e65537_128bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_128bit_modulus success."); end endtask // e65537_128bit_modulus //---------------------------------------------------------------- // e65537_256bit_modulus() // // Task that tests modexp with small exponent and 256 bit modulus. //---------------------------------------------------------------- task e65537_256bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 256 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hf169d36e); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hbe2ce61d); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc2e87809); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h4fed15c3); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h7c70eac5); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'ha123e643); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h299b36d2); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h788e583b); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hf169d36e); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hbe2ce61d); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hc2e87809); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h4fed15c3); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h7c70eac5); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'ha123e643); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h299b36d2); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h788e583a); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000009); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf169d36e, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hbe2ce61d, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hc2e87809, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4fed15c3, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h7c70eac5, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha123e643, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h299b36d2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h788e583a, read_data); if (success !== 1) begin $display("*** ERROR: e65537_256bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_256bit_modulus success."); end endtask // e65537_256bit_modulus //---------------------------------------------------------------- // e65537_1024bit_modulus() // // Task that tests modexp with small exponent and // 2048 bit modulus. //---------------------------------------------------------------- task e65537_1024bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 1024 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000021); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); if (success !== 1) begin $display("*** ERROR: e65537_1024bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_1024bit_modulus success."); end endtask // e65537_1024bit_modulus //---------------------------------------------------------------- // e65537_1536bit_modulus() // // Task that tests modexp with small exponent and // 1536 bit modulus. //---------------------------------------------------------------- task e65537_1536bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 1536 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000031); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); if (success !== 1) begin $display("*** ERROR: e65537_1536bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_1536bit_modulus success."); end endtask // e65537_1536bit_modulus //---------------------------------------------------------------- // e65537_1664bit_modulus() // // Task that tests modexp with small exponent and // 1664 bit modulus. //---------------------------------------------------------------- task e65537_1664bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 1664 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000035); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); if (success !== 1) begin $display("*** ERROR: e65537_1664bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_1664it_modulus success."); end endtask // e65537_1664bit_modulus //---------------------------------------------------------------- // e65537_2048bit_modulus() // // Task that tests modexp with small exponent and // 2048 bit modulus. //---------------------------------------------------------------- task e65537_2048bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 2048 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000041); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); if (success !== 1) begin $display("*** ERROR: e65537_2048bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_2048bit_modulus success."); end endtask // e65537_2048bit_modulus //---------------------------------------------------------------- // rob_dec_1024() // // Task that tests modexp with 1024 bit decipher/sign with // real RSA key operands. //---------------------------------------------------------------- task rob_dec_1024(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Desipher/Sign Test with Rob 1024 bit operands."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h3ff26c9e); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h32685b93); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h66570228); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hf0603c4e); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h04a717c1); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h8038b116); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'heb48325e); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hcada992a); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h920bb241); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h5aee4afe); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'he2a37e87); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hb35b9519); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hb335775d); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h989553e9); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h1326f46e); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h2cdf6b7b); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h84aabfa9); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hef24c600); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hb56872ad); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h5edb9041); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'he8ecd7f8); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h535133fb); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hdefc92c7); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h42384226); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h7d40e5f5); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hc91bd745); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h9578e460); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hfc858374); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h3172bed3); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h73b6957c); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hc0d6a68e); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h33156a61); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h0001ffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00303130); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h0d060960); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h86480165); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h03040201); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h05000420); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h8e36fc9a); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'ha31724c3); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h2416263c); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h0366a175); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hfabbb92b); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h741ca649); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h6107074d); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h0343b597); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hd075ec0a); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h95048ef8); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hcaa69073); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h8d9d58e9); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h1764b437); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h50b58cad); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h8a6e3199); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h135f80ee); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h84eb2bde); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h58d38ee3); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h5825e91e); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hafdeb1ba); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'ha15a160b); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h0057c47c); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc7765e31); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h868a3e15); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h5ee57cef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hb008c4dd); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h6a0a89ee); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h98a4ee9c); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h971a07de); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h61e5b0d3); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hcf70e1cd); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc6a0de5b); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h451f2fb9); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hdb995196); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h9f2f884b); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h4b09749a); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'he6c4ddbe); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h7ee61f79); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h265c6adf); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hb16b3015); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000021); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000021); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h06339a64, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h367db02a, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf41158cc, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h95e76049, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4519c165, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h111184be, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'he41d8ee2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2ae5f5d1, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h1da7f962, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hac93ac88, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h915eee13, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha3350c22, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf0dfa62e, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hfdfc2b62, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h29f26e27, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hbebdc84e, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4746df79, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h7b387ad2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h13423c9f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h98e8a146, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hff486b6c, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h1a85414e, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h73117121, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hb700e547, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hab4e07b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h21b988b8, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h24dd77c2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h046b0a20, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hcddb986a, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hac75c2f2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hb044ed59, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hea565879, read_data); if (success !== 1) begin $display("*** ERROR: rob_dec_1024 was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** rob_dec_1024 success."); end endtask // rob_dec_1024 //---------------------------------------------------------------- // rob_enc_1024() // // Task that tests modexp with 1024 bit encipher/verify with // real RSA key operands. //---------------------------------------------------------------- task rob_enc_1024(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Encipher/Verify Test with Rob 1024 bit operands."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h06339a64); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h367db02a); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hf41158cc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h95e76049); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h4519c165); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h111184be); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'he41d8ee2); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h2ae5f5d1); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h1da7f962); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hac93ac88); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h915eee13); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'ha3350c22); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hf0dfa62e); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hfdfc2b62); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h29f26e27); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hbebdc84e); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h4746df79); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h7b387ad2); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h13423c9f); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h98e8a146); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hff486b6c); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h1a85414e); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h73117121); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb700e547); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hab4e07b2); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h21b988b8); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h24dd77c2); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h046b0a20); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hcddb986a); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hac75c2f2); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb044ed59); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hea565879); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hd075ec0a); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h95048ef8); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hcaa69073); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h8d9d58e9); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h1764b437); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h50b58cad); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h8a6e3199); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h135f80ee); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h84eb2bde); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h58d38ee3); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h5825e91e); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hafdeb1ba); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'ha15a160b); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h0057c47c); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc7765e31); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h868a3e15); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h5ee57cef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hb008c4dd); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h6a0a89ee); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h98a4ee9c); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h971a07de); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h61e5b0d3); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hcf70e1cd); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc6a0de5b); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h451f2fb9); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hdb995196); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h9f2f884b); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h4b09749a); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'he6c4ddbe); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h7ee61f79); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h265c6adf); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hb16b3015); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000021); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000021); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h0001ffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00303130, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h0d060960, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h86480165, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h03040201, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h05000420, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h8e36fc9a, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha31724c3, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2416263c, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h0366a175, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hfabbb92b, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h741ca649, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h6107074d, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h0343b597, read_data); if (success !== 1) begin $display("*** ERROR: rob_enc_1024 was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** rob_enc_1024 success."); end endtask // rob_enc_1024 //---------------------------------------------------------------- // main // // The main test functionality. //---------------------------------------------------------------- initial begin : main $display(" -= Testbench for modexp started =-"); $display(" ================================="); $display(""); init_sim(); dump_dut_state(); reset_dut(); dump_dut_state(); // tc1(); // tc2(); // tc3(); // autogenerated_BASIC_33bit(); // autogenerated_BASIC_128bit(); // e64bit_64bit_modulus(); // e65537_64bit_modulus(); // e65537_64bit_modulus_elength(); // e65537_128bit_modulus(); // e65537_256bit_modulus(); // e65537_1024bit_modulus(); // e65537_1536bit_modulus(); // e65537_1664bit_modulus(); e65537_2048bit_modulus(); // rob_dec_1024(); // rob_enc_1024(); display_test_results(); $display(""); $display("*** modexp simulation done. ***"); $finish; end // main endmodule // tb_modexp //====================================================================== // EOF tb_modexp.v //======================================================================
//------------------------------------------------------------------ // Simulator directives. //------------------------------------------------------------------ `timescale 1ns/100ps //------------------------------------------------------------------ // Test module. //------------------------------------------------------------------ module tb_top(); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- // Debug output control. parameter DEBUG = 0; parameter VCD = 1; // Clock defines. localparam CLK_HALF_PERIOD = 1; localparam CLK_PERIOD = 2 * CLK_HALF_PERIOD; // Address defines localparam OPERAND_WIDTH = 32; localparam ADDRESS_WIDTH = 8; localparam ADDR_NAME0 = 8'h00; localparam ADDR_NAME1 = 8'h01; localparam ADDR_VERSION = 8'h02; localparam ADDR_CTRL = 8'h08; localparam CTRL_INIT_BIT = 0; localparam CTRL_NEXT_BIT = 1; localparam ADDR_STATUS = 8'h09; localparam STATUS_READY_BIT = 0; localparam ADDR_CYCLES_HIGH = 8'h10; localparam ADDR_CYCLES_LOW = 8'h11; localparam ADDR_MODULUS_LENGTH = 8'h20; localparam ADDR_EXPONENT_LENGTH = 8'h21; localparam ADDR_MODULUS_PTR_RST = 8'h30; localparam ADDR_MODULUS_DATA = 8'h31; localparam ADDR_EXPONENT_PTR_RST = 8'h40; localparam ADDR_EXPONENT_DATA = 8'h41; localparam ADDR_MESSAGE_PTR_RST = 8'h50; localparam ADDR_MESSAGE_DATA = 8'h51; localparam ADDR_RESULT_PTR_RST = 8'h60; localparam ADDR_RESULT_DATA = 8'h61; localparam DEFAULT_MODLENGTH = 8'h80; // 2048 bits. localparam DEFAULT_EXPLENGTH = 8'h80; localparam CORE_NAME0 = 32'h6d6f6465; // "mode" localparam CORE_NAME1 = 32'h78702020; // "xp " localparam CORE_VERSION = 32'h302e3532; // "0.52" //---------------------------------------------------------------- // Register and Wire declarations. //---------------------------------------------------------------- reg [31 : 0] error_ctr; reg [31 : 0] tc_ctr; reg [127 : 0] result_data; reg tb_clk; reg tb_reset; reg tb_cs; reg tb_we; reg [31 : 0] tb_address; reg [31 : 0] tb_write_data; wire [31 : 0] tb_read_data; wire tb_error; reg tb_cyc; reg [3 : 0] tb_sel; wire tb_ack; wire tb_err; wire tb_int; reg [31 : 0] pmsg [63 : 0]; reg [31 : 0] cmsg [63 : 0]; reg [31 : 0] gmsg [63 : 0]; integer f1; //---------------------------------------------------------------- // Device Under Test. //---------------------------------------------------------------- modexp_top dut( .wb_adr_i(tb_address), .wb_cyc_i(tb_cyc),// .wb_dat_i(tb_write_data), .wb_sel_i(tb_sel),// .wb_stb_i(tb_cs), .wb_we_i(tb_we), .wb_ack_o(tb_ack),// .wb_err_o(tb_err),// .wb_dat_o(tb_read_data), .wb_clk_i(tb_clk), .wb_rst_i(tb_reset), .int_o(tb_int)// ); //---------------------------------------------------------------- // clk_gen // // Always running clock generator process. //---------------------------------------------------------------- always begin : clk_gen #CLK_HALF_PERIOD; tb_clk = !tb_clk; end // clk_gen //---------------------------------------------------------------- // reset_dut() // // Toggle reset to put the DUT into a well known state. //---------------------------------------------------------------- task reset_dut(); begin $display("*** Toggle reset."); tb_reset = 1; #(2 * CLK_PERIOD); tb_reset = 0; $display(""); end endtask // reset_dut //---------------------------------------------------------------- // init_sim() // // Initialize all counters and testbed functionality as well // as setting the DUT inputs to defined values. //---------------------------------------------------------------- task init_sim(); begin error_ctr = 0; tc_ctr = 0; tb_clk = 0; tb_reset = 0; tb_cs = 0; tb_we = 0; tb_address = 32'h00000000; tb_write_data = 32'h00000000; end endtask // init_sim //---------------------------------------------------------------- // read_word() // // Read a data word from the given address in the DUT. //---------------------------------------------------------------- task read_word(input [7 : 0] address); begin tb_address = {22'b0,address,2'b0}; tb_cs = 1; tb_we = 0; #(CLK_PERIOD); tb_cs = 0; if (DEBUG) begin $display("*** (read_word) Reading 0x%08x from 0x%02x.", tb_read_data, address); $display(""); end end endtask // read_word //---------------------------------------------------------------- // write_word() // // Write the given word to the DUT using the DUT interface. //---------------------------------------------------------------- task write_word(input [ 7 : 0] address, input [31 : 0] word); begin if (DEBUG) begin $display("*** (write_word) Writing 0x%08x to 0x%02x.", word, address); $display(""); end tb_address = {22'b0,address,2'b0}; tb_write_data = word; tb_cs = 1; tb_we = 1; #(CLK_PERIOD); tb_cs = 0; tb_we = 0; end endtask // write_word //---------------------------------------------------------------- // wait_ready() // // Wait until the ready flag in the core is set. //---------------------------------------------------------------- task wait_ready(); begin while (tb_read_data != 32'h00000001) read_word(8'h09); if (DEBUG) $display("*** (wait_ready) Ready flag has been set."); end endtask // wait_ready //---------------------------------------------------------------- // assertEquals //---------------------------------------------------------------- function assertEquals( input [31:0] expected, input [31:0] actual ); begin if (expected === actual) begin assertEquals = 1; // success end else begin $display("*** Expected: 0x%08x, got 0x%08x", expected, actual); assertEquals = 0; // failure end end endfunction // assertEquals //---------------------------------------------------------------- // assertSuccess //---------------------------------------------------------------- task assertSuccess(input success); begin if (success !== 1) begin $display("*** Test -> FAILED"); error_ctr = error_ctr + 1; end else $display("*** Test -> passed"); end endtask // assertSuccess //---------------------------------------------------------------- // display_test_results() // // Display the accumulated test results. //---------------------------------------------------------------- task display_test_results(); begin $display(""); if (error_ctr == 0) begin $display("*** All %02d test cases completed successfully", tc_ctr); end else begin $display("*** %02d tests completed - %02d test cases did not complete successfully.", tc_ctr, error_ctr); end end endtask // display_test_results //---------------------------------------------------------------- // exp32bit_mod2048bit_test //---------------------------------------------------------------- task exp32bit_mod2048bit_test(); integer i; integer success; reg [31 : 0] read_data; reg [31 : 0] exp [63 : 0]; reg [31 : 0] mod [63 : 0]; reg [31 : 0] msg [63 : 0]; reg [31 : 0] res [63 : 0]; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display(""); $display("Test with e = 65537 and 2048 bit modulus -- Encrypting"); $readmemh("./gen/exp", exp); $readmemh("./gen/mod", mod); $readmemh("./gen/msg", msg); $readmemh("./gen/res", res); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , exp[0]); write_word(ADDR_MODULUS_PTR_RST, 32'h00000000); write_word(ADDR_MODULUS_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MODULUS_DATA, mod[i]); if(DEBUG) $display("writing: %d -> %h", i, mod[i]); end write_word(ADDR_MESSAGE_PTR_RST, 32'h00000000); write_word(ADDR_MESSAGE_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MESSAGE_DATA, msg[i]); if(DEBUG) $display("Writing: %d -> %h", i, msg[i]); end write_word(ADDR_EXPONENT_LENGTH, 32'h00000001); write_word(ADDR_MODULUS_LENGTH , 32'h00000041); // Start processing and wait for ready. write_word(ADDR_CTRL, 32'h00000001); wait_ready(); write_word(ADDR_RESULT_PTR_RST, 32'h00000000); read_word(ADDR_RESULT_DATA); read_data=tb_read_data; success=success&assertEquals(32'h00000000, read_data); for(i=0; i<64; i=i+1) begin read_word(ADDR_RESULT_DATA); read_data=tb_read_data; success=success&assertEquals(res[i], read_data); if(DEBUG) $display("Reading: %d -> %h -> %h", i, res[i], read_data); end if (success !== 1) begin $display("*** ERROR: e65537_2048bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_2048bit_modulus success."); end endtask // exp32bit_mod2048bit_test //---------------------------------------------------------------- // modexp_encrypt //---------------------------------------------------------------- task modexp_encrypt(); integer i; integer success; reg [31 : 0] pubexp [1]; reg [31 : 0] pubmod [63 : 0]; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display(""); $display("Encrypting -- exp = 65537 and 2048 bit mod"); $readmemh("./gen/pTextHEX", pmsg); $readmemh("./gen/exponent", pubexp); $readmemh("./gen/modulus", pubmod); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , pubexp[0]); if(DEBUG) $display("Writing EXP: %d %h", pubexp[0], pubexp[0]); write_word(ADDR_MODULUS_PTR_RST, 32'h00000000); write_word(ADDR_MODULUS_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MODULUS_DATA, pubmod[i]); if(DEBUG) $display("Writing MOD: %d -> %h", i, pubmod[i]); end write_word(ADDR_MESSAGE_PTR_RST, 32'h00000000); write_word(ADDR_MESSAGE_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MESSAGE_DATA, pmsg[i]); if(DEBUG) $display("Writing MSG: %d -> %h", i, pmsg[i]); end write_word(ADDR_EXPONENT_LENGTH, 32'h00000001); write_word(ADDR_MODULUS_LENGTH , 32'h00000041); // Start processing and wait for ready. write_word(ADDR_CTRL, 32'h00000001); wait_ready(); write_word(ADDR_RESULT_PTR_RST, 32'h00000000); read_word(ADDR_RESULT_DATA); cmsg[0]=tb_read_data; //success=success&assertEquals(32'h00000000, cmsg[0]); f1 = $fopen("./gen/cTextHEX", "w"); for(i=0; i<64; i=i+1) begin read_word(ADDR_RESULT_DATA); cmsg[i]=tb_read_data; if(DEBUG) $display("Reading: %d -> %h ", i, cmsg[i]); $fwrite(f1, "%h\n",cmsg[i]); end $fclose(f1); assertSuccess(success); end endtask // modexp_encrypt //---------------------------------------------------------------- // modexp_decrypt //---------------------------------------------------------------- task modexp_decrypt(); integer i; integer success; reg [31 : 0] rdata; reg [31 : 0] read_data; reg [31 : 0] priexp [63 : 0]; reg [31 : 0] primod [63 : 0]; begin $display(""); $display("*** Running -> modexp_decrypt()"); $readmemh("./gen/priExponent", priexp); $readmemh("./gen/priModulus", primod); success = 32'h1; tc_ctr = tc_ctr + 1; $display("Decrypting -- 2048 bit exp and 2048 bit mod"); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_EXPONENT_DATA, priexp[i]); if(DEBUG) $display("Writing EXP: %d -> %h", i, priexp[i]); end write_word(ADDR_MODULUS_PTR_RST, 32'h00000000); write_word(ADDR_MODULUS_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MODULUS_DATA, primod[i]); if(DEBUG) $display("Writing MOD: %d -> %h", i, primod[i]); end write_word(ADDR_MESSAGE_PTR_RST, 32'h00000000); write_word(ADDR_MESSAGE_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MESSAGE_DATA, cmsg[i]); if(DEBUG) $display("Writing MSG: %d -> %h", i, cmsg[i]); end write_word(ADDR_EXPONENT_LENGTH, 32'h00000041); write_word(ADDR_MODULUS_LENGTH , 32'h00000041); // Start processing and wait for ready. write_word(ADDR_CTRL, 32'h00000001); wait_ready(); write_word(ADDR_RESULT_PTR_RST, 32'h00000000); read_word(ADDR_RESULT_DATA); rdata=tb_read_data; success=success&assertEquals(32'h00000000, rdata); f1 = $fopen("./gen/gTextHEX", "w"); for(i=0; i<64; i=i+1) begin read_word(ADDR_RESULT_DATA); rdata=tb_read_data; if(DEBUG) $display("Reading: %d -> %h ", i, rdata); $fwrite(f1, "%h\n",rdata); success=success&assertEquals(pmsg[i], rdata); end $fclose(f1); assertSuccess(success); end endtask // modexp_decrypt //---------------------------------------------------------------- // modexp_32bits //---------------------------------------------------------------- task modexp_32bits(input [31:0] Wmsg, input [31:0] Wexp, input [31:0] Wmod, input [31:0] Wres); reg [31 : 0] Rmsg; reg [31 : 0] Rexp; reg [31 : 0] Rmod; reg [31 : 0] Rres; integer success; begin $display(""); $display("*** Running -> modexp_32bits()"); success = 32'h1; tc_ctr = tc_ctr + 1; $display("*** Writing -> MES: %h EXP: %h MOD: %h", Wmsg, Wexp, Wmod); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , Wexp); write_word(ADDR_MODULUS_PTR_RST , 32'h00000000); write_word(ADDR_MODULUS_DATA , Wmod); write_word(ADDR_MESSAGE_PTR_RST , 32'h00000000); write_word(ADDR_MESSAGE_DATA , Wmsg); write_word(ADDR_EXPONENT_LENGTH , 32'h00000001); write_word(ADDR_MODULUS_LENGTH , 32'h00000001); // Start processing and wait for ready. write_word(ADDR_CTRL , 32'h00000001); wait_ready(); write_word(ADDR_MESSAGE_PTR_RST , 32'h00000000); read_word(ADDR_MESSAGE_DATA); Rmsg=tb_read_data; write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); read_word(ADDR_EXPONENT_DATA); Rexp=tb_read_data; write_word(ADDR_MODULUS_PTR_RST , 32'h00000000); read_word(ADDR_MODULUS_DATA); Rmod=tb_read_data; write_word(ADDR_RESULT_PTR_RST , 32'h00000000); read_word(ADDR_RESULT_DATA); Rres=tb_read_data; $display("*** Reading -> MES: %h EXP: %h MOD: %h RES: %h", Rmsg, Rexp, Rmod, Rres); success=success&assertEquals(Wres, Rres); assertSuccess(success); end endtask // modexp_32bits //---------------------------------------------------------------- // main // // The main test functionality. //---------------------------------------------------------------- initial begin : main if(VCD) begin $dumpfile("./iverilog/tb_top.vcd"); $dumpvars(0,tb_top); //$dumpvars(1,tb_clk, tb_reset, tb_cs, tb_we, tb_address, tb_write_data, tb_read_data); end $display(" -= Testbench for modexp started =-"); $display(" ================================="); $display(""); init_sim(); reset_dut(); modexp_32bits(32'h00000001, 32'h00000002, 32'h00000005, 32'h00000001); //msg^exp < mod -> 1^2 < 5 modexp_32bits(32'h00000001, 32'h00000002, 32'h00000003, 32'h00000001); //msg^exp < mod -> 1^2 < 3 modexp_32bits(32'h00000002, 32'h00000002, 32'h00000005, 32'h00000004); //msg^exp < mod -> 2^2 < 5 modexp_32bits(32'h00000002, 32'h00000002, 32'h00000003, 32'h00000001); //msg^exp > mod -> 2^2 > 3 modexp_32bits(32'h00000004, 32'h0000000D, 32'h000001F1, 32'h000001bd); //msg^exp > mod -> 4^13 > 497 modexp_32bits(32'h01234567, 32'h89ABCDEF, 32'h11111111, 32'h0D9EF081); //msg^exp > mod -> 19088743^2309737967 > 286331153 modexp_32bits(32'h30000000, 32'hC0000000, 32'h00A00001, 32'h0000CC3F); //msg^exp > mod -> 805306368^3221225472 > 10485761 <- Passes //modexp_32bits(32'h30000000, 32'hC0000000, 32'h00A00000, 32'h00600000); //msg^exp > mod -> 805306368^3221225472 > 10485760 <- Fails //modexp_32bits(32'h00000002, 32'h00000003, 32'h00000001, 32'h00000000); //mod 1 <- FAILS Does not check /* modexp_32bits(32'h00000001, 32'h00000002, 32'h00000002, 32'h00000001); //1 mod 2 = 1 -> 0 <- FAILS modexp_32bits(32'h00000001, 32'h00000002, 32'h00000003, 32'h00000001); //1 mod 3 = 1 -> 1 <- passes modexp_32bits(32'h00000001, 32'h00000002, 32'h00000004, 32'h00000001); //1 mod 4 = 1 -> 0 <- FAILS modexp_32bits(32'h00000001, 32'h00000002, 32'h00000005, 32'h00000001); //1 mod 5 = 1 -> 1 <- passes modexp_32bits(32'h00000001, 32'h00000002, 32'h00000006, 32'h00000001); //1 mod 6 = 1 -> 4 <- FAILS modexp_32bits(32'h00000002, 32'h00000001, 32'h00000002, 32'h00000000); //2 mod 2 = 0 -> passes modexp_32bits(32'h00000002, 32'h00000001, 32'h00000003, 32'h00000002); //2 mod 3 = 2 -> passes modexp_32bits(32'h00000002, 32'h00000001, 32'h00000004, 32'h00000002); //2 mod 4 = 2 -> 0 <- FAILS modexp_32bits(32'h00000002, 32'h00000001, 32'h00000005, 32'h00000002); //2 mod 5 = 2 -> passes modexp_32bits(32'h00000002, 32'h00000001, 32'h00000006, 32'h00000002); //2 mod 6 = 2 -> passes modexp_32bits(32'h00000003, 32'h00000001, 32'h00000002, 32'h00000001); //3 mod 2 = 1 -> 0 <- FAILS modexp_32bits(32'h00000003, 32'h00000001, 32'h00000003, 32'h00000000); //3 mod 3 = 0 -> 3 <- FAILS modexp_32bits(32'h00000003, 32'h00000001, 32'h00000004, 32'h00000003); //3 mod 4 = 3 -> 0 <- FAILS modexp_32bits(32'h00000003, 32'h00000001, 32'h00000005, 32'h00000003); //3 mod 5 = 3 -> passes modexp_32bits(32'h00000003, 32'h00000001, 32'h00000006, 32'h00000003); //3 mod 6 = 3 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000002, 32'h00000000); //4 mod 2 = 0 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000003, 32'h00000001); //4 mod 3 = 1 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000004, 32'h00000000); //4 mod 4 = 0 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000005, 32'h00000004); //4 mod 5 = 4 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000006, 32'h00000004); //4 mod 6 = 4 -> passes modexp_32bits(32'h00000005, 32'h00000001, 32'h00000002, 32'h00000001); //5 mod 2 = 1 -> 0 <- FAILS modexp_32bits(32'h00000005, 32'h00000001, 32'h00000003, 32'h00000002); //5 mod 3 = 2 -> passes modexp_32bits(32'h00000005, 32'h00000001, 32'h00000004, 32'h00000001); //5 mod 4 = 1 -> 0 <- FAILS modexp_32bits(32'h00000005, 32'h00000001, 32'h00000005, 32'h00000000); //5 mod 5 = 0 -> 5 <- FAILS modexp_32bits(32'h00000005, 32'h00000001, 32'h00000006, 32'h00000005); //5 mod 6 = 5 -> passes modexp_32bits(32'h00000006, 32'h00000001, 32'h00000002, 32'h00000000); //6 mod 2 = 0 -> passes modexp_32bits(32'h00000006, 32'h00000001, 32'h00000003, 32'h00000000); //6 mod 3 = 0 -> 3 <- FAILS modexp_32bits(32'h00000006, 32'h00000001, 32'h00000004, 32'h00000002); //6 mod 4 = 2 -> 0 <- FAILS modexp_32bits(32'h00000006, 32'h00000001, 32'h00000005, 32'h00000001); //6 mod 5 = 1 -> passes modexp_32bits(32'h00000006, 32'h00000001, 32'h00000006, 32'h00000000); //6 mod 6 = 0 -> 1 <- FAILS */ /* modexp_32bits(32'h00000008, 32'h00000006, 32'h00000002, 32'h00000000); //8^6 mod 2 = 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000003, 32'h00000001); //8^6 mod 3 = 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000004, 32'h00000000); //8^6 mod 4 = 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000005, 32'h00000004); //8^6 mod 5 = 4 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000006, 32'h00000004); //8^6 mod 6 = 4 -> 1 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000007, 32'h00000001); //8^6 mod 7 = 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000008, 32'h00000000); //8^6 mod 8 = 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000009, 32'h00000001); //8^6 mod 9 = 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000A, 32'h00000004); //8^6 mod 10= 4 -> 9 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000B, 32'h00000003); //8^6 mod 11= 3 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000C, 32'h00000004); //8^6 mod 12= 4 -> 5 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000D, 32'h0000000C); //8^6 mod 13= 12-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000E, 32'h00000008); //8^6 mod 14= 8 -> 5 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000F, 32'h00000004); //8^6 mod 15= 4 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000010, 32'h00000000); //8^6 mod 16= 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000011, 32'h00000004); //8^6 mod 17= 4 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000012, 32'h0000000A); //8^6 mod 18= 10-> 13<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000013, 32'h00000001); //8^6 mod 19= 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000014, 32'h00000004); //8^6 mod 20= 4 -> 11<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000015, 32'h00000001); //8^6 mod 21= 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000016, 32'h0000000E); //8^6 mod 22= 14-> 1 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000017, 32'h0000000D); //8^6 mod 23= 13-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000018, 32'h00000010); //8^6 mod 24= 16-> 9 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000019, 32'h00000013); //8^6 mod 25= 19-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001A, 32'h0000000C); //8^6 mod 26= 12-> 19<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001B, 32'h00000001); //8^6 mod 27= 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001C, 32'h00000008); //8^6 mod 28= 8 -> 19<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001D, 32'h0000000D); //8^6 mod 29= 13-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001E, 32'h00000004); //8^6 mod 30= 4 -> 13<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001F, 32'h00000008); //8^6 mod 31= 8 -> passes */ //exp32bit_mod2048bit_test(); //modexp_encrypt(); //modexp_decrypt(); display_test_results(); $display(""); $display("*** modexp simulation done. ***"); $finish; end // main endmodule // tb_modexp //====================================================================== // EOF tb_modexp.v //======================================================================
//====================================================================== // // adder.v // ------- // Adder with separate carry in and carry out. Used in the montprod // amd residue modules of the modexp core. // // // Author: Peter Magnusson, Joachim Strömbergson // Copyright (c) 2015, NORDUnet A/S All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // - Neither the name of the NORDUnet nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== module adder #(parameter OPW = 32) ( input [(OPW - 1) : 0] a, input [(OPW - 1) : 0] b, input carry_in, output wire [(OPW - 1) : 0] sum, output wire carry_out ); reg [(OPW) : 0] adder_result; assign sum = adder_result[(OPW - 1) : 0]; assign carry_out = adder_result[(OPW)]; always @* begin adder_result = {1'b0, a} + {1'b0, b} + {{OPW{1'b0}}, carry_in}; end endmodule // adder //====================================================================== // EOF adder.v //======================================================================
//====================================================================== // // blockmem1rw1.v // -------------- // Synchronous block memory with one read and one write port. // The data size is the same for both read and write operations. // // The memory is used in the modexp core. // // paremeter OPW is operand word width in bits. // parameter ADW is address width in bits. // // // Author: Joachim Strombergson // Copyright (c) 2015, NORDUnet A/S All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // - Neither the name of the NORDUnet nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== module blockmem1r1w #(parameter OPW = 32, parameter ADW = 8) ( input wire clk, input wire [(ADW - 1) : 0] read_addr, output wire [(OPW - 1) : 0] read_data, input wire wr, input wire [(ADW - 1) : 0] write_addr, input wire [(OPW - 1) : 0] write_data ); reg [(OPW - 1) : 0] mem [0 : ((2**ADW) - 1)]; reg [(OPW - 1) : 0] tmp_read_data; assign read_data = tmp_read_data; always @ (posedge clk) begin : reg_mem if (wr) mem[write_addr] <= write_data; tmp_read_data <= mem[read_addr]; end endmodule // blockmem1r1w //====================================================================== // EOF blockmem1r1w.v //======================================================================
//====================================================================== // // blockmem2r1w.v // -------------- // Synchronous block memory with two read ports and one write port. // The data size is the same for both read and write operations. // // The memory is used in the modexp core. // // // Author: Joachim Strombergson // Copyright (c) 2015, NORDUnet A/S All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // - Neither the name of the NORDUnet nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== module blockmem2r1w #(parameter OPW = 32, parameter ADW = 8) ( input wire clk, input wire [(ADW - 1) : 0] read_addr0, output wire [(OPW - 1) : 0] read_data0, input wire [(ADW - 1) : 0] read_addr1, output wire [(OPW - 1) : 0] read_data1, input wire wr, input wire [(ADW - 1) : 0] write_addr, input wire [(OPW - 1) : 0] write_data ); reg [(OPW - 1) : 0] mem [0 : ((2**ADW) - 1)]; reg [(OPW - 1) : 0] tmp_read_data0; reg [(OPW - 1) : 0] tmp_read_data1; assign read_data0 = tmp_read_data0; assign read_data1 = tmp_read_data1; always @ (posedge clk) begin : reg_mem if (wr) mem[write_addr] <= write_data; tmp_read_data0 <= mem[read_addr0]; tmp_read_data1 <= mem[read_addr1]; end endmodule // blockmem2r1w //====================================================================== // EOF blockmem2r1w.v //======================================================================
//====================================================================== // // blockmem2r1wptr.v // ----------------- // Synchronous block memory with two read ports and one write port. // For port 1 the address is implicit and instead given by the // internal pointer. The pointer is automatically increased // when the cs signal is set. The pointer is reset to zero when // the rst signal is asserted. // // // NOTE: This memory needs to be rebuilt if interface 0 is changed // to use bigger operand widths and fewer words than interface 1. // This adaption is NOT automatic. // // // The memory is used in the modexp core. // // // Author: Joachim Strombergson // Copyright (c) 2015, NORDUnet A/S All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // - Neither the name of the NORDUnet nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== module blockmem2r1wptr #(parameter OPW = 32, parameter ADW = 8) ( input wire clk, input wire reset_n, input wire [(ADW - 1) : 0] read_addr0, output wire [(OPW - 1) : 0] read_data0, output wire [31 : 0] read_data1, input wire rst, input wire cs, input wire wr, input wire [31 : 0] write_data ); //---------------------------------------------------------------- // Memories and regs including update variables and write enable. //---------------------------------------------------------------- reg [(OPW - 1) : 0] mem [0 : ((2**ADW) - 1)]; reg [(OPW - 1) : 0] tmp_read_data0; reg [31 : 0] tmp_read_data1; reg [7 : 0] ptr_reg; reg [7 : 0] ptr_new; reg ptr_we; //---------------------------------------------------------------- // Concurrent connectivity for ports etc. //---------------------------------------------------------------- assign read_data0 = tmp_read_data0; assign read_data1 = tmp_read_data1; //---------------------------------------------------------------- // mem_update // // Clocked update of memory This should cause // the memory to be implemented as a block memory. //---------------------------------------------------------------- always @ (posedge clk) begin : mem_update if (wr) mem[ptr_reg] <= write_data; tmp_read_data0 <= mem[read_addr0]; tmp_read_data1 <= mem[ptr_reg]; end //---------------------------------------------------------------- // ptr_update //---------------------------------------------------------------- always @ (posedge clk or negedge reset_n) begin : ptr_update if (!reset_n) ptr_reg <= 8'h00; else if (ptr_we) ptr_reg <= ptr_new; end //---------------------------------------------------------------- // ptr_logic //---------------------------------------------------------------- always @* begin : ptr_logic ptr_new = 8'h00; ptr_we = 1'b0; if (rst) begin ptr_new = 8'h00; ptr_we = 1'b1; end if (cs) begin ptr_new = ptr_reg + 1'b1; ptr_we = 1'b1; end end endmodule // blockmem2r1wptr //====================================================================== // EOF blockmem2r1wptr.v //======================================================================
//====================================================================== // // blockmem2r1wptr.v // ----------------- // Synchronous block memory with two read ports and one write port. // For port 1 the address is implicit and instead given by the // internal pointer. But write address is explicitly given. // // The memory is used in the modexp core. // // // NOTE: This memory needs to be rebuilt if interface 0 is changed // to use bigger operand widths and fewer words than interface 1. // This adaption is NOT automatic. // // // Author: Joachim Strombergson // Copyright (c) 2015, NORDUnet A/S All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // - Neither the name of the NORDUnet nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== module blockmem2rptr1w #(parameter OPW = 32, parameter ADW = 8) ( input wire clk, input wire reset_n, input wire [(ADW - 1) : 0] read_addr0, output wire [(OPW - 1) : 0] read_data0, output wire [31 : 0] read_data1, input wire rst, input wire cs, input wire wr, input wire [07 : 0] write_addr, input wire [31 : 0] write_data ); //---------------------------------------------------------------- // Memories and regs including update variables and write enable. //---------------------------------------------------------------- reg [(OPW - 1) : 0] mem [0 : ((2**ADW) - 1)]; reg [(OPW - 1) : 0] tmp_read_data0; reg [31 : 0] tmp_read_data1; reg [7 : 0] ptr_reg; reg [7 : 0] ptr_new; reg ptr_we; //---------------------------------------------------------------- // Concurrent connectivity for ports etc. //---------------------------------------------------------------- assign read_data0 = tmp_read_data0; assign read_data1 = tmp_read_data1; //---------------------------------------------------------------- // mem_update // // Clocked update of memory This should cause // the memory to be implemented as a block memory. //---------------------------------------------------------------- always @ (posedge clk) begin : mem_update if (wr) mem[write_addr] <= write_data; tmp_read_data0 <= mem[read_addr0]; tmp_read_data1 <= mem[ptr_reg]; end //---------------------------------------------------------------- // reg_update //---------------------------------------------------------------- always @ (posedge clk or negedge reset_n) begin : reg_mem_update if (!reset_n) ptr_reg <= 8'h00; else if (ptr_we) ptr_reg <= ptr_new; end //---------------------------------------------------------------- // ptr_logic //---------------------------------------------------------------- always @* begin : ptr_logic ptr_new = 8'h00; ptr_we = 1'b0; if (rst) begin ptr_new = 8'h00; ptr_we = 1'b1; end if (cs) begin ptr_new = ptr_reg + 1'b1; ptr_we = 1'b1; end end endmodule // blockmem2r1wptr //====================================================================== // EOF blockmem2r1wptr.v //======================================================================
//====================================================================== // // modexp.v // -------- // Top level wrapper for the modula exponentiation core. The core // is used to implement public key algorithms such as RSA, // DH, ElGamal etc. // // The core calculates the following function: // // C = M ** e mod N // // M is a message with a length of n bits // e is the exponent with a length of m bits // N is the modulus with a length of n bits // // n can be 32 and up to and including 8192 bits in steps // of 32 bits. // m can be one and up to and including 8192 bits in steps // of 32 bits. // // The core has a 32-bit memory like interface, but provides // status signals to inform the system that a given operation // has is done. Additionally, any errors will also be asserted. // // // Author: Joachim Strombergson, Peter Magnusson // Copyright (c) 2015, NORDUnet A/S // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // - Neither the name of the NORDUnet nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // //====================================================================== module modexp( input wire clk, input wire reset_n, input wire cs, input wire we, input wire [ 7 : 0] address, input wire [31 : 0] write_data, output wire [31 : 0] read_data ); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- // The operand width is the internal operand width in bits. // The address width is the size of the address space used. This // value must be balances with OPERAND_WIDTH to allow a total // of 8192 bits of data. OPERAND_WIDTH * (ADDRESS_WIDTH ** 2) // is the formula. Note that the API data with is always 32 bits. localparam OPERAND_WIDTH = 32; localparam ADDRESS_WIDTH = 8; localparam ADDR_NAME0 = 8'h00; localparam ADDR_NAME1 = 8'h01; localparam ADDR_VERSION = 8'h02; localparam ADDR_CTRL = 8'h08; localparam CTRL_INIT_BIT = 0; localparam CTRL_NEXT_BIT = 1; localparam ADDR_STATUS = 8'h09; localparam STATUS_READY_BIT = 0; localparam ADDR_CYCLES_HIGH = 8'h10; localparam ADDR_CYCLES_LOW = 8'h11; localparam ADDR_MODULUS_LENGTH = 8'h20; localparam ADDR_EXPONENT_LENGTH = 8'h21; localparam ADDR_MODULUS_PTR_RST = 8'h30; localparam ADDR_MODULUS_DATA = 8'h31; localparam ADDR_EXPONENT_PTR_RST = 8'h40; localparam ADDR_EXPONENT_DATA = 8'h41; localparam ADDR_MESSAGE_PTR_RST = 8'h50; localparam ADDR_MESSAGE_DATA = 8'h51; localparam ADDR_RESULT_PTR_RST = 8'h60; localparam ADDR_RESULT_DATA = 8'h61; localparam DEFAULT_MODLENGTH = 8'h80; // 2048 bits. localparam DEFAULT_EXPLENGTH = 8'h80; localparam CORE_NAME0 = 32'h6d6f6465; // "mode" localparam CORE_NAME1 = 32'h78702020; // "xp " localparam CORE_VERSION = 32'h302e3532; // "0.52" //---------------------------------------------------------------- // Registers including update variables and write enable. //---------------------------------------------------------------- reg [07 : 0] exponent_length_reg; reg [07 : 0] exponent_length_new; reg exponent_length_we; reg [07 : 0] modulus_length_reg; reg [07 : 0] modulus_length_new; reg modulus_length_we; reg start_reg; reg start_new; //---------------------------------------------------------------- // Wires. //---------------------------------------------------------------- reg exponent_mem_api_rst; reg exponent_mem_api_cs; reg exponent_mem_api_wr; wire [31 : 0] exponent_mem_api_read_data; reg modulus_mem_api_rst; reg modulus_mem_api_cs; reg modulus_mem_api_wr; wire [31 : 0] modulus_mem_api_read_data; reg message_mem_api_rst; reg message_mem_api_cs; reg message_mem_api_wr; wire [31 : 0] message_mem_api_read_data; reg result_mem_api_rst; reg result_mem_api_cs; wire [31 : 0] result_mem_api_read_data; wire ready; wire [63 : 0] cycles; reg [31 : 0] tmp_read_data; //---------------------------------------------------------------- // Concurrent connectivity for ports etc. //---------------------------------------------------------------- assign read_data = tmp_read_data; //---------------------------------------------------------------- // core instantiations. //---------------------------------------------------------------- modexp_core #(.OPW(OPERAND_WIDTH), .ADW(ADDRESS_WIDTH)) core_inst( .clk(clk), .reset_n(reset_n), .start(start_reg), .ready(ready), .exponent_length(exponent_length_reg), .modulus_length(modulus_length_reg), .cycles(cycles), .exponent_mem_api_cs(exponent_mem_api_cs), .exponent_mem_api_wr(exponent_mem_api_wr), .exponent_mem_api_rst(exponent_mem_api_rst), .exponent_mem_api_write_data(write_data), .exponent_mem_api_read_data(exponent_mem_api_read_data), .modulus_mem_api_cs(modulus_mem_api_cs), .modulus_mem_api_wr(modulus_mem_api_wr), .modulus_mem_api_rst(modulus_mem_api_rst), .modulus_mem_api_write_data(write_data), .modulus_mem_api_read_data(modulus_mem_api_read_data), .message_mem_api_cs(message_mem_api_cs), .message_mem_api_wr(message_mem_api_wr), .message_mem_api_rst(message_mem_api_rst), .message_mem_api_write_data(write_data), .message_mem_api_read_data(message_mem_api_read_data), .result_mem_api_cs(result_mem_api_cs), .result_mem_api_rst(result_mem_api_rst), .result_mem_api_read_data(result_mem_api_read_data) ); //---------------------------------------------------------------- // reg_update // // Update functionality for all registers in the core. // All registers are positive edge triggered with asynchronous // active low reset. All registers have write enable. //---------------------------------------------------------------- always @ (posedge clk or negedge reset_n) begin if (!reset_n) begin start_reg <= 1'b0; exponent_length_reg <= DEFAULT_EXPLENGTH; modulus_length_reg <= DEFAULT_MODLENGTH; end else begin start_reg <= start_new; if (exponent_length_we) begin exponent_length_reg <= write_data[7 : 0]; end if (modulus_length_we) begin modulus_length_reg <= write_data[7 : 0]; end end end // reg_update //---------------------------------------------------------------- // api // // The interface command decoding logic. //---------------------------------------------------------------- always @* begin : api modulus_length_we = 1'b0; exponent_length_we = 1'b0; start_new = 1'b0; modulus_mem_api_rst = 1'b0; modulus_mem_api_cs = 1'b0; modulus_mem_api_wr = 1'b0; exponent_mem_api_rst = 1'b0; exponent_mem_api_cs = 1'b0; exponent_mem_api_wr = 1'b0; message_mem_api_rst = 1'b0; message_mem_api_cs = 1'b0; message_mem_api_wr = 1'b0; result_mem_api_rst = 1'b0; result_mem_api_cs = 1'b0; tmp_read_data = 32'h00000000; if (cs) begin if (we) begin case (address) ADDR_CTRL: begin start_new = write_data[0]; end ADDR_MODULUS_LENGTH: begin modulus_length_we = 1'b1; end ADDR_EXPONENT_LENGTH: begin exponent_length_we = 1'b1; end ADDR_MODULUS_PTR_RST: begin modulus_mem_api_rst = 1'b1; end ADDR_MODULUS_DATA: begin modulus_mem_api_cs = 1'b1; modulus_mem_api_wr = 1'b1; end ADDR_EXPONENT_PTR_RST: begin exponent_mem_api_rst = 1'b1; end ADDR_EXPONENT_DATA: begin exponent_mem_api_cs = 1'b1; exponent_mem_api_wr = 1'b1; end ADDR_MESSAGE_PTR_RST: begin message_mem_api_rst = 1'b1; end ADDR_MESSAGE_DATA: begin message_mem_api_cs = 1'b1; message_mem_api_wr = 1'b1; end ADDR_RESULT_PTR_RST: begin result_mem_api_rst = 1'b1; end default: begin end endcase // case (address[7 : 0]) end // if (we) else begin case (address) ADDR_NAME0: tmp_read_data = CORE_NAME0; ADDR_NAME1: tmp_read_data = CORE_NAME1; ADDR_VERSION: tmp_read_data = CORE_VERSION; ADDR_CTRL: tmp_read_data = {31'h00000000, start_reg}; ADDR_STATUS: tmp_read_data = {31'h00000000, ready}; ADDR_CYCLES_HIGH: tmp_read_data = cycles[63 : 32]; ADDR_CYCLES_LOW: tmp_read_data = cycles[31 : 0]; ADDR_MODULUS_LENGTH: tmp_read_data = {24'h000000, modulus_length_reg}; ADDR_EXPONENT_LENGTH: tmp_read_data = {24'h000000, exponent_length_reg}; ADDR_MODULUS_DATA: begin modulus_mem_api_cs = 1'b1; tmp_read_data = modulus_mem_api_read_data; end ADDR_EXPONENT_DATA: begin exponent_mem_api_cs = 1'b1; tmp_read_data = exponent_mem_api_read_data; end ADDR_MESSAGE_DATA: begin message_mem_api_cs = 1'b1; tmp_read_data = message_mem_api_read_data; end ADDR_RESULT_DATA: begin result_mem_api_cs = 1'b1; tmp_read_data = result_mem_api_read_data; end default: begin end endcase // case (address) end // else: !if(we) end // if (cs) end // block: api endmodule // modexp //====================================================================== // EOF modexp.v //======================================================================
//====================================================================== // // modexp_core.v // ------------- // Modular exponentiation core for implementing public key algorithms // such as RSA, DH, ElGamal etc. // // The core calculates the following function: // // C = M ** e mod N // // M is a message with a length of n bits // e is the exponent with a length of m bits // N is the modulus with a length of n bits // // n can be 32 and up to and including 8192 bits in steps // of 32 bits. // m can be one and up to and including 8192 bits in steps // of 32 bits. // // The core has access ports for the exponent, modulus, message and // result memories. // // // Author: Joachim Strombergson, Peter Magnusson // Copyright (c) 2015, NORDUnet A/S // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // - Neither the name of the NORDUnet nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // //====================================================================== module modexp_core #(parameter OPW = 32, parameter ADW = 8) ( input wire clk, input wire reset_n, input wire start, output wire ready, input wire [07 : 0] exponent_length, input wire [07 : 0] modulus_length, output wire [63 : 0] cycles, input wire exponent_mem_api_cs, input wire exponent_mem_api_wr, input wire exponent_mem_api_rst, input wire [31 : 0] exponent_mem_api_write_data, output wire [31 : 0] exponent_mem_api_read_data, input wire modulus_mem_api_cs, input wire modulus_mem_api_wr, input wire modulus_mem_api_rst, input wire [31 : 0] modulus_mem_api_write_data, output wire [31 : 0] modulus_mem_api_read_data, input wire message_mem_api_cs, input wire message_mem_api_wr, input wire message_mem_api_rst, input wire [31 : 0] message_mem_api_write_data, output wire [31 : 0] message_mem_api_read_data, input wire result_mem_api_cs, input wire result_mem_api_rst, output wire [31 : 0] result_mem_api_read_data ); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- localparam MONTPROD_SELECT_ONE_NR = 3'h0; localparam MONTPROD_SELECT_X_NR = 3'h1; localparam MONTPROD_SELECT_Z_P = 3'h2; localparam MONTPROD_SELECT_P_P = 3'h3; localparam MONTPROD_SELECT_Z_ONE = 3'h4; localparam MONTPROD_DEST_Z = 2'b00; localparam MONTPROD_DEST_P = 2'b01; localparam MONTPROD_DEST_NOWHERE = 2'b10; localparam CTRL_IDLE = 4'h0; localparam CTRL_RESIDUE = 4'h1; localparam CTRL_CALCULATE_Z0 = 4'h2; localparam CTRL_CALCULATE_P0 = 4'h3; localparam CTRL_ITERATE = 4'h4; localparam CTRL_ITERATE_Z_P = 4'h5; localparam CTRL_ITERATE_P_P = 4'h6; localparam CTRL_ITERATE_END = 4'h7; localparam CTRL_CALCULATE_ZN = 4'h8; localparam CTRL_DONE = 4'h9; //for rsa, c=M^65537 etc, there is no need to slow down to hide the exponent localparam EXPONATION_MODE_SECRET_SECURE = 1'b0; localparam EXPONATION_MODE_PUBLIC_FAST = 1'b1; //---------------------------------------------------------------- // Registers including update variables and write enable. //---------------------------------------------------------------- reg ready_reg; reg ready_new; reg ready_we; reg [2 : 0] montprod_select_reg; reg [2 : 0] montprod_select_new; reg montprod_select_we; reg [1 : 0] montprod_dest_reg; reg [1 : 0] montprod_dest_new; reg montprod_dest_we; reg [3 : 0] modexp_ctrl_reg; reg [3 : 0] modexp_ctrl_new; reg modexp_ctrl_we; reg [31 : 0] one_reg; reg [31 : 0] one_new; reg [31 : 0] b_one_reg; reg [31 : 0] b_one_new; reg [12 : 0] loop_counter_reg; reg [12 : 0] loop_counter_new; reg loop_counter_we; reg [07 : 0] E_word_index; reg [04 : 0] E_bit_index; reg last_iteration; reg ei_reg; reg ei_new; reg ei_we; reg exponation_mode_reg; reg exponation_mode_new; reg exponation_mode_we; reg [31 : 0] cycle_ctr_low_reg; reg [31 : 0] cycle_ctr_low_new; reg cycle_ctr_low_we; reg [31 : 0] cycle_ctr_high_reg; reg [31 : 0] cycle_ctr_high_new; reg cycle_ctr_high_we; reg cycle_ctr_state_reg; reg cycle_ctr_state_new; reg cycle_ctr_state_we; reg cycle_ctr_start; reg cycle_ctr_stop; //---------------------------------------------------------------- // Wires. //---------------------------------------------------------------- reg [07 : 0] modulus_mem_int_rd_addr; wire [31 : 0] modulus_mem_int_rd_data; reg [07 : 0] message_mem_int_rd_addr; wire [31 : 0] message_mem_int_rd_data; reg [07 : 0] exponent_mem_int_rd_addr; wire [31 : 0] exponent_mem_int_rd_data; reg [07 : 0] result_mem_int_rd_addr; wire [31 : 0] result_mem_int_rd_data; reg [07 : 0] result_mem_int_wr_addr; reg [31 : 0] result_mem_int_wr_data; reg result_mem_int_we; reg [07 : 0] p_mem_rd0_addr; wire [31 : 0] p_mem_rd0_data; reg [07 : 0] p_mem_rd1_addr; wire [31 : 0] p_mem_rd1_data; reg [07 : 0] p_mem_wr_addr; reg [31 : 0] p_mem_wr_data; reg p_mem_we; reg [31 : 0] tmp_read_data; reg montprod_calc; wire montprod_ready; reg [07 : 0] montprod_length; wire [07 : 0] montprod_opa_addr; reg [31 : 0] montprod_opa_data; wire [07 : 0] montprod_opb_addr; reg [31 : 0] montprod_opb_data; wire [07 : 0] montprod_opm_addr; reg [31 : 0] montprod_opm_data; wire [07 : 0] montprod_result_addr; wire [31 : 0] montprod_result_data; wire montprod_result_we; reg residue_calculate; wire residue_ready; reg [14 : 0] residue_nn; reg [07 : 0] residue_length; wire [07 : 0] residue_opa_rd_addr; wire [31 : 0] residue_opa_rd_data; wire [07 : 0] residue_opa_wr_addr; wire [31 : 0] residue_opa_wr_data; wire residue_opa_wr_we; wire [07 : 0] residue_opm_addr; reg [31 : 0] residue_opm_data; reg [07 : 0] residue_mem_montprod_read_addr; wire [31 : 0] residue_mem_montprod_read_data; reg residue_valid_reg; reg residue_valid_new; reg residue_valid_int_validated; wire [7 : 0] modulus_length_m1; wire [7 : 0] exponent_length_m1; //---------------------------------------------------------------- // Concurrent connectivity for ports etc. //---------------------------------------------------------------- assign ready = ready_reg; assign cycles = {cycle_ctr_high_reg, cycle_ctr_low_reg}; assign modulus_length_m1 = modulus_length - 8'h1; assign exponent_length_m1 = exponent_length - 8'h1; //---------------------------------------------------------------- // core instantiations. //---------------------------------------------------------------- montprod #(.OPW(OPW), .ADW(ADW)) montprod_inst( .clk(clk), .reset_n(reset_n), .calculate(montprod_calc), .ready(montprod_ready), .length(montprod_length), .opa_addr(montprod_opa_addr), .opa_data(montprod_opa_data), .opb_addr(montprod_opb_addr), .opb_data(montprod_opb_data), .opm_addr(montprod_opm_addr), .opm_data(montprod_opm_data), .result_addr(montprod_result_addr), .result_data(montprod_result_data), .result_we(montprod_result_we) ); residue #(.OPW(OPW), .ADW(ADW)) residue_inst( .clk(clk), .reset_n(reset_n), .calculate(residue_calculate), .ready(residue_ready), .nn(residue_nn), .length(residue_length), .opa_rd_addr(residue_opa_rd_addr), .opa_rd_data(residue_opa_rd_data), .opa_wr_addr(residue_opa_wr_addr), .opa_wr_data(residue_opa_wr_data), .opa_wr_we(residue_opa_wr_we), .opm_addr(residue_opm_addr), .opm_data(residue_opm_data) ); blockmem2r1w #(.OPW(OPW), .ADW(ADW)) residue_mem( .clk(clk), .read_addr0(residue_opa_rd_addr), .read_data0(residue_opa_rd_data), .read_addr1(residue_mem_montprod_read_addr), .read_data1(residue_mem_montprod_read_data), .wr(residue_opa_wr_we), .write_addr(residue_opa_wr_addr), .write_data(residue_opa_wr_data) ); blockmem2r1w #(.OPW(OPW), .ADW(ADW)) p_mem( .clk(clk), .read_addr0(p_mem_rd0_addr), .read_data0(p_mem_rd0_data), .read_addr1(p_mem_rd1_addr), .read_data1(p_mem_rd1_data), .wr(p_mem_we), .write_addr(p_mem_wr_addr), .write_data(p_mem_wr_data) ); blockmem2r1wptr #(.OPW(OPW), .ADW(ADW)) exponent_mem( .clk(clk), .reset_n(reset_n), .read_addr0(exponent_mem_int_rd_addr), .read_data0(exponent_mem_int_rd_data), .read_data1(exponent_mem_api_read_data), .rst(exponent_mem_api_rst), .cs(exponent_mem_api_cs), .wr(exponent_mem_api_wr), .write_data(exponent_mem_api_write_data) ); blockmem2r1wptr #(.OPW(OPW), .ADW(ADW)) modulus_mem( .clk(clk), .reset_n(reset_n), .read_addr0(modulus_mem_int_rd_addr), .read_data0(modulus_mem_int_rd_data), .read_data1(modulus_mem_api_read_data), .rst(modulus_mem_api_rst), .cs(modulus_mem_api_cs), .wr(modulus_mem_api_wr), .write_data(modulus_mem_api_write_data) ); blockmem2r1wptr #(.OPW(OPW), .ADW(ADW)) message_mem( .clk(clk), .reset_n(reset_n), .read_addr0(message_mem_int_rd_addr), .read_data0(message_mem_int_rd_data), .read_data1(message_mem_api_read_data), .rst(message_mem_api_rst), .cs(message_mem_api_cs), .wr(message_mem_api_wr), .write_data(message_mem_api_write_data) ); blockmem2rptr1w #(.OPW(OPW), .ADW(ADW)) result_mem( .clk(clk), .reset_n(reset_n), .read_addr0(result_mem_int_rd_addr[7 : 0]), .read_data0(result_mem_int_rd_data), .read_data1(result_mem_api_read_data), .rst(result_mem_api_rst), .cs(result_mem_api_cs), .wr(result_mem_int_we), .write_addr(result_mem_int_wr_addr), .write_data(result_mem_int_wr_data) ); //---------------------------------------------------------------- // reg_update // // Update functionality for all registers in the core. // All registers are positive edge triggered with asynchronous // active low reset. All registers have write enable. //---------------------------------------------------------------- always @ (posedge clk or negedge reset_n) begin if (!reset_n) begin ready_reg <= 1'b1; montprod_select_reg <= MONTPROD_SELECT_ONE_NR; montprod_dest_reg <= MONTPROD_DEST_NOWHERE; modexp_ctrl_reg <= CTRL_IDLE; one_reg <= 32'h0; b_one_reg <= 32'h0; loop_counter_reg <= 13'b0; ei_reg <= 1'b0; residue_valid_reg <= 1'b0; exponation_mode_reg <= EXPONATION_MODE_SECRET_SECURE; cycle_ctr_low_reg <= 32'h00000000; cycle_ctr_high_reg <= 32'h00000000; cycle_ctr_state_reg <= 1'b0; end else begin one_reg <= one_new; b_one_reg <= b_one_new; residue_valid_reg <= residue_valid_new; if (ready_we) ready_reg <= ready_new; if (montprod_select_we) montprod_select_reg <= montprod_select_new; if (montprod_dest_we) montprod_dest_reg <= montprod_dest_new; if (loop_counter_we) loop_counter_reg <= loop_counter_new; if (ei_we) ei_reg <= ei_new; if (exponation_mode_we) exponation_mode_reg <= exponation_mode_new; if (cycle_ctr_low_we) cycle_ctr_low_reg <= cycle_ctr_low_new; if (cycle_ctr_high_we) cycle_ctr_high_reg <= cycle_ctr_high_new; if (cycle_ctr_state_we) cycle_ctr_state_reg <= cycle_ctr_state_new; if (modexp_ctrl_we) modexp_ctrl_reg <= modexp_ctrl_new; end end // reg_update //---------------------------------------------------------------- // cycle_ctr // // Implementation of the cycle counter //---------------------------------------------------------------- always @* begin : cycle_ctr cycle_ctr_low_new = 32'h00000000; cycle_ctr_low_we = 1'b0; cycle_ctr_high_new = 32'h00000000; cycle_ctr_high_we = 1'b0; cycle_ctr_state_new = 1'b0; cycle_ctr_state_we = 1'b0; if (cycle_ctr_start) begin cycle_ctr_low_new = 32'h00000000; cycle_ctr_low_we = 1'b1; cycle_ctr_high_new = 32'h00000000; cycle_ctr_high_we = 1'b1; cycle_ctr_state_new = 1'b1; cycle_ctr_state_we = 1'b1; end if (cycle_ctr_stop) begin cycle_ctr_state_new = 1'b0; cycle_ctr_state_we = 1'b1; end if (cycle_ctr_state_reg) begin cycle_ctr_low_new = cycle_ctr_low_reg + 1'b1; cycle_ctr_low_we = 1'b1; if (cycle_ctr_low_new == 32'h00000000) begin cycle_ctr_high_new = cycle_ctr_high_reg + 1'b1; cycle_ctr_high_we = 1'b1; end end end // cycle_ctr //---------------------------------------------------------------- // one // // generates the big integer one ( 00... 01 ) //---------------------------------------------------------------- always @* begin : one_process one_new = 32'h00000000; b_one_new = 32'h00000000; if (montprod_opa_addr == modulus_length_m1) one_new = 32'h00000001; if (montprod_opb_addr == modulus_length_m1) b_one_new = 32'h00000001; end //---------------------------------------------------------------- // Read mux for modulus. Needed since it is being // addressed by two sources. //---------------------------------------------------------------- always @* begin : modulus_mem_reader_process if (modexp_ctrl_reg == CTRL_RESIDUE) modulus_mem_int_rd_addr = residue_opm_addr; else modulus_mem_int_rd_addr = montprod_opm_addr; end //---------------------------------------------------------------- // Feeds residue calculator. //---------------------------------------------------------------- always @* begin : residue_process //N*2, N=length*32, *32 = shl5, *64 = shl6 residue_nn = { 1'b0, modulus_length, 6'h0 }; residue_length = modulus_length; residue_opm_data = modulus_mem_int_rd_data; end //---------------------------------------------------------------- // Detects if modulus has been updated and we need to // recalculate the residue // and we need residue is valid or not. //---------------------------------------------------------------- always @* begin : residue_valid_process residue_valid_new = residue_valid_reg; if (modulus_mem_api_cs & modulus_mem_api_wr) residue_valid_new = 1'b0; else if ( residue_valid_int_validated == 1'b1) residue_valid_new = 1'b1; end //---------------------------------------------------------------- // montprod_op_select // // Select operands used during montprod calculations depending // on what operation we want to do. //---------------------------------------------------------------- always @* begin : montprod_op_select montprod_length = modulus_length; result_mem_int_rd_addr = montprod_opa_addr; message_mem_int_rd_addr = montprod_opa_addr; p_mem_rd0_addr = montprod_opa_addr; residue_mem_montprod_read_addr = montprod_opb_addr; p_mem_rd1_addr = montprod_opb_addr; montprod_opm_data = modulus_mem_int_rd_data; case (montprod_select_reg) MONTPROD_SELECT_ONE_NR: begin montprod_opa_data = one_reg; montprod_opb_data = residue_mem_montprod_read_data; end MONTPROD_SELECT_X_NR: begin montprod_opa_data = message_mem_int_rd_data; montprod_opb_data = residue_mem_montprod_read_data; end MONTPROD_SELECT_Z_P: begin montprod_opa_data = result_mem_int_rd_data; montprod_opb_data = p_mem_rd1_data; end MONTPROD_SELECT_P_P: begin montprod_opa_data = p_mem_rd0_data; montprod_opb_data = p_mem_rd1_data; end MONTPROD_SELECT_Z_ONE: begin montprod_opa_data = result_mem_int_rd_data; montprod_opb_data = b_one_reg; end default: begin montprod_opa_data = 32'h00000000; montprod_opb_data = 32'h00000000; end endcase // case (montprod_selcect_reg) end //---------------------------------------------------------------- // memory write mux // // Direct memory write signals to correct memory. //---------------------------------------------------------------- always @* begin : memory_write_process result_mem_int_wr_addr = montprod_result_addr; result_mem_int_wr_data = montprod_result_data; result_mem_int_we = 1'b0; p_mem_wr_addr = montprod_result_addr; p_mem_wr_data = montprod_result_data; p_mem_we = 1'b0; case (montprod_dest_reg) MONTPROD_DEST_Z: result_mem_int_we = montprod_result_we; MONTPROD_DEST_P: p_mem_we = montprod_result_we; default: begin end endcase // inhibit Z=Z*P when ei = 0 if (modexp_ctrl_reg == CTRL_ITERATE_Z_P) result_mem_int_we = result_mem_int_we & ei_reg; end //---------------------------------------------------------------- // loop_counter // // Calculate the loop counter and related variables. //---------------------------------------------------------------- always @* begin : loop_counters_process loop_counter_new = 13'b0; loop_counter_we = 1'b0; if (loop_counter_reg == {exponent_length_m1, 5'b11111}) last_iteration = 1'b1; else last_iteration = 1'b0; case (modexp_ctrl_reg) CTRL_CALCULATE_P0: begin loop_counter_new = 13'b0; loop_counter_we = 1'b1; end CTRL_ITERATE_END: begin loop_counter_new = loop_counter_reg + 1'b1; loop_counter_we = 1'b1; end default: begin end endcase end //---------------------------------------------------------------- // exponent // // Reads the exponent. //---------------------------------------------------------------- always @* begin : exponent_process // Accessing new instead of reg - pick up update at // CTRL_ITERATE_NEW to remove a pipeline stall. E_word_index = exponent_length_m1 - loop_counter_new[ 12 : 5 ]; E_bit_index = loop_counter_reg[ 04 : 0 ]; exponent_mem_int_rd_addr = E_word_index; ei_new = exponent_mem_int_rd_data[ E_bit_index ]; if (modexp_ctrl_reg == CTRL_ITERATE) ei_we = 1'b1; else ei_we = 1'b0; end //---------------------------------------------------------------- // modexp_ctrl // // Control FSM logic needed to perform the modexp operation. //---------------------------------------------------------------- always @* begin ready_new = 1'b0; ready_we = 1'b0; montprod_select_new = MONTPROD_SELECT_ONE_NR; montprod_select_we = 0; montprod_dest_new = MONTPROD_DEST_NOWHERE; montprod_dest_we = 0; montprod_calc = 0; modexp_ctrl_new = CTRL_IDLE; modexp_ctrl_we = 1'b0; cycle_ctr_start = 1'b0; cycle_ctr_stop = 1'b0; residue_calculate = 1'b0; residue_valid_int_validated = 1'b0; case (modexp_ctrl_reg) CTRL_IDLE: begin if (start) begin ready_new = 1'b0; ready_we = 1'b1; cycle_ctr_start = 1'b1; if (residue_valid_reg) begin //residue has alrady been calculated, start with MONTPROD( 1, Nr, MODULUS ) montprod_select_new = MONTPROD_SELECT_ONE_NR; montprod_select_we = 1; montprod_dest_new = MONTPROD_DEST_Z; montprod_dest_we = 1; montprod_calc = 1; modexp_ctrl_new = CTRL_CALCULATE_Z0; modexp_ctrl_we = 1; end else begin //modulus has been written and residue (Nr) must be calculated modexp_ctrl_new = CTRL_RESIDUE; modexp_ctrl_we = 1; residue_calculate = 1'b1; end end end CTRL_RESIDUE: begin if (residue_ready) begin montprod_select_new = MONTPROD_SELECT_ONE_NR; montprod_select_we = 1; montprod_dest_new = MONTPROD_DEST_Z; montprod_dest_we = 1; montprod_calc = 1; modexp_ctrl_new = CTRL_CALCULATE_Z0; modexp_ctrl_we = 1; residue_valid_int_validated = 1'b1; //update registers telling residue is valid end end CTRL_CALCULATE_Z0: begin if (montprod_ready) begin montprod_select_new = MONTPROD_SELECT_X_NR; montprod_select_we = 1; montprod_dest_new = MONTPROD_DEST_P; montprod_dest_we = 1; montprod_calc = 1; modexp_ctrl_new = CTRL_CALCULATE_P0; modexp_ctrl_we = 1; end end CTRL_CALCULATE_P0: begin if (montprod_ready == 1'b1) begin modexp_ctrl_new = CTRL_ITERATE; modexp_ctrl_we = 1; end end CTRL_ITERATE: begin montprod_select_new = MONTPROD_SELECT_Z_P; montprod_select_we = 1; montprod_dest_new = MONTPROD_DEST_Z; montprod_dest_we = 1; montprod_calc = 1; modexp_ctrl_new = CTRL_ITERATE_Z_P; modexp_ctrl_we = 1; if (ei_new == 1'b0 && exponation_mode_reg == EXPONATION_MODE_PUBLIC_FAST) begin //Skip the fake montgomery calculation, exponation_mode_reg optimizing for speed not blinding. montprod_select_new = MONTPROD_SELECT_P_P; montprod_dest_new = MONTPROD_DEST_P; modexp_ctrl_new = CTRL_ITERATE_P_P; end end CTRL_ITERATE_Z_P: if (montprod_ready) begin montprod_select_new = MONTPROD_SELECT_P_P; montprod_select_we = 1; montprod_dest_new = MONTPROD_DEST_P; montprod_dest_we = 1; montprod_calc = 1; modexp_ctrl_new = CTRL_ITERATE_P_P; modexp_ctrl_we = 1; end CTRL_ITERATE_P_P: if (montprod_ready == 1'b1) begin modexp_ctrl_new = CTRL_ITERATE_END; modexp_ctrl_we = 1; end CTRL_ITERATE_END: begin if (!last_iteration) begin modexp_ctrl_new = CTRL_ITERATE; modexp_ctrl_we = 1; end else begin montprod_select_new = MONTPROD_SELECT_Z_ONE; montprod_select_we = 1; montprod_dest_new = MONTPROD_DEST_Z; montprod_dest_we = 1; montprod_calc = 1; modexp_ctrl_new = CTRL_CALCULATE_ZN; modexp_ctrl_we = 1; end end CTRL_CALCULATE_ZN: begin if (montprod_ready) begin modexp_ctrl_new = CTRL_DONE; modexp_ctrl_we = 1; end end CTRL_DONE: begin cycle_ctr_stop = 1'b1; ready_new = 1'b1; ready_we = 1'b1; modexp_ctrl_new = CTRL_IDLE; modexp_ctrl_we = 1; end default: begin end endcase // case (modexp_ctrl_reg) end endmodule // modexp_core //====================================================================== // EOF modexp_core.v //======================================================================
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : modexp_top.v // Project : Common Evaluation Platform (CEP) // Description : This file provides a wishbone based-RSA core // module modexp_top( wb_adr_i, wb_cyc_i, wb_dat_i, wb_sel_i, wb_stb_i, wb_we_i, wb_ack_o, wb_err_o, wb_dat_o, wb_clk_i, wb_rst_i, int_o ); parameter dw = 32; parameter aw = 32; input [aw-1:0] wb_adr_i; //Address input wb_cyc_i; //bus cycle input [dw-1:0] wb_dat_i; //Data IN input [3:0] wb_sel_i; //Select Input Array input wb_stb_i; //Chip Select input wb_we_i; //Write Or Read Enabled output wb_ack_o; //Acknowledge output wb_err_o; //Error output reg [dw-1:0] wb_dat_o; //Data OUT output int_o; //Interrupt input wb_clk_i; //Clk input wb_rst_i; //Reset assign wb_ack_o = 1'b1; assign wb_err_o = 1'b0; assign int_o = 1'b0; wire reset_n=!wb_rst_i; //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- // The operand width is the internal operand width in bits. // The address width is the size of the address space used. This // value must be balances with OPERAND_WIDTH to allow a total // of 8192 bits of data. OPERAND_WIDTH * (ADDRESS_WIDTH ** 2) // is the formula. Note that the API data with is always 32 bits. localparam OPERAND_WIDTH = 32; localparam ADDRESS_WIDTH = 8; localparam ADDR_NAME0 = 8'h00; localparam ADDR_NAME1 = 8'h01; localparam ADDR_VERSION = 8'h02; localparam ADDR_CTRL = 8'h08; localparam CTRL_INIT_BIT = 0; localparam CTRL_NEXT_BIT = 1; localparam ADDR_STATUS = 8'h09; localparam STATUS_READY_BIT = 0; localparam ADDR_CYCLES_HIGH = 8'h10; localparam ADDR_CYCLES_LOW = 8'h11; localparam ADDR_MODULUS_LENGTH = 8'h20; localparam ADDR_EXPONENT_LENGTH = 8'h21; localparam ADDR_MODULUS_PTR_RST = 8'h30; localparam ADDR_MODULUS_DATA = 8'h31; localparam ADDR_EXPONENT_PTR_RST = 8'h40; localparam ADDR_EXPONENT_DATA = 8'h41; localparam ADDR_MESSAGE_PTR_RST = 8'h50; localparam ADDR_MESSAGE_DATA = 8'h51; localparam ADDR_RESULT_PTR_RST = 8'h60; localparam ADDR_RESULT_DATA = 8'h61; localparam DEFAULT_MODLENGTH = 8'h80; // 2048 bits. localparam DEFAULT_EXPLENGTH = 8'h80; localparam CORE_NAME0 = 32'h6d6f6465; // "mode" localparam CORE_NAME1 = 32'h78702020; // "xp " localparam CORE_VERSION = 32'h302e3532; // "0.52" //---------------------------------------------------------------- // Registers including update variables and write enable. //---------------------------------------------------------------- reg [07 : 0] exponent_length_reg; reg [07 : 0] exponent_length_new; reg exponent_length_we; reg [07 : 0] modulus_length_reg; reg [07 : 0] modulus_length_new; reg modulus_length_we; reg start_reg; reg start_new; //---------------------------------------------------------------- // Wires. //---------------------------------------------------------------- reg exponent_mem_api_rst; reg exponent_mem_api_cs; reg exponent_mem_api_wr; wire [31 : 0] exponent_mem_api_read_data; reg modulus_mem_api_rst; reg modulus_mem_api_cs; reg modulus_mem_api_wr; wire [31 : 0] modulus_mem_api_read_data; reg message_mem_api_rst; reg message_mem_api_cs; reg message_mem_api_wr; wire [31 : 0] message_mem_api_read_data; reg result_mem_api_rst; reg result_mem_api_cs; wire [31 : 0] result_mem_api_read_data; wire ready; wire [63 : 0] cycles; //reg [31 : 0] wb_dat_o; //---------------------------------------------------------------- // Concurrent connectivity for ports etc. //---------------------------------------------------------------- //assign wb_dat_o = wb_dat_o; //---------------------------------------------------------------- // core instantiations. //---------------------------------------------------------------- modexp_core #(.OPW(OPERAND_WIDTH), .ADW(ADDRESS_WIDTH)) core_inst( .clk(wb_clk_i), .reset_n(reset_n), .start(start_reg), .ready(ready), .exponent_length(exponent_length_reg), .modulus_length(modulus_length_reg), .cycles(cycles), .exponent_mem_api_cs(exponent_mem_api_cs), .exponent_mem_api_wr(exponent_mem_api_wr), .exponent_mem_api_rst(exponent_mem_api_rst), .exponent_mem_api_write_data(wb_dat_i), .exponent_mem_api_read_data(exponent_mem_api_read_data), .modulus_mem_api_cs(modulus_mem_api_cs), .modulus_mem_api_wr(modulus_mem_api_wr), .modulus_mem_api_rst(modulus_mem_api_rst), .modulus_mem_api_write_data(wb_dat_i), .modulus_mem_api_read_data(modulus_mem_api_read_data), .message_mem_api_cs(message_mem_api_cs), .message_mem_api_wr(message_mem_api_wr), .message_mem_api_rst(message_mem_api_rst), .message_mem_api_write_data(wb_dat_i), .message_mem_api_read_data(message_mem_api_read_data), .result_mem_api_cs(result_mem_api_cs), .result_mem_api_rst(result_mem_api_rst), .result_mem_api_read_data(result_mem_api_read_data) ); //---------------------------------------------------------------- // reg_update // // Update functionality for all registers in the core. // All registers are positive edge triggered with asynchronous // active low reset. All registers have write enable. //---------------------------------------------------------------- always @ (posedge wb_clk_i or negedge reset_n) begin if (!reset_n) begin start_reg <= 1'b0; exponent_length_reg <= DEFAULT_EXPLENGTH; modulus_length_reg <= DEFAULT_MODLENGTH; end else begin start_reg <= start_new; if (exponent_length_we) begin exponent_length_reg <= wb_dat_i[7 : 0]; end if (modulus_length_we) begin modulus_length_reg <= wb_dat_i[7 : 0]; end end end // reg_update //---------------------------------------------------------------- // api // // The interface command decoding logic. //---------------------------------------------------------------- always @* begin : api modulus_length_we = 1'b0; exponent_length_we = 1'b0; start_new = 1'b0; modulus_mem_api_rst = 1'b0; modulus_mem_api_cs = 1'b0; modulus_mem_api_wr = 1'b0; exponent_mem_api_rst = 1'b0; exponent_mem_api_cs = 1'b0; exponent_mem_api_wr = 1'b0; message_mem_api_rst = 1'b0; message_mem_api_cs = 1'b0; message_mem_api_wr = 1'b0; result_mem_api_rst = 1'b0; result_mem_api_cs = 1'b0; wb_dat_o = 32'h00000000; if (wb_stb_i) begin if (wb_we_i) begin case (wb_adr_i[9:2]) ADDR_CTRL: begin start_new = wb_dat_i[0]; end ADDR_MODULUS_LENGTH: begin modulus_length_we = 1'b1; end ADDR_EXPONENT_LENGTH: begin exponent_length_we = 1'b1; end ADDR_MODULUS_PTR_RST: begin modulus_mem_api_rst = 1'b1; end ADDR_MODULUS_DATA: begin modulus_mem_api_cs = 1'b1; modulus_mem_api_wr = 1'b1; end ADDR_EXPONENT_PTR_RST: begin exponent_mem_api_rst = 1'b1; end ADDR_EXPONENT_DATA: begin exponent_mem_api_cs = 1'b1; exponent_mem_api_wr = 1'b1; end ADDR_MESSAGE_PTR_RST: begin message_mem_api_rst = 1'b1; end ADDR_MESSAGE_DATA: begin message_mem_api_cs = 1'b1; message_mem_api_wr = 1'b1; end ADDR_RESULT_PTR_RST: begin result_mem_api_rst = 1'b1; end default: begin end endcase // case (wb_adr_i[7 : 0]) end // if (wb_we_i) else begin case (wb_adr_i[9:2]) ADDR_NAME0: wb_dat_o = CORE_NAME0; ADDR_NAME1: wb_dat_o = CORE_NAME1; ADDR_VERSION: wb_dat_o = CORE_VERSION; ADDR_CTRL: wb_dat_o = {31'h00000000, start_reg}; ADDR_STATUS: wb_dat_o = {31'h00000000, ready}; ADDR_CYCLES_HIGH: wb_dat_o = cycles[63 : 32]; ADDR_CYCLES_LOW: wb_dat_o = cycles[31 : 0]; ADDR_MODULUS_LENGTH: wb_dat_o = {24'h000000, modulus_length_reg}; ADDR_EXPONENT_LENGTH: wb_dat_o = {24'h000000, exponent_length_reg}; ADDR_MODULUS_DATA: begin modulus_mem_api_cs = 1'b1; wb_dat_o = modulus_mem_api_read_data; end ADDR_EXPONENT_DATA: begin exponent_mem_api_cs = 1'b1; wb_dat_o = exponent_mem_api_read_data; end ADDR_MESSAGE_DATA: begin message_mem_api_cs = 1'b1; wb_dat_o = message_mem_api_read_data; end ADDR_RESULT_DATA: begin result_mem_api_cs = 1'b1; wb_dat_o = result_mem_api_read_data; end default: begin end endcase // case (wb_adr_i) end // else: !if(wb_we_i) end // if (wb_stb_i) end // block: api endmodule // modexp //====================================================================== // EOF modexp_top.v //======================================================================
//====================================================================== // // montprod.v // --------- // Montgomery product calculator for the modular exponentiantion core. // // parameter OPW is operand word width in bits. // parameter ADW is address width in bits. // // // Author: Peter Magnusson, Joachim Strombergson // Copyright (c) 2015, NORDUnet A/S All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // - Neither the name of the NORDUnet nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== module montprod #(parameter OPW = 32, parameter ADW = 8) ( input wire clk, input wire reset_n, input wire calculate, output wire ready, input wire [(ADW - 1) : 0] length, output wire [(ADW - 1) : 0] opa_addr, input wire [(OPW - 1) : 0] opa_data, output wire [(ADW - 1) : 0] opb_addr, input wire [(OPW - 1) : 0] opb_data, output wire [(ADW - 1) : 0] opm_addr, input wire [(OPW - 1) : 0] opm_data, output wire [(ADW - 1) : 0] result_addr, output wire [(OPW - 1) : 0] result_data, output wire result_we ); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- localparam CTRL_IDLE = 4'h0; localparam CTRL_LOOP_ITER = 4'h1; localparam CTRL_LOOP_BQ = 4'h2; localparam CTRL_CALC_ADD = 4'h3; localparam CTRL_STALLPIPE_ADD = 4'h4; localparam CTRL_CALC_SDIV2 = 4'h5; localparam CTRL_STALLPIPE_SDIV2 = 4'h6; localparam CTRL_L_STALLPIPE_ES = 4'h7; localparam CTRL_EMIT_S = 4'h8; localparam SMUX_ZERO = 2'h0; localparam SMUX_ADD = 2'h1; localparam SMUX_SHR = 2'h2; //---------------------------------------------------------------- // Registers including update variables and write enable. //---------------------------------------------------------------- reg ready_reg; reg ready_new; reg ready_we; reg [3 : 0] montprod_ctrl_reg; reg [3 : 0] montprod_ctrl_new; reg montprod_ctrl_we; reg [1 : 0] s_mux_new; reg [1 : 0] s_mux_reg; reg s_mem_we_reg; reg s_mem_we_new; reg [(ADW - 1) : 0] s_mem_read_addr_reg; reg q_new; reg q_reg; reg b_new; reg b_reg; reg bq_we; reg [12 : 0] loop_ctr_reg; reg [12 : 0] loop_ctr_new; reg loop_ctr_we; reg loop_ctr_set; reg loop_ctr_dec; reg [(13 - ADW - 1) : 0] b_bit_index_reg; reg [(13 - ADW - 1) : 0] b_bit_index_new; reg b_bit_index_we; reg [(ADW - 1) : 0] word_index_reg; reg [(ADW - 1) : 0] word_index_new; reg word_index_we; reg [(ADW - 1) : 0] word_index_prev_reg; reg reset_word_index_lsw; reg reset_word_index_msw; reg inc_word_index; reg dec_word_index; reg add_carry_in_sa_reg; reg add_carry_in_sa_new; reg add_carry_in_sm_reg; reg add_carry_in_sm_new; reg shr_carry_in_reg; reg shr_carry_in_new; reg first_iteration_reg; reg first_iteration_new; reg first_iteration_we; reg test_reg; reg test_new; reg [(OPW - 2) : 0] shr_data_out_reg; reg shr_carry_out_reg; reg shr_carry_out_new; //---------------------------------------------------------------- // Wires. //---------------------------------------------------------------- wire [(OPW - 1) : 0] add_result_sa; wire add_carry_out_sa; wire [(OPW - 1) : 0] add_result_sm; wire add_carry_out_sm; reg [(ADW - 1) : 0] b_word_index; //loop counter as a word index /* verilator lint_off UNOPTFLAT */ reg [(OPW - 1) : 0] shr_data_in; /* verilator lint_on UNOPTFLAT */ wire shr_carry_out; wire [(OPW - 1) : 0] shr_data_out; reg [(ADW - 1) : 0] tmp_opa_addr; reg tmp_result_we; reg [(ADW - 1) : 0] s_mem_read_addr; wire [(OPW - 1) : 0] s_mem_read_data; reg [(ADW - 1) : 0] s_mem_write_addr; reg [(OPW - 1) : 0] s_mem_write_data; reg [(OPW - 1) : 0] tmp_s_mem_write_data; reg [(OPW - 1) : 0] sa_adder_data_in; /* verilator lint_off UNOPTFLAT */ reg [(OPW - 1) : 0] muxed_s_mem_read_data; /* verilator lint_on UNOPTFLAT */ reg [(OPW - 1) : 0] shifted_s_mem_write_data; wire [(ADW - 1) : 0] length_m1; // Temporary debug wires. reg [1 : 0] state_trace; reg [1 : 0] mux_trace; //---------------------------------------------------------------- // Concurrent connectivity for ports etc. //---------------------------------------------------------------- assign length_m1 = length - 1'b1; assign opa_addr = tmp_opa_addr; assign opb_addr = b_word_index; assign opm_addr = word_index_reg; assign result_addr = word_index_prev_reg; assign result_data = s_mem_read_data; assign result_we = tmp_result_we; assign ready = ready_reg; //---------------------------------------------------------------- // Instantions //---------------------------------------------------------------- blockmem1r1w #(.OPW(OPW), .ADW(ADW)) s_mem( .clk(clk), .read_addr(s_mem_read_addr), .read_data(s_mem_read_data), .wr(s_mem_we_reg), .write_addr(s_mem_write_addr), .write_data(s_mem_write_data) ); adder #(.OPW(OPW)) s_adder_sm( .a(muxed_s_mem_read_data), .b(opm_data), .carry_in(add_carry_in_sm_reg), .sum(add_result_sm), .carry_out(add_carry_out_sm) ); adder #(.OPW(OPW)) s_adder_sa( .a(sa_adder_data_in), .b(opa_data), .carry_in(add_carry_in_sa_reg), .sum(add_result_sa), .carry_out(add_carry_out_sa) ); shr #(.OPW(OPW)) shifter( .a(shr_data_in), .carry_in(shr_carry_in_reg), .adiv2(shr_data_out), .carry_out(shr_carry_out) ); //---------------------------------------------------------------- // reg_update // // Update functionality for all registers in the core. // All registers are positive edge triggered with asynchronous // active low reset. All registers have write enable. //---------------------------------------------------------------- always @ (posedge clk or negedge reset_n) begin : reg_update if (!reset_n) begin test_reg <= 1'b1; ready_reg <= 1'b1; loop_ctr_reg <= 13'h0; word_index_reg <= {ADW{1'b0}}; word_index_prev_reg <= {ADW{1'b0}}; add_carry_in_sa_reg <= 1'b0; add_carry_in_sm_reg <= 1'b0; shr_data_out_reg <= {(OPW - 1){1'b0}}; shr_carry_in_reg <= 1'b0; b_reg <= 1'b0; q_reg <= 1'b0; s_mux_reg <= SMUX_ZERO; s_mem_we_reg <= 1'b0; s_mem_read_addr_reg <= {ADW{1'b0}}; b_bit_index_reg <= {(13 - ADW){1'b0}}; first_iteration_reg <= 1'b0; montprod_ctrl_reg <= CTRL_IDLE; end else begin test_reg <= test_new; s_mem_read_addr_reg <= s_mem_read_addr; s_mem_we_reg <= s_mem_we_new; s_mux_reg <= s_mux_new; word_index_prev_reg <= word_index_reg; shr_carry_in_reg <= shr_carry_in_new; add_carry_in_sa_reg <= add_carry_in_sa_new; add_carry_in_sm_reg <= add_carry_in_sm_new; shr_data_out_reg <= shr_data_out[(OPW - 2) : 0]; if (word_index_we) word_index_reg <= word_index_new; if (first_iteration_we) first_iteration_reg <= first_iteration_new; if (b_bit_index_we) b_bit_index_reg <= b_bit_index_new; if (bq_we) begin b_reg <= b_new; q_reg <= q_new; end if (ready_we) ready_reg <= ready_new; if (loop_ctr_we) loop_ctr_reg <= loop_ctr_new; if (montprod_ctrl_we) begin montprod_ctrl_reg <= montprod_ctrl_new; end end end // reg_update //---------------------------------------------------------------- // s_logic // // Logic to calculate S memory updates including address // and write enable. This is the main montprod datapath. //---------------------------------------------------------------- always @* begin : s_logic shr_carry_in_new = 1'b0; muxed_s_mem_read_data = {OPW{1'b0}}; sa_adder_data_in = {OPW{1'b0}}; add_carry_in_sa_new = 1'b0; add_carry_in_sm_new = 1'b0; s_mem_read_addr = word_index_reg; s_mem_write_addr = s_mem_read_addr_reg; s_mem_write_data = {OPW{1'b0}}; s_mem_we_new = 1'b0; state_trace = 0; mux_trace = 0; tmp_s_mem_write_data = {OPW{1'b0}}; test_new = 1'b0; case (montprod_ctrl_reg) CTRL_LOOP_ITER: begin s_mem_read_addr = length_m1; end CTRL_CALC_ADD: begin //s = (s + q*M + b*A) >>> 1;, if(b==1) S+= A. Takes (1..length) cycles. s_mem_we_new = b_reg | q_reg | first_iteration_reg; state_trace = 1; test_new = 1'b1; end CTRL_CALC_SDIV2: begin //s = (s + q*M + b*A) >>> 1; s>>=1. Takes (1..length) cycles. s_mem_we_new = 1'b1; end default: begin end endcase case (s_mux_reg) SMUX_ADD: begin mux_trace = 1; if (first_iteration_reg) muxed_s_mem_read_data = {OPW{1'b0}}; else muxed_s_mem_read_data = s_mem_read_data; if (q_reg) sa_adder_data_in = add_result_sm; else sa_adder_data_in = muxed_s_mem_read_data; if (b_reg) tmp_s_mem_write_data = add_result_sa; else if (q_reg) tmp_s_mem_write_data = add_result_sm; else if (first_iteration_reg) tmp_s_mem_write_data = {OPW{1'b0}}; s_mem_write_data = tmp_s_mem_write_data; add_carry_in_sa_new = add_carry_out_sa; add_carry_in_sm_new = add_carry_out_sm; // Experimental integration of shift in add. shr_data_in = tmp_s_mem_write_data; shifted_s_mem_write_data = {shr_carry_out, shr_data_out_reg}; end SMUX_SHR: begin shr_data_in = s_mem_read_data; s_mem_write_data = shr_data_out; shr_carry_in_new = shr_carry_out; end default: begin end endcase end // s_logic //---------------------------------------------------------------- // bq // // Extract b and q bits. // b: current bit of B used. // q = (s - b * A) & 1 // update the b bit and word indices based on loop counter. //---------------------------------------------------------------- always @* begin : bq b_new = opb_data[b_bit_index_reg]; if (first_iteration_reg) q_new = 1'b0 ^ (opa_data[0] & b_new); else q_new = s_mem_read_data[0] ^ (opa_data[0] & b_new); // B_bit_index = 5'h1f - loop_counter[4:0]; b_bit_index_new = ((2**(13 - ADW)) - 1'b1) - loop_ctr_reg[(13 - ADW - 1) : 0]; b_word_index = loop_ctr_reg[12 : (13 - ADW)]; end // bq //---------------------------------------------------------------- // word_index // // Logic that implements the word index used to drive // addresses for operands. //---------------------------------------------------------------- always @* begin : word_index word_index_new = {ADW{1'b0}}; word_index_we = 1'b0; if (reset_word_index_lsw) begin word_index_new = length_m1; word_index_we = 1'b1; end if (reset_word_index_msw) begin word_index_new = {ADW{1'b0}}; word_index_we = 1'b1; end if (inc_word_index) begin word_index_new = word_index_reg + 1'b1; word_index_we = 1'b1; end if (dec_word_index) begin word_index_new = word_index_reg - 1'b1; word_index_we = 1'b1; end end // word_index //---------------------------------------------------------------- // loop_ctr // Logic for updating the loop counter. //---------------------------------------------------------------- always @* begin : loop_ctr loop_ctr_new = 13'h0; loop_ctr_we = 1'b0; if (loop_ctr_set) begin loop_ctr_new = {length, {(13 - ADW){1'b0}}} - 1'b1; loop_ctr_we = 1'b1; end if (loop_ctr_dec) begin loop_ctr_new = loop_ctr_reg - 1'b1; loop_ctr_we = 1'b1; end end //---------------------------------------------------------------- // montprod_ctrl // // Control FSM for the montgomery product calculator. //---------------------------------------------------------------- always @* begin : montprod_ctrl ready_new = 1'b0; ready_we = 1'b0; loop_ctr_set = 1'b0; loop_ctr_dec = 1'b0; b_bit_index_we = 1'b0; bq_we = 1'b0; s_mux_new = SMUX_ZERO; dec_word_index = 1'b0; inc_word_index = 1'b0; reset_word_index_lsw = 1'b0; reset_word_index_msw = 1'b0; first_iteration_new = 1'b0; first_iteration_we = 1'b0; tmp_opa_addr = word_index_reg; tmp_result_we = 1'b0; montprod_ctrl_new = CTRL_IDLE; montprod_ctrl_we = 1'b0; case (montprod_ctrl_reg) CTRL_IDLE: begin if (calculate) begin first_iteration_new = 1'b1; first_iteration_we = 1'b1; ready_new = 1'b0; ready_we = 1'b1; reset_word_index_lsw = 1'b1; loop_ctr_set = 1'b1; montprod_ctrl_new = CTRL_LOOP_ITER; montprod_ctrl_we = 1'b1; end end //calculate q = (s - b * A) & 1;. // Also abort loop if done. CTRL_LOOP_ITER: begin tmp_opa_addr = length_m1; b_bit_index_we = 1'b1; montprod_ctrl_new = CTRL_LOOP_BQ; montprod_ctrl_we = 1'b1; end CTRL_LOOP_BQ: begin reset_word_index_lsw = 1'b1; bq_we = 1'b1; montprod_ctrl_new = CTRL_CALC_ADD; montprod_ctrl_we = 1'b1; end CTRL_CALC_ADD: begin s_mux_new = SMUX_ADD; if (word_index_reg == 0) begin reset_word_index_lsw = 1'b1; montprod_ctrl_new = CTRL_STALLPIPE_ADD; montprod_ctrl_we = 1'b1; end else begin dec_word_index = 1'b1; end end CTRL_STALLPIPE_ADD: begin first_iteration_new = 1'b0; first_iteration_we = 1'b1; reset_word_index_msw = 1'b1; montprod_ctrl_new = CTRL_CALC_SDIV2; montprod_ctrl_we = 1'b1; end CTRL_CALC_SDIV2: begin s_mux_new = SMUX_SHR; if (word_index_reg == length_m1) begin montprod_ctrl_new = CTRL_STALLPIPE_SDIV2; montprod_ctrl_we = 1'b1; end else inc_word_index = 1'b1; end CTRL_STALLPIPE_SDIV2: begin loop_ctr_dec = 1'b1; montprod_ctrl_new = CTRL_LOOP_ITER; montprod_ctrl_we = 1'b1; reset_word_index_lsw = 1'b1; if (loop_ctr_reg == 0) begin montprod_ctrl_new = CTRL_L_STALLPIPE_ES; montprod_ctrl_we = 1'b1; end end CTRL_L_STALLPIPE_ES: begin montprod_ctrl_new = CTRL_EMIT_S; montprod_ctrl_we = 1'b1; end CTRL_EMIT_S: begin dec_word_index = 1'b1; tmp_result_we = 1'b1; if (word_index_prev_reg == 0) begin ready_new = 1'b1; ready_we = 1'b1; montprod_ctrl_new = CTRL_IDLE; montprod_ctrl_we = 1'b1; end end default: begin end endcase // case (montprod_ctrl_reg) end // montprod_ctrl endmodule // montprod //====================================================================== // EOF montprod.v //======================================================================
//====================================================================== // // residue.v // --------- // Modulus 2**2N residue calculator for montgomery calculations. // // m_residue_2_2N_array( N, M, Nr) // Nr = 00...01 ; Nr = 1 == 2**(2N-2N) // for (int i = 0; i < 2 * N; i++) // Nr = Nr shift left 1 // if (Nr less than M) continue; // Nr = Nr - M // return Nr // // // // Author: Peter Magnusson // Copyright (c) 2015, NORDUnet A/S All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // - Neither the name of the NORDUnet nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== module residue #(parameter OPW = 32, parameter ADW = 8) ( input wire clk, input wire reset_n, input wire calculate, output wire ready, input wire [14 : 0] nn, //MAX(2*N)=8192*2 (14 bit) input wire [(ADW - 1) : 0] length, output wire [(ADW - 1) : 0] opa_rd_addr, input wire [(OPW - 1) : 0] opa_rd_data, output wire [(ADW - 1) : 0] opa_wr_addr, output wire [(OPW - 1) : 0] opa_wr_data, output wire opa_wr_we, output wire [(ADW - 1) : 0] opm_addr, input wire [(OPW - 1) : 0] opm_data ); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- localparam CTRL_IDLE = 4'h0; localparam CTRL_INIT = 4'h1; localparam CTRL_INIT_STALL = 4'h2; localparam CTRL_SHL = 4'h3; localparam CTRL_SHL_STALL = 4'h4; localparam CTRL_COMPARE = 4'h5; localparam CTRL_COMPARE_STALL = 4'h6; localparam CTRL_SUB = 4'h7; localparam CTRL_SUB_STALL = 4'h8; localparam CTRL_LOOP = 4'h9; //---------------------------------------------------------------- // Registers including update variables and write enable. //---------------------------------------------------------------- reg [(ADW - 1) : 0] opa_rd_addr_reg; reg [(ADW - 1) : 0] opa_wr_addr_reg; reg [(OPW - 1) : 0] opa_wr_data_reg; reg opa_wr_we_reg; reg [(ADW - 1) : 0] opm_addr_reg; reg ready_reg; reg ready_new; reg ready_we; reg [03 : 0] residue_ctrl_reg; reg [03 : 0] residue_ctrl_new; reg residue_ctrl_we; reg reset_word_index; reg reset_n_counter; reg [14 : 0] loop_counter_1_to_nn_reg; //for i = 1 to nn (2*N) reg [14 : 0] loop_counter_1_to_nn_new; reg loop_counter_1_to_nn_we; reg [14 : 0] nn_reg; reg nn_we; reg [(ADW - 1) : 0] length_m1_reg; reg [(ADW - 1) : 0] length_m1_new; reg length_m1_we; reg [(ADW - 1) : 0] word_index_reg; reg [(ADW - 1) : 0] word_index_new; reg word_index_we; reg [(OPW - 1) : 0] one_data; wire [(OPW - 1) : 0] sub_data; wire [(OPW - 1) : 0] shl_data; reg sub_carry_in_new; reg sub_carry_in_reg; wire sub_carry_out; reg shl_carry_in_new; reg shl_carry_in_reg; wire shl_carry_out; //---------------------------------------------------------------- // Concurrent connectivity for ports etc. //---------------------------------------------------------------- assign opa_rd_addr = opa_rd_addr_reg; assign opa_wr_addr = opa_wr_addr_reg; assign opa_wr_data = opa_wr_data_reg; assign opa_wr_we = opa_wr_we_reg; assign opm_addr = opm_addr_reg; assign ready = ready_reg; //---------------------------------------------------------------- // Instantions //---------------------------------------------------------------- adder #(.OPW(OPW)) add_inst( .a(opa_rd_data), .b( ~ opm_data), .carry_in(sub_carry_in_reg), .sum(sub_data), .carry_out(sub_carry_out) ); shl #(.OPW(OPW)) shl_inst( .a(opa_rd_data), .carry_in(shl_carry_in_reg), .amul2(shl_data), .carry_out(shl_carry_out) ); //---------------------------------------------------------------- // reg_update //---------------------------------------------------------------- always @ (posedge clk or negedge reset_n) begin if (!reset_n) begin residue_ctrl_reg <= CTRL_IDLE; word_index_reg <= {ADW{1'b1}}; length_m1_reg <= {ADW{1'b1}}; nn_reg <= 15'h0; loop_counter_1_to_nn_reg <= 15'h0; ready_reg <= 1'b1; sub_carry_in_reg <= 1'b0; shl_carry_in_reg <= 1'b0; end else begin if (residue_ctrl_we) residue_ctrl_reg <= residue_ctrl_new; if (word_index_we) word_index_reg <= word_index_new; if (length_m1_we) length_m1_reg <= length_m1_new; if (nn_we) nn_reg <= nn; if (loop_counter_1_to_nn_we) loop_counter_1_to_nn_reg <= loop_counter_1_to_nn_new; if (ready_we) ready_reg <= ready_new; sub_carry_in_reg <= sub_carry_in_new; shl_carry_in_reg <= shl_carry_in_new; end end // reg_update //---------------------------------------------------------------- // loop counter process. implements for (int i = 0; i < 2 * N; i++) // // m_residue_2_2N_array( N, M, Nr) // Nr = 00...01 ; Nr = 1 == 2**(2N-2N) // for (int i = 0; i < 2 * N; i++) // Nr = Nr shift left 1 // if (Nr less than M) continue; // Nr = Nr - M // return Nr // //---------------------------------------------------------------- always @* begin : process_1_to_2n loop_counter_1_to_nn_new = loop_counter_1_to_nn_reg + 15'h1; loop_counter_1_to_nn_we = 1'b0; if (reset_n_counter) begin loop_counter_1_to_nn_new = 15'h1; loop_counter_1_to_nn_we = 1'b1; end if (residue_ctrl_reg == CTRL_LOOP) loop_counter_1_to_nn_we = 1'b1; end //---------------------------------------------------------------- // implements looping over words in a multiword operation //---------------------------------------------------------------- always @* begin : word_index_process word_index_new = word_index_reg - 1'b1; word_index_we = 1'b1; if (reset_word_index) word_index_new = length_m1_reg; if (residue_ctrl_reg == CTRL_IDLE) //reduce a pipeline stage with early read word_index_new = length_m1_new; end //---------------------------------------------------------------- // writer process. implements: // Nr = 00...01 ; Nr = 1 == 2**(2N-2N) // Nr = Nr shift left 1 // Nr = Nr - M // // m_residue_2_2N_array( N, M, Nr) // Nr = 00...01 ; Nr = 1 == 2**(2N-2N) // for (int i = 0; i < 2 * N; i++) // Nr = Nr shift left 1 // if (Nr less than M) continue; // Nr = Nr - M // return Nr //---------------------------------------------------------------- always @* begin : writer_process opa_wr_addr_reg = word_index_reg; case (residue_ctrl_reg) CTRL_INIT: begin opa_wr_data_reg = one_data; opa_wr_we_reg = 1'b1; end CTRL_SUB: begin opa_wr_data_reg = sub_data; opa_wr_we_reg = 1'b1; end CTRL_SHL: begin opa_wr_data_reg = shl_data; opa_wr_we_reg = 1'b1; end default: begin opa_wr_data_reg = 32'h0; opa_wr_we_reg = 1'b0; end endcase end //---------------------------------------------------------------- // reader process. reads from new value because it occurs one // cycle earlier than the writer. //---------------------------------------------------------------- always @* begin : reader_process opa_rd_addr_reg = word_index_new; opm_addr_reg = word_index_new; end //---------------------------------------------------------------- // carry process. "Ripple carry awesomeness!" //---------------------------------------------------------------- always @* begin : carry_process case (residue_ctrl_reg) CTRL_COMPARE: sub_carry_in_new = sub_carry_out; CTRL_SUB: sub_carry_in_new = sub_carry_out; default: sub_carry_in_new = 1'b1; endcase case (residue_ctrl_reg) CTRL_SHL: shl_carry_in_new = shl_carry_out; default: shl_carry_in_new = 1'b0; endcase end //---------------------------------------------------------------- // Nr = 00...01 ; Nr = 1 == 2**(2N-2N) //---------------------------------------------------------------- always @* begin : one_process one_data = 32'h0; if (residue_ctrl_reg == CTRL_INIT) if (word_index_reg == length_m1_reg) one_data = {{(OPW - 1){1'b0}}, 1'b1}; end //---------------------------------------------------------------- // residue_ctrl // // Control FSM for residue //---------------------------------------------------------------- always @* begin : residue_ctrl ready_new = 1'b0; ready_we = 1'b0; reset_word_index = 1'b0; reset_n_counter = 1'b0; length_m1_new = length - 1'b1; length_m1_we = 1'b0; nn_we = 1'b0; residue_ctrl_new = CTRL_IDLE; residue_ctrl_we = 1'b0; case (residue_ctrl_reg) CTRL_IDLE: if (calculate) begin ready_new = 1'b0; ready_we = 1'b1; reset_word_index = 1'b1; length_m1_we = 1'b1; nn_we = 1'b1; residue_ctrl_new = CTRL_INIT; residue_ctrl_we = 1'b1; end // Nr = 00...01 ; Nr = 1 == 2**(2N-2N) CTRL_INIT: if (word_index_reg == 0) begin residue_ctrl_new = CTRL_INIT_STALL; residue_ctrl_we = 1'b1; end CTRL_INIT_STALL: begin reset_word_index = 1'b1; reset_n_counter = 1'b1; residue_ctrl_new = CTRL_SHL; residue_ctrl_we = 1'b1; end // Nr = Nr shift left 1 CTRL_SHL: begin if (word_index_reg == 0) begin residue_ctrl_new = CTRL_SHL_STALL; residue_ctrl_we = 1'b1; end end CTRL_SHL_STALL: begin reset_word_index = 1'b1; residue_ctrl_new = CTRL_COMPARE; residue_ctrl_we = 1'b1; end //if (Nr less than M) continue CTRL_COMPARE: if (word_index_reg == 0) begin residue_ctrl_new = CTRL_COMPARE_STALL; residue_ctrl_we = 1'b1; end CTRL_COMPARE_STALL: begin reset_word_index = 1'b1; residue_ctrl_we = 1'b1; if (sub_carry_in_reg == 1'b1) //TODO: Bug! detect CF to detect less than, but no detect ZF to detect equal to. residue_ctrl_new = CTRL_SUB; else residue_ctrl_new = CTRL_LOOP; end //Nr = Nr - M CTRL_SUB: if (word_index_reg == 0) begin residue_ctrl_new = CTRL_SUB_STALL; residue_ctrl_we = 1'b1; end CTRL_SUB_STALL: begin residue_ctrl_new = CTRL_LOOP; residue_ctrl_we = 1'b1; end //for (int i = 0; i < 2 * N; i++) CTRL_LOOP: begin if (loop_counter_1_to_nn_reg == nn_reg) begin ready_new = 1'b1; ready_we = 1'b1; residue_ctrl_new = CTRL_IDLE; residue_ctrl_we = 1'b1; end else begin reset_word_index = 1'b1; residue_ctrl_new = CTRL_SHL; residue_ctrl_we = 1'b1; end end default: begin end endcase end endmodule // residue //====================================================================== // EOF residue.v //======================================================================
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : rsa_top_axi4lite.v // Project : Common Evaluation Platform (CEP) // Description : This file provides an axi4-lite wrapper for the wishbone based-RSA core // module rsa_top_axi4lite ( // Clock & Reset input logic clk_i, input logic rst_ni, // AXI4-Lite Slave Interface AXI_LITE.Slave slave ); // AES wishbone slave wires wire wb_clk; wire wb_rst; wire wb_rst_n; wire [slave.AXI_ADDR_WIDTH - 1:0] wbs_d_rsa_adr_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_rsa_dat_i; wire [3:0] wbs_d_rsa_sel_i; wire wbs_d_rsa_we_i; wire wbs_d_rsa_cyc_i; wire wbs_d_rsa_stb_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_rsa_dat_o; wire wbs_d_rsa_ack_o; // Instantiate the AXI4Lite to Wishbone bridge bonfire_axi4l2wb #( .ADRWIDTH (slave.AXI_ADDR_WIDTH), .FAST_READ_TERM (1'd0) ) bonfire_axi4l2wb_inst ( .S_AXI_ACLK (clk_i), .S_AXI_ARESETN (rst_ni), .S_AXI_AWADDR (slave.aw_addr), .S_AXI_AWVALID (slave.aw_valid), .S_AXI_AWREADY (slave.aw_ready), .S_AXI_WDATA (slave.w_data), .S_AXI_WSTRB (slave.w_strb), .S_AXI_WVALID (slave.w_valid), .S_AXI_WREADY (slave.w_ready), .S_AXI_ARADDR (slave.ar_addr), .S_AXI_ARVALID (slave.ar_valid), .S_AXI_ARREADY (slave.ar_ready), .S_AXI_RDATA (slave.r_data), .S_AXI_RRESP (slave.r_resp), .S_AXI_RVALID (slave.r_valid), .S_AXI_RREADY (slave.r_ready), .S_AXI_BRESP (slave.b_resp), .S_AXI_BVALID (slave.b_valid), .S_AXI_BREADY (slave.b_ready), .wb_clk_o (wb_clk), .wb_rst_o (wb_rst), .wb_addr_o (wbs_d_rsa_adr_i), .wb_dat_o (wbs_d_rsa_dat_i), .wb_we_o (wbs_d_rsa_we_i), .wb_sel_o (wbs_d_rsa_sel_i), .wb_stb_o (wbs_d_rsa_stb_i), .wb_cyc_o (wbs_d_rsa_cyc_i), .wb_dat_i (wbs_d_rsa_dat_o), .wb_ack_i (wbs_d_rsa_ack_o) ); // Instantiate the wishbone-based MD5 Core modexp_top modexp_top_inst ( // Wishbone Slave interface .wb_clk_i (wb_clk), .wb_rst_i (wb_rst), .wb_dat_i (wbs_d_rsa_dat_i), .wb_adr_i (wbs_d_rsa_adr_i), .wb_sel_i (wbs_d_rsa_sel_i[3:0]), .wb_we_i (wbs_d_rsa_we_i), .wb_cyc_i (wbs_d_rsa_cyc_i), .wb_stb_i (wbs_d_rsa_stb_i), .wb_dat_o (wbs_d_rsa_dat_o), .wb_err_o (), .wb_ack_o (wbs_d_rsa_ack_o), // Processor interrupt .int_o () ); endmodule // end rsa_top_axi4lite
//====================================================================== // // shl.v // ----- // One bit left shift of words with carry in and carry out. Used in // the residue module of the modexp core. // // // Author: Peter Magnusson, Joachim Strömbergson // Copyright (c) 2015, NORDUnet A/S All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // - Neither the name of the NORDUnet nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== module shl #(parameter OPW = 32) ( input wire [(OPW - 1) : 0] a, input wire carry_in, output wire [(OPW - 1) : 0] amul2, output wire carry_out ); assign amul2 = {a[(OPW - 2) : 0], carry_in}; assign carry_out = a[(OPW - 1)]; endmodule // shl //====================================================================== // EOF shl.v //======================================================================
//====================================================================== // // shr32.v // ------- // One bit right shift with carry in and carry out. // Used in the montprod module of the modexp core. // // // Author: Peter Magnusson, Joachim Strömbergson // Copyright (c) 2015, NORDUnet A/S All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // - Neither the name of the NORDUnet nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== module shr #(parameter OPW = 32) ( input wire [(OPW - 1) : 0] a, input wire carry_in, output wire [(OPW - 1) : 0] adiv2, output wire carry_out ); assign adiv2 = {carry_in, a[(OPW - 1) : 1]}; assign carry_out = a[0]; endmodule // shr //====================================================================== // EOF shr.v //======================================================================
//====================================================================== // // sha256_core.v // ------------- // Verilog 2001 implementation of the SHA-256 hash function. // This is the internal core with wide interfaces. // // // Author: Joachim Strombergson // Copyright (c) 2013, Secworks Sweden AB // All rights reserved. // // Redistribution and use in source and binary forms, with or // without modification, are permitted provided that the following // conditions are met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in // the documentation and/or other materials provided with the // distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== // Modified by Matthew Hicks: // Convert to synchronous, positive level reset // Fix at 256-bit mode module sha256( input wire clk, input wire rst, input wire init, input wire next, input wire [511 : 0] block, output wire ready, output wire [255 : 0] digest, output wire digest_valid ); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- parameter SHA256_H0_0 = 32'h6a09e667; parameter SHA256_H0_1 = 32'hbb67ae85; parameter SHA256_H0_2 = 32'h3c6ef372; parameter SHA256_H0_3 = 32'ha54ff53a; parameter SHA256_H0_4 = 32'h510e527f; parameter SHA256_H0_5 = 32'h9b05688c; parameter SHA256_H0_6 = 32'h1f83d9ab; parameter SHA256_H0_7 = 32'h5be0cd19; parameter SHA256_ROUNDS = 63; parameter CTRL_IDLE = 0; parameter CTRL_ROUNDS = 1; parameter CTRL_DONE = 2; //---------------------------------------------------------------- // Registers including update variables and write enable. //---------------------------------------------------------------- reg [31 : 0] a_reg; reg [31 : 0] a_new; reg [31 : 0] b_reg; reg [31 : 0] b_new; reg [31 : 0] c_reg; reg [31 : 0] c_new; reg [31 : 0] d_reg; reg [31 : 0] d_new; reg [31 : 0] e_reg; reg [31 : 0] e_new; reg [31 : 0] f_reg; reg [31 : 0] f_new; reg [31 : 0] g_reg; reg [31 : 0] g_new; reg [31 : 0] h_reg; reg [31 : 0] h_new; reg a_h_we; reg [31 : 0] H0_reg; reg [31 : 0] H0_new; reg [31 : 0] H1_reg; reg [31 : 0] H1_new; reg [31 : 0] H2_reg; reg [31 : 0] H2_new; reg [31 : 0] H3_reg; reg [31 : 0] H3_new; reg [31 : 0] H4_reg; reg [31 : 0] H4_new; reg [31 : 0] H5_reg; reg [31 : 0] H5_new; reg [31 : 0] H6_reg; reg [31 : 0] H6_new; reg [31 : 0] H7_reg; reg [31 : 0] H7_new; reg H_we; reg [5 : 0] t_ctr_reg; reg [5 : 0] t_ctr_new; reg t_ctr_we; reg t_ctr_inc; reg t_ctr_rst; reg digest_valid_reg; reg digest_valid_new; reg digest_valid_we; reg [1 : 0] sha256_ctrl_reg; reg [1 : 0] sha256_ctrl_new; reg sha256_ctrl_we; //---------------------------------------------------------------- // Wires. //---------------------------------------------------------------- reg digest_init; reg digest_update; reg state_init; reg state_update; reg first_block; reg ready_flag; reg [31 : 0] t1; reg [31 : 0] t2; wire [31 : 0] k_data; reg w_init; reg w_next; wire [31 : 0] w_data; //---------------------------------------------------------------- // Module instantiantions. //---------------------------------------------------------------- sha256_k_constants k_constants_inst( .addr(t_ctr_reg), .K(k_data) ); sha256_w_mem w_mem_inst( .clk(clk), .rst(rst), .block(block), .init(w_init), .next(w_next), .w(w_data) ); //---------------------------------------------------------------- // Concurrent connectivity for ports etc. //---------------------------------------------------------------- assign ready = ready_flag; assign digest = {H0_reg, H1_reg, H2_reg, H3_reg, H4_reg, H5_reg, H6_reg, H7_reg}; assign digest_valid = digest_valid_reg; //---------------------------------------------------------------- // reg_update // Update functionality for all registers in the core. // All registers are positive edge triggered with synchronous // reset. All registers have write enable. //---------------------------------------------------------------- always @ (posedge clk) begin : reg_update if (rst) begin a_reg <= 32'h0; b_reg <= 32'h0; c_reg <= 32'h0; d_reg <= 32'h0; e_reg <= 32'h0; f_reg <= 32'h0; g_reg <= 32'h0; h_reg <= 32'h0; H0_reg <= 32'h0; H1_reg <= 32'h0; H2_reg <= 32'h0; H3_reg <= 32'h0; H4_reg <= 32'h0; H5_reg <= 32'h0; H6_reg <= 32'h0; H7_reg <= 32'h0; digest_valid_reg <= 0; t_ctr_reg <= 6'h0; sha256_ctrl_reg <= CTRL_IDLE; end else begin if (a_h_we) begin a_reg <= a_new; b_reg <= b_new; c_reg <= c_new; d_reg <= d_new; e_reg <= e_new; f_reg <= f_new; g_reg <= g_new; h_reg <= h_new; end if (H_we) begin H0_reg <= H0_new; H1_reg <= H1_new; H2_reg <= H2_new; H3_reg <= H3_new; H4_reg <= H4_new; H5_reg <= H5_new; H6_reg <= H6_new; H7_reg <= H7_new; end if (t_ctr_we) t_ctr_reg <= t_ctr_new; if (digest_valid_we) digest_valid_reg <= digest_valid_new; if (sha256_ctrl_we) sha256_ctrl_reg <= sha256_ctrl_new; end end // reg_update //---------------------------------------------------------------- // digest_logic // // The logic needed to init as well as update the digest. //---------------------------------------------------------------- always @* begin : digest_logic H0_new = 32'h0; H1_new = 32'h0; H2_new = 32'h0; H3_new = 32'h0; H4_new = 32'h0; H5_new = 32'h0; H6_new = 32'h0; H7_new = 32'h0; H_we = 0; if (digest_init) begin H_we = 1; H0_new = SHA256_H0_0; H1_new = SHA256_H0_1; H2_new = SHA256_H0_2; H3_new = SHA256_H0_3; H4_new = SHA256_H0_4; H5_new = SHA256_H0_5; H6_new = SHA256_H0_6; H7_new = SHA256_H0_7; end if (digest_update) begin H0_new = H0_reg + a_reg; H1_new = H1_reg + b_reg; H2_new = H2_reg + c_reg; H3_new = H3_reg + d_reg; H4_new = H4_reg + e_reg; H5_new = H5_reg + f_reg; H6_new = H6_reg + g_reg; H7_new = H7_reg + h_reg; H_we = 1; end end // digest_logic //---------------------------------------------------------------- // t1_logic // // The logic for the T1 function. //---------------------------------------------------------------- always @* begin : t1_logic reg [31 : 0] sum1; reg [31 : 0] ch; sum1 = {e_reg[5 : 0], e_reg[31 : 6]} ^ {e_reg[10 : 0], e_reg[31 : 11]} ^ {e_reg[24 : 0], e_reg[31 : 25]}; ch = (e_reg & f_reg) ^ ((~e_reg) & g_reg); t1 = h_reg + sum1 + ch + w_data + k_data; end // t1_logic //---------------------------------------------------------------- // t2_logic // // The logic for the T2 function //---------------------------------------------------------------- always @* begin : t2_logic reg [31 : 0] sum0; reg [31 : 0] maj; sum0 = {a_reg[1 : 0], a_reg[31 : 2]} ^ {a_reg[12 : 0], a_reg[31 : 13]} ^ {a_reg[21 : 0], a_reg[31 : 22]}; maj = (a_reg & b_reg) ^ (a_reg & c_reg) ^ (b_reg & c_reg); t2 = sum0 + maj; end // t2_logic //---------------------------------------------------------------- // state_logic // // The logic needed to init as well as update the state during // round processing. //---------------------------------------------------------------- always @* begin : state_logic a_new = 32'h0; b_new = 32'h0; c_new = 32'h0; d_new = 32'h0; e_new = 32'h0; f_new = 32'h0; g_new = 32'h0; h_new = 32'h0; a_h_we = 0; if (state_init) begin a_h_we = 1; if (first_block) begin a_new = SHA256_H0_0; b_new = SHA256_H0_1; c_new = SHA256_H0_2; d_new = SHA256_H0_3; e_new = SHA256_H0_4; f_new = SHA256_H0_5; g_new = SHA256_H0_6; h_new = SHA256_H0_7; end else begin a_new = H0_reg; b_new = H1_reg; c_new = H2_reg; d_new = H3_reg; e_new = H4_reg; f_new = H5_reg; g_new = H6_reg; h_new = H7_reg; end end if (state_update) begin a_new = t1 + t2; b_new = a_reg; c_new = b_reg; d_new = c_reg; e_new = d_reg + t1; f_new = e_reg; g_new = f_reg; h_new = g_reg; a_h_we = 1; end end // state_logic //---------------------------------------------------------------- // t_ctr // // Update logic for the round counter, a monotonically // increasing counter with reset. //---------------------------------------------------------------- always @* begin : t_ctr t_ctr_new = 0; t_ctr_we = 0; if (t_ctr_rst) begin t_ctr_new = 0; t_ctr_we = 1; end if (t_ctr_inc) begin t_ctr_new = t_ctr_reg + 1'b1; t_ctr_we = 1; end end // t_ctr //---------------------------------------------------------------- // sha256_ctrl_fsm // // Logic for the state machine controlling the core behaviour. //---------------------------------------------------------------- always @* begin : sha256_ctrl_fsm digest_init = 0; digest_update = 0; state_init = 0; state_update = 0; first_block = 0; ready_flag = 0; w_init = 0; w_next = 0; t_ctr_inc = 0; t_ctr_rst = 0; digest_valid_new = 0; digest_valid_we = 0; sha256_ctrl_new = CTRL_IDLE; sha256_ctrl_we = 0; case (sha256_ctrl_reg) CTRL_IDLE: begin ready_flag = 1; if (init) begin digest_init = 1; w_init = 1; state_init = 1; first_block = 1; t_ctr_rst = 1; digest_valid_new = 0; digest_valid_we = 1; sha256_ctrl_new = CTRL_ROUNDS; sha256_ctrl_we = 1; end if (next) begin t_ctr_rst = 1; w_init = 1; state_init = 1; digest_valid_new = 0; digest_valid_we = 1; sha256_ctrl_new = CTRL_ROUNDS; sha256_ctrl_we = 1; end end CTRL_ROUNDS: begin w_next = 1; state_update = 1; t_ctr_inc = 1; if (t_ctr_reg == SHA256_ROUNDS) begin sha256_ctrl_new = CTRL_DONE; sha256_ctrl_we = 1; end end CTRL_DONE: begin digest_update = 1; digest_valid_new = 1; digest_valid_we = 1; sha256_ctrl_new = CTRL_IDLE; sha256_ctrl_we = 1; end endcase // case (sha256_ctrl_reg) end // sha256_ctrl_fsm endmodule // sha256_core //====================================================================== // EOF sha256_core.v //======================================================================
//====================================================================== // // sha256_k_constants.v // -------------------- // The table K with constants in the SHA-256 hash function. // // // Author: Joachim Strombergson // Copyright (c) 2013, Secworks Sweden AB // All rights reserved. // // Redistribution and use in source and binary forms, with or // without modification, are permitted provided that the following // conditions are met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in // the documentation and/or other materials provided with the // distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== module sha256_k_constants( input wire [5 : 0] addr, output wire [31 : 0] K ); //---------------------------------------------------------------- // Wires. //---------------------------------------------------------------- reg [31 : 0] tmp_K; //---------------------------------------------------------------- // Concurrent connectivity for ports etc. //---------------------------------------------------------------- assign K = tmp_K; //---------------------------------------------------------------- // addr_mux //---------------------------------------------------------------- always @* begin : addr_mux case(addr) 00: tmp_K = 32'h428a2f98; 01: tmp_K = 32'h71374491; 02: tmp_K = 32'hb5c0fbcf; 03: tmp_K = 32'he9b5dba5; 04: tmp_K = 32'h3956c25b; 05: tmp_K = 32'h59f111f1; 06: tmp_K = 32'h923f82a4; 07: tmp_K = 32'hab1c5ed5; 08: tmp_K = 32'hd807aa98; 09: tmp_K = 32'h12835b01; 10: tmp_K = 32'h243185be; 11: tmp_K = 32'h550c7dc3; 12: tmp_K = 32'h72be5d74; 13: tmp_K = 32'h80deb1fe; 14: tmp_K = 32'h9bdc06a7; 15: tmp_K = 32'hc19bf174; 16: tmp_K = 32'he49b69c1; 17: tmp_K = 32'hefbe4786; 18: tmp_K = 32'h0fc19dc6; 19: tmp_K = 32'h240ca1cc; 20: tmp_K = 32'h2de92c6f; 21: tmp_K = 32'h4a7484aa; 22: tmp_K = 32'h5cb0a9dc; 23: tmp_K = 32'h76f988da; 24: tmp_K = 32'h983e5152; 25: tmp_K = 32'ha831c66d; 26: tmp_K = 32'hb00327c8; 27: tmp_K = 32'hbf597fc7; 28: tmp_K = 32'hc6e00bf3; 29: tmp_K = 32'hd5a79147; 30: tmp_K = 32'h06ca6351; 31: tmp_K = 32'h14292967; 32: tmp_K = 32'h27b70a85; 33: tmp_K = 32'h2e1b2138; 34: tmp_K = 32'h4d2c6dfc; 35: tmp_K = 32'h53380d13; 36: tmp_K = 32'h650a7354; 37: tmp_K = 32'h766a0abb; 38: tmp_K = 32'h81c2c92e; 39: tmp_K = 32'h92722c85; 40: tmp_K = 32'ha2bfe8a1; 41: tmp_K = 32'ha81a664b; 42: tmp_K = 32'hc24b8b70; 43: tmp_K = 32'hc76c51a3; 44: tmp_K = 32'hd192e819; 45: tmp_K = 32'hd6990624; 46: tmp_K = 32'hf40e3585; 47: tmp_K = 32'h106aa070; 48: tmp_K = 32'h19a4c116; 49: tmp_K = 32'h1e376c08; 50: tmp_K = 32'h2748774c; 51: tmp_K = 32'h34b0bcb5; 52: tmp_K = 32'h391c0cb3; 53: tmp_K = 32'h4ed8aa4a; 54: tmp_K = 32'h5b9cca4f; 55: tmp_K = 32'h682e6ff3; 56: tmp_K = 32'h748f82ee; 57: tmp_K = 32'h78a5636f; 58: tmp_K = 32'h84c87814; 59: tmp_K = 32'h8cc70208; 60: tmp_K = 32'h90befffa; 61: tmp_K = 32'ha4506ceb; 62: tmp_K = 32'hbef9a3f7; 63: tmp_K = 32'hc67178f2; endcase // case (addr) end // block: addr_mux endmodule // sha256_k_constants //====================================================================== // sha256_k_constants.v //======================================================================
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : sha256_top.v // Project : Common Evaluation Platform (CEP) // Description : This file provides a wishbone based-SHA256 core // module sha256_top( wb_adr_i, wb_cyc_i, wb_dat_i, wb_sel_i, wb_stb_i, wb_we_i, wb_ack_o, wb_err_o, wb_dat_o, wb_clk_i, wb_rst_i, int_o ); parameter dw = 32; parameter aw = 32; input [aw-1:0] wb_adr_i; input wb_cyc_i; input [dw-1:0] wb_dat_i; input [3:0] wb_sel_i; input wb_stb_i; input wb_we_i; output wb_ack_o; output wb_err_o; output reg [dw-1:0] wb_dat_o; output int_o; input wb_clk_i; input wb_rst_i; assign wb_ack_o = 1'b1; assign wb_err_o = 1'b0; assign int_o = 1'b0; // Internal registers reg startHash, startHash_r; reg newMessage, newMessage_r; reg [31:0] data [0:15]; wire [511:0] bigData = {data[15], data[14], data[13], data[12], data[11], data[10], data[9], data[8], data[7], data[6], data[5], data[4], data[3], data[2], data[1], data[0]}; wire [255:0] hash; wire ready; wire hashValid; // Implement SHA256 I/O memory map interface // Write side always @(posedge wb_clk_i) begin if(wb_rst_i) begin startHash <= 0; startHash_r <= 0; newMessage <= 0; newMessage_r <= 0; data[0] <= 0; data[1] <= 0; data[2] <= 0; data[3] <= 0; data[4] <= 0; data[5] <= 0; data[6] <= 0; data[7] <= 0; data[8] <= 0; data[9] <= 0; data[10] <= 0; data[11] <= 0; data[12] <= 0; data[13] <= 0; data[14] <= 0; data[15] <= 0; end else begin // Generate a registered versions of startHash and newMessage startHash_r <= startHash; newMessage_r <= newMessage; // Perform a write if(wb_stb_i & wb_we_i) begin case(wb_adr_i[6:2]) 0: begin startHash <= wb_dat_i[0]; newMessage <= wb_dat_i[1]; end 1: data[0] <= wb_dat_i; 2: data[1] <= wb_dat_i; 3: data[2] <= wb_dat_i; 4: data[3] <= wb_dat_i; 5: data[4] <= wb_dat_i; 6: data[5] <= wb_dat_i; 7: data[6] <= wb_dat_i; 8: data[7] <= wb_dat_i; 9: data[8] <= wb_dat_i; 10: data[9] <= wb_dat_i; 11: data[10] <= wb_dat_i; 12: data[11] <= wb_dat_i; 13: data[12] <= wb_dat_i; 14: data[13] <= wb_dat_i; 15: data[14] <= wb_dat_i; 16: data[15] <= wb_dat_i; default: ; endcase end else begin startHash <= 1'b0; newMessage <= 1'b0; end // end else end end // end always // Implement SHA256 I/O memory map interface // Read side always @(*) begin case(wb_adr_i[6:2]) 0: wb_dat_o = {31'b0, ready}; 1: wb_dat_o = data[0]; 2: wb_dat_o = data[1]; 3: wb_dat_o = data[2]; 4: wb_dat_o = data[3]; 5: wb_dat_o = data[4]; 6: wb_dat_o = data[5]; 7: wb_dat_o = data[6]; 8: wb_dat_o = data[7]; 9: wb_dat_o = data[8]; 10: wb_dat_o = data[9]; 11: wb_dat_o = data[10]; 12: wb_dat_o = data[11]; 13: wb_dat_o = data[12]; 14: wb_dat_o = data[13]; 15: wb_dat_o = data[14]; 16: wb_dat_o = data[15]; 17: wb_dat_o = {31'b0, hashValid}; 18: wb_dat_o = hash[31:0]; 19: wb_dat_o = hash[63:32]; 20: wb_dat_o = hash[95:64]; 21: wb_dat_o = hash[127:96]; 22: wb_dat_o = hash[159:128]; 23: wb_dat_o = hash[191:160]; 24: wb_dat_o = hash[223:192]; 25: wb_dat_o = hash[255:224]; default: wb_dat_o = 32'b0; endcase end sha256 sha256( .clk(wb_clk_i), .rst(wb_rst_i), .init(startHash && ~startHash_r), .next(newMessage && ~newMessage_r), .block(bigData), .digest(hash), .digest_valid(hashValid), .ready(ready) ); endmodule
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : sha256_top_axi4lite.v // Project : Common Evaluation Platform (CEP) // Description : This file provides an axi4-lite wrapper for the wishbone based-SHA256 core // module sha256_top_axi4lite ( // Clock & Reset input logic clk_i, input logic rst_ni, // AXI4-Lite Slave Interface AXI_LITE.Slave slave ); // AES wishbone slave wires wire wb_clk; wire wb_rst; wire wb_rst_n; wire [slave.AXI_ADDR_WIDTH - 1:0] wbs_d_sha_adr_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_sha_dat_i; wire [3:0] wbs_d_sha_sel_i; wire wbs_d_sha_we_i; wire wbs_d_sha_cyc_i; wire wbs_d_sha_stb_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_sha_dat_o; wire wbs_d_sha_ack_o; // Instantiate the AXI4Lite to Wishbone bridge bonfire_axi4l2wb #( .ADRWIDTH (slave.AXI_ADDR_WIDTH), .FAST_READ_TERM (1'd0) ) bonfire_axi4l2wb_inst ( .S_AXI_ACLK (clk_i), .S_AXI_ARESETN (rst_ni), .S_AXI_AWADDR (slave.aw_addr), .S_AXI_AWVALID (slave.aw_valid), .S_AXI_AWREADY (slave.aw_ready), .S_AXI_WDATA (slave.w_data), .S_AXI_WSTRB (slave.w_strb), .S_AXI_WVALID (slave.w_valid), .S_AXI_WREADY (slave.w_ready), .S_AXI_ARADDR (slave.ar_addr), .S_AXI_ARVALID (slave.ar_valid), .S_AXI_ARREADY (slave.ar_ready), .S_AXI_RDATA (slave.r_data), .S_AXI_RRESP (slave.r_resp), .S_AXI_RVALID (slave.r_valid), .S_AXI_RREADY (slave.r_ready), .S_AXI_BRESP (slave.b_resp), .S_AXI_BVALID (slave.b_valid), .S_AXI_BREADY (slave.b_ready), .wb_clk_o (wb_clk), .wb_rst_o (wb_rst), .wb_addr_o (wbs_d_sha_adr_i), .wb_dat_o (wbs_d_sha_dat_i), .wb_we_o (wbs_d_sha_we_i), .wb_sel_o (wbs_d_sha_sel_i), .wb_stb_o (wbs_d_sha_stb_i), .wb_cyc_o (wbs_d_sha_cyc_i), .wb_dat_i (wbs_d_sha_dat_o), .wb_ack_i (wbs_d_sha_ack_o) ); // Instantiate the wishbone-based MD5 Core sha256_top sha256_top_inst ( // Wishbone Slave interface .wb_clk_i (wb_clk), .wb_rst_i (wb_rst), .wb_dat_i (wbs_d_sha_dat_i), .wb_adr_i (wbs_d_sha_adr_i), .wb_sel_i (wbs_d_sha_sel_i[3:0]), .wb_we_i (wbs_d_sha_we_i), .wb_cyc_i (wbs_d_sha_cyc_i), .wb_stb_i (wbs_d_sha_stb_i), .wb_dat_o (wbs_d_sha_dat_o), .wb_err_o (), .wb_ack_o (wbs_d_sha_ack_o), // Processor interrupt .int_o () ); endmodule // end md5_top_axi4lite
//====================================================================== // // sha256_w_mem_regs.v // ------------------- // The W memory. This version uses 16 32-bit registers as a sliding // window to generate the 64 words. // // // Author: Joachim Strombergson // Copyright (c) 2013, Secworks Sweden AB // All rights reserved. // // Redistribution and use in source and binary forms, with or // without modification, are permitted provided that the following // conditions are met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in // the documentation and/or other materials provided with the // distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== module sha256_w_mem( input wire clk, input wire rst, input wire [511 : 0] block, input wire init, input wire next, output wire [31 : 0] w ); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- parameter CTRL_IDLE = 0; parameter CTRL_UPDATE = 1; //---------------------------------------------------------------- // Registers including update variables and write enable. //---------------------------------------------------------------- reg [31 : 0] w_mem [0 : 15]; reg [31 : 0] w_mem00_new; reg [31 : 0] w_mem01_new; reg [31 : 0] w_mem02_new; reg [31 : 0] w_mem03_new; reg [31 : 0] w_mem04_new; reg [31 : 0] w_mem05_new; reg [31 : 0] w_mem06_new; reg [31 : 0] w_mem07_new; reg [31 : 0] w_mem08_new; reg [31 : 0] w_mem09_new; reg [31 : 0] w_mem10_new; reg [31 : 0] w_mem11_new; reg [31 : 0] w_mem12_new; reg [31 : 0] w_mem13_new; reg [31 : 0] w_mem14_new; reg [31 : 0] w_mem15_new; reg w_mem_we; reg [5 : 0] w_ctr_reg; reg [5 : 0] w_ctr_new; reg w_ctr_we; reg w_ctr_inc; reg w_ctr_rst; reg [1 : 0] sha256_w_mem_ctrl_reg; reg [1 : 0] sha256_w_mem_ctrl_new; reg sha256_w_mem_ctrl_we; //---------------------------------------------------------------- // Wires. //---------------------------------------------------------------- reg [31 : 0] w_tmp; reg [31 : 0] w_new; //---------------------------------------------------------------- // Concurrent connectivity for ports etc. //---------------------------------------------------------------- assign w = w_tmp; //---------------------------------------------------------------- // reg_update // Update functionality for all registers in the core. // All registers are positive edge triggered with synchronous // reset. All registers have write enable. //---------------------------------------------------------------- always @ (posedge clk) begin : reg_update if (rst) begin w_mem[00] <= 32'h0; w_mem[01] <= 32'h0; w_mem[02] <= 32'h0; w_mem[03] <= 32'h0; w_mem[04] <= 32'h0; w_mem[05] <= 32'h0; w_mem[06] <= 32'h0; w_mem[07] <= 32'h0; w_mem[08] <= 32'h0; w_mem[09] <= 32'h0; w_mem[10] <= 32'h0; w_mem[11] <= 32'h0; w_mem[12] <= 32'h0; w_mem[13] <= 32'h0; w_mem[14] <= 32'h0; w_mem[15] <= 32'h0; w_ctr_reg <= 6'h00; sha256_w_mem_ctrl_reg <= CTRL_IDLE; end else begin if (w_mem_we) begin w_mem[00] <= w_mem00_new; w_mem[01] <= w_mem01_new; w_mem[02] <= w_mem02_new; w_mem[03] <= w_mem03_new; w_mem[04] <= w_mem04_new; w_mem[05] <= w_mem05_new; w_mem[06] <= w_mem06_new; w_mem[07] <= w_mem07_new; w_mem[08] <= w_mem08_new; w_mem[09] <= w_mem09_new; w_mem[10] <= w_mem10_new; w_mem[11] <= w_mem11_new; w_mem[12] <= w_mem12_new; w_mem[13] <= w_mem13_new; w_mem[14] <= w_mem14_new; w_mem[15] <= w_mem15_new; end if (w_ctr_we) w_ctr_reg <= w_ctr_new; if (sha256_w_mem_ctrl_we) sha256_w_mem_ctrl_reg <= sha256_w_mem_ctrl_new; end end // reg_update //---------------------------------------------------------------- // select_w // // Mux for the external read operation. This is where we exract // the W variable. //---------------------------------------------------------------- always @* begin : select_w if (w_ctr_reg < 16) begin w_tmp = w_mem[w_ctr_reg[3 : 0]]; end else begin w_tmp = w_new; end end // select_w //---------------------------------------------------------------- // w_new_logic // // Logic that calculates the next value to be inserted into // the sliding window of the memory. //---------------------------------------------------------------- always @* begin : w_mem_update_logic reg [31 : 0] w_0; reg [31 : 0] w_1; reg [31 : 0] w_9; reg [31 : 0] w_14; reg [31 : 0] d0; reg [31 : 0] d1; w_mem00_new = 32'h0; w_mem01_new = 32'h0; w_mem02_new = 32'h0; w_mem03_new = 32'h0; w_mem04_new = 32'h0; w_mem05_new = 32'h0; w_mem06_new = 32'h0; w_mem07_new = 32'h0; w_mem08_new = 32'h0; w_mem09_new = 32'h0; w_mem10_new = 32'h0; w_mem11_new = 32'h0; w_mem12_new = 32'h0; w_mem13_new = 32'h0; w_mem14_new = 32'h0; w_mem15_new = 32'h0; w_mem_we = 0; w_0 = w_mem[0]; w_1 = w_mem[1]; w_9 = w_mem[9]; w_14 = w_mem[14]; d0 = {w_1[6 : 0], w_1[31 : 7]} ^ {w_1[17 : 0], w_1[31 : 18]} ^ {3'b000, w_1[31 : 3]}; d1 = {w_14[16 : 0], w_14[31 : 17]} ^ {w_14[18 : 0], w_14[31 : 19]} ^ {10'b0000000000, w_14[31 : 10]}; w_new = d1 + w_9 + d0 + w_0; if (init) begin w_mem00_new = block[511 : 480]; w_mem01_new = block[479 : 448]; w_mem02_new = block[447 : 416]; w_mem03_new = block[415 : 384]; w_mem04_new = block[383 : 352]; w_mem05_new = block[351 : 320]; w_mem06_new = block[319 : 288]; w_mem07_new = block[287 : 256]; w_mem08_new = block[255 : 224]; w_mem09_new = block[223 : 192]; w_mem10_new = block[191 : 160]; w_mem11_new = block[159 : 128]; w_mem12_new = block[127 : 96]; w_mem13_new = block[95 : 64]; w_mem14_new = block[63 : 32]; w_mem15_new = block[31 : 0]; w_mem_we = 1; end else if (w_ctr_reg > 15) begin w_mem00_new = w_mem[01]; w_mem01_new = w_mem[02]; w_mem02_new = w_mem[03]; w_mem03_new = w_mem[04]; w_mem04_new = w_mem[05]; w_mem05_new = w_mem[06]; w_mem06_new = w_mem[07]; w_mem07_new = w_mem[08]; w_mem08_new = w_mem[09]; w_mem09_new = w_mem[10]; w_mem10_new = w_mem[11]; w_mem11_new = w_mem[12]; w_mem12_new = w_mem[13]; w_mem13_new = w_mem[14]; w_mem14_new = w_mem[15]; w_mem15_new = w_new; w_mem_we = 1; end end // w_mem_update_logic //---------------------------------------------------------------- // w_ctr // W schedule adress counter. Counts from 0x10 to 0x3f and // is used to expand the block into words. //---------------------------------------------------------------- always @* begin : w_ctr w_ctr_new = 0; w_ctr_we = 0; if (w_ctr_rst) begin w_ctr_new = 6'h00; w_ctr_we = 1; end if (w_ctr_inc) begin w_ctr_new = w_ctr_reg + 6'h01; w_ctr_we = 1; end end // w_ctr //---------------------------------------------------------------- // sha256_w_mem_fsm // Logic for the w shedule FSM. //---------------------------------------------------------------- always @* begin : sha256_w_mem_fsm w_ctr_rst = 0; w_ctr_inc = 0; sha256_w_mem_ctrl_new = CTRL_IDLE; sha256_w_mem_ctrl_we = 0; case (sha256_w_mem_ctrl_reg) CTRL_IDLE: begin if (init) begin w_ctr_rst = 1; sha256_w_mem_ctrl_new = CTRL_UPDATE; sha256_w_mem_ctrl_we = 1; end end CTRL_UPDATE: begin if (next) begin w_ctr_inc = 1; end if (w_ctr_reg == 6'h3f) begin sha256_w_mem_ctrl_new = CTRL_IDLE; sha256_w_mem_ctrl_we = 1; end end endcase // case (sha256_ctrl_reg) end // sha256_ctrl_fsm endmodule // sha256_w_mem //====================================================================== // sha256_w_mem.v //======================================================================
`include "orpsoc-defines.sv" `timescale 1 ns / 1 ps import axi_pkg::*; module axi_top ( sys_clk_in_p, sys_clk_in_n, `ifdef RESET_HIGH rst_pad_i, `else rst_n_pad_i, `endif uart_srx_pad_i, uart_cts_pad_i, uart_stx_pad_o, uart_rts_pad_o ); input sys_clk_in_p; input sys_clk_in_n; `ifdef RESET_HIGH input rst_pad_i; `else input rst_n_pad_i; `endif input uart_srx_pad_i; input uart_cts_pad_i; output uart_stx_pad_o; output uart_rts_pad_o; wire core_clk; wire core_rst; // AXI4 - Lite declerations // Master defininitions // Master 0 // Master 1 AXI_LITE # ( .AXI_ADDR_WIDTH(`CEP_AXI_ADDR_WIDTH), .AXI_DATA_WIDTH(`CEP_AXI_DATA_WIDTH) ) master[1:0](); // Slave Bus Declaration(see orpsoc - defines.sv for additional info including slave assignment) AXI_LITE # ( .AXI_ADDR_WIDTH (`CEP_AXI_ADDR_WIDTH), .AXI_DATA_WIDTH (`CEP_AXI_DATA_WIDTH) ) slave[11:0](); // Declaration the routing rules for the AXI4 - Lite Crossbar AXI_ROUTING_RULES # ( .AXI_ADDR_WIDTH (`CEP_AXI_ADDR_WIDTH), .NUM_SLAVE (`CEP_NUM_OF_SLAVES), .NUM_RULES (1) ) routing(); //Assign the routing rules (cep_routing_rules is declared and explained in orpsoc-defines.v) for (genvar i = 0; i < `CEP_NUM_OF_SLAVES; i++) begin assign routing.rules[i][0].enabled = cep_routing_rules[i][0][0]; assign routing.rules[i][0].mask = cep_routing_rules[i][1]; assign routing.rules[i][0].base = cep_routing_rules[i][2]; end // for (genvar i = 0; i < CEP_NUM_OF_SLAVES; i++) axi_lite_xbar #( .ADDR_WIDTH (`CEP_AXI_ADDR_WIDTH ), .DATA_WIDTH (`CEP_AXI_DATA_WIDTH ), .NUM_MASTER (`CEP_NUM_OF_MASTERS ), .NUM_SLAVE (`CEP_NUM_OF_SLAVES ), .NUM_RULES (1) ) axi_lite_xbar_inst ( .clk_i ( core_clk ), .rst_ni ( ~core_rst ), .master ( master ), .slave ( slave ), .rules ( routing ) ); // Instantiating Clock and Reset Generator IP clkgen clkgen_inst ( `ifdef RESET_HIGH .rst_n_pad_i(~rst_pad_i), `else .rst_n_pad_i(rst_n_pad_i), `endif .sys_clk_in_p (sys_clk_in_p), .sys_clk_in_n (sys_clk_in_n), .core_clk_o (core_clk), .core_rst_o (core_rst) ); // Instantiating RAM IP ram_top_axi4lite # ( .MEMORY_SIZE(`CEP_RAM_SIZE) ) ram_top_axi4lite_inst ( .clk_i (core_clk), .rst_ni (~core_rst), .slave (slave[`RAM_SLAVE_NUMBER]) ); // Instantiating UART IP wire uart_irq; uart_top_axi4lite uart_top_axi4lite_inst ( // UART Signals .clk_i (core_clk), .rst_ni (~core_rst), .slave (slave[`UART_SLAVE_NUMBER]), .srx_pad_i (uart_srx_pad_i ), .stx_pad_o (uart_stx_pad_o ), .rts_pad_o (uart_rts_pad_o ), .cts_pad_i (uart_cts_pad_i ), .dtr_pad_o ( ), .dsr_pad_i (1'b0 ), .ri_pad_i (1'b0 ), .dcd_pad_i (1'b0 ), // Processor Interrupt .int_o (uart_irq ) ); // Instantiating PICORV IP picorv32_top_axi4lite picorv32_top_axi4lite_inst ( .clk_i (core_clk), .rst_i (core_rst), .master_d (master [0]) ); // Instantiating AES IP generate if(cep_routing_rules[`AES_SLAVE_NUMBER][0] == `CEP_SLAVE_ENABLED) aes_top_axi4lite aes_top_axi4lite_inst ( .clk_i (core_clk), .rst_ni (~core_rst), .slave (slave[`AES_SLAVE_NUMBER]) ); endgenerate // Instantiating DES3 IP generate if(cep_routing_rules[`DES3_SLAVE_NUMBER][0] == `CEP_SLAVE_ENABLED) des3_top_axi4lite des3_top_axi4lite_inst ( .clk_i (core_clk), .rst_ni (~core_rst), .slave (slave[`DES3_SLAVE_NUMBER]) ); endgenerate // Instantiating SHA256 IP generate if(cep_routing_rules[`SHA256_SLAVE_NUMBER][0] == `CEP_SLAVE_ENABLED) sha256_top_axi4lite sha256_top_axi4lite_inst ( .clk_i (core_clk), .rst_ni (~core_rst), .slave (slave[`SHA256_SLAVE_NUMBER]) ); endgenerate // Instantiating IIR IP generate if(cep_routing_rules[`IIR_SLAVE_NUMBER][0] == `CEP_SLAVE_ENABLED) iir_top_axi4lite iir_top_axi4lite_inst ( .clk_i (core_clk), .rst_ni (~core_rst), .slave (slave[`IIR_SLAVE_NUMBER]) ); endgenerate // Instantiating FIR IP generate if(cep_routing_rules[`FIR_SLAVE_NUMBER][0] == `CEP_SLAVE_ENABLED) fir_top_axi4lite fir_top_axi4lite_inst ( .clk_i (core_clk), .rst_ni (~core_rst), .slave (slave[`FIR_SLAVE_NUMBER]) ); endgenerate // Instantiating DFT IP generate if(cep_routing_rules[`DFT_SLAVE_NUMBER][0] == `CEP_SLAVE_ENABLED) dft_top_axi4lite dft_top_axi4lite_inst ( .clk_i (core_clk), .rst_ni (~core_rst), .slave (slave[`DFT_SLAVE_NUMBER]) ); endgenerate // Instantiating IDFT IP generate if(cep_routing_rules[`IDFT_SLAVE_NUMBER][0] == `CEP_SLAVE_ENABLED) idft_top_axi4lite idft_top_axi4lite_inst ( .clk_i (core_clk), .rst_ni (~core_rst), .slave (slave[`IDFT_SLAVE_NUMBER]) ); endgenerate // Instantiating MD5 IP generate if(cep_routing_rules[`MD5_SLAVE_NUMBER][0] == `CEP_SLAVE_ENABLED) md5_top_axi4lite md5_top_axi4lite_inst ( .clk_i (core_clk), .rst_ni (~core_rst), .slave (slave[`MD5_SLAVE_NUMBER]) ); endgenerate endmodule
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : orpsoc_defines.v // Project : Common Evaluation Platform (CEP) // Description : Defines file for the CEP // Notes : Core licensing information may be found in licenseLog.txt // `ifdef SYNTHESIS `define RESET_HIGH `endif // Define the Address and Data widths `define CEP_AXI_ADDR_WIDTH 32 `define CEP_AXI_DATA_WIDTH 32 // Define the numnber of AXI4-Lite slaves (cores) in the CEP `define CEP_NUM_OF_SLAVES 12 // Maximum number, not to be changed // when cores are enabled/disabled `define CEP_NUM_OF_MASTERS 2 // Instruction and Data Bus // Set the default address mask for the AXI4-Lite Arbiter `define CEP_ADDRESS_MASK 32'hFF00_0000 // Constants used to increase readbility (will be trimmed to one bit for assignment // to the routing rules `define CEP_SLAVE_ENABLED 32'h0000_0001 `define CEP_SLAVE_DISABLED 32'h0000_0000 // The following parameter will be used to define the rptuing rules // for the AXI4-Lite crossbar within the CEP. A total of three fields // are present: // Field 0 (enabled) - If set, then the relevant core's slave interface is enabled. // Additionally, this parameter will be used to control the instantiation of // the core in the CEP. If not set, the slave port will be disabled and the // signals will be "stubbed out" // Field 1 (mask) - Control the address masking. For the CEP, all the slaves // will use the same mask // Field 2 (address) - Sets the base address of corresponding slave (core) // // Slave assignments are including as inline comments. // // Note: The RAM and UART slaves MUST be enabled for a CEP to be functional parameter [31:0] cep_routing_rules [`CEP_NUM_OF_SLAVES - 1:0][0:2] = '{ {`CEP_SLAVE_ENABLED, `CEP_ADDRESS_MASK, 32'h0000_0000}, // Slave 0 - RAM (Mandatory) {`CEP_SLAVE_ENABLED, `CEP_ADDRESS_MASK, 32'h9000_0000}, // Slave 1 - UART (Mandatory) {`CEP_SLAVE_ENABLED, `CEP_ADDRESS_MASK, 32'h9300_0000}, // Slave 2 - AES {`CEP_SLAVE_ENABLED, `CEP_ADDRESS_MASK, 32'h9400_0000}, // Slave 3 - MD5 {`CEP_SLAVE_ENABLED, `CEP_ADDRESS_MASK, 32'h9500_0000}, // Slave 4 - SHA256 {`CEP_SLAVE_ENABLED, `CEP_ADDRESS_MASK, 32'h9600_0000}, // Slave 5 - RSA {`CEP_SLAVE_ENABLED, `CEP_ADDRESS_MASK, 32'h9700_0000}, // Slave 6 - DES3 {`CEP_SLAVE_ENABLED, `CEP_ADDRESS_MASK, 32'h9800_0000}, // Slave 7 - DFT {`CEP_SLAVE_ENABLED, `CEP_ADDRESS_MASK, 32'h9900_0000}, // Slave 8 - IDFT {`CEP_SLAVE_ENABLED, `CEP_ADDRESS_MASK, 32'h9A00_0000}, // Slave 9 - FIR {`CEP_SLAVE_ENABLED, `CEP_ADDRESS_MASK, 32'h9B00_0000}, // Slave 10 - IIR {`CEP_SLAVE_ENABLED, `CEP_ADDRESS_MASK, 32'h9C00_0000} // Slave 11 - GPS }; // A few defines to increase readability. These must match the order of slaves // as defined in the above cep_routing_rules! `define RAM_SLAVE_NUMBER 0 `define UART_SLAVE_NUMBER 1 `define AES_SLAVE_NUMBER 2 `define MD5_SLAVE_NUMBER 3 `define SHA256_SLAVE_NUMBER 4 `define RSA_SLAVE_NUMBER 5 `define DES3_SLAVE_NUMBER 6 `define DFT_SLAVE_NUMBER 7 `define IDFT_SLAVE_NUMBER 8 `define FIR_SLAVE_NUMBER 9 `define IIR_SLAVE_NUMBER 10 `define GPS_SLAVE_NUMBER 11 `define CEP_RAM_SIZE 32'h0004_0000 // 256K Bytes (64K 4-byte words)
// // Copyright (C) 2018 Massachusetts Institute of Technology // // Project : Common Evaluation Platform (CEP) // Description : This file provides an axi4-lite wrapper for the wishbone based-MOR1KX processor // `timescale 1 ns / 1 ps // `default_nettype none // `define DEBUGNETS // `define DEBUGREGS // `define DEBUGASM // `define DEBUG `ifdef DEBUG `define debug(debug_command) debug_command `else `define debug(debug_command) `endif `ifdef FORMAL `define FORMAL_KEEP (* keep *) `define assert(assert_expr) assert(assert_expr) `else `ifdef DEBUGNETS `define FORMAL_KEEP (* keep *) `else `define FORMAL_KEEP `endif `define assert(assert_expr) empty_statement `endif // uncomment this for register file in extra module // `define PICORV32_REGS picorv32_regs // this macro can be used to check if the verilog files in your // design are read in the correct order. `define PICORV32_V module picorv32_top_axi4lite ( // Clock and Resets input clk_i, input rst_i, AXI_LITE.Master master_d ); picoaxi #( .ENABLE_COUNTERS (), .ENABLE_COUNTERS64 (), .ENABLE_REGS_16_31 (), .ENABLE_REGS_DUALPORT (), .TWO_STAGE_SHIFT(), .BARREL_SHIFTER (), .TWO_CYCLE_COMPARE (), .TWO_CYCLE_ALU (), .COMPRESSED_ISA (), .CATCH_MISALIGN (), .CATCH_ILLINSN (), .ENABLE_PCPI (), .ENABLE_MUL (), .ENABLE_FAST_MUL (), .ENABLE_DIV (), .ENABLE_IRQ (), .ENABLE_IRQ_QREGS (), .ENABLE_IRQ_TIMER (), .ENABLE_TRACE (), .REGS_INIT_ZERO (), .MASKED_IRQ (), .LATCHED_IRQ (), .PROGADDR_RESET (), .PROGADDR_IRQ (), .STACKADDR () ) picoaxi_inst ( .clk_i (clk_i), .rst_i (rst_i), // AXI4-lite master memory interface .mem_axi_awvalid (master_d.aw_valid), .mem_axi_awready (master_d.aw_ready), .mem_axi_awaddr (master_d.aw_addr), .mem_axi_awprot(), .mem_axi_wvalid (master_d.w_valid), .mem_axi_wready (master_d.w_ready), .mem_axi_wdata (master_d.w_data), .mem_axi_bvalid (master_d.b_valid), .mem_axi_bready (master_d.b_ready), .mem_axi_arvalid (master_d.ar_valid), .mem_axi_arready (master_d.ar_ready), .mem_axi_araddr (master_d.ar_addr), .mem_axi_arprot (), .mem_axi_rvalid (master_d.r_valid), .mem_axi_rready (master_d.r_ready), .mem_axi_rdata (master_d.r_data) ); endmodule // picorv32_axi4lite
////////////////////////////////////////////////////////////////////// //// //// //// timescale.v //// //// //// //// //// //// This file is part of the "UART 16550 compatible" project //// //// http://www.opencores.org/cores/uart16550/ //// //// //// //// Documentation related to this project: //// //// - http://www.opencores.org/cores/uart16550/ //// //// //// //// Projects compatibility: //// //// - WISHBONE //// //// RS232 Protocol //// //// 16550D uart (mostly supported) //// //// //// //// Overview (main Features): //// //// Defines of the Core //// //// //// //// Known problems (limits): //// //// None //// //// //// //// To Do: //// //// Nothing. //// //// //// //// Author(s): //// //// - gorban@opencores.org //// //// - Jacob Gorban //// //// - Igor Mohor (igorm@opencores.org) //// //// //// //// Created: 2001/05/12 //// //// Last Updated: 2001/05/17 //// //// (See log for the revision history) //// //// //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2000, 2001 Authors //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// // Timescale define `timescale 1ns/10ps
////////////////////////////////////////////////////////////////////// //// //// //// raminfr.v //// //// //// //// //// //// This file is part of the "UART 16550 compatible" project //// //// http://www.opencores.org/cores/uart16550/ //// //// //// //// Documentation related to this project: //// //// - http://www.opencores.org/cores/uart16550/ //// //// //// //// Projects compatibility: //// //// - WISHBONE //// //// RS232 Protocol //// //// 16550D uart (mostly supported) //// //// //// //// Overview (main Features): //// //// Inferrable Distributed RAM for FIFOs //// //// //// //// Known problems (limits): //// //// None . //// //// //// //// To Do: //// //// Nothing so far. //// //// //// //// Author(s): //// //// - gorban@opencores.org //// //// - Jacob Gorban //// //// //// //// Created: 2002/07/22 //// //// Last Updated: 2002/07/22 //// //// (See log for the revision history) //// //// //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2000, 2001 Authors //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// // // CVS Revision History // // $Log: not supported by cvs2svn $ // Revision 1.1 2002/07/22 23:02:23 gorban // Bug Fixes: // * Possible loss of sync and bad reception of stop bit on slow baud rates fixed. // Problem reported by Kenny.Tung. // * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers. // // Improvements: // * Made FIFO's as general inferrable memory where possible. // So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx). // This saves about 1/3 of the Slice count and reduces P&R and synthesis times. // // * Added optional baudrate output (baud_o). // This is identical to BAUDOUT* signal on 16550 chip. // It outputs 16xbit_clock_rate - the divided clock. // It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use. // //Following is the Verilog code for a dual-port RAM with asynchronous read. module raminfr (clk, we, a, dpra, di, dpo); parameter addr_width = 4; parameter data_width = 8; parameter depth = 16; input clk; input we; input [addr_width-1:0] a; input [addr_width-1:0] dpra; input [data_width-1:0] di; //output [data_width-1:0] spo; output [data_width-1:0] dpo; reg [data_width-1:0] ram [depth-1:0]; wire [data_width-1:0] dpo; wire [data_width-1:0] di; wire [addr_width-1:0] a; wire [addr_width-1:0] dpra; always @(posedge clk) begin if (we) ram[a] <= di; end // assign spo = ram[a]; assign dpo = ram[dpra]; endmodule
////////////////////////////////////////////////////////////////////// //// //// //// uart_defines.v //// //// //// //// //// //// This file is part of the "UART 16550 compatible" project //// //// http://www.opencores.org/cores/uart16550/ //// //// //// //// Documentation related to this project: //// //// - http://www.opencores.org/cores/uart16550/ //// //// //// //// Projects compatibility: //// //// - WISHBONE //// //// RS232 Protocol //// //// 16550D uart (mostly supported) //// //// //// //// Overview (main Features): //// //// Defines of the Core //// //// //// //// Known problems (limits): //// //// None //// //// //// //// To Do: //// //// Nothing. //// //// //// //// Author(s): //// //// - gorban@opencores.org //// //// - Jacob Gorban //// //// - Igor Mohor (igorm@opencores.org) //// //// //// //// Created: 2001/05/12 //// //// Last Updated: 2001/05/17 //// //// (See log for the revision history) = //// //// //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2000, 2001 Authors //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// // // CVS Revision History // // $Log: not supported by cvs2svn $ // Revision 1.13 2003/06/11 16:37:47 gorban // This fixes errors in some cases when data is being read and put to the FIFO at the same time. Patch is submitted by Scott Furman. Update is very recommended. // // Revision 1.12 2002/07/22 23:02:23 gorban // Bug Fixes: // * Possible loss of sync and bad reception of stop bit on slow baud rates fixed. // Problem reported by Kenny.Tung. // * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers. // // Improvements: // * Made FIFO's as general inferrable memory where possible. // So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx). // This saves about 1/3 of the Slice count and reduces P&R and synthesis times. // // * Added optional baudrate output (baud_o). // This is identical to BAUDOUT* signal on 16550 chip. // It outputs 16xbit_clock_rate - the divided clock. // It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use. // // Revision 1.10 2001/12/11 08:55:40 mohor // Scratch register define added. // // Revision 1.9 2001/12/03 21:44:29 gorban // Updated specification documentation. // Added full 32-bit data bus interface, now as default. // Address is 5-bit wide in 32-bit data bus mode. // Added wb_sel_i input to the core. It's used in the 32-bit mode. // Added debug interface with two 32-bit read-only registers in 32-bit mode. // Bits 5 and 6 of LSR are now only cleared on TX FIFO write. // My small test bench is modified to work with 32-bit mode. // // Revision 1.8 2001/11/26 21:38:54 gorban // Lots of fixes: // Break condition wasn't handled correctly at all. // LSR bits could lose their values. // LSR value after reset was wrong. // Timing of THRE interrupt signal corrected. // LSR bit 0 timing corrected. // // Revision 1.7 2001/08/24 21:01:12 mohor // Things connected to parity changed. // Clock devider changed. // // Revision 1.6 2001/08/23 16:05:05 mohor // Stop bit bug fixed. // Parity bug fixed. // WISHBONE read cycle bug fixed, // OE indicator (Overrun Error) bug fixed. // PE indicator (Parity Error) bug fixed. // Register read bug fixed. // // Revision 1.5 2001/05/31 20:08:01 gorban // FIFO changes and other corrections. // // Revision 1.4 2001/05/21 19:12:02 gorban // Corrected some Linter messages. // // Revision 1.3 2001/05/17 18:34:18 gorban // First 'stable' release. Should be sythesizable now. Also added new header. // // Revision 1.0 2001-05-17 21:27:11+02 jacob // Initial revision // // // Uncomment this if you want your UART to have // 16xBaudrate output port. // If defined, the enable signal will be used to drive baudrate_o signal // It's frequency is 16xbaudrate // `define UART_HAS_BAUDRATE_OUTPUT // Register addresses `define UART_REG_RB 3'd0 // receiver buffer `define UART_REG_TR 3'd0 // transmitter `define UART_REG_IE 3'd1 // Interrupt enable `define UART_REG_II 3'd2 // Interrupt identification `define UART_REG_FC 3'd2 // FIFO control `define UART_REG_LC 3'd3 // Line Control `define UART_REG_MC 3'd4 // Modem control `define UART_REG_LS 3'd5 // Line status `define UART_REG_MS 3'd6 // Modem status `define UART_REG_SR 3'd7 // Scratch register `define UART_REG_DL1 3'd0 // Divisor latch bytes (1-2) `define UART_REG_DL2 3'd1 // Interrupt Enable register bits `define UART_IE_RDA 0 // Received Data available interrupt `define UART_IE_THRE 1 // Transmitter Holding Register empty interrupt `define UART_IE_RLS 2 // Receiver Line Status Interrupt `define UART_IE_MS 3 // Modem Status Interrupt // Interrupt Identification register bits `define UART_II_IP 0 // Interrupt pending when 0 `define UART_II_II 3:1 // Interrupt identification // Interrupt identification values for bits 3:1 `define UART_II_RLS 3'b011 // Receiver Line Status `define UART_II_RDA 3'b010 // Receiver Data available `define UART_II_TI 3'b110 // Timeout Indication `define UART_II_THRE 3'b001 // Transmitter Holding Register empty `define UART_II_MS 3'b000 // Modem Status // FIFO Control Register bits `define UART_FC_TL 1:0 // Trigger level // FIFO trigger level values `define UART_FC_1 2'b00 `define UART_FC_4 2'b01 `define UART_FC_8 2'b10 `define UART_FC_14 2'b11 // Line Control register bits `define UART_LC_BITS 1:0 // bits in character `define UART_LC_SB 2 // stop bits `define UART_LC_PE 3 // parity enable `define UART_LC_EP 4 // even parity `define UART_LC_SP 5 // stick parity `define UART_LC_BC 6 // Break control `define UART_LC_DL 7 // Divisor Latch access bit // Modem Control register bits `define UART_MC_DTR 0 `define UART_MC_RTS 1 `define UART_MC_OUT1 2 `define UART_MC_OUT2 3 `define UART_MC_LB 4 // Loopback mode // Line Status Register bits `define UART_LS_DR 0 // Data ready `define UART_LS_OE 1 // Overrun Error `define UART_LS_PE 2 // Parity Error `define UART_LS_FE 3 // Framing Error `define UART_LS_BI 4 // Break interrupt `define UART_LS_TFE 5 // Transmit FIFO is empty `define UART_LS_TE 6 // Transmitter Empty indicator `define UART_LS_EI 7 // Error indicator // Modem Status Register bits `define UART_MS_DCTS 0 // Delta signals `define UART_MS_DDSR 1 `define UART_MS_TERI 2 `define UART_MS_DDCD 3 `define UART_MS_CCTS 4 // Complement signals `define UART_MS_CDSR 5 `define UART_MS_CRI 6 `define UART_MS_CDCD 7 // FIFO parameter defines `define UART_FIFO_WIDTH 8 `define UART_FIFO_DEPTH 16 `define UART_FIFO_POINTER_W 4 `define UART_FIFO_COUNTER_W 5 // receiver fifo has width 11 because it has break, parity and framing error bits `define UART_FIFO_REC_WIDTH 11 `define VERBOSE_WB 0 // All activity on the WISHBONE is recorded `define VERBOSE_LINE_STATUS 0 // Details about the lsr (line status register) `define FAST_TEST 1 // 64/1024 packets are sent // Define the prescaler (divisor) for the UART as the initialization code that is part // of the or1k toolchain does not seem to be setting it at all `define PRESCALER_PRESET_HARD `define PRESCALER_LOW_PRESET 8'd27 `define PRESCALER_HIGH_PRESET 8'd0
////////////////////////////////////////////////////////////////////// //// //// //// uart_receiver.v //// //// //// //// //// //// This file is part of the "UART 16550 compatible" project //// //// http://www.opencores.org/cores/uart16550/ //// //// //// //// Documentation related to this project: //// //// - http://www.opencores.org/cores/uart16550/ //// //// //// //// Projects compatibility: //// //// - WISHBONE //// //// RS232 Protocol //// //// 16550D uart (mostly supported) //// //// //// //// Overview (main Features): //// //// UART core receiver logic //// //// //// //// Known problems (limits): //// //// None known //// //// //// //// To Do: //// //// Thourough testing. //// //// //// //// Author(s): //// //// - gorban@opencores.org //// //// - Jacob Gorban //// //// - Igor Mohor (igorm@opencores.org) //// //// //// //// Created: 2001/05/12 //// //// Last Updated: 2001/05/17 //// //// (See log for the revision history) //// //// //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2000, 2001 Authors //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// // // CVS Revision History // // $Log: not supported by cvs2svn $ // Revision 1.29 2002/07/29 21:16:18 gorban // The uart_defines.v file is included again in sources. // // Revision 1.28 2002/07/22 23:02:23 gorban // Bug Fixes: // * Possible loss of sync and bad reception of stop bit on slow baud rates fixed. // Problem reported by Kenny.Tung. // * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers. // // Improvements: // * Made FIFO's as general inferrable memory where possible. // So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx). // This saves about 1/3 of the Slice count and reduces P&R and synthesis times. // // * Added optional baudrate output (baud_o). // This is identical to BAUDOUT* signal on 16550 chip. // It outputs 16xbit_clock_rate - the divided clock. // It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use. // // Revision 1.27 2001/12/30 20:39:13 mohor // More than one character was stored in case of break. End of the break // was not detected correctly. // // Revision 1.26 2001/12/20 13:28:27 mohor // Missing declaration of rf_push_q fixed. // // Revision 1.25 2001/12/20 13:25:46 mohor // rx push changed to be only one cycle wide. // // Revision 1.24 2001/12/19 08:03:34 mohor // Warnings cleared. // // Revision 1.23 2001/12/19 07:33:54 mohor // Synplicity was having troubles with the comment. // // Revision 1.22 2001/12/17 14:46:48 mohor // overrun signal was moved to separate block because many sequential lsr // reads were preventing data from being written to rx fifo. // underrun signal was not used and was removed from the project. // // Revision 1.21 2001/12/13 10:31:16 mohor // timeout irq must be set regardless of the rda irq (rda irq does not reset the // timeout counter). // // Revision 1.20 2001/12/10 19:52:05 gorban // Igor fixed break condition bugs // // Revision 1.19 2001/12/06 14:51:04 gorban // Bug in LSR[0] is fixed. // All WISHBONE signals are now sampled, so another wait-state is introduced on all transfers. // // Revision 1.18 2001/12/03 21:44:29 gorban // Updated specification documentation. // Added full 32-bit data bus interface, now as default. // Address is 5-bit wide in 32-bit data bus mode. // Added wb_sel_i input to the core. It's used in the 32-bit mode. // Added debug interface with two 32-bit read-only registers in 32-bit mode. // Bits 5 and 6 of LSR are now only cleared on TX FIFO write. // My small test bench is modified to work with 32-bit mode. // // Revision 1.17 2001/11/28 19:36:39 gorban // Fixed: timeout and break didn't pay attention to current data format when counting time // // Revision 1.16 2001/11/27 22:17:09 gorban // Fixed bug that prevented synthesis in uart_receiver.v // // Revision 1.15 2001/11/26 21:38:54 gorban // Lots of fixes: // Break condition wasn't handled correctly at all. // LSR bits could lose their values. // LSR value after reset was wrong. // Timing of THRE interrupt signal corrected. // LSR bit 0 timing corrected. // // Revision 1.14 2001/11/10 12:43:21 gorban // Logic Synthesis bugs fixed. Some other minor changes // // Revision 1.13 2001/11/08 14:54:23 mohor // Comments in Slovene language deleted, few small fixes for better work of // old tools. IRQs need to be fix. // // Revision 1.12 2001/11/07 17:51:52 gorban // Heavily rewritten interrupt and LSR subsystems. // Many bugs hopefully squashed. // // Revision 1.11 2001/10/31 15:19:22 gorban // Fixes to break and timeout conditions // // Revision 1.10 2001/10/20 09:58:40 gorban // Small synopsis fixes // // Revision 1.9 2001/08/24 21:01:12 mohor // Things connected to parity changed. // Clock devider changed. // // Revision 1.8 2001/08/23 16:05:05 mohor // Stop bit bug fixed. // Parity bug fixed. // WISHBONE read cycle bug fixed, // OE indicator (Overrun Error) bug fixed. // PE indicator (Parity Error) bug fixed. // Register read bug fixed. // // Revision 1.6 2001/06/23 11:21:48 gorban // DL made 16-bit long. Fixed transmission/reception bugs. // // Revision 1.5 2001/06/02 14:28:14 gorban // Fixed receiver and transmitter. Major bug fixed. // // Revision 1.4 2001/05/31 20:08:01 gorban // FIFO changes and other corrections. // // Revision 1.3 2001/05/27 17:37:49 gorban // Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file. // // Revision 1.2 2001/05/21 19:12:02 gorban // Corrected some Linter messages. // // Revision 1.1 2001/05/17 18:34:18 gorban // First 'stable' release. Should be sythesizable now. Also added new header. // // Revision 1.0 2001-05-17 21:27:11+02 jacob // Initial revision // // `include "uart_defines.v" module uart_receiver (clk, wb_rst_i, lcr, rf_pop, srx_pad_i, enable, counter_t, rf_count, rf_data_out, rf_error_bit, rf_overrun, rx_reset, lsr_mask, rstate, rf_push_pulse); input clk; input wb_rst_i; input [7:0] lcr; input rf_pop; input srx_pad_i; input enable; input rx_reset; input lsr_mask; output [9:0] counter_t; output [`UART_FIFO_COUNTER_W-1:0] rf_count; output [`UART_FIFO_REC_WIDTH-1:0] rf_data_out; output rf_overrun; output rf_error_bit; output [3:0] rstate; output rf_push_pulse; reg [3:0] rstate; reg [3:0] rcounter16; reg [2:0] rbit_counter; reg [7:0] rshift; // receiver shift register reg rparity; // received parity reg rparity_error; reg rframing_error; // framing error flag reg rparity_xor; reg [7:0] counter_b; // counts the 0 (low) signals reg rf_push_q; // RX FIFO signals reg [`UART_FIFO_REC_WIDTH-1:0] rf_data_in; wire [`UART_FIFO_REC_WIDTH-1:0] rf_data_out; wire rf_push_pulse; reg rf_push; wire rf_pop; wire rf_overrun; wire [`UART_FIFO_COUNTER_W-1:0] rf_count; wire rf_error_bit; // an error (parity or framing) is inside the fifo wire break_error = (counter_b == 0); // RX FIFO instance uart_rfifo #(`UART_FIFO_REC_WIDTH) fifo_rx( .clk( clk ), .wb_rst_i( wb_rst_i ), .data_in( rf_data_in ), .data_out( rf_data_out ), .push( rf_push_pulse ), .pop( rf_pop ), .overrun( rf_overrun ), .count( rf_count ), .error_bit( rf_error_bit ), .fifo_reset( rx_reset ), .reset_status(lsr_mask) ); wire rcounter16_eq_7 = (rcounter16 == 4'd7); wire rcounter16_eq_0 = (rcounter16 == 4'd0); wire [3:0] rcounter16_minus_1 = rcounter16 - 3'd1; parameter sr_idle = 4'd0; parameter sr_rec_start = 4'd1; parameter sr_rec_bit = 4'd2; parameter sr_rec_parity = 4'd3; parameter sr_rec_stop = 4'd4; parameter sr_check_parity = 4'd5; parameter sr_rec_prepare = 4'd6; parameter sr_end_bit = 4'd7; parameter sr_ca_lc_parity = 4'd8; parameter sr_wait1 = 4'd9; parameter sr_push = 4'd10; always @(posedge clk or posedge wb_rst_i) begin if (wb_rst_i) begin rstate <= sr_idle; rcounter16 <= 0; rbit_counter <= 0; rparity_xor <= 1'b0; rframing_error <= 1'b0; rparity_error <= 1'b0; rparity <= 1'b0; rshift <= 0; rf_push <= 1'b0; rf_data_in <= 0; end else if (enable) begin case (rstate) sr_idle : begin rf_push <= 1'b0; rf_data_in <= 0; rcounter16 <= 4'b1110; if (srx_pad_i==1'b0 & ~break_error) // detected a pulse (start bit?) begin rstate <= sr_rec_start; end end sr_rec_start : begin rf_push <= 1'b0; if (rcounter16_eq_7) // check the pulse if (srx_pad_i==1'b1) // no start bit rstate <= sr_idle; else // start bit detected rstate <= sr_rec_prepare; rcounter16 <= rcounter16_minus_1; end sr_rec_prepare:begin case (lcr[/*`UART_LC_BITS*/1:0]) // number of bits in a word 2'b00 : rbit_counter <= 3'b100; 2'b01 : rbit_counter <= 3'b101; 2'b10 : rbit_counter <= 3'b110; 2'b11 : rbit_counter <= 3'b111; endcase if (rcounter16_eq_0) begin rstate <= sr_rec_bit; rcounter16 <= 4'b1110; rshift <= 0; end else rstate <= sr_rec_prepare; rcounter16 <= rcounter16_minus_1; end sr_rec_bit : begin if (rcounter16_eq_0) rstate <= sr_end_bit; if (rcounter16_eq_7) // read the bit case (lcr[/*`UART_LC_BITS*/1:0]) // number of bits in a word 2'b00 : rshift[4:0] <= {srx_pad_i, rshift[4:1]}; 2'b01 : rshift[5:0] <= {srx_pad_i, rshift[5:1]}; 2'b10 : rshift[6:0] <= {srx_pad_i, rshift[6:1]}; 2'b11 : rshift[7:0] <= {srx_pad_i, rshift[7:1]}; endcase rcounter16 <= rcounter16_minus_1; end sr_end_bit : begin if (rbit_counter==3'b0) // no more bits in word if (lcr[`UART_LC_PE]) // choose state based on parity rstate <= sr_rec_parity; else begin rstate <= sr_rec_stop; rparity_error <= 1'b0; // no parity - no error :) end else // else we have more bits to read begin rstate <= sr_rec_bit; rbit_counter <= rbit_counter - 3'd1; end rcounter16 <= 4'b1110; end sr_rec_parity: begin if (rcounter16_eq_7) // read the parity begin rparity <= srx_pad_i; rstate <= sr_ca_lc_parity; end rcounter16 <= rcounter16_minus_1; end sr_ca_lc_parity : begin // rcounter equals 6 rcounter16 <= rcounter16_minus_1; rparity_xor <= ^{rshift,rparity}; // calculate parity on all incoming data rstate <= sr_check_parity; end sr_check_parity: begin // rcounter equals 5 case ({lcr[`UART_LC_EP],lcr[`UART_LC_SP]}) 2'b00: rparity_error <= rparity_xor == 0; // no error if parity 1 2'b01: rparity_error <= ~rparity; // parity should sticked to 1 2'b10: rparity_error <= rparity_xor == 1; // error if parity is odd 2'b11: rparity_error <= rparity; // parity should be sticked to 0 endcase rcounter16 <= rcounter16_minus_1; rstate <= sr_wait1; end sr_wait1 : if (rcounter16_eq_0) begin rstate <= sr_rec_stop; rcounter16 <= 4'b1110; end else rcounter16 <= rcounter16_minus_1; sr_rec_stop : begin if (rcounter16_eq_7) // read the parity begin rframing_error <= !srx_pad_i; // no framing error if input is 1 (stop bit) rstate <= sr_push; end rcounter16 <= rcounter16_minus_1; end sr_push : begin /////////////////////////////////////// // $display($time, ": received: %b", rf_data_in); if(srx_pad_i | break_error) begin if(break_error) rf_data_in <= {8'b0, 3'b100}; // break input (empty character) to receiver FIFO else rf_data_in <= {rshift, 1'b0, rparity_error, rframing_error}; rf_push <= 1'b1; rstate <= sr_idle; end else if(~rframing_error) // There's always a framing before break_error -> wait for break or srx_pad_i begin rf_data_in <= {rshift, 1'b0, rparity_error, rframing_error}; rf_push <= 1'b1; rcounter16 <= 4'b1110; rstate <= sr_rec_start; end end default : rstate <= sr_idle; endcase end // if (enable) end // always of receiver always @ (posedge clk or posedge wb_rst_i) begin if(wb_rst_i) rf_push_q <= 0; else rf_push_q <= rf_push; end assign rf_push_pulse = rf_push & ~rf_push_q; // // Break condition detection. // Works in conjuction with the receiver state machine reg [9:0] toc_value; // value to be set to timeout counter always @(lcr) case (lcr[3:0]) 4'b0000 : toc_value = 447; // 7 bits 4'b0100 : toc_value = 479; // 7.5 bits 4'b0001, 4'b1000 : toc_value = 511; // 8 bits 4'b1100 : toc_value = 543; // 8.5 bits 4'b0010, 4'b0101, 4'b1001 : toc_value = 575; // 9 bits 4'b0011, 4'b0110, 4'b1010, 4'b1101 : toc_value = 639; // 10 bits 4'b0111, 4'b1011, 4'b1110 : toc_value = 703; // 11 bits 4'b1111 : toc_value = 767; // 12 bits endcase // case(lcr[3:0]) wire [7:0] brc_value; // value to be set to break counter assign brc_value = toc_value[9:2]; // the same as timeout but 1 insead of 4 character times always @(posedge clk or posedge wb_rst_i) begin if (wb_rst_i) counter_b <= 8'd159; else if (srx_pad_i) counter_b <= brc_value; // character time length - 1 else if(enable & counter_b != 8'b0) // only work on enable times break not reached. counter_b <= counter_b - 8'd1; // decrement break counter end // always of break condition detection /// /// Timeout condition detection reg [9:0] counter_t; // counts the timeout condition clocks always @(posedge clk or posedge wb_rst_i) begin if (wb_rst_i) counter_t <= 10'd639; // 10 bits for the default 8N1 else if(rf_push_pulse || rf_pop || rf_count == 0) // counter is reset when RX FIFO is empty, accessed or above trigger level counter_t <= toc_value; else if (enable && counter_t != 10'b0) // we don't want to underflow counter_t <= counter_t - 10'd1; end endmodule
////////////////////////////////////////////////////////////////////// //// //// //// uart_regs.v //// //// //// //// //// //// This file is part of the "UART 16550 compatible" project //// //// http://www.opencores.org/cores/uart16550/ //// //// //// //// Documentation related to this project: //// //// - http://www.opencores.org/cores/uart16550/ //// //// //// //// Projects compatibility: //// //// - WISHBONE //// //// RS232 Protocol //// //// 16550D uart (mostly supported) //// //// //// //// Overview (main Features): //// //// Registers of the uart 16550 core //// //// //// //// Known problems (limits): //// //// Inserts 1 wait state in all WISHBONE transfers //// //// //// //// To Do: //// //// Nothing or verification. //// //// //// //// Author(s): //// //// - gorban@opencores.org //// //// - Jacob Gorban //// //// - Igor Mohor (igorm@opencores.org) //// //// //// //// Created: 2001/05/12 //// //// Last Updated: (See log for the revision history //// //// //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2000, 2001 Authors //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// // // CVS Revision History // // $Log: not supported by cvs2svn $ // Revision 1.41 2004/05/21 11:44:41 tadejm // Added synchronizer flops for RX input. // // Revision 1.40 2003/06/11 16:37:47 gorban // This fixes errors in some cases when data is being read and put to the FIFO at the same time. Patch is submitted by Scott Furman. Update is very recommended. // // Revision 1.39 2002/07/29 21:16:18 gorban // The uart_defines.v file is included again in sources. // // Revision 1.38 2002/07/22 23:02:23 gorban // Bug Fixes: // * Possible loss of sync and bad reception of stop bit on slow baud rates fixed. // Problem reported by Kenny.Tung. // * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers. // // Improvements: // * Made FIFO's as general inferrable memory where possible. // So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx). // This saves about 1/3 of the Slice count and reduces P&R and synthesis times. // // * Added optional baudrate output (baud_o). // This is identical to BAUDOUT* signal on 16550 chip. // It outputs 16xbit_clock_rate - the divided clock. // It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use. // // Revision 1.37 2001/12/27 13:24:09 mohor // lsr[7] was not showing overrun errors. // // Revision 1.36 2001/12/20 13:25:46 mohor // rx push changed to be only one cycle wide. // // Revision 1.35 2001/12/19 08:03:34 mohor // Warnings cleared. // // Revision 1.34 2001/12/19 07:33:54 mohor // Synplicity was having troubles with the comment. // // Revision 1.33 2001/12/17 10:14:43 mohor // Things related to msr register changed. After THRE IRQ occurs, and one // character is written to the transmit fifo, the detection of the THRE bit in the // LSR is delayed for one character time. // // Revision 1.32 2001/12/14 13:19:24 mohor // MSR register fixed. // // Revision 1.31 2001/12/14 10:06:58 mohor // After reset modem status register MSR should be reset. // // Revision 1.30 2001/12/13 10:09:13 mohor // thre irq should be cleared only when being source of interrupt. // // Revision 1.29 2001/12/12 09:05:46 mohor // LSR status bit 0 was not cleared correctly in case of reseting the FCR (rx fifo). // // Revision 1.28 2001/12/10 19:52:41 gorban // Scratch register added // // Revision 1.27 2001/12/06 14:51:04 gorban // Bug in LSR[0] is fixed. // All WISHBONE signals are now sampled, so another wait-state is introduced on all transfers. // // Revision 1.26 2001/12/03 21:44:29 gorban // Updated specification documentation. // Added full 32-bit data bus interface, now as default. // Address is 5-bit wide in 32-bit data bus mode. // Added wb_sel_i input to the core. It's used in the 32-bit mode. // Added debug interface with two 32-bit read-only registers in 32-bit mode. // Bits 5 and 6 of LSR are now only cleared on TX FIFO write. // My small test bench is modified to work with 32-bit mode. // // Revision 1.25 2001/11/28 19:36:39 gorban // Fixed: timeout and break didn't pay attention to current data format when counting time // // Revision 1.24 2001/11/26 21:38:54 gorban // Lots of fixes: // Break condition wasn't handled correctly at all. // LSR bits could lose their values. // LSR value after reset was wrong. // Timing of THRE interrupt signal corrected. // LSR bit 0 timing corrected. // // Revision 1.23 2001/11/12 21:57:29 gorban // fixed more typo bugs // // Revision 1.22 2001/11/12 15:02:28 mohor // lsr1r error fixed. // // Revision 1.21 2001/11/12 14:57:27 mohor // ti_int_pnd error fixed. // // Revision 1.20 2001/11/12 14:50:27 mohor // ti_int_d error fixed. // // Revision 1.19 2001/11/10 12:43:21 gorban // Logic Synthesis bugs fixed. Some other minor changes // // Revision 1.18 2001/11/08 14:54:23 mohor // Comments in Slovene language deleted, few small fixes for better work of // old tools. IRQs need to be fix. // // Revision 1.17 2001/11/07 17:51:52 gorban // Heavily rewritten interrupt and LSR subsystems. // Many bugs hopefully squashed. // // Revision 1.16 2001/11/02 09:55:16 mohor // no message // // Revision 1.15 2001/10/31 15:19:22 gorban // Fixes to break and timeout conditions // // Revision 1.14 2001/10/29 17:00:46 gorban // fixed parity sending and tx_fifo resets over- and underrun // // Revision 1.13 2001/10/20 09:58:40 gorban // Small synopsis fixes // // Revision 1.12 2001/10/19 16:21:40 gorban // Changes data_out to be synchronous again as it should have been. // // Revision 1.11 2001/10/18 20:35:45 gorban // small fix // // Revision 1.10 2001/08/24 21:01:12 mohor // Things connected to parity changed. // Clock devider changed. // // Revision 1.9 2001/08/23 16:05:05 mohor // Stop bit bug fixed. // Parity bug fixed. // WISHBONE read cycle bug fixed, // OE indicator (Overrun Error) bug fixed. // PE indicator (Parity Error) bug fixed. // Register read bug fixed. // // Revision 1.10 2001/06/23 11:21:48 gorban // DL made 16-bit long. Fixed transmission/reception bugs. // // Revision 1.9 2001/05/31 20:08:01 gorban // FIFO changes and other corrections. // // Revision 1.8 2001/05/29 20:05:04 gorban // Fixed some bugs and synthesis problems. // // Revision 1.7 2001/05/27 17:37:49 gorban // Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file. // // Revision 1.6 2001/05/21 19:12:02 gorban // Corrected some Linter messages. // // Revision 1.5 2001/05/17 18:34:18 gorban // First 'stable' release. Should be sythesizable now. Also added new header. // // Revision 1.0 2001-05-17 21:27:11+02 jacob // Initial revision // // `include "uart_defines.v" `define UART_DL1 7:0 `define UART_DL2 15:8 module uart_regs #(parameter SIM = 0) (clk, wb_rst_i, wb_addr_i, wb_dat_i, wb_dat_o, wb_we_i, wb_re_i, // additional signals modem_inputs, stx_pad_o, srx_pad_i, rts_pad_o, dtr_pad_o, int_o `ifdef UART_HAS_BAUDRATE_OUTPUT , baud_o `endif ); input clk; input wb_rst_i; input [2:0] wb_addr_i; input [7:0] wb_dat_i; output [7:0] wb_dat_o; input wb_we_i; input wb_re_i; output stx_pad_o; input srx_pad_i; input [3:0] modem_inputs; output rts_pad_o; output dtr_pad_o; output int_o; `ifdef UART_HAS_BAUDRATE_OUTPUT output baud_o; `endif wire [3:0] modem_inputs; reg enable; `ifdef UART_HAS_BAUDRATE_OUTPUT assign baud_o = enable; // baud_o is actually the enable signal `endif wire stx_pad_o; // received from transmitter module wire srx_pad_i; wire srx_pad; reg [7:0] wb_dat_o; wire [2:0] wb_addr_i; wire [7:0] wb_dat_i; reg [3:0] ier; reg [3:0] iir; reg [1:0] fcr; /// bits 7 and 6 of fcr. Other bits are ignored reg [4:0] mcr; reg [7:0] lcr; reg [7:0] msr; reg [15:0] dl; // 32-bit divisor latch reg [7:0] scratch; // UART scratch register reg start_dlc; // activate dlc on writing to UART_DL1 reg lsr_mask_d; // delay for lsr_mask condition reg msi_reset; // reset MSR 4 lower bits indicator //reg threi_clear; // THRE interrupt clear flag reg [15:0] dlc; // 32-bit divisor latch counter reg int_o; reg [3:0] trigger_level; // trigger level of the receiver FIFO reg rx_reset; reg tx_reset; wire dlab; // divisor latch access bit wire cts_pad_i, dsr_pad_i, ri_pad_i, dcd_pad_i; // modem status bits wire loopback; // loopback bit (MCR bit 4) wire cts, dsr, ri, dcd; // effective signals wire cts_c, dsr_c, ri_c, dcd_c; // Complement effective signals (considering loopback) wire rts_pad_o, dtr_pad_o; // modem control outputs // LSR bits wires and regs wire [7:0] lsr; wire lsr0, lsr1, lsr2, lsr3, lsr4, lsr5, lsr6, lsr7; reg lsr0r, lsr1r, lsr2r, lsr3r, lsr4r, lsr5r, lsr6r, lsr7r; wire lsr_mask; // lsr_mask // // ASSINGS // assign lsr[7:0] = { lsr7r, lsr6r, lsr5r, lsr4r, lsr3r, lsr2r, lsr1r, lsr0r }; assign {cts_pad_i, dsr_pad_i, ri_pad_i, dcd_pad_i} = modem_inputs; assign {cts, dsr, ri, dcd} = ~{cts_pad_i,dsr_pad_i,ri_pad_i,dcd_pad_i}; assign {cts_c, dsr_c, ri_c, dcd_c} = loopback ? {mcr[`UART_MC_RTS],mcr[`UART_MC_DTR],mcr[`UART_MC_OUT1],mcr[`UART_MC_OUT2]} : {cts_pad_i,dsr_pad_i,ri_pad_i,dcd_pad_i}; assign dlab = lcr[`UART_LC_DL]; assign loopback = mcr[4]; // assign modem outputs assign rts_pad_o = mcr[`UART_MC_RTS]; assign dtr_pad_o = mcr[`UART_MC_DTR]; // Interrupt signals wire rls_int; // receiver line status interrupt wire rda_int; // receiver data available interrupt wire ti_int; // timeout indicator interrupt wire thre_int; // transmitter holding register empty interrupt wire ms_int; // modem status interrupt // FIFO signals reg tf_push; reg rf_pop; wire [`UART_FIFO_REC_WIDTH-1:0] rf_data_out; wire rf_error_bit; // an error (parity or framing) is inside the fifo wire rf_overrun; wire rf_push_pulse; wire [`UART_FIFO_COUNTER_W-1:0] rf_count; wire [`UART_FIFO_COUNTER_W-1:0] tf_count; wire [2:0] tstate; wire [3:0] rstate; wire [9:0] counter_t; wire thre_set_en; // THRE status is delayed one character time when a character is written to fifo. reg [7:0] block_cnt; // While counter counts, THRE status is blocked (delayed one character cycle) reg [7:0] block_value; // One character length minus stop bit // Transmitter Instance wire serial_out; uart_transmitter #(.SIM (SIM)) transmitter(clk, wb_rst_i, lcr, tf_push, wb_dat_i, enable, serial_out, tstate, tf_count, tx_reset, lsr_mask); // Synchronizing and sampling serial RX input uart_sync_flops i_uart_sync_flops ( .rst_i (wb_rst_i), .clk_i (clk), .stage1_rst_i (1'b0), .stage1_clk_en_i (1'b1), .async_dat_i (srx_pad_i), .sync_dat_o (srx_pad) ); defparam i_uart_sync_flops.width = 1; defparam i_uart_sync_flops.init_value = 1'b1; // handle loopback wire serial_in = loopback ? serial_out : srx_pad; assign stx_pad_o = loopback ? 1'b1 : serial_out; // Receiver Instance uart_receiver receiver(clk, wb_rst_i, lcr, rf_pop, serial_in, enable, counter_t, rf_count, rf_data_out, rf_error_bit, rf_overrun, rx_reset, lsr_mask, rstate, rf_push_pulse); // Asynchronous reading here because the outputs are sampled in uart_wb.v file always @(dl or dlab or ier or iir or scratch or lcr or lsr or msr or rf_data_out or wb_addr_i or wb_re_i) // asynchrounous reading begin case (wb_addr_i) `UART_REG_RB : wb_dat_o = dlab ? dl[`UART_DL1] : rf_data_out[10:3]; `UART_REG_IE : wb_dat_o = dlab ? dl[`UART_DL2] : {4'd0,ier}; `UART_REG_II : wb_dat_o = {4'b1100,iir}; `UART_REG_LC : wb_dat_o = lcr; `UART_REG_LS : wb_dat_o = lsr; `UART_REG_MS : wb_dat_o = msr; `UART_REG_SR : wb_dat_o = scratch; default: wb_dat_o = 8'b0; // ?? endcase // case(wb_addr_i) end // always @ (dl or dlab or ier or iir or scratch... // rf_pop signal handling always @(posedge clk or posedge wb_rst_i) begin if (wb_rst_i) rf_pop <= 0; else if (rf_pop) // restore the signal to 0 after one clock cycle rf_pop <= 0; else if (wb_re_i && wb_addr_i == `UART_REG_RB && !dlab) rf_pop <= 1; // advance read pointer end wire lsr_mask_condition; wire iir_read; wire msr_read; wire fifo_read; wire fifo_write; assign lsr_mask_condition = (wb_re_i && wb_addr_i == `UART_REG_LS && !dlab); assign iir_read = (wb_re_i && wb_addr_i == `UART_REG_II && !dlab); assign msr_read = (wb_re_i && wb_addr_i == `UART_REG_MS && !dlab); assign fifo_read = (wb_re_i && wb_addr_i == `UART_REG_RB && !dlab); assign fifo_write = (wb_we_i && wb_addr_i == `UART_REG_TR && !dlab); // lsr_mask_d delayed signal handling always @(posedge clk or posedge wb_rst_i) begin if (wb_rst_i) lsr_mask_d <= 0; else // reset bits in the Line Status Register lsr_mask_d <= lsr_mask_condition; end // lsr_mask is rise detected assign lsr_mask = lsr_mask_condition && ~lsr_mask_d; // msi_reset signal handling always @(posedge clk or posedge wb_rst_i) begin if (wb_rst_i) msi_reset <= 1; else if (msi_reset) msi_reset <= 0; else if (msr_read) msi_reset <= 1; // reset bits in Modem Status Register end // // WRITES AND RESETS // // // Line Control Register always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lcr <= 8'b00000011; // 8n1 setting else if (wb_we_i && wb_addr_i==`UART_REG_LC) lcr <= wb_dat_i; // Interrupt Enable Register or UART_DL2 always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) begin ier <= 4'b0000; // no interrupts after reset `ifdef PRESCALER_PRESET_HARD dl[`UART_DL2] <= `PRESCALER_HIGH_PRESET; `else dl[`UART_DL2] <= 8'b0; `endif end else if (wb_we_i && wb_addr_i==`UART_REG_IE) if (dlab) begin dl[`UART_DL2] <= `ifdef PRESCALER_PRESET_HARD dl[`UART_DL2]; `else wb_dat_i; `endif end else ier <= wb_dat_i[3:0]; // ier uses only 4 lsb // FIFO Control Register and rx_reset, tx_reset signals always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) begin fcr <= 2'b11; rx_reset <= 0; tx_reset <= 0; end else if (wb_we_i && wb_addr_i==`UART_REG_FC) begin fcr <= wb_dat_i[7:6]; rx_reset <= wb_dat_i[1]; tx_reset <= wb_dat_i[2]; end else begin rx_reset <= 0; tx_reset <= 0; end // Modem Control Register always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) mcr <= 5'b0; else if (wb_we_i && wb_addr_i==`UART_REG_MC) mcr <= wb_dat_i[4:0]; // Scratch register // Line Control Register always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) scratch <= 0; // 8n1 setting else if (wb_we_i && wb_addr_i==`UART_REG_SR) scratch <= wb_dat_i; // TX_FIFO or UART_DL1 always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) begin `ifdef PRESCALER_PRESET_HARD dl[`UART_DL1] <= `PRESCALER_LOW_PRESET; `else dl[`UART_DL1] <= 8'b0; `endif tf_push <= 1'b0; start_dlc <= 1'b0; end else if (wb_we_i && wb_addr_i==`UART_REG_TR) if (dlab) begin `ifdef PRESCALER_PRESET_HARD dl[`UART_DL1] <= dl[`UART_DL1]; `else dl[`UART_DL1] <= wb_dat_i; `endif start_dlc <= 1'b1; // enable DL counter tf_push <= 1'b0; end else begin tf_push <= 1'b1; start_dlc <= 1'b0; end // else: !if(dlab) else begin start_dlc <= 1'b0; tf_push <= 1'b0; end // else: !if(dlab) // Receiver FIFO trigger level selection logic (asynchronous mux) always @(fcr) case (fcr[`UART_FC_TL]) 2'b00 : trigger_level = 1; 2'b01 : trigger_level = 4; 2'b10 : trigger_level = 8; 2'b11 : trigger_level = 14; endcase // case(fcr[`UART_FC_TL]) // // STATUS REGISTERS // // // Modem Status Register reg [3:0] delayed_modem_signals; always @(posedge clk or posedge wb_rst_i) begin if (wb_rst_i) begin msr <= 0; delayed_modem_signals[3:0] <= 0; end else begin msr[`UART_MS_DDCD:`UART_MS_DCTS] <= msi_reset ? 4'b0 : msr[`UART_MS_DDCD:`UART_MS_DCTS] | ({dcd, ri, dsr, cts} ^ delayed_modem_signals[3:0]); msr[`UART_MS_CDCD:`UART_MS_CCTS] <= {dcd_c, ri_c, dsr_c, cts_c}; delayed_modem_signals[3:0] <= {dcd, ri, dsr, cts}; end end // Line Status Register // activation conditions assign lsr0 = (rf_count==0 && rf_push_pulse); // data in receiver fifo available set condition assign lsr1 = rf_overrun; // Receiver overrun error assign lsr2 = rf_data_out[1]; // parity error bit assign lsr3 = rf_data_out[0]; // framing error bit assign lsr4 = rf_data_out[2]; // break error in the character assign lsr5 = (tf_count==5'b0 && thre_set_en); // transmitter fifo is empty assign lsr6 = (tf_count==5'b0 && thre_set_en && (tstate == /*`S_IDLE */ 0)); // transmitter empty assign lsr7 = rf_error_bit | rf_overrun; // lsr bit0 (receiver data available) reg lsr0_d; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr0_d <= 0; else lsr0_d <= lsr0; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr0r <= 0; else lsr0r <= (rf_count==1 && rf_pop && !rf_push_pulse || rx_reset) ? 1'b0 : // deassert condition lsr0r || (lsr0 && ~lsr0_d); // set on rise of lsr0 and keep asserted until deasserted // lsr bit 1 (receiver overrun) reg lsr1_d; // delayed always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr1_d <= 0; else lsr1_d <= lsr1; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr1r <= 0; else lsr1r <= lsr_mask ? 1'b0 : lsr1r || (lsr1 && ~lsr1_d); // set on rise // lsr bit 2 (parity error) reg lsr2_d; // delayed always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr2_d <= 0; else lsr2_d <= lsr2; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr2r <= 0; else lsr2r <= lsr_mask ? 1'b0 : lsr2r || (lsr2 && ~lsr2_d); // set on rise // lsr bit 3 (framing error) reg lsr3_d; // delayed always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr3_d <= 0; else lsr3_d <= lsr3; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr3r <= 0; else lsr3r <= lsr_mask ? 1'b0 : lsr3r || (lsr3 && ~lsr3_d); // set on rise // lsr bit 4 (break indicator) reg lsr4_d; // delayed always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr4_d <= 0; else lsr4_d <= lsr4; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr4r <= 0; else lsr4r <= lsr_mask ? 1'b0 : lsr4r || (lsr4 && ~lsr4_d); // lsr bit 5 (transmitter fifo is empty) reg lsr5_d; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr5_d <= 1; else lsr5_d <= lsr5; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr5r <= 1; else lsr5r <= (fifo_write) ? 1'b0 : lsr5r || (lsr5 && ~lsr5_d); // lsr bit 6 (transmitter empty indicator) reg lsr6_d; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr6_d <= 1; else lsr6_d <= lsr6; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr6r <= 1; else lsr6r <= (fifo_write) ? 1'b0 : lsr6r || (lsr6 && ~lsr6_d); // lsr bit 7 (error in fifo) reg lsr7_d; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr7_d <= 0; else lsr7_d <= lsr7; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) lsr7r <= 0; else lsr7r <= lsr_mask ? 1'b0 : lsr7r || (lsr7 && ~lsr7_d); // Frequency divider always @(posedge clk or posedge wb_rst_i) begin if (wb_rst_i) dlc <= 0; else if (start_dlc | ~ (|dlc)) dlc <= dl - 16'd1; // preset counter else dlc <= dlc - 16'd1; // decrement counter end // Enable signal generation logic always @(posedge clk or posedge wb_rst_i) begin if (wb_rst_i) enable <= 1'b0; else if (|dl & ~(|dlc)) // dl>0 & dlc==0 enable <= 1'b1; else enable <= 1'b0; end // Delaying THRE status for one character cycle after a character is written to an empty fifo. always @(lcr) case (lcr[3:0]) 4'b0000 : block_value = 95; // 6 bits 4'b0100 : block_value = 103; // 6.5 bits 4'b0001, 4'b1000 : block_value = 111; // 7 bits 4'b1100 : block_value = 119; // 7.5 bits 4'b0010, 4'b0101, 4'b1001 : block_value = 127; // 8 bits 4'b0011, 4'b0110, 4'b1010, 4'b1101 : block_value = 143; // 9 bits 4'b0111, 4'b1011, 4'b1110 : block_value = 159; // 10 bits 4'b1111 : block_value = 175; // 11 bits endcase // case(lcr[3:0]) // Counting time of one character minus stop bit always @(posedge clk or posedge wb_rst_i) begin if (wb_rst_i) block_cnt <= 8'd0; else if(lsr5r & fifo_write) // THRE bit set & write to fifo occured block_cnt <= SIM ? 8'd1 : block_value; else if (enable & block_cnt != 8'b0) // only work on enable times block_cnt <= block_cnt - 8'd1; // decrement break counter end // always of break condition detection // Generating THRE status enable signal assign thre_set_en = ~(|block_cnt); // // INTERRUPT LOGIC // assign rls_int = ier[`UART_IE_RLS] && (lsr[`UART_LS_OE] || lsr[`UART_LS_PE] || lsr[`UART_LS_FE] || lsr[`UART_LS_BI]); assign rda_int = ier[`UART_IE_RDA] && (rf_count >= {1'b0,trigger_level}); assign thre_int = ier[`UART_IE_THRE] && lsr[`UART_LS_TFE]; assign ms_int = ier[`UART_IE_MS] && (| msr[3:0]); assign ti_int = ier[`UART_IE_RDA] && (counter_t == 10'b0) && (|rf_count); reg rls_int_d; reg thre_int_d; reg ms_int_d; reg ti_int_d; reg rda_int_d; // delay lines always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) rls_int_d <= 0; else rls_int_d <= rls_int; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) rda_int_d <= 0; else rda_int_d <= rda_int; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) thre_int_d <= 0; else thre_int_d <= thre_int; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) ms_int_d <= 0; else ms_int_d <= ms_int; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) ti_int_d <= 0; else ti_int_d <= ti_int; // rise detection signals wire rls_int_rise; wire thre_int_rise; wire ms_int_rise; wire ti_int_rise; wire rda_int_rise; assign rda_int_rise = rda_int & ~rda_int_d; assign rls_int_rise = rls_int & ~rls_int_d; assign thre_int_rise = thre_int & ~thre_int_d; assign ms_int_rise = ms_int & ~ms_int_d; assign ti_int_rise = ti_int & ~ti_int_d; // interrupt pending flags reg rls_int_pnd; reg rda_int_pnd; reg thre_int_pnd; reg ms_int_pnd; reg ti_int_pnd; // interrupt pending flags assignments always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) rls_int_pnd <= 0; else rls_int_pnd <= lsr_mask ? 1'b0 : // reset condition rls_int_rise ? 1'b1 : // latch condition rls_int_pnd && ier[`UART_IE_RLS]; // default operation: remove if masked always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) rda_int_pnd <= 0; else rda_int_pnd <= ((rf_count == {1'b0,trigger_level}) && fifo_read) ? 1'b0 : // reset condition rda_int_rise ? 1'b1 : // latch condition rda_int_pnd && ier[`UART_IE_RDA]; // default operation: remove if masked always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) thre_int_pnd <= 0; else thre_int_pnd <= fifo_write || (iir_read & ~iir[`UART_II_IP] & iir[`UART_II_II] == `UART_II_THRE)? 1'b0 : thre_int_rise ? 1'b1 : thre_int_pnd && ier[`UART_IE_THRE]; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) ms_int_pnd <= 0; else ms_int_pnd <= msr_read ? 1'b0 : ms_int_rise ? 1'b1 : ms_int_pnd && ier[`UART_IE_MS]; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) ti_int_pnd <= 0; else ti_int_pnd <= fifo_read ? 1'b0 : ti_int_rise ? 1'b1 : ti_int_pnd && ier[`UART_IE_RDA]; // end of pending flags // INT_O logic always @(posedge clk or posedge wb_rst_i) begin if (wb_rst_i) int_o <= 1'b0; else int_o <= rls_int_pnd ? ~lsr_mask : rda_int_pnd ? 1'b1 : ti_int_pnd ? ~fifo_read : thre_int_pnd ? !(fifo_write & iir_read) : ms_int_pnd ? ~msr_read : 1'd0; // if no interrupt are pending end // Interrupt Identification register always @(posedge clk or posedge wb_rst_i) begin if (wb_rst_i) iir <= 1; else if (rls_int_pnd) // interrupt is pending begin iir[`UART_II_II] <= `UART_II_RLS; // set identification register to correct value iir[`UART_II_IP] <= 1'b0; // and clear the IIR bit 0 (interrupt pending) end else // the sequence of conditions determines priority of interrupt identification if (rda_int) begin iir[`UART_II_II] <= `UART_II_RDA; iir[`UART_II_IP] <= 1'b0; end else if (ti_int_pnd) begin iir[`UART_II_II] <= `UART_II_TI; iir[`UART_II_IP] <= 1'b0; end else if (thre_int_pnd) begin iir[`UART_II_II] <= `UART_II_THRE; iir[`UART_II_IP] <= 1'b0; end else if (ms_int_pnd) begin iir[`UART_II_II] <= `UART_II_MS; iir[`UART_II_IP] <= 1'b0; end else // no interrupt is pending begin iir[`UART_II_II] <= 0; iir[`UART_II_IP] <= 1'b1; end end endmodule
////////////////////////////////////////////////////////////////////// //// //// //// uart_rfifo.v (Modified from uart_fifo.v) //// //// //// //// //// //// This file is part of the "UART 16550 compatible" project //// //// http://www.opencores.org/cores/uart16550/ //// //// //// //// Documentation related to this project: //// //// - http://www.opencores.org/cores/uart16550/ //// //// //// //// Projects compatibility: //// //// - WISHBONE //// //// RS232 Protocol //// //// 16550D uart (mostly supported) //// //// //// //// Overview (main Features): //// //// UART core receiver FIFO //// //// //// //// To Do: //// //// Nothing. //// //// //// //// Author(s): //// //// - gorban@opencores.org //// //// - Jacob Gorban //// //// - Igor Mohor (igorm@opencores.org) //// //// //// //// Created: 2001/05/12 //// //// Last Updated: 2002/07/22 //// //// (See log for the revision history) //// //// //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2000, 2001 Authors //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// // // CVS Revision History // // $Log: not supported by cvs2svn $ // Revision 1.3 2003/06/11 16:37:47 gorban // This fixes errors in some cases when data is being read and put to the FIFO at the same time. Patch is submitted by Scott Furman. Update is very recommended. // // Revision 1.2 2002/07/29 21:16:18 gorban // The uart_defines.v file is included again in sources. // // Revision 1.1 2002/07/22 23:02:23 gorban // Bug Fixes: // * Possible loss of sync and bad reception of stop bit on slow baud rates fixed. // Problem reported by Kenny.Tung. // * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers. // // Improvements: // * Made FIFO's as general inferrable memory where possible. // So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx). // This saves about 1/3 of the Slice count and reduces P&R and synthesis times. // // * Added optional baudrate output (baud_o). // This is identical to BAUDOUT* signal on 16550 chip. // It outputs 16xbit_clock_rate - the divided clock. // It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use. // // Revision 1.16 2001/12/20 13:25:46 mohor // rx push changed to be only one cycle wide. // // Revision 1.15 2001/12/18 09:01:07 mohor // Bug that was entered in the last update fixed (rx state machine). // // Revision 1.14 2001/12/17 14:46:48 mohor // overrun signal was moved to separate block because many sequential lsr // reads were preventing data from being written to rx fifo. // underrun signal was not used and was removed from the project. // // Revision 1.13 2001/11/26 21:38:54 gorban // Lots of fixes: // Break condition wasn't handled correctly at all. // LSR bits could lose their values. // LSR value after reset was wrong. // Timing of THRE interrupt signal corrected. // LSR bit 0 timing corrected. // // Revision 1.12 2001/11/08 14:54:23 mohor // Comments in Slovene language deleted, few small fixes for better work of // old tools. IRQs need to be fix. // // Revision 1.11 2001/11/07 17:51:52 gorban // Heavily rewritten interrupt and LSR subsystems. // Many bugs hopefully squashed. // // Revision 1.10 2001/10/20 09:58:40 gorban // Small synopsis fixes // // Revision 1.9 2001/08/24 21:01:12 mohor // Things connected to parity changed. // Clock devider changed. // // Revision 1.8 2001/08/24 08:48:10 mohor // FIFO was not cleared after the data was read bug fixed. // // Revision 1.7 2001/08/23 16:05:05 mohor // Stop bit bug fixed. // Parity bug fixed. // WISHBONE read cycle bug fixed, // OE indicator (Overrun Error) bug fixed. // PE indicator (Parity Error) bug fixed. // Register read bug fixed. // // Revision 1.3 2001/05/31 20:08:01 gorban // FIFO changes and other corrections. // // Revision 1.3 2001/05/27 17:37:48 gorban // Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file. // // Revision 1.2 2001/05/17 18:34:18 gorban // First 'stable' release. Should be sythesizable now. Also added new header. // // Revision 1.0 2001-05-17 21:27:12+02 jacob // Initial revision // // `include "uart_defines.v" module uart_rfifo (clk, wb_rst_i, data_in, data_out, // Control signals push, // push strobe, active high pop, // pop strobe, active high // status signals overrun, count, error_bit, fifo_reset, reset_status ); // FIFO parameters parameter fifo_width = `UART_FIFO_WIDTH; parameter fifo_depth = `UART_FIFO_DEPTH; parameter fifo_pointer_w = `UART_FIFO_POINTER_W; parameter fifo_counter_w = `UART_FIFO_COUNTER_W; input clk; input wb_rst_i; input push; input pop; input [fifo_width-1:0] data_in; input fifo_reset; input reset_status; output [fifo_width-1:0] data_out; output overrun; output [fifo_counter_w-1:0] count; output error_bit; wire [fifo_width-1:0] data_out; wire [7:0] data8_out; // flags FIFO reg [2:0] fifo[fifo_depth-1:0]; // FIFO pointers reg [fifo_pointer_w-1:0] top; reg [fifo_pointer_w-1:0] bottom; reg [fifo_counter_w-1:0] count; reg overrun; wire [fifo_pointer_w-1:0] top_plus_1 = top + 4'h1; raminfr #(fifo_pointer_w,8,fifo_depth) rfifo (.clk(clk), .we(push), .a(top), .dpra(bottom), .di(data_in[fifo_width-1:fifo_width-8]), .dpo(data8_out) ); always @(posedge clk or posedge wb_rst_i) // synchronous FIFO begin if (wb_rst_i) begin top <= 0; bottom <= 0; count <= 0; fifo[0] <= 0; fifo[1] <= 0; fifo[2] <= 0; fifo[3] <= 0; fifo[4] <= 0; fifo[5] <= 0; fifo[6] <= 0; fifo[7] <= 0; fifo[8] <= 0; fifo[9] <= 0; fifo[10] <= 0; fifo[11] <= 0; fifo[12] <= 0; fifo[13] <= 0; fifo[14] <= 0; fifo[15] <= 0; end else if (fifo_reset) begin top <= 0; bottom <= 0; count <= 0; fifo[0] <= 0; fifo[1] <= 0; fifo[2] <= 0; fifo[3] <= 0; fifo[4] <= 0; fifo[5] <= 0; fifo[6] <= 0; fifo[7] <= 0; fifo[8] <= 0; fifo[9] <= 0; fifo[10] <= 0; fifo[11] <= 0; fifo[12] <= 0; fifo[13] <= 0; fifo[14] <= 0; fifo[15] <= 0; end else begin case ({push, pop}) 2'b10 : if (count<fifo_depth) // overrun condition begin top <= top_plus_1; fifo[top] <= data_in[2:0]; count <= count + 5'd1; end 2'b01 : if(count>0) begin fifo[bottom] <= 0; bottom <= bottom + 4'd1; count <= count - 5'd1; end 2'b11 : begin bottom <= bottom + 4'd1; top <= top_plus_1; fifo[top] <= data_in[2:0]; end default: ; endcase end end // always always @(posedge clk or posedge wb_rst_i) // synchronous FIFO begin if (wb_rst_i) overrun <= 1'b0; else if(fifo_reset | reset_status) overrun <= 1'b0; else if(push & ~pop & (count==fifo_depth)) overrun <= 1'b1; end // always // please note though that data_out is only valid one clock after pop signal assign data_out = {data8_out,fifo[bottom]}; // Additional logic for detection of error conditions (parity and framing) inside the FIFO // for the Line Status Register bit 7 wire [2:0] word0 = fifo[0]; wire [2:0] word1 = fifo[1]; wire [2:0] word2 = fifo[2]; wire [2:0] word3 = fifo[3]; wire [2:0] word4 = fifo[4]; wire [2:0] word5 = fifo[5]; wire [2:0] word6 = fifo[6]; wire [2:0] word7 = fifo[7]; wire [2:0] word8 = fifo[8]; wire [2:0] word9 = fifo[9]; wire [2:0] word10 = fifo[10]; wire [2:0] word11 = fifo[11]; wire [2:0] word12 = fifo[12]; wire [2:0] word13 = fifo[13]; wire [2:0] word14 = fifo[14]; wire [2:0] word15 = fifo[15]; // a 1 is returned if any of the error bits in the fifo is 1 assign error_bit = |(word0[2:0] | word1[2:0] | word2[2:0] | word3[2:0] | word4[2:0] | word5[2:0] | word6[2:0] | word7[2:0] | word8[2:0] | word9[2:0] | word10[2:0] | word11[2:0] | word12[2:0] | word13[2:0] | word14[2:0] | word15[2:0] ); endmodule
////////////////////////////////////////////////////////////////////// //// //// //// uart_sync_flops.v //// //// //// //// //// //// This file is part of the "UART 16550 compatible" project //// //// http://www.opencores.org/cores/uart16550/ //// //// //// //// Documentation related to this project: //// //// - http://www.opencores.org/cores/uart16550/ //// //// //// //// Projects compatibility: //// //// - WISHBONE //// //// RS232 Protocol //// //// 16550D uart (mostly supported) //// //// //// //// Overview (main Features): //// //// UART core receiver logic //// //// //// //// Known problems (limits): //// //// None known //// //// //// //// To Do: //// //// Thourough testing. //// //// //// //// Author(s): //// //// - Andrej Erzen (andreje@flextronics.si) //// //// - Tadej Markovic (tadejm@flextronics.si) //// //// //// //// Created: 2004/05/20 //// //// Last Updated: 2004/05/20 //// //// (See log for the revision history) //// //// //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2000, 2001 Authors //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// // // CVS Revision History // // $Log: not supported by cvs2svn $ // module uart_sync_flops ( // internal signals rst_i, clk_i, stage1_rst_i, stage1_clk_en_i, async_dat_i, sync_dat_o ); parameter width = 1; parameter init_value = 1'b0; input rst_i; // reset input input clk_i; // clock input input stage1_rst_i; // synchronous reset for stage 1 FF input stage1_clk_en_i; // synchronous clock enable for stage 1 FF input [width-1:0] async_dat_i; // asynchronous data input output [width-1:0] sync_dat_o; // synchronous data output // // Interal signal declarations // reg [width-1:0] sync_dat_o; reg [width-1:0] flop_0; // first stage always @ (posedge clk_i or posedge rst_i) begin if (rst_i) flop_0 <= {width{init_value}}; else flop_0 <= async_dat_i; end // second stage always @ (posedge clk_i or posedge rst_i) begin if (rst_i) sync_dat_o <= {width{init_value}}; else if (stage1_rst_i) sync_dat_o <= {width{init_value}}; else if (stage1_clk_en_i) sync_dat_o <= flop_0; end endmodule
////////////////////////////////////////////////////////////////////// //// //// //// uart_tfifo.v //// //// //// //// //// //// This file is part of the "UART 16550 compatible" project //// //// http://www.opencores.org/cores/uart16550/ //// //// //// //// Documentation related to this project: //// //// - http://www.opencores.org/cores/uart16550/ //// //// //// //// Projects compatibility: //// //// - WISHBONE //// //// RS232 Protocol //// //// 16550D uart (mostly supported) //// //// //// //// Overview (main Features): //// //// UART core transmitter FIFO //// //// //// //// To Do: //// //// Nothing. //// //// //// //// Author(s): //// //// - gorban@opencores.org //// //// - Jacob Gorban //// //// - Igor Mohor (igorm@opencores.org) //// //// //// //// Created: 2001/05/12 //// //// Last Updated: 2002/07/22 //// //// (See log for the revision history) //// //// //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2000, 2001 Authors //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// // // CVS Revision History // // $Log: not supported by cvs2svn $ // Revision 1.1 2002/07/22 23:02:23 gorban // Bug Fixes: // * Possible loss of sync and bad reception of stop bit on slow baud rates fixed. // Problem reported by Kenny.Tung. // * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers. // // Improvements: // * Made FIFO's as general inferrable memory where possible. // So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx). // This saves about 1/3 of the Slice count and reduces P&R and synthesis times. // // * Added optional baudrate output (baud_o). // This is identical to BAUDOUT* signal on 16550 chip. // It outputs 16xbit_clock_rate - the divided clock. // It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use. // // Revision 1.16 2001/12/20 13:25:46 mohor // rx push changed to be only one cycle wide. // // Revision 1.15 2001/12/18 09:01:07 mohor // Bug that was entered in the last update fixed (rx state machine). // // Revision 1.14 2001/12/17 14:46:48 mohor // overrun signal was moved to separate block because many sequential lsr // reads were preventing data from being written to rx fifo. // underrun signal was not used and was removed from the project. // // Revision 1.13 2001/11/26 21:38:54 gorban // Lots of fixes: // Break condition wasn't handled correctly at all. // LSR bits could lose their values. // LSR value after reset was wrong. // Timing of THRE interrupt signal corrected. // LSR bit 0 timing corrected. // // Revision 1.12 2001/11/08 14:54:23 mohor // Comments in Slovene language deleted, few small fixes for better work of // old tools. IRQs need to be fix. // // Revision 1.11 2001/11/07 17:51:52 gorban // Heavily rewritten interrupt and LSR subsystems. // Many bugs hopefully squashed. // // Revision 1.10 2001/10/20 09:58:40 gorban // Small synopsis fixes // // Revision 1.9 2001/08/24 21:01:12 mohor // Things connected to parity changed. // Clock devider changed. // // Revision 1.8 2001/08/24 08:48:10 mohor // FIFO was not cleared after the data was read bug fixed. // // Revision 1.7 2001/08/23 16:05:05 mohor // Stop bit bug fixed. // Parity bug fixed. // WISHBONE read cycle bug fixed, // OE indicator (Overrun Error) bug fixed. // PE indicator (Parity Error) bug fixed. // Register read bug fixed. // // Revision 1.3 2001/05/31 20:08:01 gorban // FIFO changes and other corrections. // // Revision 1.3 2001/05/27 17:37:48 gorban // Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file. // // Revision 1.2 2001/05/17 18:34:18 gorban // First 'stable' release. Should be sythesizable now. Also added new header. // // Revision 1.0 2001-05-17 21:27:12+02 jacob // Initial revision // // `include "uart_defines.v" module uart_tfifo (clk, wb_rst_i, data_in, data_out, // Control signals push, // push strobe, active high pop, // pop strobe, active high // status signals overrun, count, fifo_reset, reset_status ); // FIFO parameters parameter fifo_width = `UART_FIFO_WIDTH; parameter fifo_depth = `UART_FIFO_DEPTH; parameter fifo_pointer_w = `UART_FIFO_POINTER_W; parameter fifo_counter_w = `UART_FIFO_COUNTER_W; input clk; input wb_rst_i; input push; input pop; input [fifo_width-1:0] data_in; input fifo_reset; input reset_status; output [fifo_width-1:0] data_out; output overrun; output [fifo_counter_w-1:0] count; wire [fifo_width-1:0] data_out; // FIFO pointers reg [fifo_pointer_w-1:0] top; reg [fifo_pointer_w-1:0] bottom; reg [fifo_counter_w-1:0] count; reg overrun; wire [fifo_pointer_w-1:0] top_plus_1 = top + 4'd1; raminfr #(fifo_pointer_w,fifo_width,fifo_depth) tfifo (.clk(clk), .we(push), .a(top), .dpra(bottom), .di(data_in), .dpo(data_out) ); always @(posedge clk or posedge wb_rst_i) // synchronous FIFO begin if (wb_rst_i) begin top <= 0; bottom <= 0; count <= 0; end else if (fifo_reset) begin top <= 0; bottom <= 0; count <= 0; end else begin case ({push, pop}) 2'b10 : if (count<fifo_depth) // overrun condition begin top <= top_plus_1; count <= count + 5'd1; end 2'b01 : if(count>0) begin bottom <= bottom + 4'd1; count <= count - 5'd1; end 2'b11 : begin bottom <= bottom + 4'd1; top <= top_plus_1; end default: ; endcase end end // always always @(posedge clk or posedge wb_rst_i) // synchronous FIFO begin if (wb_rst_i) overrun <= 1'b0; else if(fifo_reset | reset_status) overrun <= 1'b0; else if(push & (count==fifo_depth)) overrun <= 1'b1; end // always endmodule
////////////////////////////////////////////////////////////////////// //// //// //// uart_top.v //// //// //// //// //// //// This file is part of the "UART 16550 compatible" project //// //// http://www.opencores.org/cores/uart16550/ //// //// //// //// Documentation related to this project: //// //// - http://www.opencores.org/cores/uart16550/ //// //// //// //// Projects compatibility: //// //// - WISHBONE //// //// RS232 Protocol //// //// 16550D uart (mostly supported) //// //// //// //// Overview (main Features): //// //// UART core top level. //// //// //// //// Known problems (limits): //// //// Note that transmitter and receiver instances are inside //// //// the uart_regs.v file. //// //// //// //// To Do: //// //// Nothing so far. //// //// //// //// Author(s): //// //// - gorban@opencores.org //// //// - Jacob Gorban //// //// - Igor Mohor (igorm@opencores.org) //// //// //// //// Created: 2001/05/12 //// //// Last Updated: 2001/05/17 //// //// (See log for the revision history) //// //// //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2000, 2001 Authors //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// // // CVS Revision History // // $Log: not supported by cvs2svn $ // Revision 1.18 2002/07/22 23:02:23 gorban // Bug Fixes: // * Possible loss of sync and bad reception of stop bit on slow baud rates fixed. // Problem reported by Kenny.Tung. // * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers. // // Improvements: // * Made FIFO's as general inferrable memory where possible. // So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx). // This saves about 1/3 of the Slice count and reduces P&R and synthesis times. // // * Added optional baudrate output (baud_o). // This is identical to BAUDOUT* signal on 16550 chip. // It outputs 16xbit_clock_rate - the divided clock. // It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use. // // Revision 1.17 2001/12/19 08:40:03 mohor // Warnings fixed (unused signals removed). // // Revision 1.16 2001/12/06 14:51:04 gorban // Bug in LSR[0] is fixed. // All WISHBONE signals are now sampled, so another wait-state is introduced on all transfers. // // Revision 1.15 2001/12/03 21:44:29 gorban // Updated specification documentation. // Added full 32-bit data bus interface, now as default. // Address is 5-bit wide in 32-bit data bus mode. // Added wb_sel_i input to the core. It's used in the 32-bit mode. // Added debug interface with two 32-bit read-only registers in 32-bit mode. // Bits 5 and 6 of LSR are now only cleared on TX FIFO write. // My small test bench is modified to work with 32-bit mode. // // Revision 1.14 2001/11/07 17:51:52 gorban // Heavily rewritten interrupt and LSR subsystems. // Many bugs hopefully squashed. // // Revision 1.13 2001/10/20 09:58:40 gorban // Small synopsis fixes // // Revision 1.12 2001/08/25 15:46:19 gorban // Modified port names again // // Revision 1.11 2001/08/24 21:01:12 mohor // Things connected to parity changed. // Clock devider changed. // // Revision 1.10 2001/08/23 16:05:05 mohor // Stop bit bug fixed. // Parity bug fixed. // WISHBONE read cycle bug fixed, // OE indicator (Overrun Error) bug fixed. // PE indicator (Parity Error) bug fixed. // Register read bug fixed. // // Revision 1.4 2001/05/31 20:08:01 gorban // FIFO changes and other corrections. // // Revision 1.3 2001/05/21 19:12:02 gorban // Corrected some Linter messages. // // Revision 1.2 2001/05/17 18:34:18 gorban // First 'stable' release. Should be sythesizable now. Also added new header. // // Revision 1.0 2001-05-17 21:27:12+02 jacob // Initial revision // // `include "uart_defines.v" module uart_top ( wb_clk_i, // Wishbone signals wb_rst_i, wb_adr_i, wb_dat_i, wb_dat_o, wb_we_i, wb_stb_i, wb_cyc_i, wb_err_o, wb_ack_o, wb_sel_i, int_o, // interrupt request // UART signals // serial input/output stx_pad_o, srx_pad_i, // modem signals rts_pad_o, cts_pad_i, dtr_pad_o, dsr_pad_i, ri_pad_i, dcd_pad_i `ifdef UART_HAS_BAUDRATE_OUTPUT , baud_o `endif ); parameter SIM = 0; parameter debug = 0; input wb_clk_i; // WISHBONE interface input wb_rst_i; input [2:0] wb_adr_i; input [7:0] wb_dat_i; output [7:0] wb_dat_o; input wb_we_i; input wb_stb_i; input wb_cyc_i; input [3:0] wb_sel_i; output wb_err_o; output wb_ack_o; output int_o; // UART signals input srx_pad_i; output stx_pad_o; output rts_pad_o; input cts_pad_i; output dtr_pad_o; input dsr_pad_i; input ri_pad_i; input dcd_pad_i; // optional baudrate output `ifdef UART_HAS_BAUDRATE_OUTPUT output baud_o; `endif wire stx_pad_o; wire rts_pad_o; wire dtr_pad_o; wire [2:0] wb_adr_i; wire [7:0] wb_dat_i; wire [7:0] wb_dat_o; wire [7:0] wb_dat8_i; // 8-bit internal data input wire [7:0] wb_dat8_o; // 8-bit internal data output wire [3:0] wb_sel_i; // WISHBONE select signal wire [2:0] wb_adr_int; wire we_o; // Write enable for registers wire re_o; // Read enable for registers // // MODULE INSTANCES // assign wb_err_o = 1'b0; //// WISHBONE interface module uart_wb uart_wb_inst ( .clk( wb_clk_i ), .wb_rst_i( wb_rst_i ), .wb_dat_i(wb_dat_i), .wb_dat_o(wb_dat_o), .wb_dat8_i(wb_dat8_i), .wb_dat8_o(wb_dat8_o), .wb_dat32_o(32'b0), .wb_sel_i(4'b0), .wb_we_i( wb_we_i ), .wb_stb_i( wb_stb_i ), .wb_cyc_i( wb_cyc_i ), .wb_ack_o( wb_ack_o ), .wb_adr_i(wb_adr_i), .wb_adr_int(wb_adr_int), .we_o( we_o ), .re_o(re_o) ); // Registers uart_regs #(.SIM (SIM)) uart_regs_inst ( .clk( wb_clk_i ), .wb_rst_i( wb_rst_i ), .wb_addr_i( wb_adr_int ), .wb_dat_i( wb_dat8_i ), .wb_dat_o( wb_dat8_o ), .wb_we_i( we_o ), .wb_re_i(re_o), .modem_inputs( {cts_pad_i, dsr_pad_i, ri_pad_i, dcd_pad_i} ), .stx_pad_o( stx_pad_o ), .srx_pad_i( srx_pad_i ), .rts_pad_o( rts_pad_o ), .dtr_pad_o( dtr_pad_o ), .int_o( int_o ) `ifdef UART_HAS_BAUDRATE_OUTPUT , .baud_o(baud_o) `endif ); initial begin if(debug) begin `ifdef UART_HAS_BAUDRATE_OUTPUT $display("(%m) UART INFO: Has baudrate output\n"); `else $display("(%m) UART INFO: Doesn't have baudrate output\n"); `endif end end endmodule
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : uart_top_axi4lite.sv // Project : Common Evaluation Platform (CEP) // Description : This file provides an axi4-lite wrapper for the wishbone based-UART core // module uart_top_axi4lite ( // Clock & Reset input logic clk_i, input logic rst_ni, // AXI4-Lite Slave Interface AXI_LITE.Slave slave, // UART signals input logic srx_pad_i, output logic stx_pad_o, output logic rts_pad_o, input logic cts_pad_i, output logic dtr_pad_o, input logic dsr_pad_i, input logic ri_pad_i, input logic dcd_pad_i, // Processor Interrupt output logic int_o ); // If not currently targeting synthesis, override the SIM parameter for UART0 `ifndef SYNTHESIS defparam uart_top_inst.SIM = 1'b1; `endif // UART wishbone slave wires wire wb_clk; wire wb_rst; wire wb_rst_n; wire [slave.AXI_ADDR_WIDTH - 1:0] wbs_d_uart_adr_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_uart_dat_i; wire wbs_d_uart_we_i; wire wbs_d_uart_cyc_i; wire wbs_d_uart_stb_i; wire [slave.AXI_DATA_WIDTH - 1:0] wbs_d_uart_dat_o; wire wbs_d_uart_ack_o; // Instantiate the AXI4Lite to Wishbone bridge bonfire_axi4l2wb #( .ADRWIDTH (slave.AXI_ADDR_WIDTH), .FAST_READ_TERM (1'd0) ) bonfire_axi4l2wb_inst ( .S_AXI_ACLK (clk_i), .S_AXI_ARESETN (rst_ni), .S_AXI_AWADDR (slave.aw_addr), .S_AXI_AWVALID (slave.aw_valid), .S_AXI_AWREADY (slave.aw_ready), .S_AXI_WDATA (slave.w_data), .S_AXI_WSTRB (slave.w_strb), .S_AXI_WVALID (slave.w_valid), .S_AXI_WREADY (slave.w_ready), .S_AXI_ARADDR (slave.ar_addr), .S_AXI_ARVALID (slave.ar_valid), .S_AXI_ARREADY (slave.ar_ready), .S_AXI_RDATA (slave.r_data), .S_AXI_RRESP (slave.r_resp), .S_AXI_RVALID (slave.r_valid), .S_AXI_RREADY (slave.r_ready), .S_AXI_BRESP (slave.b_resp), .S_AXI_BVALID (slave.b_valid), .S_AXI_BREADY (slave.b_ready), .wb_clk_o (wb_clk), .wb_rst_o (wb_rst), .wb_addr_o (wbs_d_uart_adr_i), .wb_dat_o (wbs_d_uart_dat_i), .wb_we_o (wbs_d_uart_we_i), .wb_sel_o (), .wb_stb_o (wbs_d_uart_stb_i), .wb_cyc_o (wbs_d_uart_cyc_i), .wb_dat_i (wbs_d_uart_dat_o), .wb_ack_i (wbs_d_uart_ack_o) ); // Instantiate the wishbone-based UART assign wbs_d_uart_dat_o[31:24] = 8'd0; assign wbs_d_uart_dat_o[15:0] = 16'd0; uart_top uart_top_inst ( // Wishbone Slave interface .wb_clk_i (wb_clk), .wb_rst_i (wb_rst), .wb_adr_i (wbs_d_uart_adr_i[2:0]), .wb_dat_i (wbs_d_uart_dat_i[23:16]), .wb_we_i (wbs_d_uart_we_i), .wb_stb_i (wbs_d_uart_stb_i), .wb_cyc_i (wbs_d_uart_cyc_i), .wb_sel_i (4'hF), .wb_dat_o (wbs_d_uart_dat_o[23:16]), .wb_ack_o (wbs_d_uart_ack_o), .wb_err_o (), // UART Signals .srx_pad_i (srx_pad_i), .stx_pad_o (stx_pad_o), .rts_pad_o (rts_pad_o), .cts_pad_i (cts_pad_i), .dtr_pad_o (dtr_pad_o), .dsr_pad_i (dsr_pad_i), .ri_pad_i (ri_pad_i), .dcd_pad_i (dcd_pad_i), // Processor interrupt .int_o (int_o) ); endmodule // end aes_top_axi4lite
////////////////////////////////////////////////////////////////////// //// //// //// uart_transmitter.v //// //// //// //// //// //// This file is part of the "UART 16550 compatible" project //// //// http://www.opencores.org/cores/uart16550/ //// //// //// //// Documentation related to this project: //// //// - http://www.opencores.org/cores/uart16550/ //// //// //// //// Projects compatibility: //// //// - WISHBONE //// //// RS232 Protocol //// //// 16550D uart (mostly supported) //// //// //// //// Overview (main Features): //// //// UART core transmitter logic //// //// //// //// Known problems (limits): //// //// None known //// //// //// //// To Do: //// //// Thourough testing. //// //// //// //// Author(s): //// //// - gorban@opencores.org //// //// - Jacob Gorban //// //// - Igor Mohor (igorm@opencores.org) //// //// //// //// Created: 2001/05/12 //// //// Last Updated: 2001/05/17 //// //// (See log for the revision history) //// //// //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2000, 2001 Authors //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// // // CVS Revision History // // $Log: not supported by cvs2svn $ // Revision 1.18 2002/07/22 23:02:23 gorban // Bug Fixes: // * Possible loss of sync and bad reception of stop bit on slow baud rates fixed. // Problem reported by Kenny.Tung. // * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers. // // Improvements: // * Made FIFO's as general inferrable memory where possible. // So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx). // This saves about 1/3 of the Slice count and reduces P&R and synthesis times. // // * Added optional baudrate output (baud_o). // This is identical to BAUDOUT* signal on 16550 chip. // It outputs 16xbit_clock_rate - the divided clock. // It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use. // // Revision 1.16 2002/01/08 11:29:40 mohor // tf_pop was too wide. Now it is only 1 clk cycle width. // // Revision 1.15 2001/12/17 14:46:48 mohor // overrun signal was moved to separate block because many sequential lsr // reads were preventing data from being written to rx fifo. // underrun signal was not used and was removed from the project. // // Revision 1.14 2001/12/03 21:44:29 gorban // Updated specification documentation. // Added full 32-bit data bus interface, now as default. // Address is 5-bit wide in 32-bit data bus mode. // Added wb_sel_i input to the core. It's used in the 32-bit mode. // Added debug interface with two 32-bit read-only registers in 32-bit mode. // Bits 5 and 6 of LSR are now only cleared on TX FIFO write. // My small test bench is modified to work with 32-bit mode. // // Revision 1.13 2001/11/08 14:54:23 mohor // Comments in Slovene language deleted, few small fixes for better work of // old tools. IRQs need to be fix. // // Revision 1.12 2001/11/07 17:51:52 gorban // Heavily rewritten interrupt and LSR subsystems. // Many bugs hopefully squashed. // // Revision 1.11 2001/10/29 17:00:46 gorban // fixed parity sending and tx_fifo resets over- and underrun // // Revision 1.10 2001/10/20 09:58:40 gorban // Small synopsis fixes // // Revision 1.9 2001/08/24 21:01:12 mohor // Things connected to parity changed. // Clock devider changed. // // Revision 1.8 2001/08/23 16:05:05 mohor // Stop bit bug fixed. // Parity bug fixed. // WISHBONE read cycle bug fixed, // OE indicator (Overrun Error) bug fixed. // PE indicator (Parity Error) bug fixed. // Register read bug fixed. // // Revision 1.6 2001/06/23 11:21:48 gorban // DL made 16-bit long. Fixed transmission/reception bugs. // // Revision 1.5 2001/06/02 14:28:14 gorban // Fixed receiver and transmitter. Major bug fixed. // // Revision 1.4 2001/05/31 20:08:01 gorban // FIFO changes and other corrections. // // Revision 1.3 2001/05/27 17:37:49 gorban // Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file. // // Revision 1.2 2001/05/21 19:12:02 gorban // Corrected some Linter messages. // // Revision 1.1 2001/05/17 18:34:18 gorban // First 'stable' release. Should be sythesizable now. Also added new header. // // Revision 1.0 2001-05-17 21:27:12+02 jacob // Initial revision // // `include "uart_defines.v" module uart_transmitter #(parameter SIM = 0) (clk, wb_rst_i, lcr, tf_push, wb_dat_i, enable, stx_pad_o, tstate, tf_count, tx_reset, lsr_mask); input clk; input wb_rst_i; input [7:0] lcr; input tf_push; input [7:0] wb_dat_i; input enable; input tx_reset; input lsr_mask; //reset of fifo output stx_pad_o; output [2:0] tstate; output [`UART_FIFO_COUNTER_W-1:0] tf_count; reg [2:0] tstate; reg [4:0] counter; reg [2:0] bit_counter; // counts the bits to be sent reg [6:0] shift_out; // output shift register reg stx_o_tmp; reg parity_xor; // parity of the word reg tf_pop; reg bit_out; // TX FIFO instance // // Transmitter FIFO signals wire [`UART_FIFO_WIDTH-1:0] tf_data_in; wire [`UART_FIFO_WIDTH-1:0] tf_data_out; wire tf_push; wire tf_overrun; wire [`UART_FIFO_COUNTER_W-1:0] tf_count; assign tf_data_in = wb_dat_i; uart_tfifo fifo_tx( // error bit signal is not used in transmitter FIFO .clk( clk ), .wb_rst_i( wb_rst_i ), .data_in( tf_data_in ), .data_out( tf_data_out ), .push( tf_push ), .pop( tf_pop ), .overrun( tf_overrun ), .count( tf_count ), .fifo_reset( tx_reset ), .reset_status(lsr_mask) ); // TRANSMITTER FINAL STATE MACHINE localparam s_idle = 3'd0; localparam s_send_start = 3'd1; localparam s_send_byte = 3'd2; localparam s_send_parity = 3'd3; localparam s_send_stop = 3'd4; localparam s_pop_byte = 3'd5; always @(posedge clk or posedge wb_rst_i) begin if (wb_rst_i) begin tstate <= s_idle; stx_o_tmp <= 1'b1; counter <= 5'b0; shift_out <= 7'b0; bit_out <= 1'b0; parity_xor <= 1'b0; tf_pop <= 1'b0; bit_counter <= 3'b0; end else if (enable | SIM) begin case (tstate) s_idle : if (~|tf_count) // if tf_count==0 begin tstate <= s_idle; stx_o_tmp <= 1'b1; end else begin tf_pop <= 1'b0; stx_o_tmp <= 1'b1; tstate <= s_pop_byte; end s_pop_byte : begin tf_pop <= 1'b1; case (lcr[/*`UART_LC_BITS*/1:0]) // number of bits in a word 2'b00 : begin bit_counter <= 3'b100; parity_xor <= ^tf_data_out[4:0]; end 2'b01 : begin bit_counter <= 3'b101; parity_xor <= ^tf_data_out[5:0]; end 2'b10 : begin bit_counter <= 3'b110; parity_xor <= ^tf_data_out[6:0]; end 2'b11 : begin bit_counter <= 3'b111; parity_xor <= ^tf_data_out[7:0]; end endcase {shift_out[6:0], bit_out} <= tf_data_out; tstate <= s_send_start; end s_send_start : begin tf_pop <= 1'b0; if (~|counter) counter <= 5'b01111; else if (counter == 5'b00001) begin counter <= 0; tstate <= s_send_byte; end else counter <= counter - 5'd1; stx_o_tmp <= 1'b0; if (SIM) begin tstate <= s_idle; $write("%c", tf_data_out); $fflush(32'h80000001); end end s_send_byte : begin if (~|counter) counter <= 5'b01111; else if (counter == 5'b00001) begin if (bit_counter > 3'b0) begin bit_counter <= bit_counter - 3'd1; {shift_out[5:0],bit_out } <= {shift_out[6:1], shift_out[0]}; tstate <= s_send_byte; end else // end of byte if (~lcr[`UART_LC_PE]) begin tstate <= s_send_stop; end else begin case ({lcr[`UART_LC_EP],lcr[`UART_LC_SP]}) 2'b00: bit_out <= ~parity_xor; 2'b01: bit_out <= 1'b1; 2'b10: bit_out <= parity_xor; 2'b11: bit_out <= 1'b0; endcase tstate <= s_send_parity; end counter <= 0; end else counter <= counter - 5'd1; stx_o_tmp <= bit_out; // set output pin end s_send_parity : begin if (~|counter) counter <= 5'b01111; else if (counter == 5'b00001) begin counter <= 5'd0; tstate <= s_send_stop; end else counter <= counter - 5'd1; stx_o_tmp <= bit_out; end s_send_stop : begin if (~|counter) begin casez ({lcr[`UART_LC_SB],lcr[`UART_LC_BITS]}) 3'b0??: counter <= 5'b01101; // 1 stop bit ok igor 3'b100: counter <= 5'b10101; // 1.5 stop bit default: counter <= 5'b11101; // 2 stop bits endcase end else if (counter == 5'b00001) begin counter <= 0; tstate <= s_idle; end else counter <= counter - 5'd1; stx_o_tmp <= 1'b1; end default : // should never get here tstate <= s_idle; endcase end // end if enable else tf_pop <= 1'b0; // tf_pop must be 1 cycle width end // transmitter logic assign stx_pad_o = lcr[`UART_LC_BC] ? 1'b0 : stx_o_tmp; // Break condition endmodule
////////////////////////////////////////////////////////////////////// //// //// //// uart_wb.v //// //// //// //// //// //// This file is part of the "UART 16550 compatible" project //// //// http://www.opencores.org/cores/uart16550/ //// //// //// //// Documentation related to this project: //// //// - http://www.opencores.org/cores/uart16550/ //// //// //// //// Projects compatibility: //// //// - WISHBONE //// //// RS232 Protocol //// //// 16550D uart (mostly supported) //// //// //// //// Overview (main Features): //// //// UART core WISHBONE interface. //// //// //// //// Known problems (limits): //// //// Inserts one wait state on all transfers. //// //// Note affected signals and the way they are affected. //// //// //// //// To Do: //// //// Nothing. //// //// //// //// Author(s): //// //// - gorban@opencores.org //// //// - Jacob Gorban //// //// - Igor Mohor (igorm@opencores.org) //// //// //// //// Created: 2001/05/12 //// //// Last Updated: 2001/05/17 //// //// (See log for the revision history) //// //// //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2000, 2001 Authors //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// // // CVS Revision History // // $Log: not supported by cvs2svn $ // Revision 1.16 2002/07/29 21:16:18 gorban // The uart_defines.v file is included again in sources. // // Revision 1.15 2002/07/22 23:02:23 gorban // Bug Fixes: // * Possible loss of sync and bad reception of stop bit on slow baud rates fixed. // Problem reported by Kenny.Tung. // * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers. // // Improvements: // * Made FIFO's as general inferrable memory where possible. // So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx). // This saves about 1/3 of the Slice count and reduces P&R and synthesis times. // // * Added optional baudrate output (baud_o). // This is identical to BAUDOUT* signal on 16550 chip. // It outputs 16xbit_clock_rate - the divided clock. // It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use. // // Revision 1.12 2001/12/19 08:03:34 mohor // Warnings cleared. // // Revision 1.11 2001/12/06 14:51:04 gorban // Bug in LSR[0] is fixed. // All WISHBONE signals are now sampled, so another wait-state is introduced on all transfers. // // Revision 1.10 2001/12/03 21:44:29 gorban // Updated specification documentation. // Added full 32-bit data bus interface, now as default. // Address is 5-bit wide in 32-bit data bus mode. // Added wb_sel_i input to the core. It's used in the 32-bit mode. // Added debug interface with two 32-bit read-only registers in 32-bit mode. // Bits 5 and 6 of LSR are now only cleared on TX FIFO write. // My small test bench is modified to work with 32-bit mode. // // Revision 1.9 2001/10/20 09:58:40 gorban // Small synopsis fixes // // Revision 1.8 2001/08/24 21:01:12 mohor // Things connected to parity changed. // Clock devider changed. // // Revision 1.7 2001/08/23 16:05:05 mohor // Stop bit bug fixed. // Parity bug fixed. // WISHBONE read cycle bug fixed, // OE indicator (Overrun Error) bug fixed. // PE indicator (Parity Error) bug fixed. // Register read bug fixed. // // Revision 1.4 2001/05/31 20:08:01 gorban // FIFO changes and other corrections. // // Revision 1.3 2001/05/21 19:12:01 gorban // Corrected some Linter messages. // // Revision 1.2 2001/05/17 18:34:18 gorban // First 'stable' release. Should be sythesizable now. Also added new header. // // Revision 1.0 2001-05-17 21:27:13+02 jacob // Initial revision // // // UART core WISHBONE interface // // Author: Jacob Gorban (jacob.gorban@flextronicssemi.com) // Company: Flextronics Semiconductor // `include "uart_defines.v" module uart_wb (clk, wb_rst_i, wb_we_i, wb_stb_i, wb_cyc_i, wb_ack_o, wb_adr_i, wb_adr_int, wb_dat_i, wb_dat_o, wb_dat8_i, wb_dat8_o, wb_dat32_o, wb_sel_i, we_o, re_o // Write and read enable output for the core ); input clk; // WISHBONE interface input wb_rst_i; input wb_we_i; input wb_stb_i; input wb_cyc_i; input [3:0] wb_sel_i; input [2:0] wb_adr_i; //WISHBONE address line input [7:0] wb_dat_i; //input WISHBONE bus output [7:0] wb_dat_o; reg [7:0] wb_dat_o; wire [7:0] wb_dat_i; reg [7:0] wb_dat_is; output [2:0] wb_adr_int; // internal signal for address bus input [7:0] wb_dat8_o; // internal 8 bit output to be put into wb_dat_o output [7:0] wb_dat8_i; input [31:0] wb_dat32_o; // 32 bit data output (for debug interface) output wb_ack_o; output we_o; output re_o; wire we_o; reg wb_ack_o; reg [7:0] wb_dat8_i; wire [7:0] wb_dat8_o; wire [2:0] wb_adr_int; // internal signal for address bus reg [2:0] wb_adr_is; reg wb_we_is; reg wb_cyc_is; reg wb_stb_is; wire [3:0] wb_sel_i; reg wre ;// timing control signal for write or read enable // wb_ack_o FSM reg [1:0] wbstate; always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) begin wb_ack_o <= 1'b0; wbstate <= 0; wre <= 1'b1; end else case (wbstate) 0: begin if (wb_stb_is & wb_cyc_is) begin wre <= 0; wbstate <= 1; wb_ack_o <= 1; end else begin wre <= 1; wb_ack_o <= 0; end end 1: begin wb_ack_o <= 0; wbstate <= 2; wre <= 0; end 2: begin wb_ack_o <= 0; wbstate <= 3; wre <= 0; end 3: begin wb_ack_o <= 0; wbstate <= 0; wre <= 1; end endcase assign we_o = wb_we_is & wb_stb_is & wb_cyc_is & wre ; //WE for registers assign re_o = ~wb_we_is & wb_stb_is & wb_cyc_is & wre ; //RE for registers // Sample input signals always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) begin wb_adr_is <= 0; wb_we_is <= 0; wb_cyc_is <= 0; wb_stb_is <= 0; wb_dat_is <= 0; end else begin wb_adr_is <= wb_adr_i; wb_we_is <= wb_we_i; wb_cyc_is <= wb_cyc_i; wb_stb_is <= wb_stb_i; wb_dat_is <= wb_dat_i; end always @(posedge clk or posedge wb_rst_i) if (wb_rst_i) wb_dat_o <= 0; else wb_dat_o <= wb_dat8_o; always @(wb_dat_is) wb_dat8_i = wb_dat_is; assign wb_adr_int = wb_adr_is; endmodule
/* * Copyright 2012, Homer Hsing <homer.hsing@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // assumes input does not change between start going high and out_valid module aes_128(clk, start, state, key, out, out_valid); input clk; input start; input [127:0] state, key; output [127:0] out; output out_valid; reg [127:0] s0, k0; wire [127:0] s1, s2, s3, s4, s5, s6, s7, s8, s9, k1, k2, k3, k4, k5, k6, k7, k8, k9, k0b, k1b, k2b, k3b, k4b, k5b, k6b, k7b, k8b, k9b; reg start_r; always @(posedge clk) begin start_r <= start; end wire start_posedge = start & ~start_r; reg [4:0] validCounter; always @ (posedge clk) begin if(start_posedge) begin s0 <= state ^ key; k0 <= key; validCounter <= 21; end else if(~out_valid) begin validCounter <= validCounter - 1; end end assign out_valid = (validCounter == 0); expand_key_128 a1 (clk, k0, k1, k0b, 8'h1), a2 (clk, k1, k2, k1b, 8'h2), a3 (clk, k2, k3, k2b, 8'h4), a4 (clk, k3, k4, k3b, 8'h8), a5 (clk, k4, k5, k4b, 8'h10), a6 (clk, k5, k6, k5b, 8'h20), a7 (clk, k6, k7, k6b, 8'h40), a8 (clk, k7, k8, k7b, 8'h80), a9 (clk, k8, k9, k8b, 8'h1b), a10 (clk, k9, , k9b, 8'h36); one_round r1 (clk, s0, k0b, s1), r2 (clk, s1, k1b, s2), r3 (clk, s2, k2b, s3), r4 (clk, s3, k3b, s4), r5 (clk, s4, k4b, s5), r6 (clk, s5, k5b, s6), r7 (clk, s6, k6b, s7), r8 (clk, s7, k7b, s8), r9 (clk, s8, k8b, s9); final_round rf (clk, s9, k9b, out); endmodule module expand_key_128(clk, in, out_1, out_2, rcon); input clk; input [127:0] in; input [7:0] rcon; output reg [127:0] out_1; output [127:0] out_2; wire [31:0] k0, k1, k2, k3, v0, v1, v2, v3; reg [31:0] k0a, k1a, k2a, k3a; wire [31:0] k0b, k1b, k2b, k3b, k4a; assign {k0, k1, k2, k3} = in; assign v0 = {k0[31:24] ^ rcon, k0[23:0]}; assign v1 = v0 ^ k1; assign v2 = v1 ^ k2; assign v3 = v2 ^ k3; always @ (posedge clk) {k0a, k1a, k2a, k3a} <= {v0, v1, v2, v3}; S4 S4_0 (clk, {k3[23:0], k3[31:24]}, k4a); assign k0b = k0a ^ k4a; assign k1b = k1a ^ k4a; assign k2b = k2a ^ k4a; assign k3b = k3a ^ k4a; always @ (posedge clk) out_1 <= {k0b, k1b, k2b, k3b}; assign out_2 = {k0b, k1b, k2b, k3b}; endmodule
/* * Copyright 2012, Homer Hsing <homer.hsing@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // This is a fully unrolled implementation module aes_192 (clk, rst, start, state, key, out, out_valid); input clk; input rst; input start; input [127:0] state; input [191:0] key; output [127:0] out; output out_valid; // Internals signals and such reg [127:0] s0; reg [191:0] k0; wire [127:0] s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11; wire [191:0] k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11; wire [127:0] k0b, k1b, k2b, k3b, k4b, k5b, k6b, k7b, k8b, k9b, k10b, k11b; reg start_r; wire start_posedge = start & ~start_r; reg [4:0] validCounter; always @(posedge clk or posedge rst) begin if (rst) start_r <= 1'b0; else start_r <= start; end // end always always @ (posedge clk or posedge rst) begin if (rst) begin s0 <= 0; k0 <= 0; validCounter <= 0; end else if(start_posedge) begin s0 <= state ^ key[191:64]; k0 <= key; validCounter <= 26; end else if(validCounter > 1) begin validCounter <= validCounter - 1; end end // end always assign out_valid = (validCounter == 1); expand_key_type_D_192 a0 (clk, rst, k0, 8'h1, k1, k0b); expand_key_type_B_192 a1 (clk, rst, k1, k2, k1b); expand_key_type_A_192 a2 (clk, rst, k2, 8'h2, k3, k2b); expand_key_type_C_192 a3 (clk, rst, k3, 8'h4, k4, k3b); expand_key_type_B_192 a4 (clk, rst, k4, k5, k4b); expand_key_type_A_192 a5 (clk, rst, k5, 8'h8, k6, k5b); expand_key_type_C_192 a6 (clk, rst, k6, 8'h10, k7, k6b); expand_key_type_B_192 a7 (clk, rst, k7, k8, k7b); expand_key_type_A_192 a8 (clk, rst, k8, 8'h20, k9, k8b); expand_key_type_C_192 a9 (clk, rst, k9, 8'h40, k10, k9b); expand_key_type_B_192 a10 (clk, rst, k10, k11, k10b); expand_key_type_A_192 a11 (clk, rst, k11, 8'h80, , k11b); one_round r1 (clk, rst, s0, k0b, s1), r2 (clk, rst, s1, k1b, s2), r3 (clk, rst, s2, k2b, s3), r4 (clk, rst, s3, k3b, s4), r5 (clk, rst, s4, k4b, s5), r6 (clk, rst, s5, k5b, s6), r7 (clk, rst, s6, k6b, s7), r8 (clk, rst, s7, k7b, s8), r9 (clk, rst, s8, k8b, s9), r10 (clk, rst, s9, k9b, s10), r11 (clk, rst, s10, k10b, s11); final_round rf (clk, rst, s11, k11b, out); endmodule /* expand k0,k1,k2,k3 for every two clock cycles */ module expand_key_type_A_192 (clk, rst, in, rcon, out_1, out_2); input clk; input rst; input [191:0] in; input [7:0] rcon; output reg [191:0] out_1; output [127:0] out_2; // Internal signals wire [31:0] k0, k1, k2, k3, k4, k5, v0, v1, v2, v3; reg [31:0] k0a, k1a, k2a, k3a, k4a, k5a; wire [31:0] k0b, k1b, k2b, k3b, k4b, k5b, k6a; assign {k0, k1, k2, k3, k4, k5} = in; assign v0 = {k0[31:24] ^ rcon, k0[23:0]}; assign v1 = v0 ^ k1; assign v2 = v1 ^ k2; assign v3 = v2 ^ k3; always @ (posedge clk or posedge rst) begin if (rst) {k0a, k1a, k2a, k3a, k4a, k5a} <= {32'd0, 32'd0, 32'd0, 32'd0, 32'd0, 32'd0}; else {k0a, k1a, k2a, k3a, k4a, k5a} <= {v0, v1, v2, v3, k4, k5}; end // end always S4 S4_0 (clk, rst, {k5[23:0], k5[31:24]}, k6a); assign k0b = k0a ^ k6a; assign k1b = k1a ^ k6a; assign k2b = k2a ^ k6a; assign k3b = k3a ^ k6a; assign {k4b, k5b} = {k4a, k5a}; always @ (posedge clk or posedge rst) begin if (rst) out_1 <= 0; else out_1 <= {k0b, k1b, k2b, k3b, k4b, k5b}; end // end always assign out_2 = {k0b, k1b, k2b, k3b}; endmodule // end module expand_key_type_A_192 /* expand k2,k3,k4,k5 for every two clock cycles */ module expand_key_type_B_192 (clk, rst, in, out_1, out_2); input clk; input rst; input [191:0] in; output reg [191:0] out_1; output [127:0] out_2; wire [31:0] k0, k1, k2, k3, k4, k5, v2, v3, v4, v5; reg [31:0] k0a, k1a, k2a, k3a, k4a, k5a; assign {k0, k1, k2, k3, k4, k5} = in; assign v2 = k1 ^ k2; assign v3 = v2 ^ k3; assign v4 = v3 ^ k4; assign v5 = v4 ^ k5; always @ (posedge clk or posedge rst) begin if (rst) {k0a, k1a, k2a, k3a, k4a, k5a} <= {32'd0, 32'd0, 32'd0, 32'd0, 32'd0, 32'd0}; else {k0a, k1a, k2a, k3a, k4a, k5a} <= {k0, k1, v2, v3, v4, v5}; end // end always always @ (posedge clk or posedge rst) begin if (rst) out_1 <= 0; else out_1 <= {k0a, k1a, k2a, k3a, k4a, k5a}; end assign out_2 = {k2a, k3a, k4a, k5a}; endmodule // end expand_key_type_B_192 /* expand k0,k1,k4,k5 for every two clock cycles */ module expand_key_type_C_192 (clk, rst, in, rcon, out_1, out_2); input clk; input rst; input [191:0] in; input [7:0] rcon; output reg [191:0] out_1; output [127:0] out_2; wire [31:0] k0, k1, k2, k3, k4, k5, v4, v5, v0, v1; reg [31:0] k0a, k1a, k2a, k3a, k4a, k5a; wire [31:0] k0b, k1b, k2b, k3b, k4b, k5b, k6a; assign {k0, k1, k2, k3, k4, k5} = in; assign v4 = k3 ^ k4; assign v5 = v4 ^ k5; assign v0 = {k0[31:24] ^ rcon, k0[23:0]}; assign v1 = v0 ^ k1; always @ (posedge clk or posedge rst) begin if (rst) {k0a, k1a, k2a, k3a, k4a, k5a} <= {32'd0, 32'd0, 32'd0, 32'd0, 32'd0, 32'd0}; else {k0a, k1a, k2a, k3a, k4a, k5a} <= {v0, v1, k2, k3, v4, v5}; end S4 S4_0 (clk, rst, {v5[23:0], v5[31:24]}, k6a); assign k0b = k0a ^ k6a; assign k1b = k1a ^ k6a; assign {k2b, k3b, k4b, k5b} = {k2a, k3a, k4a, k5a}; always @ (posedge clk or posedge rst) begin if (rst) out_1 <= 0; else out_1 <= {k0b, k1b, k2b, k3b, k4b, k5b}; end assign out_2 = {k4b, k5b, k0b, k1b}; endmodule // end expand_key_type_C_192 /* expand k0,k1 for every two clock cycles */ module expand_key_type_D_192 (clk, rst, in, rcon, out_1, out_2); input clk; input rst; input [191:0] in; input [7:0] rcon; output reg [191:0] out_1; output [127:0] out_2; wire [31:0] k0, k1, k2, k3, k4, k5, v0, v1; reg [31:0] k0a, k1a, k2a, k3a, k4a, k5a; wire [31:0] k0b, k1b, k2b, k3b, k4b, k5b, k6a; assign {k0, k1, k2, k3, k4, k5} = in; assign v0 = {k0[31:24] ^ rcon, k0[23:0]}; assign v1 = v0 ^ k1; always @ (posedge clk or posedge rst) begin if (rst) {k0a, k1a, k2a, k3a, k4a, k5a} <= {32'd0, 32'd0, 32'd0, 32'd0, 32'd0, 32'd0}; else {k0a, k1a, k2a, k3a, k4a, k5a} <= {v0, v1, k2, k3, k4, k5}; end // end always S4 S4_0 (clk, rst, {k5[23:0], k5[31:24]}, k6a); assign k0b = k0a ^ k6a; assign k1b = k1a ^ k6a; assign {k2b, k3b, k4b, k5b} = {k2a, k3a, k4a, k5a}; always @ (posedge clk or posedge rst) begin if (rst) out_1 <= 0; else out_1 <= {k0b, k1b, k2b, k3b, k4b, k5b}; end // end always assign out_2 = {k4b, k5b, k0b, k1b}; endmodule // end expand_key_type_D_192
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : aes_top.v // Project : Common Evaluation Platform (CEP) // Description : This file provides a wishbone based-AES core // module aes_top( wb_adr_i, wb_cyc_i, wb_dat_i, wb_sel_i, wb_stb_i, wb_we_i, wb_ack_o, wb_err_o, wb_dat_o, wb_clk_i, wb_rst_i, int_o ); parameter dw = 32; parameter aw = 32; input [aw-1:0] wb_adr_i; input wb_cyc_i; input [dw-1:0] wb_dat_i; input [3:0] wb_sel_i; input wb_stb_i; input wb_we_i; output wb_ack_o; output wb_err_o; output reg [dw-1:0] wb_dat_o; output int_o; input wb_clk_i; input wb_rst_i; // As of now, no errors are generated assign wb_err_o = 1'b0; // Interrupt is unused assign int_o = 1'b0; // Internal registers reg start, start_r; reg [31:0] pt [0:3]; reg [31:0] key [0:5]; reg wb_stb_i_r; wire [127:0] pt_big = {pt[0], pt[1], pt[2], pt[3]}; wire [191:0] key_big = {key[0], key[1], key[2], key[3], key[4], key[5]}; wire [127:0] ct; wire ct_valid; // Generate the acknowledgement signal assign wb_ack_o = wb_stb_i_r && wb_stb_i; // Implement MD5 I/O memory map interface // Write side always @(posedge wb_clk_i or negedge wb_rst_i) begin if(wb_rst_i) begin start <= 0; start_r <= 0; pt[0] <= 0; pt[1] <= 0; pt[2] <= 0; pt[3] <= 0; key[0] <= 0; key[1] <= 0; key[2] <= 0; key[3] <= 0; key[4] <= 0; key[5] <= 0; wb_stb_i_r <= 1'b0; end else begin // Generate registered version of start (for edge detection) start_r <= start; // Generate a registered version of the write strobe wb_stb_i_r <= wb_stb_i; // Perform a write if(wb_stb_i & wb_we_i) begin case(wb_adr_i[5:2]) 0: start <= wb_dat_i[0]; 1: pt[3] <= wb_dat_i; 2: pt[2] <= wb_dat_i; 3: pt[1] <= wb_dat_i; 4: pt[0] <= wb_dat_i; 5: key[5] <= wb_dat_i; 6: key[4] <= wb_dat_i; 7: key[3] <= wb_dat_i; 8: key[2] <= wb_dat_i; 9: key[1] <= wb_dat_i; 10: key[0] <= wb_dat_i; default: ; endcase end else begin // end if wb_stb_i & wb_we_i start <= 1'b0; end end // end else begin end // always @ (posedge wb_clk_i) // Implement MD5 I/O memory map interface // Read side always @(*) begin case(wb_adr_i[5:2]) 1: wb_dat_o = pt[3]; 2: wb_dat_o = pt[2]; 3: wb_dat_o = pt[1]; 4: wb_dat_o = pt[0]; 5: wb_dat_o = key[5]; 6: wb_dat_o = key[4]; 7: wb_dat_o = key[3]; 8: wb_dat_o = key[2]; 9: wb_dat_o = key[1]; 10: wb_dat_o = key[0]; 11: wb_dat_o = {31'b0, ct_valid}; 12: wb_dat_o = ct[127:96]; 13: wb_dat_o = ct[95:64]; 14: wb_dat_o = ct[63:32]; 15: wb_dat_o = ct[31:0]; default: wb_dat_o = 32'b0; endcase end // always @ (*) aes_192 aes( .clk(wb_clk_i), .rst(wb_rst_i), .state(pt_big), .key(key_big), .start(start && ~start_r), // start on detected position edge .out(ct), .out_valid(ct_valid) ); endmodule
/* * Copyright 2012, Homer Hsing <homer.hsing@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* verilator lint_off UNOPTFLAT */ /* one AES round for every two clock cycles */ module one_round (clk, rst, state_in, key, state_out); input clk; input rst; input [127:0] state_in, key; output reg [127:0] state_out; wire [31:0] s0, s1, s2, s3, z0, z1, z2, z3, p00, p01, p02, p03, p10, p11, p12, p13, p20, p21, p22, p23, p30, p31, p32, p33, k0, k1, k2, k3; assign {k0, k1, k2, k3} = key; assign {s0, s1, s2, s3} = state_in; table_lookup t0 (clk, rst, s0, p00, p01, p02, p03), t1 (clk, rst, s1, p10, p11, p12, p13), t2 (clk, rst, s2, p20, p21, p22, p23), t3 (clk, rst, s3, p30, p31, p32, p33); assign z0 = p00 ^ p11 ^ p22 ^ p33 ^ k0; assign z1 = p03 ^ p10 ^ p21 ^ p32 ^ k1; assign z2 = p02 ^ p13 ^ p20 ^ p31 ^ k2; assign z3 = p01 ^ p12 ^ p23 ^ p30 ^ k3; always @ (posedge clk) state_out <= {z0, z1, z2, z3}; endmodule /* AES final round for every two clock cycles */ module final_round (clk, rst, state_in, key_in, state_out); input clk; input rst; input [127:0] state_in; input [127:0] key_in; output reg [127:0] state_out; wire [31:0] s0, s1, s2, s3, z0, z1, z2, z3, k0, k1, k2, k3; wire [7:0] p00, p01, p02, p03, p10, p11, p12, p13, p20, p21, p22, p23, p30, p31, p32, p33; assign {k0, k1, k2, k3} = key_in; assign {s0, s1, s2, s3} = state_in; S4 S4_1 (clk, rst, s0, {p00, p01, p02, p03}), S4_2 (clk, rst, s1, {p10, p11, p12, p13}), S4_3 (clk, rst, s2, {p20, p21, p22, p23}), S4_4 (clk, rst, s3, {p30, p31, p32, p33}); assign z0 = {p00, p11, p22, p33} ^ k0; assign z1 = {p10, p21, p32, p03} ^ k1; assign z2 = {p20, p31, p02, p13} ^ k2; assign z3 = {p30, p01, p12, p23} ^ k3; always @ (posedge clk or posedge rst) if (rst) state_out <= 0; else state_out <= {z0, z1, z2, z3}; endmodule
/* * Copyright 2012, Homer Hsing <homer.hsing@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* verilator lint_off UNOPTFLAT */ module table_lookup (clk, rst, state, p0, p1, p2, p3); input clk; input rst; input [31:0] state; output [31:0] p0, p1, p2, p3; wire [7:0] b0, b1, b2, b3; assign {b0, b1, b2, b3} = state; T t0 (clk, rst, b0, {p0[23:0], p0[31:24]}), t1 (clk, rst, b1, {p1[15:0], p1[31:16]}), t2 (clk, rst, b2, {p2[7:0], p2[31:8]} ), t3 (clk, rst, b3, p3); endmodule // end table_lookup /* substitue four bytes in a word */ module S4 (clk, rst, in, out); input clk; input rst; input [31:0] in; output [31:0] out; S S_0 (clk, rst, in[31:24], out[31:24]), S_1 (clk, rst, in[23:16], out[23:16]), S_2 (clk, rst, in[15:8], out[15:8] ), S_3 (clk, rst, in[7:0], out[7:0] ); endmodule // end S4 /* S_box, S_box, S_box*(x+1), S_box*x */ module T (clk, rst, in, out); input clk; input rst; input [7:0] in; output [31:0] out; S s0 (clk, rst, in, out[31:24]); assign out[23:16] = out[31:24]; xS s4 (clk, rst, in, out[7:0]); assign out[15:8] = out[23:16] ^ out[7:0]; endmodule // end T /* S box */ module S (clk, rst, in, out); input clk; input rst; input [7:0] in; output reg [7:0] out; always @ (posedge clk or posedge rst) if (rst) out <= 8'd0; else case (in) 8'h00: out <= 8'h63; 8'h01: out <= 8'h7c; 8'h02: out <= 8'h77; 8'h03: out <= 8'h7b; 8'h04: out <= 8'hf2; 8'h05: out <= 8'h6b; 8'h06: out <= 8'h6f; 8'h07: out <= 8'hc5; 8'h08: out <= 8'h30; 8'h09: out <= 8'h01; 8'h0a: out <= 8'h67; 8'h0b: out <= 8'h2b; 8'h0c: out <= 8'hfe; 8'h0d: out <= 8'hd7; 8'h0e: out <= 8'hab; 8'h0f: out <= 8'h76; 8'h10: out <= 8'hca; 8'h11: out <= 8'h82; 8'h12: out <= 8'hc9; 8'h13: out <= 8'h7d; 8'h14: out <= 8'hfa; 8'h15: out <= 8'h59; 8'h16: out <= 8'h47; 8'h17: out <= 8'hf0; 8'h18: out <= 8'had; 8'h19: out <= 8'hd4; 8'h1a: out <= 8'ha2; 8'h1b: out <= 8'haf; 8'h1c: out <= 8'h9c; 8'h1d: out <= 8'ha4; 8'h1e: out <= 8'h72; 8'h1f: out <= 8'hc0; 8'h20: out <= 8'hb7; 8'h21: out <= 8'hfd; 8'h22: out <= 8'h93; 8'h23: out <= 8'h26; 8'h24: out <= 8'h36; 8'h25: out <= 8'h3f; 8'h26: out <= 8'hf7; 8'h27: out <= 8'hcc; 8'h28: out <= 8'h34; 8'h29: out <= 8'ha5; 8'h2a: out <= 8'he5; 8'h2b: out <= 8'hf1; 8'h2c: out <= 8'h71; 8'h2d: out <= 8'hd8; 8'h2e: out <= 8'h31; 8'h2f: out <= 8'h15; 8'h30: out <= 8'h04; 8'h31: out <= 8'hc7; 8'h32: out <= 8'h23; 8'h33: out <= 8'hc3; 8'h34: out <= 8'h18; 8'h35: out <= 8'h96; 8'h36: out <= 8'h05; 8'h37: out <= 8'h9a; 8'h38: out <= 8'h07; 8'h39: out <= 8'h12; 8'h3a: out <= 8'h80; 8'h3b: out <= 8'he2; 8'h3c: out <= 8'heb; 8'h3d: out <= 8'h27; 8'h3e: out <= 8'hb2; 8'h3f: out <= 8'h75; 8'h40: out <= 8'h09; 8'h41: out <= 8'h83; 8'h42: out <= 8'h2c; 8'h43: out <= 8'h1a; 8'h44: out <= 8'h1b; 8'h45: out <= 8'h6e; 8'h46: out <= 8'h5a; 8'h47: out <= 8'ha0; 8'h48: out <= 8'h52; 8'h49: out <= 8'h3b; 8'h4a: out <= 8'hd6; 8'h4b: out <= 8'hb3; 8'h4c: out <= 8'h29; 8'h4d: out <= 8'he3; 8'h4e: out <= 8'h2f; 8'h4f: out <= 8'h84; 8'h50: out <= 8'h53; 8'h51: out <= 8'hd1; 8'h52: out <= 8'h00; 8'h53: out <= 8'hed; 8'h54: out <= 8'h20; 8'h55: out <= 8'hfc; 8'h56: out <= 8'hb1; 8'h57: out <= 8'h5b; 8'h58: out <= 8'h6a; 8'h59: out <= 8'hcb; 8'h5a: out <= 8'hbe; 8'h5b: out <= 8'h39; 8'h5c: out <= 8'h4a; 8'h5d: out <= 8'h4c; 8'h5e: out <= 8'h58; 8'h5f: out <= 8'hcf; 8'h60: out <= 8'hd0; 8'h61: out <= 8'hef; 8'h62: out <= 8'haa; 8'h63: out <= 8'hfb; 8'h64: out <= 8'h43; 8'h65: out <= 8'h4d; 8'h66: out <= 8'h33; 8'h67: out <= 8'h85; 8'h68: out <= 8'h45; 8'h69: out <= 8'hf9; 8'h6a: out <= 8'h02; 8'h6b: out <= 8'h7f; 8'h6c: out <= 8'h50; 8'h6d: out <= 8'h3c; 8'h6e: out <= 8'h9f; 8'h6f: out <= 8'ha8; 8'h70: out <= 8'h51; 8'h71: out <= 8'ha3; 8'h72: out <= 8'h40; 8'h73: out <= 8'h8f; 8'h74: out <= 8'h92; 8'h75: out <= 8'h9d; 8'h76: out <= 8'h38; 8'h77: out <= 8'hf5; 8'h78: out <= 8'hbc; 8'h79: out <= 8'hb6; 8'h7a: out <= 8'hda; 8'h7b: out <= 8'h21; 8'h7c: out <= 8'h10; 8'h7d: out <= 8'hff; 8'h7e: out <= 8'hf3; 8'h7f: out <= 8'hd2; 8'h80: out <= 8'hcd; 8'h81: out <= 8'h0c; 8'h82: out <= 8'h13; 8'h83: out <= 8'hec; 8'h84: out <= 8'h5f; 8'h85: out <= 8'h97; 8'h86: out <= 8'h44; 8'h87: out <= 8'h17; 8'h88: out <= 8'hc4; 8'h89: out <= 8'ha7; 8'h8a: out <= 8'h7e; 8'h8b: out <= 8'h3d; 8'h8c: out <= 8'h64; 8'h8d: out <= 8'h5d; 8'h8e: out <= 8'h19; 8'h8f: out <= 8'h73; 8'h90: out <= 8'h60; 8'h91: out <= 8'h81; 8'h92: out <= 8'h4f; 8'h93: out <= 8'hdc; 8'h94: out <= 8'h22; 8'h95: out <= 8'h2a; 8'h96: out <= 8'h90; 8'h97: out <= 8'h88; 8'h98: out <= 8'h46; 8'h99: out <= 8'hee; 8'h9a: out <= 8'hb8; 8'h9b: out <= 8'h14; 8'h9c: out <= 8'hde; 8'h9d: out <= 8'h5e; 8'h9e: out <= 8'h0b; 8'h9f: out <= 8'hdb; 8'ha0: out <= 8'he0; 8'ha1: out <= 8'h32; 8'ha2: out <= 8'h3a; 8'ha3: out <= 8'h0a; 8'ha4: out <= 8'h49; 8'ha5: out <= 8'h06; 8'ha6: out <= 8'h24; 8'ha7: out <= 8'h5c; 8'ha8: out <= 8'hc2; 8'ha9: out <= 8'hd3; 8'haa: out <= 8'hac; 8'hab: out <= 8'h62; 8'hac: out <= 8'h91; 8'had: out <= 8'h95; 8'hae: out <= 8'he4; 8'haf: out <= 8'h79; 8'hb0: out <= 8'he7; 8'hb1: out <= 8'hc8; 8'hb2: out <= 8'h37; 8'hb3: out <= 8'h6d; 8'hb4: out <= 8'h8d; 8'hb5: out <= 8'hd5; 8'hb6: out <= 8'h4e; 8'hb7: out <= 8'ha9; 8'hb8: out <= 8'h6c; 8'hb9: out <= 8'h56; 8'hba: out <= 8'hf4; 8'hbb: out <= 8'hea; 8'hbc: out <= 8'h65; 8'hbd: out <= 8'h7a; 8'hbe: out <= 8'hae; 8'hbf: out <= 8'h08; 8'hc0: out <= 8'hba; 8'hc1: out <= 8'h78; 8'hc2: out <= 8'h25; 8'hc3: out <= 8'h2e; 8'hc4: out <= 8'h1c; 8'hc5: out <= 8'ha6; 8'hc6: out <= 8'hb4; 8'hc7: out <= 8'hc6; 8'hc8: out <= 8'he8; 8'hc9: out <= 8'hdd; 8'hca: out <= 8'h74; 8'hcb: out <= 8'h1f; 8'hcc: out <= 8'h4b; 8'hcd: out <= 8'hbd; 8'hce: out <= 8'h8b; 8'hcf: out <= 8'h8a; 8'hd0: out <= 8'h70; 8'hd1: out <= 8'h3e; 8'hd2: out <= 8'hb5; 8'hd3: out <= 8'h66; 8'hd4: out <= 8'h48; 8'hd5: out <= 8'h03; 8'hd6: out <= 8'hf6; 8'hd7: out <= 8'h0e; 8'hd8: out <= 8'h61; 8'hd9: out <= 8'h35; 8'hda: out <= 8'h57; 8'hdb: out <= 8'hb9; 8'hdc: out <= 8'h86; 8'hdd: out <= 8'hc1; 8'hde: out <= 8'h1d; 8'hdf: out <= 8'h9e; 8'he0: out <= 8'he1; 8'he1: out <= 8'hf8; 8'he2: out <= 8'h98; 8'he3: out <= 8'h11; 8'he4: out <= 8'h69; 8'he5: out <= 8'hd9; 8'he6: out <= 8'h8e; 8'he7: out <= 8'h94; 8'he8: out <= 8'h9b; 8'he9: out <= 8'h1e; 8'hea: out <= 8'h87; 8'heb: out <= 8'he9; 8'hec: out <= 8'hce; 8'hed: out <= 8'h55; 8'hee: out <= 8'h28; 8'hef: out <= 8'hdf; 8'hf0: out <= 8'h8c; 8'hf1: out <= 8'ha1; 8'hf2: out <= 8'h89; 8'hf3: out <= 8'h0d; 8'hf4: out <= 8'hbf; 8'hf5: out <= 8'he6; 8'hf6: out <= 8'h42; 8'hf7: out <= 8'h68; 8'hf8: out <= 8'h41; 8'hf9: out <= 8'h99; 8'hfa: out <= 8'h2d; 8'hfb: out <= 8'h0f; 8'hfc: out <= 8'hb0; 8'hfd: out <= 8'h54; 8'hfe: out <= 8'hbb; 8'hff: out <= 8'h16; endcase endmodule /* S box * x */ module xS (clk, rst, in, out); input clk; input rst; input [7:0] in; output reg [7:0] out; always @ (posedge clk or posedge rst) if (rst) out <= 8'd0; else case (in) 8'h00: out <= 8'hc6; 8'h01: out <= 8'hf8; 8'h02: out <= 8'hee; 8'h03: out <= 8'hf6; 8'h04: out <= 8'hff; 8'h05: out <= 8'hd6; 8'h06: out <= 8'hde; 8'h07: out <= 8'h91; 8'h08: out <= 8'h60; 8'h09: out <= 8'h02; 8'h0a: out <= 8'hce; 8'h0b: out <= 8'h56; 8'h0c: out <= 8'he7; 8'h0d: out <= 8'hb5; 8'h0e: out <= 8'h4d; 8'h0f: out <= 8'hec; 8'h10: out <= 8'h8f; 8'h11: out <= 8'h1f; 8'h12: out <= 8'h89; 8'h13: out <= 8'hfa; 8'h14: out <= 8'hef; 8'h15: out <= 8'hb2; 8'h16: out <= 8'h8e; 8'h17: out <= 8'hfb; 8'h18: out <= 8'h41; 8'h19: out <= 8'hb3; 8'h1a: out <= 8'h5f; 8'h1b: out <= 8'h45; 8'h1c: out <= 8'h23; 8'h1d: out <= 8'h53; 8'h1e: out <= 8'he4; 8'h1f: out <= 8'h9b; 8'h20: out <= 8'h75; 8'h21: out <= 8'he1; 8'h22: out <= 8'h3d; 8'h23: out <= 8'h4c; 8'h24: out <= 8'h6c; 8'h25: out <= 8'h7e; 8'h26: out <= 8'hf5; 8'h27: out <= 8'h83; 8'h28: out <= 8'h68; 8'h29: out <= 8'h51; 8'h2a: out <= 8'hd1; 8'h2b: out <= 8'hf9; 8'h2c: out <= 8'he2; 8'h2d: out <= 8'hab; 8'h2e: out <= 8'h62; 8'h2f: out <= 8'h2a; 8'h30: out <= 8'h08; 8'h31: out <= 8'h95; 8'h32: out <= 8'h46; 8'h33: out <= 8'h9d; 8'h34: out <= 8'h30; 8'h35: out <= 8'h37; 8'h36: out <= 8'h0a; 8'h37: out <= 8'h2f; 8'h38: out <= 8'h0e; 8'h39: out <= 8'h24; 8'h3a: out <= 8'h1b; 8'h3b: out <= 8'hdf; 8'h3c: out <= 8'hcd; 8'h3d: out <= 8'h4e; 8'h3e: out <= 8'h7f; 8'h3f: out <= 8'hea; 8'h40: out <= 8'h12; 8'h41: out <= 8'h1d; 8'h42: out <= 8'h58; 8'h43: out <= 8'h34; 8'h44: out <= 8'h36; 8'h45: out <= 8'hdc; 8'h46: out <= 8'hb4; 8'h47: out <= 8'h5b; 8'h48: out <= 8'ha4; 8'h49: out <= 8'h76; 8'h4a: out <= 8'hb7; 8'h4b: out <= 8'h7d; 8'h4c: out <= 8'h52; 8'h4d: out <= 8'hdd; 8'h4e: out <= 8'h5e; 8'h4f: out <= 8'h13; 8'h50: out <= 8'ha6; 8'h51: out <= 8'hb9; 8'h52: out <= 8'h00; 8'h53: out <= 8'hc1; 8'h54: out <= 8'h40; 8'h55: out <= 8'he3; 8'h56: out <= 8'h79; 8'h57: out <= 8'hb6; 8'h58: out <= 8'hd4; 8'h59: out <= 8'h8d; 8'h5a: out <= 8'h67; 8'h5b: out <= 8'h72; 8'h5c: out <= 8'h94; 8'h5d: out <= 8'h98; 8'h5e: out <= 8'hb0; 8'h5f: out <= 8'h85; 8'h60: out <= 8'hbb; 8'h61: out <= 8'hc5; 8'h62: out <= 8'h4f; 8'h63: out <= 8'hed; 8'h64: out <= 8'h86; 8'h65: out <= 8'h9a; 8'h66: out <= 8'h66; 8'h67: out <= 8'h11; 8'h68: out <= 8'h8a; 8'h69: out <= 8'he9; 8'h6a: out <= 8'h04; 8'h6b: out <= 8'hfe; 8'h6c: out <= 8'ha0; 8'h6d: out <= 8'h78; 8'h6e: out <= 8'h25; 8'h6f: out <= 8'h4b; 8'h70: out <= 8'ha2; 8'h71: out <= 8'h5d; 8'h72: out <= 8'h80; 8'h73: out <= 8'h05; 8'h74: out <= 8'h3f; 8'h75: out <= 8'h21; 8'h76: out <= 8'h70; 8'h77: out <= 8'hf1; 8'h78: out <= 8'h63; 8'h79: out <= 8'h77; 8'h7a: out <= 8'haf; 8'h7b: out <= 8'h42; 8'h7c: out <= 8'h20; 8'h7d: out <= 8'he5; 8'h7e: out <= 8'hfd; 8'h7f: out <= 8'hbf; 8'h80: out <= 8'h81; 8'h81: out <= 8'h18; 8'h82: out <= 8'h26; 8'h83: out <= 8'hc3; 8'h84: out <= 8'hbe; 8'h85: out <= 8'h35; 8'h86: out <= 8'h88; 8'h87: out <= 8'h2e; 8'h88: out <= 8'h93; 8'h89: out <= 8'h55; 8'h8a: out <= 8'hfc; 8'h8b: out <= 8'h7a; 8'h8c: out <= 8'hc8; 8'h8d: out <= 8'hba; 8'h8e: out <= 8'h32; 8'h8f: out <= 8'he6; 8'h90: out <= 8'hc0; 8'h91: out <= 8'h19; 8'h92: out <= 8'h9e; 8'h93: out <= 8'ha3; 8'h94: out <= 8'h44; 8'h95: out <= 8'h54; 8'h96: out <= 8'h3b; 8'h97: out <= 8'h0b; 8'h98: out <= 8'h8c; 8'h99: out <= 8'hc7; 8'h9a: out <= 8'h6b; 8'h9b: out <= 8'h28; 8'h9c: out <= 8'ha7; 8'h9d: out <= 8'hbc; 8'h9e: out <= 8'h16; 8'h9f: out <= 8'had; 8'ha0: out <= 8'hdb; 8'ha1: out <= 8'h64; 8'ha2: out <= 8'h74; 8'ha3: out <= 8'h14; 8'ha4: out <= 8'h92; 8'ha5: out <= 8'h0c; 8'ha6: out <= 8'h48; 8'ha7: out <= 8'hb8; 8'ha8: out <= 8'h9f; 8'ha9: out <= 8'hbd; 8'haa: out <= 8'h43; 8'hab: out <= 8'hc4; 8'hac: out <= 8'h39; 8'had: out <= 8'h31; 8'hae: out <= 8'hd3; 8'haf: out <= 8'hf2; 8'hb0: out <= 8'hd5; 8'hb1: out <= 8'h8b; 8'hb2: out <= 8'h6e; 8'hb3: out <= 8'hda; 8'hb4: out <= 8'h01; 8'hb5: out <= 8'hb1; 8'hb6: out <= 8'h9c; 8'hb7: out <= 8'h49; 8'hb8: out <= 8'hd8; 8'hb9: out <= 8'hac; 8'hba: out <= 8'hf3; 8'hbb: out <= 8'hcf; 8'hbc: out <= 8'hca; 8'hbd: out <= 8'hf4; 8'hbe: out <= 8'h47; 8'hbf: out <= 8'h10; 8'hc0: out <= 8'h6f; 8'hc1: out <= 8'hf0; 8'hc2: out <= 8'h4a; 8'hc3: out <= 8'h5c; 8'hc4: out <= 8'h38; 8'hc5: out <= 8'h57; 8'hc6: out <= 8'h73; 8'hc7: out <= 8'h97; 8'hc8: out <= 8'hcb; 8'hc9: out <= 8'ha1; 8'hca: out <= 8'he8; 8'hcb: out <= 8'h3e; 8'hcc: out <= 8'h96; 8'hcd: out <= 8'h61; 8'hce: out <= 8'h0d; 8'hcf: out <= 8'h0f; 8'hd0: out <= 8'he0; 8'hd1: out <= 8'h7c; 8'hd2: out <= 8'h71; 8'hd3: out <= 8'hcc; 8'hd4: out <= 8'h90; 8'hd5: out <= 8'h06; 8'hd6: out <= 8'hf7; 8'hd7: out <= 8'h1c; 8'hd8: out <= 8'hc2; 8'hd9: out <= 8'h6a; 8'hda: out <= 8'hae; 8'hdb: out <= 8'h69; 8'hdc: out <= 8'h17; 8'hdd: out <= 8'h99; 8'hde: out <= 8'h3a; 8'hdf: out <= 8'h27; 8'he0: out <= 8'hd9; 8'he1: out <= 8'heb; 8'he2: out <= 8'h2b; 8'he3: out <= 8'h22; 8'he4: out <= 8'hd2; 8'he5: out <= 8'ha9; 8'he6: out <= 8'h07; 8'he7: out <= 8'h33; 8'he8: out <= 8'h2d; 8'he9: out <= 8'h3c; 8'hea: out <= 8'h15; 8'heb: out <= 8'hc9; 8'hec: out <= 8'h87; 8'hed: out <= 8'haa; 8'hee: out <= 8'h50; 8'hef: out <= 8'ha5; 8'hf0: out <= 8'h03; 8'hf1: out <= 8'h59; 8'hf2: out <= 8'h09; 8'hf3: out <= 8'h1a; 8'hf4: out <= 8'h65; 8'hf5: out <= 8'hd7; 8'hf6: out <= 8'h84; 8'hf7: out <= 8'hd0; 8'hf8: out <= 8'h82; 8'hf9: out <= 8'h29; 8'hfa: out <= 8'h5a; 8'hfb: out <= 8'h1e; 8'hfc: out <= 8'h7b; 8'hfd: out <= 8'ha8; 8'hfe: out <= 8'h6d; 8'hff: out <= 8'h2c; endcase endmodule
///////////////////////////////////////////////////////////////////// //// //// //// CRP //// //// DES Crypt Module //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module crp(P, R, K_sub); /* verilator lint_off LITENDIAN */ output [1:32] P; input [1:32] R; input [1:48] K_sub; wire [1:48] E; wire [1:48] X; wire [1:32] S; /* verilator lint_on LITENDIAN */ assign E[1:48] = { R[32], R[1], R[2], R[3], R[4], R[5], R[4], R[5], R[6], R[7], R[8], R[9], R[8], R[9], R[10], R[11], R[12], R[13], R[12], R[13], R[14], R[15], R[16], R[17], R[16], R[17], R[18], R[19], R[20], R[21], R[20], R[21], R[22], R[23], R[24], R[25], R[24], R[25], R[26], R[27], R[28], R[29], R[28], R[29], R[30], R[31], R[32], R[1]}; assign X = E ^ K_sub; sbox1 u0( .addr(X[01:06]), .dout(S[01:04]) ); sbox2 u1( .addr(X[07:12]), .dout(S[05:08]) ); sbox3 u2( .addr(X[13:18]), .dout(S[09:12]) ); sbox4 u3( .addr(X[19:24]), .dout(S[13:16]) ); sbox5 u4( .addr(X[25:30]), .dout(S[17:20]) ); sbox6 u5( .addr(X[31:36]), .dout(S[21:24]) ); sbox7 u6( .addr(X[37:42]), .dout(S[25:28]) ); sbox8 u7( .addr(X[43:48]), .dout(S[29:32]) ); assign P[1:32] = { S[16], S[7], S[20], S[21], S[29], S[12], S[28], S[17], S[1], S[15], S[23], S[26], S[5], S[18], S[31], S[10], S[2], S[8], S[24], S[14], S[32], S[27], S[3], S[9], S[19], S[13], S[30], S[6], S[22], S[11], S[4], S[25]}; endmodule
///////////////////////////////////////////////////////////////////// //// //// //// DES //// //// DES Top Level module //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module des3(desOut, out_valid, start, desIn, key1, key2, key3, decrypt, clk); output reg[63:0] desOut; output out_valid; input start; input [63:0] desIn; input [55:0] key1; input [55:0] key2; input [55:0] key3; input decrypt; input clk; /* verilator lint_off LITENDIAN */ wire [1:48] K_sub; wire [1:64] IP, FP; reg [1:64] FP_R; reg [1:32] L, R; wire [1:32] Xin; wire [1:32] Lout; wire [1:32] Rout; wire [1:32] out; /* verilator lint_on LITENDIAN */ reg [5:0] roundSel; reg start_r; always @(posedge clk) begin start_r <= start; end wire start_posedge = start & ~start_r; reg [7:0] validCounter; wire [63:0] des; always @ (posedge clk) begin if(start_posedge) begin roundSel <= 6'h00; end else if(~out_valid) begin roundSel <= roundSel +1; end end assign out_valid = (roundSel == 6'h30); always @ (posedge clk) begin if(!out_valid) begin desOut <= des; end end crp u0( .P(out), .R(Lout), .K_sub(K_sub)); // Select a subkey from key. key_sel3 u1( .K_sub(K_sub), .key1(key1), .key2(key2), .key3(key3), .roundSel(roundSel), .decrypt(decrypt) ); assign Lout = (roundSel == 0) ? IP[33:64] : ((roundSel == 16) ? FP_R[33:64] : ((roundSel == 32) ? FP_R[33:64] : R)); assign Xin = (roundSel == 0) ? IP[01:32] : ((roundSel == 16) ? FP_R[01:32] : ((roundSel == 32) ? FP_R[01:32] : L)); always @(posedge clk) FP_R <= FP; assign Rout = Xin ^ out; assign FP = { Rout, Lout}; always @(posedge clk) L <= Lout; always @(posedge clk) R <= Rout; // Perform initial permutation assign IP[1:64] = {desIn[06], desIn[14], desIn[22], desIn[30], desIn[38], desIn[46], desIn[54], desIn[62], desIn[04], desIn[12], desIn[20], desIn[28], desIn[36], desIn[44], desIn[52], desIn[60], desIn[02], desIn[10], desIn[18], desIn[26], desIn[34], desIn[42], desIn[50], desIn[58], desIn[00], desIn[08], desIn[16], desIn[24], desIn[32], desIn[40], desIn[48], desIn[56], desIn[07], desIn[15], desIn[23], desIn[31], desIn[39], desIn[47], desIn[55], desIn[63], desIn[05], desIn[13], desIn[21], desIn[29], desIn[37], desIn[45], desIn[53], desIn[61], desIn[03], desIn[11], desIn[19], desIn[27], desIn[35], desIn[43], desIn[51], desIn[59], desIn[01], desIn[09], desIn[17], desIn[25], desIn[33], desIn[41], desIn[49], desIn[57] }; // Perform final permutation assign des = {FP[40], FP[08], FP[48], FP[16], FP[56], FP[24], FP[64], FP[32], FP[39], FP[07], FP[47], FP[15], FP[55], FP[23], FP[63], FP[31], FP[38], FP[06], FP[46], FP[14], FP[54], FP[22], FP[62], FP[30], FP[37], FP[05], FP[45], FP[13], FP[53], FP[21], FP[61], FP[29], FP[36], FP[04], FP[44], FP[12], FP[52], FP[20], FP[60], FP[28], FP[35], FP[03], FP[43], FP[11], FP[51], FP[19], FP[59], FP[27], FP[34], FP[02], FP[42], FP[10], FP[50], FP[18], FP[58], FP[26], FP[33], FP[01], FP[41], FP[09], FP[49], FP[17], FP[57], FP[25] }; endmodule
///////////////////////////////////////////////////////////////////// //// //// //// DES TEST BENCH //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module test; reg clk; reg [319:0] x[512:0]; reg [319:0] tmp; reg [5:0] cnt; integer select; integer decrypt; wire [63:0] desOut; wire [63:0] des_in; wire [63:0] exp_out; wire [55:0] key1; wire [55:0] key2; wire [55:0] key3; integer ZZZ; initial begin $display("\n\n"); $display("*********************************************************"); $display("* Area Optimized DES core simulation started ... *"); $display("*********************************************************"); $display("\n"); //`ifdef WAVES // $shm_open("waves"); // $shm_probe("AS",test,"AS"); // $display("INFO: Signal dump enabled ...\n\n"); //`endif if(1) begin $dumpfile("./iverilog/test.vcd"); $dumpvars(0,test); end clk=0; ZZZ=0; // key1 key2 key3 Test data Out data x[0]=320'h0101010101010101_0101010101010101_0101010101010101_95F8A5E5DD31D900_8000000000000000; x[1]=320'h0101010101010101_0101010101010101_0101010101010101_9D64555A9A10B852_0000001000000000; x[2]=320'h3849674C2602319E_3849674C2602319E_3849674C2602319E_51454B582DDF440A_7178876E01F19B2A; x[3]=320'h04B915BA43FEB5B6_04B915BA43FEB5B6_04B915BA43FEB5B6_42FD443059577FA2_AF37FB421F8C4095; x[4]=320'h0123456789ABCDEF_0123456789ABCDEF_0123456789ABCDEF_736F6D6564617461_3D124FE2198BA318; x[5]=320'h0123456789ABCDEF_5555555555555555_0123456789ABCDEF_736F6D6564617461_FBABA1FF9D05E9B1; x[6]=320'h0123456789ABCDEF_5555555555555555_FEDCBA9876543210_736F6D6564617461_18d748e563620572; x[7]=320'h0352020767208217_8602876659082198_64056ABDFEA93457_7371756967676C65_c07d2a0fa566fa30; x[8]=320'h0101010101010101_8001010101010101_0101010101010102_0000000000000000_e6e6dd5b7e722974; x[9]=320'h1046103489988020_9107D01589190101_19079210981A0101_0000000000000000_e1ef62c332fe825b; decrypt = 0; @(posedge clk); $display(""); $display("**************************************"); $display("* Starting DES Test ... *"); $display("**************************************"); $display(""); for(decrypt=0;decrypt<2;decrypt=decrypt+1) begin if(decrypt) $display("Running Encrypt test ...\n"); else $display("Running Decrypt test ...\n"); for(select=0;select<16;select=select+1) begin tmp=x[select]; for(cnt=0;cnt<47;cnt=cnt+1) @(posedge clk); #10; if((exp_out !== desOut) | (^exp_out===1'bx) | (^desOut===1'bx)) $display("ERROR: (%0d) Expected %x Got %x", select, exp_out, desOut); else $display("PASS : (%0d) Expected %x Got %x", select, exp_out, desOut); //#2 $display("%h %h %h %h %h", key3, key2, key1, des_in, exp_out); @(posedge clk); end end $display(""); $display("**************************************"); $display("* DES Test done ... *"); $display("**************************************"); $display(""); $finish; end // end of innitial always #100 clk=~clk; assign #1 key1 = {tmp[319:313],tmp[311:305],tmp[303:297],tmp[295:289], tmp[287:281],tmp[279:273],tmp[271:265],tmp[263:257]}; assign #1 key2 = {tmp[255:249],tmp[247:241],tmp[239:233],tmp[231:225], tmp[223:217],tmp[215:209],tmp[207:201],tmp[199:193]}; assign #1 key3 = {tmp[191:185],tmp[183:177],tmp[175:169],tmp[167:161], tmp[159:153],tmp[151:145],tmp[143:137],tmp[135:129]}; assign #1 des_in = decrypt[0] ? tmp[63:0] : tmp[127:64]; assign exp_out = decrypt[0] ? tmp[127:64] : tmp[63:0]; des3 u0( .clk( clk ), .desOut( desOut ), .desIn( des_in ), .key1( key1 ), .key2( key2 ), .key3( key3 ), .roundSel( cnt ), .decrypt( decrypt[0] ) ); endmodule
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : des3_top.v // Project : Common Evaluation Platform (CEP) // Description : This file provides a wishbone based-DES3 core // module des3_top #( parameter remove_parity_bits=0) ( wb_adr_i, wb_cyc_i, wb_dat_i, wb_sel_i, wb_stb_i, wb_we_i, wb_ack_o, wb_err_o, wb_dat_o, wb_clk_i, wb_rst_i, int_o ); parameter dw = 32; parameter aw = 32; input [aw-1:0] wb_adr_i; input wb_cyc_i; input [dw-1:0] wb_dat_i; input [3:0] wb_sel_i; input wb_stb_i; input wb_we_i; output wb_ack_o; output wb_err_o; output reg [dw-1:0] wb_dat_o; output int_o; input wb_clk_i; input wb_rst_i; assign wb_err_o = 1'b0; assign int_o = 1'b0; // Internal registers reg start, start_r; reg decrypt; reg [31:0] desIn [0:1]; reg [31:0] key [0:5]; reg wb_stb_i_r; wire [63:0] des_in={desIn[0], desIn[1]}; wire [55:0] key_1; wire [55:0] key_2; wire [55:0] key_3; wire [63:0] ct; wire ct_valid; // The following generate logic is to used to remove the parity bits from the key // This was performed in the C test code that loaded vectors genvar i; generate if (remove_parity_bits == 1) begin for (i = 0; i < 4; i = i + 1) begin assign key_1[34 + i*7:28 + i*7] = key[0][i*8+1 + 6:i*8+1]; assign key_1[ 6 + i*7: i*7] = key[1][i*8+1 + 6:i*8+1]; assign key_2[34 + i*7:28 + i*7] = key[2][i*8+1 + 6:i*8+1]; assign key_2[ 6 + i*7: i*7] = key[3][i*8+1 + 6:i*8+1]; assign key_3[34 + i*7:28 + i*7] = key[4][i*8+1 + 6:i*8+1]; assign key_3[ 6 + i*7: i*7] = key[5][i*8+1 + 6:i*8+1]; end // generate for (i = 0; i < 4; i = i + 1) end else begin assign key_1 = {key[0][27:0], key[1][27:0]}; assign key_2 = {key[2][27:0], key[3][27:0]}; assign key_3 = {key[4][27:0], key[5][27:0]}; end // end else endgenerate // Generate the acknowledgement signal assign wb_ack_o = wb_stb_i_r && wb_stb_i; // Implement MD5 I/O memory map interface // Write side always @(posedge wb_clk_i) begin if(wb_rst_i) begin start <= 0; start_r <= 0; decrypt <= 0; desIn[1] <= 0; desIn[0] <= 0; key[5] <= 0; key[4] <= 0; key[3] <= 0; key[2] <= 0; key[1] <= 0; key[0] <= 0; wb_stb_i_r <= 1'b0; end else begin // Generate registered versions of start start_r <= start; // Generate a registered version of the write strobe wb_stb_i_r <= wb_stb_i; // Peform a write if(wb_stb_i & wb_we_i) begin case(wb_adr_i[5:2]) 0: start <= wb_dat_i[0]; 1: decrypt <= wb_dat_i[0]; 2: desIn[1]<= wb_dat_i; 3: desIn[0]<= wb_dat_i; 4: key[5] <= wb_dat_i; 5: key[4] <= wb_dat_i; 6: key[3] <= wb_dat_i; 7: key[2] <= wb_dat_i; 8: key[1] <= wb_dat_i; 9: key[0] <= wb_dat_i; default: ; endcase end else begin // if wb_stb_i & wb_we_i start <= 1'b0; end end // else end // always @ (posedge wb_clk_i) // Implement MD5 I/O memory map interface // Read side always @(*) begin case(wb_adr_i[5:2]) 2: wb_dat_o = desIn[1]; 3: wb_dat_o = desIn[0]; 4: wb_dat_o = key[5]; 5: wb_dat_o = key[4]; 6: wb_dat_o = key[3]; 7: wb_dat_o = key[2]; 8: wb_dat_o = key[1]; 9: wb_dat_o = key[0]; 10: wb_dat_o = {31'b0, ct_valid}; 11: wb_dat_o = ct[63:32]; 12: wb_dat_o = ct[31:0]; default: wb_dat_o = 32'b0; endcase end // always @ (*) des3 des3( .desOut(ct), .out_valid(ct_valid), .start(start && ~start_r), .desIn(des_in), .key1(key_1), .key2(key_2), .key3(key_3), .decrypt(decrypt), .clk(wb_clk_i)); endmodule
///////////////////////////////////////////////////////////////////// //// //// //// KEY_SEL //// //// Select one of 16 sub-keys for round //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module key_sel3(K_sub, key1, key2, key3, roundSel, decrypt); /* verilator lint_off LITENDIAN */ output [1:48] K_sub; /* verilator lint_on LITENDIAN */ input [55:0] key1, key2, key3; input [5:0] roundSel; input decrypt; wire decrypt_int; reg [55:0] K; reg [1:48] K_sub; /* verilator lint_off LITENDIAN */ wire [1:48] K1, K2, K3, K4, K5, K6, K7, K8, K9; wire [1:48] K10, K11, K12, K13, K14, K15, K16; /* verilator lint_on LITENDIAN */ always @(roundSel or decrypt or key1 or key2 or key3) case ({decrypt, roundSel[5:4]}) // synopsys full_case parallel_case 3'b0_00: K = key1; 3'b0_01: K = key2; 3'b0_10: K = key3; 3'b1_00: K = key3; 3'b1_01: K = key2; 3'b1_10: K = key1; 3'b0_11: K = 56'b0; 3'b1_11: K = 56'b0; endcase assign decrypt_int = (roundSel[5:4]==2'h1) ? !decrypt : decrypt; always @(K1 or K2 or K3 or K4 or K5 or K6 or K7 or K8 or K9 or K10 or K11 or K12 or K13 or K14 or K15 or K16 or roundSel) case(roundSel[3:0]) // synopsys full_case parallel_case 0: K_sub = K1; 1: K_sub = K2; 2: K_sub = K3; 3: K_sub = K4; 4: K_sub = K5; 5: K_sub = K6; 6: K_sub = K7; 7: K_sub = K8; 8: K_sub = K9; 9: K_sub = K10; 10: K_sub = K11; 11: K_sub = K12; 12: K_sub = K13; 13: K_sub = K14; 14: K_sub = K15; 15: K_sub = K16; endcase assign K16[1] = decrypt_int ? K[47] : K[40]; assign K16[2] = decrypt_int ? K[11] : K[4]; assign K16[3] = decrypt_int ? K[26] : K[19]; assign K16[4] = decrypt_int ? K[3] : K[53]; assign K16[5] = decrypt_int ? K[13] : K[6]; assign K16[6] = decrypt_int ? K[41] : K[34]; assign K16[7] = decrypt_int ? K[27] : K[20]; assign K16[8] = decrypt_int ? K[6] : K[24]; assign K16[9] = decrypt_int ? K[54] : K[47]; assign K16[10] = decrypt_int ? K[48] : K[41]; assign K16[11] = decrypt_int ? K[39] : K[32]; assign K16[12] = decrypt_int ? K[19] : K[12]; assign K16[13] = decrypt_int ? K[53] : K[46]; assign K16[14] = decrypt_int ? K[25] : K[18]; assign K16[15] = decrypt_int ? K[33] : K[26]; assign K16[16] = decrypt_int ? K[34] : K[27]; assign K16[17] = decrypt_int ? K[17] : K[10]; assign K16[18] = decrypt_int ? K[5] : K[55]; assign K16[19] = decrypt_int ? K[4] : K[54]; assign K16[20] = decrypt_int ? K[55] : K[48]; assign K16[21] = decrypt_int ? K[24] : K[17]; assign K16[22] = decrypt_int ? K[32] : K[25]; assign K16[23] = decrypt_int ? K[40] : K[33]; assign K16[24] = decrypt_int ? K[20] : K[13]; assign K16[25] = decrypt_int ? K[36] : K[29]; assign K16[26] = decrypt_int ? K[31] : K[51]; assign K16[27] = decrypt_int ? K[21] : K[14]; assign K16[28] = decrypt_int ? K[8] : K[1]; assign K16[29] = decrypt_int ? K[23] : K[16]; assign K16[30] = decrypt_int ? K[52] : K[45]; assign K16[31] = decrypt_int ? K[14] : K[7]; assign K16[32] = decrypt_int ? K[29] : K[22]; assign K16[33] = decrypt_int ? K[51] : K[44]; assign K16[34] = decrypt_int ? K[9] : K[2]; assign K16[35] = decrypt_int ? K[35] : K[28]; assign K16[36] = decrypt_int ? K[30] : K[23]; assign K16[37] = decrypt_int ? K[2] : K[50]; assign K16[38] = decrypt_int ? K[37] : K[30]; assign K16[39] = decrypt_int ? K[22] : K[15]; assign K16[40] = decrypt_int ? K[0] : K[52]; assign K16[41] = decrypt_int ? K[42] : K[35]; assign K16[42] = decrypt_int ? K[38] : K[31]; assign K16[43] = decrypt_int ? K[16] : K[9]; assign K16[44] = decrypt_int ? K[43] : K[36]; assign K16[45] = decrypt_int ? K[44] : K[37]; assign K16[46] = decrypt_int ? K[1] : K[49]; assign K16[47] = decrypt_int ? K[7] : K[0]; assign K16[48] = decrypt_int ? K[28] : K[21]; assign K15[1] = decrypt_int ? K[54] : K[33]; assign K15[2] = decrypt_int ? K[18] : K[54]; assign K15[3] = decrypt_int ? K[33] : K[12]; assign K15[4] = decrypt_int ? K[10] : K[46]; assign K15[5] = decrypt_int ? K[20] : K[24]; assign K15[6] = decrypt_int ? K[48] : K[27]; assign K15[7] = decrypt_int ? K[34] : K[13]; assign K15[8] = decrypt_int ? K[13] : K[17]; assign K15[9] = decrypt_int ? K[4] : K[40]; assign K15[10] = decrypt_int ? K[55] : K[34]; assign K15[11] = decrypt_int ? K[46] : K[25]; assign K15[12] = decrypt_int ? K[26] : K[5]; assign K15[13] = decrypt_int ? K[3] : K[39]; assign K15[14] = decrypt_int ? K[32] : K[11]; assign K15[15] = decrypt_int ? K[40] : K[19]; assign K15[16] = decrypt_int ? K[41] : K[20]; assign K15[17] = decrypt_int ? K[24] : K[3]; assign K15[18] = decrypt_int ? K[12] : K[48]; assign K15[19] = decrypt_int ? K[11] : K[47]; assign K15[20] = decrypt_int ? K[5] : K[41]; assign K15[21] = decrypt_int ? K[6] : K[10]; assign K15[22] = decrypt_int ? K[39] : K[18]; assign K15[23] = decrypt_int ? K[47] : K[26]; assign K15[24] = decrypt_int ? K[27] : K[6]; assign K15[25] = decrypt_int ? K[43] : K[22]; assign K15[26] = decrypt_int ? K[38] : K[44]; assign K15[27] = decrypt_int ? K[28] : K[7]; assign K15[28] = decrypt_int ? K[15] : K[49]; assign K15[29] = decrypt_int ? K[30] : K[9]; assign K15[30] = decrypt_int ? K[0] : K[38]; assign K15[31] = decrypt_int ? K[21] : K[0]; assign K15[32] = decrypt_int ? K[36] : K[15]; assign K15[33] = decrypt_int ? K[31] : K[37]; assign K15[34] = decrypt_int ? K[16] : K[50]; assign K15[35] = decrypt_int ? K[42] : K[21]; assign K15[36] = decrypt_int ? K[37] : K[16]; assign K15[37] = decrypt_int ? K[9] : K[43]; assign K15[38] = decrypt_int ? K[44] : K[23]; assign K15[39] = decrypt_int ? K[29] : K[8]; assign K15[40] = decrypt_int ? K[7] : K[45]; assign K15[41] = decrypt_int ? K[49] : K[28]; assign K15[42] = decrypt_int ? K[45] : K[51]; assign K15[43] = decrypt_int ? K[23] : K[2]; assign K15[44] = decrypt_int ? K[50] : K[29]; assign K15[45] = decrypt_int ? K[51] : K[30]; assign K15[46] = decrypt_int ? K[8] : K[42]; assign K15[47] = decrypt_int ? K[14] : K[52]; assign K15[48] = decrypt_int ? K[35] : K[14]; assign K14[1] = decrypt_int ? K[11] : K[19]; assign K14[2] = decrypt_int ? K[32] : K[40]; assign K14[3] = decrypt_int ? K[47] : K[55]; assign K14[4] = decrypt_int ? K[24] : K[32]; assign K14[5] = decrypt_int ? K[34] : K[10]; assign K14[6] = decrypt_int ? K[5] : K[13]; assign K14[7] = decrypt_int ? K[48] : K[24]; assign K14[8] = decrypt_int ? K[27] : K[3]; assign K14[9] = decrypt_int ? K[18] : K[26]; assign K14[10] = decrypt_int ? K[12] : K[20]; assign K14[11] = decrypt_int ? K[3] : K[11]; assign K14[12] = decrypt_int ? K[40] : K[48]; assign K14[13] = decrypt_int ? K[17] : K[25]; assign K14[14] = decrypt_int ? K[46] : K[54]; assign K14[15] = decrypt_int ? K[54] : K[5]; assign K14[16] = decrypt_int ? K[55] : K[6]; assign K14[17] = decrypt_int ? K[13] : K[46]; assign K14[18] = decrypt_int ? K[26] : K[34]; assign K14[19] = decrypt_int ? K[25] : K[33]; assign K14[20] = decrypt_int ? K[19] : K[27]; assign K14[21] = decrypt_int ? K[20] : K[53]; assign K14[22] = decrypt_int ? K[53] : K[4]; assign K14[23] = decrypt_int ? K[4] : K[12]; assign K14[24] = decrypt_int ? K[41] : K[17]; assign K14[25] = decrypt_int ? K[2] : K[8]; assign K14[26] = decrypt_int ? K[52] : K[30]; assign K14[27] = decrypt_int ? K[42] : K[52]; assign K14[28] = decrypt_int ? K[29] : K[35]; assign K14[29] = decrypt_int ? K[44] : K[50]; assign K14[30] = decrypt_int ? K[14] : K[51]; assign K14[31] = decrypt_int ? K[35] : K[45]; assign K14[32] = decrypt_int ? K[50] : K[1]; assign K14[33] = decrypt_int ? K[45] : K[23]; assign K14[34] = decrypt_int ? K[30] : K[36]; assign K14[35] = decrypt_int ? K[1] : K[7]; assign K14[36] = decrypt_int ? K[51] : K[2]; assign K14[37] = decrypt_int ? K[23] : K[29]; assign K14[38] = decrypt_int ? K[31] : K[9]; assign K14[39] = decrypt_int ? K[43] : K[49]; assign K14[40] = decrypt_int ? K[21] : K[31]; assign K14[41] = decrypt_int ? K[8] : K[14]; assign K14[42] = decrypt_int ? K[0] : K[37]; assign K14[43] = decrypt_int ? K[37] : K[43]; assign K14[44] = decrypt_int ? K[9] : K[15]; assign K14[45] = decrypt_int ? K[38] : K[16]; assign K14[46] = decrypt_int ? K[22] : K[28]; assign K14[47] = decrypt_int ? K[28] : K[38]; assign K14[48] = decrypt_int ? K[49] : K[0]; assign K13[1] = decrypt_int ? K[25] : K[5]; assign K13[2] = decrypt_int ? K[46] : K[26]; assign K13[3] = decrypt_int ? K[4] : K[41]; assign K13[4] = decrypt_int ? K[13] : K[18]; assign K13[5] = decrypt_int ? K[48] : K[53]; assign K13[6] = decrypt_int ? K[19] : K[24]; assign K13[7] = decrypt_int ? K[5] : K[10]; assign K13[8] = decrypt_int ? K[41] : K[46]; assign K13[9] = decrypt_int ? K[32] : K[12]; assign K13[10] = decrypt_int ? K[26] : K[6]; assign K13[11] = decrypt_int ? K[17] : K[54]; assign K13[12] = decrypt_int ? K[54] : K[34]; assign K13[13] = decrypt_int ? K[6] : K[11]; assign K13[14] = decrypt_int ? K[3] : K[40]; assign K13[15] = decrypt_int ? K[11] : K[48]; assign K13[16] = decrypt_int ? K[12] : K[17]; assign K13[17] = decrypt_int ? K[27] : K[32]; assign K13[18] = decrypt_int ? K[40] : K[20]; assign K13[19] = decrypt_int ? K[39] : K[19]; assign K13[20] = decrypt_int ? K[33] : K[13]; assign K13[21] = decrypt_int ? K[34] : K[39]; assign K13[22] = decrypt_int ? K[10] : K[47]; assign K13[23] = decrypt_int ? K[18] : K[55]; assign K13[24] = decrypt_int ? K[55] : K[3]; assign K13[25] = decrypt_int ? K[16] : K[49]; assign K13[26] = decrypt_int ? K[7] : K[16]; assign K13[27] = decrypt_int ? K[1] : K[38]; assign K13[28] = decrypt_int ? K[43] : K[21]; assign K13[29] = decrypt_int ? K[31] : K[36]; assign K13[30] = decrypt_int ? K[28] : K[37]; assign K13[31] = decrypt_int ? K[49] : K[31]; assign K13[32] = decrypt_int ? K[9] : K[42]; assign K13[33] = decrypt_int ? K[0] : K[9]; assign K13[34] = decrypt_int ? K[44] : K[22]; assign K13[35] = decrypt_int ? K[15] : K[52]; assign K13[36] = decrypt_int ? K[38] : K[43]; assign K13[37] = decrypt_int ? K[37] : K[15]; assign K13[38] = decrypt_int ? K[45] : K[50]; assign K13[39] = decrypt_int ? K[2] : K[35]; assign K13[40] = decrypt_int ? K[35] : K[44]; assign K13[41] = decrypt_int ? K[22] : K[0]; assign K13[42] = decrypt_int ? K[14] : K[23]; assign K13[43] = decrypt_int ? K[51] : K[29]; assign K13[44] = decrypt_int ? K[23] : K[1]; assign K13[45] = decrypt_int ? K[52] : K[2]; assign K13[46] = decrypt_int ? K[36] : K[14]; assign K13[47] = decrypt_int ? K[42] : K[51]; assign K13[48] = decrypt_int ? K[8] : K[45]; assign K12[1] = decrypt_int ? K[39] : K[48]; assign K12[2] = decrypt_int ? K[3] : K[12]; assign K12[3] = decrypt_int ? K[18] : K[27]; assign K12[4] = decrypt_int ? K[27] : K[4]; assign K12[5] = decrypt_int ? K[5] : K[39]; assign K12[6] = decrypt_int ? K[33] : K[10]; assign K12[7] = decrypt_int ? K[19] : K[53]; assign K12[8] = decrypt_int ? K[55] : K[32]; assign K12[9] = decrypt_int ? K[46] : K[55]; assign K12[10] = decrypt_int ? K[40] : K[17]; assign K12[11] = decrypt_int ? K[6] : K[40]; assign K12[12] = decrypt_int ? K[11] : K[20]; assign K12[13] = decrypt_int ? K[20] : K[54]; assign K12[14] = decrypt_int ? K[17] : K[26]; assign K12[15] = decrypt_int ? K[25] : K[34]; assign K12[16] = decrypt_int ? K[26] : K[3]; assign K12[17] = decrypt_int ? K[41] : K[18]; assign K12[18] = decrypt_int ? K[54] : K[6]; assign K12[19] = decrypt_int ? K[53] : K[5]; assign K12[20] = decrypt_int ? K[47] : K[24]; assign K12[21] = decrypt_int ? K[48] : K[25]; assign K12[22] = decrypt_int ? K[24] : K[33]; assign K12[23] = decrypt_int ? K[32] : K[41]; assign K12[24] = decrypt_int ? K[12] : K[46]; assign K12[25] = decrypt_int ? K[30] : K[35]; assign K12[26] = decrypt_int ? K[21] : K[2]; assign K12[27] = decrypt_int ? K[15] : K[51]; assign K12[28] = decrypt_int ? K[2] : K[7]; assign K12[29] = decrypt_int ? K[45] : K[22]; assign K12[30] = decrypt_int ? K[42] : K[23]; assign K12[31] = decrypt_int ? K[8] : K[44]; assign K12[32] = decrypt_int ? K[23] : K[28]; assign K12[33] = decrypt_int ? K[14] : K[50]; assign K12[34] = decrypt_int ? K[31] : K[8]; assign K12[35] = decrypt_int ? K[29] : K[38]; assign K12[36] = decrypt_int ? K[52] : K[29]; assign K12[37] = decrypt_int ? K[51] : K[1]; assign K12[38] = decrypt_int ? K[0] : K[36]; assign K12[39] = decrypt_int ? K[16] : K[21]; assign K12[40] = decrypt_int ? K[49] : K[30]; assign K12[41] = decrypt_int ? K[36] : K[45]; assign K12[42] = decrypt_int ? K[28] : K[9]; assign K12[43] = decrypt_int ? K[38] : K[15]; assign K12[44] = decrypt_int ? K[37] : K[42]; assign K12[45] = decrypt_int ? K[7] : K[43]; assign K12[46] = decrypt_int ? K[50] : K[0]; assign K12[47] = decrypt_int ? K[1] : K[37]; assign K12[48] = decrypt_int ? K[22] : K[31]; assign K11[1] = decrypt_int ? K[53] : K[34]; assign K11[2] = decrypt_int ? K[17] : K[55]; assign K11[3] = decrypt_int ? K[32] : K[13]; assign K11[4] = decrypt_int ? K[41] : K[47]; assign K11[5] = decrypt_int ? K[19] : K[25]; assign K11[6] = decrypt_int ? K[47] : K[53]; assign K11[7] = decrypt_int ? K[33] : K[39]; assign K11[8] = decrypt_int ? K[12] : K[18]; assign K11[9] = decrypt_int ? K[3] : K[41]; assign K11[10] = decrypt_int ? K[54] : K[3]; assign K11[11] = decrypt_int ? K[20] : K[26]; assign K11[12] = decrypt_int ? K[25] : K[6]; assign K11[13] = decrypt_int ? K[34] : K[40]; assign K11[14] = decrypt_int ? K[6] : K[12]; assign K11[15] = decrypt_int ? K[39] : K[20]; assign K11[16] = decrypt_int ? K[40] : K[46]; assign K11[17] = decrypt_int ? K[55] : K[4]; assign K11[18] = decrypt_int ? K[11] : K[17]; assign K11[19] = decrypt_int ? K[10] : K[48]; assign K11[20] = decrypt_int ? K[4] : K[10]; assign K11[21] = decrypt_int ? K[5] : K[11]; assign K11[22] = decrypt_int ? K[13] : K[19]; assign K11[23] = decrypt_int ? K[46] : K[27]; assign K11[24] = decrypt_int ? K[26] : K[32]; assign K11[25] = decrypt_int ? K[44] : K[21]; assign K11[26] = decrypt_int ? K[35] : K[43]; assign K11[27] = decrypt_int ? K[29] : K[37]; assign K11[28] = decrypt_int ? K[16] : K[52]; assign K11[29] = decrypt_int ? K[0] : K[8]; assign K11[30] = decrypt_int ? K[1] : K[9]; assign K11[31] = decrypt_int ? K[22] : K[30]; assign K11[32] = decrypt_int ? K[37] : K[14]; assign K11[33] = decrypt_int ? K[28] : K[36]; assign K11[34] = decrypt_int ? K[45] : K[49]; assign K11[35] = decrypt_int ? K[43] : K[51]; assign K11[36] = decrypt_int ? K[7] : K[15]; assign K11[37] = decrypt_int ? K[38] : K[42]; assign K11[38] = decrypt_int ? K[14] : K[22]; assign K11[39] = decrypt_int ? K[30] : K[7]; assign K11[40] = decrypt_int ? K[8] : K[16]; assign K11[41] = decrypt_int ? K[50] : K[31]; assign K11[42] = decrypt_int ? K[42] : K[50]; assign K11[43] = decrypt_int ? K[52] : K[1]; assign K11[44] = decrypt_int ? K[51] : K[28]; assign K11[45] = decrypt_int ? K[21] : K[29]; assign K11[46] = decrypt_int ? K[9] : K[45]; assign K11[47] = decrypt_int ? K[15] : K[23]; assign K11[48] = decrypt_int ? K[36] : K[44]; assign K10[1] = decrypt_int ? K[10] : K[20]; assign K10[2] = decrypt_int ? K[6] : K[41]; assign K10[3] = decrypt_int ? K[46] : K[24]; assign K10[4] = decrypt_int ? K[55] : K[33]; assign K10[5] = decrypt_int ? K[33] : K[11]; assign K10[6] = decrypt_int ? K[4] : K[39]; assign K10[7] = decrypt_int ? K[47] : K[25]; assign K10[8] = decrypt_int ? K[26] : K[4]; assign K10[9] = decrypt_int ? K[17] : K[27]; assign K10[10] = decrypt_int ? K[11] : K[46]; assign K10[11] = decrypt_int ? K[34] : K[12]; assign K10[12] = decrypt_int ? K[39] : K[17]; assign K10[13] = decrypt_int ? K[48] : K[26]; assign K10[14] = decrypt_int ? K[20] : K[55]; assign K10[15] = decrypt_int ? K[53] : K[6]; assign K10[16] = decrypt_int ? K[54] : K[32]; assign K10[17] = decrypt_int ? K[12] : K[47]; assign K10[18] = decrypt_int ? K[25] : K[3]; assign K10[19] = decrypt_int ? K[24] : K[34]; assign K10[20] = decrypt_int ? K[18] : K[53]; assign K10[21] = decrypt_int ? K[19] : K[54]; assign K10[22] = decrypt_int ? K[27] : K[5]; assign K10[23] = decrypt_int ? K[3] : K[13]; assign K10[24] = decrypt_int ? K[40] : K[18]; assign K10[25] = decrypt_int ? K[31] : K[7]; assign K10[26] = decrypt_int ? K[49] : K[29]; assign K10[27] = decrypt_int ? K[43] : K[23]; assign K10[28] = decrypt_int ? K[30] : K[38]; assign K10[29] = decrypt_int ? K[14] : K[49]; assign K10[30] = decrypt_int ? K[15] : K[50]; assign K10[31] = decrypt_int ? K[36] : K[16]; assign K10[32] = decrypt_int ? K[51] : K[0]; assign K10[33] = decrypt_int ? K[42] : K[22]; assign K10[34] = decrypt_int ? K[0] : K[35]; assign K10[35] = decrypt_int ? K[2] : K[37]; assign K10[36] = decrypt_int ? K[21] : K[1]; assign K10[37] = decrypt_int ? K[52] : K[28]; assign K10[38] = decrypt_int ? K[28] : K[8]; assign K10[39] = decrypt_int ? K[44] : K[52]; assign K10[40] = decrypt_int ? K[22] : K[2]; assign K10[41] = decrypt_int ? K[9] : K[44]; assign K10[42] = decrypt_int ? K[1] : K[36]; assign K10[43] = decrypt_int ? K[7] : K[42]; assign K10[44] = decrypt_int ? K[38] : K[14]; assign K10[45] = decrypt_int ? K[35] : K[15]; assign K10[46] = decrypt_int ? K[23] : K[31]; assign K10[47] = decrypt_int ? K[29] : K[9]; assign K10[48] = decrypt_int ? K[50] : K[30]; assign K9[1] = decrypt_int ? K[24] : K[6]; assign K9[2] = decrypt_int ? K[20] : K[27]; assign K9[3] = decrypt_int ? K[3] : K[10]; assign K9[4] = decrypt_int ? K[12] : K[19]; assign K9[5] = decrypt_int ? K[47] : K[54]; assign K9[6] = decrypt_int ? K[18] : K[25]; assign K9[7] = decrypt_int ? K[4] : K[11]; assign K9[8] = decrypt_int ? K[40] : K[47]; assign K9[9] = decrypt_int ? K[6] : K[13]; assign K9[10] = decrypt_int ? K[25] : K[32]; assign K9[11] = decrypt_int ? K[48] : K[55]; assign K9[12] = decrypt_int ? K[53] : K[3]; assign K9[13] = decrypt_int ? K[5] : K[12]; assign K9[14] = decrypt_int ? K[34] : K[41]; assign K9[15] = decrypt_int ? K[10] : K[17]; assign K9[16] = decrypt_int ? K[11] : K[18]; assign K9[17] = decrypt_int ? K[26] : K[33]; assign K9[18] = decrypt_int ? K[39] : K[46]; assign K9[19] = decrypt_int ? K[13] : K[20]; assign K9[20] = decrypt_int ? K[32] : K[39]; assign K9[21] = decrypt_int ? K[33] : K[40]; assign K9[22] = decrypt_int ? K[41] : K[48]; assign K9[23] = decrypt_int ? K[17] : K[24]; assign K9[24] = decrypt_int ? K[54] : K[4]; assign K9[25] = decrypt_int ? K[45] : K[52]; assign K9[26] = decrypt_int ? K[8] : K[15]; assign K9[27] = decrypt_int ? K[2] : K[9]; assign K9[28] = decrypt_int ? K[44] : K[51]; assign K9[29] = decrypt_int ? K[28] : K[35]; assign K9[30] = decrypt_int ? K[29] : K[36]; assign K9[31] = decrypt_int ? K[50] : K[2]; assign K9[32] = decrypt_int ? K[38] : K[45]; assign K9[33] = decrypt_int ? K[1] : K[8]; assign K9[34] = decrypt_int ? K[14] : K[21]; assign K9[35] = decrypt_int ? K[16] : K[23]; assign K9[36] = decrypt_int ? K[35] : K[42]; assign K9[37] = decrypt_int ? K[7] : K[14]; assign K9[38] = decrypt_int ? K[42] : K[49]; assign K9[39] = decrypt_int ? K[31] : K[38]; assign K9[40] = decrypt_int ? K[36] : K[43]; assign K9[41] = decrypt_int ? K[23] : K[30]; assign K9[42] = decrypt_int ? K[15] : K[22]; assign K9[43] = decrypt_int ? K[21] : K[28]; assign K9[44] = decrypt_int ? K[52] : K[0]; assign K9[45] = decrypt_int ? K[49] : K[1]; assign K9[46] = decrypt_int ? K[37] : K[44]; assign K9[47] = decrypt_int ? K[43] : K[50]; assign K9[48] = decrypt_int ? K[9] : K[16]; assign K8[1] = decrypt_int ? K[6] : K[24]; assign K8[2] = decrypt_int ? K[27] : K[20]; assign K8[3] = decrypt_int ? K[10] : K[3]; assign K8[4] = decrypt_int ? K[19] : K[12]; assign K8[5] = decrypt_int ? K[54] : K[47]; assign K8[6] = decrypt_int ? K[25] : K[18]; assign K8[7] = decrypt_int ? K[11] : K[4]; assign K8[8] = decrypt_int ? K[47] : K[40]; assign K8[9] = decrypt_int ? K[13] : K[6]; assign K8[10] = decrypt_int ? K[32] : K[25]; assign K8[11] = decrypt_int ? K[55] : K[48]; assign K8[12] = decrypt_int ? K[3] : K[53]; assign K8[13] = decrypt_int ? K[12] : K[5]; assign K8[14] = decrypt_int ? K[41] : K[34]; assign K8[15] = decrypt_int ? K[17] : K[10]; assign K8[16] = decrypt_int ? K[18] : K[11]; assign K8[17] = decrypt_int ? K[33] : K[26]; assign K8[18] = decrypt_int ? K[46] : K[39]; assign K8[19] = decrypt_int ? K[20] : K[13]; assign K8[20] = decrypt_int ? K[39] : K[32]; assign K8[21] = decrypt_int ? K[40] : K[33]; assign K8[22] = decrypt_int ? K[48] : K[41]; assign K8[23] = decrypt_int ? K[24] : K[17]; assign K8[24] = decrypt_int ? K[4] : K[54]; assign K8[25] = decrypt_int ? K[52] : K[45]; assign K8[26] = decrypt_int ? K[15] : K[8]; assign K8[27] = decrypt_int ? K[9] : K[2]; assign K8[28] = decrypt_int ? K[51] : K[44]; assign K8[29] = decrypt_int ? K[35] : K[28]; assign K8[30] = decrypt_int ? K[36] : K[29]; assign K8[31] = decrypt_int ? K[2] : K[50]; assign K8[32] = decrypt_int ? K[45] : K[38]; assign K8[33] = decrypt_int ? K[8] : K[1]; assign K8[34] = decrypt_int ? K[21] : K[14]; assign K8[35] = decrypt_int ? K[23] : K[16]; assign K8[36] = decrypt_int ? K[42] : K[35]; assign K8[37] = decrypt_int ? K[14] : K[7]; assign K8[38] = decrypt_int ? K[49] : K[42]; assign K8[39] = decrypt_int ? K[38] : K[31]; assign K8[40] = decrypt_int ? K[43] : K[36]; assign K8[41] = decrypt_int ? K[30] : K[23]; assign K8[42] = decrypt_int ? K[22] : K[15]; assign K8[43] = decrypt_int ? K[28] : K[21]; assign K8[44] = decrypt_int ? K[0] : K[52]; assign K8[45] = decrypt_int ? K[1] : K[49]; assign K8[46] = decrypt_int ? K[44] : K[37]; assign K8[47] = decrypt_int ? K[50] : K[43]; assign K8[48] = decrypt_int ? K[16] : K[9]; assign K7[1] = decrypt_int ? K[20] : K[10]; assign K7[2] = decrypt_int ? K[41] : K[6]; assign K7[3] = decrypt_int ? K[24] : K[46]; assign K7[4] = decrypt_int ? K[33] : K[55]; assign K7[5] = decrypt_int ? K[11] : K[33]; assign K7[6] = decrypt_int ? K[39] : K[4]; assign K7[7] = decrypt_int ? K[25] : K[47]; assign K7[8] = decrypt_int ? K[4] : K[26]; assign K7[9] = decrypt_int ? K[27] : K[17]; assign K7[10] = decrypt_int ? K[46] : K[11]; assign K7[11] = decrypt_int ? K[12] : K[34]; assign K7[12] = decrypt_int ? K[17] : K[39]; assign K7[13] = decrypt_int ? K[26] : K[48]; assign K7[14] = decrypt_int ? K[55] : K[20]; assign K7[15] = decrypt_int ? K[6] : K[53]; assign K7[16] = decrypt_int ? K[32] : K[54]; assign K7[17] = decrypt_int ? K[47] : K[12]; assign K7[18] = decrypt_int ? K[3] : K[25]; assign K7[19] = decrypt_int ? K[34] : K[24]; assign K7[20] = decrypt_int ? K[53] : K[18]; assign K7[21] = decrypt_int ? K[54] : K[19]; assign K7[22] = decrypt_int ? K[5] : K[27]; assign K7[23] = decrypt_int ? K[13] : K[3]; assign K7[24] = decrypt_int ? K[18] : K[40]; assign K7[25] = decrypt_int ? K[7] : K[31]; assign K7[26] = decrypt_int ? K[29] : K[49]; assign K7[27] = decrypt_int ? K[23] : K[43]; assign K7[28] = decrypt_int ? K[38] : K[30]; assign K7[29] = decrypt_int ? K[49] : K[14]; assign K7[30] = decrypt_int ? K[50] : K[15]; assign K7[31] = decrypt_int ? K[16] : K[36]; assign K7[32] = decrypt_int ? K[0] : K[51]; assign K7[33] = decrypt_int ? K[22] : K[42]; assign K7[34] = decrypt_int ? K[35] : K[0]; assign K7[35] = decrypt_int ? K[37] : K[2]; assign K7[36] = decrypt_int ? K[1] : K[21]; assign K7[37] = decrypt_int ? K[28] : K[52]; assign K7[38] = decrypt_int ? K[8] : K[28]; assign K7[39] = decrypt_int ? K[52] : K[44]; assign K7[40] = decrypt_int ? K[2] : K[22]; assign K7[41] = decrypt_int ? K[44] : K[9]; assign K7[42] = decrypt_int ? K[36] : K[1]; assign K7[43] = decrypt_int ? K[42] : K[7]; assign K7[44] = decrypt_int ? K[14] : K[38]; assign K7[45] = decrypt_int ? K[15] : K[35]; assign K7[46] = decrypt_int ? K[31] : K[23]; assign K7[47] = decrypt_int ? K[9] : K[29]; assign K7[48] = decrypt_int ? K[30] : K[50]; assign K6[1] = decrypt_int ? K[34] : K[53]; assign K6[2] = decrypt_int ? K[55] : K[17]; assign K6[3] = decrypt_int ? K[13] : K[32]; assign K6[4] = decrypt_int ? K[47] : K[41]; assign K6[5] = decrypt_int ? K[25] : K[19]; assign K6[6] = decrypt_int ? K[53] : K[47]; assign K6[7] = decrypt_int ? K[39] : K[33]; assign K6[8] = decrypt_int ? K[18] : K[12]; assign K6[9] = decrypt_int ? K[41] : K[3]; assign K6[10] = decrypt_int ? K[3] : K[54]; assign K6[11] = decrypt_int ? K[26] : K[20]; assign K6[12] = decrypt_int ? K[6] : K[25]; assign K6[13] = decrypt_int ? K[40] : K[34]; assign K6[14] = decrypt_int ? K[12] : K[6]; assign K6[15] = decrypt_int ? K[20] : K[39]; assign K6[16] = decrypt_int ? K[46] : K[40]; assign K6[17] = decrypt_int ? K[4] : K[55]; assign K6[18] = decrypt_int ? K[17] : K[11]; assign K6[19] = decrypt_int ? K[48] : K[10]; assign K6[20] = decrypt_int ? K[10] : K[4]; assign K6[21] = decrypt_int ? K[11] : K[5]; assign K6[22] = decrypt_int ? K[19] : K[13]; assign K6[23] = decrypt_int ? K[27] : K[46]; assign K6[24] = decrypt_int ? K[32] : K[26]; assign K6[25] = decrypt_int ? K[21] : K[44]; assign K6[26] = decrypt_int ? K[43] : K[35]; assign K6[27] = decrypt_int ? K[37] : K[29]; assign K6[28] = decrypt_int ? K[52] : K[16]; assign K6[29] = decrypt_int ? K[8] : K[0]; assign K6[30] = decrypt_int ? K[9] : K[1]; assign K6[31] = decrypt_int ? K[30] : K[22]; assign K6[32] = decrypt_int ? K[14] : K[37]; assign K6[33] = decrypt_int ? K[36] : K[28]; assign K6[34] = decrypt_int ? K[49] : K[45]; assign K6[35] = decrypt_int ? K[51] : K[43]; assign K6[36] = decrypt_int ? K[15] : K[7]; assign K6[37] = decrypt_int ? K[42] : K[38]; assign K6[38] = decrypt_int ? K[22] : K[14]; assign K6[39] = decrypt_int ? K[7] : K[30]; assign K6[40] = decrypt_int ? K[16] : K[8]; assign K6[41] = decrypt_int ? K[31] : K[50]; assign K6[42] = decrypt_int ? K[50] : K[42]; assign K6[43] = decrypt_int ? K[1] : K[52]; assign K6[44] = decrypt_int ? K[28] : K[51]; assign K6[45] = decrypt_int ? K[29] : K[21]; assign K6[46] = decrypt_int ? K[45] : K[9]; assign K6[47] = decrypt_int ? K[23] : K[15]; assign K6[48] = decrypt_int ? K[44] : K[36]; assign K5[1] = decrypt_int ? K[48] : K[39]; assign K5[2] = decrypt_int ? K[12] : K[3]; assign K5[3] = decrypt_int ? K[27] : K[18]; assign K5[4] = decrypt_int ? K[4] : K[27]; assign K5[5] = decrypt_int ? K[39] : K[5]; assign K5[6] = decrypt_int ? K[10] : K[33]; assign K5[7] = decrypt_int ? K[53] : K[19]; assign K5[8] = decrypt_int ? K[32] : K[55]; assign K5[9] = decrypt_int ? K[55] : K[46]; assign K5[10] = decrypt_int ? K[17] : K[40]; assign K5[11] = decrypt_int ? K[40] : K[6]; assign K5[12] = decrypt_int ? K[20] : K[11]; assign K5[13] = decrypt_int ? K[54] : K[20]; assign K5[14] = decrypt_int ? K[26] : K[17]; assign K5[15] = decrypt_int ? K[34] : K[25]; assign K5[16] = decrypt_int ? K[3] : K[26]; assign K5[17] = decrypt_int ? K[18] : K[41]; assign K5[18] = decrypt_int ? K[6] : K[54]; assign K5[19] = decrypt_int ? K[5] : K[53]; assign K5[20] = decrypt_int ? K[24] : K[47]; assign K5[21] = decrypt_int ? K[25] : K[48]; assign K5[22] = decrypt_int ? K[33] : K[24]; assign K5[23] = decrypt_int ? K[41] : K[32]; assign K5[24] = decrypt_int ? K[46] : K[12]; assign K5[25] = decrypt_int ? K[35] : K[30]; assign K5[26] = decrypt_int ? K[2] : K[21]; assign K5[27] = decrypt_int ? K[51] : K[15]; assign K5[28] = decrypt_int ? K[7] : K[2]; assign K5[29] = decrypt_int ? K[22] : K[45]; assign K5[30] = decrypt_int ? K[23] : K[42]; assign K5[31] = decrypt_int ? K[44] : K[8]; assign K5[32] = decrypt_int ? K[28] : K[23]; assign K5[33] = decrypt_int ? K[50] : K[14]; assign K5[34] = decrypt_int ? K[8] : K[31]; assign K5[35] = decrypt_int ? K[38] : K[29]; assign K5[36] = decrypt_int ? K[29] : K[52]; assign K5[37] = decrypt_int ? K[1] : K[51]; assign K5[38] = decrypt_int ? K[36] : K[0]; assign K5[39] = decrypt_int ? K[21] : K[16]; assign K5[40] = decrypt_int ? K[30] : K[49]; assign K5[41] = decrypt_int ? K[45] : K[36]; assign K5[42] = decrypt_int ? K[9] : K[28]; assign K5[43] = decrypt_int ? K[15] : K[38]; assign K5[44] = decrypt_int ? K[42] : K[37]; assign K5[45] = decrypt_int ? K[43] : K[7]; assign K5[46] = decrypt_int ? K[0] : K[50]; assign K5[47] = decrypt_int ? K[37] : K[1]; assign K5[48] = decrypt_int ? K[31] : K[22]; assign K4[1] = decrypt_int ? K[5] : K[25]; assign K4[2] = decrypt_int ? K[26] : K[46]; assign K4[3] = decrypt_int ? K[41] : K[4]; assign K4[4] = decrypt_int ? K[18] : K[13]; assign K4[5] = decrypt_int ? K[53] : K[48]; assign K4[6] = decrypt_int ? K[24] : K[19]; assign K4[7] = decrypt_int ? K[10] : K[5]; assign K4[8] = decrypt_int ? K[46] : K[41]; assign K4[9] = decrypt_int ? K[12] : K[32]; assign K4[10] = decrypt_int ? K[6] : K[26]; assign K4[11] = decrypt_int ? K[54] : K[17]; assign K4[12] = decrypt_int ? K[34] : K[54]; assign K4[13] = decrypt_int ? K[11] : K[6]; assign K4[14] = decrypt_int ? K[40] : K[3]; assign K4[15] = decrypt_int ? K[48] : K[11]; assign K4[16] = decrypt_int ? K[17] : K[12]; assign K4[17] = decrypt_int ? K[32] : K[27]; assign K4[18] = decrypt_int ? K[20] : K[40]; assign K4[19] = decrypt_int ? K[19] : K[39]; assign K4[20] = decrypt_int ? K[13] : K[33]; assign K4[21] = decrypt_int ? K[39] : K[34]; assign K4[22] = decrypt_int ? K[47] : K[10]; assign K4[23] = decrypt_int ? K[55] : K[18]; assign K4[24] = decrypt_int ? K[3] : K[55]; assign K4[25] = decrypt_int ? K[49] : K[16]; assign K4[26] = decrypt_int ? K[16] : K[7]; assign K4[27] = decrypt_int ? K[38] : K[1]; assign K4[28] = decrypt_int ? K[21] : K[43]; assign K4[29] = decrypt_int ? K[36] : K[31]; assign K4[30] = decrypt_int ? K[37] : K[28]; assign K4[31] = decrypt_int ? K[31] : K[49]; assign K4[32] = decrypt_int ? K[42] : K[9]; assign K4[33] = decrypt_int ? K[9] : K[0]; assign K4[34] = decrypt_int ? K[22] : K[44]; assign K4[35] = decrypt_int ? K[52] : K[15]; assign K4[36] = decrypt_int ? K[43] : K[38]; assign K4[37] = decrypt_int ? K[15] : K[37]; assign K4[38] = decrypt_int ? K[50] : K[45]; assign K4[39] = decrypt_int ? K[35] : K[2]; assign K4[40] = decrypt_int ? K[44] : K[35]; assign K4[41] = decrypt_int ? K[0] : K[22]; assign K4[42] = decrypt_int ? K[23] : K[14]; assign K4[43] = decrypt_int ? K[29] : K[51]; assign K4[44] = decrypt_int ? K[1] : K[23]; assign K4[45] = decrypt_int ? K[2] : K[52]; assign K4[46] = decrypt_int ? K[14] : K[36]; assign K4[47] = decrypt_int ? K[51] : K[42]; assign K4[48] = decrypt_int ? K[45] : K[8]; assign K3[1] = decrypt_int ? K[19] : K[11]; assign K3[2] = decrypt_int ? K[40] : K[32]; assign K3[3] = decrypt_int ? K[55] : K[47]; assign K3[4] = decrypt_int ? K[32] : K[24]; assign K3[5] = decrypt_int ? K[10] : K[34]; assign K3[6] = decrypt_int ? K[13] : K[5]; assign K3[7] = decrypt_int ? K[24] : K[48]; assign K3[8] = decrypt_int ? K[3] : K[27]; assign K3[9] = decrypt_int ? K[26] : K[18]; assign K3[10] = decrypt_int ? K[20] : K[12]; assign K3[11] = decrypt_int ? K[11] : K[3]; assign K3[12] = decrypt_int ? K[48] : K[40]; assign K3[13] = decrypt_int ? K[25] : K[17]; assign K3[14] = decrypt_int ? K[54] : K[46]; assign K3[15] = decrypt_int ? K[5] : K[54]; assign K3[16] = decrypt_int ? K[6] : K[55]; assign K3[17] = decrypt_int ? K[46] : K[13]; assign K3[18] = decrypt_int ? K[34] : K[26]; assign K3[19] = decrypt_int ? K[33] : K[25]; assign K3[20] = decrypt_int ? K[27] : K[19]; assign K3[21] = decrypt_int ? K[53] : K[20]; assign K3[22] = decrypt_int ? K[4] : K[53]; assign K3[23] = decrypt_int ? K[12] : K[4]; assign K3[24] = decrypt_int ? K[17] : K[41]; assign K3[25] = decrypt_int ? K[8] : K[2]; assign K3[26] = decrypt_int ? K[30] : K[52]; assign K3[27] = decrypt_int ? K[52] : K[42]; assign K3[28] = decrypt_int ? K[35] : K[29]; assign K3[29] = decrypt_int ? K[50] : K[44]; assign K3[30] = decrypt_int ? K[51] : K[14]; assign K3[31] = decrypt_int ? K[45] : K[35]; assign K3[32] = decrypt_int ? K[1] : K[50]; assign K3[33] = decrypt_int ? K[23] : K[45]; assign K3[34] = decrypt_int ? K[36] : K[30]; assign K3[35] = decrypt_int ? K[7] : K[1]; assign K3[36] = decrypt_int ? K[2] : K[51]; assign K3[37] = decrypt_int ? K[29] : K[23]; assign K3[38] = decrypt_int ? K[9] : K[31]; assign K3[39] = decrypt_int ? K[49] : K[43]; assign K3[40] = decrypt_int ? K[31] : K[21]; assign K3[41] = decrypt_int ? K[14] : K[8]; assign K3[42] = decrypt_int ? K[37] : K[0]; assign K3[43] = decrypt_int ? K[43] : K[37]; assign K3[44] = decrypt_int ? K[15] : K[9]; assign K3[45] = decrypt_int ? K[16] : K[38]; assign K3[46] = decrypt_int ? K[28] : K[22]; assign K3[47] = decrypt_int ? K[38] : K[28]; assign K3[48] = decrypt_int ? K[0] : K[49]; assign K2[1] = decrypt_int ? K[33] : K[54]; assign K2[2] = decrypt_int ? K[54] : K[18]; assign K2[3] = decrypt_int ? K[12] : K[33]; assign K2[4] = decrypt_int ? K[46] : K[10]; assign K2[5] = decrypt_int ? K[24] : K[20]; assign K2[6] = decrypt_int ? K[27] : K[48]; assign K2[7] = decrypt_int ? K[13] : K[34]; assign K2[8] = decrypt_int ? K[17] : K[13]; assign K2[9] = decrypt_int ? K[40] : K[4]; assign K2[10] = decrypt_int ? K[34] : K[55]; assign K2[11] = decrypt_int ? K[25] : K[46]; assign K2[12] = decrypt_int ? K[5] : K[26]; assign K2[13] = decrypt_int ? K[39] : K[3]; assign K2[14] = decrypt_int ? K[11] : K[32]; assign K2[15] = decrypt_int ? K[19] : K[40]; assign K2[16] = decrypt_int ? K[20] : K[41]; assign K2[17] = decrypt_int ? K[3] : K[24]; assign K2[18] = decrypt_int ? K[48] : K[12]; assign K2[19] = decrypt_int ? K[47] : K[11]; assign K2[20] = decrypt_int ? K[41] : K[5]; assign K2[21] = decrypt_int ? K[10] : K[6]; assign K2[22] = decrypt_int ? K[18] : K[39]; assign K2[23] = decrypt_int ? K[26] : K[47]; assign K2[24] = decrypt_int ? K[6] : K[27]; assign K2[25] = decrypt_int ? K[22] : K[43]; assign K2[26] = decrypt_int ? K[44] : K[38]; assign K2[27] = decrypt_int ? K[7] : K[28]; assign K2[28] = decrypt_int ? K[49] : K[15]; assign K2[29] = decrypt_int ? K[9] : K[30]; assign K2[30] = decrypt_int ? K[38] : K[0]; assign K2[31] = decrypt_int ? K[0] : K[21]; assign K2[32] = decrypt_int ? K[15] : K[36]; assign K2[33] = decrypt_int ? K[37] : K[31]; assign K2[34] = decrypt_int ? K[50] : K[16]; assign K2[35] = decrypt_int ? K[21] : K[42]; assign K2[36] = decrypt_int ? K[16] : K[37]; assign K2[37] = decrypt_int ? K[43] : K[9]; assign K2[38] = decrypt_int ? K[23] : K[44]; assign K2[39] = decrypt_int ? K[8] : K[29]; assign K2[40] = decrypt_int ? K[45] : K[7]; assign K2[41] = decrypt_int ? K[28] : K[49]; assign K2[42] = decrypt_int ? K[51] : K[45]; assign K2[43] = decrypt_int ? K[2] : K[23]; assign K2[44] = decrypt_int ? K[29] : K[50]; assign K2[45] = decrypt_int ? K[30] : K[51]; assign K2[46] = decrypt_int ? K[42] : K[8]; assign K2[47] = decrypt_int ? K[52] : K[14]; assign K2[48] = decrypt_int ? K[14] : K[35]; assign K1[1] = decrypt_int ? K[40] : K[47]; assign K1[2] = decrypt_int ? K[4] : K[11]; assign K1[3] = decrypt_int ? K[19] : K[26]; assign K1[4] = decrypt_int ? K[53] : K[3]; assign K1[5] = decrypt_int ? K[6] : K[13]; assign K1[6] = decrypt_int ? K[34] : K[41]; assign K1[7] = decrypt_int ? K[20] : K[27]; assign K1[8] = decrypt_int ? K[24] : K[6]; assign K1[9] = decrypt_int ? K[47] : K[54]; assign K1[10] = decrypt_int ? K[41] : K[48]; assign K1[11] = decrypt_int ? K[32] : K[39]; assign K1[12] = decrypt_int ? K[12] : K[19]; assign K1[13] = decrypt_int ? K[46] : K[53]; assign K1[14] = decrypt_int ? K[18] : K[25]; assign K1[15] = decrypt_int ? K[26] : K[33]; assign K1[16] = decrypt_int ? K[27] : K[34]; assign K1[17] = decrypt_int ? K[10] : K[17]; assign K1[18] = decrypt_int ? K[55] : K[5]; assign K1[19] = decrypt_int ? K[54] : K[4]; assign K1[20] = decrypt_int ? K[48] : K[55]; assign K1[21] = decrypt_int ? K[17] : K[24]; assign K1[22] = decrypt_int ? K[25] : K[32]; assign K1[23] = decrypt_int ? K[33] : K[40]; assign K1[24] = decrypt_int ? K[13] : K[20]; assign K1[25] = decrypt_int ? K[29] : K[36]; assign K1[26] = decrypt_int ? K[51] : K[31]; assign K1[27] = decrypt_int ? K[14] : K[21]; assign K1[28] = decrypt_int ? K[1] : K[8]; assign K1[29] = decrypt_int ? K[16] : K[23]; assign K1[30] = decrypt_int ? K[45] : K[52]; assign K1[31] = decrypt_int ? K[7] : K[14]; assign K1[32] = decrypt_int ? K[22] : K[29]; assign K1[33] = decrypt_int ? K[44] : K[51]; assign K1[34] = decrypt_int ? K[2] : K[9]; assign K1[35] = decrypt_int ? K[28] : K[35]; assign K1[36] = decrypt_int ? K[23] : K[30]; assign K1[37] = decrypt_int ? K[50] : K[2]; assign K1[38] = decrypt_int ? K[30] : K[37]; assign K1[39] = decrypt_int ? K[15] : K[22]; assign K1[40] = decrypt_int ? K[52] : K[0]; assign K1[41] = decrypt_int ? K[35] : K[42]; assign K1[42] = decrypt_int ? K[31] : K[38]; assign K1[43] = decrypt_int ? K[9] : K[16]; assign K1[44] = decrypt_int ? K[36] : K[43]; assign K1[45] = decrypt_int ? K[37] : K[44]; assign K1[46] = decrypt_int ? K[49] : K[1]; assign K1[47] = decrypt_int ? K[0] : K[7]; assign K1[48] = decrypt_int ? K[21] : K[28]; endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox1(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 14; 1: dout = 4; 2: dout = 13; 3: dout = 1; 4: dout = 2; 5: dout = 15; 6: dout = 11; 7: dout = 8; 8: dout = 3; 9: dout = 10; 10: dout = 6; 11: dout = 12; 12: dout = 5; 13: dout = 9; 14: dout = 0; 15: dout = 7; 16: dout = 0; 17: dout = 15; 18: dout = 7; 19: dout = 4; 20: dout = 14; 21: dout = 2; 22: dout = 13; 23: dout = 1; 24: dout = 10; 25: dout = 6; 26: dout = 12; 27: dout = 11; 28: dout = 9; 29: dout = 5; 30: dout = 3; 31: dout = 8; 32: dout = 4; 33: dout = 1; 34: dout = 14; 35: dout = 8; 36: dout = 13; 37: dout = 6; 38: dout = 2; 39: dout = 11; 40: dout = 15; 41: dout = 12; 42: dout = 9; 43: dout = 7; 44: dout = 3; 45: dout = 10; 46: dout = 5; 47: dout = 0; 48: dout = 15; 49: dout = 12; 50: dout = 8; 51: dout = 2; 52: dout = 4; 53: dout = 9; 54: dout = 1; 55: dout = 7; 56: dout = 5; 57: dout = 11; 58: dout = 3; 59: dout = 14; 60: dout = 10; 61: dout = 0; 62: dout = 6; 63: dout = 13; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox2(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 15; 1: dout = 1; 2: dout = 8; 3: dout = 14; 4: dout = 6; 5: dout = 11; 6: dout = 3; 7: dout = 4; 8: dout = 9; 9: dout = 7; 10: dout = 2; 11: dout = 13; 12: dout = 12; 13: dout = 0; 14: dout = 5; 15: dout = 10; 16: dout = 3; 17: dout = 13; 18: dout = 4; 19: dout = 7; 20: dout = 15; 21: dout = 2; 22: dout = 8; 23: dout = 14; 24: dout = 12; 25: dout = 0; 26: dout = 1; 27: dout = 10; 28: dout = 6; 29: dout = 9; 30: dout = 11; 31: dout = 5; 32: dout = 0; 33: dout = 14; 34: dout = 7; 35: dout = 11; 36: dout = 10; 37: dout = 4; 38: dout = 13; 39: dout = 1; 40: dout = 5; 41: dout = 8; 42: dout = 12; 43: dout = 6; 44: dout = 9; 45: dout = 3; 46: dout = 2; 47: dout = 15; 48: dout = 13; 49: dout = 8; 50: dout = 10; 51: dout = 1; 52: dout = 3; 53: dout = 15; 54: dout = 4; 55: dout = 2; 56: dout = 11; 57: dout = 6; 58: dout = 7; 59: dout = 12; 60: dout = 0; 61: dout = 5; 62: dout = 14; 63: dout = 9; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox3(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 10; 1: dout = 0; 2: dout = 9; 3: dout = 14; 4: dout = 6; 5: dout = 3; 6: dout = 15; 7: dout = 5; 8: dout = 1; 9: dout = 13; 10: dout = 12; 11: dout = 7; 12: dout = 11; 13: dout = 4; 14: dout = 2; 15: dout = 8; 16: dout = 13; 17: dout = 7; 18: dout = 0; 19: dout = 9; 20: dout = 3; 21: dout = 4; 22: dout = 6; 23: dout = 10; 24: dout = 2; 25: dout = 8; 26: dout = 5; 27: dout = 14; 28: dout = 12; 29: dout = 11; 30: dout = 15; 31: dout = 1; 32: dout = 13; 33: dout = 6; 34: dout = 4; 35: dout = 9; 36: dout = 8; 37: dout = 15; 38: dout = 3; 39: dout = 0; 40: dout = 11; 41: dout = 1; 42: dout = 2; 43: dout = 12; 44: dout = 5; 45: dout = 10; 46: dout = 14; 47: dout = 7; 48: dout = 1; 49: dout = 10; 50: dout = 13; 51: dout = 0; 52: dout = 6; 53: dout = 9; 54: dout = 8; 55: dout = 7; 56: dout = 4; 57: dout = 15; 58: dout = 14; 59: dout = 3; 60: dout = 11; 61: dout = 5; 62: dout = 2; 63: dout = 12; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox4(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 7; 1: dout = 13; 2: dout = 14; 3: dout = 3; 4: dout = 0; 5: dout = 6; 6: dout = 9; 7: dout = 10; 8: dout = 1; 9: dout = 2; 10: dout = 8; 11: dout = 5; 12: dout = 11; 13: dout = 12; 14: dout = 4; 15: dout = 15; 16: dout = 13; 17: dout = 8; 18: dout = 11; 19: dout = 5; 20: dout = 6; 21: dout = 15; 22: dout = 0; 23: dout = 3; 24: dout = 4; 25: dout = 7; 26: dout = 2; 27: dout = 12; 28: dout = 1; 29: dout = 10; 30: dout = 14; 31: dout = 9; 32: dout = 10; 33: dout = 6; 34: dout = 9; 35: dout = 0; 36: dout = 12; 37: dout = 11; 38: dout = 7; 39: dout = 13; 40: dout = 15; 41: dout = 1; 42: dout = 3; 43: dout = 14; 44: dout = 5; 45: dout = 2; 46: dout = 8; 47: dout = 4; 48: dout = 3; 49: dout = 15; 50: dout = 0; 51: dout = 6; 52: dout = 10; 53: dout = 1; 54: dout = 13; 55: dout = 8; 56: dout = 9; 57: dout = 4; 58: dout = 5; 59: dout = 11; 60: dout = 12; 61: dout = 7; 62: dout = 2; 63: dout = 14; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox5(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 2; 1: dout = 12; 2: dout = 4; 3: dout = 1; 4: dout = 7; 5: dout = 10; 6: dout = 11; 7: dout = 6; 8: dout = 8; 9: dout = 5; 10: dout = 3; 11: dout = 15; 12: dout = 13; 13: dout = 0; 14: dout = 14; 15: dout = 9; 16: dout = 14; 17: dout = 11; 18: dout = 2; 19: dout = 12; 20: dout = 4; 21: dout = 7; 22: dout = 13; 23: dout = 1; 24: dout = 5; 25: dout = 0; 26: dout = 15; 27: dout = 10; 28: dout = 3; 29: dout = 9; 30: dout = 8; 31: dout = 6; 32: dout = 4; 33: dout = 2; 34: dout = 1; 35: dout = 11; 36: dout = 10; 37: dout = 13; 38: dout = 7; 39: dout = 8; 40: dout = 15; 41: dout = 9; 42: dout = 12; 43: dout = 5; 44: dout = 6; 45: dout = 3; 46: dout = 0; 47: dout = 14; 48: dout = 11; 49: dout = 8; 50: dout = 12; 51: dout = 7; 52: dout = 1; 53: dout = 14; 54: dout = 2; 55: dout = 13; 56: dout = 6; 57: dout = 15; 58: dout = 0; 59: dout = 9; 60: dout = 10; 61: dout = 4; 62: dout = 5; 63: dout = 3; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox6(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 12; 1: dout = 1; 2: dout = 10; 3: dout = 15; 4: dout = 9; 5: dout = 2; 6: dout = 6; 7: dout = 8; 8: dout = 0; 9: dout = 13; 10: dout = 3; 11: dout = 4; 12: dout = 14; 13: dout = 7; 14: dout = 5; 15: dout = 11; 16: dout = 10; 17: dout = 15; 18: dout = 4; 19: dout = 2; 20: dout = 7; 21: dout = 12; 22: dout = 9; 23: dout = 5; 24: dout = 6; 25: dout = 1; 26: dout = 13; 27: dout = 14; 28: dout = 0; 29: dout = 11; 30: dout = 3; 31: dout = 8; 32: dout = 9; 33: dout = 14; 34: dout = 15; 35: dout = 5; 36: dout = 2; 37: dout = 8; 38: dout = 12; 39: dout = 3; 40: dout = 7; 41: dout = 0; 42: dout = 4; 43: dout = 10; 44: dout = 1; 45: dout = 13; 46: dout = 11; 47: dout = 6; 48: dout = 4; 49: dout = 3; 50: dout = 2; 51: dout = 12; 52: dout = 9; 53: dout = 5; 54: dout = 15; 55: dout = 10; 56: dout = 11; 57: dout = 14; 58: dout = 1; 59: dout = 7; 60: dout = 6; 61: dout = 0; 62: dout = 8; 63: dout = 13; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox7(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 4; 1: dout = 11; 2: dout = 2; 3: dout = 14; 4: dout = 15; 5: dout = 0; 6: dout = 8; 7: dout = 13; 8: dout = 3; 9: dout = 12; 10: dout = 9; 11: dout = 7; 12: dout = 5; 13: dout = 10; 14: dout = 6; 15: dout = 1; 16: dout = 13; 17: dout = 0; 18: dout = 11; 19: dout = 7; 20: dout = 4; 21: dout = 9; 22: dout = 1; 23: dout = 10; 24: dout = 14; 25: dout = 3; 26: dout = 5; 27: dout = 12; 28: dout = 2; 29: dout = 15; 30: dout = 8; 31: dout = 6; 32: dout = 1; 33: dout = 4; 34: dout = 11; 35: dout = 13; 36: dout = 12; 37: dout = 3; 38: dout = 7; 39: dout = 14; 40: dout = 10; 41: dout = 15; 42: dout = 6; 43: dout = 8; 44: dout = 0; 45: dout = 5; 46: dout = 9; 47: dout = 2; 48: dout = 6; 49: dout = 11; 50: dout = 13; 51: dout = 8; 52: dout = 1; 53: dout = 4; 54: dout = 10; 55: dout = 7; 56: dout = 9; 57: dout = 5; 58: dout = 0; 59: dout = 15; 60: dout = 14; 61: dout = 2; 62: dout = 3; 63: dout = 12; endcase end endmodule
///////////////////////////////////////////////////////////////////// //// //// //// SBOX //// //// The SBOX is essentially a 64x4 ROM //// //// //// //// Author: Rudolf Usselmann //// //// rudi@asics.ws //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2001 Rudolf Usselmann //// //// rudi@asics.ws //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer.//// //// //// //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// //// POSSIBILITY OF SUCH DAMAGE. //// //// //// ///////////////////////////////////////////////////////////////////// module sbox8(addr, dout); /* verilator lint_off LITENDIAN */ input [1:6] addr; output [1:4] dout; reg [1:4] dout; /* verilator lint_on LITENDIAN */ always @(addr) begin case ({addr[1], addr[6], addr[2:5]}) //synopsys full_case parallel_case 0: dout = 13; 1: dout = 2; 2: dout = 8; 3: dout = 4; 4: dout = 6; 5: dout = 15; 6: dout = 11; 7: dout = 1; 8: dout = 10; 9: dout = 9; 10: dout = 3; 11: dout = 14; 12: dout = 5; 13: dout = 0; 14: dout = 12; 15: dout = 7; 16: dout = 1; 17: dout = 15; 18: dout = 13; 19: dout = 8; 20: dout = 10; 21: dout = 3; 22: dout = 7; 23: dout = 4; 24: dout = 12; 25: dout = 5; 26: dout = 6; 27: dout = 11; 28: dout = 0; 29: dout = 14; 30: dout = 9; 31: dout = 2; 32: dout = 7; 33: dout = 11; 34: dout = 4; 35: dout = 1; 36: dout = 9; 37: dout = 12; 38: dout = 14; 39: dout = 2; 40: dout = 0; 41: dout = 6; 42: dout = 10; 43: dout = 13; 44: dout = 15; 45: dout = 3; 46: dout = 5; 47: dout = 8; 48: dout = 2; 49: dout = 1; 50: dout = 14; 51: dout = 7; 52: dout = 4; 53: dout = 10; 54: dout = 8; 55: dout = 13; 56: dout = 15; 57: dout = 12; 58: dout = 9; 59: dout = 0; 60: dout = 3; 61: dout = 5; 62: dout = 6; 63: dout = 11; endcase end endmodule
// // Copyright (C) 2018 Massachusetts Institute of Technology // // File : md5_top.v // Project : Common Evaluation Platform (CEP) // Description : This file provides a wishbone based-MD5 core // module md5_top( wb_adr_i, wb_cyc_i, wb_dat_i, wb_sel_i, wb_stb_i, wb_we_i, wb_ack_o, wb_err_o, wb_dat_o, wb_clk_i, wb_rst_i, int_o ); parameter dw = 32; parameter aw = 32; input [aw-1:0] wb_adr_i; input wb_cyc_i; input [dw-1:0] wb_dat_i; input [3:0] wb_sel_i; input wb_stb_i; input wb_we_i; output wb_ack_o; output wb_err_o; output reg [dw-1:0] wb_dat_o; output int_o; input wb_clk_i; input wb_rst_i; assign wb_ack_o = 1'b1; assign wb_err_o = 1'b0; assign int_o = 1'b0; // Internal registers reg startHash, startHash_r; reg [31:0] data [15:0]; reg message_reset, message_reset_r; wire [511:0] bigData = {data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15]}; wire [127:0] hash; wire ready; wire hashValid; // Implement MD5 I/O memory map interface // Write side always @(posedge wb_clk_i) begin if(wb_rst_i) begin startHash <= 0; startHash_r <= 0; message_reset <= 0; message_reset_r <= 0; data[0] <= 0; data[1] <= 0; data[2] <= 0; data[3] <= 0; data[4] <= 0; data[5] <= 0; data[6] <= 0; data[7] <= 0; data[8] <= 0; data[9] <= 0; data[10] <= 0; data[11] <= 0; data[12] <= 0; data[13] <= 0; data[14] <= 0; data[15] <= 0; end else begin // Generate a registered versions of startHash and message_reset startHash_r <= startHash; message_reset_r <= message_reset; // Perform a write if(wb_stb_i & wb_we_i) begin case(wb_adr_i[6:2]) 0: startHash <= wb_dat_i[0]; 1: data[15] <= wb_dat_i; 2: data[14] <= wb_dat_i; 3: data[13] <= wb_dat_i; 4: data[12] <= wb_dat_i; 5: data[11] <= wb_dat_i; 6: data[10] <= wb_dat_i; 7: data[9] <= wb_dat_i; 8: data[8] <= wb_dat_i; 9: data[7] <= wb_dat_i; 10: data[6] <= wb_dat_i; 11: data[5] <= wb_dat_i; 12: data[4] <= wb_dat_i; 13: data[3] <= wb_dat_i; 14: data[2] <= wb_dat_i; 15: data[1] <= wb_dat_i; 16: data[0] <= wb_dat_i; 22: message_reset <= wb_dat_i[0]; default: ; endcase end else begin // if(wb_stb_i & wb_we_i) startHash <= 1'b0; message_reset <= 1'b0; end // end else end // else end // end always // Implement MD5 I/O memory map interface // Read side always @(*) begin case(wb_adr_i[6:2]) 0: wb_dat_o = {31'b0, ready}; 1: wb_dat_o = data[15]; 2: wb_dat_o = data[14]; 3: wb_dat_o = data[13]; 4: wb_dat_o = data[12]; 5: wb_dat_o = data[11]; 6: wb_dat_o = data[10]; 7: wb_dat_o = data[9]; 8: wb_dat_o = data[8]; 9: wb_dat_o = data[7]; 10: wb_dat_o = data[6]; 11: wb_dat_o = data[5]; 12: wb_dat_o = data[4]; 13: wb_dat_o = data[3]; 14: wb_dat_o = data[2]; 15: wb_dat_o = data[1]; 16: wb_dat_o = data[0]; 17: wb_dat_o = {31'b0, hashValid}; 21: wb_dat_o = hash[127:96]; 20: wb_dat_o = hash[95:64]; 19: wb_dat_o = hash[63:32]; 18: wb_dat_o = hash[31:0]; default: wb_dat_o = 32'b0; endcase end pancham pancham( .clk(wb_clk_i), .rst(wb_rst_i | (message_reset & ~message_reset_r)), .msg_padded(bigData), .msg_in_valid(startHash && ~startHash_r), .msg_output(hash), .msg_out_valid(hashValid), .ready(ready) ); endmodule
/***************************************************************** Pancham is an MD5 compliant IP core for cryptographic applications. Copyright (C) 2003 Swapnajit Mittra, Project VeriPage (Contact email: verilog_tutorial at hotmail.com Website : http://www.angelfire.com/ca/verilog) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc. 59 Temple Place, Suite 330 Boston, MA 02111-1307 USA ******************************************************************/ /* * This is the main module that computes a 128-bit message * digest from a maximum of 512-bit long input message using * MD5 algorithm. * * Modified by Matthew Hicks (mdhicks@gmail.com) * Input from 128-bit to 512-bit * Hold valid outputs * Carry over constants between encryptions * Support for arbitrary size encryption * Address some Verilator warnings * Convert vector direction * */ // ROUNDs `define ROUND1 2'b00 `define ROUND2 2'b01 `define ROUND3 2'b10 `define ROUND4 2'b11 // T_i = 4294967296*abs(sin(i)) `define T_1 32'hd76aa478 `define T_2 32'he8c7b756 `define T_3 32'h242070db `define T_4 32'hc1bdceee `define T_5 32'hf57c0faf `define T_6 32'h4787c62a `define T_7 32'ha8304613 `define T_8 32'hfd469501 `define T_9 32'h698098d8 `define T_10 32'h8b44f7af `define T_11 32'hffff5bb1 `define T_12 32'h895cd7be `define T_13 32'h6b901122 `define T_14 32'hfd987193 `define T_15 32'ha679438e `define T_16 32'h49b40821 `define T_17 32'hf61e2562 `define T_18 32'hc040b340 `define T_19 32'h265e5a51 `define T_20 32'he9b6c7aa `define T_21 32'hd62f105d `define T_22 32'h2441453 `define T_23 32'hd8a1e681 `define T_24 32'he7d3fbc8 `define T_25 32'h21e1cde6 `define T_26 32'hc33707d6 `define T_27 32'hf4d50d87 `define T_28 32'h455a14ed `define T_29 32'ha9e3e905 `define T_30 32'hfcefa3f8 `define T_31 32'h676f02d9 `define T_32 32'h8d2a4c8a `define T_33 32'hfffa3942 `define T_34 32'h8771f681 `define T_35 32'h6d9d6122 `define T_36 32'hfde5380c `define T_37 32'ha4beea44 `define T_38 32'h4bdecfa9 `define T_39 32'hf6bb4b60 `define T_40 32'hbebfbc70 `define T_41 32'h289b7ec6 `define T_42 32'heaa127fa `define T_43 32'hd4ef3085 `define T_44 32'h4881d05 `define T_45 32'hd9d4d039 `define T_46 32'he6db99e5 `define T_47 32'h1fa27cf8 `define T_48 32'hc4ac5665 `define T_49 32'hf4292244 `define T_50 32'h432aff97 `define T_51 32'hab9423a7 `define T_52 32'hfc93a039 `define T_53 32'h655b59c3 `define T_54 32'h8f0ccc92 `define T_55 32'hffeff47d `define T_56 32'h85845dd1 `define T_57 32'h6fa87e4f `define T_58 32'hfe2ce6e0 `define T_59 32'ha3014314 `define T_60 32'h4e0811a1 `define T_61 32'hf7537e82 `define T_62 32'hbd3af235 `define T_63 32'h2ad7d2bb `define T_64 32'heb86d391 /* verilator lint_off UNOPTFLAT */ module pancham ( clk , rst , msg_padded , msg_in_valid , msg_output , msg_out_valid , ready ); //-------------------------------- // // Input/Output declarations // //-------------------------------- input clk; // input clock input rst; // global rst input [511:0] msg_padded; // input message, already padded input msg_in_valid; // input message is valid, active high output [127:0] msg_output; // output message, always 128 bit wide output msg_out_valid; // if asserted, output message is valid output ready; // the core is ready for an input message //-------------------------------- // // Variable declarations // //-------------------------------- // inputs wire clk; wire rst; wire [511:0] msg_padded; wire msg_in_valid; // output wire [127:0] msg_output; reg msg_out_valid; wire ready; // scratch pads reg [1:0] round; reg [31:0] a; reg [31:0] A; reg [31:0] AA; reg [31:0] next_A; reg [31:0] b; reg [31:0] B; reg [31:0] BB; reg [31:0] next_B; reg [31:0] c; reg [31:0] C; reg [31:0] CC; reg [31:0] next_C; reg [31:0] d; reg [31:0] D; reg [31:0] DD; reg [31:0] next_D; reg [31:0] m; reg [31:0] s; reg [31:0] t; reg [3:0] phase; // Counter to determine 16 phases within each round. wire [31:0] next_a; reg [7:0] current_state; reg [7:0] next_state; reg [8*11:1] ascii_state; //-------------------------------- // // Parameter definitions // //-------------------------------- parameter SALT_A = 32'h67452301; parameter SALT_B = 32'hefcdab89; parameter SALT_C = 32'h98badcfe; parameter SALT_D = 32'h10325476; parameter ONE = 72'h1; parameter IDLE_BIT = 0; parameter IDLE = ONE << IDLE_BIT; parameter ROUND1_BIT = 1; parameter ROUND1 = ONE << ROUND1_BIT; parameter ROUND2_BIT = 2; parameter ROUND2 = ONE << ROUND2_BIT; parameter ROUND3_BIT = 3; parameter ROUND3 = ONE << ROUND3_BIT; parameter ROUND4_BIT = 4; parameter ROUND4 = ONE << ROUND4_BIT; parameter FINISH_OFF_BIT = 5; parameter FINISH_OFF = ONE << FINISH_OFF_BIT; parameter TURN_ARND_BIT = 6; parameter TURN_ARND = ONE << TURN_ARND_BIT; //-------------------------------- // // Submodule instantiation // //-------------------------------- pancham_round ROUND ( .a (a ) , .b (b ) , .c (c ) , .d (d ) , .m (m ) , .s (s ) , .t (t ) , .round (round) , .next_a (next_a) ); wire [31:0] m0 = msg_padded[31:0]; wire [31:0] m1 = msg_padded[63:32]; wire [31:0] m2 = msg_padded[95:64]; wire [31:0] m3 = msg_padded[127:96]; wire [31:0] m4 = msg_padded[159:128]; wire [31:0] m5 = msg_padded[191:160]; wire [31:0] m6 = msg_padded[223:192]; wire [31:0] m7 = msg_padded[255:224]; wire [31:0] m8 = msg_padded[287:256]; wire [31:0] m9 = msg_padded[319:288]; wire [31:0] m10 = msg_padded[351:320]; wire [31:0] m11 = msg_padded[383:352]; wire [31:0] m12 = msg_padded[415:384]; wire [31:0] m13 = msg_padded[447:416]; wire [31:0] m14 = msg_padded[479:448]; wire [31:0] m15 = msg_padded[511:480]; //-------------------------------- // // Actual code starts here // //-------------------------------- always @(current_state or msg_in_valid or A or B or C or D or phase or msg_padded or next_a or AA or BB or CC or DD ) begin // { round = `ROUND1; next_A = A; next_B = B; next_C = C; next_D = D; a = 32'h0; b = 32'h0; c = 32'h0; d = 32'h0; m = 32'h0; s = 32'h0; t = 32'h0; next_state = current_state; case (1'b1) // synopsys full_case parallel_case current_state[IDLE_BIT]: begin // { // synopsys translate_off ascii_state = "IDLE"; // synopsys translate_on if (msg_in_valid) next_state = ROUND1[7:0]; end // } //---------------------------------------------------------------- //--------------------------- ROUND 1 ---------------------------- //---------------------------------------------------------------- current_state[ROUND1_BIT]: begin // { // synopsys translate_off ascii_state = "ROUND1"; // synopsys translate_on round = `ROUND1; case (phase) 4'b0000: begin a=A; b=B; c=C; d=D; m=m0; s=32'd07; t= `T_1; next_A=next_a; end 4'b0001: begin a=D; b=A; c=B; d=C; m=m1; s=32'd12; t= `T_2; next_D=next_a; end 4'b0010: begin a=C; b=D; c=A; d=B; m=m2; s=32'd17; t= `T_3; next_C=next_a; end 4'b0011: begin a=B; b=C; c=D; d=A; m=m3; s=32'd22; t= `T_4; next_B=next_a; end 4'b0100: begin a=A; b=B; c=C; d=D; m=m4; s=32'd07; t= `T_5; next_A=next_a; end 4'b0101: begin a=D; b=A; c=B; d=C; m=m5; s=32'd12; t= `T_6; next_D=next_a; end 4'b0110: begin a=C; b=D; c=A; d=B; m=m6; s=32'd17; t= `T_7; next_C=next_a; end 4'b0111: begin a=B; b=C; c=D; d=A; m=m7; s=32'd22; t= `T_8; next_B=next_a; end 4'b1000: begin a=A; b=B; c=C; d=D; m=m8; s=32'd07; t= `T_9; next_A=next_a; end 4'b1001: begin a=D; b=A; c=B; d=C; m=m9; s=32'd12; t=`T_10; next_D=next_a; end 4'b1010: begin a=C; b=D; c=A; d=B; m=m10; s=32'd17; t=`T_11; next_C=next_a; end 4'b1011: begin a=B; b=C; c=D; d=A; m=m11; s=32'd22; t=`T_12; next_B=next_a; end 4'b1100: begin a=A; b=B; c=C; d=D; m=m12; s=32'd7; t=`T_13; next_A=next_a; end 4'b1101: begin a=D; b=A; c=B; d=C; m=m13; s=32'd12; t=`T_14; next_D=next_a; end 4'b1110: begin a=C; b=D; c=A; d=B; m=m14; s=32'd17; t=`T_15; next_C=next_a; end 4'b1111: begin a=B; b=C; c=D; d=A; m=m15; s=32'd22; t=`T_16; next_B=next_a; end endcase if (phase == 4'b1111) next_state = ROUND2[7:0]; end // } //---------------------------------------------------------------- //--------------------------- ROUND 2 ---------------------------- //---------------------------------------------------------------- current_state[ROUND2_BIT]: begin // { // synopsys translate_off ascii_state = "ROUND2"; // synopsys translate_on round = `ROUND2; case (phase) 4'b0000: begin a=A; b=B; c=C; d=D; m=m1; s=32'd05; t=`T_17; next_A=next_a; end 4'b0001: begin a=D; b=A; c=B; d=C; m=m6; s=32'd09; t=`T_18; next_D=next_a; end 4'b0010: begin a=C; b=D; c=A; d=B; m=m11; s=32'd14; t=`T_19; next_C=next_a; end 4'b0011: begin a=B; b=C; c=D; d=A; m=m0; s=32'd20; t=`T_20; next_B=next_a; end 4'b0100: begin a=A; b=B; c=C; d=D; m=m5; s=32'd05; t=`T_21; next_A=next_a; end 4'b0101: begin a=D; b=A; c=B; d=C; m=m10; s=32'd09; t=`T_22; next_D=next_a; end 4'b0110: begin a=C; b=D; c=A; d=B; m=m15; s=32'd14; t=`T_23; next_C=next_a; end 4'b0111: begin a=B; b=C; c=D; d=A; m=m4; s=32'd20; t=`T_24; next_B=next_a; end 4'b1000: begin a=A; b=B; c=C; d=D; m=m9; s=32'd05; t=`T_25; next_A=next_a; end 4'b1001: begin a=D; b=A; c=B; d=C; m=m14; s=32'd9; t=`T_26; next_D=next_a; end 4'b1010: begin a=C; b=D; c=A; d=B; m=m3; s=32'd14; t=`T_27; next_C=next_a; end 4'b1011: begin a=B; b=C; c=D; d=A; m=m8; s=32'd20; t=`T_28; next_B=next_a; end 4'b1100: begin a=A; b=B; c=C; d=D; m=m13; s=32'd05; t=`T_29; next_A=next_a; end 4'b1101: begin a=D; b=A; c=B; d=C; m=m2; s=32'd09; t=`T_30; next_D=next_a; end 4'b1110: begin a=C; b=D; c=A; d=B; m=m7; s=32'd14; t=`T_31; next_C=next_a; end 4'b1111: begin a=B; b=C; c=D; d=A; m=m12; s=32'd20; t=`T_32; next_B=next_a; end endcase if (phase == 4'b1111) next_state = ROUND3[7:0]; end // } //---------------------------------------------------------------- //--------------------------- ROUND 3 ---------------------------- //---------------------------------------------------------------- current_state[ROUND3_BIT]: begin // { // synopsys translate_off ascii_state = "ROUND3"; // synopsys translate_on round = `ROUND3; case (phase) 4'b0000: begin a=A; b=B; c=C; d=D; m=m5; s=32'd04; t=`T_33; next_A=next_a; end 4'b0001: begin a=D; b=A; c=B; d=C; m=m8; s=32'd11; t=`T_34; next_D=next_a; end 4'b0010: begin a=C; b=D; c=A; d=B; m=m11; s=32'd16; t=`T_35; next_C=next_a; end 4'b0011: begin a=B; b=C; c=D; d=A; m=m14; s=32'd23; t=`T_36; next_B=next_a; end 4'b0100: begin a=A; b=B; c=C; d=D; m=m1; s=32'd04; t=`T_37; next_A=next_a; end 4'b0101: begin a=D; b=A; c=B; d=C; m=m4; s=32'd11; t=`T_38; next_D=next_a; end 4'b0110: begin a=C; b=D; c=A; d=B; m=m7; s=32'd16; t=`T_39; next_C=next_a; end 4'b0111: begin a=B; b=C; c=D; d=A; m=m10; s=32'd23; t=`T_40; next_B=next_a; end 4'b1000: begin a=A; b=B; c=C; d=D; m=m13; s=32'd04; t=`T_41; next_A=next_a; end 4'b1001: begin a=D; b=A; c=B; d=C; m=m0; s=32'd11; t=`T_42; next_D=next_a; end 4'b1010: begin a=C; b=D; c=A; d=B; m=m3; s=32'd16; t=`T_43; next_C=next_a; end 4'b1011: begin a=B; b=C; c=D; d=A; m=m6; s=32'd23; t=`T_44; next_B=next_a; end 4'b1100: begin a=A; b=B; c=C; d=D; m=m9; s=32'd04; t=`T_45; next_A=next_a; end 4'b1101: begin a=D; b=A; c=B; d=C; m=m12; s=32'd11; t=`T_46; next_D=next_a; end 4'b1110: begin a=C; b=D; c=A; d=B; m=m15; s=32'd16; t=`T_47; next_C=next_a; end 4'b1111: begin a=B; b=C; c=D; d=A; m=m2; s=32'd23; t=`T_48; next_B=next_a; end endcase if (phase == 4'b1111) next_state = ROUND4[7:0]; end // } //---------------------------------------------------------------- //--------------------------- ROUND 4 ---------------------------- //---------------------------------------------------------------- current_state[ROUND4_BIT]: begin // { // synopsys translate_off ascii_state = "ROUND4"; // synopsys translate_on round = `ROUND4; case (phase) 4'b0000: begin a=A; b=B; c=C; d=D; m=m0; s=32'd06; t=`T_49; next_A=next_a; end 4'b0001: begin a=D; b=A; c=B; d=C; m=m7; s=32'd10; t=`T_50; next_D=next_a; end 4'b0010: begin a=C; b=D; c=A; d=B; m=m14; s=32'd15; t=`T_51; next_C=next_a; end 4'b0011: begin a=B; b=C; c=D; d=A; m=m5; s=32'd21; t=`T_52; next_B=next_a; end 4'b0100: begin a=A; b=B; c=C; d=D; m=m12; s=32'd06; t=`T_53; next_A=next_a; end 4'b0101: begin a=D; b=A; c=B; d=C; m=m3; s=32'd10; t=`T_54; next_D=next_a; end 4'b0110: begin a=C; b=D; c=A; d=B; m=m10; s=32'd15; t=`T_55; next_C=next_a; end 4'b0111: begin a=B; b=C; c=D; d=A; m=m1; s=32'd21; t=`T_56; next_B=next_a; end 4'b1000: begin a=A; b=B; c=C; d=D; m=m8; s=32'd06; t=`T_57; next_A=next_a; end 4'b1001: begin a=D; b=A; c=B; d=C; m=m15; s=32'd10; t=`T_58; next_D=next_a; end 4'b1010: begin a=C; b=D; c=A; d=B; m=m6; s=32'd15; t=`T_59; next_C=next_a; end 4'b1011: begin a=B; b=C; c=D; d=A; m=m13; s=32'd21; t=`T_60; next_B=next_a; end 4'b1100: begin a=A; b=B; c=C; d=D; m=m4; s=32'd06; t=`T_61; next_A=next_a; end 4'b1101: begin a=D; b=A; c=B; d=C; m=m11; s=32'd10; t=`T_62; next_D=next_a; end 4'b1110: begin a=C; b=D; c=A; d=B; m=m2; s=32'd15; t=`T_63; next_C=next_a; end 4'b1111: begin a=B; b=C; c=D; d=A; m=m9; s=32'd21; t=`T_64; next_B=next_a; end endcase if (phase == 4'b1111) next_state = FINISH_OFF[7:0]; end // } //---------------------------------------------------------------- current_state[FINISH_OFF_BIT]: begin // { // synopsys translate_off ascii_state = "FINISH_OFF"; // synopsys translate_on next_A = AA + A; next_B = BB + B; next_C = CC + C; next_D = DD + D; next_state = TURN_ARND[7:0]; end // } //---------------------------------------------------------------- // One cycle for making the system to come to reset state current_state[TURN_ARND_BIT]: begin // { // synopsys translate_off ascii_state = "TURN_ARND"; // synopsys translate_on next_state = IDLE[7:0]; end // } endcase end // } //-------------------------------- // // Flops and other combinatorial // logic definition // //-------------------------------- // Outputs assign msg_output = {{A[7:0], A[15:8], A[23:16], A[31:24]} ,{B[7:0], B[15:8], B[23:16], B[31:24]} ,{C[7:0], C[15:8], C[23:16], C[31:24]} ,{D[7:0], D[15:8], D[23:16], D[31:24]}}; always @(posedge clk) msg_out_valid <= current_state[FINISH_OFF_BIT]; assign ready = current_state[IDLE_BIT]; // Internal scratch pads always @(posedge clk) if (next_state[ROUND1_BIT] && current_state[IDLE_BIT]) begin // { AA <= A; BB <= B; CC <= C; DD <= D; end // } // Initialize A, B, C and D and then compute them always @(posedge clk) if (rst ) begin // { A <= SALT_A; B <= SALT_B; C <= SALT_C; D <= SALT_D; end // } else begin // { A <= next_A; B <= next_B; C <= next_C; D <= next_D; end // } // Determine one of the 16 phases within each round always @(posedge clk) if (rst) phase <= 4'b0; else if (next_state[ROUND1_BIT] && current_state[IDLE_BIT]) phase <= 4'b0; else phase <= phase + 4'b1; // Assign current_state based on rst and the next_state always @(posedge clk) if (rst) current_state <= IDLE[7:0]; else current_state <= next_state; endmodule
/***************************************************************** Pancham is an MD5 compliant IP core for cryptographic applicati -ons. Copyright (C) 2003 Swapnajit Mittra, Project VeriPage (Contact email: verilog_tutorial at hotmail.com Website : http://www.angelfire.com/ca/verilog) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc. 59 Temple Place, Suite 330 Boston, MA 02111-1307 USA ******************************************************************/ /* * pancham_round performs the rounds 1-4 of the MD5 algorithm * described in RFC1321 for a 128-bit long input message. * * Inputs: [abcd m[k] s abs(sin(2*pi*t/64))] as described * in RFC1321.Also the round number (1-4). * * Outputs: the modified 'a' value as describes in RFC1321 * on the left hand side of the round #n equation. * */ `define ROUND1 2'b00 `define ROUND2 2'b01 `define ROUND3 2'b10 `define ROUND4 2'b11 module pancham_round ( a , b , c , d , m , s , t , round , next_a ); input [31:0] a; input [31:0] b; input [31:0] c; input [31:0] d; input [31:0] m; // Note that for a 128-bit long input message, X[k] = M[k] = m input [31:0] s; input [31:0] t; // t-th sample of abs(sin(i)), i = 1, 2, ..., 64 input [1:0] round; // round number (1-4). output [31:0] next_a; wire [31:0] a; // wire [31:0] b; wire [31:0] c; wire [31:0] d; wire [31:0] m; wire [31:0] s; wire [31:0] t; wire [1:0] round; reg [31:0] next_a; reg [31:0] add_result; reg [31:0] rotate_result1; reg [31:0] rotate_result2; always @(a or b or c or d or m or s or t or round) begin // { case (round) `ROUND1: begin // { add_result = (a + F(b,c,d) + m + t); rotate_result1 = add_result << s; rotate_result2 = add_result >> (32-s); next_a = b + (rotate_result1 | rotate_result2); end // } `ROUND2: begin // { add_result = (a + G(b,c,d) + m + t); rotate_result1 = add_result << s; rotate_result2 = add_result >> (32-s); next_a = b + (rotate_result1 | rotate_result2); end // } `ROUND3: begin // { add_result = (a + H(b,c,d) + m + t); rotate_result1 = add_result << s; rotate_result2 = add_result >> (32-s); next_a = b + (rotate_result1 | rotate_result2); end // } `ROUND4: begin // { add_result = (a + I(b,c,d) + m + t); rotate_result1 = add_result << s; rotate_result2 = add_result >> (32-s); next_a = b + (rotate_result1 | rotate_result2); end // } endcase end // } //-------------------------------- // // Function declarations // //-------------------------------- // Step 4 functions F, G, H and I function [31:0] F; input [31:0] x, y, z; begin // { F = (x&y)|((~x)&z); end // } endfunction // } function [31:0] G; input [31:0] x, y, z; begin // { G = (x&z)|(y&(~z)); end // } endfunction function [31:0] H; input [31:0] x, y, z; begin // { H = (x^y^z); end // } endfunction function [31:0] I; input [31:0] x, y, z; begin // { I = (y^(x|(~z))); end // } endfunction endmodule
//------------------------------------------------------------------ // Simulator directives. //------------------------------------------------------------------ `timescale 1ns/100ps //------------------------------------------------------------------ // Test module. //------------------------------------------------------------------ module tb_modexp(); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- // Debug output control. parameter DEBUG = 0; parameter VCD = 1; // Clock defines. localparam CLK_HALF_PERIOD = 1; localparam CLK_PERIOD = 2 * CLK_HALF_PERIOD; // Address defines localparam OPERAND_WIDTH = 32; localparam ADDRESS_WIDTH = 8; localparam ADDR_NAME0 = 8'h00; localparam ADDR_NAME1 = 8'h01; localparam ADDR_VERSION = 8'h02; localparam ADDR_CTRL = 8'h08; localparam CTRL_INIT_BIT = 0; localparam CTRL_NEXT_BIT = 1; localparam ADDR_STATUS = 8'h09; localparam STATUS_READY_BIT = 0; localparam ADDR_CYCLES_HIGH = 8'h10; localparam ADDR_CYCLES_LOW = 8'h11; localparam ADDR_MODULUS_LENGTH = 8'h20; localparam ADDR_EXPONENT_LENGTH = 8'h21; localparam ADDR_MODULUS_PTR_RST = 8'h30; localparam ADDR_MODULUS_DATA = 8'h31; localparam ADDR_EXPONENT_PTR_RST = 8'h40; localparam ADDR_EXPONENT_DATA = 8'h41; localparam ADDR_MESSAGE_PTR_RST = 8'h50; localparam ADDR_MESSAGE_DATA = 8'h51; localparam ADDR_RESULT_PTR_RST = 8'h60; localparam ADDR_RESULT_DATA = 8'h61; localparam DEFAULT_MODLENGTH = 8'h80; // 2048 bits. localparam DEFAULT_EXPLENGTH = 8'h80; localparam CORE_NAME0 = 32'h6d6f6465; // "mode" localparam CORE_NAME1 = 32'h78702020; // "xp " localparam CORE_VERSION = 32'h302e3532; // "0.52" //---------------------------------------------------------------- // Register and Wire declarations. //---------------------------------------------------------------- reg [31 : 0] error_ctr; reg [31 : 0] tc_ctr; reg [127 : 0] result_data; reg tb_clk; reg tb_reset_n; reg tb_cs; reg tb_we; reg [31 : 0] tb_address; reg [31 : 0] tb_write_data; wire [31 : 0] tb_read_data; wire tb_error; reg tb_cyc; reg [3 : 0] tb_sel; wire tb_ack; wire tb_err; wire tb_int; reg [31 : 0] pmsg [63 : 0]; reg [31 : 0] cmsg [63 : 0]; reg [31 : 0] gmsg [63 : 0]; integer f1; //---------------------------------------------------------------- // Device Under Test. //---------------------------------------------------------------- modexp dut( .clk(tb_clk), .reset_n(tb_reset_n), .cs(tb_cs), .we(tb_we), .address(tb_address[10:2]), .write_data(tb_write_data), .read_data(tb_read_data)); //---------------------------------------------------------------- // clk_gen // // Always running clock generator process. //---------------------------------------------------------------- always begin : clk_gen #CLK_HALF_PERIOD; tb_clk = !tb_clk; end // clk_gen //---------------------------------------------------------------- // reset_dut() // // Toggle reset to put the DUT into a well known state. //---------------------------------------------------------------- task reset_dut(); begin $display("*** Toggle reset."); tb_reset_n = 0; #(2 * CLK_PERIOD); tb_reset_n = 1; $display(""); end endtask // reset_dut //---------------------------------------------------------------- // init_sim() // // Initialize all counters and testbed functionality as well // as setting the DUT inputs to defined values. //---------------------------------------------------------------- task init_sim(); begin error_ctr = 0; tc_ctr = 0; tb_clk = 0; tb_reset_n = 1; tb_cs = 0; tb_we = 0; tb_address = 32'h00000000; tb_write_data = 32'h00000000; end endtask // init_sim //---------------------------------------------------------------- // read_word() // // Read a data word from the given address in the DUT. //---------------------------------------------------------------- task read_word(input [7 : 0] address); begin tb_address = {22'b0,address,2'b0}; tb_cs = 1; tb_we = 0; #(CLK_PERIOD); tb_cs = 0; if (DEBUG) begin $display("*** (read_word) Reading 0x%08x from 0x%02x.", tb_read_data, address); $display(""); end end endtask // read_word //---------------------------------------------------------------- // write_word() // // Write the given word to the DUT using the DUT interface. //---------------------------------------------------------------- task write_word(input [ 7 : 0] address, input [31 : 0] word); begin if (DEBUG) begin $display("*** (write_word) Writing 0x%08x to 0x%02x.", word, address); $display(""); end tb_address = {22'b0,address,2'b0}; tb_write_data = word; tb_cs = 1; tb_we = 1; #(CLK_PERIOD); tb_cs = 0; tb_we = 0; end endtask // write_word //---------------------------------------------------------------- // wait_ready() // // Wait until the ready flag in the core is set. //---------------------------------------------------------------- task wait_ready(); begin while (tb_read_data != 32'h00000001) read_word(8'h09); if (DEBUG) $display("*** (wait_ready) Ready flag has been set."); end endtask // wait_ready //---------------------------------------------------------------- // assertEquals //---------------------------------------------------------------- function assertEquals( input [31:0] expected, input [31:0] actual ); begin if (expected === actual) begin assertEquals = 1; // success end else begin $display("*** Expected: 0x%08x, got 0x%08x", expected, actual); assertEquals = 0; // failure end end endfunction // assertEquals //---------------------------------------------------------------- // assertSuccess //---------------------------------------------------------------- task assertSuccess(input success); begin if (success !== 1) begin $display("*** Test -> FAILED"); error_ctr = error_ctr + 1; end else $display("*** Test -> passed"); end endtask // assertSuccess //---------------------------------------------------------------- // display_test_results() // // Display the accumulated test results. //---------------------------------------------------------------- task display_test_results(); begin $display(""); if (error_ctr == 0) begin $display("*** All %02d test cases completed successfully", tc_ctr); end else begin $display("*** %02d tests completed - %02d test cases did not complete successfully.", tc_ctr, error_ctr); end end endtask // display_test_results //---------------------------------------------------------------- // exp32bit_mod2048bit_test(); //---------------------------------------------------------------- task exp32bit_mod2048bit_test(); integer i; integer success; reg [31 : 0] read_data; reg [31 : 0] exp [63 : 0]; reg [31 : 0] mod [63 : 0]; reg [31 : 0] msg [63 : 0]; reg [31 : 0] res [63 : 0]; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display(""); $display("Test with e = 65537 and 2048 bit modulus -- Encrypting"); $readmemh("./gen/exp", exp); $readmemh("./gen/mod", mod); $readmemh("./gen/msg", msg); $readmemh("./gen/res", res); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , exp[0]); write_word(ADDR_MODULUS_PTR_RST, 32'h00000000); write_word(ADDR_MODULUS_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MODULUS_DATA, mod[i]); if(DEBUG) $display("writing: %d -> %h", i, mod[i]); end write_word(ADDR_MESSAGE_PTR_RST, 32'h00000000); write_word(ADDR_MESSAGE_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MESSAGE_DATA, msg[i]); if(DEBUG) $display("Writing: %d -> %h", i, msg[i]); end write_word(ADDR_EXPONENT_LENGTH, 32'h00000001); write_word(ADDR_MODULUS_LENGTH , 32'h00000041); // Start processing and wait for ready. write_word(ADDR_CTRL, 32'h00000001); wait_ready(); write_word(ADDR_RESULT_PTR_RST, 32'h00000000); read_word(ADDR_RESULT_DATA); read_data=tb_read_data; success=success&assertEquals(32'h00000000, read_data); for(i=0; i<64; i=i+1) begin read_word(ADDR_RESULT_DATA); read_data=tb_read_data; success=success&assertEquals(res[i], read_data); if(DEBUG) $display("Reading: %d -> %h -> %h", i, res[i], read_data); end if (success !== 1) begin $display("*** ERROR: e65537_2048bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_2048bit_modulus success."); end endtask // e65537_2048bit_modulus //---------------------------------------------------------------- // modexp_encrypt //---------------------------------------------------------------- task modexp_encrypt(); integer i; integer success; reg [31 : 0] pubexp [1]; reg [31 : 0] pubmod [63 : 0]; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display(""); $display("Encrypting -- exp = 65537 and 2048 bit mod"); $readmemh("./gen/pTextHEX", pmsg); $readmemh("./gen/exponent", pubexp); $readmemh("./gen/modulus", pubmod); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , pubexp[0]); if(DEBUG) $display("Writing EXP: %d %h", pubexp[0], pubexp[0]); write_word(ADDR_MODULUS_PTR_RST, 32'h00000000); write_word(ADDR_MODULUS_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MODULUS_DATA, pubmod[i]); if(DEBUG) $display("Writing MOD: %d -> %h", i, pubmod[i]); end write_word(ADDR_MESSAGE_PTR_RST, 32'h00000000); write_word(ADDR_MESSAGE_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MESSAGE_DATA, pmsg[i]); if(DEBUG) $display("Writing MSG: %d -> %h", i, pmsg[i]); end write_word(ADDR_EXPONENT_LENGTH, 32'h00000001); write_word(ADDR_MODULUS_LENGTH , 32'h00000041); // Start processing and wait for ready. write_word(ADDR_CTRL, 32'h00000001); wait_ready(); write_word(ADDR_RESULT_PTR_RST, 32'h00000000); read_word(ADDR_RESULT_DATA); cmsg[0]=tb_read_data; //success=success&assertEquals(32'h00000000, cmsg[0]); f1 = $fopen("./gen/cTextHEX", "w"); for(i=0; i<64; i=i+1) begin read_word(ADDR_RESULT_DATA); cmsg[i]=tb_read_data; if(DEBUG) $display("Reading: %d -> %h ", i, cmsg[i]); $fwrite(f1, "%h\n",cmsg[i]); end $fclose(f1); assertSuccess(success); end endtask // e65537_2048bit_modulus //---------------------------------------------------------------- // modexp_decrypt //---------------------------------------------------------------- task modexp_decrypt(); integer i; integer success; reg [31 : 0] rdata; reg [31 : 0] read_data; reg [31 : 0] priexp [63 : 0]; reg [31 : 0] primod [63 : 0]; begin $display(""); $display("*** Running -> modexp_decrypt()"); $readmemh("./gen/priExponent", priexp); $readmemh("./gen/priModulus", primod); success = 32'h1; tc_ctr = tc_ctr + 1; $display("Decrypting -- 2048 bit exp and 2048 bit mod"); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_EXPONENT_DATA, priexp[i]); if(DEBUG) $display("Writing EXP: %d -> %h", i, priexp[i]); end write_word(ADDR_MODULUS_PTR_RST, 32'h00000000); write_word(ADDR_MODULUS_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MODULUS_DATA, primod[i]); if(DEBUG) $display("Writing MOD: %d -> %h", i, primod[i]); end write_word(ADDR_MESSAGE_PTR_RST, 32'h00000000); write_word(ADDR_MESSAGE_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MESSAGE_DATA, cmsg[i]); if(DEBUG) $display("Writing MSG: %d -> %h", i, cmsg[i]); end write_word(ADDR_EXPONENT_LENGTH, 32'h00000041); write_word(ADDR_MODULUS_LENGTH , 32'h00000041); // Start processing and wait for ready. write_word(ADDR_CTRL, 32'h00000001); wait_ready(); write_word(ADDR_RESULT_PTR_RST, 32'h00000000); read_word(ADDR_RESULT_DATA); rdata=tb_read_data; success=success&assertEquals(32'h00000000, rdata); f1 = $fopen("./gen/gTextHEX", "w"); for(i=0; i<64; i=i+1) begin read_word(ADDR_RESULT_DATA); rdata=tb_read_data; if(DEBUG) $display("Reading: %d -> %h ", i, rdata); $fwrite(f1, "%h\n",rdata); success=success&assertEquals(pmsg[i], rdata); end $fclose(f1); assertSuccess(success); end endtask // e65537_2048bit_modulus //---------------------------------------------------------------- // modexp_32bits //---------------------------------------------------------------- task modexp_32bits(input [31:0] Wmsg, input [31:0] Wexp, input [31:0] Wmod, input [31:0] Wres); reg [31 : 0] Rmsg; reg [31 : 0] Rexp; reg [31 : 0] Rmod; reg [31 : 0] Rres; integer success; begin $display(""); $display("*** Running -> modexp_32bits()"); success = 32'h1; tc_ctr = tc_ctr + 1; $display("*** Writing -> MES: %h EXP: %h MOD: %h", Wmsg, Wexp, Wmod); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , Wexp); write_word(ADDR_MODULUS_PTR_RST , 32'h00000000); write_word(ADDR_MODULUS_DATA , Wmod); write_word(ADDR_MESSAGE_PTR_RST , 32'h00000000); write_word(ADDR_MESSAGE_DATA , Wmsg); write_word(ADDR_EXPONENT_LENGTH , 32'h00000001); write_word(ADDR_MODULUS_LENGTH , 32'h00000001); // Start processing and wait for ready. write_word(ADDR_CTRL , 32'h00000001); wait_ready(); write_word(ADDR_MESSAGE_PTR_RST , 32'h00000000); read_word(ADDR_MESSAGE_DATA); Rmsg=tb_read_data; write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); read_word(ADDR_EXPONENT_DATA); Rexp=tb_read_data; write_word(ADDR_MODULUS_PTR_RST , 32'h00000000); read_word(ADDR_MODULUS_DATA); Rmod=tb_read_data; write_word(ADDR_RESULT_PTR_RST , 32'h00000000); read_word(ADDR_RESULT_DATA); Rres=tb_read_data; $display("*** Reading -> MES: %h EXP: %h MOD: %h RES: %h", Rmsg, Rexp, Rmod, Rres); success=success&assertEquals(Wres, Rres); assertSuccess(success); end endtask // e65537_2048bit_modulus //---------------------------------------------------------------- // main // // The main test functionality. //---------------------------------------------------------------- initial begin : main if(VCD) begin $dumpfile("./iverilog/tb_modexp.vcd"); $dumpvars(0,tb_modexp); //$dumpvars(1,tb_clk, tb_reset_n, tb_cs, tb_we, tb_address, tb_write_data, tb_read_data); end $display(" -= Testbench for modexp started =-"); $display(" ================================="); $display(""); init_sim(); reset_dut(); modexp_32bits(32'h00000001, 32'h00000002, 32'h00000005, 32'h00000001); //msg^exp < mod -> 1^2 < 5 modexp_32bits(32'h00000001, 32'h00000002, 32'h00000003, 32'h00000001); //msg^exp < mod -> 1^2 < 3 modexp_32bits(32'h00000002, 32'h00000002, 32'h00000005, 32'h00000004); //msg^exp < mod -> 2^2 < 5 modexp_32bits(32'h00000002, 32'h00000002, 32'h00000003, 32'h00000001); //msg^exp > mod -> 2^2 > 3 modexp_32bits(32'h00000004, 32'h0000000D, 32'h000001F1, 32'h000001bd); //msg^exp > mod -> 4^13 > 497 modexp_32bits(32'h01234567, 32'h89ABCDEF, 32'h11111111, 32'h0D9EF081); //msg^exp > mod -> 19088743^2309737967 > 286331153 modexp_32bits(32'h30000000, 32'hC0000000, 32'h00A00001, 32'h0000CC3F); //msg^exp > mod -> 805306368^3221225472 > 10485761 <- Passes //modexp_32bits(32'h30000000, 32'hC0000000, 32'h00A00000, 32'h00600000); //msg^exp > mod -> 805306368^3221225472 > 10485760 <- Fails //modexp_32bits(32'h00000002, 32'h00000003, 32'h00000001, 32'h00000000); //mod 1 <- FAILS Does not check /* modexp_32bits(32'h00000001, 32'h00000002, 32'h00000002, 32'h00000001); //1 mod 2 = 1 -> 0 <- FAILS modexp_32bits(32'h00000001, 32'h00000002, 32'h00000003, 32'h00000001); //1 mod 3 = 1 -> 1 <- passes modexp_32bits(32'h00000001, 32'h00000002, 32'h00000004, 32'h00000001); //1 mod 4 = 1 -> 0 <- FAILS modexp_32bits(32'h00000001, 32'h00000002, 32'h00000005, 32'h00000001); //1 mod 5 = 1 -> 1 <- passes modexp_32bits(32'h00000001, 32'h00000002, 32'h00000006, 32'h00000001); //1 mod 6 = 1 -> 4 <- FAILS modexp_32bits(32'h00000002, 32'h00000001, 32'h00000002, 32'h00000000); //2 mod 2 = 0 -> passes modexp_32bits(32'h00000002, 32'h00000001, 32'h00000003, 32'h00000002); //2 mod 3 = 2 -> passes modexp_32bits(32'h00000002, 32'h00000001, 32'h00000004, 32'h00000002); //2 mod 4 = 2 -> 0 <- FAILS modexp_32bits(32'h00000002, 32'h00000001, 32'h00000005, 32'h00000002); //2 mod 5 = 2 -> passes modexp_32bits(32'h00000002, 32'h00000001, 32'h00000006, 32'h00000002); //2 mod 6 = 2 -> passes modexp_32bits(32'h00000003, 32'h00000001, 32'h00000002, 32'h00000001); //3 mod 2 = 1 -> 0 <- FAILS modexp_32bits(32'h00000003, 32'h00000001, 32'h00000003, 32'h00000000); //3 mod 3 = 0 -> 3 <- FAILS modexp_32bits(32'h00000003, 32'h00000001, 32'h00000004, 32'h00000003); //3 mod 4 = 3 -> 0 <- FAILS modexp_32bits(32'h00000003, 32'h00000001, 32'h00000005, 32'h00000003); //3 mod 5 = 3 -> passes modexp_32bits(32'h00000003, 32'h00000001, 32'h00000006, 32'h00000003); //3 mod 6 = 3 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000002, 32'h00000000); //4 mod 2 = 0 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000003, 32'h00000001); //4 mod 3 = 1 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000004, 32'h00000000); //4 mod 4 = 0 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000005, 32'h00000004); //4 mod 5 = 4 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000006, 32'h00000004); //4 mod 6 = 4 -> passes modexp_32bits(32'h00000005, 32'h00000001, 32'h00000002, 32'h00000001); //5 mod 2 = 1 -> 0 <- FAILS modexp_32bits(32'h00000005, 32'h00000001, 32'h00000003, 32'h00000002); //5 mod 3 = 2 -> passes modexp_32bits(32'h00000005, 32'h00000001, 32'h00000004, 32'h00000001); //5 mod 4 = 1 -> 0 <- FAILS modexp_32bits(32'h00000005, 32'h00000001, 32'h00000005, 32'h00000000); //5 mod 5 = 0 -> 5 <- FAILS modexp_32bits(32'h00000005, 32'h00000001, 32'h00000006, 32'h00000005); //5 mod 6 = 5 -> passes modexp_32bits(32'h00000006, 32'h00000001, 32'h00000002, 32'h00000000); //6 mod 2 = 0 -> passes modexp_32bits(32'h00000006, 32'h00000001, 32'h00000003, 32'h00000000); //6 mod 3 = 0 -> 3 <- FAILS modexp_32bits(32'h00000006, 32'h00000001, 32'h00000004, 32'h00000002); //6 mod 4 = 2 -> 0 <- FAILS modexp_32bits(32'h00000006, 32'h00000001, 32'h00000005, 32'h00000001); //6 mod 5 = 1 -> passes modexp_32bits(32'h00000006, 32'h00000001, 32'h00000006, 32'h00000000); //6 mod 6 = 0 -> 1 <- FAILS */ /* modexp_32bits(32'h00000008, 32'h00000006, 32'h00000002, 32'h00000000); //8^6 mod 2 = 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000003, 32'h00000001); //8^6 mod 3 = 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000004, 32'h00000000); //8^6 mod 4 = 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000005, 32'h00000004); //8^6 mod 5 = 4 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000006, 32'h00000004); //8^6 mod 6 = 4 -> 1 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000007, 32'h00000001); //8^6 mod 7 = 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000008, 32'h00000000); //8^6 mod 8 = 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000009, 32'h00000001); //8^6 mod 9 = 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000A, 32'h00000004); //8^6 mod 10= 4 -> 9 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000B, 32'h00000003); //8^6 mod 11= 3 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000C, 32'h00000004); //8^6 mod 12= 4 -> 5 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000D, 32'h0000000C); //8^6 mod 13= 12-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000E, 32'h00000008); //8^6 mod 14= 8 -> 5 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000F, 32'h00000004); //8^6 mod 15= 4 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000010, 32'h00000000); //8^6 mod 16= 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000011, 32'h00000004); //8^6 mod 17= 4 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000012, 32'h0000000A); //8^6 mod 18= 10-> 13<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000013, 32'h00000001); //8^6 mod 19= 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000014, 32'h00000004); //8^6 mod 20= 4 -> 11<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000015, 32'h00000001); //8^6 mod 21= 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000016, 32'h0000000E); //8^6 mod 22= 14-> 1 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000017, 32'h0000000D); //8^6 mod 23= 13-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000018, 32'h00000010); //8^6 mod 24= 16-> 9 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000019, 32'h00000013); //8^6 mod 25= 19-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001A, 32'h0000000C); //8^6 mod 26= 12-> 19<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001B, 32'h00000001); //8^6 mod 27= 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001C, 32'h00000008); //8^6 mod 28= 8 -> 19<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001D, 32'h0000000D); //8^6 mod 29= 13-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001E, 32'h00000004); //8^6 mod 30= 4 -> 13<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001F, 32'h00000008); //8^6 mod 31= 8 -> passes */ //exp32bit_mod2048bit_test(); //modexp_encrypt(); //modexp_decrypt(); display_test_results(); $display(""); $display("*** modexp simulation done. ***"); $finish; end // main endmodule // tb_modexp //====================================================================== // EOF tb_modexp.v //======================================================================
//====================================================================== // // tb_modexp.v // ----------- // Testbench modular exponentiation core. // // // Author: Joachim Strombergson, Peter Magnusson // Copyright (c) 2015, NORDUnet A/S All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // - Neither the name of the NORDUnet nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //====================================================================== //------------------------------------------------------------------ // Simulator directives. //------------------------------------------------------------------ `timescale 1ns/100ps //------------------------------------------------------------------ // Test module. //------------------------------------------------------------------ module tb_modexp(); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- // Debug output control. parameter DEBUG = 0; parameter DEBUG_EI = 0; parameter DEBUG_RESULT = 0; parameter DISPLAY_TEST_CYCLES = 1; // Clock defines. localparam CLK_HALF_PERIOD = 1; localparam CLK_PERIOD = 2 * CLK_HALF_PERIOD; // The DUT address map. localparam GENERAL_PREFIX = 4'h0; localparam ADDR_NAME0 = 8'h00; localparam ADDR_NAME1 = 8'h01; localparam ADDR_VERSION = 8'h02; localparam ADDR_CTRL = 8'h08; localparam CTRL_START_BIT = 0; localparam ADDR_STATUS = 8'h09; localparam STATUS_READY_BIT = 0; localparam ADDR_MODULUS_LENGTH = 8'h20; localparam ADDR_EXPONENT_LENGTH = 8'h21; localparam ADDR_LENGTH = 8'h22; localparam ADDR_MODULUS_PTR_RST = 8'h30; localparam ADDR_MODULUS_DATA = 8'h31; localparam ADDR_EXPONENT_PTR_RST = 8'h40; localparam ADDR_EXPONENT_DATA = 8'h41; localparam ADDR_MESSAGE_PTR_RST = 8'h50; localparam ADDR_MESSAGE_DATA = 8'h51; localparam ADDR_RESULT_PTR_RST = 8'h60; localparam ADDR_RESULT_DATA = 8'h61; //---------------------------------------------------------------- // Register and Wire declarations. //---------------------------------------------------------------- reg [31 : 0] test_cycle_ctr; reg test_cycle_ctr_rst; reg test_cycle_ctr_inc; reg [31 : 0] cycle_ctr; reg [31 : 0] error_ctr; reg [31 : 0] tc_ctr; reg [31 : 0] read_data; reg [127 : 0] result_data; reg tb_clk; reg tb_reset_n; reg tb_cs; reg tb_we; reg [11 : 0] tb_address; reg [31 : 0] tb_write_data; wire [31 : 0] tb_read_data; wire tb_error; //---------------------------------------------------------------- // Device Under Test. //---------------------------------------------------------------- modexp dut( .clk(tb_clk), .reset_n(tb_reset_n), .cs(tb_cs), .we(tb_we), .address(tb_address), .write_data(tb_write_data), .read_data(tb_read_data) ); //---------------------------------------------------------------- // clk_gen // // Always running clock generator process. //---------------------------------------------------------------- always begin : clk_gen #CLK_HALF_PERIOD; tb_clk = !tb_clk; end // clk_gen //---------------------------------------------------------------- // sys_monitor() // // An always running process that creates a cycle counter and // conditionally displays information about the DUT. //---------------------------------------------------------------- always begin : sys_monitor cycle_ctr = cycle_ctr + 1; #(CLK_PERIOD); if (DEBUG) begin dump_dut_state(); end end //---------------------------------------------------------------- // test_cycle_counter // // Used to measure the number of cycles it takes to perform // a given test case. //---------------------------------------------------------------- always @ (posedge tb_clk) begin if (test_cycle_ctr_rst) test_cycle_ctr = 64'h0000000000000000; if (test_cycle_ctr_inc) test_cycle_ctr = test_cycle_ctr + 1; end //---------------------------------------------------------------- // start_test_cycle_ctr // // Reset and start the test cycle counter. //---------------------------------------------------------------- task start_test_cycle_ctr(); begin test_cycle_ctr_rst = 1; #(CLK_PERIOD); test_cycle_ctr_rst = 0; test_cycle_ctr_inc = 1; end endtask // start_test_cycle_ctr() //---------------------------------------------------------------- // stop_test_cycle_ctr() // // Stop the test cycle counter and optionally display the // result. //---------------------------------------------------------------- task stop_test_cycle_ctr(); begin test_cycle_ctr_inc = 0; #(CLK_PERIOD); if (DISPLAY_TEST_CYCLES) $display("*** Number of cycles performed during test: 0x%016x", test_cycle_ctr); end endtask // stop_test_cycle_ctr() //---------------------------------------------------------------- // ei_monitor() // // Displays ei_new, the most important variable for determining // what modexp will do (i.e. should Z=MONTPROD( Z, P, M) be // performed //---------------------------------------------------------------- always @* begin : ei_monitor if (DEBUG_EI) if (dut.modexp_ctrl_reg == dut.CTRL_ITERATE_Z_P) $display("loop counter %d: ei = %d", dut.loop_counter_reg, dut.ei_reg); end //---------------------------------------------------------------- // z_monitor() // // Displays the contents of the result_mem. //---------------------------------------------------------------- always @* begin : result_monitor if (DEBUG_RESULT) $display("result_mem[0][1] = %x %x",dut.result_mem.mem[0],dut.result_mem.mem[1]); end //---------------------------------------------------------------- // dump_dut_state() // // Dump the state of the dump when needed. //---------------------------------------------------------------- task dump_dut_state(); begin $display("cycle: 0x%016x", cycle_ctr); $display("State of DUT"); $display("------------"); $display("Inputs and outputs:"); $display("cs = 0x%01x, we = 0x%01x", tb_cs, tb_we); $display("addr = 0x%08x, read_data = 0x%08x, write_data = 0x%08x", tb_address, tb_read_data, tb_write_data); $display(""); $display("State:"); $display("ready_reg = 0x%01x, start_reg = 0x%01x, start_new = 0x%01x", dut.core_inst.ready_reg, dut.start_reg, dut.start_new); $display("residue_valid = 0x%01x", dut.core_inst.residue_valid_reg); $display("loop_counter_reg = 0x%08x", dut.core_inst.loop_counter_reg); $display("exponent_length_reg = 0x%02x exponent_length_m1 = 0x%02x modulus_length_reg = 0x%02x modulus_length_m1 = 0x%02x", dut.exponent_length_reg, dut.core_inst.exponent_length_m1, dut.modulus_length_reg, dut.core_inst.modulus_length_m1); $display("ctrl_reg = 0x%04x", dut.core_inst.modexp_ctrl_reg); $display(""); end endtask // dump_dut_state //---------------------------------------------------------------- // reset_dut() // // Toggle reset to put the DUT into a well known state. //---------------------------------------------------------------- task reset_dut(); begin $display("*** Toggle reset."); tb_reset_n = 0; #(2 * CLK_PERIOD); tb_reset_n = 1; $display(""); end endtask // reset_dut //---------------------------------------------------------------- // display_test_results() // // Display the accumulated test results. //---------------------------------------------------------------- task display_test_results(); begin if (error_ctr == 0) begin $display("*** All %02d test cases completed successfully", tc_ctr); end else begin $display("*** %02d tests completed - %02d test cases did not complete successfully.", tc_ctr, error_ctr); end end endtask // display_test_results //---------------------------------------------------------------- // init_sim() // // Initialize all counters and testbed functionality as well // as setting the DUT inputs to defined values. //---------------------------------------------------------------- task init_sim(); begin cycle_ctr = 0; error_ctr = 0; tc_ctr = 0; tb_clk = 0; tb_reset_n = 1; tb_cs = 0; tb_we = 0; tb_address = 8'h00; tb_write_data = 32'h00000000; end endtask // init_sim //---------------------------------------------------------------- // read_word() // // Read a data word from the given address in the DUT. // the word read will be available in the global variable // read_data. //---------------------------------------------------------------- task read_word(input [11 : 0] address); begin tb_address = address; tb_cs = 1; tb_we = 0; #(CLK_PERIOD); read_data = tb_read_data; tb_cs = 0; if (DEBUG) begin $display("*** (read_word) Reading 0x%08x from 0x%02x.", read_data, address); $display(""); end end endtask // read_word //---------------------------------------------------------------- // write_word() // // Write the given word to the DUT using the DUT interface. //---------------------------------------------------------------- task write_word(input [11 : 0] address, input [31 : 0] word); begin if (DEBUG) begin $display("*** (write_word) Writing 0x%08x to 0x%02x.", word, address); $display(""); end tb_address = address; tb_write_data = word; tb_cs = 1; tb_we = 1; #(CLK_PERIOD); tb_cs = 0; tb_we = 0; end endtask // write_word //---------------------------------------------------------------- // wait_ready() // // Wait until the ready flag in the core is set. //---------------------------------------------------------------- task wait_ready(); begin while (tb_read_data != 32'h00000001) read_word({GENERAL_PREFIX, ADDR_STATUS}); if (DEBUG) $display("*** (wait_ready) Ready flag has been set."); end endtask // wait_ready //---------------------------------------------------------------- // dump_message_mem() // // Dump the contents of the message memory. //---------------------------------------------------------------- task dump_message_mem(); reg [8 : 0] i; begin $display("Contents of the message memory:"); for (i = 0 ; i < 256 ; i = i + 8) begin $display("message_mem[0x%02x .. 0x%02x] = 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x", i[7 : 0], (i[7 : 0] + 8'h07), dut.core_inst.message_mem.mem[(i[7 : 0] + 0)], dut.core_inst.message_mem.mem[(i[7 : 0] + 1)], dut.core_inst.message_mem.mem[(i[7 : 0] + 2)], dut.core_inst.message_mem.mem[(i[7 : 0] + 3)], dut.core_inst.message_mem.mem[(i[7 : 0] + 4)], dut.core_inst.message_mem.mem[(i[7 : 0] + 5)], dut.core_inst.message_mem.mem[(i[7 : 0] + 6)], dut.core_inst.message_mem.mem[(i[7 : 0] + 7)], ); end $display(""); end endtask // dump_message_mem //---------------------------------------------------------------- // dump_exponent_mem() // // Dump the contents of the exponent memory. //---------------------------------------------------------------- task dump_exponent_mem(); reg [8 : 0] i; begin $display("Contents of the exponent memory:"); for (i = 0 ; i < 256 ; i = i + 8) begin $display("exponent_mem[0x%02x .. 0x%02x] = 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x", i[7 : 0], (i[7 : 0] + 8'h07), dut.core_inst.exponent_mem.mem[(i[7 : 0] + 0)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 1)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 2)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 3)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 4)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 5)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 6)], dut.core_inst.exponent_mem.mem[(i[7 : 0] + 7)], ); end $display(""); end endtask // dump_exponent_mem //---------------------------------------------------------------- // dump_modulus_mem() // // Dump the contents of the modulus memory. //---------------------------------------------------------------- task dump_modulus_mem(); reg [8 : 0] i; begin $display("Contents of the modulus memory:"); for (i = 0 ; i < 256 ; i = i + 8) begin $display("modulus_mem[0x%02x .. 0x%02x] = 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x", i[7 : 0], (i[7 : 0] + 8'h07), dut.core_inst.modulus_mem.mem[(i[7 : 0] + 0)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 1)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 2)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 3)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 4)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 5)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 6)], dut.core_inst.modulus_mem.mem[(i[7 : 0] + 7)], ); end $display(""); end endtask // dump_modulus_mem //---------------------------------------------------------------- // dump_residue_mem() // // Dump the contents of the residue memory. //---------------------------------------------------------------- task dump_residue_mem(); reg [8 : 0] i; begin $display("Contents of the residue memory:"); for (i = 0 ; i < 256 ; i = i + 8) begin $display("residue_mem[0x%02x .. 0x%02x] = 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x", i[7 : 0], (i[7 : 0] + 8'h07), dut.core_inst.residue_mem.mem[(i[7 : 0] + 0)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 1)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 2)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 3)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 4)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 5)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 6)], dut.core_inst.residue_mem.mem[(i[7 : 0] + 7)], ); end $display(""); end endtask // dump_residue_mem //---------------------------------------------------------------- // dump_result_mem() // // Dump the contents of the result memory. //---------------------------------------------------------------- task dump_result_mem(); reg [8 : 0] i; begin $display("Contents of the result memory:"); for (i = 0 ; i < 256 ; i = i + 8) begin $display("result_mem[0x%02x .. 0x%02x] = 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x", i[7 : 0], (i[7 : 0] + 8'h07), dut.core_inst.result_mem.mem[(i[7 : 0] + 0)], dut.core_inst.result_mem.mem[(i[7 : 0] + 1)], dut.core_inst.result_mem.mem[(i[7 : 0] + 2)], dut.core_inst.result_mem.mem[(i[7 : 0] + 3)], dut.core_inst.result_mem.mem[(i[7 : 0] + 4)], dut.core_inst.result_mem.mem[(i[7 : 0] + 5)], dut.core_inst.result_mem.mem[(i[7 : 0] + 6)], dut.core_inst.result_mem.mem[(i[7 : 0] + 7)], ); end $display(""); end endtask // dump_result_mem //---------------------------------------------------------------- // dump_memories() // // Dump the contents of the memories in the dut. //---------------------------------------------------------------- task dump_memories(); begin dump_message_mem(); dump_exponent_mem(); dump_modulus_mem(); dump_residue_mem(); dump_result_mem(); end endtask // dump_memories //---------------------------------------------------------------- // tc1 // // A first, very simple testcase where we want to do: // c = m ** e % N with the following (decimal) test values: // m = 3 // e = 7 // n = 11 // c = 3 ** 7 % 11 = 9 //---------------------------------------------------------------- task tc1(); reg [31 : 0] read_data; begin tc_ctr = tc_ctr + 1; $display("TC1: Trying to calculate 3**7 mod 11 = 9"); // Write 3 to message memory. write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000003); // Write 7 to exponent memory and set length to one word. write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000007); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); // Write 11 to modulus memory and set length to one word. write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h0000000b); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000001); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); // Read out result word and check result. write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; if (read_data == 32'h00000009) begin $display("*** TC1 successful."); $display(""); end else begin $display("*** ERROR: TC1 NOT successful."); $display("Expected: 0x09, got 0x%08x", read_data); error_ctr = error_ctr + 1; dump_memories(); end end endtask // tc1 //---------------------------------------------------------------- // tc2 // // c = m ** e % N with the following (decimal) test values: // m = 251 // e = 251 // n = 257 // c = 251 ** 251 % 257 = 183 //---------------------------------------------------------------- task tc2(); reg [31 : 0] read_data; begin tc_ctr = tc_ctr + 1; $display("TC2: Trying to calculate 251**251 mod 257 = 183"); // Write 13 to message memory. write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h000000fb); // Write 11 to exponent memory and set length to one word. write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h000000fb); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); // Write 7 to modulus memory and set length to one word. write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000101); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000001); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); // Read out result word and check result. write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; if (read_data == 32'h000000b7) begin $display("*** TC2 successful."); $display(""); end else begin $display("*** ERROR: TC2 NOT successful."); $display("Expected: 0x000000b7, got 0x%08x", read_data); error_ctr = error_ctr + 1; end end endtask // tc2 //---------------------------------------------------------------- // tc3 // // c = m ** e % N with the following (decimal) test values: // m = 0x81 // e = 0x41 // n = 0x87 // c = 0x81 ** 0x41 % 0x87 = 0x36 //---------------------------------------------------------------- task tc3(); reg [31 : 0] read_data; begin tc_ctr = tc_ctr + 1; $display("TC3: Trying to calculate 0x81 ** 0x41 mod 0x87 = 0x36"); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000081); // Write 11 to exponent memory and set length to one word. write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000041); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); // Write 7 to modulus memory and set length to one word. write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000087); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000001); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); // Read out result word and check result. write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; if (read_data == 32'h00000036) begin $display("*** TC3 successful."); $display(""); end else begin $display("*** ERROR: TC3 NOT successful."); $display("Expected: 0x06, got 0x%08x", read_data); error_ctr = error_ctr + 1; end end endtask // tc3 //---------------------------------------------------------------- // assertEquals //---------------------------------------------------------------- function assertEquals( input [31:0] expected, input [31:0] actual ); begin if (expected === actual) begin assertEquals = 1; // success end else begin $display("Expected: 0x%08x, got 0x%08x", expected, actual); assertEquals = 0; // failure end end endfunction // assertEquals integer success; //---------------------------------------------------------------- // autogenerated_BASIC_33bit() // // Task that tests modexp with 33 bit oprerands. //---------------------------------------------------------------- task autogenerated_BASIC_33bit(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("autogenerated_BASIC_33bit: 00000001946473e1 ** h000000010e85e74f mod 0000000170754797 "); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h946473e1); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h0e85e74f); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h70754797); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000002); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000002); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h7761ed4f, read_data); if (success !== 1) begin $display("*** ERROR: autogenerated_BASIC_33bit was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** autogenerated_BASIC_33bit success."); end endtask // autogenerated_BASIC_33bit //---------------------------------------------------------------- // autogenerated_BASIC_128bit() // // Task that tests modexp with 128 bit operands. //---------------------------------------------------------------- task autogenerated_BASIC_128bit(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("autogenerated_BASIC_128bit"); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h3285c343); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h2acbcb0f); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h4d023228); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h2ecc73db); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h29462882); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h12caa2d5); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb80e1c66); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h1006807f); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h267d2f2e); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h51c216a7); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hda752ead); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h48d22d89); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000004); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000005); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h0ddc404d, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h91600596, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h7425a8d8, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha066ca56, read_data); if (success !== 1) begin $display("*** ERROR: autogenerated_BASIC_128bit was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** autogenerated_BASIC_128bit success."); end endtask // autogenerated_BASIC_128bit //---------------------------------------------------------------- // e64bit_64bit_modulus() //---------------------------------------------------------------- task e64bit_64bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with 64 bit exponent and 64 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h12345678); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h97543211); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hfeababab); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hdeadbeef); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffee); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hbeefbeef); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000002); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000003); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'he52c5b9f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h85de87eb, read_data); if (success !== 1) begin $display("*** ERROR: 64 bit exponent and 64 bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** 64 bit exponent and 64 bit modulus success."); end endtask // e64bit_64bit_modulus //---------------------------------------------------------------- // e65537_64bit_modulus() //---------------------------------------------------------------- task e65537_64bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 64 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hf077656f); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h3bf9e69b); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb6684dc3); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h79a5824b); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000003); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h132d8e17, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hdd4d85a4, read_data); if (success !== 1) begin $display("*** ERROR: e65537_64bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_64bit_modulus success."); end endtask // e65537_64bit_modulus //---------------------------------------------------------------- // e65537_64bit_modulus_elength() //---------------------------------------------------------------- task e65537_64bit_modulus_elength(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 64 bit modulus, explicit exponent length."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hf077656f); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h3bf9e69b); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb6684dc3); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h79a5824b); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000003); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h132d8e17, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hdd4d85a4, read_data); if (success !== 1) begin $display("*** ERROR: e65537_64bit_modulus with explicit elength was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_64bit_modulus success."); end endtask // e65537_64bit_modulus_elength //---------------------------------------------------------------- // e65537_128bit_modulus() //---------------------------------------------------------------- task e65537_128bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 128 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hf5e8eee0); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc06b048a); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h964b2105); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h2c36ad6b); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h956e61b3); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h27997bc4); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h94e7e5c9); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb53585cf); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000005); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h9c6d322c, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h25ab8bd3, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4aa80100, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf0f3a02c, read_data); if (success !== 1) begin $display("*** ERROR: e65537_128bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_128bit_modulus success."); end endtask // e65537_128bit_modulus //---------------------------------------------------------------- // e65537_256bit_modulus() // // Task that tests modexp with small exponent and 256 bit modulus. //---------------------------------------------------------------- task e65537_256bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 256 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hf169d36e); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hbe2ce61d); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc2e87809); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h4fed15c3); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h7c70eac5); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'ha123e643); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h299b36d2); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h788e583b); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hf169d36e); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hbe2ce61d); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hc2e87809); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h4fed15c3); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h7c70eac5); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'ha123e643); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h299b36d2); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h788e583a); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000009); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf169d36e, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hbe2ce61d, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hc2e87809, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4fed15c3, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h7c70eac5, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha123e643, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h299b36d2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h788e583a, read_data); if (success !== 1) begin $display("*** ERROR: e65537_256bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_256bit_modulus success."); end endtask // e65537_256bit_modulus //---------------------------------------------------------------- // e65537_1024bit_modulus() // // Task that tests modexp with small exponent and // 2048 bit modulus. //---------------------------------------------------------------- task e65537_1024bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 1024 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000021); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h45d55343, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha0971add, read_data); if (success !== 1) begin $display("*** ERROR: e65537_1024bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_1024bit_modulus success."); end endtask // e65537_1024bit_modulus //---------------------------------------------------------------- // e65537_1536bit_modulus() // // Task that tests modexp with small exponent and // 1536 bit modulus. //---------------------------------------------------------------- task e65537_1536bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 1536 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000031); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4ade4f46, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h02cb4a2f, read_data); if (success !== 1) begin $display("*** ERROR: e65537_1536bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_1536bit_modulus success."); end endtask // e65537_1536bit_modulus //---------------------------------------------------------------- // e65537_1664bit_modulus() // // Task that tests modexp with small exponent and // 1664 bit modulus. //---------------------------------------------------------------- task e65537_1664bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 1664 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000035); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h88671c15, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2aeeb8b2, read_data); if (success !== 1) begin $display("*** ERROR: e65537_1664bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_1664it_modulus success."); end endtask // e65537_1664bit_modulus //---------------------------------------------------------------- // e65537_2048bit_modulus() // // Task that tests modexp with small exponent and // 2048 bit modulus. //---------------------------------------------------------------- task e65537_2048bit_modulus(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Test with e = 65537 and 2048 bit modulus."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hffeeffef); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffaabbcc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hddeeffff); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000001); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000041); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf1752196, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4c36e92f, read_data); if (success !== 1) begin $display("*** ERROR: e65537_2048bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_2048bit_modulus success."); end endtask // e65537_2048bit_modulus //---------------------------------------------------------------- // rob_dec_1024() // // Task that tests modexp with 1024 bit decipher/sign with // real RSA key operands. //---------------------------------------------------------------- task rob_dec_1024(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Desipher/Sign Test with Rob 1024 bit operands."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h3ff26c9e); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h32685b93); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h66570228); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hf0603c4e); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h04a717c1); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h8038b116); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'heb48325e); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hcada992a); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h920bb241); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h5aee4afe); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'he2a37e87); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hb35b9519); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hb335775d); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h989553e9); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h1326f46e); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h2cdf6b7b); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h84aabfa9); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hef24c600); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hb56872ad); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h5edb9041); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'he8ecd7f8); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h535133fb); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hdefc92c7); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h42384226); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h7d40e5f5); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hc91bd745); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h9578e460); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hfc858374); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h3172bed3); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h73b6957c); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'hc0d6a68e); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h33156a61); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h0001ffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hffffffff); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00303130); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h0d060960); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h86480165); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h03040201); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h05000420); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h8e36fc9a); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'ha31724c3); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h2416263c); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h0366a175); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hfabbb92b); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h741ca649); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h6107074d); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h0343b597); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hd075ec0a); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h95048ef8); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hcaa69073); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h8d9d58e9); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h1764b437); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h50b58cad); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h8a6e3199); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h135f80ee); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h84eb2bde); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h58d38ee3); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h5825e91e); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hafdeb1ba); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'ha15a160b); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h0057c47c); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc7765e31); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h868a3e15); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h5ee57cef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hb008c4dd); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h6a0a89ee); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h98a4ee9c); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h971a07de); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h61e5b0d3); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hcf70e1cd); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc6a0de5b); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h451f2fb9); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hdb995196); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h9f2f884b); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h4b09749a); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'he6c4ddbe); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h7ee61f79); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h265c6adf); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hb16b3015); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000021); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000021); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h06339a64, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h367db02a, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf41158cc, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h95e76049, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4519c165, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h111184be, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'he41d8ee2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2ae5f5d1, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h1da7f962, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hac93ac88, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h915eee13, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha3350c22, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hf0dfa62e, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hfdfc2b62, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h29f26e27, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hbebdc84e, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h4746df79, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h7b387ad2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h13423c9f, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h98e8a146, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hff486b6c, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h1a85414e, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h73117121, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hb700e547, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hab4e07b2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h21b988b8, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h24dd77c2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h046b0a20, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hcddb986a, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hac75c2f2, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hb044ed59, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hea565879, read_data); if (success !== 1) begin $display("*** ERROR: rob_dec_1024 was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** rob_dec_1024 success."); end endtask // rob_dec_1024 //---------------------------------------------------------------- // rob_enc_1024() // // Task that tests modexp with 1024 bit encipher/verify with // real RSA key operands. //---------------------------------------------------------------- task rob_enc_1024(); reg [31 : 0] read_data; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display("Encipher/Verify Test with Rob 1024 bit operands."); write_word({GENERAL_PREFIX, ADDR_EXPONENT_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_EXPONENT_DATA}, 32'h00010001); write_word({GENERAL_PREFIX, ADDR_MESSAGE_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h06339a64); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h367db02a); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hf41158cc); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h95e76049); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h4519c165); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h111184be); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'he41d8ee2); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h2ae5f5d1); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h1da7f962); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hac93ac88); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h915eee13); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'ha3350c22); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hf0dfa62e); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hfdfc2b62); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h29f26e27); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hbebdc84e); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h4746df79); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h7b387ad2); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h13423c9f); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h98e8a146); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hff486b6c); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h1a85414e); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h73117121); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb700e547); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hab4e07b2); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h21b988b8); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h24dd77c2); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'h046b0a20); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hcddb986a); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hac75c2f2); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hb044ed59); write_word({GENERAL_PREFIX, ADDR_MESSAGE_DATA}, 32'hea565879); write_word({GENERAL_PREFIX, ADDR_MODULUS_PTR_RST}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h00000000); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hd075ec0a); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h95048ef8); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hcaa69073); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h8d9d58e9); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h1764b437); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h50b58cad); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h8a6e3199); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h135f80ee); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h84eb2bde); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h58d38ee3); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h5825e91e); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hafdeb1ba); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'ha15a160b); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h0057c47c); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc7765e31); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h868a3e15); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h5ee57cef); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hb008c4dd); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h6a0a89ee); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h98a4ee9c); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h971a07de); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h61e5b0d3); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hcf70e1cd); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hc6a0de5b); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h451f2fb9); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hdb995196); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h9f2f884b); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h4b09749a); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'he6c4ddbe); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h7ee61f79); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'h265c6adf); write_word({GENERAL_PREFIX, ADDR_MODULUS_DATA}, 32'hb16b3015); write_word({GENERAL_PREFIX, ADDR_EXPONENT_LENGTH}, 32'h00000021); write_word({GENERAL_PREFIX, ADDR_MODULUS_LENGTH}, 32'h00000021); start_test_cycle_ctr(); // Start processing and wait for ready. write_word({GENERAL_PREFIX, ADDR_CTRL}, 32'h00000001); wait_ready(); stop_test_cycle_ctr(); write_word({GENERAL_PREFIX, ADDR_RESULT_PTR_RST}, 32'h00000000); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00000000, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h0001ffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hffffffff, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h00303130, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h0d060960, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h86480165, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h03040201, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h05000420, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h8e36fc9a, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'ha31724c3, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h2416263c, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h0366a175, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'hfabbb92b, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h741ca649, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h6107074d, read_data); read_word({GENERAL_PREFIX, ADDR_RESULT_DATA}); read_data = tb_read_data; success = success & assertEquals(32'h0343b597, read_data); if (success !== 1) begin $display("*** ERROR: rob_enc_1024 was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** rob_enc_1024 success."); end endtask // rob_enc_1024 //---------------------------------------------------------------- // main // // The main test functionality. //---------------------------------------------------------------- initial begin : main $display(" -= Testbench for modexp started =-"); $display(" ================================="); $display(""); init_sim(); dump_dut_state(); reset_dut(); dump_dut_state(); // tc1(); // tc2(); // tc3(); // autogenerated_BASIC_33bit(); // autogenerated_BASIC_128bit(); // e64bit_64bit_modulus(); // e65537_64bit_modulus(); // e65537_64bit_modulus_elength(); // e65537_128bit_modulus(); // e65537_256bit_modulus(); // e65537_1024bit_modulus(); // e65537_1536bit_modulus(); // e65537_1664bit_modulus(); e65537_2048bit_modulus(); // rob_dec_1024(); // rob_enc_1024(); display_test_results(); $display(""); $display("*** modexp simulation done. ***"); $finish; end // main endmodule // tb_modexp //====================================================================== // EOF tb_modexp.v //======================================================================
//------------------------------------------------------------------ // Simulator directives. //------------------------------------------------------------------ `timescale 1ns/100ps //------------------------------------------------------------------ // Test module. //------------------------------------------------------------------ module tb_top(); //---------------------------------------------------------------- // Internal constant and parameter definitions. //---------------------------------------------------------------- // Debug output control. parameter DEBUG = 0; parameter VCD = 1; // Clock defines. localparam CLK_HALF_PERIOD = 1; localparam CLK_PERIOD = 2 * CLK_HALF_PERIOD; // Address defines localparam OPERAND_WIDTH = 32; localparam ADDRESS_WIDTH = 8; localparam ADDR_NAME0 = 8'h00; localparam ADDR_NAME1 = 8'h01; localparam ADDR_VERSION = 8'h02; localparam ADDR_CTRL = 8'h08; localparam CTRL_INIT_BIT = 0; localparam CTRL_NEXT_BIT = 1; localparam ADDR_STATUS = 8'h09; localparam STATUS_READY_BIT = 0; localparam ADDR_CYCLES_HIGH = 8'h10; localparam ADDR_CYCLES_LOW = 8'h11; localparam ADDR_MODULUS_LENGTH = 8'h20; localparam ADDR_EXPONENT_LENGTH = 8'h21; localparam ADDR_MODULUS_PTR_RST = 8'h30; localparam ADDR_MODULUS_DATA = 8'h31; localparam ADDR_EXPONENT_PTR_RST = 8'h40; localparam ADDR_EXPONENT_DATA = 8'h41; localparam ADDR_MESSAGE_PTR_RST = 8'h50; localparam ADDR_MESSAGE_DATA = 8'h51; localparam ADDR_RESULT_PTR_RST = 8'h60; localparam ADDR_RESULT_DATA = 8'h61; localparam DEFAULT_MODLENGTH = 8'h80; // 2048 bits. localparam DEFAULT_EXPLENGTH = 8'h80; localparam CORE_NAME0 = 32'h6d6f6465; // "mode" localparam CORE_NAME1 = 32'h78702020; // "xp " localparam CORE_VERSION = 32'h302e3532; // "0.52" //---------------------------------------------------------------- // Register and Wire declarations. //---------------------------------------------------------------- reg [31 : 0] error_ctr; reg [31 : 0] tc_ctr; reg [127 : 0] result_data; reg tb_clk; reg tb_reset; reg tb_cs; reg tb_we; reg [31 : 0] tb_address; reg [31 : 0] tb_write_data; wire [31 : 0] tb_read_data; wire tb_error; reg tb_cyc; reg [3 : 0] tb_sel; wire tb_ack; wire tb_err; wire tb_int; reg [31 : 0] pmsg [63 : 0]; reg [31 : 0] cmsg [63 : 0]; reg [31 : 0] gmsg [63 : 0]; integer f1; //---------------------------------------------------------------- // Device Under Test. //---------------------------------------------------------------- modexp_top dut( .wb_adr_i(tb_address), .wb_cyc_i(tb_cyc),// .wb_dat_i(tb_write_data), .wb_sel_i(tb_sel),// .wb_stb_i(tb_cs), .wb_we_i(tb_we), .wb_ack_o(tb_ack),// .wb_err_o(tb_err),// .wb_dat_o(tb_read_data), .wb_clk_i(tb_clk), .wb_rst_i(tb_reset), .int_o(tb_int)// ); //---------------------------------------------------------------- // clk_gen // // Always running clock generator process. //---------------------------------------------------------------- always begin : clk_gen #CLK_HALF_PERIOD; tb_clk = !tb_clk; end // clk_gen //---------------------------------------------------------------- // reset_dut() // // Toggle reset to put the DUT into a well known state. //---------------------------------------------------------------- task reset_dut(); begin $display("*** Toggle reset."); tb_reset = 1; #(2 * CLK_PERIOD); tb_reset = 0; $display(""); end endtask // reset_dut //---------------------------------------------------------------- // init_sim() // // Initialize all counters and testbed functionality as well // as setting the DUT inputs to defined values. //---------------------------------------------------------------- task init_sim(); begin error_ctr = 0; tc_ctr = 0; tb_clk = 0; tb_reset = 0; tb_cs = 0; tb_we = 0; tb_address = 32'h00000000; tb_write_data = 32'h00000000; end endtask // init_sim //---------------------------------------------------------------- // read_word() // // Read a data word from the given address in the DUT. //---------------------------------------------------------------- task read_word(input [7 : 0] address); begin tb_address = {22'b0,address,2'b0}; tb_cs = 1; tb_we = 0; #(CLK_PERIOD); tb_cs = 0; if (DEBUG) begin $display("*** (read_word) Reading 0x%08x from 0x%02x.", tb_read_data, address); $display(""); end end endtask // read_word //---------------------------------------------------------------- // write_word() // // Write the given word to the DUT using the DUT interface. //---------------------------------------------------------------- task write_word(input [ 7 : 0] address, input [31 : 0] word); begin if (DEBUG) begin $display("*** (write_word) Writing 0x%08x to 0x%02x.", word, address); $display(""); end tb_address = {22'b0,address,2'b0}; tb_write_data = word; tb_cs = 1; tb_we = 1; #(CLK_PERIOD); tb_cs = 0; tb_we = 0; end endtask // write_word //---------------------------------------------------------------- // wait_ready() // // Wait until the ready flag in the core is set. //---------------------------------------------------------------- task wait_ready(); begin while (tb_read_data != 32'h00000001) read_word(8'h09); if (DEBUG) $display("*** (wait_ready) Ready flag has been set."); end endtask // wait_ready //---------------------------------------------------------------- // assertEquals //---------------------------------------------------------------- function assertEquals( input [31:0] expected, input [31:0] actual ); begin if (expected === actual) begin assertEquals = 1; // success end else begin $display("*** Expected: 0x%08x, got 0x%08x", expected, actual); assertEquals = 0; // failure end end endfunction // assertEquals //---------------------------------------------------------------- // assertSuccess //---------------------------------------------------------------- task assertSuccess(input success); begin if (success !== 1) begin $display("*** Test -> FAILED"); error_ctr = error_ctr + 1; end else $display("*** Test -> passed"); end endtask // assertSuccess //---------------------------------------------------------------- // display_test_results() // // Display the accumulated test results. //---------------------------------------------------------------- task display_test_results(); begin $display(""); if (error_ctr == 0) begin $display("*** All %02d test cases completed successfully", tc_ctr); end else begin $display("*** %02d tests completed - %02d test cases did not complete successfully.", tc_ctr, error_ctr); end end endtask // display_test_results //---------------------------------------------------------------- // exp32bit_mod2048bit_test //---------------------------------------------------------------- task exp32bit_mod2048bit_test(); integer i; integer success; reg [31 : 0] read_data; reg [31 : 0] exp [63 : 0]; reg [31 : 0] mod [63 : 0]; reg [31 : 0] msg [63 : 0]; reg [31 : 0] res [63 : 0]; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display(""); $display("Test with e = 65537 and 2048 bit modulus -- Encrypting"); $readmemh("./gen/exp", exp); $readmemh("./gen/mod", mod); $readmemh("./gen/msg", msg); $readmemh("./gen/res", res); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , exp[0]); write_word(ADDR_MODULUS_PTR_RST, 32'h00000000); write_word(ADDR_MODULUS_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MODULUS_DATA, mod[i]); if(DEBUG) $display("writing: %d -> %h", i, mod[i]); end write_word(ADDR_MESSAGE_PTR_RST, 32'h00000000); write_word(ADDR_MESSAGE_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MESSAGE_DATA, msg[i]); if(DEBUG) $display("Writing: %d -> %h", i, msg[i]); end write_word(ADDR_EXPONENT_LENGTH, 32'h00000001); write_word(ADDR_MODULUS_LENGTH , 32'h00000041); // Start processing and wait for ready. write_word(ADDR_CTRL, 32'h00000001); wait_ready(); write_word(ADDR_RESULT_PTR_RST, 32'h00000000); read_word(ADDR_RESULT_DATA); read_data=tb_read_data; success=success&assertEquals(32'h00000000, read_data); for(i=0; i<64; i=i+1) begin read_word(ADDR_RESULT_DATA); read_data=tb_read_data; success=success&assertEquals(res[i], read_data); if(DEBUG) $display("Reading: %d -> %h -> %h", i, res[i], read_data); end if (success !== 1) begin $display("*** ERROR: e65537_2048bit_modulus was NOT successful."); error_ctr = error_ctr + 1; end else $display("*** e65537_2048bit_modulus success."); end endtask // exp32bit_mod2048bit_test //---------------------------------------------------------------- // modexp_encrypt //---------------------------------------------------------------- task modexp_encrypt(); integer i; integer success; reg [31 : 0] pubexp [1]; reg [31 : 0] pubmod [63 : 0]; begin success = 32'h1; tc_ctr = tc_ctr + 1; $display(""); $display("Encrypting -- exp = 65537 and 2048 bit mod"); $readmemh("./gen/pTextHEX", pmsg); $readmemh("./gen/exponent", pubexp); $readmemh("./gen/modulus", pubmod); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , pubexp[0]); if(DEBUG) $display("Writing EXP: %d %h", pubexp[0], pubexp[0]); write_word(ADDR_MODULUS_PTR_RST, 32'h00000000); write_word(ADDR_MODULUS_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MODULUS_DATA, pubmod[i]); if(DEBUG) $display("Writing MOD: %d -> %h", i, pubmod[i]); end write_word(ADDR_MESSAGE_PTR_RST, 32'h00000000); write_word(ADDR_MESSAGE_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MESSAGE_DATA, pmsg[i]); if(DEBUG) $display("Writing MSG: %d -> %h", i, pmsg[i]); end write_word(ADDR_EXPONENT_LENGTH, 32'h00000001); write_word(ADDR_MODULUS_LENGTH , 32'h00000041); // Start processing and wait for ready. write_word(ADDR_CTRL, 32'h00000001); wait_ready(); write_word(ADDR_RESULT_PTR_RST, 32'h00000000); read_word(ADDR_RESULT_DATA); cmsg[0]=tb_read_data; //success=success&assertEquals(32'h00000000, cmsg[0]); f1 = $fopen("./gen/cTextHEX", "w"); for(i=0; i<64; i=i+1) begin read_word(ADDR_RESULT_DATA); cmsg[i]=tb_read_data; if(DEBUG) $display("Reading: %d -> %h ", i, cmsg[i]); $fwrite(f1, "%h\n",cmsg[i]); end $fclose(f1); assertSuccess(success); end endtask // modexp_encrypt //---------------------------------------------------------------- // modexp_decrypt //---------------------------------------------------------------- task modexp_decrypt(); integer i; integer success; reg [31 : 0] rdata; reg [31 : 0] read_data; reg [31 : 0] priexp [63 : 0]; reg [31 : 0] primod [63 : 0]; begin $display(""); $display("*** Running -> modexp_decrypt()"); $readmemh("./gen/priExponent", priexp); $readmemh("./gen/priModulus", primod); success = 32'h1; tc_ctr = tc_ctr + 1; $display("Decrypting -- 2048 bit exp and 2048 bit mod"); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_EXPONENT_DATA, priexp[i]); if(DEBUG) $display("Writing EXP: %d -> %h", i, priexp[i]); end write_word(ADDR_MODULUS_PTR_RST, 32'h00000000); write_word(ADDR_MODULUS_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MODULUS_DATA, primod[i]); if(DEBUG) $display("Writing MOD: %d -> %h", i, primod[i]); end write_word(ADDR_MESSAGE_PTR_RST, 32'h00000000); write_word(ADDR_MESSAGE_DATA , 32'h00000000); for(i=0; i<64; i=i+1) begin write_word(ADDR_MESSAGE_DATA, cmsg[i]); if(DEBUG) $display("Writing MSG: %d -> %h", i, cmsg[i]); end write_word(ADDR_EXPONENT_LENGTH, 32'h00000041); write_word(ADDR_MODULUS_LENGTH , 32'h00000041); // Start processing and wait for ready. write_word(ADDR_CTRL, 32'h00000001); wait_ready(); write_word(ADDR_RESULT_PTR_RST, 32'h00000000); read_word(ADDR_RESULT_DATA); rdata=tb_read_data; success=success&assertEquals(32'h00000000, rdata); f1 = $fopen("./gen/gTextHEX", "w"); for(i=0; i<64; i=i+1) begin read_word(ADDR_RESULT_DATA); rdata=tb_read_data; if(DEBUG) $display("Reading: %d -> %h ", i, rdata); $fwrite(f1, "%h\n",rdata); success=success&assertEquals(pmsg[i], rdata); end $fclose(f1); assertSuccess(success); end endtask // modexp_decrypt //---------------------------------------------------------------- // modexp_32bits //---------------------------------------------------------------- task modexp_32bits(input [31:0] Wmsg, input [31:0] Wexp, input [31:0] Wmod, input [31:0] Wres); reg [31 : 0] Rmsg; reg [31 : 0] Rexp; reg [31 : 0] Rmod; reg [31 : 0] Rres; integer success; begin $display(""); $display("*** Running -> modexp_32bits()"); success = 32'h1; tc_ctr = tc_ctr + 1; $display("*** Writing -> MES: %h EXP: %h MOD: %h", Wmsg, Wexp, Wmod); write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); write_word(ADDR_EXPONENT_DATA , Wexp); write_word(ADDR_MODULUS_PTR_RST , 32'h00000000); write_word(ADDR_MODULUS_DATA , Wmod); write_word(ADDR_MESSAGE_PTR_RST , 32'h00000000); write_word(ADDR_MESSAGE_DATA , Wmsg); write_word(ADDR_EXPONENT_LENGTH , 32'h00000001); write_word(ADDR_MODULUS_LENGTH , 32'h00000001); // Start processing and wait for ready. write_word(ADDR_CTRL , 32'h00000001); wait_ready(); write_word(ADDR_MESSAGE_PTR_RST , 32'h00000000); read_word(ADDR_MESSAGE_DATA); Rmsg=tb_read_data; write_word(ADDR_EXPONENT_PTR_RST, 32'h00000000); read_word(ADDR_EXPONENT_DATA); Rexp=tb_read_data; write_word(ADDR_MODULUS_PTR_RST , 32'h00000000); read_word(ADDR_MODULUS_DATA); Rmod=tb_read_data; write_word(ADDR_RESULT_PTR_RST , 32'h00000000); read_word(ADDR_RESULT_DATA); Rres=tb_read_data; $display("*** Reading -> MES: %h EXP: %h MOD: %h RES: %h", Rmsg, Rexp, Rmod, Rres); success=success&assertEquals(Wres, Rres); assertSuccess(success); end endtask // modexp_32bits //---------------------------------------------------------------- // main // // The main test functionality. //---------------------------------------------------------------- initial begin : main if(VCD) begin $dumpfile("./iverilog/tb_top.vcd"); $dumpvars(0,tb_top); //$dumpvars(1,tb_clk, tb_reset, tb_cs, tb_we, tb_address, tb_write_data, tb_read_data); end $display(" -= Testbench for modexp started =-"); $display(" ================================="); $display(""); init_sim(); reset_dut(); modexp_32bits(32'h00000001, 32'h00000002, 32'h00000005, 32'h00000001); //msg^exp < mod -> 1^2 < 5 modexp_32bits(32'h00000001, 32'h00000002, 32'h00000003, 32'h00000001); //msg^exp < mod -> 1^2 < 3 modexp_32bits(32'h00000002, 32'h00000002, 32'h00000005, 32'h00000004); //msg^exp < mod -> 2^2 < 5 modexp_32bits(32'h00000002, 32'h00000002, 32'h00000003, 32'h00000001); //msg^exp > mod -> 2^2 > 3 modexp_32bits(32'h00000004, 32'h0000000D, 32'h000001F1, 32'h000001bd); //msg^exp > mod -> 4^13 > 497 modexp_32bits(32'h01234567, 32'h89ABCDEF, 32'h11111111, 32'h0D9EF081); //msg^exp > mod -> 19088743^2309737967 > 286331153 modexp_32bits(32'h30000000, 32'hC0000000, 32'h00A00001, 32'h0000CC3F); //msg^exp > mod -> 805306368^3221225472 > 10485761 <- Passes //modexp_32bits(32'h30000000, 32'hC0000000, 32'h00A00000, 32'h00600000); //msg^exp > mod -> 805306368^3221225472 > 10485760 <- Fails //modexp_32bits(32'h00000002, 32'h00000003, 32'h00000001, 32'h00000000); //mod 1 <- FAILS Does not check /* modexp_32bits(32'h00000001, 32'h00000002, 32'h00000002, 32'h00000001); //1 mod 2 = 1 -> 0 <- FAILS modexp_32bits(32'h00000001, 32'h00000002, 32'h00000003, 32'h00000001); //1 mod 3 = 1 -> 1 <- passes modexp_32bits(32'h00000001, 32'h00000002, 32'h00000004, 32'h00000001); //1 mod 4 = 1 -> 0 <- FAILS modexp_32bits(32'h00000001, 32'h00000002, 32'h00000005, 32'h00000001); //1 mod 5 = 1 -> 1 <- passes modexp_32bits(32'h00000001, 32'h00000002, 32'h00000006, 32'h00000001); //1 mod 6 = 1 -> 4 <- FAILS modexp_32bits(32'h00000002, 32'h00000001, 32'h00000002, 32'h00000000); //2 mod 2 = 0 -> passes modexp_32bits(32'h00000002, 32'h00000001, 32'h00000003, 32'h00000002); //2 mod 3 = 2 -> passes modexp_32bits(32'h00000002, 32'h00000001, 32'h00000004, 32'h00000002); //2 mod 4 = 2 -> 0 <- FAILS modexp_32bits(32'h00000002, 32'h00000001, 32'h00000005, 32'h00000002); //2 mod 5 = 2 -> passes modexp_32bits(32'h00000002, 32'h00000001, 32'h00000006, 32'h00000002); //2 mod 6 = 2 -> passes modexp_32bits(32'h00000003, 32'h00000001, 32'h00000002, 32'h00000001); //3 mod 2 = 1 -> 0 <- FAILS modexp_32bits(32'h00000003, 32'h00000001, 32'h00000003, 32'h00000000); //3 mod 3 = 0 -> 3 <- FAILS modexp_32bits(32'h00000003, 32'h00000001, 32'h00000004, 32'h00000003); //3 mod 4 = 3 -> 0 <- FAILS modexp_32bits(32'h00000003, 32'h00000001, 32'h00000005, 32'h00000003); //3 mod 5 = 3 -> passes modexp_32bits(32'h00000003, 32'h00000001, 32'h00000006, 32'h00000003); //3 mod 6 = 3 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000002, 32'h00000000); //4 mod 2 = 0 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000003, 32'h00000001); //4 mod 3 = 1 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000004, 32'h00000000); //4 mod 4 = 0 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000005, 32'h00000004); //4 mod 5 = 4 -> passes modexp_32bits(32'h00000004, 32'h00000001, 32'h00000006, 32'h00000004); //4 mod 6 = 4 -> passes modexp_32bits(32'h00000005, 32'h00000001, 32'h00000002, 32'h00000001); //5 mod 2 = 1 -> 0 <- FAILS modexp_32bits(32'h00000005, 32'h00000001, 32'h00000003, 32'h00000002); //5 mod 3 = 2 -> passes modexp_32bits(32'h00000005, 32'h00000001, 32'h00000004, 32'h00000001); //5 mod 4 = 1 -> 0 <- FAILS modexp_32bits(32'h00000005, 32'h00000001, 32'h00000005, 32'h00000000); //5 mod 5 = 0 -> 5 <- FAILS modexp_32bits(32'h00000005, 32'h00000001, 32'h00000006, 32'h00000005); //5 mod 6 = 5 -> passes modexp_32bits(32'h00000006, 32'h00000001, 32'h00000002, 32'h00000000); //6 mod 2 = 0 -> passes modexp_32bits(32'h00000006, 32'h00000001, 32'h00000003, 32'h00000000); //6 mod 3 = 0 -> 3 <- FAILS modexp_32bits(32'h00000006, 32'h00000001, 32'h00000004, 32'h00000002); //6 mod 4 = 2 -> 0 <- FAILS modexp_32bits(32'h00000006, 32'h00000001, 32'h00000005, 32'h00000001); //6 mod 5 = 1 -> passes modexp_32bits(32'h00000006, 32'h00000001, 32'h00000006, 32'h00000000); //6 mod 6 = 0 -> 1 <- FAILS */ /* modexp_32bits(32'h00000008, 32'h00000006, 32'h00000002, 32'h00000000); //8^6 mod 2 = 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000003, 32'h00000001); //8^6 mod 3 = 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000004, 32'h00000000); //8^6 mod 4 = 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000005, 32'h00000004); //8^6 mod 5 = 4 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000006, 32'h00000004); //8^6 mod 6 = 4 -> 1 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000007, 32'h00000001); //8^6 mod 7 = 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000008, 32'h00000000); //8^6 mod 8 = 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000009, 32'h00000001); //8^6 mod 9 = 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000A, 32'h00000004); //8^6 mod 10= 4 -> 9 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000B, 32'h00000003); //8^6 mod 11= 3 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000C, 32'h00000004); //8^6 mod 12= 4 -> 5 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000D, 32'h0000000C); //8^6 mod 13= 12-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000E, 32'h00000008); //8^6 mod 14= 8 -> 5 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000000F, 32'h00000004); //8^6 mod 15= 4 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000010, 32'h00000000); //8^6 mod 16= 0 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000011, 32'h00000004); //8^6 mod 17= 4 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000012, 32'h0000000A); //8^6 mod 18= 10-> 13<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000013, 32'h00000001); //8^6 mod 19= 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000014, 32'h00000004); //8^6 mod 20= 4 -> 11<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000015, 32'h00000001); //8^6 mod 21= 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000016, 32'h0000000E); //8^6 mod 22= 14-> 1 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000017, 32'h0000000D); //8^6 mod 23= 13-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h00000018, 32'h00000010); //8^6 mod 24= 16-> 9 <- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h00000019, 32'h00000013); //8^6 mod 25= 19-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001A, 32'h0000000C); //8^6 mod 26= 12-> 19<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001B, 32'h00000001); //8^6 mod 27= 1 -> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001C, 32'h00000008); //8^6 mod 28= 8 -> 19<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001D, 32'h0000000D); //8^6 mod 29= 13-> passes modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001E, 32'h00000004); //8^6 mod 30= 4 -> 13<- FAILS modexp_32bits(32'h00000008, 32'h00000006, 32'h0000001F, 32'h00000008); //8^6 mod 31= 8 -> passes */ //exp32bit_mod2048bit_test(); //modexp_encrypt(); //modexp_decrypt(); display_test_results(); $display(""); $display("*** modexp simulation done. ***"); $finish; end // main endmodule // tb_modexp //====================================================================== // EOF tb_modexp.v //======================================================================