OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_processor/] [new_lm32/] [rtl/] [lm32_adder.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
//   ==================================================================
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
// =============================================================================
49
 
50
`include "lm32_include.v"
51
 
52
/////////////////////////////////////////////////////
53
// Module interface
54
/////////////////////////////////////////////////////
55
 
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
    );
67
 
68
/////////////////////////////////////////////////////
69
// Inputs
70
/////////////////////////////////////////////////////
71
 
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
76
 
77
/////////////////////////////////////////////////////
78
// Outputs
79
/////////////////////////////////////////////////////
80
 
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;
87
 
88
/////////////////////////////////////////////////////
89
// Internal nets and registers
90
/////////////////////////////////////////////////////
91
 
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
95
 
96
/////////////////////////////////////////////////////
97
// Instantiations
98
/////////////////////////////////////////////////////
99
 
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
    );
110
 
111
/////////////////////////////////////////////////////
112
// Combinational Logic
113
/////////////////////////////////////////////////////
114
 
115
// Extract signs of operands and result
116
 
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];
120
 
121
// Determine whether an overflow occured when performing a subtraction
122
 
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
134
 
135
endmodule
136
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.