lm32_adder.v

Sat, 06 Aug 2011 01:26:56 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Sat, 06 Aug 2011 01:26:56 +0100
changeset 27
d6c693415d59
parent 26
73de224304c1
permissions
-rwxr-xr-x

remove synthesis delay entities to ease merge

philpem@26 1 // ==================================================================
philpem@26 2 // >>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<
philpem@26 3 // ------------------------------------------------------------------
philpem@26 4 // Copyright (c) 2006-2011 by Lattice Semiconductor Corporation
philpem@26 5 // ALL RIGHTS RESERVED
philpem@26 6 // ------------------------------------------------------------------
philpem@26 7 //
philpem@26 8 // IMPORTANT: THIS FILE IS AUTO-GENERATED BY THE LATTICEMICO SYSTEM.
philpem@26 9 //
philpem@26 10 // Permission:
philpem@26 11 //
philpem@26 12 // Lattice Semiconductor grants permission to use this code
philpem@26 13 // pursuant to the terms of the Lattice Semiconductor Corporation
philpem@26 14 // Open Source License Agreement.
philpem@26 15 //
philpem@26 16 // Disclaimer:
philpem@0 17 //
philpem@26 18 // Lattice Semiconductor provides no warranty regarding the use or
philpem@26 19 // functionality of this code. It is the user's responsibility to
philpem@26 20 // verify the userís design for consistency and functionality through
philpem@26 21 // the use of formal verification methods.
philpem@26 22 //
philpem@26 23 // --------------------------------------------------------------------
philpem@26 24 //
philpem@26 25 // Lattice Semiconductor Corporation
philpem@26 26 // 5555 NE Moore Court
philpem@26 27 // Hillsboro, OR 97214
philpem@26 28 // U.S.A
philpem@26 29 //
philpem@26 30 // TEL: 1-800-Lattice (USA and Canada)
philpem@26 31 // 503-286-8001 (other locations)
philpem@26 32 //
philpem@26 33 // web: http://www.latticesemi.com/
philpem@26 34 // email: techsupport@latticesemi.com
philpem@26 35 //
philpem@26 36 // --------------------------------------------------------------------
philpem@0 37 // FILE DETAILS
philpem@0 38 // Project : LatticeMico32
philpem@0 39 // File : lm32_adder.v
philpem@0 40 // Title : Integer adder / subtractor with comparison flag generation
philpem@0 41 // Dependencies : lm32_include.v
philpem@0 42 // Version : 6.1.17
philpem@0 43 // : Initial Release
philpem@0 44 // Version : 7.0SP2, 3.0
philpem@0 45 // : No Change
philpem@0 46 // Version : 3.1
philpem@0 47 // : No Change
philpem@0 48 // =============================================================================
philpem@0 49
philpem@0 50 `include "lm32_include.v"
philpem@0 51
philpem@0 52 /////////////////////////////////////////////////////
philpem@0 53 // Module interface
philpem@0 54 /////////////////////////////////////////////////////
philpem@0 55
philpem@0 56 module lm32_adder (
philpem@0 57 // ----- Inputs -------
philpem@0 58 adder_op_x,
philpem@0 59 adder_op_x_n,
philpem@0 60 operand_0_x,
philpem@0 61 operand_1_x,
philpem@0 62 // ----- Outputs -------
philpem@0 63 adder_result_x,
philpem@0 64 adder_carry_n_x,
philpem@0 65 adder_overflow_x
philpem@0 66 );
philpem@0 67
philpem@0 68 /////////////////////////////////////////////////////
philpem@0 69 // Inputs
philpem@0 70 /////////////////////////////////////////////////////
philpem@0 71
philpem@0 72 input adder_op_x; // Operating to perform, 0 for addition, 1 for subtraction
philpem@0 73 input adder_op_x_n; // Inverted version of adder_op_x
philpem@0 74 input [`LM32_WORD_RNG] operand_0_x; // Operand to add, or subtract from
philpem@0 75 input [`LM32_WORD_RNG] operand_1_x; // Opearnd to add, or subtract by
philpem@0 76
philpem@0 77 /////////////////////////////////////////////////////
philpem@0 78 // Outputs
philpem@0 79 /////////////////////////////////////////////////////
philpem@0 80
philpem@0 81 output [`LM32_WORD_RNG] adder_result_x; // Result of addition or subtraction
philpem@0 82 wire [`LM32_WORD_RNG] adder_result_x;
philpem@0 83 output adder_carry_n_x; // Inverted carry
philpem@0 84 wire adder_carry_n_x;
philpem@0 85 output adder_overflow_x; // Indicates if overflow occured, only valid for subtractions
philpem@0 86 reg adder_overflow_x;
philpem@0 87
philpem@0 88 /////////////////////////////////////////////////////
philpem@0 89 // Internal nets and registers
philpem@0 90 /////////////////////////////////////////////////////
philpem@0 91
philpem@0 92 wire a_sign; // Sign (i.e. positive or negative) of operand 0
philpem@0 93 wire b_sign; // Sign of operand 1
philpem@0 94 wire result_sign; // Sign of result
philpem@0 95
philpem@0 96 /////////////////////////////////////////////////////
philpem@0 97 // Instantiations
philpem@0 98 /////////////////////////////////////////////////////
philpem@0 99
philpem@0 100 lm32_addsub addsub (
philpem@0 101 // ----- Inputs -----
philpem@0 102 .DataA (operand_0_x),
philpem@0 103 .DataB (operand_1_x),
philpem@0 104 .Cin (adder_op_x),
philpem@0 105 .Add_Sub (adder_op_x_n),
philpem@0 106 // ----- Ouputs -----
philpem@0 107 .Result (adder_result_x),
philpem@0 108 .Cout (adder_carry_n_x)
philpem@0 109 );
philpem@0 110
philpem@0 111 /////////////////////////////////////////////////////
philpem@0 112 // Combinational Logic
philpem@0 113 /////////////////////////////////////////////////////
philpem@0 114
philpem@0 115 // Extract signs of operands and result
philpem@0 116
philpem@0 117 assign a_sign = operand_0_x[`LM32_WORD_WIDTH-1];
philpem@0 118 assign b_sign = operand_1_x[`LM32_WORD_WIDTH-1];
philpem@0 119 assign result_sign = adder_result_x[`LM32_WORD_WIDTH-1];
philpem@0 120
philpem@0 121 // Determine whether an overflow occured when performing a subtraction
philpem@0 122
philpem@0 123 always @(*)
philpem@0 124 begin
philpem@0 125 // +ve - -ve = -ve -> overflow
philpem@0 126 // -ve - +ve = +ve -> overflow
philpem@0 127 if ( (!a_sign & b_sign & result_sign)
philpem@0 128 || (a_sign & !b_sign & !result_sign)
philpem@0 129 )
philpem@0 130 adder_overflow_x = `TRUE;
philpem@0 131 else
philpem@0 132 adder_overflow_x = `FALSE;
philpem@0 133 end
philpem@0 134
philpem@0 135 endmodule
philpem@0 136