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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [gsi/] [ssram/] [functions.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
-----------------------------------------------------------
2
-- VHDL file for FUNCTIONs used in verilog2vhdl files
3
-- DO NOT MODIFY THIS FILE
4
-- Author : S.O
5
-- Date   : March 14, 1995
6
-- Modification History --
7
-- 3/31/95 Added shift operations (S.O)
8
-- 4/6/95 Added arithmetic operations for std_logic_vectors (S.O)
9
-- 4/11/95 Added conversion functions
10
-- 10/5/95 added to_boolean conversions
11
-- 1/31/96 added funcs. for std_logic and std_logic
12
-- 2/28/96 added funcs. for TERNARY combinations
13
-- 4/18/96 added logical operations bet. std_logic_vector and integer/boolean
14
-- 7/9/96  modified all TERNARY functions with *ulogic* conditional
15
-----------------------------------------------------------
16
 
17
library ieee;
18
library GSI;
19
use ieee.std_logic_1164.all;
20
--use ieee.numeric_std.all;
21
library grlib;
22
use grlib.stdlib.all;
23
 
24
package FUNCTIONS is
25
 
26
-- TYPE used in conversion function
27
TYPE direction is (LITTLE_ENDIAN, BIG_ENDIAN);
28
 
29
TYPE hex_digit IS ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',
30
                   'B', 'C', 'D', 'E', 'F', 'a', 'b', 'c', 'd', 'e', 'f');
31
TYPE hex_number IS array (POSITIVE range <>) OF hex_digit;
32
 
33
TYPE hexstdlogic IS ARRAY (hex_digit'LOW TO hex_digit'HIGH) of std_logic_vector(3 DOWNTO 0);
34
 
35
-- This conversion table would not accept X or Z.
36
-- To convert a hex number with X or Z use to_stdlogicvector(hex : STRING).
37
--CONSTANT hex_to_stdlogic : hexstdlogic := (x"0", x"1", x"2", x"3", x"4", x"5",
38
--       x"6", x"7", x"8", x"9", x"A", x"B", x"C", x"D", x"E", x"F", x"A", x"B",
39
--       x"C", x"D", x"E", x"F");
40
 
41
-- Signals used for v2v
42
 
43
--SIGNAL v2v_std_logic : std_logic;
44
--SIGNAL v2v_sig_integer : integer;
45
--SIGNAL v2v_boolean : boolean;
46
--SIGNAL v2v_real : real;
47
 
48
-- FUNCTIONs for unary operations
49
 
50
FUNCTION U_AND(a : std_ulogic_vector) return std_ulogic;
51
FUNCTION U_AND(a : std_logic_vector) return std_logic;
52
 
53
FUNCTION U_NAND(a : std_ulogic_vector) return std_ulogic;
54
FUNCTION U_NAND(a : std_logic_vector) return std_logic;
55
 
56
FUNCTION U_OR(a : std_ulogic_vector) return std_ulogic;
57
FUNCTION U_OR(a : std_logic_vector) return std_logic;
58
 
59
FUNCTION U_NOR(a : std_ulogic_vector) return std_ulogic;
60
FUNCTION U_NOR(a : std_logic_vector) return std_logic;
61
 
62
FUNCTION U_XOR(a : std_ulogic_vector) return std_ulogic;
63
FUNCTION U_XOR(a : std_logic_vector) return std_logic;
64
 
65
FUNCTION U_XNOR(a : std_ulogic_vector) return std_ulogic;
66
FUNCTION U_XNOR(a : std_logic_vector) return std_logic;
67
 
68
-- FUNCTIONs for ternary operations
69
 
70
FUNCTION TERNARY(a,b,c : boolean) return boolean;
71
FUNCTION TERNARY(a : boolean; b,c : std_ulogic) return std_ulogic;
72
FUNCTION TERNARY(a : boolean; b,c : std_ulogic_vector) return std_ulogic_vector;
73
FUNCTION TERNARY(a : boolean; b,c : std_logic_vector) return std_logic_vector;
74
--pragma synthesis_off
75
FUNCTION TERNARY(a : boolean; b,c : real) return real;
76
FUNCTION TERNARY(a : boolean; b,c : time) return time;
77
--pragma synthesis_on
78
 
79
FUNCTION TERNARY(a,b,c : integer) return integer;
80
FUNCTION TERNARY(a : integer; b,c : std_ulogic) return std_ulogic;
81
FUNCTION TERNARY(a : integer; b,c : std_ulogic_vector) return std_ulogic_vector;
82
FUNCTION TERNARY(a : integer; b,c : std_logic_vector) return std_logic_vector;
83
--pragma synthesis_off
84
FUNCTION TERNARY(a : integer; b,c : real) return real;
85
FUNCTION TERNARY(a : integer; b,c : time) return time;
86
--pragma synthesis_on
87
 
88
FUNCTION TERNARY(a,b,c : std_ulogic) return std_ulogic;
89
FUNCTION TERNARY(a : std_ulogic; b,c : integer) return integer;
90
FUNCTION TERNARY(a : std_ulogic; b,c : std_ulogic_vector) return std_ulogic_vector;
91
FUNCTION TERNARY(a : std_ulogic; b,c : std_logic_vector) return std_logic_vector;
92
--pragma synthesis_off
93
FUNCTION TERNARY(a : std_ulogic; b,c : real) return real;
94
FUNCTION TERNARY(a : std_ulogic; b,c : time) return time;
95
--pragma synthesis_on
96
 
97
FUNCTION TERNARY(a,b,c : std_ulogic_vector) return std_ulogic_vector;
98
FUNCTION TERNARY(a : std_ulogic_vector; b,c : integer) return integer;
99
FUNCTION TERNARY(a : std_ulogic_vector; b,c : std_ulogic) return std_ulogic;
100
FUNCTION TERNARY(a : std_ulogic_vector; b,c : std_logic_vector) return std_logic_vector;
101
--pragma synthesis_off
102
FUNCTION TERNARY(a : std_ulogic_vector; b,c : real) return real;
103
FUNCTION TERNARY(a : std_ulogic_vector; b,c : time) return time;
104
--pragma synthesis_on
105
 
106
FUNCTION TERNARY(a,b,c : std_logic_vector) return std_logic_vector;
107
FUNCTION TERNARY(a : std_logic_vector; b,c : integer) return integer;
108
FUNCTION TERNARY(a : std_logic_vector; b,c : std_ulogic) return std_ulogic;
109
FUNCTION TERNARY(a : std_logic_vector; b,c : std_ulogic_vector) return std_ulogic_vector;
110
--pragma synthesis_off
111
FUNCTION TERNARY(a : std_logic_vector; b,c : real) return real;
112
FUNCTION TERNARY(a : std_logic_vector; b,c : time) return time;
113
 
114
FUNCTION TERNARY(a,b,c : real) return real;
115
FUNCTION TERNARY(a : real; b,c : std_ulogic) return std_ulogic;
116
FUNCTION TERNARY(a : real; b,c : std_ulogic_vector) return std_ulogic_vector;
117
FUNCTION TERNARY(a : real; b,c : std_logic_vector) return std_logic_vector;
118
FUNCTION TERNARY(a : real; b,c : integer) return integer;
119
FUNCTION TERNARY(a : real; b,c : time) return time;
120
--pragma synthesis_on
121
 
122
-- functions for TERNARY combination
123
FUNCTION TERNARY(a : std_ulogic; b : std_logic_vector; c: std_ulogic) return
124
        std_logic_vector;
125
 
126
FUNCTION TERNARY(a : std_ulogic; b : std_ulogic; c: std_logic_vector) return
127
        std_logic_vector;
128
 
129
FUNCTION TERNARY(a : std_ulogic; b : integer; c: std_ulogic) return
130
        integer;
131
 
132
FUNCTION TERNARY(a : std_ulogic; b : std_ulogic; c: integer) return
133
        integer;
134
 
135
FUNCTION TERNARY(a : integer; b : integer; c: std_ulogic) return
136
        integer;
137
 
138
FUNCTION TERNARY(a : integer; b : std_ulogic; c: integer) return
139
        integer;
140
 
141
FUNCTION TERNARY(a : integer; b : std_logic_vector; c: std_ulogic) return
142
        std_logic_vector;
143
 
144
FUNCTION TERNARY(a : integer; b : std_ulogic; c: std_logic_vector) return
145
        std_logic_vector;
146
 
147
 
148
 
149
 
150
 
151
--end functions for TERNARY combination
152
 
153
-- FUNCTIONS for shift operations
154
 
155
FUNCTION "sll"  ( l : std_logic_vector; r : integer) RETURN std_logic_vector;
156
FUNCTION "sll"  ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector;
157
 
158
FUNCTION "srl"  ( l : std_logic_vector; r : integer) RETURN std_logic_vector;
159
FUNCTION "srl"  ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector;
160
 
161
FUNCTION "sla"  ( l : std_logic_vector; r : integer) RETURN std_logic_vector;
162
FUNCTION "sla"  ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector;
163
 
164
FUNCTION "sra"  ( l : std_logic_vector; r : integer) RETURN std_logic_vector;
165
FUNCTION "sra"  ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector;
166
 
167
FUNCTION "rol"  ( l : std_logic_vector; r : integer) RETURN std_logic_vector;
168
FUNCTION "rol"  ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector;
169
 
170
FUNCTION "ror"  ( l : std_logic_vector; r : integer) RETURN std_logic_vector;
171
FUNCTION "ror"  ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector;
172
 
173
 
174
-- FUNCTIONs for integer operations
175
 
176
FUNCTION "not" (l: integer) return integer;
177
FUNCTION "and" (l,r: integer) return integer;
178
FUNCTION "nand" (l,r: integer) return integer;
179
FUNCTION "or" (l,r: integer) return integer;
180
FUNCTION "nor" (l,r: integer) return integer;
181
FUNCTION "xor" (l,r: integer) return integer;
182
FUNCTION "xnor" (l,r: integer) return integer;
183
FUNCTION "sll" (l,r: integer) return integer;
184
FUNCTION "srl" (l,r: integer) return integer;
185
 
186
 
187
-- FUNCTIONs for std_logic/std_ulogic_vector/std_logic_vector operations
188
 
189
-- FUNCTIONs for combination of Boolean and ints
190
 
191
FUNCTION "="  ( l : Boolean; r : natural ) RETURN boolean;
192
FUNCTION "/="  ( l : Boolean; r : natural ) RETURN boolean;
193
 
194
 
195
FUNCTION "="  ( l : integer; r : std_logic_vector ) RETURN boolean;
196
FUNCTION "/=" ( l : integer;  r : std_logic_vector ) RETURN boolean;
197
FUNCTION "<"  ( l : integer;  r : std_logic_vector ) RETURN boolean;
198
FUNCTION ">"  ( l : integer;  r : std_logic_vector ) RETURN boolean;
199
FUNCTION "<=" ( l : integer;  r : std_logic_vector ) RETURN boolean;
200
FUNCTION ">=" ( l : integer;  r : std_logic_vector ) RETURN boolean;
201
 
202
 
203
FUNCTION "="  ( l : std_logic_vector;  r : integer ) RETURN boolean;
204
FUNCTION "/=" ( l : std_logic_vector;  r : integer ) RETURN boolean;
205
FUNCTION "<"  ( l : std_logic_vector;  r : integer ) RETURN boolean;
206
FUNCTION ">"  ( l : std_logic_vector;  r : integer ) RETURN boolean;
207
FUNCTION "<=" ( l : std_logic_vector;  r : integer ) RETURN boolean;
208
FUNCTION ">=" ( l : std_logic_vector;  r : integer ) RETURN boolean;
209
 
210
--logical functions between std_logic_vector and integer, std_logic_vector and boolean
211
 
212
FUNCTION "and" ( l : std_logic_vector;  r : integer ) RETURN std_logic_vector;
213
FUNCTION "nand"  ( l : std_logic_vector;  r : integer ) RETURN std_logic_vector;
214
FUNCTION "or"  ( l : std_logic_vector;  r : integer ) RETURN std_logic_vector;
215
FUNCTION "nor" ( l : std_logic_vector;  r : integer ) RETURN std_logic_vector;
216
FUNCTION "xor" ( l : std_logic_vector;  r : integer ) RETURN std_logic_vector;
217
 
218
FUNCTION "and"  ( l : integer; r : std_logic_vector ) RETURN integer;
219
FUNCTION "nand" ( l : integer;  r : std_logic_vector ) RETURN integer;
220
FUNCTION "or"  ( l : integer;  r : std_logic_vector ) RETURN integer;
221
FUNCTION "nor"  ( l : integer;  r : std_logic_vector ) RETURN integer;
222
FUNCTION "xor" ( l : integer;  r : std_logic_vector ) RETURN integer;
223
 
224
FUNCTION "and" ( l : std_logic_vector;  r : boolean ) RETURN std_logic_vector;
225
FUNCTION "nand"  ( l : std_logic_vector;  r : boolean ) RETURN std_logic_vector;
226
FUNCTION "or"  ( l : std_logic_vector;  r : boolean ) RETURN std_logic_vector;
227
FUNCTION "nor" ( l : std_logic_vector;  r : boolean ) RETURN std_logic_vector;
228
FUNCTION "xor" ( l : std_logic_vector;  r : boolean ) RETURN std_logic_vector;
229
 
230
FUNCTION "and"  ( l : boolean; r : std_logic_vector ) RETURN boolean;
231
FUNCTION "nand" ( l : boolean;  r : std_logic_vector ) RETURN boolean;
232
FUNCTION "or"  ( l : boolean;  r : std_logic_vector ) RETURN boolean;
233
FUNCTION "nor"  ( l : boolean;  r : std_logic_vector ) RETURN boolean;
234
FUNCTION "xor" ( l : boolean;  r : std_logic_vector ) RETURN boolean;
235
 
236
--logical functions between std_logic_vector and integer, std_logic_vector and boolean
237
 
238
-- Added functions for std_logic, integer
239
FUNCTION "="  ( l : std_logic;  r : integer ) RETURN boolean;
240
FUNCTION "/=" ( l : std_logic;  r : integer ) RETURN boolean;
241
FUNCTION "<"  ( l : std_logic;  r : integer ) RETURN boolean;
242
FUNCTION ">"  ( l : std_logic;  r : integer ) RETURN boolean;
243
FUNCTION "<=" ( l : std_logic;  r : integer ) RETURN boolean;
244
FUNCTION ">=" ( l : std_logic;  r : integer ) RETURN boolean;
245
-- Functions for std_logic, integer
246
 
247
--pragma synthesis_off
248
 
249
-- arithmetic operations for real and int and int and real
250
FUNCTION "+"  ( l : real;  r : integer ) RETURN real;
251
FUNCTION "-" ( l : real;  r : integer ) RETURN real;
252
FUNCTION "/"  ( l : real;  r : integer ) RETURN real;
253
FUNCTION "*"  ( l : real;  r : integer ) RETURN real;
254
 
255
 
256
FUNCTION "+"  ( l : integer;  r : real ) RETURN real;
257
FUNCTION "-" ( l : integer;  r : real ) RETURN real;
258
FUNCTION "/"  ( l : integer;  r : real ) RETURN real;
259
FUNCTION "*"  ( l : integer;  r : real ) RETURN real;
260
 
261
-- end arithmetic operations for real and int and int and real
262
 
263
FUNCTION "="  ( l : real;  r : integer ) RETURN boolean;
264
FUNCTION "/=" ( l : real;  r : integer ) RETURN boolean;
265
FUNCTION "<"  ( l : real;  r : integer ) RETURN boolean;
266
FUNCTION ">"  ( l : real;  r : integer ) RETURN boolean;
267
FUNCTION "<=" ( l : real;  r : integer ) RETURN boolean;
268
FUNCTION ">=" ( l : real;  r : integer ) RETURN boolean;
269
 
270
FUNCTION "="  ( l : integer;  r : real ) RETURN boolean;
271
FUNCTION "/=" ( l : integer;  r : real ) RETURN boolean;
272
FUNCTION "<"  ( l : integer;  r : real ) RETURN boolean;
273
FUNCTION ">"  ( l : integer;  r : real ) RETURN boolean;
274
FUNCTION "<=" ( l : integer;  r : real ) RETURN boolean;
275
FUNCTION ">=" ( l : integer;  r : real ) RETURN boolean;
276
--pragma synthesis_on
277
 
278
FUNCTION "+"   ( l, r : std_logic_vector ) RETURN std_logic_vector;
279
FUNCTION "-"   ( l, r : std_logic_vector ) RETURN std_logic_vector;
280
FUNCTION "*"   ( l, r : std_logic_vector ) RETURN std_logic_vector;
281
FUNCTION "/"   ( l, r : std_logic_vector ) RETURN std_logic_vector;
282
FUNCTION "REM" ( l, r : std_logic_vector ) RETURN std_logic_vector;
283
 
284
 
