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

Subversion Repositories pcie_sg_dma

[/] [pcie_sg_dma/] [branches/] [Virtex6/] [ML605_ISE12.3/] [MyUserLogic/] [top_level_1_PCIe_UserLogic_00_USER_LOGIC/] [sysgen/] [perl_results.vhd] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 barabba
 
2
-------------------------------------------------------------------
3
-- System Generator version 12.3 VHDL source file.
4
--
5
-- Copyright(C) 2010 by Xilinx, Inc.  All rights reserved.  This
6
-- text/file contains proprietary, confidential information of Xilinx,
7
-- Inc., is distributed under license from Xilinx, Inc., and may be used,
8
-- copied and/or disclosed only pursuant to the terms of a valid license
9
-- agreement with Xilinx, Inc.  Xilinx hereby grants you a license to use
10
-- this text/file solely for design, simulation, implementation and
11
-- creation of design files limited to Xilinx devices or technologies.
12
-- Use with non-Xilinx devices or technologies is expressly prohibited
13
-- and immediately terminates your license unless covered by a separate
14
-- agreement.
15
--
16
-- Xilinx is providing this design, code, or information "as is" solely
17
-- for use in developing programs and solutions for Xilinx devices.  By
18
-- providing this design, code, or information as one possible
19
-- implementation of this feature, application or standard, Xilinx is
20
-- making no representation that this implementation is free from any
21
-- claims of infringement.  You are responsible for obtaining any rights
22
-- you may require for your implementation.  Xilinx expressly disclaims
23
-- any warranty whatsoever with respect to the adequacy of the
24
-- implementation, including but not limited to warranties of
25
-- merchantability or fitness for a particular purpose.
26
--
27
-- Xilinx products are not intended for use in life support appliances,
28
-- devices, or systems.  Use in such applications is expressly prohibited.
29
--
30
-- Any modifications that are made to the source code are done at the user's
31
-- sole risk and will be unsupported.
32
--
33
-- This copyright and support notice must be retained as part of this
34
-- text at all times.  (c) Copyright 1995-2010 Xilinx, Inc.  All rights
35
-- reserved.
36
-------------------------------------------------------------------
37
library IEEE;
38
use IEEE.std_logic_1164.all;
39
use IEEE.numeric_std.all;
40
package conv_pkg is
41
    constant simulating : boolean := false
42
      -- synopsys translate_off
43
        or true
44
      -- synopsys translate_on
45
    ;
46
    constant xlUnsigned : integer := 1;
47
    constant xlSigned : integer := 2;
48
    constant xlWrap : integer := 1;
49
    constant xlSaturate : integer := 2;
50
    constant xlTruncate : integer := 1;
51
    constant xlRound : integer := 2;
52
    constant xlRoundBanker : integer := 3;
53
    constant xlAddMode : integer := 1;
54
    constant xlSubMode : integer := 2;
55
    attribute black_box : boolean;
56
    attribute syn_black_box : boolean;
57
    attribute fpga_dont_touch: string;
58
    attribute box_type :  string;
59
    attribute keep : string;
60
    attribute syn_keep : boolean;
61
    function std_logic_vector_to_unsigned(inp : std_logic_vector) return unsigned;
62
    function unsigned_to_std_logic_vector(inp : unsigned) return std_logic_vector;
63
    function std_logic_vector_to_signed(inp : std_logic_vector) return signed;
64
    function signed_to_std_logic_vector(inp : signed) return std_logic_vector;
65
    function unsigned_to_signed(inp : unsigned) return signed;
66
    function signed_to_unsigned(inp : signed) return unsigned;
67
    function pos(inp : std_logic_vector; arith : INTEGER) return boolean;
68
    function all_same(inp: std_logic_vector) return boolean;
69
    function all_zeros(inp: std_logic_vector) return boolean;
70
    function is_point_five(inp: std_logic_vector) return boolean;
71
    function all_ones(inp: std_logic_vector) return boolean;
72
    function convert_type (inp : std_logic_vector; old_width, old_bin_pt,
73
                           old_arith, new_width, new_bin_pt, new_arith,
74
                           quantization, overflow : INTEGER)
75
        return std_logic_vector;
76
    function cast (inp : std_logic_vector; old_bin_pt,
77
                   new_width, new_bin_pt, new_arith : INTEGER)
78
        return std_logic_vector;
79
    function vec_slice (inp : std_logic_vector; upper, lower : INTEGER)
80
        return std_logic_vector;
81
    function s2u_slice (inp : signed; upper, lower : INTEGER)
82
        return unsigned;
83
    function u2u_slice (inp : unsigned; upper, lower : INTEGER)
84
        return unsigned;
85
    function s2s_cast (inp : signed; old_bin_pt,
86
                   new_width, new_bin_pt : INTEGER)
87
        return signed;
88
    function u2s_cast (inp : unsigned; old_bin_pt,
89
                   new_width, new_bin_pt : INTEGER)
90
        return signed;
91
    function s2u_cast (inp : signed; old_bin_pt,
92
                   new_width, new_bin_pt : INTEGER)
93
        return unsigned;
94
    function u2u_cast (inp : unsigned; old_bin_pt,
95
                   new_width, new_bin_pt : INTEGER)
96
        return unsigned;
97
    function u2v_cast (inp : unsigned; old_bin_pt,
98
                   new_width, new_bin_pt : INTEGER)
99
        return std_logic_vector;
100
    function s2v_cast (inp : signed; old_bin_pt,
101
                   new_width, new_bin_pt : INTEGER)
102
        return std_logic_vector;
103
    function trunc (inp : std_logic_vector; old_width, old_bin_pt, old_arith,
104
                    new_width, new_bin_pt, new_arith : INTEGER)
105
        return std_logic_vector;
106
    function round_towards_inf (inp : std_logic_vector; old_width, old_bin_pt,
107
                                old_arith, new_width, new_bin_pt,
108
                                new_arith : INTEGER) return std_logic_vector;
109
    function round_towards_even (inp : std_logic_vector; old_width, old_bin_pt,
110
                                old_arith, new_width, new_bin_pt,
111
                                new_arith : INTEGER) return std_logic_vector;
112
    function max_signed(width : INTEGER) return std_logic_vector;
113
    function min_signed(width : INTEGER) return std_logic_vector;
114
    function saturation_arith(inp:  std_logic_vector;  old_width, old_bin_pt,
115
                              old_arith, new_width, new_bin_pt, new_arith
116
                              : INTEGER) return std_logic_vector;
117
    function wrap_arith(inp:  std_logic_vector;  old_width, old_bin_pt,
118
                        old_arith, new_width, new_bin_pt, new_arith : INTEGER)
119
                        return std_logic_vector;
120
    function fractional_bits(a_bin_pt, b_bin_pt: INTEGER) return INTEGER;
121
    function integer_bits(a_width, a_bin_pt, b_width, b_bin_pt: INTEGER)
122
        return INTEGER;
123
    function sign_ext(inp : std_logic_vector; new_width : INTEGER)
124
        return std_logic_vector;
125
    function zero_ext(inp : std_logic_vector; new_width : INTEGER)
126
        return std_logic_vector;
127
    function zero_ext(inp : std_logic; new_width : INTEGER)
128
        return std_logic_vector;
129
    function extend_MSB(inp : std_logic_vector; new_width, arith : INTEGER)
130
        return std_logic_vector;
131
    function align_input(inp : std_logic_vector; old_width, delta, new_arith,
132
                          new_width: INTEGER)
133
        return std_logic_vector;
134
    function pad_LSB(inp : std_logic_vector; new_width: integer)
135
        return std_logic_vector;
136
    function pad_LSB(inp : std_logic_vector; new_width, arith : integer)
137
        return std_logic_vector;
138
    function max(L, R: INTEGER) return INTEGER;
139
    function min(L, R: INTEGER) return INTEGER;
140
    function "="(left,right: STRING) return boolean;
141
    function boolean_to_signed (inp : boolean; width: integer)
142
        return signed;
143
    function boolean_to_unsigned (inp : boolean; width: integer)
144
        return unsigned;
145
    function boolean_to_vector (inp : boolean)
146
        return std_logic_vector;
147
    function std_logic_to_vector (inp : std_logic)
148
        return std_logic_vector;
149
    function integer_to_std_logic_vector (inp : integer;  width, arith : integer)
150
        return std_logic_vector;
151
    function std_logic_vector_to_integer (inp : std_logic_vector;  arith : integer)
152
        return integer;
153
    function std_logic_to_integer(constant inp : std_logic := '0')
154
        return integer;
155
    function bin_string_element_to_std_logic_vector (inp : string;  width, index : integer)
156
        return std_logic_vector;
157
    function bin_string_to_std_logic_vector (inp : string)
158
        return std_logic_vector;
159
    function hex_string_to_std_logic_vector (inp : string; width : integer)
160
        return std_logic_vector;
161
    function makeZeroBinStr (width : integer) return STRING;
162
    function and_reduce(inp: std_logic_vector) return std_logic;
163
    -- synopsys translate_off
164
    function is_binary_string_invalid (inp : string)
165
        return boolean;
166
    function is_binary_string_undefined (inp : string)
167
        return boolean;
168
    function is_XorU(inp : std_logic_vector)
169
        return boolean;
170
    function to_real(inp : std_logic_vector; bin_pt : integer; arith : integer)
171
        return real;
172
    function std_logic_to_real(inp : std_logic; bin_pt : integer; arith : integer)
173
        return real;
174
    function real_to_std_logic_vector (inp : real;  width, bin_pt, arith : integer)
175
        return std_logic_vector;
176
    function real_string_to_std_logic_vector (inp : string;  width, bin_pt, arith : integer)
177
        return std_logic_vector;
178
    constant display_precision : integer := 20;
179
    function real_to_string (inp : real) return string;
180
    function valid_bin_string(inp : string) return boolean;
181
    function std_logic_vector_to_bin_string(inp : std_logic_vector) return string;
182
    function std_logic_to_bin_string(inp : std_logic) return string;
183
    function std_logic_vector_to_bin_string_w_point(inp : std_logic_vector; bin_pt : integer)
184
        return string;
185
    function real_to_bin_string(inp : real;  width, bin_pt, arith : integer)
186
        return string;
187
    type stdlogic_to_char_t is array(std_logic) of character;
188
    constant to_char : stdlogic_to_char_t := (
189
        'U' => 'U',
190
        'X' => 'X',
191
        '0' => '0',
192
        '1' => '1',
193
        'Z' => 'Z',
194
        'W' => 'W',
195
        'L' => 'L',
196
        'H' => 'H',
197
        '-' => '-');
198
    -- synopsys translate_on
199
end conv_pkg;
200
package body conv_pkg is
201
    function std_logic_vector_to_unsigned(inp : std_logic_vector)
202
        return unsigned
203
    is
204
    begin
205
        return unsigned (inp);
206
    end;
207
    function unsigned_to_std_logic_vector(inp : unsigned)
208
        return std_logic_vector
209
    is
210
    begin
211
        return std_logic_vector(inp);
212
    end;
213
    function std_logic_vector_to_signed(inp : std_logic_vector)
214
        return signed
215
    is
216
    begin
217
        return  signed (inp);
218
    end;
219
    function signed_to_std_logic_vector(inp : signed)
220
        return std_logic_vector
221
    is
222
    begin
223
        return std_logic_vector(inp);
224
    end;
