lm32_adder.v

Mon, 05 Apr 2010 21:00:31 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Mon, 05 Apr 2010 21:00:31 +0100
changeset 6
a8e459b24c31
parent 0
cd0b58aa6f83
child 26
73de224304c1
permissions
-rw-r--r--

reduce size of caches to fit in DE1 FPGA

The default cache size makes the Icache and Dcache "just a bit" too big to
fit in the EP2C20 FPGA on the DE1 board. This commit reduces the Icache and
Dcache sizes to the defaults shown in the LatticeMico32 Processor Reference
Manual (pages 36 and 37).

     1 // =============================================================================
     2 //                           COPYRIGHT NOTICE
     3 // Copyright 2006 (c) Lattice Semiconductor Corporation
     4 // ALL RIGHTS RESERVED
     5 // This confidential and proprietary software may be used only as authorised by
     6 // a licensing agreement from Lattice Semiconductor Corporation.
     7 // The entire notice above must be reproduced on all authorized copies and
     8 // copies may only be made to the extent permitted by a licensing agreement from
     9 // Lattice Semiconductor Corporation.
    10 //
    11 // Lattice Semiconductor Corporation        TEL : 1-800-Lattice (USA and Canada)
    12 // 5555 NE Moore Court                            408-826-6000 (other locations)
    13 // Hillsboro, OR 97124                     web  : http://www.latticesemi.com/
    14 // U.S.A                                   email: techsupport@latticesemi.com
    15 // ============================================================================/
    16 //                         FILE DETAILS
    17 // Project          : LatticeMico32
    18 // File             : lm32_adder.v
    19 // Title            : Integer adder / subtractor with comparison flag generation 
    20 // Dependencies     : lm32_include.v
    21 // Version          : 6.1.17
    22 //                  : Initial Release
    23 // Version          : 7.0SP2, 3.0
    24 //                  : No Change
    25 // Version          : 3.1
    26 //                  : No Change
    27 // =============================================================================
    29 `include "lm32_include.v"
    31 /////////////////////////////////////////////////////
    32 // Module interface
    33 /////////////////////////////////////////////////////
    35 module lm32_adder (
    36     // ----- Inputs -------
    37     adder_op_x,
    38     adder_op_x_n,
    39     operand_0_x,
    40     operand_1_x,
    41     // ----- Outputs -------
    42     adder_result_x,
    43     adder_carry_n_x,
    44     adder_overflow_x
    45     );
    47 /////////////////////////////////////////////////////
    48 // Inputs
    49 /////////////////////////////////////////////////////
    51 input adder_op_x;                                       // Operating to perform, 0 for addition, 1 for subtraction
    52 input adder_op_x_n;                                     // Inverted version of adder_op_x
    53 input [`LM32_WORD_RNG] operand_0_x;                     // Operand to add, or subtract from
    54 input [`LM32_WORD_RNG] operand_1_x;                     // Opearnd to add, or subtract by
    56 /////////////////////////////////////////////////////
    57 // Outputs
    58 /////////////////////////////////////////////////////
    60 output [`LM32_WORD_RNG] adder_result_x;                 // Result of addition or subtraction
    61 wire   [`LM32_WORD_RNG] adder_result_x;
    62 output adder_carry_n_x;                                 // Inverted carry
    63 wire   adder_carry_n_x;
    64 output adder_overflow_x;                                // Indicates if overflow occured, only valid for subtractions
    65 reg    adder_overflow_x;
    67 /////////////////////////////////////////////////////
    68 // Internal nets and registers 
    69 /////////////////////////////////////////////////////
    71 wire a_sign;                                            // Sign (i.e. positive or negative) of operand 0
    72 wire b_sign;                                            // Sign of operand 1
    73 wire result_sign;                                       // Sign of result
    75 /////////////////////////////////////////////////////
    76 // Instantiations 
    77 /////////////////////////////////////////////////////
    79 lm32_addsub addsub (
    80     // ----- Inputs -----
    81     .DataA          (operand_0_x), 
    82     .DataB          (operand_1_x), 
    83     .Cin            (adder_op_x), 
    84     .Add_Sub        (adder_op_x_n), 
    85     // ----- Ouputs -----
    86     .Result         (adder_result_x), 
    87     .Cout           (adder_carry_n_x)
    88     );
    90 /////////////////////////////////////////////////////
    91 // Combinational Logic
    92 /////////////////////////////////////////////////////
    94 // Extract signs of operands and result
    96 assign a_sign = operand_0_x[`LM32_WORD_WIDTH-1];
    97 assign b_sign = operand_1_x[`LM32_WORD_WIDTH-1];
    98 assign result_sign = adder_result_x[`LM32_WORD_WIDTH-1];
   100 // Determine whether an overflow occured when performing a subtraction
   102 always @(*)
   103 begin    
   104     //  +ve - -ve = -ve -> overflow
   105     //  -ve - +ve = +ve -> overflow
   106     if  (   (!a_sign & b_sign & result_sign)
   107          || (a_sign & !b_sign & !result_sign)
   108         )
   109         adder_overflow_x = `TRUE;
   110     else
   111         adder_overflow_x = `FALSE;
   112 end
   114 endmodule