285
FUNCTION "+"   ( l : std_logic_vector; r : integer ) RETURN std_logic_vector;
286
FUNCTION "-"   ( l : std_logic_vector; r : integer ) RETURN std_logic_vector;
287
FUNCTION "*"   ( l : std_logic_vector; r : integer ) RETURN std_logic_vector;
288
FUNCTION "/"   ( l : std_logic_vector; r : integer ) RETURN std_logic_vector;
289
FUNCTION "REM" ( l : std_logic_vector; r : integer ) RETURN std_logic_vector;
290
FUNCTION "&" ( l : std_logic_vector; r : integer ) RETURN std_logic_vector;
291
FUNCTION "&" ( l : std_logic_vector; r : boolean ) RETURN std_logic_vector;
292
 
293
-- need logical functions bet. std_logic_vector and std_logic
294
FUNCTION "and" ( l : std_logic_vector; r : std_logic )  RETURN std_logic_vector;
295
FUNCTION "nand" ( l : std_logic_vector; r : std_logic )  RETURN std_logic_vector;
296
FUNCTION "or" ( l : std_logic_vector; r : std_logic )  RETURN std_logic_vector;
297
FUNCTION "nor" ( l : std_logic_vector; r : std_logic )  RETURN std_logic_vector;
298
FUNCTION "xor" ( l : std_logic_vector; r : std_logic )  RETURN std_logic_vector;
299
--FUNCTION "xnor" ( l : std_logic_vector; r : std_logic )  RETURN std_logic_vector;
300
 
301
FUNCTION "and" ( l : std_logic; r : std_logic_vector )  RETURN std_logic_vector;
302
FUNCTION "nand" ( l : std_logic; r : std_logic_vector )  RETURN std_logic_vector;
303
FUNCTION "or" ( l : std_logic; r : std_logic_vector )  RETURN std_logic_vector;
304
FUNCTION "nor" ( l : std_logic; r : std_logic_vector )  RETURN std_logic_vector;
305
FUNCTION "xor" ( l : std_logic; r : std_logic_vector )  RETURN std_logic_vector;
306
--FUNCTION "xnor" ( l : std_logic; r : std_logic_vector )  RETURN std_logic_vector;
307
 
308
-- end logical functions for std_logic_vector and std_logic
309
 
310
-- need arith functions bet std_logic and std_logic
311
-- used only when the int can be 0 or 1
312
-- need arithmetic functions bet. std_logic_vector and std_logic
313
FUNCTION "+"   ( l : std_logic; r : std_logic ) RETURN std_logic;
314
FUNCTION "-"   ( l : std_logic; r : std_logic ) RETURN std_logic;
315
FUNCTION "*"   ( l : std_logic; r : std_logic ) RETURN std_logic;
316
FUNCTION "/"   ( l : std_logic; r : std_logic ) RETURN std_logic;
317
FUNCTION "REM" ( l : std_logic; r : std_logic ) RETURN std_logic;
318
 
319
-- need arithmetic functions bet. std_logic_vector and std_logic
320
FUNCTION "+"   ( l : std_logic_vector; r : std_logic ) RETURN std_logic_vector;
321
FUNCTION "-"   ( l : std_logic_vector; r : std_logic ) RETURN std_logic_vector;
322
FUNCTION "*"   ( l : std_logic_vector; r : std_logic ) RETURN std_logic_vector;
323
FUNCTION "/"   ( l : std_logic_vector; r : std_logic ) RETURN std_logic_vector;
324
FUNCTION "REM" ( l : std_logic_vector; r : std_logic ) RETURN std_logic_vector;
325
 
326
-- need arithmetic func. between std_logic and std_logic_vector, caveat, returns type of 'r'
327
FUNCTION "+"   ( l : std_logic; r : std_logic_vector ) RETURN std_logic_vector;
328
FUNCTION "-"   ( l : std_logic; r : std_logic_vector ) RETURN std_logic_vector;
329
FUNCTION "*"   ( l : std_logic; r : std_logic_vector ) RETURN std_logic_vector;
330
FUNCTION "/"   ( l : std_logic; r : std_logic_vector ) RETURN std_logic_vector;
331
FUNCTION "REM" ( l : std_logic; r : std_logic_vector ) RETURN std_logic_vector;
332
 
333
 
334
FUNCTION "+"   ( l : integer; r : std_logic_vector ) RETURN integer;
335
FUNCTION "-"   ( l : integer; r : std_logic_vector ) RETURN integer;
336
FUNCTION "*"   ( l : integer; r : std_logic_vector ) RETURN integer;
337
FUNCTION "/"   ( l : integer; r : std_logic_vector ) RETURN integer;
338
FUNCTION "REM" ( l : integer; r : std_logic_vector ) RETURN integer;
339
 
340
-- need arith. functions bet std_logic and integer
341
FUNCTION "+" ( l : std_logic; r : integer )  RETURN integer;
342
FUNCTION "-" ( l : std_logic; r : integer ) RETURN integer;
343
FUNCTION "*" ( l : std_logic; r : integer ) RETURN integer;
344
FUNCTION "/" ( l : std_logic; r : integer ) RETURN integer;
345
FUNCTION "REM" ( l : std_logic; r : integer ) RETURN integer;
346
 
347
FUNCTION "and" ( l : std_logic; r : integer )  RETURN std_logic;
348
FUNCTION "nand" ( l : std_logic; r : integer ) RETURN std_logic;
349
FUNCTION "or" ( l : std_logic; r : integer ) RETURN std_logic;
350
FUNCTION "nor" ( l : std_logic; r : integer ) RETURN std_logic;
351
FUNCTION "xor" ( l : std_logic; r : integer ) RETURN std_logic;
352
FUNCTION "&" ( l : std_logic; r : integer ) RETURN std_logic_vector;
353
FUNCTION "xnor" ( l : std_logic; r : integer ) RETURN std_logic;
354
 
355
FUNCTION "and" ( l : integer; r : std_logic ) RETURN integer;
356
FUNCTION "nand" ( l : integer; r : std_logic ) RETURN integer;
357
FUNCTION "or" ( l : integer; r : std_logic ) RETURN integer;
358
FUNCTION "nor" ( l : integer; r : std_logic ) RETURN integer;
359
FUNCTION "xor" ( l : integer; r : std_logic ) RETURN integer;
360
FUNCTION "&" ( l : integer; r : std_logic ) RETURN std_logic_vector;
361
FUNCTION "xnor" ( l : integer; r : std_logic ) RETURN integer;
362
 
363
-- need functions for operations between std_logic and integer
364
FUNCTION "+"   ( l : integer; r : std_logic ) RETURN integer;
365
FUNCTION "-"   ( l : integer; r : std_logic ) RETURN integer;
366
FUNCTION "*"   ( l : integer; r : std_logic ) RETURN integer;
367
FUNCTION "/"   ( l : integer; r : std_logic ) RETURN integer;
368
FUNCTION "REM" ( l : integer; r : std_logic ) RETURN integer;
369
 
370
FUNCTION "and" ( l : std_logic; r : boolean )  RETURN std_logic;
371
FUNCTION "nand" ( l : std_logic; r : boolean ) RETURN std_logic;
372
FUNCTION "or" ( l : std_logic; r : boolean ) RETURN std_logic;
373
FUNCTION "nor" ( l : std_logic; r : boolean ) RETURN std_logic;
374
FUNCTION "xor" ( l : std_logic; r : boolean ) RETURN std_logic;
375
FUNCTION "&" ( l : std_logic; r : boolean ) RETURN std_logic_vector;
376
FUNCTION "xnor" ( l : std_logic; r : boolean ) RETURN std_logic;
377
 
378
FUNCTION "and" ( l : boolean; r : std_logic ) RETURN boolean;
379
FUNCTION "nand" ( l : boolean; r : std_logic ) RETURN boolean;
380
FUNCTION "or" ( l : boolean; r : std_logic ) RETURN boolean;
381
FUNCTION "nor" ( l : boolean; r : std_logic ) RETURN boolean;
382
FUNCTION "xor" ( l : boolean; r : std_logic ) RETURN boolean;
383
FUNCTION "&" ( l : boolean; r : std_logic ) RETURN std_logic_vector;
384
FUNCTION "xnor" ( l : boolean; r : std_logic ) RETURN boolean;
385
 
386
 
387
FUNCTION "and" ( l : integer; r : boolean ) RETURN integer;
388
FUNCTION "nand" ( l : integer; r : boolean ) RETURN integer;
389
FUNCTION "or" ( l : integer; r : boolean ) RETURN integer;
390
FUNCTION "nor" ( l : integer; r : boolean ) RETURN integer;
391
FUNCTION "xor" ( l : integer; r : boolean ) RETURN integer;
392
FUNCTION "&" ( l : integer; r : boolean ) RETURN std_logic_vector;
393
FUNCTION "xnor" ( l : integer; r : boolean ) RETURN integer;
394
 
395
FUNCTION "and" ( l : boolean; r : integer ) RETURN boolean;
396
FUNCTION "nand" ( l : boolean; r : integer ) RETURN boolean;
397
FUNCTION "or" ( l : boolean; r : integer ) RETURN boolean;
398
FUNCTION "nor" ( l : boolean; r : integer ) RETURN boolean;
399
FUNCTION "xor" ( l : boolean; r : integer ) RETURN boolean;
400
FUNCTION "&" ( l : boolean; r : integer ) RETURN std_logic_vector;
401
FUNCTION "xnor" ( l : boolean; r : integer ) RETURN boolean;
402
 
403
-- Overloaded function for text output
404
FUNCTION to_bitvector ( a : bit ) RETURN bit_vector;
405
FUNCTION to_bitvector ( a : std_ulogic ) RETURN bit_vector;
406
FUNCTION to_bitvector ( a : integer ) RETURN bit_vector;
407
 
408
--Conversion functions
409
FUNCTION to_stdlogicvector(l : integer; size : natural; dir : direction := LITTLE_ENDIAN) RETURN std_logic_vector;
410
FUNCTION to_stdlogicvector(l : std_logic_vector) RETURN std_logic_vector;
411
FUNCTION to_stdlogicvector(l : std_logic_vector; size : natural;dir : direction := little_endian ) RETURN std_logic_vector;
412
FUNCTION to_stdlogicvector ( hex : STRING ) RETURN std_logic_vector;
413
FUNCTION to_stdlogicvector(l : std_logic; size : natural) RETURN std_logic_vector;
414
FUNCTION to_stdlogicvector(l : boolean; size : natural) RETURN std_logic_vector;
415
 
416
FUNCTION to_integer(l : std_logic_vector; dir : direction := little_endian) RETURN integer;
417
FUNCTION to_integer(l : integer) RETURN integer;
418
FUNCTION to_integer(l : std_logic) RETURN integer;
419
FUNCTION to_integer(l : boolean) RETURN integer;
420
 
421
-- functions for resolving ambiguity
422
FUNCTION v2v_to_integer(l : std_logic_vector; dir : direction := little_endian) RETURN integer;
423
FUNCTION v2v_to_integer(l : integer) RETURN integer;
424
FUNCTION v2v_to_integer(l : std_logic) RETURN integer;
425
FUNCTION v2v_to_integer(l : boolean) RETURN integer;
426
 
427
FUNCTION to_stdlogic(l : integer) RETURN std_logic;
428
FUNCTION to_stdlogic(l : Boolean) RETURN std_logic;
429
FUNCTION to_stdlogic(l : std_logic) RETURN std_logic;
430
FUNCTION to_stdlogic(l : std_logic_vector) RETURN std_logic;
431
 
432
--pragma synthesis_off
433
FUNCTION to_real(l : integer) RETURN real;
434
FUNCTION to_real (l : real) RETURN real;
435
--pragma synthesis_on
436
 
437
FUNCTION to_boolean(l : std_logic) RETURN boolean;
438
FUNCTION to_boolean(l : integer) RETURN boolean;
439
FUNCTION to_boolean(l : std_logic_vector) RETURN boolean;
440
FUNCTION to_boolean(l : boolean) RETURN boolean;
441
 
442
end FUNCTIONS;
443
 
444
library ieee;
445
library GSI;
446
use ieee.std_logic_1164.all;
447
use ieee.numeric_std.all;
448
--library grlib;
449
--use grlib.stdlib.all;
450
 
451
Package body FUNCTIONS is
452
 
453
  --============= Local Subprograms (from numeric_std.vhd)=====================
454
 
455
  function MAX (LEFT, RIGHT: INTEGER) return INTEGER is
456
  begin
457
    if LEFT > RIGHT then return LEFT;
458
    else return RIGHT;
459
    end if;
460
  end MAX;
461
 
462
  function MIN (LEFT, RIGHT: INTEGER) return INTEGER is
463
  begin
464
    if LEFT < RIGHT then return LEFT;
465
    else return RIGHT;
466
    end if;
467
  end MIN;
468
 
469
 
470
-- unary operations
471
TYPE stdlogic_boolean_table is array(std_ulogic, std_ulogic) of boolean;
472
TYPE stdlogic_1d IS ARRAY (std_ulogic) OF std_ulogic;
473
    TYPE stdlogic_table IS ARRAY(std_ulogic, std_ulogic) OF std_ulogic;
474
 
475
 
476
FUNCTION U_AND(a : std_ulogic_vector) return std_ulogic is
477
 
478
VARIABLE result : std_ulogic := '1';
479
begin
480
        FOR i in a'RANGE LOOP
481
                result := result and a(i);
482
        END LOOP;
483
        return result;
484
end U_AND;
485
 
486
FUNCTION U_AND(a : std_logic_vector) return std_logic is
487
 
488
VARIABLE result : std_logic := '1';
489
begin
490
        FOR i in a'RANGE LOOP
491
                result := result and a(i);
492
        END LOOP;
493
        return result;
494
end U_AND;
495
 
496
FUNCTION U_NAND(a : std_ulogic_vector) return std_ulogic is
497
 
498
VARIABLE result : std_ulogic := '1';
499
begin
500
        FOR i in a'RANGE LOOP
501
                result := result and a(i);
502
        END LOOP;
503
        return not(result);
504
end U_NAND;
505
 
506
FUNCTION U_NAND(a : std_logic_vector) return std_logic is
507
 
508
VARIABLE result : std_logic := '1';
509
begin
510
        FOR i in a'RANGE LOOP
511
                result := result and a(i);
512
        END LOOP;
513
        return not(result);
514
end U_NAND;
515
 
516
FUNCTION U_OR(a : std_ulogic_vector) return std_ulogic is
517
 
518
VARIABLE result : std_ulogic := '0';
519
begin
520
        FOR i in a'RANGE LOOP
521
                result := result or a(i);
522
        END LOOP;
523
        return result;
524
end U_OR;
525
 
526
FUNCTION U_OR(a : std_logic_vector) return std_logic is
527
 
528
VARIABLE result : std_logic := '0';
529
begin
530
        FOR i in a'RANGE LOOP
531
                result := result or a(i);
532
        END LOOP;
533
        return result;
534
end U_OR;
535
 
536
FUNCTION U_NOR(a : std_ulogic_vector) return std_ulogic is
537
 
538
VARIABLE result : std_ulogic := '0';
539
begin
540
        FOR i in a'RANGE LOOP
541
                result := result or a(i);
542
        END LOOP;
543
        return not(result);
544
end U_NOR;
545
 
546
FUNCTION U_NOR(a : std_logic_vector) return std_logic is
547
 
548
VARIABLE result : std_logic := '0';
549
begin
550
        FOR i in a'RANGE LOOP
551
                result := result or a(i);
552
        END LOOP;
553
        return not(result);
554
end U_NOR;
555
 
556
FUNCTION U_XOR(a : std_ulogic_vector) return std_ulogic is
557
 
558
VARIABLE result : std_ulogic := '0';
559
begin
560
        FOR i in a'RANGE LOOP
561
                result := result xor a(i);
562
        END LOOP;
563
        return result;
564
end U_XOR;
565
 
566
FUNCTION U_XOR(a : std_logic_vector) return std_logic is
567
 
568
VARIABLE result : std_logic := '0';
569
begin
570
        FOR i in a'RANGE LOOP
571
                result := result xor a(i);
572
        END LOOP;
573
        return result;
574
end U_XOR;
575
 
576
FUNCTION U_XNOR(a : std_ulogic_vector) return std_ulogic is
577
 
578
VARIABLE result : std_ulogic := '0';
579
begin
580
        FOR i in a'RANGE LOOP
581
                result := result xor a(i);
582
        END LOOP;
583
        return not(result);
584
end U_XNOR;
585
 
586
FUNCTION U_XNOR(a : std_logic_vector) return std_logic is
587
 
588
VARIABLE result : std_logic := '0';
589
begin
590
        FOR i in a'RANGE LOOP
591
                result := result xor a(i);
592
        END LOOP;
593
        return not(result);
594
end U_XNOR;
595
 
596
-- ternary operations
597
FUNCTION TERNARY(a,b,c : boolean) return boolean IS
598
 
599
begin
600
        IF a = TRUE THEN
