Project

General

Profile

Download (31 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc
3

    
4
-- This file is part of VESTs (Vhdl tESTs).
5

    
6
-- VESTs is free software; you can redistribute it and/or modify it
7
-- under the terms of the GNU General Public License as published by the
8
-- Free Software Foundation; either version 2 of the License, or (at
9
-- your option) any later version. 
10

    
11
-- VESTs is distributed in the hope that it will be useful, but WITHOUT
12
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
-- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
-- for more details. 
15

    
16
-- You should have received a copy of the GNU General Public License
17
-- along with VESTs; if not, write to the Free Software Foundation,
18
-- Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
19

    
20
-- ---------------------------------------------------------------------
21
--
22
-- $Id: ch_10_bvat-b.vhd,v 1.3 2001-10-26 16:29:35 paw Exp $
23
-- $Revision: 1.3 $
24
--
25
-- ---------------------------------------------------------------------
26

    
27
library bv_utilities;
28

    
29
use std.textio.all, bv_utilities.bv_arithmetic.all;
30

    
31
architecture bench of bv_test is
32
  
33
begin
34

    
35
  process is
36

    
37
            variable L : line;
38
          variable byte : bit_vector(0 to 7);
39
          variable word : bit_vector(1 to 32);
40
          variable half_byte : bit_vector(1 to 4);
41
          variable overflow, div_by_zero, result : boolean;
42

    
43
  begin
44
    wait for 1 ns;
45

    
46
    ----------------------------------------------------------------
47
    ----------------------------------------------------------------
48
    -- test bit_vector to numeric conversions
49
    ----------------------------------------------------------------
50
    ----------------------------------------------------------------
51

    
52
    write(L, string'("Testing bv_to_natural:"));
53
    writeline(output, L);
54

    
55
    write(L, string'("  bv_to_natural(X""02"") = "));
56
    write(L, bv_to_natural(X"02"));
57
    writeline(output, L);
58
    assert bv_to_natural(X"02") = 2;
59

    
60
    write(L, string'("  bv_to_natural(X""FE"") = "));
61
    write(L, bv_to_natural(X"FE"));
62
    writeline(output, L);
63
    assert bv_to_natural(X"FE") = 254;
64

    
65
    ----------------------------------------------------------------
66

    
67
    write(L, string'("Testing natural_to_bv:"));
68
    writeline(output, L);
69

    
70
    write(L, string'("  natural_to_bv(2) = "));
71
    write(L, natural_to_bv(2, 8));
72
    writeline(output, L);
73
    assert natural_to_bv(2, 8) = X"02";
74

    
75
    write(L, string'("  natural_to_bv(254) = "));
76
    write(L, natural_to_bv(254, 8));
77
    writeline(output, L);
78
    assert natural_to_bv(254, 8) = X"FE";
79

    
80
    ----------------------------------------------------------------
81

    
82
    write(L, string'("Testing bv_to_integer:"));
83
    writeline(output, L);
84

    
85
    write(L, string'("  bv_to_integer(X""02"") = "));
86
    write(L, bv_to_integer(X"02"));
87
    writeline(output, L);
88
    assert bv_to_integer(X"02") = 2;
89

    
90
    write(L, string'("  bv_to_integer(X""FE"") = "));
91
    write(L, bv_to_integer(X"FE"));
92
    writeline(output, L);
93
    assert bv_to_integer(X"FE") = -2;
94

    
95
    ----------------------------------------------------------------
96

    
97
    write(L, string'("Testing integer_to_bv:"));
98
    writeline(output, L);
99

    
100
    write(L, string'("  integer_to_bv(2) = "));
101
    write(L, integer_to_bv(2, 8));
102
    writeline(output, L);
103
    assert integer_to_bv(2, 8) = X"02";
104

    
105
    write(L, string'("  integer_to_bv(-2) = "));
106
    write(L, integer_to_bv(-2, 8));
107
    writeline(output, L);
108
    assert integer_to_bv(-2, 8) = X"FE";
109

    
110

    
111
    ----------------------------------------------------------------
112
    ----------------------------------------------------------------
113
    --  Arithmetic operations
114
    ----------------------------------------------------------------
115
    ----------------------------------------------------------------
116

    
117
    ----------------------------------------------------------------
118
    -- bv_add: Signed addition with overflow detection
119
    ----------------------------------------------------------------
120

    
121
    writeline(output, L);
122
    write(L, string'("Testing bv_add with overflow:"));
123
    writeline(output, L);
124

    
125
    write(L, string'("  2+2 = "));
126
    bv_add(X"02", X"02", byte, overflow);
127
    write(L, byte);
128
    write(L, string'(", overflow = "));  write(L, overflow);
129
    writeline(output, L);
130
    assert byte = X"04" and not overflow;
131

    
132
    write(L, string'("  2+(-3) = "));
133
    bv_add(X"02", X"FD", byte, overflow);
134
    write(L, byte);
135
    write(L, string'(", overflow = "));  write(L, overflow);
136
    writeline(output, L);
137
    assert byte = X"FF" and not overflow;
138

    
139
    write(L, string'("  64+64 = "));
140
    bv_add(X"40", X"40", byte, overflow);
141
    write(L, byte);
142
    write(L, string'(", overflow = "));  write(L, overflow);
143
    writeline(output, L);
144
    assert byte = X"80" and overflow;
145

    
146
    write(L, string'("  -64+(-64) = "));
147
    bv_add(X"C0", X"C0", byte, overflow);
148
    write(L, byte);
149
    write(L, string'(", overflow = "));  write(L, overflow);
150
    writeline(output, L);
151
    assert byte = X"80" and not overflow;
152

    
153
    ----------------------------------------------------------------
154
    -- "+": Signed addition without overflow detection
155
    ----------------------------------------------------------------
156

    
157
    writeline(output, L);
158
    write(L, string'("Testing ""+"" without overflow:"));
159
    writeline(output, L);
160

    
161
    write(L, string'("  2+2 = "));
162
    byte := X"02" + X"02";
163
    write(L, byte);
164
    writeline(output, L);
165
    assert byte = X"04";
166

    
167
    write(L, string'("  2+(-3) = "));
168
    byte := X"02" + X"FD";
169
    write(L, byte);
170
    writeline(output, L);
171
    assert byte = X"FF";
172

    
173
    write(L, string'("  64+64 = "));
174
    byte := X"40" + X"40";
175
    write(L, byte);
176
    writeline(output, L);
177
    assert byte = X"80";
178

    
179
    write(L, string'("  -64+(-64) = "));
180
    byte := X"C0" + X"C0";
181
    write(L, byte);
182
    writeline(output, L);
183
    assert byte = X"80";
184

    
185
    ----------------------------------------------------------------
186
    -- bv_sub: Signed subtraction with overflow detection
187
    ----------------------------------------------------------------
188
    
189
    writeline(output, L);
190
    write(L, string'("Testing bv_sub with overflow:"));
191
    writeline(output, L);
192

    
193
    write(L, string'("  2-2 = "));
194
    bv_sub(X"02", X"02", byte, overflow);
195
    write(L, byte);
196
    write(L, string'(", overflow = "));  write(L, overflow);
197
    writeline(output, L);
198
    assert byte = X"00" and not overflow;
199

    
200
    write(L, string'("  2-(-3) = "));
201
    bv_sub(X"02", X"FD", byte, overflow);
202
    write(L, byte);
203
    write(L, string'(", overflow = "));  write(L, overflow);
204
    writeline(output, L);
205
    assert byte = X"05" and not overflow;
206

    
207
    write(L, string'("  64-(-64) = "));
208
    bv_sub(X"40", X"C0", byte, overflow);
209
    write(L, byte);
210
    write(L, string'(", overflow = "));  write(L, overflow);
211
    writeline(output, L);
212
    assert byte = X"80" and overflow;
213

    
214
    write(L, string'("  -64-64 = "));
215
    bv_sub(X"C0", X"40", byte, overflow);
216
    write(L, byte);
217
    write(L, string'(", overflow = "));  write(L, overflow);
218
    writeline(output, L);
219
    assert byte = X"80" and not overflow;
220

    
221
    ----------------------------------------------------------------
222
    -- "-": Signed subtraction without overflow detection
223
    ----------------------------------------------------------------
224

    
225
    writeline(output, L);
226
    write(L, string'("Testing ""-"" without overflow:"));
227
    writeline(output, L);
228

    
229
    write(L, string'("  2-2 = "));
230
    byte := X"02" - X"02";
231
    write(L, byte);
232
    writeline(output, L);
233
    assert byte = X"00";
234

    
235
    write(L, string'("  2-(-3) = "));
236
    byte := X"02" - X"FD";
237
    write(L, byte);
238
    writeline(output, L);
239
    assert byte = X"05";
240

    
241
    write(L, string'("  64-(-64) = "));
242
    byte := X"40" - X"C0";
243
    write(L, byte);
244
    writeline(output, L);
245
    assert byte = X"80";
246

    
247
    write(L, string'("  -64-64 = "));
248
    byte := X"C0" - X"40";
249
    write(L, byte);
250
    writeline(output, L);
251
    assert byte = X"80";
252

    
253
    ----------------------------------------------------------------
254
    -- bv_addu:  Unsigned addition with overflow detection
255
    ----------------------------------------------------------------
256

    
257
    writeline(output, L);
258
    write(L, string'("Testing bv_addu with overflow:"));
259
    writeline(output, L);
260

    
261
    write(L, string'("  2+2 = "));
262
    bv_addu(X"02", X"02", byte, overflow);
263
    write(L, byte);
264
    write(L, string'(", overflow = "));  write(L, overflow);
265
    writeline(output, L);
266
    assert byte = X"04" and not overflow;
267

    
268
    write(L, string'("  64+64 = "));
269
    bv_addu(X"40", X"40", byte, overflow);
270
    write(L, byte);
271
    write(L, string'(", overflow = "));  write(L, overflow);
272
    writeline(output, L);
273
    assert byte = X"80" and not overflow;
274

    
275
    write(L, string'("  128+128 = "));
276
    bv_addu(X"80", X"80", byte, overflow);
277
    write(L, byte);
278
    write(L, string'(", overflow = "));  write(L, overflow);
279
    writeline(output, L);
280
    assert byte = X"00" and overflow;
281

    
282
    ----------------------------------------------------------------
283
    -- bv_addu: Unsigned addition without overflow detection
284
    ----------------------------------------------------------------
285

    
286
    writeline(output, L);
287
    write(L, string'("Testing bv_addu without overflow:"));
288
    writeline(output, L);
289

    
290
    write(L, string'("  2+2 = "));
291
    byte := bv_addu(X"02", X"02");
292
    write(L, byte);
293
    writeline(output, L);
294
    assert byte = X"04";
295

    
296
    write(L, string'("  64+64 = "));
297
    byte := bv_addu(X"40", X"40");
298
    write(L, byte);
299
    writeline(output, L);
300
    assert byte = X"80";
301

    
302
    write(L, string'("  128+128 = "));
303
    byte := bv_addu(X"80", X"80");
304
    write(L, byte);
305
    writeline(output, L);
306
    assert byte = X"00";
307

    
308
    ----------------------------------------------------------------
309
    -- bv_subu: Unsigned subtraction with overflow detection
310
    ----------------------------------------------------------------
311

    
312
    writeline(output, L);
313
    write(L, string'("Testing bv_subu with overflow:"));
314
    writeline(output, L);
315

    
316
    write(L, string'("  3-2 = "));
317
    bv_subu(X"03", X"02", byte, overflow);
318
    write(L, byte);
319
    write(L, string'(", overflow = "));  write(L, overflow);
320
    writeline(output, L);
321
    assert byte = X"01" and not overflow;
322

    
323
    write(L, string'("  64-64 = "));
324
    bv_subu(X"40", X"40", byte, overflow);
325
    write(L, byte);
326
    write(L, string'(", overflow = "));  write(L, overflow);
327
    writeline(output, L);
328
    assert byte = X"00" and not overflow;
329

    
330
    write(L, string'("  64-128 = "));
331
    bv_subu(X"40", X"80", byte, overflow);
332
    write(L, byte);
333
    write(L, string'(", overflow = "));  write(L, overflow);
334
    writeline(output, L);
335
    assert byte = X"C0" and overflow;
336

    
337
    ----------------------------------------------------------------
338
    -- bv_subu: Unsigned subtraction without overflow detection
339
    ----------------------------------------------------------------
340

    
341
    writeline(output, L);
342
    write(L, string'("Testing bv_subu without overflow:"));
343
    writeline(output, L);
344

    
345
    write(L, string'("  3-2 = "));
346
    byte := bv_subu(X"03", X"02");
347
    write(L, byte);
348
    writeline(output, L);
349
    assert byte = X"01";
350

    
351
    write(L, string'("  64-64 = "));
352
    byte := bv_subu(X"40", X"40");
353
    write(L, byte);
354
    writeline(output, L);
355
    assert byte = X"00";
356

    
357
    write(L, string'("  64-128 = "));
358
    byte := bv_subu(X"40", X"80");
359
    write(L, byte);
360
    writeline(output, L);
361
    assert byte = X"C0";
362

    
363
    ----------------------------------------------------------------
364
    -- bv_neg: Signed negation with overflow detection
365
    ----------------------------------------------------------------
366

    
367
    writeline(output, L);
368
    write(L, string'("Testing bv_neg with overflow:"));
369
    writeline(output, L);
370

    
371
    write(L, string'("  -(3) = "));
372
    bv_neg(X"03", byte, overflow);
373
    write(L, byte);
374
    write(L, string'(", overflow = "));  write(L, overflow);
375
    writeline(output, L);
376
    assert byte = X"FD" and not overflow;
377

    
378
    write(L, string'("  -(-3) = "));
379
    bv_neg(X"FD", byte, overflow);
380
    write(L, byte);
381
    write(L, string'(", overflow = "));  write(L, overflow);
382
    writeline(output, L);
383
    assert byte = X"03" and not overflow;
384

    
385
    write(L, string'("  -(127) = "));
386
    bv_neg(X"7F", byte, overflow);
387
    write(L, byte);
388
    write(L, string'(", overflow = "));  write(L, overflow);
389
    writeline(output, L);
390
    assert byte = X"81" and not overflow;
391

    
392
    write(L, string'("  -(-128) = "));
393
    bv_neg(X"80", byte, overflow);
394
    write(L, byte);
395
    write(L, string'(", overflow = "));  write(L, overflow);
396
    writeline(output, L);
397
    assert byte = X"80" and overflow;
398

    
399
    ----------------------------------------------------------------
400
    -- "-": Signed negation without overflow detection
401
    ----------------------------------------------------------------
402

    
403
    writeline(output, L);
404
    write(L, string'("Testing ""-"" without overflow:"));
405
    writeline(output, L);
406

    
407
    write(L, string'("  -(3) = "));
408
    byte := - X"03";
409
    write(L, byte);
410
    writeline(output, L);
411
    assert byte = X"FD";
412

    
413
    write(L, string'("  -(-3) = "));
414
    byte := - X"FD";
415
    write(L, byte);
416
    writeline(output, L);
417
    assert byte = X"03";
418

    
419
    write(L, string'("  -(127) = "));
420
    byte := - X"7F";
421
    write(L, byte);
422
    writeline(output, L);
423
    assert byte = X"81";
424

    
425
    write(L, string'("  -(-128) = "));
426
    byte := - X"80";
427
    write(L, byte);
428
    writeline(output, L);
429
    assert byte = X"80";
430

    
431
    ----------------------------------------------------------------
432
    -- bv_mult: Signed multiplication with overflow detection
433
    ----------------------------------------------------------------
434

    
435
    writeline(output, L);
436
    write(L, string'("Testing bv_mult with overflow:"));
437
    writeline(output, L);
438

    
439
    write(L, string'("  5*(-3) = "));
440
    bv_mult(X"05", X"FD", byte, overflow);
441
    write(L, byte);
442
    write(L, string'(", overflow = "));  write(L, overflow);
443
    writeline(output, L);
444
    assert byte = X"F1" and not overflow;
445

    
446
    write(L, string'("  (-5)*(-3) = "));
447
    bv_mult(X"FB", X"FD", byte, overflow);
448
    write(L, byte);
449
    write(L, string'(", overflow = "));  write(L, overflow);
450
    writeline(output, L);
451
    assert byte = X"0F" and not overflow;
452

    
453
    write(L, string'("  16*8 = "));
454
    bv_mult(X"10", X"08", byte, overflow);
455
    write(L, byte);
456
    write(L, string'(", overflow = "));  write(L, overflow);
457
    writeline(output, L);
458
    assert byte = X"80" and overflow;
459

    
460
    write(L, string'("  16*16 = "));
461
    bv_mult(X"10", X"10", byte, overflow);
462
    write(L, byte);
463
    write(L, string'(", overflow = "));  write(L, overflow);
464
    writeline(output, L);
465
    assert byte = X"00" and overflow;
466

    
467
    write(L, string'("  16*(-8) = "));
468
    bv_mult(X"10", X"F8", byte, overflow);
469
    write(L, byte);
470
    write(L, string'(", overflow = "));  write(L, overflow);
471
    writeline(output, L);
472
    assert byte = X"80" and not overflow;
473

    
474
    write(L, string'("  16*(-16) = "));
475
    bv_mult(X"10", X"F0", byte, overflow);
476
    write(L, byte);
477
    write(L, string'(", overflow = "));  write(L, overflow);
478
    writeline(output, L);
479
    assert byte = X"00" and overflow;
480

    
481
    ----------------------------------------------------------------
482
    -- "*":  Signed multiplication without overflow detection
483
    ----------------------------------------------------------------
484

    
485
    writeline(output, L);
486
    write(L, string'("Testing ""*"" without overflow:"));
487
    writeline(output, L);
488

    
489
    write(L, string'("  5*(-3) = "));
490
    byte := X"05" * X"FD";
491
    write(L, byte);
492
    writeline(output, L);
493
    assert byte = X"F1";
494

    
495
    write(L, string'("  (-5)*(-3) = "));
496
    byte := X"FB" * X"FD";
497
    write(L, byte);
498
    writeline(output, L);
499
    assert byte = X"0F";
500

    
501
    write(L, string'("  16*8 = "));
502
    byte := X"10" * X"08";
503
    write(L, byte);
504
    writeline(output, L);
505
    assert byte = X"80";
506

    
507
    write(L, string'("  16*16 = "));
508
    byte := X"10" * X"10";
509
    write(L, byte);
510
    writeline(output, L);
511
    assert byte = X"00";
512

    
513
    write(L, string'("  16*(-8) = "));
514
    byte := X"10" * X"F8";
515
    write(L, byte);
516
    writeline(output, L);
517
    assert byte = X"80";
518

    
519
    write(L, string'("  16*(-16) = "));
520
    byte := X"10" * X"F0";
521
    write(L, byte);
522
    writeline(output, L);
523
    assert byte = X"00";
524

    
525
    ----------------------------------------------------------------
526
    -- bv_multu:  Unsigned multiplication with overflow detection
527
    ----------------------------------------------------------------
528

    
529
    writeline(output, L);
530
    write(L, string'("Testing bv_multu with overflow:"));
531
    writeline(output, L);
532

    
533
    write(L, string'("  5*7 = "));
534
    bv_multu(X"05", X"07", byte, overflow);
535
    write(L, byte);
536
    write(L, string'(", overflow = "));  write(L, overflow);
537
    writeline(output, L);
538
    assert byte = X"23" and not overflow;
539

    
540
    write(L, string'("  16*8 = "));
541
    bv_multu(X"10", X"08", byte, overflow);
542
    write(L, byte);
543
    write(L, string'(", overflow = "));  write(L, overflow);
544
    writeline(output, L);
545
    assert byte = X"80" and not overflow;
546

    
547
    write(L, string'("  16*16 = "));
548
    bv_multu(X"10", X"10", byte, overflow);
549
    write(L, byte);
550
    write(L, string'(", overflow = "));  write(L, overflow);
551
    writeline(output, L);
552
    assert byte = X"00" and overflow;
553

    
554
    ----------------------------------------------------------------
555
    --  bv_multu: Unsigned multiplication without overflow detection
556
    ----------------------------------------------------------------
557

    
558
    writeline(output, L);
559
    write(L, string'("Testing bv_multu without overflow:"));
560
    writeline(output, L);
561

    
562
    write(L, string'("  5*7 = "));
563
    byte := bv_multu(X"05", X"07");
564
    write(L, byte);
565
    writeline(output, L);
566
    assert byte = X"23";
567

    
568
    write(L, string'("  16*8 = "));
569
    byte := bv_multu(X"10", X"08");
570
    write(L, byte);
571
    writeline(output, L);
572
    assert byte = X"80";
573

    
574
    write(L, string'("  16*16 = "));
575
    byte := bv_multu(X"10", X"10");
576
    write(L, byte);
577
    writeline(output, L);
578
    assert byte = X"00";
579

    
580
    ----------------------------------------------------------------
581
    -- bv_div: Signed division with divide by zero and overflow detection
582
    ----------------------------------------------------------------
583

    
584
    writeline(output, L);
585
    write(L, string'("Testing bv_div with flags:"));
586
    writeline(output, L);
587

    
588
    write(L, string'("  7/2 = "));
589
    bv_div(X"07", X"02", byte, div_by_zero, overflow);
590
    write(L, byte);
591
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
592
    write(L, string'(", overflow = "));  write(L, overflow);
593
    writeline(output, L);
594
    assert byte = X"03" and not div_by_zero and not overflow;
595

    
596
    write(L, string'("  -7/2 = "));
597
    bv_div(X"F9", X"02", byte, div_by_zero, overflow);
598
    write(L, byte);
599
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
600
    write(L, string'(", overflow = "));  write(L, overflow);
601
    writeline(output, L);
602
    assert byte = X"FD" and not div_by_zero and not overflow;
603

    
604
    write(L, string'("  7/-2 = "));
605
    bv_div(X"07", X"FE", byte, div_by_zero, overflow);
606
    write(L, byte);
607
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
608
    write(L, string'(", overflow = "));  write(L, overflow);
609
    writeline(output, L);
610
    assert byte = X"FD" and not div_by_zero and not overflow;
611

    
612
    write(L, string'("  -7/-2 = "));
613
    bv_div(X"F9", X"FE", byte, div_by_zero, overflow);
614
    write(L, byte);
615
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
616
    write(L, string'(", overflow = "));  write(L, overflow);
617
    writeline(output, L);
618
    assert byte = X"03" and not div_by_zero and not overflow;
619

    
620
    write(L, string'("  -128/1 = "));
621
    bv_div(X"80", X"01", byte, div_by_zero, overflow);
622
    write(L, byte);
623
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
624
    write(L, string'(", overflow = "));  write(L, overflow);
625
    writeline(output, L);
626
    assert byte = X"80" and not div_by_zero and not overflow;
627

    
628
    write(L, string'("  -128/-1 = "));
629
    bv_div(X"80", X"FF", byte, div_by_zero, overflow);
630
    write(L, byte);
631
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
632
    write(L, string'(", overflow = "));  write(L, overflow);
633
    writeline(output, L);
634
    assert byte = X"80" and not div_by_zero and overflow;
635

    
636
    write(L, string'("  -16/0 = "));
637
    bv_div(X"F0", X"00", byte, div_by_zero, overflow);
638
    write(L, byte);
639
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
640
    write(L, string'(", overflow = "));  write(L, overflow);
641
    writeline(output, L);
642
    assert byte = X"00" and div_by_zero and not overflow;
643

    
644
    ----------------------------------------------------------------
645
    -- "/": Signed division without divide by zero and overflow detection
646
    ----------------------------------------------------------------
647

    
648
    writeline(output, L);
649
    write(L, string'("Testing ""/"" without flags:"));
650
    writeline(output, L);
651

    
652
    write(L, string'("  7/2 = "));
653
    byte := X"07" / X"02";
654
    write(L, byte);
655
    writeline(output, L);
656
    assert byte = X"03";
657

    
658
    write(L, string'("  -7/2 = "));
659
    byte := X"F9" / X"02";
660
    write(L, byte);
661
    writeline(output, L);
662
    assert byte = X"FD";
663

    
664
    write(L, string'("  7/-2 = "));
665
    byte := X"07" / X"FE";
666
    write(L, byte);
667
    writeline(output, L);
668
    assert byte = X"FD";
669

    
670
    write(L, string'("  -7/-2 = "));
671
    byte := X"F9" / X"FE";
672
    write(L, byte);
673
    writeline(output, L);
674
    assert byte = X"03";
675

    
676
    write(L, string'("  -128/1 = "));
677
    byte := X"80" / X"01";
678
    write(L, byte);
679
    writeline(output, L);
680
    assert byte = X"80";
681

    
682
    write(L, string'("  -128/-1 = "));
683
    byte := X"80" / X"FF";
684
    write(L, byte);
685
    writeline(output, L);
686
    assert byte = X"80";
687

    
688
    write(L, string'("  -16/0 = "));
689
    byte := X"F0" / X"00";
690
    write(L, byte);
691
    writeline(output, L);
692
    assert byte = X"00";
693

    
694
    ----------------------------------------------------------------
695
    -- bv_divu: Unsigned division with divide by zero detection
696
    ----------------------------------------------------------------
697

    
698
    writeline(output, L);
699
    write(L, string'("Testing bv_divu with flag:"));
700
    writeline(output, L);
701

    
702
    write(L, string'("  7/2 = "));
703
    bv_divu(X"07", X"02", byte, div_by_zero);
704
    write(L, byte);
705
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
706
    writeline(output, L);
707
    assert byte = X"03" and not div_by_zero;
708

    
709
    write(L, string'("  14/7 = "));
710
    bv_divu(X"0E", X"07", byte, div_by_zero);
711
    write(L, byte);
712
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
713
    writeline(output, L);
714
    assert byte = X"02" and not div_by_zero;
715

    
716
    write(L, string'("  16/1 = "));
717
    bv_divu(X"10", X"01", byte, div_by_zero);
718
    write(L, byte);
719
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
720
    writeline(output, L);
721
    assert byte = X"10" and not div_by_zero;
722

    
723
    write(L, string'("  16/0 = "));
724
    bv_divu(X"10", X"00", byte, div_by_zero);
725
    write(L, byte);
726
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
727
    writeline(output, L);
728
    assert byte = X"10" and div_by_zero;
729

    
730
    write(L, string'("  16/16 = "));
731
    bv_divu(X"10", X"10", byte, div_by_zero);
732
    write(L, byte);
733
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
734
    writeline(output, L);
735
    assert byte = X"01" and not div_by_zero;
736

    
737
    write(L, string'("  1/16 = "));
738
    bv_divu(X"01", X"10", byte, div_by_zero);
739
    write(L, byte);
740
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
741
    writeline(output, L);
742
    assert byte = X"00" and not div_by_zero;
743

    
744
    write(L, string'("  255/1 = "));
745
    bv_divu(X"FF", X"01", byte, div_by_zero);
746
    write(L, byte);
747
    write(L, string'(", div_by_zero = "));  write(L, div_by_zero);
748
    writeline(output, L);
749
    assert byte = X"FF" and not div_by_zero;
750

    
751
    ----------------------------------------------------------------
752
    -- bv_divu: Unsigned division without divide by zero detection
753
    ----------------------------------------------------------------
754

    
755
    writeline(output, L);
756
    write(L, string'("Testing bv_divu without flag:"));
757
    writeline(output, L);
758

    
759
    write(L, string'("  7/2 = "));
760
    byte := bv_divu(X"07", X"02");
761
    write(L, byte);
762
    writeline(output, L);
763
    assert byte = X"03";
764

    
765
    write(L, string'("  14/7 = "));
766
    byte := bv_divu(X"0E", X"07");
767
    write(L, byte);
768
    writeline(output, L);
769
    assert byte = X"02";
770

    
771
    write(L, string'("  16/1 = "));
772
    byte := bv_divu(X"10", X"01");
773
    write(L, byte);
774
    writeline(output, L);
775
    assert byte = X"10";
776

    
777
    write(L, string'("  16/0 = "));
778
    byte := bv_divu(X"10", X"00");
779
    write(L, byte);
780
    writeline(output, L);
781
    assert byte = X"00";
782

    
783
    write(L, string'("  16/16 = "));
784
    byte := bv_divu(X"10", X"10");
785
    write(L, byte);
786
    writeline(output, L);
787
    assert byte = X"01";
788

    
789
    write(L, string'("  1/16 = "));
790
    byte := bv_divu(X"01", X"10");
791
    write(L, byte);
792
    writeline(output, L);
793
    assert byte = X"00";
794

    
795
    write(L, string'("  255/1 = "));
796
    byte := bv_divu(X"FF", X"01");
797
    write(L, byte);
798
    writeline(output, L);
799
    assert byte = X"FF";
800

    
801

    
802
    ----------------------------------------------------------------
803
    ----------------------------------------------------------------
804
    --  Arithmetic comparison operators.
805
    ----------------------------------------------------------------
806
    ----------------------------------------------------------------
807

    
808
    ----------------------------------------------------------------
809
    -- bv_lt: Signed less than comparison
810
    ----------------------------------------------------------------
811

    
812
    writeline(output, L);
813
    write(L, string'("Testing bv_lt:"));
814
    writeline(output, L);
815

    
816
    write(L, string'("  2 < 2 = "));
817
    result := bv_lt(X"02", X"02");
818
    write(L, result);
819
    writeline(output, L);
820
    assert NOT result;
821

    
822
    write(L, string'("  2 < 3 = "));
823
    result := bv_lt(X"02", X"03");
824
    write(L, result);
825
    writeline(output, L);
826
    assert result;
827

    
828
    write(L, string'("  -2 < 2 = "));
829
    result := bv_lt(X"FE", X"02");
830
    write(L, result);
831
    writeline(output, L);
832
    assert result;
833

    
834
    write(L, string'("  2 < -3 = "));
835
    result := bv_lt(X"02", X"FD");
836
    write(L, result);
837
    writeline(output, L);
838
    assert NOT result;
839

    
840
    ----------------------------------------------------------------
841
    -- bv_le: Signed less than or equal comparison
842
    ----------------------------------------------------------------
843

    
844
    writeline(output, L);
845
    write(L, string'("Testing bv_le:"));
846
    writeline(output, L);
847

    
848
    write(L, string'("  2 <= 2 = "));
849
    result := bv_le(X"02", X"02");
850
    write(L, result);
851
    writeline(output, L);
852
    assert result;
853

    
854
    write(L, string'("  2 <= 3 = "));
855
    result := bv_le(X"02", X"03");
856
    write(L, result);
857
    writeline(output, L);
858
    assert result;
859

    
860
    write(L, string'("  -2 <= 2 = "));
861
    result := bv_le(X"FE", X"02");
862
    write(L, result);
863
    writeline(output, L);
864
    assert result;
865

    
866
    write(L, string'("  2 <= -3 = "));
867
    result := bv_le(X"02", X"FD");
868
    write(L, result);
869
    writeline(output, L);
870
    assert NOT result;
871

    
872
    ----------------------------------------------------------------
873
    -- bv_gt: Signed greater than comparison
874
    ----------------------------------------------------------------
875

    
876
    writeline(output, L);
877
    write(L, string'("Testing bv_gt:"));
878
    writeline(output, L);
879

    
880
    write(L, string'("  2 > 2 = "));
881
    result := bv_gt(X"02", X"02");
882
    write(L, result);
883
    writeline(output, L);
884
    assert NOT result;
885

    
886
    write(L, string'("  3 > 2 = "));
887
    result := bv_gt(X"03", X"02");
888
    write(L, result);
889
    writeline(output, L);
890
    assert result;
891

    
892
    write(L, string'("  2 > -2 = "));
893
    result := bv_gt(X"02", X"FE");
894
    write(L, result);
895
    writeline(output, L);
896
    assert result;
897

    
898
    write(L, string'("  -3 > 2 = "));
899
    result := bv_gt(X"FD", X"02");
900
    write(L, result);
901
    writeline(output, L);
902
    assert NOT result;
903

    
904
    ----------------------------------------------------------------
905
    -- bv_ge: Signed greater than or equal comparison
906
    ----------------------------------------------------------------
907

    
908
    writeline(output, L);
909
    write(L, string'("Testing bv_ge:"));
910
    writeline(output, L);
911

    
912
    write(L, string'("  2 >= 2 = "));
913
    result := bv_ge(X"02", X"02");
914
    write(L, result);
915
    writeline(output, L);
916
    assert result;
917

    
918
    write(L, string'("  3 >= 2 = "));
919
    result := bv_ge(X"03", X"02");
920
    write(L, result);
921
    writeline(output, L);
922
    assert result;
923

    
924
    write(L, string'("  2 >= -2 = "));
925
    result := bv_ge(X"02", X"FE");
926
    write(L, result);
927
    writeline(output, L);
928
    assert result;
929

    
930
    write(L, string'("  -3 >= 2 = "));
931
    result := bv_ge(X"FD", X"02");
932
    write(L, result);
933
    writeline(output, L);
934
    assert NOT result;
935

    
936
    ----------------------------------------------------------------
937
    ----------------------------------------------------------------
938
    --  Extension operators - convert a bit vector to a longer one
939
    ----------------------------------------------------------------
940
    ----------------------------------------------------------------
941

    
942
    ----------------------------------------------------------------
943
    -- bv_sext: Sign extension
944
    ----------------------------------------------------------------
945

    
946
    writeline(output, L);
947
    write(L, string'("Testing bv_sext:"));
948
    writeline(output, L);
949

    
950
    write(L, string'("  sext(X""02"", 32) = "));
951
    word := bv_sext(X"02", 32);
952
    write(L, word);
953
    writeline(output, L);
954
    assert word = X"00000002";
955

    
956
    write(L, string'("  sext(X""FE"", 32) = "));
957
    word := bv_sext(X"FE", 32);
958
    write(L, word);
959
    writeline(output, L);
960
    assert word = X"FFFFFFFE";
961

    
962
    write(L, string'("  sext(X""02"", 8) = "));
963
    byte := bv_sext(X"02", 8);
964
    write(L, byte);
965
    writeline(output, L);
966
    assert byte = X"02";
967

    
968
    write(L, string'("  sext(X""FE"", 8) = "));
969
    byte := bv_sext(X"FE", 8);
970
    write(L, byte);
971
    writeline(output, L);
972
    assert byte = X"FE";
973

    
974
    write(L, string'("  sext(X""02"", 4) = "));
975
    half_byte := bv_sext(X"02", 4);
976
    write(L, half_byte);
977
    writeline(output, L);
978
    assert half_byte = X"2";
979

    
980
    write(L, string'("  sext(X""FE"", 4) = "));
981
    half_byte := bv_sext(X"FE", 4);
982
    write(L, half_byte);
983
    writeline(output, L);
984
    assert half_byte = X"E";
985

    
986
    ----------------------------------------------------------------
987
    -- bv_zext" Zero extension
988
    ----------------------------------------------------------------
989

    
990
    writeline(output, L);
991
    write(L, string'("Testing bv_zext:"));
992
    writeline(output, L);
993

    
994
    write(L, string'("  zext(X""02"", 32) = "));
995
    word := bv_zext(X"02", 32);
996
    write(L, word);
997
    writeline(output, L);
998
    assert word = X"00000002";
999

    
1000
    write(L, string'("  zext(X""FE"", 32) = "));
1001
    word := bv_zext(X"FE", 32);
1002
    write(L, word);
1003
    writeline(output, L);
1004
    assert word = X"000000FE";
1005

    
1006
    write(L, string'("  zext(X""02"", 8) = "));
1007
    byte := bv_zext(X"02", 8);
1008
    write(L, byte);
1009
    writeline(output, L);
1010
    assert byte = X"02";
1011

    
1012
    write(L, string'("  zext(X""FE"", 8) = "));
1013
    byte := bv_zext(X"FE", 8);
1014
    write(L, byte);
1015
    writeline(output, L);
1016
    assert byte = X"FE";
1017

    
1018
    write(L, string'("  zext(X""02"", 4) = "));
1019
    half_byte := bv_zext(X"02", 4);
1020
    write(L, half_byte);
1021
    writeline(output, L);
1022
    assert half_byte = X"2";
1023

    
1024
    write(L, string'("  zext(X""FE"", 4) = "));
1025
    half_byte := bv_zext(X"FE", 4);
1026
    write(L, half_byte);
1027
    writeline(output, L);
1028
    assert half_byte = X"E";
1029

    
1030

    
1031
    wait;
1032
  end process;
1033

    
1034
end architecture bench;
(169-169/510)