OpenCores
URL https://opencores.org/ocsvn/altor32/altor32/trunk

Subversion Repositories altor32

[/] [altor32/] [trunk/] [rtl/] [cpu_lite/] [altor32_funcs.v] - Blame information for rev 37

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 34 ultra_embe
//-----------------------------------------------------------------
2
//                           AltOR32 
3
//                Alternative Lightweight OpenRisc 
4 36 ultra_embe
//                            V2.1
5 34 ultra_embe
//                     Ultra-Embedded.com
6 36 ultra_embe
//                   Copyright 2011 - 2014
7 34 ultra_embe
//
8
//               Email: admin@ultra-embedded.com
9
//
10
//                       License: LGPL
11
//-----------------------------------------------------------------
12
//
13 37 ultra_embe
// Copyright (C) 2011 - 2014 Ultra-Embedded.com
14 34 ultra_embe
//
15
// This source file may be used and distributed without         
16
// restriction provided that this copyright statement is not    
17
// removed from the file and that any derivative work contains  
18
// the original copyright notice and the associated disclaimer. 
19
//
20
// This source file is free software; you can redistribute it   
21
// and/or modify it under the terms of the GNU Lesser General   
22
// Public License as published by the Free Software Foundation; 
23
// either version 2.1 of the License, or (at your option) any   
24
// later version.
25
//
26
// This source is distributed in the hope that it will be       
27
// useful, but WITHOUT ANY WARRANTY; without even the implied   
28
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      
29
// PURPOSE.  See the GNU Lesser General Public License for more 
30
// details.
31
//
32
// You should have received a copy of the GNU Lesser General    
33
// Public License along with this source; if not, write to the 
34
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
35
// Boston, MA  02111-1307  USA
36
//-----------------------------------------------------------------
37
 
38
//-----------------------------------------------------------------
39
// less_than_signed: Less than operator (signed)
40
// Inputs: x = left operand, y = right operand
41
// Return: (int)x < (int)y
42
//-----------------------------------------------------------------
43
function [0:0] less_than_signed;
44
    input  [31:0] x;
45
    input  [31:0] y;
46
    reg [31:0] v;
47
begin
48
    v = (x - y);
49
    if (x[31] != y[31])
50
        less_than_signed = x[31];
51
    else
52
        less_than_signed = v[31];
53
end
54
endfunction
55
 
56
//-----------------------------------------------------------------
57
// less_than_equal_signed: Less than or equal to operator (signed)
58
// Inputs: x = left operand, y = right operand
59
// Return: (int)x <= (int)y
60
//-----------------------------------------------------------------
61
function [0:0] less_than_equal_signed;
62
    input  [31:0] x;
63
    input  [31:0] y;
64
    reg [31:0] v;
65
begin
66
    v = (x - y);
67
    if (x == y)
68
        less_than_equal_signed = 1'b1;
69
    else if (x[31] != y[31])
70
        less_than_equal_signed = x[31];
71
    else
72
        less_than_equal_signed = v[31];
73
end
74
endfunction
75
 
76
//-----------------------------------------------------------------
77
// greater_than_signed: Greater than operator (signed)
78
// Inputs: x = left operand, y = right operand
79
// Return: (int)x > (int)y
80
//-----------------------------------------------------------------
81
function [0:0] greater_than_signed;
82
    input  [31:0] x;
83
    input  [31:0] y;
84
    reg [31:0] v;
85
begin
86
    v = (y - x);
87
    if (x[31] != y[31])
88
        greater_than_signed = y[31];
89
    else
90
        greater_than_signed = v[31];
91
end
92
endfunction
93
 
94
//-----------------------------------------------------------------
95
// greater_than_equal_signed: Greater than or equal to operator (signed)
96
// Inputs: x = left operand, y = right operand
97
// Return: (int)x >= (int)y
98
//-----------------------------------------------------------------
99
function [0:0] greater_than_equal_signed;
100
    input  [31:0] x;
101
    input  [31:0] y;
102
    reg [31:0] v;
103
begin
104
    v = (y - x);
105
    if (x == y)
106
        greater_than_equal_signed = 1'b1;
107
    else if (x[31] != y[31])
108
        greater_than_equal_signed = y[31];
109
    else
110
        greater_than_equal_signed = v[31];
111
end
112
endfunction
113
 
114
//-----------------------------------------------------------------
115
// sign_extend_imm16: Extend 16-bit signed value to 32-bit signed.
116
// Inputs: x = operand
117
// Return: (int)((short)x)
118
//-----------------------------------------------------------------
119
function [31:0] sign_extend_imm16;
120
    input  [15:0] x;
121
    reg [31:0] y;