601
                RETURN b;
602
        ELSE
603
                RETURN c;
604
        END IF;
605
end TERNARY;
606
 
607
---------------------------------------------------
608
FUNCTION TERNARY(a : boolean; b,c : std_ulogic) return std_ulogic IS
609
 
610
begin
611
        IF a = TRUE THEN
612
                RETURN b;
613
        ELSE
614
                RETURN c;
615
        END IF;
616
end TERNARY;
617
 
618
---------------------------------------------------
619
FUNCTION TERNARY(a : boolean; b,c : std_ulogic_vector) return std_ulogic_vector IS
620
 
621
begin
622
        IF a = TRUE THEN
623
                RETURN b;
624
        ELSE
625
                RETURN c;
626
        END IF;
627
end TERNARY;
628
 
629
---------------------------------------------------
630
FUNCTION TERNARY(a : boolean; b,c : std_logic_vector) return std_logic_vector IS
631
 
632
begin
633
        IF a = TRUE THEN
634
                RETURN b;
635
        ELSE
636
                RETURN c;
637
        END IF;
638
end TERNARY;
639
 
640
--pragma synthesis_off
641
---------------------------------------------------
642
FUNCTION TERNARY(a : boolean; b,c : real) return real IS
643
 
644
begin
645
        IF a = TRUE THEN
646
                RETURN b;
647
        ELSE
648
                RETURN c;
649
        END IF;
650
end TERNARY;
651
 
652
---------------------------------------------------
653
FUNCTION TERNARY(a : boolean; b,c : time) return time IS
654
 
655
begin
656
        IF a = TRUE THEN
657
                RETURN b;
658
        ELSE
659
                RETURN c;
660
        END IF;
661
end TERNARY;
662
--pragma synthesis_on
663
---------------------------------------------------
664
 
665
FUNCTION TERNARY(a,b,c : integer) return integer is
666
 
667
begin
668
        IF (a /= 0) THEN
669
                return b;
670
        ELSE
671
                return c;
672
        END IF;
673
end TERNARY;
674
 
675
FUNCTION TERNARY(a : integer; b,c : std_ulogic) return std_ulogic is
676
 
677
begin
678
        IF (a /= 0) THEN
679
                return b;
680
        ELSE
681
                return c;
682
        END IF;
683
end TERNARY;
684
 
685
 
686
FUNCTION TERNARY(a : integer; b,c : std_ulogic_vector) return std_ulogic_vector is
687
 
688
begin
689
        IF (a /= 0) THEN
690
                return b;
691
        ELSE
692
                return c;
693
        END IF;
694
end TERNARY;
695
 
696
FUNCTION TERNARY(a : integer; b,c : std_logic_vector) return std_logic_vector is
697
 
698
begin
699
        IF (a /= 0) THEN
700
                return b;
701
        ELSE
702
                return c;
703
        END IF;
704
end TERNARY;
705
 
706
--pragma synthesis_off
707
FUNCTION TERNARY(a : integer; b,c : real) return real is
708
 
709
begin
710
        IF (a /= 0) THEN
711
                return b;
712
        ELSE
713
                return c;
714
        END IF;
715
end TERNARY;
716
 
717
FUNCTION TERNARY(a : integer; b,c : time) return time is
718
 
719
begin
720
        IF (a /= 0) THEN
721
                return b;
722
        ELSE
723
                return c;
724
        END IF;
725
end TERNARY;
726
--pragma synthesis_on
727
 
728
FUNCTION TERNARY(a,b,c : std_ulogic) return std_ulogic is
729
 
730
begin
731
        IF (a = '1') THEN
732
                return b;
733
        ELSIF (a = '0') THEN
734
                return c;
735
--pragma synthesis_off
736
        ELSIF (b = c AND NOT Is_X(b)) THEN
737
                return b;
738
        ELSE
739
                return 'X';
740
--pragma synthesis_on
741
        END IF;
742
end TERNARY;
743
 
744
FUNCTION TERNARY(a : std_ulogic; b,c : integer) return integer is
745
 
746
begin
747
        IF (a = '1') THEN
748
                return b;
749
        ELSIF (a = '0') THEN
750
                return c;
751
--pragma synthesis_off
752
        ELSIF (b = c) THEN
753
                return b;
754
        ELSE
755
                return 0;
756
--pragma synthesis_on
757
        END IF;
758
end TERNARY;
759
 
760
FUNCTION TERNARY(a : std_ulogic; b,c : std_ulogic_vector) return std_ulogic_vector is
761
--pragma synthesis_off
762
    constant SIZE: NATURAL := MAX(b'LENGTH, c'LENGTH);
763
    variable b01 : std_ulogic_vector(SIZE-1 downto 0) := (OTHERS => '0');
764
    variable c01 : std_ulogic_vector(SIZE-1 downto 0) := (OTHERS => '0');
765
    variable result : std_ulogic_vector(SIZE-1 downto 0);
766
--pragma synthesis_on
767
begin
768
        IF (a = '1') THEN
769
                return b;
770
        ELSIF (a = '0') THEN
771
                return c;
772
--pragma synthesis_off
773
        ELSIF (b = c AND NOT Is_X(b)) THEN
774
                return b;
775
        ELSE