225
    function unsigned_to_signed (inp : unsigned)
226
        return signed
227
    is
228
    begin
229
        return signed(std_logic_vector(inp));
230
    end;
231
    function signed_to_unsigned (inp : signed)
232
        return unsigned
233
    is
234
    begin
235
        return unsigned(std_logic_vector(inp));
236
    end;
237
    function pos(inp : std_logic_vector; arith : INTEGER)
238
        return boolean
239
    is
240
        constant width : integer := inp'length;
241
        variable vec : std_logic_vector(width-1 downto 0);
242
    begin
243
        vec := inp;
244
        if arith = xlUnsigned then
245
            return true;
246
        else
247
            if vec(width-1) = '0' then
248
                return true;
249
            else
250
                return false;
251
            end if;
252
        end if;
253
        return true;
254
    end;
255
    function max_signed(width : INTEGER)
256
        return std_logic_vector
257
    is
258
        variable ones : std_logic_vector(width-2 downto 0);
259
        variable result : std_logic_vector(width-1 downto 0);
260
    begin
261
        ones := (others => '1');
262
        result(width-1) := '0';
263
        result(width-2 downto 0) := ones;
264
        return result;
265
    end;
266
    function min_signed(width : INTEGER)
267
        return std_logic_vector
268
    is
269
        variable zeros : std_logic_vector(width-2 downto 0);
270
        variable result : std_logic_vector(width-1 downto 0);
271
    begin
272
        zeros := (others => '0');
273
        result(width-1) := '1';
274
        result(width-2 downto 0) := zeros;
275
        return result;
276
    end;
277
    function and_reduce(inp: std_logic_vector) return std_logic
278
    is
279
        variable result: std_logic;
280
        constant width : integer := inp'length;
281
        variable vec : std_logic_vector(width-1 downto 0);
282
    begin
283
        vec := inp;
284
        result := vec(0);
285
        if width > 1 then
286
            for i in 1 to width-1 loop
287
                result := result and vec(i);
288
            end loop;
289
        end if;
290
        return result;
291
    end;
292
    function all_same(inp: std_logic_vector) return boolean
293
    is
294
        variable result: boolean;
295
        constant width : integer := inp'length;
296
        variable vec : std_logic_vector(width-1 downto 0);
297
    begin
298
        vec := inp;
299
        result := true;
300
        if width > 0 then
301
            for i in 1 to width-1 loop
302
                if vec(i) /= vec(0) then
303
                    result := false;
304
                end if;
305
            end loop;
306
        end if;
307
        return result;
308
    end;
309
    function all_zeros(inp: std_logic_vector)
310
        return boolean
311
    is
312
        constant width : integer := inp'length;
313
        variable vec : std_logic_vector(width-1 downto 0);
314
        variable zero : std_logic_vector(width-1 downto 0);
315
        variable result : boolean;
316
    begin
317
        zero := (others => '0');
318
        vec := inp;
319
        -- synopsys translate_off
320
        if (is_XorU(vec)) then
321
            return false;
322
        end if;
323
         -- synopsys translate_on
324
        if (std_logic_vector_to_unsigned(vec) = std_logic_vector_to_unsigned(zero)) then
325
            result := true;
326
        else
327
            result := false;
328
        end if;
329
        return result;
330
    end;
331
    function is_point_five(inp: std_logic_vector)
332
        return boolean
333
    is
334
        constant width : integer := inp'length;
335
        variable vec : std_logic_vector(width-1 downto 0);
336
        variable result : boolean;
337
    begin
338
        vec := inp;
339
        -- synopsys translate_off
340
        if (is_XorU(vec)) then
341
            return false;
342
        end if;
343
         -- synopsys translate_on
344
        if (width > 1) then
345
           if ((vec(width-1) = '1') and (all_zeros(vec(width-2 downto 0)) = true)) then
346
               result := true;
347
           else
348
               result := false;
349
           end if;
350
        else
351
           if (vec(width-1) = '1') then
352
               result := true;
353
           else
354
               result := false;
355
           end if;
356
        end if;
357
        return result;
358
    end;
359
    function all_ones(inp: std_logic_vector)
360
        return boolean
361
    is
362
        constant width : integer := inp'length;
363
        variable vec : std_logic_vector(width-1 downto 0);
364
        variable one : std_logic_vector(width-1 downto 0);
365
        variable result : boolean;
366
    begin
367
        one := (others => '1');
368
        vec := inp;
369
        -- synopsys translate_off
370
        if (is_XorU(vec)) then
371
            return false;
372
        end if;
373
         -- synopsys translate_on
374
        if (std_logic_vector_to_unsigned(vec) = std_logic_vector_to_unsigned(one)) then
375
            result := true;
376
        else
377
            result := false;
378
        end if;
379
        return result;
380
    end;
381
    function full_precision_num_width(quantization, overflow, old_width,
382
                                      old_bin_pt, old_arith,
383
                                      new_width, new_bin_pt, new_arith : INTEGER)
384
        return integer
385
    is
386
        variable result : integer;
387
    begin
388
        result := old_width + 2;
389
        return result;
390
    end;
391
    function quantized_num_width(quantization, overflow, old_width, old_bin_pt,
392
                                 old_arith, new_width, new_bin_pt, new_arith
393
                                 : INTEGER)
394
        return integer
395
    is
396
        variable right_of_dp, left_of_dp, result : integer;
397
    begin
398
        right_of_dp := max(new_bin_pt, old_bin_pt);
399
        left_of_dp := max((new_width - new_bin_pt), (old_width - old_bin_pt));
400
        result := (old_width + 2) + (new_bin_pt - old_bin_pt);
401
        return result;
402
    end;
403
    function convert_type (inp : std_logic_vector; old_width, old_bin_pt,
404
                           old_arith, new_width, new_bin_pt, new_arith,
405
                           quantization, overflow : INTEGER)
406
        return std_logic_vector
407
    is
408
        constant fp_width : integer :=
409
            full_precision_num_width(quantization, overflow, old_width,
410
                                     old_bin_pt, old_arith, new_width,
411
                                     new_bin_pt, new_arith);
412
        constant fp_bin_pt : integer := old_bin_pt;
413
        constant fp_arith : integer := old_arith;
414
        variable full_precision_result : std_logic_vector(fp_width-1 downto 0);
415
        constant q_width : integer :=
416
            quantized_num_width(quantization, overflow, old_width, old_bin_pt,
417
                                old_arith, new_width, new_bin_pt, new_arith);
418
        constant q_bin_pt : integer := new_bin_pt;
419
        constant q_arith : integer := old_arith;
420
        variable quantized_result : std_logic_vector(q_width-1 downto 0);
421
        variable result : std_logic_vector(new_width-1 downto 0);
422
    begin
423
        result := (others => '0');
424
        full_precision_result := cast(inp, old_bin_pt, fp_width, fp_bin_pt,
425
                                      fp_arith);
426
        if (quantization = xlRound) then
427
            quantized_result := round_towards_inf(full_precision_result,
428
                                                  fp_width, fp_bin_pt,
429
                                                  fp_arith, q_width, q_bin_pt,
430
                                                  q_arith);
431
        elsif (quantization = xlRoundBanker) then
432
            quantized_result := round_towards_even(full_precision_result,
433
                                                  fp_width, fp_bin_pt,
434
                                                  fp_arith, q_width, q_bin_pt,
435
                                                  q_arith);
436
        else
437
            quantized_result := trunc(full_precision_result, fp_width, fp_bin_pt,
438
                                      fp_arith, q_width, q_bin_pt, q_arith);
439
        end if;
440
        if (overflow = xlSaturate) then
441
            result := saturation_arith(quantized_result, q_width, q_bin_pt,
442
                                       q_arith, new_width, new_bin_pt, new_arith);
443
        else
444
             result := wrap_arith(quantized_result, q_width, q_bin_pt, q_arith,
445
                                  new_width, new_bin_pt, new_arith);
446
        end if;
447
        return result;
448
    end;
449
    function cast (inp : std_logic_vector; old_bin_pt, new_width,
450
                   new_bin_pt, new_arith : INTEGER)
451
        return std_logic_vector
452
    is
453
        constant old_width : integer := inp'length;
454
        constant left_of_dp : integer := (new_width - new_bin_pt)
455
                                         - (old_width - old_bin_pt);
456
        constant right_of_dp : integer := (new_bin_pt - old_bin_pt);
457
        variable vec : std_logic_vector(old_width-1 downto 0);
458
        variable result : std_logic_vector(new_width-1 downto 0);
459
        variable j   : integer;
460
    begin
461
        vec := inp;
462
        for i in new_width-1 downto 0 loop
463
            j := i - right_of_dp;
464
            if ( j > old_width-1) then
465
                if (new_arith = xlUnsigned) then
466
                    result(i) := '0';
467
                else
468
                    result(i) := vec(old_width-1);
469
                end if;
470
            elsif ( j >= 0) then
471
                result(i) := vec(j);
472
            else
473
                result(i) := '0';
474
            end if;
475
        end loop;
476
        return result;
477
    end;
478
    function vec_slice (inp : std_logic_vector; upper, lower : INTEGER)
479
      return std_logic_vector
480
    is
481
    begin
482
        return inp(upper downto lower);
483
    end;
484
    function s2u_slice (inp : signed; upper, lower : INTEGER)
485
      return unsigned
486
    is
487
    begin
488
        return unsigned(vec_slice(std_logic_vector(inp), upper, lower));
489
    end;
490
    function u2u_slice (inp : unsigned; upper, lower : INTEGER)
491
      return unsigned
492
    is
493
    begin
494
        return unsigned(vec_slice(std_logic_vector(inp), upper, lower));
495
    end;
496
    function s2s_cast (inp : signed; old_bin_pt, new_width, new_bin_pt : INTEGER)
497
        return signed
498
    is
499
    begin
500
        return signed(cast(std_logic_vector(inp), old_bin_pt, new_width, new_bin_pt, xlSigned));
501
    end;
502
    function s2u_cast (inp : signed; old_bin_pt, new_width,
503
                   new_bin_pt : INTEGER)
504
        return unsigned
505
    is
506
    begin
507
        return unsigned(cast(std_logic_vector(inp), old_bin_pt, new_width, new_bin_pt, xlSigned));
508
    end;
509
    function u2s_cast (inp : unsigned; old_bin_pt, new_width,
510
                   new_bin_pt : INTEGER)
511
        return signed
512
    is
513
    begin
514
        return signed(cast(std_logic_vector(inp), old_bin_pt, new_width, new_bin_pt, xlUnsigned));
515
    end;
516
    function u2u_cast (inp : unsigned; old_bin_pt, new_width,
517
                   new_bin_pt : INTEGER)
518
        return unsigned
519
    is
520
    begin
521
        return unsigned(cast(std_logic_vector(inp), old_bin_pt, new_width, new_bin_pt, xlUnsigned));
522
    end;
523
    function u2v_cast (inp : unsigned; old_bin_pt, new_width,
524
                   new_bin_pt : INTEGER)
525
        return std_logic_vector
526
    is
527
    begin
528
        return cast(std_logic_vector(inp), old_bin_pt, new_width, new_bin_pt, xlUnsigned);
529
    end;
530
    function s2v_cast (inp : signed; old_bin_pt, new_width,
531
                   new_bin_pt : INTEGER)
532
        return std_logic_vector
533
    is
534
    begin