122
begin
123
    if (x[15] == 1'b0)
124
        y[31:16] = 16'b0000000000000000;
125
    else
126
        y[31:16] = 16'b1111111111111111;
127
 
128
    y[15:0] = x;
129
    sign_extend_imm16 = y;
130
end
131
endfunction
132
 
133
//-----------------------------------------------------------------
134
// sign_extend_imm26: Extend 26-bit signed value to 32-bit signed.
135
// Inputs: x = operand
136
// Return: (int)((short)x)
137
//-----------------------------------------------------------------
138
function [31:0] sign_extend_imm26;
139
    input  [25:0] x;
140
    reg [31:0] y;
141
begin
142
    if (x[25] == 1'b0)
143
        y[31:26] = 6'b000000;
144
    else
145
        y[31:26] = 6'b111111;
146
 
147
    y[25:0] = x;
148
    sign_extend_imm26 = y;
149
end
150
endfunction
151
 
152
//-----------------------------------------------------------------
153
// extend_imm16: Extend 16-bit unsigned value to 32-bit unsigned.
154
// Inputs: x = operand
155
// Return: (unsigned int)x
156
//-----------------------------------------------------------------
157
function [31:0] extend_imm16;
158
    input  [15:0] x;
159
begin
160
    extend_imm16 = {16'h0000,x};
161
end
162
endfunction
163
 
164
//-----------------------------------------------------------------
165
// less_than_zero: Is signed value less than 0?
166
// Inputs: x = operand
167
// Return: ((int)x) < 0
168
//-----------------------------------------------------------------
169
function [0:0] less_than_zero;
170
    input  [31:0] x;
171
begin
172
    if ((x != 32'h00000000) & (x[31] == 1'b1))
173
        less_than_zero = 1'b1;
174
    else
175
        less_than_zero = 1'b0;
176
end
177
endfunction
178
 
179
//-----------------------------------------------------------------
180
// less_than_equal_zero: Is signed value less than or equal to 0?
181
// Inputs: x = operand
182
// Return: ((int)x) <= 0
183
//-----------------------------------------------------------------
184
function [0:0] less_than_equal_zero;
185
    input  [31:0] x;
186
begin
187
    if ((x == 32'h00000000) | (x[31] == 1'b1))
188
        less_than_equal_zero = 1'b1;
189
    else
190
        less_than_equal_zero = 1'b0;
191
end
192
endfunction
193
 
194
//-----------------------------------------------------------------
195
// more_than_equal_zero: Is signed value more than or equal to 0?
196
// Inputs: x = operand
197
// Return: ((int)x) >= 0
198
//-----------------------------------------------------------------
199
function [0:0] more_than_equal_zero;
200
    input  [31:0] x;
201
begin
202
    if ((x == 32'h00000000) | (x[31] == 1'b0))
203
        more_than_equal_zero = 1'b1;
204
    else
205
        more_than_equal_zero = 1'b0;
206
end
207
endfunction
208
 
209
//-----------------------------------------------------------------
210
// more_than_equal_zero: Is signed value more than 0?
211
// Inputs: x = operand
212
// Return: ((int)x) > 0
213
//-----------------------------------------------------------------
214
function [0:0] more_than_zero;
215
    input  [31:0] x;
216
begin
217
    if (((x != 32'h00000000) & (x[31] == 1'b0)))
218
        more_than_zero = 1'b1;
219
    else
220
        more_than_zero = 1'b0;
221
end
222
endfunction
223
 
224
//-----------------------------------------------------------------
225
// is_load_operation: Is this opcode a load operation?
226
// Inputs: opcode
227
// Return: 1 or 0
228
//-----------------------------------------------------------------
229
function [0:0] is_load_operation;
230
    input [7:0] opcode;
231
begin
232
    is_load_operation = (opcode == `INST_OR32_LBS ||
233
                         opcode == `INST_OR32_LBZ ||
234
                         opcode == `INST_OR32_LHS ||
235
                         opcode == `INST_OR32_LHZ ||
236
                         opcode == `INST_OR32_LWZ ||
237
                         opcode == `INST_OR32_LWS) ? 1'b1 : 1'b0;
238
end
239
endfunction
240
 
241
//-----------------------------------------------------------------
242
// is_store_operation: Is this opcode a store operation?
243
// Inputs: opcode
244
// Return: 1 or 0
245
//-----------------------------------------------------------------
246
function [0:0] is_store_operation;
247
    input [7:0] opcode;
248
begin
249
    is_store_operation = (opcode == `INST_OR32_SB ||
250
                          opcode == `INST_OR32_SH ||
251
                          opcode == `INST_OR32_SW) ? 1'b1 : 1'b0;
252
end
253
endfunction

powered by: WebSVN 2.1.0

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