776
                b01(b'LENGTH-1 downto 0) := b;
777
                c01(c'LENGTH-1 downto 0) := c;
778
                FOR I IN SIZE-1 DOWNTO 0 LOOP
779
                    IF (b01(I) = c01(I) AND NOT Is_X(b01(I))) THEN
780
                        result(I) := b01(I);
781
                    ELSE
782
                        result(I) := 'X';
783
                    END IF;
784
                END LOOP;
785
                return result;
786
--pragma synthesis_on
787
        END IF;
788
end TERNARY;
789
 
790
FUNCTION TERNARY(a : std_ulogic; b,c : std_logic_vector) return std_logic_vector is
791
--pragma synthesis_off
792
    constant SIZE: NATURAL := MAX(b'LENGTH, c'LENGTH);
793
    variable b01 : std_logic_vector(SIZE-1 downto 0) := (OTHERS => '0');
794
    variable c01 : std_logic_vector(SIZE-1 downto 0) := (OTHERS => '0');
795
    variable result : std_logic_vector(SIZE-1 downto 0);
796
--pragma synthesis_on
797
begin
798
        IF (a = '1') THEN
799
                return b;
800
        ELSIF (a = '0') THEN
801
                return c;
802
--pragma synthesis_off
803
        ELSIF (b = c AND NOT Is_X(b)) THEN
804
                return b;
805
        ELSE
806
                b01(b'LENGTH-1 downto 0) := b;
807
                c01(c'LENGTH-1 downto 0) := c;
808
                FOR I IN SIZE-1 DOWNTO 0 LOOP
809
                    IF (b01(I) = c01(I) AND NOT Is_X(b01(I))) THEN
810
                        result(I) := b01(I);
811
                    ELSE
812
                        result(I) := 'X';
813
                    END IF;
814
                END LOOP;
815
                return result;
816
--pragma synthesis_on
817
        END IF;
818
end TERNARY;
819
 
820
--pragma synthesis_off
821
FUNCTION TERNARY(a : std_ulogic; b,c : real) return real is
822
 
823
begin
824
        IF (a = '1') THEN
825
                return b;
826
        ELSIF (a = '0') THEN
827
                return c;
828
        ELSIF (b = c) THEN
829
                return b;
830
        ELSE
831
                return 0.0;
832
        END IF;
833
end TERNARY;
834
 
835
FUNCTION TERNARY(a : std_ulogic; b,c : time) return time is
836
 
837
begin
838
        IF (a = '1') THEN
839
                return b;
840
        ELSIF (a = '0') THEN
841
                return c;
842
        ELSIF (b = c) THEN
843
                return b;
844
        ELSE
845
                return 0 ns;
846
        END IF;
847
end TERNARY;
848
--pragma synthesis_on
849
 
850
FUNCTION TERNARY(a,b,c : std_ulogic_vector) return std_ulogic_vector is
851
--pragma synthesis_off
852
    constant SIZE: NATURAL := MAX(b'LENGTH, c'LENGTH);
853
    variable b01 : std_ulogic_vector(SIZE-1 downto 0) := (OTHERS => '0');
854
    variable c01 : std_ulogic_vector(SIZE-1 downto 0) := (OTHERS => '0');
855
    variable result : std_ulogic_vector(SIZE-1 downto 0);
856
--pragma synthesis_on
857
begin
858
        IF to_boolean(to_stdlogicvector(to_bitvector(a))) THEN
859
                return b;
860
--pragma synthesis_off
861
        ELSIF (Is_X(a)) THEN
862
            IF (b = c) THEN return b;
863
            ELSE
864
                b01(b'LENGTH-1 downto 0) := b;
865
                c01(c'LENGTH-1 downto 0) := c;
866
                FOR I IN SIZE-1 DOWNTO 0 LOOP
867
                    IF (b01(I) = c01(I) AND NOT Is_X(b01(I))) THEN
868
                        result(I) := b01(I);
869
                    ELSE
870
                        result(I) := 'X';
871
                    END IF;
872
                END LOOP;
873
                return result;
874
            END IF;
875
--pragma synthesis_on
876
        ELSE
877
                return c;
878
        END IF;
879
end TERNARY;
880
 
881
FUNCTION TERNARY(a : std_ulogic_vector; b,c : integer) return integer is
882
 
883
begin
884
        IF to_boolean(to_stdlogicvector(to_bitvector(a))) THEN
885
                return b;
886
--pragma synthesis_off
887
        ELSIF (Is_X(a)) THEN
888
            IF (b = c) THEN return b;
889
            ELSE return 0;
890
            END IF;
891
--pragma synthesis_on
892
        ELSE
893
                return c;
894
        END IF;
895
end TERNARY;
896
 
897
FUNCTION TERNARY(a : std_ulogic_vector; b,c : std_ulogic) return std_ulogic is
898
 
899
begin
900
        IF to_boolean(to_stdlogicvector(to_bitvector(a))) THEN
901
                return b;
902
--pragma synthesis_off
903
        ELSIF (Is_X(a)) THEN
904
            IF (b = c) THEN return b;
905
            ELSE return 'X';
906
            END IF;
907
--pragma synthesis_on
908
        ELSE
909
                return c;
910
        END IF;
911
end TERNARY;
912
 
913
FUNCTION TERNARY(a : std_ulogic_vector; b,c : std_logic_vector) return std_logic_vector is
914
--pragma synthesis_off
915
    constant SIZE: NATURAL := MAX(b'LENGTH, c'LENGTH);
916
    variable b01 : std_logic_vector(SIZE-1 downto 0) := (OTHERS => '0');
917
    variable c01 : std_logic_vector(SIZE-1 downto 0) := (OTHERS => '0');
918
    variable result : std_logic_vector(SIZE-1 downto 0);
919
--pragma synthesis_on
920
begin
921
        IF to_boolean(to_stdlogicvector(to_bitvector(a))) THEN
922
                return b;
923
--pragma synthesis_off
924
        ELSIF (Is_X(a)) THEN
925
            IF (b = c) THEN return b;
926
            ELSE
927
                b01(b'LENGTH-1 downto 0) := b;
928
                c01(c'LENGTH-1 downto 0) := c;
929
                FOR I IN SIZE-1 DOWNTO 0 LOOP
930
                    IF (b01(I) = c01(I) AND NOT Is_X(b01(I))) THEN
931
                        result(I) := b01(I);
932
                    ELSE
933
                        result(I) := 'X';
934
                    END IF;
935
                END LOOP;
936
                return result;
937
            END IF;
938
--pragma synthesis_on
939
        ELSE
940
                return c;
941
        END IF;
942
end TERNARY;
943
 
944
--pragma synthesis_off
945
FUNCTION TERNARY(a : std_ulogic_vector; b,c : real) return real is
946
 
947
begin
948
        IF to_boolean(to_stdlogicvector(to_bitvector(a))) THEN
949
                return b;
950
        ELSIF (Is_X(a)) THEN
951
            IF (b = c) THEN return b;
952
            ELSE return 0.0;
953
            END IF;
954
        ELSE
955
                return c;
956
        END IF;
957
end TERNARY;
958
 
959
FUNCTION TERNARY(a : std_ulogic_vector; b,c : time) return time is
960
 
961
begin
962
        IF to_boolean(to_stdlogicvector(to_bitvector(a))) THEN
963
                return b;
964
        ELSIF (Is_X(a)) THEN
965
            IF (b = c) THEN return b;
966
            ELSE return 0 ns;
967
            END IF;
968
        ELSE
969
                return c;
970
        END IF;
971
end TERNARY;
972
--pragma synthesis_on
973
 
974
FUNCTION TERNARY(a,b,c : std_logic_vector) return std_logic_vector is
975
--pragma synthesis_off
976
    constant SIZE: NATURAL := MAX(b'LENGTH, c'LENGTH);
977
    variable b01 : std_logic_vector(SIZE-1 downto 0) := (OTHERS => '0');
978
    variable c01 : std_logic_vector(SIZE-1 downto 0) := (OTHERS => '0');
979
    variable result : std_logic_vector(SIZE-1 downto 0);
980
--pragma synthesis_on
981
begin
982
        IF to_boolean(to_stdlogicvector(to_bitvector(a))) THEN
983
                return b;
984
--pragma synthesis_off
985
        ELSIF (Is_X(a)) THEN
986
            IF (b = c) THEN return b;
987
            ELSE
988
                b01(b'LENGTH-1 downto 0) := b;
989
                c01(c'LENGTH-1 downto 0) := c;
990
                FOR I IN SIZE-1 DOWNTO 0 LOOP
991
                    IF (b01(I) = c01(I) AND NOT Is_X(b01(I))) THEN
992
                        result(I) := b01(I);
993
                    ELSE
994
                        result(I) := 'X';
995
                    END IF;
996
                END LOOP;
997
                return result;
998
            END IF;
999
--pragma synthesis_on
1000
        ELSE
1001
                return c;
1002
        END IF;
1003
end TERNARY;
1004
 
1005
FUNCTION TERNARY(a : std_logic_vector; b,c : integer) return integer is
1006
 
1007
begin
1008
        IF to_boolean(to_stdlogicvector(to_bitvector(a))) THEN
1009
                return b;
1010
--pragma synthesis_off
1011
        ELSIF (Is_X(a)) THEN
1012
            IF (b = c) THEN return b;
1013
            ELSE return 0;
1014
            END IF;
1015
--pragma synthesis_on
1016
        ELSE
1017
                return c;
1018
        END IF;
1019
end TERNARY;
1020
 
1021
 
1022
FUNCTION TERNARY(a : std_logic_vector; b,c : std_ulogic) return std_ulogic is
1023
 
1024
begin
1025
        IF to_boolean(to_stdlogicvector(to_bitvector(a))) THEN
1026
                return b;
1027
--pragma synthesis_off
1028
        ELSIF (Is_X(a)) THEN
1029
            IF (b = c) THEN return b;
1030
            ELSE return 'X';
1031
            END IF;
1032
--pragma synthesis_on
1033
        ELSE
1034
                return c;
1035
        END IF;
1036
end TERNARY;
1037
 
1038
 
1039
FUNCTION TERNARY(a : std_logic_vector; b,c : std_ulogic_vector) return std_ulogic_vector is
1040
--pragma synthesis_off
1041
    constant SIZE: NATURAL := MAX(b'LENGTH, c'LENGTH);
1042
    variable b01 : std_ulogic_vector(SIZE-1 downto 0) := (OTHERS => '0');
1043
    variable c01 : std_ulogic_vector(SIZE-1 downto 0) := (OTHERS => '0');
1044
    variable result : std_ulogic_vector(SIZE-1 downto 0);
1045
--pragma synthesis_on
1046
begin
1047
        IF to_boolean(to_stdlogicvector(to_bitvector(a))) THEN
1048
                return b;
1049
--pragma synthesis_off
1050
        ELSIF (Is_X(a)) THEN
1051
            IF (b = c) THEN return b;
1052
            ELSE
1053
                b01(b'LENGTH-1 downto 0) := b;
1054
                c01(c'LENGTH-1 downto 0) := c;
1055
                FOR I IN SIZE-1 DOWNTO 0 LOOP
1056
                    IF (b01(I) = c01(I) AND NOT Is_X(b01(I))) THEN
1057
                        result(I) := b01(I);
1058
                    ELSE
1059
                        result(I) := 'X';
1060
                    END IF;
1061
                END LOOP;
1062
                return result;
1063
            END IF;
1064
--pragma synthesis_on
1065
        ELSE
1066
                return c;
1067
        END IF;
1068
end TERNARY;
1069
 
1070
--pragma synthesis_off
1071
FUNCTION TERNARY(a : std_logic_vector; b,c : real) return real is
1072
 
1073
begin
1074
        IF to_boolean(to_stdlogicvector(to_bitvector(a))) THEN
1075
                return b;
1076
        ELSIF (Is_X(a)) THEN
1077
            IF (b = c) THEN return b;
1078
            ELSE return 0.0;
1079
            END IF;
1080
        ELSE
1081
                return c;
1082
        END IF;
1083
end TERNARY;
1084
 
1085
FUNCTION TERNARY(a : std_logic_vector; b,c : time) return time is
1086
 
1087
begin
1088
        IF to_boolean(to_stdlogicvector(to_bitvector(a))) THEN
1089
                return b;
1090
        ELSIF (Is_X(a)) THEN
1091
            IF (b = c) THEN return b;
1092
            ELSE return 0 ns;
1093
            END IF;
1094
        ELSE
1095
                return c;
1096
        END IF;
1097
end TERNARY;
1098
 
1099
FUNCTION TERNARY(a,b,c : real) return real is
1100
 
1101
begin
1102
        IF (a /= 0) THEN
1103
                return b;
1104
        ELSE
1105
                return c;
1106
        END IF;
1107
end TERNARY;
1108
 
1109
FUNCTION TERNARY(a : real; b,c : std_ulogic) return std_ulogic is
1110
 
1111
begin
1112
        IF (a /= 0) THEN
1113
                return b;
1114
        ELSE
1115
                return c;
1116
        END IF;
1117
end TERNARY;
1118
 
1119
FUNCTION TERNARY(a : real; b,c : std_ulogic_vector) return std_ulogic_vector is
1120
 
1121
begin
1122
        IF (a /= 0) THEN
1123
                return b;
1124
        ELSE
1125
                return c;
1126
        END IF;
1127
end TERNARY;
1128
 
1129
FUNCTION TERNARY(a : real; b,c : std_logic_vector) return std_logic_vector is
1130
 
1131
begin
1132
        IF (a /= 0) THEN
1133
                return b;
1134
        ELSE
1135
                return c;
1136
        END IF;
1137
end TERNARY;
1138
 
1139
FUNCTION TERNARY(a : real; b,c : integer) return integer is
1140
 
1141
begin
1142
        IF (a /= 0) THEN
1143
                return b;
1144
        ELSE
1145
                return c;
1146
        END IF;
1147
end TERNARY;
1148
 
1149
FUNCTION TERNARY(a : real; b,c : time) return time is
1150
 
1151
begin
1152
        IF (a /= 0) THEN
1153
                return b;
1154
        ELSE
1155
                return c;
1156
        END IF;
1157
end TERNARY;
1158
--pragma synthesis_on 
1159
 
1160
-- functions for TERNARY combination
1161
FUNCTION TERNARY(a : std_ulogic; b : std_logic_vector; c: std_ulogic) return
1162
        std_logic_vector IS
1163
    variable c01 : std_logic_vector(b'LENGTH-1 downto 0) := (OTHERS => '0');
1164
--pragma synthesis_off
1165
    variable b01 : std_logic_vector(b'LENGTH-1 downto 0) := b;
1166
    variable result : std_logic_vector(b'LENGTH-1 downto 0);
1167
--pragma synthesis_on
1168
BEGIN
1169
        c01(0) := c;
1170
        IF (a = '1') THEN
1171
                return b;
1172
        ELSIF (a = '0') THEN
1173
                return c01;
1174
--pragma synthesis_off
1175
        ELSIF (b01 = c01 AND NOT Is_X(b)) THEN
1176
                return b;
1177
        ELSE
1178
                FOR I IN b'LENGTH-1 DOWNTO 0 LOOP
1179
                    IF (b01(I) = c01(I) AND NOT Is_X(b01(I))) THEN
1180
                        result(I) := b01(I);
1181
                    ELSE
1182
                        result(I) := 'X';
1183
                    END IF;
1184
                END LOOP;
1185
                return result;
1186
--pragma synthesis_on
1187
        END IF;
1188
END TERNARY;
1189
 
1190
FUNCTION TERNARY(a : std_ulogic; b : std_ulogic; c: std_logic_vector) return
1191
        std_logic_vector  IS
1192
    variable b01 : std_logic_vector(c'LENGTH-1 downto 0) := (OTHERS => '0');
1193
--pragma synthesis_off
1194
    variable c01 : std_logic_vector(c'LENGTH-1 downto 0) := c;
1195
    variable result : std_logic_vector(c'LENGTH-1 downto 0);
1196
--pragma synthesis_on
1197
BEGIN
1198
        b01(0) := b;
1199
        IF (a = '1') THEN
1200
                return b01;
1201
        ELSIF (a = '0') THEN
1202
                return c;
1203
--pragma synthesis_off
1204
        ELSIF (b01 = c01 AND NOT Is_X(b01)) THEN
1205
                return b01;
1206
        ELSE
1207
                FOR I IN c'LENGTH-1 DOWNTO 0 LOOP
1208
                    IF (b01(I) = c01(I) AND NOT Is_X(b01(I))) THEN
1209
                        result(I) := b01(I);
1210
                    ELSE
1211
                        result(I) := 'X';
1212
                    END IF;
1213
                END LOOP;
1214
                return result;
1215
--pragma synthesis_on
1216
        END IF;
1217
END TERNARY;
1218
 
1219
FUNCTION TERNARY(a : std_ulogic; b : integer; c: std_ulogic) return
1220
        integer IS
1221
BEGIN
1222
        IF (a = '0') THEN
1223
                return to_integer(c);
1224
        ELSIF (a = '1') THEN
1225
                return b;
1226
--pragma synthesis_off
1227
        ELSIF (b = to_integer(c) AND NOT Is_X(c)) THEN
1228
                return b;
1229
        ELSE
1230
                return 0;
1231
--pragma synthesis_on
1232
        END IF;
1233
END TERNARY;
1234
 
1235
FUNCTION TERNARY(a : std_ulogic; b : std_ulogic; c: integer) return
1236
        integer IS
1237
BEGIN
1238
        IF (a = '0') THEN
1239
                return c;
1240
        ELSIF (a = '1') THEN
1241
                return to_integer(b);
1242
--pragma synthesis_off
1243
        ELSIF (to_integer(b) = c AND NOT Is_X(b)) THEN
1244
                return c;
1245
        ELSE
1246
                return 0;
1247
--pragma synthesis_on
1248
        END IF;
1249
END TERNARY;
1250
 
1251
FUNCTION TERNARY(a : integer; b : integer; c: std_ulogic) return
1252
        integer IS
1253
BEGIN
1254
        IF (a /= 0) THEN
1255
                return b;
1256
        ELSE
1257
                return to_integer(c);
1258
        END IF;
1259
 
1260
END TERNARY;
1261
 
1262
FUNCTION TERNARY(a : integer; b : std_ulogic; c: integer) return
1263
        integer IS
1264
BEGIN
1265
        IF (a /= 0) THEN
1266
                return to_integer(b);
1267
        ELSE
1268
                return c;
1269
        END IF;
1270
 
1271
END TERNARY;
1272
 
1273
FUNCTION TERNARY(a : integer; b : std_logic_vector; c: std_ulogic) return
1274
        std_logic_vector IS
1275
VARIABLE temp : std_logic_vector(0 downto 0);
1276
BEGIN
1277
        IF (a /= 0) THEN
1278
                return b;
1279
        ELSE
1280
                temp(0) := c;
1281
                return temp;
1282
        END IF;
1283
END TERNARY;
1284
 
1285
FUNCTION TERNARY(a : integer; b : std_ulogic; c: std_logic_vector) return
1286
        std_logic_vector IS
1287
VARIABLE temp : std_logic_vector(0 downto 0);
1288
BEGIN
1289
        IF (a /= 0) THEN
1290
                temp(0) := b;
1291
                return temp;
1292
        ELSE
1293
                return c;
1294
        END IF;
1295
 
1296
END TERNARY;
1297
 
1298
--end functions for TERNARY combination 
1299
 
1300
-- FUNCTIONS for integer operations
1301
 
1302
FUNCTION "not" (l: integer) return integer is
1303
 
1304
VARIABLE temp : SIGNED(31 downto 0) := TO_SIGNED(l,32);
1305
begin
1306
        return TO_INTEGER(NOT(temp));
1307
end "not";
1308
 
1309
FUNCTION "and" (l,r: integer) return integer is
1310
 
1311
VARIABLE temp1 : SIGNED(31 downto 0) := TO_SIGNED(l,32);
1312
VARIABLE temp2 : SIGNED(31 downto 0) := TO_SIGNED(r,32);
1313
 
1314
begin
1315
        return TO_INTEGER(temp1 AND temp2);
1316
end "and";
1317
 
1318
FUNCTION "nand" (l,r: integer) return integer is
1319
 
1320
VARIABLE temp1 : SIGNED(31 downto 0) := TO_SIGNED(l,32);
1321
VARIABLE temp2 : SIGNED(31 downto 0) := TO_SIGNED(r,32);
1322
 
1323
begin
1324
        return TO_INTEGER(temp1 NAND temp2);
1325
end "nand";
1326
 
1327
FUNCTION "or" (l,r: integer) return integer is
1328
 
1329
VARIABLE temp1 : SIGNED(31 downto 0) := TO_SIGNED(l,32);
1330
VARIABLE temp2 : SIGNED(31 downto 0) := TO_SIGNED(r,32);
1331
 
1332
begin
1333
        return TO_INTEGER(temp1 OR temp2);
1334
end "or";
1335
 
1336
FUNCTION "nor" (l,r: integer) return integer is
1337
 
1338
VARIABLE temp1 : SIGNED(31 downto 0) := TO_SIGNED(l,32);
1339
VARIABLE temp2 : SIGNED(31 downto 0) := TO_SIGNED(r,32);
1340
 
1341
begin
1342
        return TO_INTEGER(temp1 NOR temp2);
1343
end "nor";
1344
 
1345
FUNCTION "xor" (l,r: integer) return integer is
1346
 
1347
VARIABLE temp1 : SIGNED(31 downto 0) := TO_SIGNED(l,32);
1348
VARIABLE temp2 : SIGNED(31 downto 0) := TO_SIGNED(r,32);
1349
 
1350
begin
1351
        return TO_INTEGER(temp1 XOR temp2);
1352
end "xor";
1353
 
1354
FUNCTION "xnor" (l,r: integer) return integer is
1355
 
1356
VARIABLE temp1 : SIGNED(31 downto 0) := TO_SIGNED(l,32);
1357
VARIABLE temp2 : SIGNED(31 downto 0) := TO_SIGNED(r,32);
1358
 
1359
begin
1360
        return TO_INTEGER(temp1 XNOR temp2);
1361
end "xnor";
1362
 
1363
FUNCTION "sll" (l,r: integer) return integer is
1364
 
1365
VARIABLE temp1 : SIGNED(31 downto 0) := TO_SIGNED(l,32);
1366
 
1367
begin
1368
        return TO_INTEGER(temp1 SLL r);
1369
end "sll";
1370
 
1371
FUNCTION "srl" (l,r: integer) return integer is
1372
 
1373
VARIABLE temp1 : SIGNED(31 downto 0) := TO_SIGNED(l,32);
1374
 
1375
begin
1376
        return TO_INTEGER(temp1 SRL r);
1377
end "srl";
1378
 
1379
 
1380
-- functions for std_ulogic operations
1381
-- first add all the tables needed
1382
 
1383
 -- truth table for "=" function
1384
CONSTANT eq_table : stdlogic_boolean_table := (
1385
--      ----------------------------------------------------------------------------
1386
--      |  U       X      0     1      Z      W      L      H      D         |   |
1387
--      ----------------------------------------------------------------------------
1388
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | U |
1389
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | X |
1390
        ( FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE ),  -- | 0 |
1391
        ( FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE ),  -- | 1 |
1392
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | Z |
1393
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | W |
1394
        ( FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE ),  -- | L |
1395
        ( FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE ),  -- | H |
1396
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE )   -- | D |
1397
    );
1398
 
1399
-- truth table for "/=" function
1400
CONSTANT neq_table : stdlogic_boolean_table := (
1401
--      ----------------------------------------------------------------------------
1402
--      |  U       X      0     1      Z      W      L      H      D         |   |
1403
--      ----------------------------------------------------------------------------
1404
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | U |
1405
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | X |
1406
        ( FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE ),  -- | 0 |
1407
        ( FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE ),  -- | 1 |
1408
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | Z |
1409
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | W |
1410
        ( FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE ),  -- | L |
1411
        ( FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE ),  -- | H |
1412
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE )   -- | D |
1413
    );
1414
 
1415
-- truth table for "<" function
1416
CONSTANT ltb_table : stdlogic_boolean_table := (
1417
--      ----------------------------------------------------------------------------
1418
--      |  U       X      0     1      Z      W      L      H      D         |   |
1419
--      ----------------------------------------------------------------------------
1420
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | U |
1421
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | X |
1422
        ( FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE ),  -- | 0 |
1423
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | 1 |
1424
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | Z |
1425
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | W |
1426
        ( FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE ),  -- | L |
1427
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | H |
1428
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE )   -- | D |
1429
    );
1430
 
1431
 -- truth table for ">" function
1432
CONSTANT gtb_table : stdlogic_boolean_table := (
1433
--      ----------------------------------------------------------------------------
1434
--      |  U       X      0     1      Z      W      L      H      D         |   |
1435
--      ----------------------------------------------------------------------------
1436
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | U |
1437
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | X |
1438
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | 0 |
1439
        ( FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE ),  -- | 1 |
1440
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | Z |
1441
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | W |
1442
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ),  -- | L |
1443
        ( FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE ),  -- | H |
1444
        ( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE )   -- | D |
1445
    );
1446
 
1447
-- truth table for "<=" function
1448
CONSTANT leb_table : stdlogic_boolean_table := (
1449
--      ----------------------------------------------------------------------------
1450
--      |  U       X      0     1      Z      W      L      H      D         |   |
1451
--      ----------------------------------------------------------------------------
1452
        ( FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE ),  -- | U |
1453
        ( FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE ),  -- | X |
1454
        ( TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE ),  -- | 0 |
1455
        ( FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE ),  -- | 1 |
1456
        ( FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE ),  -- | Z |
1457
        ( FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE ),  -- | W |
1458
        ( TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE ),  -- | L |
1459
        ( FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE ),  -- | H |
1460
        ( FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE )   -- | D |
1461
    );
1462
 
1463
-- truth table for ">=" function
1464
CONSTANT geb_table : stdlogic_boolean_table := (
1465
--      ----------------------------------------------------------------------------
1466
--      |  U       X      0     1      Z      W      L      H      D         |   |
1467
--      ----------------------------------------------------------------------------
1468
        ( FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE ),  -- | U |
1469
        ( FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE ),  -- | X |
1470
        ( FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE ),  -- | 0 |
1471
        ( TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE ),  -- | 1 |
1472
        ( FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE ),  -- | Z |
1473
        ( FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE ),  -- | W |
1474
        ( FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE ),  -- | L |
1475
        ( TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE ),  -- | H |
1476
        ( FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE )   -- | D |
1477
    );
1478
 
1479
CONSTANT lt_table : stdlogic_table := (
1480
--      ----------------------------------------------------
1481
--      |  U    X    0    1    Z    W    L    H    D         |   |
1482
--      ----------------------------------------------------
1483
        ( 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U' ),  -- | U |
1484
        ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ),  -- | X |
1485
        ( 'U', 'X', '0', '1', 'X', 'X', '0', '1', 'X' ),  -- | 0 |
1486
        ( 'U', 'X', '0', '0', 'X', 'X', '0', '0', 'X' ),  -- | 1 |
1487
        ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ),  -- | Z |
1488
        ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ),  -- | W |
1489
        ( 'U', 'X', '0', '1', 'X', 'X', '0', '1', 'X' ),  -- | L |
1490
        ( 'U', 'X', '0', '0', 'X', 'X', '0', '0', 'X' ),  -- | H |
1491
        ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' )   -- | D |
1492
    );
1493
 
1494
 -- truth table for ">" function
1495
CONSTANT gt_table : stdlogic_table := (
1496
--      ----------------------------------------------------
1497
--      |  U    X    0    1    Z    W    L    H    D         |   |
1498
--      ----------------------------------------------------
1499
        ( 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U' ),  -- | U |
1500
        ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ),  -- | X |
1501
        ( 'U', 'X', '0', '0', 'X', 'X', '0', '0', 'X' ),  -- | 0 |
1502
        ( 'U', 'X', '1', '0', 'X', 'X', '1', '0', 'X' ),  -- | 1 |
1503
        ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ),  -- | Z |
1504
        ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ),  -- | W |
1505
        ( 'U', 'X', '0', '0', 'X', 'X', '0', '0', 'X' ),  -- | L |
1506
        ( 'U', 'X', '1', '0', 'X', 'X', '1', '0', 'X' ),  -- | H |
1507
        ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' )   -- | D |
1508
    );
1509
 
1510
-- truth table for "<=" function
1511
        CONSTANT le_table : stdlogic_table := (
1512
        --      ----------------------------------------------------
1513
        --      |  U    X    0    1    Z    W    L    H    D         |   |
1514
        --      ----------------------------------------------------
1515
                ( 'U', 'U', 'U', '1', 'U', 'U', 'U', '1', 'U' ),  -- | U |
1516
                ( 'U', 'X', 'X', '1', 'X', 'X', 'X', '1', 'X' ),  -- | X |
1517
                ( '1', '1', '1', '1', '1', '1', '1', '1', '1' ),  -- | 0 |
1518
                ( 'U', 'X', '0', '1', 'X', 'X', '0', '1', 'X' ),  -- | 1 |
1519
                ( 'U', 'X', 'X', '1', 'X', 'X', 'X', '1', 'X' ),  -- | Z |
1520
                ( 'U', 'X', 'X', '1', 'X', 'X', 'X', '1', 'X' ),  -- | W |
1521
                ( '1', '1', '1', '1', '1', '1', '1', '1', '1' ),  -- | L |
1522
                ( 'U', 'X', '0', '1', 'X', 'X', '0', '1', 'X' ),  -- | H |
1523
                ( 'U', 'X', 'X', '1', 'X', 'X', 'X', '1', 'X' )   -- | D |
1524
    );
1525
 
1526
-- truth table for ">=" function
1527
        CONSTANT ge_table : stdlogic_table := (
1528
        --      ----------------------------------------------------
1529
        --      |  U    X    0    1    Z    W    L    H    D         |   |
1530
        --      ----------------------------------------------------
1531
                ( 'U', 'U', '1', 'U', 'U', 'U', '1', 'U', 'U' ),  -- | U |
1532
                ( 'U', 'X', '1', 'X', 'X', 'X', '1', 'X', 'X' ),  -- | X |
1533
                ( 'U', 'X', '1', '0', 'X', 'X', '1', '0', 'X' ),  -- | 0 |
1534
                ( '1', '1', '1', '1', '1', '1', '1', '1', '1' ),  -- | 1 |
1535
                ( 'U', 'X', '1', 'X', 'X', 'X', '1', 'X', 'X' ),  -- | Z |
1536
                ( 'U', 'X', '1', 'X', 'X', 'X', '1', 'X', 'X' ),  -- | W |
1537
                ( 'U', 'X', '1', '0', 'X', 'X', '1', '0', 'X' ),  -- | L |
1538
                ( '1', '1', '1', '1', '1', '1', '1', '1', '1' ),  -- | H |
1539
                ( 'U', 'X', '1', 'X', 'X', 'X', '1', 'X', 'X' )   -- | D |
1540
    );
1541
 
1542
 
1543
FUNCTION "="  ( l : Boolean;  r : natural ) RETURN Boolean is
1544
 
1545
begin
1546
        IF l = TRUE AND r = 1 THEN
1547
                return TRUE;
1548
        ELSIF l = FALSE AND r = 0 THEN
1549
                return TRUE;
1550
        ELSE
1551
                return FALSE;
1552
        END IF;
1553
end "=";
1554
 
1555
FUNCTION "/="  ( l : Boolean;  r : natural ) RETURN Boolean is
1556
 
1557
begin
1558
        return NOT (l = r);
1559
end "/=";
1560
 
1561
-----------------------------------------------------------------
1562
 
1563
FUNCTION "="  ( l : integer; r : std_logic_vector ) RETURN boolean IS
1564
 
1565
BEGIN
1566
        RETURN l = SIGNED(r);
1567
END "=";
1568
 
1569
-----------------------------------------------------------------
1570
FUNCTION "/=" ( l : integer;  r : std_logic_vector ) RETURN boolean IS
1571
 
1572
BEGIN
1573
        RETURN l /= SIGNED(r);
1574
END "/=";
1575
 
1576
-----------------------------------------------------------------
1577
FUNCTION "<"  ( l : integer;  r : std_logic_vector ) RETURN boolean IS
1578
 
1579
BEGIN
1580
        RETURN l < SIGNED(r);
1581
END "<";
1582
 
1583
-----------------------------------------------------------------
1584
FUNCTION ">"  ( l : integer;  r : std_logic_vector ) RETURN boolean IS
1585
 
1586
BEGIN
1587
        RETURN l > SIGNED(r);
1588
END ">";
1589
 
1590
-----------------------------------------------------------------
1591
FUNCTION "<=" ( l : integer;  r : std_logic_vector ) RETURN boolean IS
1592
 
1593
BEGIN
1594
        RETURN l <= SIGNED(r);
1595
END "<=";
1596
 
1597
-----------------------------------------------------------------
1598
FUNCTION ">=" ( l : integer;  r : std_logic_vector ) RETURN boolean IS
1599
 
1600
BEGIN
1601
        RETURN l >= SIGNED(r);
1602
END ">=";
1603
 
1604
-----------------------------------------------------------------
1605
 
1606
FUNCTION "="  ( l : std_logic_vector;  r : integer ) RETURN boolean IS
1607
 
1608
BEGIN
1609
        RETURN SIGNED(l) = r;
1610
END "=";
1611
 
1612
-----------------------------------------------------------------
1613
FUNCTION "/=" ( l : std_logic_vector;  r : integer ) RETURN boolean IS
1614
 
1615
BEGIN
1616
        RETURN SIGNED(l) /= r;
1617
END "/=";
1618
 
1619
-----------------------------------------------------------------
1620
FUNCTION "<"  ( l : std_logic_vector;  r : integer ) RETURN boolean IS
1621
 
1622
BEGIN
1623
        RETURN SIGNED(l) < r;
1624
END "<";
1625
 
1626
-----------------------------------------------------------------
1627
FUNCTION ">"  ( l : std_logic_vector;  r : integer ) RETURN boolean IS
1628
 
1629
BEGIN
1630
        RETURN SIGNED(l) > r;
1631
END ">";
1632
 
1633
-----------------------------------------------------------------
1634
FUNCTION "<=" ( l : std_logic_vector;  r : integer ) RETURN boolean IS
1635
 
1636
BEGIN
1637
        RETURN SIGNED(l) <= r;
1638
END "<=";
1639
 
1640
-----------------------------------------------------------------
1641
FUNCTION ">=" ( l : std_logic_vector;  r : integer ) RETURN boolean IS
1642
 
1643
BEGIN
1644
        RETURN SIGNED(l) >= r;
1645
END ">=";
1646
 
1647
-----------------------------------------------------------------
1648
--logical functions between std_logic_vector and integer, std_logic_vector and boolean
1649
 
1650
FUNCTION "and" ( l : std_logic_vector;  r : integer ) RETURN std_logic_vector is
1651
BEGIN
1652
        RETURN l and to_stdlogicvector(l, 32);
1653
END;
1654
 
1655
-----------------------------------------------------------------
1656
 
1657
FUNCTION "nand"  ( l : std_logic_vector;  r : integer ) RETURN std_logic_vector IS
1658
BEGIN
1659
        RETURN l nand to_stdlogicvector(l, 32);
1660
END;
1661
 
1662
-----------------------------------------------------------------
1663
 
1664
FUNCTION "or"  ( l : std_logic_vector;  r : integer ) RETURN std_logic_vector IS
1665
BEGIN
1666
        RETURN l or to_stdlogicvector(l, 32);
1667
END;
1668
 
1669
-----------------------------------------------------------------
1670
 
1671
FUNCTION "nor" ( l : std_logic_vector;  r : integer ) RETURN std_logic_vector IS
1672
BEGIN
1673
        RETURN l nor to_stdlogicvector(l, 32);
1674
END;
1675
 
1676
-----------------------------------------------------------------
1677
 
1678
FUNCTION "xor" ( l : std_logic_vector;  r : integer ) RETURN std_logic_vector IS
1679
BEGIN
1680
        RETURN l xor to_stdlogicvector(l, 32);
1681
END;
1682
 
1683
-----------------------------------------------------------------
1684
 
1685
FUNCTION "and"  ( l : integer; r : std_logic_vector ) RETURN integer IS
1686
BEGIN
1687
        RETURN l and v2v_to_integer(r);
1688
END;
1689
 
1690
-----------------------------------------------------------------
1691
 
1692
FUNCTION "nand" ( l : integer;  r : std_logic_vector ) RETURN integer IS
1693
BEGIN
1694
        RETURN l nand v2v_to_integer(r);
1695
END;
1696
 
1697
-----------------------------------------------------------------
1698
 
1699
FUNCTION "or"  ( l : integer;  r : std_logic_vector ) RETURN integer IS
1700
BEGIN
1701
        RETURN l or v2v_to_integer(r);
1702
END;
1703
 
1704
-----------------------------------------------------------------
1705
 
1706
FUNCTION "nor"  ( l : integer;  r : std_logic_vector ) RETURN integer IS
1707
BEGIN
1708
        RETURN l nor v2v_to_integer(r);
1709
END;
1710
 
1711
-----------------------------------------------------------------
1712
 
1713
FUNCTION "xor" ( l : integer;  r : std_logic_vector ) RETURN integer IS
1714
BEGIN
1715
        RETURN l xor v2v_to_integer(r);
1716
END;
1717
 
1718
-----------------------------------------------------------------
1719
 
1720
FUNCTION "and" ( l : std_logic_vector;  r : boolean ) RETURN std_logic_vector IS
1721
BEGIN
1722
        RETURN l and to_stdlogicvector(r,32);
1723
END;
1724
 
1725
-----------------------------------------------------------------
1726
 
1727
FUNCTION "nand"  ( l : std_logic_vector;  r : boolean ) RETURN std_logic_vector IS
1728
BEGIN
1729
        RETURN l nand to_stdlogicvector(r,32);
1730
END;
1731
 
1732
-----------------------------------------------------------------
1733
 
1734
FUNCTION "or"  ( l : std_logic_vector;  r : boolean ) RETURN std_logic_vector IS
1735
BEGIN
1736
        RETURN l or to_stdlogicvector(r,32);
1737
END;
1738
 
1739
-----------------------------------------------------------------
1740
 
1741
FUNCTION "nor" ( l : std_logic_vector;  r : boolean ) RETURN std_logic_vector IS
1742
BEGIN
1743
        RETURN l nor to_stdlogicvector(r,32);
1744
END;
1745
 
1746
-----------------------------------------------------------------
1747
 
1748
FUNCTION "xor" ( l : std_logic_vector;  r : boolean ) RETURN std_logic_vector IS
1749
BEGIN
1750
        RETURN l xor to_stdlogicvector(r,32);
1751
END;
1752
 
1753
-----------------------------------------------------------------
1754
 
1755
FUNCTION "and"  ( l : boolean; r : std_logic_vector ) RETURN boolean IS
1756
BEGIN
1757
        RETURN l and to_boolean(r);
1758
END;
1759
 
1760
-----------------------------------------------------------------
1761
 
1762
FUNCTION "nand" ( l : boolean;  r : std_logic_vector ) RETURN boolean IS
1763
BEGIN
1764
        RETURN l nand to_boolean(r);
1765
END;
1766
 
1767
-----------------------------------------------------------------
1768
 
1769
FUNCTION "or"  ( l : boolean;  r : std_logic_vector ) RETURN boolean IS
1770
BEGIN
1771
        RETURN l or to_boolean(r);
1772
END;
1773
 
1774
-----------------------------------------------------------------
1775
 
1776
FUNCTION "nor"  ( l : boolean;  r : std_logic_vector ) RETURN boolean IS
1777
BEGIN
1778
        RETURN l nor to_boolean(r);
1779
END;
1780
 
1781
-----------------------------------------------------------------
1782
 
1783
FUNCTION "xor" ( l : boolean;  r : std_logic_vector ) RETURN boolean IS
1784
BEGIN
1785
        RETURN l xor to_boolean(r);
1786
END;
1787
 
1788
--logical functions between std_logic_vector and integer, std_logic_vector and boolean
1789
-----------------------------------------------------------------
1790
-- Added functions for std_logic, integer
1791
FUNCTION "="  ( l : std_logic;  r : integer ) RETURN boolean IS
1792
BEGIN
1793
        RETURN to_integer(l) = r;
1794
END "=";
1795
-----------------------------------------------------------------
1796
 
1797
FUNCTION "/=" ( l : std_logic;  r : integer ) RETURN boolean IS
1798
BEGIN
1799
        RETURN to_integer(l) /= r;
1800
END "/=";
1801
-----------------------------------------------------------------
1802
 
1803
FUNCTION "<"  ( l : std_logic;  r : integer ) RETURN boolean IS
1804
BEGIN
1805
        RETURN to_integer(l) < r;
1806
END "<";
1807
-----------------------------------------------------------------
1808
 
1809
FUNCTION ">"  ( l : std_logic;  r : integer ) RETURN boolean IS
1810
BEGIN
1811
        RETURN to_integer(l) > r;
1812
END ">";
1813
-----------------------------------------------------------------
1814
 
1815
FUNCTION "<=" ( l : std_logic;  r : integer ) RETURN boolean IS
1816
BEGIN
1817
        RETURN to_integer(l) <= r;
1818
END "<=";
1819
-----------------------------------------------------------------
1820
 
1821
FUNCTION ">=" ( l : std_logic;  r : integer ) RETURN boolean IS
1822
BEGIN
1823
        RETURN to_integer(l) >= r;
1824
END ">=";
1825
-----------------------------------------------------------------
1826
 
1827
-- Functions for std_logic, integer
1828
-----------------------------------------------------------------
1829
 
1830
--pragma synthesis_off
1831
-- arithmetic operations for real and int and int and real
1832
FUNCTION "+"  ( l : real;  r : integer ) RETURN real IS
1833
BEGIN
1834
        RETURN l + to_real(r);
1835
END;
1836
 
1837
FUNCTION "-" ( l : real;  r : integer ) RETURN real IS
1838
BEGIN
1839
        RETURN l - to_real(r);
1840
END;
1841
 
1842
FUNCTION "/"  ( l : real;  r : integer ) RETURN real IS
1843
BEGIN
1844
        RETURN l / to_real(r);
1845
END;
1846
 
1847
FUNCTION "*"  ( l : real;  r : integer ) RETURN real IS
1848
BEGIN
1849
        RETURN l * to_real(r);
1850
END ;
1851
 
1852
 
1853
FUNCTION "+"  ( l : integer;  r : real ) RETURN real  IS
1854
BEGIN
1855
        RETURN to_real(l) + r;
1856
END;
1857
 
1858
FUNCTION "-" ( l : integer;  r : real ) RETURN real IS
1859
BEGIN
1860
        RETURN to_real(l) - r;
1861
END;
1862
 
1863
FUNCTION "/"  ( l : integer;  r : real ) RETURN real  IS
1864
BEGIN
1865
        RETURN to_real(l) / l;
1866
END;
1867
 
1868
FUNCTION "*"  ( l : integer;  r : real ) RETURN real IS
1869
BEGIN
1870
        RETURN to_real(l) * r;
1871
END;
1872
 
1873
 
1874
-- end arithmetic operations for real and int and int and real
1875
-----------------------------------------------------------------
1876
 
1877
FUNCTION "="  ( l : real;  r : integer ) RETURN boolean IS
1878
 
1879
BEGIN
1880
        RETURN INTEGER(l) = r;
1881
 
1882
END "=";
1883
 
1884
-----------------------------------------------------------------
1885
FUNCTION "/=" ( l : real;  r : integer ) RETURN boolean IS
1886
 
1887
BEGIN
1888
        RETURN INTEGER(l) /= r;
1889
 
1890
END "/=";
1891
 
1892
-----------------------------------------------------------------
1893
FUNCTION "<"  ( l : real;  r : integer ) RETURN boolean IS
1894
 
1895
BEGIN
1896
        RETURN INTEGER(l) < r;
1897
 
1898
END "<";
1899
 
1900
-----------------------------------------------------------------
1901
FUNCTION ">"  ( l : real;  r : integer ) RETURN boolean IS
1902
 
1903
BEGIN
1904
        RETURN INTEGER(l) > r;
1905
 
1906
END ">";
1907
 
1908
-----------------------------------------------------------------
1909
FUNCTION "<=" ( l : real;  r : integer ) RETURN boolean IS
1910
 
1911
BEGIN
1912
        RETURN INTEGER(l) <= r;
1913
 
1914
END "<=";
1915
 
1916
-----------------------------------------------------------------
1917
FUNCTION ">=" ( l : real;  r : integer ) RETURN boolean IS
1918
 
1919
BEGIN
1920
        RETURN INTEGER(l) >= r;
1921
 
1922
END ">=";
1923
 
1924
-----------------------------------------------------------------
1925
 
1926
FUNCTION "="  ( l : integer;  r : real ) RETURN boolean IS
1927
 
1928
BEGIN
1929
        RETURN l = INTEGER(r);
1930
 
1931
END "=";
1932
 
1933
-----------------------------------------------------------------
1934
FUNCTION "/=" ( l : integer;  r : real ) RETURN boolean IS
1935
 
1936
BEGIN
1937
        RETURN l /= INTEGER(r);
1938
 
1939
END "/=";
1940
 
1941
 
1942
 
1943
-----------------------------------------------------------------
1944
FUNCTION "<"  ( l : integer;  r : real ) RETURN boolean IS
1945
 
1946
BEGIN
1947
        RETURN l < INTEGER(r);
1948
 
1949
END "<";
1950
 
1951
-----------------------------------------------------------------
1952
FUNCTION ">"  ( l : integer;  r : real ) RETURN boolean IS
1953
 
1954
BEGIN
1955
        RETURN l > INTEGER(r);
1956
 
1957
END ">";
1958
 
1959
-----------------------------------------------------------------
1960
FUNCTION "<=" ( l : integer;  r : real ) RETURN boolean IS
1961
 
1962
BEGIN
1963
        RETURN l <= INTEGER(r);
1964
 
1965
END "<=";
1966
 
1967
-----------------------------------------------------------------
1968
FUNCTION ">=" ( l : integer;  r : real ) RETURN boolean IS
1969
 
1970
BEGIN
1971
        RETURN l >= INTEGER(r);
1972
 
1973
END ">=";
1974
 
1975
--pragma synthesis_on
1976
-----------------------------------------------------------------
1977
 
1978
FUNCTION "+"   ( l, r : std_logic_vector ) RETURN std_logic_vector is
1979
 
1980
begin
1981
        return STD_LOGIC_VECTOR(UNSIGNED(l) + UNSIGNED(r));
1982
 
1983
end "+";
1984
------------------------------------------------------------------
1985
FUNCTION "-"   ( l, r : std_logic_vector ) RETURN std_logic_vector is
1986
 
1987
begin
1988
        return STD_LOGIC_VECTOR(UNSIGNED(l) - UNSIGNED(r));
1989
 
1990
end "-";
1991
 
1992
------------------------------------------------------------------
1993
FUNCTION "*"   ( l, r : std_logic_vector ) RETURN std_logic_vector is
1994
 
1995
begin
1996
        return STD_LOGIC_VECTOR(UNSIGNED(l) * UNSIGNED(r));
1997
 
1998
end "*";
1999
------------------------------------------------------------------
2000
FUNCTION "/"   ( l, r : std_logic_vector ) RETURN std_logic_vector is
2001
 
2002
begin
2003
        return STD_LOGIC_VECTOR(UNSIGNED(l) / UNSIGNED(r));
2004
 
2005
end "/";
2006
 
2007
------------------------------------------------------------------
2008
 
2009
FUNCTION "REM" ( l, r : std_logic_vector ) RETURN std_logic_vector is
2010
begin
2011
        return STD_LOGIC_VECTOR(UNSIGNED(l) rem UNSIGNED(r));
2012
 
2013
end "REM";
2014
 
2015
------------------------------------------------------------------
2016
 
2017
FUNCTION "+"   ( l : std_logic_vector; r : integer ) RETURN std_logic_vector is
2018
 
2019
begin
2020
        return STD_LOGIC_VECTOR(SIGNED(l) + r);
2021
 
2022
end "+";
2023
------------------------------------------------------------------
2024
FUNCTION "-"   ( l : std_logic_vector; r : integer ) RETURN std_logic_vector is
2025
 
2026
begin
2027
        return STD_LOGIC_VECTOR(SIGNED(l) - r);
2028
 
2029
end "-";
2030
------------------------------------------------------------------
2031
FUNCTION "*"   ( l : std_logic_vector; r : integer ) RETURN std_logic_vector is
2032
 
2033
begin
2034
        return STD_LOGIC_VECTOR(SIGNED(l) * r);
2035
 
2036
end "*";
2037
------------------------------------------------------------------
2038
FUNCTION "/"   ( l : std_logic_vector; r : integer ) RETURN std_logic_vector is
2039
 
2040
begin
2041
        return STD_LOGIC_VECTOR(SIGNED(l) / r);
2042
 
2043
end "/";
2044
------------------------------------------------------------------
2045
FUNCTION "REM" ( l : std_logic_vector; r : integer ) RETURN std_logic_vector is
2046
 
2047
begin
2048
        return STD_LOGIC_VECTOR(SIGNED(l) rem r);
2049
 
2050
end "REM";
2051
 
2052
------------------------------------------------------------------
2053
FUNCTION "&" ( l : std_logic_vector; r : integer ) RETURN std_logic_vector is
2054
 
2055
begin
2056
        return l & to_stdlogic(r);
2057
 
2058
end "&";
2059
 
2060
------------------------------------------------------------------
2061
FUNCTION "&" ( l : std_logic_vector; r : boolean ) RETURN std_logic_vector is
2062
 
2063
begin
2064
        return l & to_stdlogic(r);
2065
 
2066
end "&";
2067
 
2068
------------------------------------------------------------------
2069
FUNCTION "+"   ( l : std_logic_vector; r : std_logic ) RETURN std_logic_vector is
2070
 
2071
begin
2072
        return STD_LOGIC_VECTOR(SIGNED(l) + to_integer(r));
2073
 
2074
end "+";
2075
------------------------------------------------------------------
2076
FUNCTION "-"   ( l : std_logic_vector; r : std_logic ) RETURN std_logic_vector is
2077
 
2078
begin
2079
        return STD_LOGIC_VECTOR(SIGNED(l) - to_integer(r));
2080
 
2081
end "-";
2082
------------------------------------------------------------------
2083
FUNCTION "*"   ( l : std_logic_vector; r : std_logic ) RETURN std_logic_vector is
2084
 
2085
begin
2086
        return STD_LOGIC_VECTOR(SIGNED(l) * to_integer(r));
2087
 
2088
end "*";
2089
------------------------------------------------------------------
2090
FUNCTION "/"   ( l : std_logic_vector; r : std_logic ) RETURN std_logic_vector is
2091
 
2092
begin
2093
        return STD_LOGIC_VECTOR(SIGNED(l) / to_integer(r));
2094
 
2095
end "/";
2096
------------------------------------------------------------------
2097
FUNCTION "REM" ( l : std_logic_vector; r : std_logic ) RETURN std_logic_vector is
2098
 
2099
begin
2100
        return STD_LOGIC_VECTOR(SIGNED(l) rem to_integer(r));
2101
 
2102
end "REM";
2103
 
2104
------------------------------------------------------------------
2105
FUNCTION "+"   ( l : std_logic; r : std_logic_vector ) RETURN std_logic_vector is
2106
begin
2107
        return STD_LOGIC_VECTOR(to_integer(l) + SIGNED(r));
2108
END "+";
2109
 
2110
------------------------------------------------------------------
2111
 
2112
FUNCTION "-"   ( l : std_logic; r : std_logic_vector ) RETURN std_logic_vector is
2113
begin
2114
        return STD_LOGIC_VECTOR(to_integer(l) - SIGNED(r));
2115
END "-";
2116
------------------------------------------------------------------
2117
 
2118
FUNCTION "*"   ( l : std_logic; r : std_logic_vector ) RETURN std_logic_vector is
2119
begin
2120
        return STD_LOGIC_VECTOR(to_integer(l) * SIGNED(r));
2121
END "*";
2122
------------------------------------------------------------------
2123
 
2124
FUNCTION "/"   ( l : std_logic; r : std_logic_vector ) RETURN std_logic_vector is
2125
begin
2126
        return STD_LOGIC_VECTOR(to_integer(l) / SIGNED(r));
2127
END "/";
2128
------------------------------------------------------------------
2129
 
2130
FUNCTION "REM" ( l : std_logic; r : std_logic_vector ) RETURN std_logic_vector is
2131
begin
2132
        return STD_LOGIC_VECTOR(to_integer(l) REM SIGNED(r));
2133
END "REM";
2134
-------------------------------------------------------------
2135
-- need logical functions bet. std_logic_vector and std_logic
2136
FUNCTION "and" ( l : std_logic_vector; r : std_logic )  RETURN std_logic_vector IS
2137
BEGIN
2138
        RETURN l and to_stdlogicvector(r, l'length);
2139
END "and";
2140
--------------------------------------------------------------
2141
 
2142
FUNCTION "nand" ( l : std_logic_vector; r : std_logic )  RETURN std_logic_vector IS
2143
BEGIN
2144
        RETURN l nand to_stdlogicvector(r, l'length);
2145
END "nand";
2146
--------------------------------------------------------------
2147
FUNCTION "or" ( l : std_logic_vector; r : std_logic )  RETURN std_logic_vector IS
2148
BEGIN
2149
        RETURN l or to_stdlogicvector(r, l'length);
2150
END "or";
2151
--------------------------------------------------------------
2152
 
2153
FUNCTION "nor" ( l : std_logic_vector; r : std_logic )  RETURN std_logic_vector IS
2154
BEGIN
2155
        RETURN l nor to_stdlogicvector(r, l'length);
2156
END "nor";
2157
--------------------------------------------------------------
2158
 
2159
FUNCTION "xor" ( l : std_logic_vector; r : std_logic )  RETURN std_logic_vector IS
2160
BEGIN
2161
        RETURN l xor to_stdlogicvector(r, l'length);
2162
END "xor";
2163
--------------------------------------------------------------
2164
 
2165
FUNCTION "xnor" ( l : std_logic_vector; r : std_logic )  RETURN std_logic_vector IS
2166
 
2167
BEGIN
2168
        RETURN NOT(l xor to_stdlogicvector(r, l'length));
2169
END "xnor";
2170
--------------------------------------------------------------
2171
 
2172
FUNCTION "and" ( l : std_logic; r : std_logic_vector )  RETURN std_logic_vector IS
2173
BEGIN
2174
        RETURN to_stdlogicvector(l, r'length) and r;
2175
END "and";
2176
--------------------------------------------------------------
2177
 
2178
FUNCTION "nand" ( l : std_logic; r : std_logic_vector )  RETURN std_logic_vector IS
2179
BEGIN
2180
        RETURN to_stdlogicvector(l, r'length) nand r;
2181
END "nand";
2182
--------------------------------------------------------------
2183
FUNCTION "or" ( l : std_logic; r : std_logic_vector )  RETURN std_logic_vector IS
2184
BEGIN
2185
        RETURN to_stdlogicvector(l, r'length) or r;
2186
END "or";
2187
--------------------------------------------------------------
2188
 
2189
FUNCTION "nor" ( l : std_logic; r : std_logic_vector )  RETURN std_logic_vector IS
2190
BEGIN
2191
        RETURN to_stdlogicvector(l, r'length) nor r;
2192
END "nor";
2193
--------------------------------------------------------------
2194
 
2195
FUNCTION "xor" ( l : std_logic; r : std_logic_vector )  RETURN std_logic_vector IS
2196
BEGIN
2197
        RETURN to_stdlogicvector(l, r'length) xor r;
2198
END "xor";
2199
--------------------------------------------------------------
2200
FUNCTION "xnor" ( l : std_logic; r : std_logic_vector )  RETURN std_logic_vector IS
2201
BEGIN
2202
        RETURN NOT(to_stdlogicvector(l, r'length) xor r);
2203
END "xnor";
2204
--------------------------------------------------------------
2205
 
2206
-- end logical functions for std_logic_vector and std_logic
2207
------------------------------------------------------------------
2208
-- need arith functions bet std_logic and std_logic
2209
-- used only when the int can be 0 or 1
2210
-- need arithmetic functions bet. std_logic_vector and std_logic
2211
 
2212
FUNCTION "+"   ( l : std_logic; r : std_logic ) RETURN std_logic IS
2213
BEGIN
2214
        return to_stdlogic(to_integer(l) + to_integer(r));
2215
END "+";
2216
 
2217
FUNCTION "-"   ( l : std_logic; r : std_logic ) RETURN std_logic IS
2218
BEGIN
2219
        return to_stdlogic(to_integer(l) - to_integer(r));
2220
END "-";
2221
 
2222
FUNCTION "*"   ( l : std_logic; r : std_logic ) RETURN std_logic IS
2223
BEGIN
2224
        return to_stdlogic(to_integer(l) * to_integer(r));
2225
END "*";
2226
 
2227
FUNCTION "/"   ( l : std_logic; r : std_logic ) RETURN std_logic IS
2228
BEGIN
2229
        return to_stdlogic(to_integer(l) / to_integer(r));
2230
END "/";
2231
 
2232
FUNCTION "REM" ( l : std_logic; r : std_logic ) RETURN std_logic IS
2233
BEGIN
2234
        return to_stdlogic(to_integer(l) REM to_integer(r));
2235
END "REM";
2236
 
2237
 
2238
------- Arithmatic operations between std_logic and integer
2239
-- caveat, functions below return integer
2240
 
2241
FUNCTION "+" ( l : std_logic; r : integer )  RETURN integer IS
2242
BEGIN
2243
        return to_integer(l) + r;
2244
END "+";
2245
 
2246
-------------------------------------------------------
2247
 
2248
FUNCTION "-" ( l : std_logic; r : integer ) RETURN integer IS
2249
BEGIN
2250
        return to_integer(l) - r;
2251
END "-";
2252
 
2253
-------------------------------------------------------
2254
FUNCTION "*" ( l : std_logic; r : integer ) RETURN integer IS
2255
BEGIN
2256
        return to_integer(l) * r;
2257
END "*";
2258
 
2259
-------------------------------------------------------
2260
FUNCTION "/" ( l : std_logic; r : integer ) RETURN integer IS
2261
BEGIN
2262
        return to_integer(l) / r;
2263
END "/";
2264
 
2265
------------------------------------------------------- 
2266
FUNCTION "REM" ( l : std_logic; r : integer ) RETURN integer IS
2267
BEGIN
2268
        return to_integer(l) REM r;
2269
END "REM";
2270
 
2271
-------------------------------------------------------
2272
-------------------------------------------------------
2273
FUNCTION "+"   ( l : integer; r : std_logic ) RETURN integer IS
2274
begin
2275
        return l + to_integer(r);
2276
END "+";
2277
-------------------------------------------------------
2278
 
2279
FUNCTION "-"   ( l : integer; r : std_logic ) RETURN integer IS
2280
begin
2281
        return l - to_integer(r);
2282
END "-";
2283
-------------------------------------------------------
2284
FUNCTION "*"   ( l : integer; r : std_logic ) RETURN integer IS
2285
begin
2286
        return l * to_integer(r);
2287
END "*";
2288
 
2289
-------------------------------------------------------
2290
FUNCTION "/"   ( l : integer; r : std_logic ) RETURN integer IS
2291
begin
2292
        return l / to_integer(r);
2293
END "/";
2294
 
2295
-------------------------------------------------------
2296
FUNCTION "REM" ( l : integer; r : std_logic ) RETURN integer IS
2297
begin
2298
        return l REM to_integer(r);
2299
END "REM";
2300
 
2301
-------------------------------------------------------
2302
FUNCTION "+"   ( l : integer; r : std_logic_vector ) RETURN integer IS
2303
 
2304
BEGIN
2305
        RETURN to_integer(l + SIGNED(r));
2306
END "+";
2307
------------------------------------------------------------------
2308
 
2309
FUNCTION "-"   ( l : integer; r : std_logic_vector ) RETURN integer IS
2310
 
2311
BEGIN
2312
        RETURN to_integer(l - SIGNED(r));
2313
END "-";
2314
------------------------------------------------------------------
2315
FUNCTION "*"   ( l : integer; r : std_logic_vector ) RETURN integer IS
2316
 
2317
BEGIN
2318
        RETURN to_integer(l * SIGNED(r));
2319
END "*";
2320
------------------------------------------------------------------
2321
FUNCTION "/"   ( l : integer; r : std_logic_vector ) RETURN integer IS
2322
 
2323
BEGIN
2324
        RETURN to_integer(l / SIGNED(r));
2325
END "/";
2326
------------------------------------------------------------------
2327
FUNCTION "REM" ( l : integer; r : std_logic_vector ) RETURN integer IS
2328
 
2329
BEGIN
2330
        RETURN to_integer(l REM SIGNED(r));
2331
END "REM";
2332
------------------------------------------------------------------
2333
 
2334
 
2335
FUNCTION "and" ( l : std_logic; r : integer )  RETURN std_logic IS
2336
 
2337
BEGIN
2338
        RETURN l and to_stdlogic(r);
2339
END "and";
2340
 
2341
------------------------------------------------------------------
2342
FUNCTION "nand" ( l : std_logic; r : integer ) RETURN std_logic IS
2343
 
2344
BEGIN
2345
        RETURN l nand to_stdlogic(r);
2346
END "nand";
2347
 
2348
------------------------------------------------------------------
2349
FUNCTION "or" ( l : std_logic; r : integer ) RETURN std_logic IS
2350
 
2351
BEGIN
2352
        RETURN l or to_stdlogic(r);
2353
END "or";
2354
 
2355
------------------------------------------------------------------
2356
FUNCTION "nor" ( l : std_logic; r : integer ) RETURN std_logic IS
2357
 
2358
BEGIN
2359
        RETURN l nor to_stdlogic(r);
2360
END "nor";
2361
 
2362
------------------------------------------------------------------
2363
FUNCTION "xor" ( l : std_logic; r : integer ) RETURN std_logic IS
2364
 
2365
BEGIN
2366
        RETURN l xor to_stdlogic(r);
2367
END "xor";
2368
 
2369
------------------------------------------------------------------
2370
FUNCTION "&" ( l : std_logic; r : integer ) RETURN std_logic_vector IS
2371
 
2372
BEGIN
2373
        RETURN l & to_stdlogic(r);
2374
END "&";
2375
 
2376
------------------------------------------------------------------
2377
 
2378
FUNCTION "xnor" ( l : std_logic; r : integer ) RETURN std_logic IS
2379
 
2380
BEGIN
2381
        RETURN not(l xor to_stdlogic(r));
2382
END "xnor";
2383
 
2384
------------------------------------------------------------------
2385
 
2386
FUNCTION "and" ( l : integer; r : std_logic ) RETURN integer IS
2387
 
2388
VARIABLE tmp : integer := 0;
2389
 
2390
BEGIN
2391
        RETURN l and to_integer(r);
2392
 
2393
END "and";
2394
 
2395
------------------------------------------------------------------
2396
FUNCTION "nand" ( l : integer; r : std_logic ) RETURN integer IS
2397
 
2398
VARIABLE tmp : integer := 0;
2399
BEGIN
2400
        RETURN l nand to_integer(r);
2401
 
2402
END "nand";
2403
 
2404
------------------------------------------------------------------
2405
FUNCTION "or" ( l : integer; r : std_logic ) RETURN integer IS
2406
 
2407
VARIABLE tmp : integer := 0;
2408
BEGIN
2409
        RETURN l or to_integer(r);
2410
 
2411
END "or";
2412
 
2413
------------------------------------------------------------------
2414
FUNCTION "nor" ( l : integer; r : std_logic ) RETURN integer IS
2415
 
2416
VARIABLE tmp : integer := 0;
2417
BEGIN
2418
        RETURN l nor to_integer(r);
2419
 
2420
END "nor";
2421
 
2422
------------------------------------------------------------------
2423
FUNCTION "xor" ( l : integer; r : std_logic ) RETURN integer IS
2424
 
2425
VARIABLE tmp : integer := 0;
2426
BEGIN
2427
        RETURN l xor to_integer(r);
2428
 
2429
END "xor";
2430
 
2431
------------------------------------------------------------------
2432
FUNCTION "&" ( l : integer; r : std_logic ) RETURN std_logic_vector IS
2433
BEGIN
2434
        RETURN to_stdlogic(l) & r;
2435
 
2436
END "&";
2437
------------------------------------------------------------------
2438
 
2439
FUNCTION "xnor" ( l : integer; r : std_logic ) RETURN integer IS
2440
 
2441
VARIABLE tmp : integer := 0;
2442
BEGIN
2443
        RETURN l xnor to_integer(r);
2444
 
2445
END "xnor";
2446
 
2447
------------------------------------------------------------------
2448
 
2449
FUNCTION "and" ( l : std_logic ;  r : boolean )  RETURN std_logic IS
2450
BEGIN
2451
        RETURN l AND to_stdlogic(r);
2452
END "and";
2453
------------------------------------------------------------------
2454
 
2455
FUNCTION "nand" ( l : std_logic ;  r : boolean ) RETURN std_logic IS
2456
BEGIN
2457
        RETURN l NAND to_stdlogic(r);
2458
END "nand";
2459
------------------------------------------------------------------
2460
 
2461
FUNCTION "or" ( l : std_logic ;  r : boolean ) RETURN std_logic IS
2462
BEGIN
2463
        RETURN l OR to_stdlogic(r);
2464
END "or";
2465
------------------------------------------------------------------
2466
 
2467
FUNCTION "nor" ( l : std_logic ;  r : boolean ) RETURN std_logic IS
2468
BEGIN
2469
        RETURN l NOR to_stdlogic(r);
2470
END "nor";
2471
------------------------------------------------------------------
2472
 
2473
FUNCTION "xor" ( l : std_logic ;  r : boolean ) RETURN std_logic IS
2474
BEGIN
2475
        RETURN l XOR to_stdlogic(r);
2476
END "xor";
2477
------------------------------------------------------------------
2478
FUNCTION "&" ( l : std_logic; r : boolean ) RETURN std_logic_vector IS
2479
BEGIN
2480
        RETURN l & to_stdlogic(r);
2481
END "&";
2482
------------------------------------------------------------------
2483
 
2484
FUNCTION "xnor" ( l : std_logic ;  r : boolean ) RETURN std_logic IS
2485
BEGIN
2486
        RETURN NOT(l XOR to_stdlogic(r));
2487
END "xnor";
2488
------------------------------------------------------------------
2489
 
2490
 
2491
FUNCTION "and" ( l : boolean ;  r : std_logic ) RETURN boolean IS
2492
 
2493
VARIABLE tmp : std_logic := 'U';
2494
BEGIN
2495
        tmp := to_stdlogic(l) AND r;
2496
        RETURN to_boolean(tmp);
2497
END "and";
2498
------------------------------------------------------------------
2499
 
2500
FUNCTION "nand" ( l : boolean ;  r : std_logic ) RETURN boolean IS
2501
VARIABLE tmp : std_logic := 'U';
2502
BEGIN
2503
        tmp := to_stdlogic(l) NAND r;
2504
        RETURN to_boolean(tmp);
2505
END "nand";
2506
------------------------------------------------------------------
2507
 
2508
FUNCTION "or" ( l : boolean ;  r : std_logic ) RETURN boolean IS
2509
VARIABLE tmp : std_logic := 'U';
2510
BEGIN
2511
        tmp := to_stdlogic(l) OR r;
2512
        RETURN to_boolean(tmp);
2513
END "or";
2514
------------------------------------------------------------------
2515
 
2516
FUNCTION "nor" ( l : boolean ;  r : std_logic ) RETURN boolean IS
2517
VARIABLE tmp : std_logic := 'U';
2518
BEGIN
2519
        tmp := to_stdlogic(l) NOR r;
2520
        RETURN to_boolean(tmp);
2521
END "nor";
2522
------------------------------------------------------------------
2523
 
2524
FUNCTION "xor" ( l : boolean ;  r : std_logic ) RETURN boolean IS
2525
VARIABLE tmp : std_logic := 'U';
2526
BEGIN
2527
        tmp := to_stdlogic(l) XOR r;
2528
        RETURN to_boolean(tmp);
2529
END "xor";
2530
------------------------------------------------------------------
2531
FUNCTION "&" ( l : boolean ;  r : std_logic ) RETURN std_logic_vector IS
2532
BEGIN
2533
        RETURN to_stdlogic(l) & r;
2534
END "&";
2535
------------------------------------------------------------------
2536
 
2537
FUNCTION "xnor" ( l : boolean ;  r : std_logic ) RETURN boolean IS
2538
VARIABLE tmp : std_logic := 'U';
2539
BEGIN
2540
        tmp := NOT(to_stdlogic(l) XOR r);
2541
        RETURN to_boolean(tmp);
2542
END "xnor";
2543
------------------------------------------------------------------
2544
 
2545
FUNCTION "and" ( l : integer; r : boolean ) RETURN integer IS
2546
BEGIN
2547
        RETURN l and to_integer(r);
2548
END "and";
2549
 
2550
------------------------------------------------------------------
2551
FUNCTION "nand" ( l : integer; r : boolean ) RETURN integer IS
2552
BEGIN
2553
        RETURN l nand to_integer(r);
2554
END "nand";
2555
------------------------------------------------------------------
2556
FUNCTION "or" ( l : integer; r : boolean ) RETURN integer IS
2557
BEGIN
2558
        RETURN l or to_integer(r);
2559
END "or";
2560
------------------------------------------------------------------
2561
FUNCTION "nor" ( l : integer; r : boolean ) RETURN integer IS
2562
BEGIN
2563
        RETURN l nor to_integer(r);
2564
END "nor";
2565
------------------------------------------------------------------
2566
FUNCTION "xor" ( l : integer; r : boolean ) RETURN integer IS
2567
BEGIN
2568
        RETURN l xor to_integer(r);
2569
END "xor";
2570
------------------------------------------------------------------
2571
FUNCTION "&" ( l : integer; r : boolean ) RETURN std_logic_vector IS
2572
BEGIN
2573
        RETURN to_stdlogic(l) & to_stdlogic(r);
2574
END "&";
2575
------------------------------------------------------------------
2576
FUNCTION "xnor" ( l : integer; r : boolean ) RETURN integer IS
2577
BEGIN
2578
        RETURN l xnor to_integer(r);
2579
END "xnor";
2580
------------------------------------------------------------------
2581
 
2582
FUNCTION "and" ( l : boolean; r : integer ) RETURN boolean IS
2583
BEGIN
2584
        RETURN l AND to_boolean(r);
2585
END "and";
2586
------------------------------------------------------------------
2587
FUNCTION "nand" ( l : boolean; r : integer ) RETURN boolean IS
2588
BEGIN
2589
        RETURN l NAND to_boolean(r);
2590
END "nand";
2591
------------------------------------------------------------------
2592
FUNCTION "or" ( l : boolean; r : integer ) RETURN boolean IS
2593
BEGIN
2594
        RETURN l or to_boolean(r);
2595
END "or";
2596
------------------------------------------------------------------
2597
FUNCTION "nor" ( l : boolean; r : integer ) RETURN boolean IS
2598
BEGIN
2599
        RETURN l nor to_boolean(r);
2600
END "nor";
2601
------------------------------------------------------------------
2602
FUNCTION "xor" ( l : boolean; r : integer ) RETURN boolean IS
2603
BEGIN
2604
        RETURN l xor to_boolean(r);
2605
END "xor";
2606
------------------------------------------------------------------
2607
FUNCTION "&" ( l : boolean; r : integer ) RETURN std_logic_vector IS
2608
BEGIN
2609
        RETURN to_stdlogic(l) & to_stdlogic(r);
2610
END "&";
2611
 
2612
------------------------------------------------------------------
2613
FUNCTION "xnor" ( l : boolean; r : integer ) RETURN boolean IS
2614
BEGIN
2615
        RETURN l xnor to_boolean(r);
2616
END "xnor";
2617
------------------------------------------------------------------
2618
 
2619
 
2620
-- Overloaded function for text output
2621
 
2622
FUNCTION to_bitvector ( a : bit ) RETURN bit_vector IS
2623
VARIABLE s : bit_vector ( 1 TO 1 );
2624
BEGIN
2625
        s(1) := a;
2626
        RETURN s;
2627
END to_bitvector;
2628
 
2629
------------------------------------------------------------------
2630
 
2631
FUNCTION to_bitvector ( a : std_ulogic ) RETURN bit_vector IS
2632
VARIABLE s : bit_vector ( 1 TO 1 );
2633
BEGIN
2634
        s(1) := to_bit(a);
2635
        RETURN s;
2636
END to_bitvector;
2637
 
2638
------------------------------------------------------------------
2639
 
2640
FUNCTION to_bitvector ( a : integer ) RETURN bit_vector IS
2641
VARIABLE s : bit_vector ( 31 DOWNTO 0 );
2642
BEGIN
2643
        s := to_bitvector(STD_LOGIC_VECTOR(to_signed(a, 32)));
2644
        RETURN s;
2645
END to_bitvector;
2646
 
2647
------------------------------------------------------------------
2648
 
2649
FUNCTION to_stdlogicvector(l : integer; size : natural; dir : direction := little_endian) RETURN std_logic_vector IS
2650
 
2651
BEGIN
2652
        IF dir = little_endian THEN
2653
                RETURN STD_LOGIC_VECTOR(to_signed(l,size));
2654
        ELSE
2655
                RETURN STD_LOGIC_VECTOR(to_signed(l,size) ROL size); -- rotate left by size times
2656
        END IF;
2657
 
2658
END to_stdlogicvector;
2659
 
2660
------------------------------------------------------------------
2661
FUNCTION to_stdlogicvector(l : std_logic_vector ) RETURN std_logic_vector IS
2662
 
2663
BEGIN
2664
        RETURN l;
2665
 
2666
END to_stdlogicvector;
2667
 
2668
------------------------------------------------------------------
2669
FUNCTION to_stdlogicvector(l : std_logic_vector; size : natural; dir : direction := little_endian )
2670
        RETURN std_logic_vector IS
2671
VARIABLE tmp1 : UNSIGNED(l'length-1 downto 0);
2672
VARIABLE tmp2 : UNSIGNED(size-1 downto 0);
2673
BEGIN
2674
        IF dir = little_endian THEN
2675
                RETURN STD_LOGIC_VECTOR(resize(UNSIGNED(l),size));
2676
        ELSE
2677
                -- using function ROTATE_LEFT to make it both 87 and 93 compliant
2678
                -- first get eqiv. in descending range
2679
                -- second resize
2680
                -- finally, rotate and return
2681
 
2682
                tmp1 :=  ROTATE_LEFT(UNSIGNED(l),l'length);
2683
                tmp2 := resize(UNSIGNED(tmp1),size);
2684
                RETURN STD_LOGIC_VECTOR(ROTATE_LEFT(UNSIGNED(tmp2),size));
2685
        END IF;
2686
 
2687
END to_stdlogicvector;
2688
 
2689
------------------------------------------------------------------
2690
FUNCTION to_stdlogicvector(l : std_logic; size : natural) RETURN std_logic_vector IS
2691
 
2692
VARIABLE tmp : std_logic_vector(size-1 DOWNTO 0) := (OTHERS => '0');
2693
BEGIN
2694
        tmp(0) := l;
2695
        RETURN tmp;
2696
END to_stdlogicvector;
2697
 
2698
------------------------------------------------------------------
2699
FUNCTION to_stdlogicvector(l : boolean; size : natural) RETURN std_logic_vector IS
2700
 
2701
VARIABLE tmp : std_logic_vector(size-1 DOWNTO 0) := (OTHERS => '0');
2702
BEGIN
2703
        tmp(0) := to_stdlogic(l);
2704
        RETURN tmp;
2705
END to_stdlogicvector;
2706
 
2707
------------------------------------------------------------------
2708
FUNCTION to_integer(l : integer) RETURN integer IS
2709
 
2710
BEGIN
2711
        RETURN l;
2712
END to_integer;
2713
 
2714
------------------------------------------------------------------
2715
FUNCTION to_integer(l : std_logic) RETURN integer IS
2716
 
2717
BEGIN
2718
        IF ( l = '0') THEN
2719
                RETURN 0;
2720
        ELSIF (l = '1') THEN
2721
                RETURN 1;
2722
        ELSE
2723
                ASSERT FALSE REPORT("Std_logic values other than '0' and '1' cannot be converted to integer type")
2724
                SEVERITY WARNING;
2725
                RETURN 0;
2726
        END IF;
2727
END to_integer;
2728
 
2729
------------------------------------------------------------------
2730
FUNCTION to_integer(l : boolean) RETURN integer IS
2731
 
2732
BEGIN
2733
        IF ( l = TRUE) THEN
2734
                RETURN 0;
2735
        ELSE
2736
                RETURN 1;
2737
        END IF;
2738
END to_integer;
2739
 
2740
------------------------------------------------------------------
2741
FUNCTION to_stdlogic(l : integer) RETURN std_logic IS
2742
 
2743
VARIABLE ret_val : std_logic := '0';
2744
BEGIN
2745
        IF l = 0 THEN
2746
                ret_val := '0';
2747
        ELSIF l = 1 THEN
2748
                ret_val := '1';
2749
        ELSE
2750
                ASSERT FALSE REPORT("Integers other than 0 and 1 cannot be converted to std_logic type")
2751
                SEVERITY WARNING;
2752
        END IF;
2753
        RETURN ret_val;
2754
END to_stdlogic;
2755
 
2756
------------------------------------------------------------------
2757
FUNCTION to_stdlogic(l : Boolean) RETURN std_logic IS
2758
 
2759
VARIABLE ret_val : std_logic := '0';
2760
BEGIN
2761
        IF l = FALSE THEN
2762
                ret_val := '0';
2763
        ELSE
2764
                ret_val := '1';
2765
        END IF;
2766
 
2767
        RETURN ret_val;
2768
END to_stdlogic;
2769
 
2770
------------------------------------------------------------------
2771
FUNCTION to_stdlogic(l : std_logic) RETURN std_logic IS
2772
 
2773
BEGIN
2774
        RETURN l;
2775
END to_stdlogic;
2776
------------------------------------------------------------------
2777
FUNCTION to_stdlogic(l : std_logic_vector) RETURN std_logic IS
2778
 
2779
 
2780
BEGIN
2781
        RETURN l(l'LOW);
2782
END to_stdlogic;
2783
 
2784
------------------------------------------------------------------
2785
 
2786
FUNCTION to_integer(l : std_logic_vector; dir : direction := little_endian) RETURN integer IS
2787
 
2788
BEGIN
2789
        IF dir = little_endian THEN
2790
--              RETURN to_integer(SIGNED(l));
2791
                RETURN to_integer(UNSIGNED(l));
2792
        ELSE
2793
--              RETURN to_integer(SIGNED(l) ROR l'LENGTH);
2794
                RETURN to_integer(UNSIGNED(l) ROR l'LENGTH);
2795
        END IF;
2796
 
2797
END to_integer;
2798
 
2799
------------------------------------------------------------------
2800
 
2801
FUNCTION v2v_to_integer(l : std_logic_vector; dir : direction := little_endian) RETURN integer IS
2802
 
2803
BEGIN
2804
        IF dir = little_endian THEN
2805
--              RETURN to_integer(SIGNED(l));
2806
                RETURN to_integer(UNSIGNED(l));
2807
        ELSE
2808
                --NOTE, since ROR is not available in 87, we will use ROTATE_RIGHT
2809
                RETURN to_integer(ROTATE_RIGHT(UNSIGNED(l) , l'LENGTH));
2810
--              RETURN to_integer(UNSIGNED(l) ROR l'LENGTH);
2811
        END IF;
2812
 
2813
END v2v_to_integer;
2814
 
2815
------------------------------------------------------------------
2816
FUNCTION v2v_to_integer(l : integer) RETURN integer IS
2817
 
2818
BEGIN
2819
        RETURN l;
2820
END v2v_to_integer;
2821
 
2822
------------------------------------------------------------------
2823
FUNCTION v2v_to_integer(l : std_logic) RETURN integer IS
2824
 
2825
BEGIN
2826
        IF ( l = '0') THEN
2827
                RETURN 0;
2828
        ELSIF (l = '1') THEN
2829
                RETURN 1;
2830
        ELSE
2831
                ASSERT FALSE REPORT("Std_logic values other than '0' and '1' cannot be converted to integer type")
2832
                SEVERITY WARNING;
2833
                RETURN 0;
2834
        END IF;
2835
END v2v_to_integer;
2836
 
2837
------------------------------------------------------------------
2838
FUNCTION v2v_to_integer(l : boolean) RETURN integer IS
2839
 
2840
BEGIN
2841
        IF ( l = TRUE) THEN
2842
                RETURN 0;
2843
        ELSE
2844
                RETURN 1;
2845
        END IF;
2846
END v2v_to_integer;
2847
 
2848
------------------------------------------------------------------
2849
--pragma synthesis_off
2850
------------------------------------------------------------------
2851
FUNCTION to_real(l : integer) RETURN real IS
2852
 
2853
BEGIN
2854
        RETURN REAL(l);
2855
END to_real;
2856
 
2857
------------------------------------------------------------------
2858
FUNCTION to_real(l : real) RETURN real IS
2859
 
2860
BEGIN
2861
        RETURN l;
2862
END to_real;
2863
--pragma synthesis_on
2864
 
2865
------------------------------------------------------------------
2866
FUNCTION to_boolean(l : std_logic) RETURN boolean IS
2867
 
2868
BEGIN
2869
        IF ( l = '0' ) THEN
2870
                RETURN FALSE;
2871
        ELSIF (l = '1') THEN
2872
                RETURN TRUE;
2873
        ELSE
2874
                ASSERT FALSE REPORT("Std_logic values other than '0' and '1' cannot be converted to boolean type")
2875
                SEVERITY WARNING;
2876
                RETURN FALSE;
2877
        END IF;
2878
 
2879
END to_boolean;
2880
------------------------------------------------------------------
2881
FUNCTION to_boolean(l : std_logic_vector) RETURN boolean IS
2882
 
2883
VARIABLE tmp : std_logic_vector(l'RANGE);
2884
BEGIN
2885
        tmp := (OTHERS=>'1');
2886
        if to_integer(l AND tmp) /= 0 THEN
2887
                RETURN TRUE;
2888
        END IF;
2889
        RETURN FALSE;
2890
 
2891
END to_boolean;
2892
 
2893
------------------------------------------------------------------
2894
FUNCTION to_boolean(l : boolean) RETURN boolean IS
2895
 
2896
BEGIN
2897
        IF ( l) THEN
2898
                RETURN TRUE;
2899
        END IF;
2900
        RETURN FALSE;
2901
 
2902
END to_boolean;
2903
 
2904
------------------------------------------------------------------
2905
FUNCTION to_boolean(l : integer) RETURN boolean IS
2906
 
2907
BEGIN
2908
        IF ( l = 0 ) THEN
2909
                RETURN FALSE;
2910
        ELSE
2911
                RETURN TRUE;
2912
        END IF;
2913
 
2914
END to_boolean;
2915
 
2916
------------------------------------------------------------------
2917
 
2918
    FUNCTION "sll"  ( l : std_logic_vector; r : integer) RETURN std_logic_vector IS
2919
         VARIABLE v : std_logic_vector(l'RANGE) := (others=>'0');
2920
    BEGIN
2921
        IF r=0 THEN
2922
                RETURN l;
2923
        ELSIF r<0 THEN
2924
                RETURN "srl"(l,-r);
2925
        ELSIF r<l'LENGTH THEN
2926
                IF l'LEFT<l'RIGHT THEN
2927
                        FOR i IN l'LEFT TO (l'RIGHT-r) LOOP
2928
                          v(i) := l(i+r);
2929
                        END LOOP;
2930
                ELSE
2931
                        FOR i IN l'LEFT DOWNTO (l'RIGHT+r) LOOP
2932
                          v(i) := l(i-r);
2933
                        END LOOP;
2934
                END IF;
2935
        END IF;
2936
        RETURN v;
2937
    END;
2938
 
2939
    FUNCTION "sll"  ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector IS
2940
         VARIABLE v : std_ulogic_vector(l'RANGE) := (others=>'0');
2941
    BEGIN
2942
        IF r=0 THEN
2943
                RETURN l;
2944
        ELSIF r<0 THEN
2945
                RETURN "srl"(l,-r);
2946
        ELSIF r<l'LENGTH THEN
2947
                IF l'LEFT<l'RIGHT THEN
2948
                        FOR i IN l'LEFT TO (l'RIGHT-r) LOOP
2949
                          v(i) := l(i+r);
2950
                        END LOOP;
2951
                ELSE
2952
                        FOR i IN l'LEFT DOWNTO (l'RIGHT+r) LOOP
2953
                          v(i) := l(i-r);
2954
                        END LOOP;
2955
                END IF;
2956
        END IF;
2957
        RETURN v;
2958
    END;
2959
 
2960
    FUNCTION "srl"  ( l : std_logic_vector; r : integer) RETURN std_logic_vector IS
2961
         VARIABLE v : std_logic_vector(l'RANGE) := (others=>'0');
2962
    BEGIN
2963
        IF r=0 THEN
2964
                RETURN l;
2965
        ELSIF r<0 THEN
2966
                RETURN "sll"(l,-r);
2967
        ELSIF r<l'LENGTH THEN
2968
                IF l'LEFT<l'RIGHT THEN
2969
                        FOR i IN l'LEFT TO (l'RIGHT-r) LOOP
2970
                           v(i+r) := l(i);
2971
                        END LOOP;
2972
                ELSE
2973
                        FOR i IN l'LEFT DOWNTO (l'RIGHT+r) LOOP
2974
                           v(i-r) := l(i);
2975
                        END LOOP;
2976
                END IF;
2977
        END IF;
2978
        RETURN v;
2979
    END;
2980
 
2981
    FUNCTION "srl"  ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector IS
2982
         VARIABLE v : std_ulogic_vector(l'RANGE) := (others=>'0');
2983
    BEGIN
2984
        IF r=0 THEN
2985
                RETURN l;
2986
        ELSIF r<0 THEN
2987
                RETURN "sll"(l,-r);
2988
        ELSIF r<l'LENGTH THEN
2989
                IF l'LEFT<l'RIGHT THEN
2990
                        FOR i IN l'LEFT TO (l'RIGHT-r) LOOP
2991
                           v(i+r) := l(i);
2992
                        END LOOP;
2993
                ELSE
2994
                        FOR i IN l'LEFT DOWNTO (l'RIGHT+r) LOOP
2995
                           v(i-r) := l(i);
2996
                        END LOOP;
2997
                END IF;
2998
        END IF;
2999
        RETURN v;
3000
    END;
3001
 
3002
    FUNCTION "sla"  ( l : std_logic_vector; r : integer) RETURN std_logic_vector IS
3003
         VARIABLE v : std_logic_vector(l'RANGE) := (others=>l(l'RIGHT));
3004
    BEGIN
3005
        IF r=0 THEN
3006
                RETURN l;
3007
        ELSIF r<0 THEN
3008
                RETURN "sra"(l,-r);
3009
        ELSIF r<l'LENGTH THEN
3010
                IF l'LEFT<l'RIGHT THEN
3011
                        FOR i IN l'LEFT TO (l'RIGHT-r) LOOP
3012
                          v(i) := l(i+r);
3013
                        END LOOP;
3014
                ELSE
3015
                        FOR i IN l'LEFT DOWNTO (l'RIGHT+r) LOOP
3016
                          v(i) := l(i-r);
3017
                        END LOOP;
3018
                END IF;
3019
        END IF;
3020
        RETURN v;
3021
    END;
3022
 
3023
    FUNCTION "sla"  ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector IS
3024
         VARIABLE v : std_ulogic_vector(l'RANGE) := (others=>l(l'RIGHT));
3025
    BEGIN
3026
        IF r=0 THEN
3027
                RETURN l;
3028
        ELSIF r<0 THEN
3029
                RETURN "sra"(l,-r);
3030
        ELSIF r<l'LENGTH THEN
3031
                IF l'LEFT<l'RIGHT THEN
3032
                        FOR i IN l'LEFT TO (l'RIGHT-r) LOOP
3033
                          v(i) := l(i+r);
3034
                        END LOOP;
3035
                ELSE
3036
                        FOR i IN l'LEFT DOWNTO (l'RIGHT+r) LOOP
3037
                          v(i) := l(i-r);
3038
                        END LOOP;
3039
                END IF;
3040
        END IF;
3041
        RETURN v;
3042
    END;
3043
 
3044
    FUNCTION "sra"  ( l : std_logic_vector; r : integer) RETURN std_logic_vector IS
3045
         VARIABLE v : std_logic_vector(l'RANGE) := (others=>l(l'RIGHT));
3046
    BEGIN
3047
        IF r=0 THEN
3048
                RETURN l;
3049
        ELSIF r<0 THEN
3050
                RETURN "sla"(l,-r);
3051
        ELSIF r<l'LENGTH THEN
3052
                IF l'LEFT<l'RIGHT THEN
3053
                        FOR i IN l'LEFT TO (l'RIGHT-r) LOOP
3054
                           v(i+r) := l(i);
3055
                        END LOOP;
3056
                ELSE
3057
                        FOR i IN l'LEFT DOWNTO (l'RIGHT+r) LOOP
3058
                           v(i-r) := l(i);
3059
                        END LOOP;
3060
                END IF;
3061
        END IF;
3062
        RETURN v;
3063
    END;
3064
 
3065
    FUNCTION "sra"  ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector IS
3066
         VARIABLE v : std_ulogic_vector(l'RANGE) := (others=>l(l'RIGHT));
3067
    BEGIN
3068
        IF r=0 THEN
3069
                RETURN l;
3070
        ELSIF r<0 THEN
3071
                RETURN "sla"(l,-r);
3072
        ELSIF r<l'LENGTH THEN
3073
                IF l'LEFT<l'RIGHT THEN
3074
                        FOR i IN l'LEFT TO (l'RIGHT-r) LOOP
3075
                           v(i+r) := l(i);
3076
                        END LOOP;
3077
                ELSE
3078
                        FOR i IN l'LEFT DOWNTO (l'RIGHT+r) LOOP
3079
                           v(i-r) := l(i);
3080
                        END LOOP;
3081
                END IF;
3082
        END IF;
3083
        RETURN v;
3084
    END;
3085
 
3086
    FUNCTION "rol"  ( l : std_logic_vector; r : integer) RETURN std_logic_vector IS
3087
         VARIABLE v : std_logic_vector(0 TO l'LENGTH*2-1);
3088
         VARIABLE v1 : std_logic_vector(l'RANGE);
3089
    BEGIN
3090
        IF r=0 THEN
3091
                RETURN l;
3092
        ELSIF r<0 THEN
3093
                RETURN "ror"(l,-r);
3094
        ELSE
3095
                v(0 TO l'LENGTH-1) := l;
3096
                v(l'LENGTH TO v'LENGTH-1) := l;
3097
                v1 := v(r TO r+l'LENGTH-1);
3098
                RETURN v1;
3099
        END IF;
3100
    END;
3101
            FUNCTION "rol"  ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector IS
3102
         VARIABLE v : std_ulogic_vector(0 TO l'LENGTH*2-1);
3103
         VARIABLE v1 : std_ulogic_vector(l'RANGE);
3104
    BEGIN
3105
        IF r=0 THEN
3106
                RETURN l;
3107
        ELSIF r<0 THEN
3108
                RETURN "ror"(l,-r);
3109
        ELSE
3110
                v(0 TO l'LENGTH-1) := l;
3111
                v(l'LENGTH TO v'LENGTH-1) := l;
3112
                v1 := v(r TO r+l'LENGTH-1);
3113
                RETURN v1;
3114
        END IF;
3115
    END;
3116
 
3117
    FUNCTION "ror"  ( l : std_logic_vector; r : integer) RETURN std_logic_vector IS
3118
         VARIABLE v : std_logic_vector(0 TO l'LENGTH*2-1);
3119
         VARIABLE v1 : std_logic_vector(l'RANGE);
3120
    BEGIN
3121
        IF r=0 THEN
3122
                RETURN l;
3123
        ELSIF r<0 THEN
3124
                RETURN "rol"(l,-r);
3125
        ELSE
3126
                v(0 TO l'LENGTH-1) := l;
3127
                v(l'LENGTH TO v'LENGTH-1) := l;
3128
                v1 := v(l'LENGTH-r TO v'LENGTH-r-1);
3129
                RETURN v1;
3130
        END IF;
3131
    END;
3132
    FUNCTION "ror"  ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector IS
3133
         VARIABLE v : std_ulogic_vector(0 TO l'LENGTH*2-1);
3134
         VARIABLE v1 : std_ulogic_vector(l'RANGE);
3135
    BEGIN
3136
        IF r=0 THEN
3137
                RETURN l;
3138
        ELSIF r<0 THEN
3139
                RETURN "rol"(l,-r);
3140
        ELSE
3141
                v(0 TO l'LENGTH-1) := l;
3142
                v(l'LENGTH TO v'LENGTH-1) := l;
3143
                v1 := v(l'LENGTH-r TO v'LENGTH-r-1);
3144
                RETURN v1;
3145
        END IF;
3146
    END;
3147
 
3148
FUNCTION to_stdlogicvector(hex : STRING) RETURN std_logic_vector IS
3149
        VARIABLE result : std_logic_vector(4 * hex'LENGTH DOWNTO 1);
3150
BEGIN
3151
-- Note: The hex parameter can have a range with hex'LOW > 1.
3152
-- For these cases, variable index i in assignments in the FOR loop is normalized
3153
-- to 1 by subtracting hex'LOW  ** sas 2/13/96 ** 
3154
    FOR i in hex'RANGE LOOP
3155
        CASE hex(i) IS
3156
        WHEN '0' =>
3157
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"0";
3158
        WHEN '1' =>
3159
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"1";
3160
        WHEN '2' =>
3161
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"2";
3162
        WHEN '3' =>
3163
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"3";
3164
        WHEN '4' =>
3165
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"4";
3166
        WHEN '5' =>
3167
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"5";
3168
        WHEN '6' =>
3169
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"6";
3170
        WHEN '7' =>
3171
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"7";
3172
        WHEN '8' =>
3173
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"8";
3174
        WHEN '9' =>
3175
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"9";
3176
        WHEN 'A' | 'a' =>
3177
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"A";
3178
        WHEN 'B' | 'b' =>
3179
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"B";
3180
        WHEN 'C' | 'c' =>
3181
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"C";
3182
        WHEN 'D' | 'd' =>
3183
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"D";
3184
        WHEN 'E' | 'e' =>
3185
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"E";
3186
        WHEN 'F' | 'f' =>
3187
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := x"F";
3188
        WHEN 'X' | 'x' =>
3189
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := "XXXX";
3190
        WHEN 'Z' | 'z' =>
3191
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := "ZZZZ";
3192
        WHEN OTHERS =>
3193
        result(4*(hex'LENGTH - (i-hex'LOW)) DOWNTO 4*(hex'LENGTH - (i-hex'LOW)) -3) := "XXXX";
3194
        END CASE;
3195
    END LOOP;
3196
    RETURN result;
3197
END to_stdlogicvector;
3198
 
3199
end FUNCTIONS;
3200
 
3201
 

powered by: WebSVN 2.1.0

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