535
        return cast(std_logic_vector(inp), old_bin_pt, new_width, new_bin_pt, xlSigned);
536
    end;
537
    function boolean_to_signed (inp : boolean; width : integer)
538
        return signed
539
    is
540
        variable result : signed(width - 1 downto 0);
541
    begin
542
        result := (others => '0');
543
        if inp then
544
          result(0) := '1';
545
        else
546
          result(0) := '0';
547
        end if;
548
        return result;
549
    end;
550
    function boolean_to_unsigned (inp : boolean; width : integer)
551
        return unsigned
552
    is
553
        variable result : unsigned(width - 1 downto 0);
554
    begin
555
        result := (others => '0');
556
        if inp then
557
          result(0) := '1';
558
        else
559
          result(0) := '0';
560
        end if;
561
        return result;
562
    end;
563
    function boolean_to_vector (inp : boolean)
564
        return std_logic_vector
565
    is
566
        variable result : std_logic_vector(1 - 1 downto 0);
567
    begin
568
        result := (others => '0');
569
        if inp then
570
          result(0) := '1';
571
        else
572
          result(0) := '0';
573
        end if;
574
        return result;
575
    end;
576
    function std_logic_to_vector (inp : std_logic)
577
        return std_logic_vector
578
    is
579
        variable result : std_logic_vector(1 - 1 downto 0);
580
    begin
581
        result(0) := inp;
582
        return result;
583
    end;
584
    function trunc (inp : std_logic_vector; old_width, old_bin_pt, old_arith,
585
                                new_width, new_bin_pt, new_arith : INTEGER)
586
        return std_logic_vector
587
    is
588
        constant right_of_dp : integer := (old_bin_pt - new_bin_pt);
589
        variable vec : std_logic_vector(old_width-1 downto 0);
590
        variable result : std_logic_vector(new_width-1 downto 0);
591
    begin
592
        vec := inp;
593
        if right_of_dp >= 0 then
594
            if new_arith = xlUnsigned then
595
                result := zero_ext(vec(old_width-1 downto right_of_dp), new_width);
596
            else
597
                result := sign_ext(vec(old_width-1 downto right_of_dp), new_width);
598
            end if;
599
        else
600
            if new_arith = xlUnsigned then
601
                result := zero_ext(pad_LSB(vec, old_width +
602
                                           abs(right_of_dp)), new_width);
603
            else
604
                result := sign_ext(pad_LSB(vec, old_width +
605
                                           abs(right_of_dp)), new_width);
606
            end if;
607
        end if;
608
        return result;
609
    end;
610
    function round_towards_inf (inp : std_logic_vector; old_width, old_bin_pt,
611
                                old_arith, new_width, new_bin_pt, new_arith
612
                                : INTEGER)
613
        return std_logic_vector
614
    is
615
        constant right_of_dp : integer := (old_bin_pt - new_bin_pt);
616
        constant expected_new_width : integer :=  old_width - right_of_dp  + 1;
617
        variable vec : std_logic_vector(old_width-1 downto 0);
618
        variable one_or_zero : std_logic_vector(new_width-1 downto 0);
619
        variable truncated_val : std_logic_vector(new_width-1 downto 0);
620
        variable result : std_logic_vector(new_width-1 downto 0);
621
    begin
622
        vec := inp;
623
        if right_of_dp >= 0 then
624
            if new_arith = xlUnsigned then
625
                truncated_val := zero_ext(vec(old_width-1 downto right_of_dp),
626
                                          new_width);
627
            else
628
                truncated_val := sign_ext(vec(old_width-1 downto right_of_dp),
629
                                          new_width);
630
            end if;
631
        else
632
            if new_arith = xlUnsigned then
633
                truncated_val := zero_ext(pad_LSB(vec, old_width +
634
                                                  abs(right_of_dp)), new_width);
635
            else
636
                truncated_val := sign_ext(pad_LSB(vec, old_width +
637
                                                  abs(right_of_dp)), new_width);
638
            end if;
639
        end if;
640
        one_or_zero := (others => '0');
641
        if (new_arith = xlSigned) then
642
            if (vec(old_width-1) = '0') then
643
                one_or_zero(0) := '1';
644
            end if;
645
            if (right_of_dp >= 2) and (right_of_dp <= old_width) then
646
                if (all_zeros(vec(right_of_dp-2 downto 0)) = false) then
647
                    one_or_zero(0) := '1';
648
                end if;
649
            end if;
650
            if (right_of_dp >= 1) and (right_of_dp <= old_width) then
651
                if vec(right_of_dp-1) = '0' then
652
                    one_or_zero(0) := '0';
653
                end if;
654
            else
655
                one_or_zero(0) := '0';
656
            end if;
657
        else
658
            if (right_of_dp >= 1) and (right_of_dp <= old_width) then
659
                one_or_zero(0) :=  vec(right_of_dp-1);
660
            end if;
661
        end if;
662
        if new_arith = xlSigned then
663
            result := signed_to_std_logic_vector(std_logic_vector_to_signed(truncated_val) +
664
                                                 std_logic_vector_to_signed(one_or_zero));
665
        else
666
            result := unsigned_to_std_logic_vector(std_logic_vector_to_unsigned(truncated_val) +
667
                                                  std_logic_vector_to_unsigned(one_or_zero));
668
        end if;
669
        return result;
670
    end;
671
    function round_towards_even (inp : std_logic_vector; old_width, old_bin_pt,
672
                                old_arith, new_width, new_bin_pt, new_arith
673
                                : INTEGER)
674
        return std_logic_vector
675
    is
676
        constant right_of_dp : integer := (old_bin_pt - new_bin_pt);
677
        constant expected_new_width : integer :=  old_width - right_of_dp  + 1;
678
        variable vec : std_logic_vector(old_width-1 downto 0);
679
        variable one_or_zero : std_logic_vector(new_width-1 downto 0);
680
        variable truncated_val : std_logic_vector(new_width-1 downto 0);
681
        variable result : std_logic_vector(new_width-1 downto 0);
682
    begin
683
        vec := inp;
684
        if right_of_dp >= 0 then
685
            if new_arith = xlUnsigned then
686
                truncated_val := zero_ext(vec(old_width-1 downto right_of_dp),
687
                                          new_width);
688
            else
689
                truncated_val := sign_ext(vec(old_width-1 downto right_of_dp),
690
                                          new_width);
691
            end if;
692
        else
693
            if new_arith = xlUnsigned then
694
                truncated_val := zero_ext(pad_LSB(vec, old_width +
695
                                                  abs(right_of_dp)), new_width);
696
            else
697
                truncated_val := sign_ext(pad_LSB(vec, old_width +
698
                                                  abs(right_of_dp)), new_width);
699
            end if;
700
        end if;
701
        one_or_zero := (others => '0');
702
        if (right_of_dp >= 1) and (right_of_dp <= old_width) then
703
            if (is_point_five(vec(right_of_dp-1 downto 0)) = false) then
704
                one_or_zero(0) :=  vec(right_of_dp-1);
705
            else
706
                one_or_zero(0) :=  vec(right_of_dp);
707
            end if;
708
        end if;
709
        if new_arith = xlSigned then
710
            result := signed_to_std_logic_vector(std_logic_vector_to_signed(truncated_val) +
711
                                                 std_logic_vector_to_signed(one_or_zero));
712
        else
713
            result := unsigned_to_std_logic_vector(std_logic_vector_to_unsigned(truncated_val) +
714
                                                  std_logic_vector_to_unsigned(one_or_zero));
715
        end if;
716
        return result;
717
    end;
718
    function saturation_arith(inp:  std_logic_vector;  old_width, old_bin_pt,
719
                              old_arith, new_width, new_bin_pt, new_arith
720
                              : INTEGER)
721
        return std_logic_vector
722
    is
723
        constant left_of_dp : integer := (old_width - old_bin_pt) -
724
                                         (new_width - new_bin_pt);
725
        variable vec : std_logic_vector(old_width-1 downto 0);
726
        variable result : std_logic_vector(new_width-1 downto 0);
727
        variable overflow : boolean;
728
    begin
729
        vec := inp;
730
        overflow := true;
731
        result := (others => '0');
732
        if (new_width >= old_width) then
733
            overflow := false;
734
        end if;
735
        if ((old_arith = xlSigned and new_arith = xlSigned) and (old_width > new_width)) then
736
            if all_same(vec(old_width-1 downto new_width-1)) then
737
                overflow := false;
738
            end if;
739
        end if;
740
        if (old_arith = xlSigned and new_arith = xlUnsigned) then
741
            if (old_width > new_width) then
742
                if all_zeros(vec(old_width-1 downto new_width)) then
743
                    overflow := false;
744
                end if;
745
            else
746
                if (old_width = new_width) then
747
                    if (vec(new_width-1) = '0') then
748
                        overflow := false;
749
                    end if;
750
                end if;
751
            end if;
752
        end if;
753
        if (old_arith = xlUnsigned and new_arith = xlUnsigned) then
754
            if (old_width > new_width) then
755
                if all_zeros(vec(old_width-1 downto new_width)) then
756
                    overflow := false;
757
                end if;
758
            else
759
                if (old_width = new_width) then
760
                    overflow := false;
761
                end if;
762
            end if;
763
        end if;
764
        if ((old_arith = xlUnsigned and new_arith = xlSigned) and (old_width > new_width)) then
765
            if all_same(vec(old_width-1 downto new_width-1)) then
766
                overflow := false;
767
            end if;
768
        end if;
769
        if overflow then
770
            if new_arith = xlSigned then
771
                if vec(old_width-1) = '0' then
772
                    result := max_signed(new_width);
773
                else
774
                    result := min_signed(new_width);
775
                end if;
776
            else
777
                if ((old_arith = xlSigned) and vec(old_width-1) = '1') then
778
                    result := (others => '0');
779
                else
780
                    result := (others => '1');
781
                end if;
782
            end if;
783
        else
784
            if (old_arith = xlSigned) and (new_arith = xlUnsigned) then
785
                if (vec(old_width-1) = '1') then
786
                    vec := (others => '0');
787
                end if;
788
            end if;
789
            if new_width <= old_width then
790
                result := vec(new_width-1 downto 0);
791
            else
792
                if new_arith = xlUnsigned then
793
                    result := zero_ext(vec, new_width);
794
                else
795
                    result := sign_ext(vec, new_width);
796
                end if;
797
            end if;
798
        end if;
799
        return result;
800
    end;
801
   function wrap_arith(inp:  std_logic_vector;  old_width, old_bin_pt,
802
                       old_arith, new_width, new_bin_pt, new_arith : INTEGER)
803
        return std_logic_vector
804
    is
805
        variable result : std_logic_vector(new_width-1 downto 0);
806
        variable result_arith : integer;
807
    begin
808
        if (old_arith = xlSigned) and (new_arith = xlUnsigned) then
809
            result_arith := xlSigned;
810
        end if;
811
        result := cast(inp, old_bin_pt, new_width, new_bin_pt, result_arith);
812
        return result;
813
    end;
814
    function fractional_bits(a_bin_pt, b_bin_pt: INTEGER) return INTEGER is
815
    begin
816
        return max(a_bin_pt, b_bin_pt);
817
    end;
818
    function integer_bits(a_width, a_bin_pt, b_width, b_bin_pt: INTEGER)
819
        return INTEGER is
820
    begin
