|
|
//======================================================================
//
// Copyright (c) 2019, 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.
//
//======================================================================
//
// Headers
//
`include "modexpng_parameters_x8.vh"
`include "cryptech_clog2.vh"
//
// Debug Settings
//
/* Only define this for simulation, must be turned off to synthesize properly! */
//`define MODEXPNG_ENABLE_DEBUG
//
// Core Settings
//
localparam MAX_OP_W = 4096;
localparam WORD_W = 16;
localparam WORD_EXT_W = 18;
localparam MAC_W = 47;
localparam BUS_DATA_W = 32;
localparam BUS_OP_ADDR_W = cryptech_clog2(MAX_OP_W / BUS_DATA_W);
localparam BIT_INDEX_W = cryptech_clog2(MAX_OP_W);
localparam BANK_ADDR_W = 3;
localparam OP_ADDR_W = cryptech_clog2(MAX_OP_W / WORD_W);
localparam COL_INDEX_W = OP_ADDR_W - cryptech_clog2(NUM_MULTS);
localparam MAC_INDEX_W = cryptech_clog2(NUM_MULTS);
localparam CARRY_W = WORD_EXT_W - WORD_W;
localparam WORD_MUX_W = cryptech_clog2(WORD_W);
//
// Wide Bank
//
localparam [BANK_ADDR_W-1:0] BANK_WIDE_A = 3'd0;
localparam [BANK_ADDR_W-1:0] BANK_WIDE_B = 3'd1;
localparam [BANK_ADDR_W-1:0] BANK_WIDE_C = 3'd2;
localparam [BANK_ADDR_W-1:0] BANK_WIDE_D = 3'd3;
localparam [BANK_ADDR_W-1:0] BANK_WIDE_E = 3'd4;
localparam [BANK_ADDR_W-1:0] BANK_WIDE_N = 3'd5;
localparam [BANK_ADDR_W-1:0] BANK_WIDE_L = 3'd6;
localparam [BANK_ADDR_W-1:0] BANK_WIDE_H = 3'd7;
//
// Narrow Bank
//
localparam [BANK_ADDR_W-1:0] BANK_NARROW_A = 3'd0;
localparam [BANK_ADDR_W-1:0] BANK_NARROW_B = 3'd1;
localparam [BANK_ADDR_W-1:0] BANK_NARROW_C = 3'd2;
localparam [BANK_ADDR_W-1:0] BANK_NARROW_D = 3'd3;
localparam [BANK_ADDR_W-1:0] BANK_NARROW_E = 3'd4;
localparam [BANK_ADDR_W-1:0] BANK_NARROW_COEFF = 3'd5;
localparam [BANK_ADDR_W-1:0] BANK_NARROW_Q = 3'd6;
localparam [BANK_ADDR_W-1:0] BANK_NARROW_EXT = 3'd7; // [0] -> COEFF', [1] -> Q'
//
// Recombinator Bank
//
localparam [BANK_ADDR_W-1:0] BANK_RCMB_ML = 3'd0;
localparam [BANK_ADDR_W-1:0] BANK_RCMB_MH = 3'd1;
localparam [BANK_ADDR_W-1:0] BANK_RCMB_EXT = 3'd2; // [0] -> MH'
//
// Input Bank #1
//
localparam [BANK_ADDR_W-1:0] BANK_IN_1_M = 3'd0;
localparam [BANK_ADDR_W-1:0] BANK_IN_1_N = 3'd1;
localparam [BANK_ADDR_W-1:0] BANK_IN_1_N_FACTOR = 3'd2;
localparam [BANK_ADDR_W-1:0] BANK_IN_1_N_COEFF = 3'd3;/*
localparam [BANK_ADDR_W-1:0] BANK_IN_1_EXT = 3'd4; // [0] -> N_COEFF'*/
localparam [BANK_ADDR_W-1:0] BANK_IN_1_X = 3'd5;
localparam [BANK_ADDR_W-1:0] BANK_IN_1_Y = 3'd6;
//
// Input Bank #2
//
localparam [BANK_ADDR_W-1:0] BANK_IN_2_D = 3'd0;
localparam [BANK_ADDR_W-1:0] BANK_IN_2_P = 3'd1;
localparam [BANK_ADDR_W-1:0] BANK_IN_2_P_FACTOR = 3'd2;
localparam [BANK_ADDR_W-1:0] BANK_IN_2_P_COEFF = 3'd3;
localparam [BANK_ADDR_W-1:0] BANK_IN_2_Q = 3'd4;
localparam [BANK_ADDR_W-1:0] BANK_IN_2_Q_FACTOR = 3'd5;
localparam [BANK_ADDR_W-1:0] BANK_IN_2_Q_COEFF = 3'd6;
localparam [BANK_ADDR_W-1:0] BANK_IN_2_QINV = 3'd7;
//
// Output Bank
//
localparam [BANK_ADDR_W-1:0] BANK_OUT_S = 3'd0;
localparam [BANK_ADDR_W-1:0] BANK_OUT_XM = 3'd1;
localparam [BANK_ADDR_W-1:0] BANK_OUT_YM = 3'd2;
//
// Carry Values
//
localparam [CARRY_W-1:0] CARRY_ZERO = {CARRY_W{1'b0}};
//
// Bank Values
//
localparam [ BANK_ADDR_W-1:0] BANK_DNC = {BANK_ADDR_W{1'bX}};
localparam [4*BANK_ADDR_W-1:0] BANK_DNC_ALL = {4{BANK_DNC}};
//
// Operand Address Values
//
localparam [OP_ADDR_W-1:0] OP_ADDR_LADDER_LAST = 3; // 0..3, i.e. <dummy>, D, P, Q
localparam [OP_ADDR_W-1:0] OP_ADDR_EXT_COEFF = 0;
localparam [OP_ADDR_W-1:0] OP_ADDR_EXT_Q = 1;
localparam [OP_ADDR_W-1:0] OP_ADDR_ZERO = {OP_ADDR_W{1'b0}};
localparam [OP_ADDR_W-1:0] OP_ADDR_ONE = {{(OP_ADDR_W-1){1'b0}}, 1'b1};
localparam [OP_ADDR_W-1:0] OP_ADDR_DNC = {OP_ADDR_W{1'bX}};
//
// Bit Index Values
//
localparam [BIT_INDEX_W-1:0] BIT_INDEX_ZERO = {BIT_INDEX_W{1'b0}};
localparam [BIT_INDEX_W-1:0] BIT_INDEX_DNC = {BIT_INDEX_W{1'bX}};
//
// Word Values
//
localparam [WORD_W-1:0] WORD_ZERO = {WORD_W{1'b0}};
localparam [WORD_W-1:0] WORD_DNC = {WORD_W{1'bX}};
localparam [WORD_W-1:0] WORD_ONE = {{(WORD_W-1){1'b0}}, 1'b1};
//
// Extended Word Values
//
localparam [WORD_EXT_W-1:0] WORD_EXT_ZERO = {WORD_EXT_W{1'b0}};
localparam [WORD_EXT_W-1:0] WORD_EXT_DNC = {WORD_EXT_W{1'bX}};
//
// MAC Index Values
//
localparam [MAC_INDEX_W-1:0] MAC_INDEX_DNC = {MAC_INDEX_W{1'bX}};
//
// Multiplier Bitmap Values
//
localparam [NUM_MULTS-1:0] MULT_BITMAP_ZEROES = {NUM_MULTS{1'b0}};
|