lm32_multiplier.v

changeset 0
cd0b58aa6f83
child 26
73de224304c1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lm32_multiplier.v	Sun Apr 04 20:40:03 2010 +0100
     1.3 @@ -0,0 +1,99 @@
     1.4 +// =============================================================================
     1.5 +//                           COPYRIGHT NOTICE
     1.6 +// Copyright 2006 (c) Lattice Semiconductor Corporation
     1.7 +// ALL RIGHTS RESERVED
     1.8 +// This confidential and proprietary software may be used only as authorised by
     1.9 +// a licensing agreement from Lattice Semiconductor Corporation.
    1.10 +// The entire notice above must be reproduced on all authorized copies and
    1.11 +// copies may only be made to the extent permitted by a licensing agreement from
    1.12 +// Lattice Semiconductor Corporation.
    1.13 +//
    1.14 +// Lattice Semiconductor Corporation        TEL : 1-800-Lattice (USA and Canada)
    1.15 +// 5555 NE Moore Court                            408-826-6000 (other locations)
    1.16 +// Hillsboro, OR 97124                     web  : http://www.latticesemi.com/
    1.17 +// U.S.A                                   email: techsupport@latticesemi.com
    1.18 +// =============================================================================/
    1.19 +//                         FILE DETAILS
    1.20 +// Project          : LatticeMico32
    1.21 +// File             : lm32_multiplier.v
    1.22 +// Title            : Pipelined multiplier.
    1.23 +// Dependencies     : lm32_include.v
    1.24 +// Version          : 6.1.17
    1.25 +//                  : Initial Release
    1.26 +// Version          : 7.0SP2, 3.0
    1.27 +//                  : No Change
    1.28 +// Version          : 3.1
    1.29 +//                  : No Change
    1.30 +// =============================================================================
    1.31 +                  
    1.32 +`include "lm32_include.v"
    1.33 +
    1.34 +/////////////////////////////////////////////////////
    1.35 +// Module interface
    1.36 +/////////////////////////////////////////////////////
    1.37 +
    1.38 +module lm32_multiplier (
    1.39 +    // ----- Inputs -----
    1.40 +    clk_i,
    1.41 +    rst_i,
    1.42 +    stall_x,
    1.43 +    stall_m,
    1.44 +    operand_0,
    1.45 +    operand_1,
    1.46 +    // ----- Ouputs -----
    1.47 +    result
    1.48 +    );
    1.49 +
    1.50 +/////////////////////////////////////////////////////
    1.51 +// Inputs
    1.52 +/////////////////////////////////////////////////////
    1.53 +
    1.54 +input clk_i;                            // Clock 
    1.55 +input rst_i;                            // Reset
    1.56 +input stall_x;                          // Stall instruction in X stage
    1.57 +input stall_m;                          // Stall instruction in M stage
    1.58 +input [`LM32_WORD_RNG] operand_0;     	// Muliplicand
    1.59 +input [`LM32_WORD_RNG] operand_1;     	// Multiplier
    1.60 +
    1.61 +/////////////////////////////////////////////////////
    1.62 +// Outputs
    1.63 +/////////////////////////////////////////////////////
    1.64 +
    1.65 +output [`LM32_WORD_RNG] result;       	// Product of multiplication
    1.66 +reg    [`LM32_WORD_RNG] result;
    1.67 +
    1.68 +/////////////////////////////////////////////////////
    1.69 +// Internal nets and registers 
    1.70 +/////////////////////////////////////////////////////
    1.71 +
    1.72 +reg [`LM32_WORD_RNG] muliplicand; 
    1.73 +reg [`LM32_WORD_RNG] multiplier; 
    1.74 +reg [`LM32_WORD_RNG] product; 
    1.75 +
    1.76 +/////////////////////////////////////////////////////
    1.77 +// Sequential logic
    1.78 +/////////////////////////////////////////////////////
    1.79 +
    1.80 +always @(posedge clk_i `CFG_RESET_SENSITIVITY)
    1.81 +begin
    1.82 +    if (rst_i == `TRUE)
    1.83 +    begin
    1.84 +        muliplicand <= {`LM32_WORD_WIDTH{1'b0}};
    1.85 +        multiplier <= {`LM32_WORD_WIDTH{1'b0}};
    1.86 +        product <= {`LM32_WORD_WIDTH{1'b0}};
    1.87 +        result <= {`LM32_WORD_WIDTH{1'b0}};
    1.88 +    end
    1.89 +    else
    1.90 +    begin
    1.91 +        if (stall_x == `FALSE)
    1.92 +        begin    
    1.93 +            muliplicand <= operand_0;
    1.94 +            multiplier <= operand_1;
    1.95 +        end
    1.96 +        if (stall_m == `FALSE)
    1.97 +            product <= muliplicand * multiplier;
    1.98 +        result <= product;
    1.99 +    end
   1.100 +end
   1.101 +
   1.102 +endmodule