821
        return  max(a_width - a_bin_pt, b_width - b_bin_pt);
822
    end;
823
    function pad_LSB(inp : std_logic_vector; new_width: integer)
824
        return STD_LOGIC_VECTOR
825
    is
826
        constant orig_width : integer := inp'length;
827
        variable vec : std_logic_vector(orig_width-1 downto 0);
828
        variable result : std_logic_vector(new_width-1 downto 0);
829
        variable pos : integer;
830
        constant pad_pos : integer := new_width - orig_width - 1;
831
    begin
832
        vec := inp;
833
        pos := new_width-1;
834
        if (new_width >= orig_width) then
835
            for i in orig_width-1 downto 0 loop
836
                result(pos) := vec(i);
837
                pos := pos - 1;
838
            end loop;
839
            if pad_pos >= 0 then
840
                for i in pad_pos downto 0 loop
841
                    result(i) := '0';
842
                end loop;
843
            end if;
844
        end if;
845
        return result;
846
    end;
847
    function sign_ext(inp : std_logic_vector; new_width : INTEGER)
848
        return std_logic_vector
849
    is
850
        constant old_width : integer := inp'length;
851
        variable vec : std_logic_vector(old_width-1 downto 0);
852
        variable result : std_logic_vector(new_width-1 downto 0);
853
    begin
854
        vec := inp;
855
        if new_width >= old_width then
856
            result(old_width-1 downto 0) := vec;
857
            if new_width-1 >= old_width then
858
                for i in new_width-1 downto old_width loop
859
                    result(i) := vec(old_width-1);
860
                end loop;
861
            end if;
862
        else
863
            result(new_width-1 downto 0) := vec(new_width-1 downto 0);
864
        end if;
865
        return result;
866
    end;
867
    function zero_ext(inp : std_logic_vector; new_width : INTEGER)
868
        return std_logic_vector
869
    is
870
        constant old_width : integer := inp'length;
871
        variable vec : std_logic_vector(old_width-1 downto 0);
872
        variable result : std_logic_vector(new_width-1 downto 0);
873
    begin
874
        vec := inp;
875
        if new_width >= old_width then
876
            result(old_width-1 downto 0) := vec;
877
            if new_width-1 >= old_width then
878
                for i in new_width-1 downto old_width loop
879
                    result(i) := '0';
880
                end loop;
881
            end if;
882
        else
883
            result(new_width-1 downto 0) := vec(new_width-1 downto 0);
884
        end if;
885
        return result;
886
    end;
887
    function zero_ext(inp : std_logic; new_width : INTEGER)
888
        return std_logic_vector
889
    is
890
        variable result : std_logic_vector(new_width-1 downto 0);
891
    begin
892
        result(0) := inp;
893
        for i in new_width-1 downto 1 loop
894
            result(i) := '0';
895
        end loop;
896
        return result;
897
    end;
898
    function extend_MSB(inp : std_logic_vector; new_width, arith : INTEGER)
899
        return std_logic_vector
900
    is
901
        constant orig_width : integer := inp'length;
902
        variable vec : std_logic_vector(orig_width-1 downto 0);
903
        variable result : std_logic_vector(new_width-1 downto 0);
904
    begin
905
        vec := inp;
906
        if arith = xlUnsigned then
907
            result := zero_ext(vec, new_width);
908
        else
909
            result := sign_ext(vec, new_width);
910
        end if;
911
        return result;
912
    end;
913
    function pad_LSB(inp : std_logic_vector; new_width, arith: integer)
914
        return STD_LOGIC_VECTOR
915
    is
916
        constant orig_width : integer := inp'length;
917
        variable vec : std_logic_vector(orig_width-1 downto 0);
918
        variable result : std_logic_vector(new_width-1 downto 0);
919
        variable pos : integer;
920
    begin
921
        vec := inp;
922
        pos := new_width-1;
923
        if (arith = xlUnsigned) then
924
            result(pos) := '0';
925
            pos := pos - 1;
926
        else
927
            result(pos) := vec(orig_width-1);
928
            pos := pos - 1;
929
        end if;
930
        if (new_width >= orig_width) then
931
            for i in orig_width-1 downto 0 loop
932
                result(pos) := vec(i);
933
                pos := pos - 1;
934
            end loop;
935
            if pos >= 0 then
936
                for i in pos downto 0 loop
937
                    result(i) := '0';
938
                end loop;
939
            end if;
940
        end if;
941
        return result;
942
    end;
943
    function align_input(inp : std_logic_vector; old_width, delta, new_arith,
944
                         new_width: INTEGER)
945
        return std_logic_vector
946
    is
947
        variable vec : std_logic_vector(old_width-1 downto 0);
948
        variable padded_inp : std_logic_vector((old_width + delta)-1  downto 0);
949
        variable result : std_logic_vector(new_width-1 downto 0);
950
    begin
951
        vec := inp;
952
        if delta > 0 then
953
            padded_inp := pad_LSB(vec, old_width+delta);
954
            result := extend_MSB(padded_inp, new_width, new_arith);
955
        else
956
            result := extend_MSB(vec, new_width, new_arith);
957
        end if;
958
        return result;
959
    end;
960
    function max(L, R: INTEGER) return INTEGER is
961
    begin
962
        if L > R then
963
            return L;
964
        else
965
            return R;
966
        end if;
967
    end;
968
    function min(L, R: INTEGER) return INTEGER is
969
    begin
970
        if L < R then
971
            return L;
972
        else
973
            return R;
974
        end if;
975
    end;
976
    function "="(left,right: STRING) return boolean is
977
    begin
978
        if (left'length /= right'length) then
979
            return false;
980
        else
981
            test : for i in 1 to left'length loop
982
                if left(i) /= right(i) then
983
                    return false;
984
                end if;
985
            end loop test;
986
            return true;
987
        end if;
988
    end;
989
    -- synopsys translate_off
990
    function is_binary_string_invalid (inp : string)
991
        return boolean
992
    is
