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