993
        variable vec : string(1 to inp'length);
994
        variable result : boolean;
995
    begin
996
        vec := inp;
997
        result := false;
998
        for i in 1 to vec'length loop
999
            if ( vec(i) = 'X' ) then
1000
                result := true;
1001
            end if;
1002
        end loop;
1003
        return result;
1004
    end;
1005
    function is_binary_string_undefined (inp : string)
1006
        return boolean
1007
    is
1008
        variable vec : string(1 to inp'length);
1009
        variable result : boolean;
1010
    begin
1011
        vec := inp;
1012
        result := false;
1013
        for i in 1 to vec'length loop
1014
            if ( vec(i) = 'U' ) then
1015
                result := true;
1016
            end if;
1017
        end loop;
1018
        return result;
1019
    end;
1020
    function is_XorU(inp : std_logic_vector)
1021
        return boolean
1022
    is
1023
        constant width : integer := inp'length;
1024
        variable vec : std_logic_vector(width-1 downto 0);
1025
        variable result : boolean;
1026
    begin
1027
        vec := inp;
1028
        result := false;
1029
        for i in 0 to width-1 loop
1030
            if (vec(i) = 'U') or (vec(i) = 'X') then
1031
                result := true;
1032
            end if;
1033
        end loop;
1034
        return result;
1035
    end;
1036
    function to_real(inp : std_logic_vector; bin_pt : integer; arith : integer)
1037
        return real
1038
    is
1039
        variable  vec : std_logic_vector(inp'length-1 downto 0);
1040
        variable result, shift_val, undefined_real : real;
1041
        variable neg_num : boolean;
1042
    begin
1043
        vec := inp;
1044
        result := 0.0;
1045
        neg_num := false;
1046
        if vec(inp'length-1) = '1' then
1047
            neg_num := true;
1048
        end if;
1049
        for i in 0 to inp'length-1 loop
1050
            if  vec(i) = 'U' or vec(i) = 'X' then
1051
                return undefined_real;
1052
            end if;
1053
            if arith = xlSigned then
1054
                if neg_num then
1055
                    if vec(i) = '0' then
1056
                        result := result + 2.0**i;
1057
                    end if;
1058
                else
1059
                    if vec(i) = '1' then
1060
                        result := result + 2.0**i;
1061
                    end if;
1062
                end if;
1063
            else
1064
                if vec(i) = '1' then
1065
                    result := result + 2.0**i;
1066
                end if;
1067
            end if;
1068
        end loop;
1069
        if arith = xlSigned then
1070
            if neg_num then
1071
                result := result + 1.0;
1072
                result := result * (-1.0);
1073
            end if;
1074
        end if;
1075
        shift_val := 2.0**(-1*bin_pt);
1076
        result := result * shift_val;
1077
        return result;
1078
    end;
1079
    function std_logic_to_real(inp : std_logic; bin_pt : integer; arith : integer)
1080
        return real
1081
    is
1082
        variable result : real := 0.0;
1083
    begin
1084
        if inp = '1' then
1085
            result := 1.0;
1086
        end if;
1087
        if arith = xlSigned then
1088
            assert false
1089
                report "It doesn't make sense to convert a 1 bit number to a signed real.";
1090
        end if;
1091
        return result;
1092
    end;
1093
    -- synopsys translate_on
1094
    function integer_to_std_logic_vector (inp : integer;  width, arith : integer)
1095
        return std_logic_vector
1096
    is
1097
        variable result : std_logic_vector(width-1 downto 0);
1098
        variable unsigned_val : unsigned(width-1 downto 0);
1099
        variable signed_val : signed(width-1 downto 0);
1100
    begin
1101
        if (arith = xlSigned) then
1102
            signed_val := to_signed(inp, width);
1103
            result := signed_to_std_logic_vector(signed_val);
1104
        else
1105
            unsigned_val := to_unsigned(inp, width);
1106
            result := unsigned_to_std_logic_vector(unsigned_val);
1107
        end if;
1108
        return result;
1109
    end;
1110
    function std_logic_vector_to_integer (inp : std_logic_vector;  arith : integer)
1111
        return integer
1112
    is
1113
        constant width : integer := inp'length;
1114
        variable unsigned_val : unsigned(width-1 downto 0);
1115
        variable signed_val : signed(width-1 downto 0);
1116
        variable result : integer;
1117
    begin
1118
        if (arith = xlSigned) then
1119
            signed_val := std_logic_vector_to_signed(inp);
1120
            result := to_integer(signed_val);
1121
        else
1122
            unsigned_val := std_logic_vector_to_unsigned(inp);
1123
            result := to_integer(unsigned_val);
1124
        end if;
1125
        return result;
1126
    end;
1127
    function std_logic_to_integer(constant inp : std_logic := '0')
1128
        return integer
1129
    is
1130
    begin
1131
        if inp = '1' then
1132
            return 1;
1133
        else
1134
            return 0;
1135
        end if;
1136
    end;
1137
    function makeZeroBinStr (width : integer) return STRING is
1138
        variable result : string(1 to width+3);
1139
    begin
1140
        result(1) := '0';
1141
        result(2) := 'b';
1142
        for i in 3 to width+2 loop
1143
            result(i) := '0';
1144
        end loop;
1145
        result(width+3) := '.';
1146
        return result;
1147
    end;
1148
    -- synopsys translate_off
1149
    function real_string_to_std_logic_vector (inp : string;  width, bin_pt, arith : integer)
1150
        return std_logic_vector
1151
    is
1152
        variable result : std_logic_vector(width-1 downto 0);
1153
    begin
1154
        result := (others => '0');
1155
        return result;
1156
    end;
1157
    function real_to_std_logic_vector (inp : real;  width, bin_pt, arith : integer)
1158
        return std_logic_vector
1159
    is
1160
        variable real_val : real;
1161
        variable int_val : integer;
1162
        variable result : std_logic_vector(width-1 downto 0) := (others => '0');
1163
        variable unsigned_val : unsigned(width-1 downto 0) := (others => '0');
1164
        variable signed_val : signed(width-1 downto 0) := (others => '0');
1165
    begin
1166
        real_val := inp;
1167
        int_val := integer(real_val * 2.0**(bin_pt));
1168
        if (arith = xlSigned) then
1169
            signed_val := to_signed(int_val, width);
1170
            result := signed_to_std_logic_vector(signed_val);
1171
        else
1172
            unsigned_val := to_unsigned(int_val, width);
1173
            result := unsigned_to_std_logic_vector(unsigned_val);
1174
        end if;
1175
        return result;
1176
    end;
1177
    -- synopsys translate_on
1178
    function valid_bin_string (inp : string)
1179
        return boolean
1180
    is
1181
        variable vec : string(1 to inp'length);
1182
    begin
1183
        vec := inp;
1184
        if (vec(1) = '0' and vec(2) = 'b') then
1185
            return true;
1186
        else
1187
            return false;
1188
        end if;
1189
    end;
1190
    function hex_string_to_std_logic_vector(inp: string; width : integer)
1191
        return std_logic_vector is
1192
        constant strlen       : integer := inp'LENGTH;
1193
        variable result       : std_logic_vector(width-1 downto 0);
1194
        variable bitval       : std_logic_vector((strlen*4)-1 downto 0);
1195
        variable posn         : integer;
1196
        variable ch           : character;
1197
        variable vec          : string(1 to strlen);
1198
    begin
1199
        vec := inp;
1200
        result := (others => '0');
1201
        posn := (strlen*4)-1;
1202
        for i in 1 to strlen loop
1203
            ch := vec(i);
1204
            case ch is
1205
                when '0' => bitval(posn downto posn-3) := "0000";
1206
                when '1' => bitval(posn downto posn-3) := "0001";
1207
                when '2' => bitval(posn downto posn-3) := "0010";
1208
                when '3' => bitval(posn downto posn-3) := "0011";
1209
                when '4' => bitval(posn downto posn-3) := "0100";
1210
                when '5' => bitval(posn downto posn-3) := "0101";
1211
                when '6' => bitval(posn downto posn-3) := "0110";
1212
                when '7' => bitval(posn downto posn-3) := "0111";
1213
                when '8' => bitval(posn downto posn-3) := "1000";
1214
                when '9' => bitval(posn downto posn-3) := "1001";
1215
                when 'A' | 'a' => bitval(posn downto posn-3) := "1010";
1216
                when 'B' | 'b' => bitval(posn downto posn-3) := "1011";
1217
                when 'C' | 'c' => bitval(posn downto posn-3) := "1100";
1218
                when 'D' | 'd' => bitval(posn downto posn-3) := "1101";
1219
                when 'E' | 'e' => bitval(posn downto posn-3) := "1110";
1220
                when 'F' | 'f' => bitval(posn downto posn-3) := "1111";
1221
                when others => bitval(posn downto posn-3) := "XXXX";
1222
                               -- synopsys translate_off
1223
                               ASSERT false
1224
                                   REPORT "Invalid hex value" SEVERITY ERROR;
1225
                               -- synopsys translate_on
1226
            end case;
1227
            posn := posn - 4;
1228
        end loop;
1229
        if (width <= strlen*4) then
1230
            result :=  bitval(width-1 downto 0);
1231
        else
1232
            result((strlen*4)-1 downto 0) := bitval;
1233
        end if;
1234
        return result;
1235
    end;
1236
    function bin_string_to_std_logic_vector (inp : string)
1237
        return std_logic_vector
1238
    is
1239
        variable pos : integer;
1240
        variable vec : string(1 to inp'length);
1241
        variable result : std_logic_vector(inp'length-1 downto 0);
1242
    begin
1243
        vec := inp;
1244
        pos := inp'length-1;
1245
        result := (others => '0');
1246
        for i in 1 to vec'length loop
1247
            -- synopsys translate_off
1248
            if (pos < 0) and (vec(i) = '0' or vec(i) = '1' or vec(i) = 'X' or vec(i) = 'U')  then
1249
                assert false
1250
                    report "Input string is larger than output std_logic_vector. Truncating output.";
1251
                return result;
1252
            end if;
1253
            -- synopsys translate_on
1254
            if vec(i) = '0' then
1255
                result(pos) := '0';
1256
                pos := pos - 1;
1257
            end if;
1258
            if vec(i) = '1' then
1259
                result(pos) := '1';
1260
                pos := pos - 1;
1261
            end if;
1262
            -- synopsys translate_off
1263
            if (vec(i) = 'X' or vec(i) = 'U') then
1264
                result(pos) := 'U';
1265
                pos := pos - 1;
1266
            end if;
1267
            -- synopsys translate_on
1268
        end loop;
1269
        return result;
1270
    end;
1271
    function bin_string_element_to_std_logic_vector (inp : string;  width, index : integer)
1272
        return std_logic_vector
1273
    is
1274
        constant str_width : integer := width + 4;
1275
        constant inp_len : integer := inp'length;
1276
        constant num_elements : integer := (inp_len + 1)/str_width;
1277
        constant reverse_index : integer := (num_elements-1) - index;
1278
        variable left_pos : integer;
1279
        variable right_pos : integer;
1280
        variable vec : string(1 to inp'length);
1281
        variable result : std_logic_vector(width-1 downto 0);
1282
    begin
1283
        vec := inp;
1284
        result := (others => '0');
1285
        if (reverse_index = 0) and (reverse_index < num_elements) and (inp_len-3 >= width) then
1286
            left_pos := 1;
1287
            right_pos := width + 3;
1288
            result := bin_string_to_std_logic_vector(vec(left_pos to right_pos));
1289
        end if;
1290
        if (reverse_index > 0) and (reverse_index < num_elements) and (inp_len-3 >= width) then
1291
            left_pos := (reverse_index * str_width) + 1;
1292
            right_pos := left_pos + width + 2;
1293
            result := bin_string_to_std_logic_vector(vec(left_pos to right_pos));
1294
        end if;
1295
        return result;
1296
    end;
1297
   -- synopsys translate_off
1298
    function std_logic_vector_to_bin_string(inp : std_logic_vector)
1299
        return string
1300
    is
1301
        variable vec : std_logic_vector(1 to inp'length);
1302
        variable result : string(vec'range);
1303
    begin
1304
        vec := inp;
1305
        for i in vec'range loop
1306
            result(i) := to_char(vec(i));
1307
        end loop;
1308
        return result;
1309
    end;
1310
    function std_logic_to_bin_string(inp : std_logic)
1311
        return string
1312
    is
1313
        variable result : string(1 to 3);
1314
    begin
1315
        result(1) := '0';
1316
        result(2) := 'b';
1317
        result(3) := to_char(inp);
1318
        return result;
1319
    end;
1320
    function std_logic_vector_to_bin_string_w_point(inp : std_logic_vector; bin_pt : integer)
1321
        return string
1322
    is
1323
        variable width : integer := inp'length;
1324
        variable vec : std_logic_vector(width-1 downto 0);
1325
        variable str_pos : integer;
1326
        variable result : string(1 to width+3);
1327
    begin
1328
        vec := inp;
1329
        str_pos := 1;
1330
        result(str_pos) := '0';
1331
        str_pos := 2;
1332
        result(str_pos) := 'b';
1333
        str_pos := 3;
1334
        for i in width-1 downto 0  loop
1335
            if (((width+3) - bin_pt) = str_pos) then
1336
                result(str_pos) := '.';
1337
                str_pos := str_pos + 1;
1338
            end if;
1339
            result(str_pos) := to_char(vec(i));
1340
            str_pos := str_pos + 1;
1341
        end loop;
1342
        if (bin_pt = 0) then
1343
            result(str_pos) := '.';
1344
        end if;
1345
        return result;
1346
    end;
1347
    function real_to_bin_string(inp : real;  width, bin_pt, arith : integer)
1348
        return string
1349
    is
1350
        variable result : string(1 to width);
1351
        variable vec : std_logic_vector(width-1 downto 0);
1352
    begin
1353
        vec := real_to_std_logic_vector(inp, width, bin_pt, arith);
1354
        result := std_logic_vector_to_bin_string(vec);
1355
        return result;
1356
    end;
1357
    function real_to_string (inp : real) return string
1358
    is
1359
        variable result : string(1 to display_precision) := (others => ' ');
1360
    begin
1361
        result(real'image(inp)'range) := real'image(inp);
1362
        return result;
1363
    end;
1364
    -- synopsys translate_on
1365
end conv_pkg;
1366
 
1367
-------------------------------------------------------------------
1368
-- System Generator version 12.3 VHDL source file.
1369
--
1370
-- Copyright(C) 2010 by Xilinx, Inc.  All rights reserved.  This
1371
-- text/file contains proprietary, confidential information of Xilinx,
1372
-- Inc., is distributed under license from Xilinx, Inc., and may be used,
1373
-- copied and/or disclosed only pursuant to the terms of a valid license
1374
-- agreement with Xilinx, Inc.  Xilinx hereby grants you a license to use
1375
-- this text/file solely for design, simulation, implementation and
1376
-- creation of design files limited to Xilinx devices or technologies.
1377
-- Use with non-Xilinx devices or technologies is expressly prohibited
1378
-- and immediately terminates your license unless covered by a separate
1379
-- agreement.
1380
--
1381
-- Xilinx is providing this design, code, or information "as is" solely
1382
-- for use in developing programs and solutions for Xilinx devices.  By
1383
-- providing this design, code, or information as one possible
1384
-- implementation of this feature, application or standard, Xilinx is
1385
-- making no representation that this implementation is free from any
1386
-- claims of infringement.  You are responsible for obtaining any rights
1387
-- you may require for your implementation.  Xilinx expressly disclaims
1388
-- any warranty whatsoever with respect to the adequacy of the
1389
-- implementation, including but not limited to warranties of
1390
-- merchantability or fitness for a particular purpose.
1391
--
1392
-- Xilinx products are not intended for use in life support appliances,
1393
-- devices, or systems.  Use in such applications is expressly prohibited.
1394
--
1395
-- Any modifications that are made to the source code are done at the user's
1396
-- sole risk and will be unsupported.
1397
--
1398
-- This copyright and support notice must be retained as part of this
1399
-- text at all times.  (c) Copyright 1995-2010 Xilinx, Inc.  All rights
1400
-- reserved.
1401
-------------------------------------------------------------------
1402
-- synopsys translate_off
1403
library unisim;
1404
use unisim.vcomponents.all;
1405
-- synopsys translate_on
1406
library IEEE;
1407
use IEEE.std_logic_1164.all;
1408
use work.conv_pkg.all;
1409
entity srl17e is
1410
    generic (width : integer:=16;
1411
             latency : integer :=8);
1412
    port (clk   : in std_logic;
1413
          ce    : in std_logic;
1414
          d     : in std_logic_vector(width-1 downto 0);
1415
          q     : out std_logic_vector(width-1 downto 0));
1416
end srl17e;
1417
architecture structural of srl17e is
1418
    component SRL16E
1419
        port (D   : in STD_ULOGIC;
1420
              CE  : in STD_ULOGIC;
1421
              CLK : in STD_ULOGIC;
1422
              A0  : in STD_ULOGIC;
1423
              A1  : in STD_ULOGIC;
1424
              A2  : in STD_ULOGIC;
1425
              A3  : in STD_ULOGIC;
1426
              Q   : out STD_ULOGIC);
1427
    end component;
1428
    attribute syn_black_box of SRL16E : component is true;
1429
    attribute fpga_dont_touch of SRL16E : component is "true";
1430
    component FDE
1431
        port(
1432
            Q  :        out   STD_ULOGIC;
1433
            D  :        in    STD_ULOGIC;
1434
            C  :        in    STD_ULOGIC;
1435
            CE :        in    STD_ULOGIC);
1436
    end component;
1437
    attribute syn_black_box of FDE : component is true;
1438
    attribute fpga_dont_touch of FDE : component is "true";
1439
    constant a : std_logic_vector(4 downto 0) :=
1440
        integer_to_std_logic_vector(latency-2,5,xlSigned);
1441
    signal d_delayed : std_logic_vector(width-1 downto 0);
1442
    signal srl16_out : std_logic_vector(width-1 downto 0);
1443
begin
1444
    d_delayed <= d after 200 ps;
1445
    reg_array : for i in 0 to width-1 generate
1446
        srl16_used: if latency > 1 generate
1447
            u1 : srl16e port map(clk => clk,
1448
                                 d => d_delayed(i),
1449
                                 q => srl16_out(i),
1450
                                 ce => ce,
1451
                                 a0 => a(0),
1452
                                 a1 => a(1),
1453
                                 a2 => a(2),
1454
                                 a3 => a(3));
1455
        end generate;
1456
        srl16_not_used: if latency <= 1 generate
1457
            srl16_out(i) <= d_delayed(i);
1458
        end generate;
1459
        fde_used: if latency /= 0  generate
1460
            u2 : fde port map(c => clk,
1461
                              d => srl16_out(i),
1462
                              q => q(i),
1463
                              ce => ce);
1464
        end generate;
1465
        fde_not_used: if latency = 0  generate
1466
            q(i) <= srl16_out(i);
1467
        end generate;
1468
    end generate;
1469
 end structural;
1470
library IEEE;
1471
use IEEE.std_logic_1164.all;
1472
use work.conv_pkg.all;
1473
entity synth_reg is
1474
    generic (width           : integer := 8;
1475
             latency         : integer := 1);
1476
    port (i       : in std_logic_vector(width-1 downto 0);
1477
          ce      : in std_logic;
1478
          clr     : in std_logic;
1479
          clk     : in std_logic;
1480
          o       : out std_logic_vector(width-1 downto 0));
1481
end synth_reg;
1482
architecture structural of synth_reg is
1483
    component srl17e
1484
        generic (width : integer:=16;
1485
                 latency : integer :=8);
1486
        port (clk : in std_logic;
1487
              ce  : in std_logic;
1488
              d   : in std_logic_vector(width-1 downto 0);
1489
              q   : out std_logic_vector(width-1 downto 0));
1490
    end component;
1491
    function calc_num_srl17es (latency : integer)
1492
        return integer
1493
    is
1494
        variable remaining_latency : integer;
1495
        variable result : integer;
1496
    begin
1497
        result := latency / 17;
1498
        remaining_latency := latency - (result * 17);
1499
        if (remaining_latency /= 0) then
1500
            result := result + 1;
1501
        end if;
1502
        return result;
1503
    end;
1504
    constant complete_num_srl17es : integer := latency / 17;
1505
    constant num_srl17es : integer := calc_num_srl17es(latency);
1506
    constant remaining_latency : integer := latency - (complete_num_srl17es * 17);
1507
    type register_array is array (num_srl17es downto 0) of
1508
        std_logic_vector(width-1 downto 0);
1509
    signal z : register_array;
1510
begin
1511
    z(0) <= i;
1512
    complete_ones : if complete_num_srl17es > 0 generate
1513
        srl17e_array: for i in 0 to complete_num_srl17es-1 generate
1514
            delay_comp : srl17e
1515
                generic map (width => width,
1516
                             latency => 17)
1517
                port map (clk => clk,
1518
                          ce  => ce,
1519
                          d       => z(i),
1520
                          q       => z(i+1));
1521
        end generate;
1522
    end generate;
1523
    partial_one : if remaining_latency > 0 generate
1524
        last_srl17e : srl17e
1525
            generic map (width => width,
1526
                         latency => remaining_latency)
1527
            port map (clk => clk,
1528
                      ce  => ce,
1529
                      d   => z(num_srl17es-1),
1530
                      q   => z(num_srl17es));
1531
    end generate;
1532
    o <= z(num_srl17es);
1533
end structural;
1534
library IEEE;
1535
use IEEE.std_logic_1164.all;
1536
use work.conv_pkg.all;
1537
entity synth_reg_reg is
1538
    generic (width           : integer := 8;
1539
             latency         : integer := 1);
1540
    port (i       : in std_logic_vector(width-1 downto 0);
1541
          ce      : in std_logic;
1542
          clr     : in std_logic;
1543
          clk     : in std_logic;
1544
          o       : out std_logic_vector(width-1 downto 0));
1545
end synth_reg_reg;
1546
architecture behav of synth_reg_reg is
1547
  type reg_array_type is array (latency-1 downto 0) of std_logic_vector(width -1 downto 0);
1548
  signal reg_bank : reg_array_type := (others => (others => '0'));
1549
  signal reg_bank_in : reg_array_type := (others => (others => '0'));
1550
  attribute syn_allow_retiming : boolean;
1551
  attribute syn_srlstyle : string;
1552
  attribute syn_allow_retiming of reg_bank : signal is true;
1553
  attribute syn_allow_retiming of reg_bank_in : signal is true;
1554
  attribute syn_srlstyle of reg_bank : signal is "registers";
1555
  attribute syn_srlstyle of reg_bank_in : signal is "registers";
1556
begin
1557
  latency_eq_0: if latency = 0 generate
1558
    o <= i;
1559
  end generate latency_eq_0;
1560
  latency_gt_0: if latency >= 1 generate
1561
    o <= reg_bank(latency-1);
1562
    reg_bank_in(0) <= i;
1563
    loop_gen: for idx in latency-2 downto 0 generate
1564
      reg_bank_in(idx+1) <= reg_bank(idx);
1565
    end generate loop_gen;
1566
    sync_loop: for sync_idx in latency-1 downto 0 generate
1567
      sync_proc: process (clk)
1568
      begin
1569
        if clk'event and clk = '1' then
1570
          if ce = '1'  then
1571
            reg_bank(sync_idx) <= reg_bank_in(sync_idx);
1572
          end if;
1573
        end if;
1574
      end process sync_proc;
1575
    end generate sync_loop;
1576
  end generate latency_gt_0;
1577
end behav;
1578
 
1579
-------------------------------------------------------------------
1580
-- System Generator version 12.3 VHDL source file.
1581
--
1582
-- Copyright(C) 2010 by Xilinx, Inc.  All rights reserved.  This
1583
-- text/file contains proprietary, confidential information of Xilinx,
1584
-- Inc., is distributed under license from Xilinx, Inc., and may be used,
1585
-- copied and/or disclosed only pursuant to the terms of a valid license
1586
-- agreement with Xilinx, Inc.  Xilinx hereby grants you a license to use
1587
-- this text/file solely for design, simulation, implementation and
1588
-- creation of design files limited to Xilinx devices or technologies.
1589
-- Use with non-Xilinx devices or technologies is expressly prohibited
1590
-- and immediately terminates your license unless covered by a separate
1591
-- agreement.
1592
--
1593
-- Xilinx is providing this design, code, or information "as is" solely
1594
-- for use in developing programs and solutions for Xilinx devices.  By
1595
-- providing this design, code, or information as one possible
1596
-- implementation of this feature, application or standard, Xilinx is
1597
-- making no representation that this implementation is free from any
1598
-- claims of infringement.  You are responsible for obtaining any rights
1599
-- you may require for your implementation.  Xilinx expressly disclaims
1600
-- any warranty whatsoever with respect to the adequacy of the
1601
-- implementation, including but not limited to warranties of
1602
-- merchantability or fitness for a particular purpose.
1603
--
1604
-- Xilinx products are not intended for use in life support appliances,
1605
-- devices, or systems.  Use in such applications is expressly prohibited.
1606
--
1607
-- Any modifications that are made to the source code are done at the user's
1608
-- sole risk and will be unsupported.
1609
--
1610
-- This copyright and support notice must be retained as part of this
1611
-- text at all times.  (c) Copyright 1995-2010 Xilinx, Inc.  All rights
1612
-- reserved.
1613
-------------------------------------------------------------------
1614
-- synopsys translate_off
1615
library unisim;
1616
use unisim.vcomponents.all;
1617
-- synopsys translate_on
1618
library IEEE;
1619
use IEEE.std_logic_1164.all;
1620
use work.conv_pkg.all;
1621
entity single_reg_w_init is
1622
  generic (
1623
    width: integer := 8;
1624
    init_index: integer := 0;
1625
    init_value: bit_vector := b"0000"
1626
  );
1627
  port (
1628
    i: in std_logic_vector(width - 1 downto 0);
1629
    ce: in std_logic;
1630
    clr: in std_logic;
1631
    clk: in std_logic;
1632
    o: out std_logic_vector(width - 1 downto 0)
1633
  );
1634
end single_reg_w_init;
1635
architecture structural of single_reg_w_init is
1636
  function build_init_const(width: integer;
1637
                            init_index: integer;
1638
                            init_value: bit_vector)
1639
    return std_logic_vector
1640
  is
1641
    variable result: std_logic_vector(width - 1 downto 0);
1642
  begin
1643
    if init_index = 0 then
1644
      result := (others => '0');
1645
    elsif init_index = 1 then
1646
      result := (others => '0');
1647
      result(0) := '1';
1648
    else
1649
      result := to_stdlogicvector(init_value);
1650
    end if;
1651
    return result;
1652
  end;
1653
  component fdre
1654
    port (
1655
      q: out std_ulogic;
1656
      d: in  std_ulogic;
1657
      c: in  std_ulogic;
1658
      ce: in  std_ulogic;
1659
      r: in  std_ulogic
1660
    );
1661
  end component;
1662
  attribute syn_black_box of fdre: component is true;
1663
  attribute fpga_dont_touch of fdre: component is "true";
1664
  component fdse
1665
    port (
1666
      q: out std_ulogic;
1667
      d: in  std_ulogic;
1668
      c: in  std_ulogic;
1669
      ce: in  std_ulogic;
1670
      s: in  std_ulogic
1671
    );
1672
  end component;
1673
  attribute syn_black_box of fdse: component is true;
1674
  attribute fpga_dont_touch of fdse: component is "true";
1675
  constant init_const: std_logic_vector(width - 1 downto 0)
1676
    := build_init_const(width, init_index, init_value);
1677
begin
1678
  fd_prim_array: for index in 0 to width - 1 generate
1679
    bit_is_0: if (init_const(index) = '0') generate
1680
      fdre_comp: fdre
1681
        port map (
1682
          c => clk,
1683
          d => i(index),
1684
          q => o(index),
1685
          ce => ce,
1686
          r => clr
1687
        );
1688
    end generate;
1689
    bit_is_1: if (init_const(index) = '1') generate
1690
      fdse_comp: fdse
1691
        port map (
1692
          c => clk,
1693
          d => i(index),
1694
          q => o(index),
1695
          ce => ce,
1696
          s => clr
1697
        );
1698
    end generate;
1699
  end generate;
1700
end architecture structural;
1701
-- synopsys translate_off
1702
library unisim;
1703
use unisim.vcomponents.all;
1704
-- synopsys translate_on
1705
library IEEE;
1706
use IEEE.std_logic_1164.all;
1707
use work.conv_pkg.all;
1708
entity synth_reg_w_init is
1709
  generic (
1710
    width: integer := 8;
1711
    init_index: integer := 0;
1712
    init_value: bit_vector := b"0000";
1713
    latency: integer := 1
1714
  );
1715
  port (
1716
    i: in std_logic_vector(width - 1 downto 0);
1717
    ce: in std_logic;
1718
    clr: in std_logic;
1719
    clk: in std_logic;
1720
    o: out std_logic_vector(width - 1 downto 0)
1721
  );
1722
end synth_reg_w_init;
1723
architecture structural of synth_reg_w_init is
1724
  component single_reg_w_init
1725
    generic (
1726
      width: integer := 8;
1727
      init_index: integer := 0;
1728
      init_value: bit_vector := b"0000"
1729
    );
1730
    port (
1731
      i: in std_logic_vector(width - 1 downto 0);
1732
      ce: in std_logic;
1733
      clr: in std_logic;
1734
      clk: in std_logic;
1735
      o: out std_logic_vector(width - 1 downto 0)
1736
    );
1737
  end component;
1738
  signal dly_i: std_logic_vector((latency + 1) * width - 1 downto 0);
1739
  signal dly_clr: std_logic;
1740
begin
1741
  latency_eq_0: if (latency = 0) generate
1742
    o <= i;
1743
  end generate;
1744
  latency_gt_0: if (latency >= 1) generate
1745
    dly_i((latency + 1) * width - 1 downto latency * width) <= i
1746
      after 200 ps;
1747
    dly_clr <= clr after 200 ps;
1748
    fd_array: for index in latency downto 1 generate
1749
       reg_comp: single_reg_w_init
1750
          generic map (
1751
            width => width,
1752
            init_index => init_index,
1753
            init_value => init_value
1754
          )
1755
          port map (
1756
            clk => clk,
1757
            i => dly_i((index + 1) * width - 1 downto index * width),
1758
            o => dly_i(index * width - 1 downto (index - 1) * width),
1759
            ce => ce,
1760
            clr => dly_clr
1761
          );
1762
    end generate;
1763
    o <= dly_i(width - 1 downto 0);
1764
  end generate;
1765
end structural;
1766
 
1767
-------------------------------------------------------------------
1768
-- System Generator version 12.3 VHDL source file.
1769
--
1770
-- Copyright(C) 2010 by Xilinx, Inc.  All rights reserved.  This
1771
-- text/file contains proprietary, confidential information of Xilinx,
1772
-- Inc., is distributed under license from Xilinx, Inc., and may be used,
1773
-- copied and/or disclosed only pursuant to the terms of a valid license
1774
-- agreement with Xilinx, Inc.  Xilinx hereby grants you a license to use
1775
-- this text/file solely for design, simulation, implementation and
1776
-- creation of design files limited to Xilinx devices or technologies.
1777
-- Use with non-Xilinx devices or technologies is expressly prohibited
1778
-- and immediately terminates your license unless covered by a separate
1779
-- agreement.
1780
--
1781
-- Xilinx is providing this design, code, or information "as is" solely
1782
-- for use in developing programs and solutions for Xilinx devices.  By
1783
-- providing this design, code, or information as one possible
1784
-- implementation of this feature, application or standard, Xilinx is
1785
-- making no representation that this implementation is free from any
1786
-- claims of infringement.  You are responsible for obtaining any rights
1787
-- you may require for your implementation.  Xilinx expressly disclaims
1788
-- any warranty whatsoever with respect to the adequacy of the
1789
-- implementation, including but not limited to warranties of
1790
-- merchantability or fitness for a particular purpose.
1791
--
1792
-- Xilinx products are not intended for use in life support appliances,
1793
-- devices, or systems.  Use in such applications is expressly prohibited.
1794
--
1795
-- Any modifications that are made to the source code are done at the user's
1796
-- sole risk and will be unsupported.
1797
--
1798
-- This copyright and support notice must be retained as part of this
1799
-- text at all times.  (c) Copyright 1995-2010 Xilinx, Inc.  All rights
1800
-- reserved.
1801
-------------------------------------------------------------------
1802
library IEEE;
1803
use IEEE.std_logic_1164.all;
1804
use work.conv_pkg.all;
1805
entity convert_func_call is
1806
    generic (
1807
        din_width    : integer := 16;
1808
        din_bin_pt   : integer := 4;
1809
        din_arith    : integer := xlUnsigned;
1810
        dout_width   : integer := 8;
1811
        dout_bin_pt  : integer := 2;
1812
        dout_arith   : integer := xlUnsigned;
1813
        quantization : integer := xlTruncate;
1814
        overflow     : integer := xlWrap);
1815
    port (
1816
        din : in std_logic_vector (din_width-1 downto 0);
1817
        result : out std_logic_vector (dout_width-1 downto 0));
1818
end convert_func_call;
1819
architecture behavior of convert_func_call is
1820
begin
1821
    result <= convert_type(din, din_width, din_bin_pt, din_arith,
1822
                           dout_width, dout_bin_pt, dout_arith,
1823
                           quantization, overflow);
1824
end behavior;
1825
library IEEE;
1826
use IEEE.std_logic_1164.all;
1827
use work.conv_pkg.all;
1828
entity xlconvert is
1829
    generic (
1830
        din_width    : integer := 16;
1831
        din_bin_pt   : integer := 4;
1832
        din_arith    : integer := xlUnsigned;
1833
        dout_width   : integer := 8;
1834
        dout_bin_pt  : integer := 2;
1835
        dout_arith   : integer := xlUnsigned;
1836
        en_width     : integer := 1;
1837
        en_bin_pt    : integer := 0;
1838
        en_arith     : integer := xlUnsigned;
1839
        bool_conversion : integer :=0;
1840
        latency      : integer := 0;
1841
        quantization : integer := xlTruncate;
1842
        overflow     : integer := xlWrap);
1843
    port (
1844
        din : in std_logic_vector (din_width-1 downto 0);
1845
        en  : in std_logic_vector (en_width-1 downto 0);
1846
        ce  : in std_logic;
1847
        clr : in std_logic;
1848
        clk : in std_logic;
1849
        dout : out std_logic_vector (dout_width-1 downto 0));
1850
end xlconvert;
1851
architecture behavior of xlconvert is
1852
    component synth_reg
1853
        generic (width       : integer;
1854
                 latency     : integer);
1855
        port (i       : in std_logic_vector(width-1 downto 0);
1856
              ce      : in std_logic;
1857
              clr     : in std_logic;
1858
              clk     : in std_logic;
1859
              o       : out std_logic_vector(width-1 downto 0));
1860
    end component;
1861
    component convert_func_call
1862
        generic (
1863
            din_width    : integer := 16;
1864
            din_bin_pt   : integer := 4;
1865
            din_arith    : integer := xlUnsigned;
1866
            dout_width   : integer := 8;
1867
            dout_bin_pt  : integer := 2;
1868
            dout_arith   : integer := xlUnsigned;
1869
            quantization : integer := xlTruncate;
1870
            overflow     : integer := xlWrap);
1871
        port (
1872
            din : in std_logic_vector (din_width-1 downto 0);
1873
            result : out std_logic_vector (dout_width-1 downto 0));
1874
    end component;
1875
    -- synopsys translate_off
1876
    -- synopsys translate_on
1877
    signal result : std_logic_vector(dout_width-1 downto 0);
1878
    signal internal_ce : std_logic;
1879
begin
1880
    -- synopsys translate_off
1881
    -- synopsys translate_on
1882
    internal_ce <= ce and en(0);
1883
 
1884
    bool_conversion_generate : if (bool_conversion = 1)
1885
    generate
1886
      result <= din;
1887
    end generate;
1888
    std_conversion_generate : if (bool_conversion = 0)
1889
    generate
1890
      convert : convert_func_call
1891
        generic map (
1892
          din_width   => din_width,
1893
          din_bin_pt  => din_bin_pt,
1894
          din_arith   => din_arith,
1895
          dout_width  => dout_width,
1896
          dout_bin_pt => dout_bin_pt,
1897
          dout_arith  => dout_arith,
1898
          quantization => quantization,
1899
          overflow     => overflow)
1900
        port map (
1901
          din => din,
1902
          result => result);
1903
    end generate;
1904
    latency_test : if (latency > 0) generate
1905
        reg : synth_reg
1906
            generic map (
1907
              width => dout_width,
1908
              latency => latency
1909
            )
1910
            port map (
1911
              i => result,
1912
              ce => internal_ce,
1913
              clr => clr,
1914
              clk => clk,
1915
              o => dout
1916
            );
1917
    end generate;
1918
    latency0 : if (latency = 0)
1919
    generate
1920
        dout <= result;
1921
    end generate latency0;
1922
end  behavior;
1923
library IEEE;
1924
use IEEE.std_logic_1164.all;
1925
use IEEE.numeric_std.all;
1926
use work.conv_pkg.all;
1927
 
1928
entity constant_963ed6358a is
1929
  port (
1930
    op : out std_logic_vector((1 - 1) downto 0);
1931
    clk : in std_logic;
1932
    ce : in std_logic;
1933
    clr : in std_logic);
1934
end constant_963ed6358a;
1935
 
1936
 
1937
architecture behavior of constant_963ed6358a is
1938
begin
1939
  op <= "0";
1940
end behavior;
1941
 
1942
 
1943
-------------------------------------------------------------------
1944
-- System Generator version 12.3 VHDL source file.
1945
--
1946
-- Copyright(C) 2010 by Xilinx, Inc.  All rights reserved.  This
1947
-- text/file contains proprietary, confidential information of Xilinx,
1948
-- Inc., is distributed under license from Xilinx, Inc., and may be used,
1949
-- copied and/or disclosed only pursuant to the terms of a valid license
1950
-- agreement with Xilinx, Inc.  Xilinx hereby grants you a license to use
1951
-- this text/file solely for design, simulation, implementation and
1952
-- creation of design files limited to Xilinx devices or technologies.
1953
-- Use with non-Xilinx devices or technologies is expressly prohibited
1954
-- and immediately terminates your license unless covered by a separate
1955
-- agreement.
1956
--
1957
-- Xilinx is providing this design, code, or information "as is" solely
1958
-- for use in developing programs and solutions for Xilinx devices.  By
1959
-- providing this design, code, or information as one possible
1960
-- implementation of this feature, application or standard, Xilinx is
1961
-- making no representation that this implementation is free from any
1962
-- claims of infringement.  You are responsible for obtaining any rights
1963
-- you may require for your implementation.  Xilinx expressly disclaims
1964
-- any warranty whatsoever with respect to the adequacy of the
1965
-- implementation, including but not limited to warranties of
1966
-- merchantability or fitness for a particular purpose.
1967
--
1968
-- Xilinx products are not intended for use in life support appliances,
1969
-- devices, or systems.  Use in such applications is expressly prohibited.
1970
--
1971
-- Any modifications that are made to the source code are done at the user's
1972
-- sole risk and will be unsupported.
1973
--
1974
-- This copyright and support notice must be retained as part of this
1975
-- text at all times.  (c) Copyright 1995-2010 Xilinx, Inc.  All rights
1976
-- reserved.
1977
-------------------------------------------------------------------
1978
library IEEE;
1979
use IEEE.std_logic_1164.all;
1980
use work.conv_pkg.all;
1981
entity xlregister is
1982
   generic (d_width          : integer := 5;
1983
            init_value       : bit_vector := b"00");
1984
   port (d   : in std_logic_vector (d_width-1 downto 0);
1985
         rst : in std_logic_vector(0 downto 0) := "0";
1986
         en  : in std_logic_vector(0 downto 0) := "1";
1987
         ce  : in std_logic;
1988
         clk : in std_logic;
1989
         q   : out std_logic_vector (d_width-1 downto 0));
1990
end xlregister;
1991
architecture behavior of xlregister is
1992
   component synth_reg_w_init
1993
      generic (width      : integer;
1994
               init_index : integer;
1995
               init_value : bit_vector;
1996
               latency    : integer);
1997
      port (i   : in std_logic_vector(width-1 downto 0);
1998
            ce  : in std_logic;
1999
            clr : in std_logic;
2000
            clk : in std_logic;
2001
            o   : out std_logic_vector(width-1 downto 0));
2002
   end component;
2003
   -- synopsys translate_off
2004
   signal real_d, real_q           : real;
2005
   -- synopsys translate_on
2006
   signal internal_clr             : std_logic;
2007
   signal internal_ce              : std_logic;
2008
begin
2009
   internal_clr <= rst(0) and ce;
2010
   internal_ce  <= en(0) and ce;
2011
   synth_reg_inst : synth_reg_w_init
2012
      generic map (width      => d_width,
2013
                   init_index => 2,
2014
                   init_value => init_value,
2015
                   latency    => 1)
2016
      port map (i   => d,
2017
                ce  => internal_ce,
2018
                clr => internal_clr,
2019
                clk => clk,
2020
                o   => q);
2021
end architecture behavior;
2022
library IEEE;
2023
use IEEE.std_logic_1164.all;
2024
use IEEE.numeric_std.all;
2025
use work.conv_pkg.all;
2026
 
2027
entity constant_6293007044 is
2028
  port (
2029
    op : out std_logic_vector((1 - 1) downto 0);
2030
    clk : in std_logic;
2031
    ce : in std_logic;
2032
    clr : in std_logic);
2033
end constant_6293007044;
2034
 
2035
 
2036
architecture behavior of constant_6293007044 is
2037
begin
2038
  op <= "1";
2039
end behavior;
2040
 
2041
library IEEE;
2042
use IEEE.std_logic_1164.all;
2043
use IEEE.numeric_std.all;
2044
use work.conv_pkg.all;
2045
 
2046
entity constant_19562ab42f is
2047
  port (
2048
    op : out std_logic_vector((8 - 1) downto 0);
2049
    clk : in std_logic;
2050
    ce : in std_logic;
2051
    clr : in std_logic);
2052
end constant_19562ab42f;
2053
 
2054
 
2055
architecture behavior of constant_19562ab42f is
2056
begin
2057
  op <= "11111111";
2058
end behavior;
2059
 
2060
 
2061
-------------------------------------------------------------------
2062
-- System Generator version 12.3 VHDL source file.
2063
--
2064
-- Copyright(C) 2010 by Xilinx, Inc.  All rights reserved.  This
2065
-- text/file contains proprietary, confidential information of Xilinx,
2066
-- Inc., is distributed under license from Xilinx, Inc., and may be used,
2067
-- copied and/or disclosed only pursuant to the terms of a valid license
2068
-- agreement with Xilinx, Inc.  Xilinx hereby grants you a license to use
2069
-- this text/file solely for design, simulation, implementation and
2070
-- creation of design files limited to Xilinx devices or technologies.
2071
-- Use with non-Xilinx devices or technologies is expressly prohibited
2072
-- and immediately terminates your license unless covered by a separate
2073
-- agreement.
2074
--
2075
-- Xilinx is providing this design, code, or information "as is" solely
2076
-- for use in developing programs and solutions for Xilinx devices.  By
2077
-- providing this design, code, or information as one possible
2078
-- implementation of this feature, application or standard, Xilinx is
2079
-- making no representation that this implementation is free from any
2080
-- claims of infringement.  You are responsible for obtaining any rights
2081
-- you may require for your implementation.  Xilinx expressly disclaims
2082
-- any warranty whatsoever with respect to the adequacy of the
2083
-- implementation, including but not limited to warranties of
2084
-- merchantability or fitness for a particular purpose.
2085
--
2086
-- Xilinx products are not intended for use in life support appliances,
2087
-- devices, or systems.  Use in such applications is expressly prohibited.
2088
--
2089
-- Any modifications that are made to the source code are done at the user's
2090
-- sole risk and will be unsupported.
2091
--
2092
-- This copyright and support notice must be retained as part of this
2093
-- text at all times.  (c) Copyright 1995-2010 Xilinx, Inc.  All rights
2094
-- reserved.
2095
-------------------------------------------------------------------
2096
-- synopsys translate_off
2097
library XilinxCoreLib;
2098
-- synopsys translate_on
2099
library IEEE;
2100
use IEEE.std_logic_1164.all;
2101
use work.conv_pkg.all;
2102
entity xlcounter_free is
2103
  generic (
2104
    core_name0: string := "";
2105
    op_width: integer := 5;
2106
    op_arith: integer := xlSigned
2107
  );
2108
  port (
2109
    ce: in std_logic;
2110
    clr: in std_logic;
2111
    clk: in std_logic;
2112
    op: out std_logic_vector(op_width - 1 downto 0);
2113
    up: in std_logic_vector(0 downto 0) := (others => '0');
2114
    load: in std_logic_vector(0 downto 0) := (others => '0');
2115
    din: in std_logic_vector(op_width - 1 downto 0) := (others => '0');
2116
    en: in std_logic_vector(0 downto 0);
2117
    rst: in std_logic_vector(0 downto 0)
2118
  );
2119
end xlcounter_free ;
2120
architecture behavior of xlcounter_free is
2121
  component cntr_11_0_1a411d6ef586e892
2122
    port (
2123
      clk: in std_logic;
2124
      ce: in std_logic;
2125
      SINIT: in std_logic;
2126
      q: out std_logic_vector(op_width - 1 downto 0)
2127
    );
2128
  end component;
2129
  attribute syn_black_box of cntr_11_0_1a411d6ef586e892:
2130
    component is true;
2131
  attribute fpga_dont_touch of cntr_11_0_1a411d6ef586e892:
2132
    component is "true";
2133
  attribute box_type of cntr_11_0_1a411d6ef586e892:
2134
    component  is "black_box";
2135
-- synopsys translate_off
2136
  constant zeroVec: std_logic_vector(op_width - 1 downto 0) := (others => '0');
2137
  constant oneVec: std_logic_vector(op_width - 1 downto 0) := (others => '1');
2138
  constant zeroStr: string(1 to op_width) :=
2139
    std_logic_vector_to_bin_string(zeroVec);
2140
  constant oneStr: string(1 to op_width) :=
2141
    std_logic_vector_to_bin_string(oneVec);
2142
-- synopsys translate_on
2143
  signal core_sinit: std_logic;
2144
  signal core_ce: std_logic;
2145
  signal op_net: std_logic_vector(op_width - 1 downto 0);
2146
begin
2147
  core_ce <= ce and en(0);
2148
  core_sinit <= (clr or rst(0)) and ce;
2149
  op <= op_net;
2150
  comp0: if ((core_name0 = "cntr_11_0_1a411d6ef586e892")) generate
2151
    core_instance0: cntr_11_0_1a411d6ef586e892
2152
      port map (
2153
        clk => clk,
2154
        ce => core_ce,
2155
        SINIT => core_sinit,
2156
        q => op_net
2157
      );
2158
  end generate;
2159
end behavior;
2160
library IEEE;
2161
use IEEE.std_logic_1164.all;
2162
use IEEE.numeric_std.all;
2163
use work.conv_pkg.all;
2164
 
2165
entity inverter_e5b38cca3b is
2166
  port (
2167
    ip : in std_logic_vector((1 - 1) downto 0);
2168
    op : out std_logic_vector((1 - 1) downto 0);
2169
    clk : in std_logic;
2170
    ce : in std_logic;
2171
    clr : in std_logic);
2172
end inverter_e5b38cca3b;
2173
 
2174
 
2175
architecture behavior of inverter_e5b38cca3b is
2176
  signal ip_1_26: boolean;
2177
  type array_type_op_mem_22_20 is array (0 to (1 - 1)) of boolean;
2178
  signal op_mem_22_20: array_type_op_mem_22_20 := (
2179
 
2180
  signal op_mem_22_20_front_din: boolean;
2181
  signal op_mem_22_20_back: boolean;
2182
  signal op_mem_22_20_push_front_pop_back_en: std_logic;
2183
  signal internal_ip_12_1_bitnot: boolean;
2184
begin
2185
  ip_1_26 <= ((ip) = "1");
2186
  op_mem_22_20_back <= op_mem_22_20(0);
2187
  proc_op_mem_22_20: process (clk)
2188
  is
2189
    variable i: integer;
2190
  begin
2191
    if (clk'event and (clk = '1')) then
2192
      if ((ce = '1') and (op_mem_22_20_push_front_pop_back_en = '1')) then
2193
        op_mem_22_20(0) <= op_mem_22_20_front_din;
2194
      end if;
2195
    end if;
2196
  end process proc_op_mem_22_20;
2197
  internal_ip_12_1_bitnot <= ((not boolean_to_vector(ip_1_26)) = "1");
2198
  op_mem_22_20_push_front_pop_back_en <= '0';
2199
  op <= boolean_to_vector(internal_ip_12_1_bitnot);
2200
end behavior;
2201
 
2202
library IEEE;
2203
use IEEE.std_logic_1164.all;
2204
use IEEE.numeric_std.all;
2205
use work.conv_pkg.all;
2206
 
2207
entity logical_80f90b97d0 is
2208
  port (
2209
    d0 : in std_logic_vector((1 - 1) downto 0);
2210
    d1 : in std_logic_vector((1 - 1) downto 0);
2211
    y : out std_logic_vector((1 - 1) downto 0);
2212
    clk : in std_logic;
2213
    ce : in std_logic;
2214
    clr : in std_logic);
2215
end logical_80f90b97d0;
2216
 
2217
 
2218
architecture behavior of logical_80f90b97d0 is
2219
  signal d0_1_24: std_logic;
2220
  signal d1_1_27: std_logic;
2221
  signal fully_2_1_bit: std_logic;
2222
begin
2223
  d0_1_24 <= d0(0);
2224
  d1_1_27 <= d1(0);
2225
  fully_2_1_bit <= d0_1_24 and d1_1_27;
2226
  y <= std_logic_to_vector(fully_2_1_bit);
2227
end behavior;
2228
 

powered by: WebSVN 2.1.0

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