default_constructor.cpp revision 12855:588919e0e4aa
1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22  default_constructor.cpp --
23
24  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32
33      Name, Affiliation, Date:
34  Description of Modification:
35
36 *****************************************************************************/
37
38// This may look like C code, but it is really -*- C++ -*-
39//
40// default_constructor.cxx --
41// Copyright Synopsys 1998
42// Author          : Ric Hilderink
43// Created On      : Wed Dec 30 09:38:31 1998
44// Status          : none
45//
46
47#include <limits.h>
48#include <float.h>
49#define SC_INCLUDE_FX
50#include "systemc.h"
51
52typedef unsigned int   uint;
53typedef unsigned short ushort;
54typedef unsigned long  ulong;
55
56#define SHOW(a) cerr << #a << " : " << double(a) << " : " << a.to_string(SC_HEX) << "\n"
57#define IDENT(a) cerr << "--default_constructor-Inf-Inf-Inf-Inf-Inf- " << a << "\n"
58
59#define T_CHAR_MAX "0b010101110100110111001011"
60#define T_CHAR_MIN "-0xsmdeadbeafe-101"
61#define T_UCHAR_MAX "0b010101110100110111001011e+101"
62#define T_UCHAR_MIN "0xdeadbeafe-101"
63
64static void test_fx_float_char()
65{
66  IDENT("test_fx_float_char");
67
68  sc_fxval a("0");
69  sc_fxval b("1");
70  sc_fxval c("-1");
71  sc_fxval d(T_CHAR_MAX);
72  sc_fxval e(T_CHAR_MIN);
73
74  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
75}
76
77static void test_fx_float_int()
78{
79  IDENT("test_fx_float_int");
80
81  sc_fxval a(0);
82  sc_fxval b(1);
83  sc_fxval c(-1);
84  sc_fxval d(INT_MAX);
85  sc_fxval e(INT_MIN);
86
87  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
88}
89
90static void test_fx_float_uint()
91{
92  IDENT("test_fx_float_uint");
93
94  sc_fxval a((uint)0);
95  sc_fxval b((uint)1);
96  sc_fxval c((uint)-1);
97  sc_fxval d(UINT_MAX);
98  sc_fxval e((uint)abs(INT_MIN));
99
100  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
101}
102
103static void test_fx_float_short()
104{
105  IDENT("test_fx_float_short");
106
107  sc_fxval a((short)0);
108  sc_fxval b((short)1);
109  sc_fxval c((short)-1);
110  sc_fxval d((short)SHRT_MAX);
111  sc_fxval e((short)SHRT_MIN);
112
113  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
114}
115
116static void test_fx_float_ushort()
117{
118  IDENT("test_fx_float_ushort");
119
120  sc_fxval a((ushort)0);
121  sc_fxval b((ushort)1);
122  sc_fxval c((ushort)-1);
123  sc_fxval d(USHRT_MAX);
124  sc_fxval e((ushort)abs(SHRT_MIN));
125
126  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
127}
128
129static void test_fx_float_long()
130{
131  IDENT("test_fx_float_long");
132
133  sc_fxval a((long)0);
134  sc_fxval b((long)1);
135  sc_fxval c((long)-1);
136  sc_fxval d(LONG_MAX);
137  sc_fxval e(LONG_MIN);
138
139  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
140}
141
142static void test_fx_float_ulong()
143{
144  IDENT("test_fx_float_ulong");
145
146  sc_fxval a((ulong)0);
147  sc_fxval b((ulong)1);
148  sc_fxval c((ulong)-1);
149  sc_fxval d(ULONG_MAX);
150  sc_fxval e((ulong)abs(LONG_MIN));
151
152  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
153}
154
155static void test_fx_float_float()
156{
157  IDENT("test_fx_float_float");
158
159  sc_fxval a(0.0);
160  sc_fxval b(1.0);
161  sc_fxval c(-1.0);
162  sc_fxval d(FLT_MAX);
163  sc_fxval e(FLT_MIN);
164
165  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
166}
167
168static void test_fx_float_double()
169{
170  IDENT("test_fx_float_double");
171
172  sc_fxval a((double)0.0);
173  sc_fxval b((double)1.0);
174  sc_fxval c((double)-1.0);
175  sc_fxval d(DBL_MAX);
176  sc_fxval e(DBL_MIN);
177
178  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
179}
180
181//-----------------------------------------------------------------------
182static void test_fx_ufix_char()
183{
184  IDENT("test_fx_ufix_char");
185
186  sc_ufix a("0");
187  sc_ufix b("1");
188  sc_ufix c("-1");
189  sc_ufix d(T_UCHAR_MAX);
190  sc_ufix e(T_UCHAR_MIN);
191
192  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
193}
194
195static void test_fx_ufix_int()
196{
197  IDENT("test_fx_ufix_int");
198
199  sc_ufix a(0);
200  sc_ufix b(1);
201  sc_ufix c(-1);
202  sc_ufix d(INT_MAX);
203  sc_ufix e(INT_MIN);
204
205  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
206}
207
208static void test_fx_ufix_uint()
209{
210  IDENT("test_fx_ufix_uint");
211
212  sc_ufix a((uint)0);
213  sc_ufix b((uint)1);
214  sc_ufix c((uint)-1);
215  sc_ufix d(UINT_MAX);
216  sc_ufix e((uint)abs(INT_MIN));
217
218  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
219}
220
221static void test_fx_ufix_short()
222{
223  IDENT("test_fx_ufix_short");
224
225  sc_ufix a((short)0);
226  sc_ufix b((short)1);
227  sc_ufix c((short)-1);
228  sc_ufix d(SHRT_MAX);
229  sc_ufix e(SHRT_MIN);
230
231  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
232}
233
234static void test_fx_ufix_ushort()
235{
236  IDENT("test_fx_ufix_ushort");
237
238  sc_ufix a((ushort)0);
239  sc_ufix b((ushort)1);
240  sc_ufix c((ushort)-1);
241  sc_ufix d(USHRT_MAX);
242  sc_ufix e((ushort)abs(SHRT_MIN));
243
244  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
245}
246
247static void test_fx_ufix_long()
248{
249  IDENT("test_fx_ufix_long");
250
251  sc_ufix a((long)0);
252  sc_ufix b((long)1);
253  sc_ufix c((long)-1);
254  sc_ufix d(LONG_MAX);
255  sc_ufix e(LONG_MIN);
256
257  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
258}
259
260static void test_fx_ufix_ulong()
261{
262  IDENT("test_fx_ufix_ulong");
263
264  sc_ufix a((ulong)0);
265  sc_ufix b((ulong)1);
266  sc_ufix c((ulong)-1);
267  sc_ufix d(ULONG_MAX);
268  sc_ufix e((ulong)abs(LONG_MIN));
269
270  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
271}
272
273static void test_fx_ufix_float()
274{
275  IDENT("test_fx_ufix_float");
276
277  sc_ufix a(0.0);
278  sc_ufix b(1.0);
279  sc_ufix c(-1.0);
280  sc_ufix d(FLT_MAX);
281  sc_ufix e(FLT_MIN);
282
283  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
284}
285
286static void test_fx_ufix_double()
287{
288  IDENT("test_fx_ufix_double");
289
290  sc_ufix a((double)0.0);
291  sc_ufix b((double)1.0);
292  sc_ufix c((double)-1.0);
293  sc_ufix d(DBL_MAX);
294  sc_ufix e(DBL_MIN);
295
296  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
297}
298
299//-----------------------------------------------------------------------
300static void test_fx_fix_char()
301{
302  IDENT("test_fx_fix_char");
303
304  sc_fix a("0"); SHOW(a);
305  sc_fix b("1"); SHOW(b);
306  sc_fix c("-1"); SHOW(c);
307  sc_fix d(T_CHAR_MAX); SHOW(d);
308  sc_fix e(T_CHAR_MIN); SHOW(e);
309
310  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
311}
312
313static void test_fx_fix_int()
314{
315  IDENT("test_fx_fix_int");
316
317  sc_fix a(0);
318  sc_fix b(1);
319  sc_fix c(-1);
320  sc_fix d(INT_MAX);
321  sc_fix e(INT_MIN);
322
323  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
324}
325
326static void test_fx_fix_uint()
327{
328  IDENT("test_fx_fix_uint");
329
330  sc_fix a((uint)0);
331  sc_fix b((uint)1);
332  sc_fix c((uint)-1);
333  sc_fix d(UINT_MAX);
334  sc_fix e((uint)abs(INT_MIN));
335
336  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
337}
338static void test_fx_fix_short()
339{
340  IDENT("test_fx_fix_short");
341
342  sc_fix a((short)0);
343  sc_fix b((short)1);
344  sc_fix c((short)-1);
345  sc_fix d(SHRT_MAX);
346  sc_fix e(SHRT_MIN);
347
348  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
349}
350
351static void test_fx_fix_ushort()
352{
353  IDENT("test_fx_fix_ushort");
354
355  sc_fix a((ushort)0);
356  sc_fix b((ushort)1);
357  sc_fix c((ushort)-1);
358  sc_fix d(USHRT_MAX);
359  sc_fix e((ushort)abs(SHRT_MIN));
360
361  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
362}
363
364static void test_fx_fix_long()
365{
366  IDENT("test_fx_fix_long");
367
368  sc_fix a((long)0);
369  sc_fix b((long)1);
370  sc_fix c((long)-1);
371  sc_fix d(LONG_MAX);
372  sc_fix e(LONG_MIN);
373
374  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
375}
376
377static void test_fx_fix_ulong()
378{
379  IDENT("test_fx_fix_ulong");
380
381  sc_fix a((ulong)0);
382  sc_fix b((ulong)1);
383  sc_fix c((ulong)-1);
384  sc_fix d(ULONG_MAX);
385  sc_fix e((ulong)abs(LONG_MIN));
386
387  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
388}
389
390static void test_fx_fix_float()
391{
392  IDENT("test_fx_fix_float");
393
394  sc_fix a(0.0);
395  sc_fix b(1.0);
396  sc_fix c(-1.0);
397  sc_fix d(FLT_MAX);
398  sc_fix e(FLT_MIN);
399
400  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
401}
402
403static void test_fx_fix_double()
404{
405  IDENT("test_fx_fix_double");
406
407  sc_fix a((double)0.0);
408  sc_fix b((double)1.0);
409  sc_fix c((double)-1.0);
410  sc_fix d(DBL_MAX);
411  sc_fix e(DBL_MIN);
412
413  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
414}
415
416//-----------------------------------------------------------------------
417static void test_fx_fixed_char()
418{
419  IDENT("test_fx_fixed_char");
420
421  sc_fixed<8, 5> a("0");
422  sc_fixed<8, 5> b("1");
423  sc_fixed<8, 5> c("-1");
424  sc_fixed<8, 5> d(T_CHAR_MAX);
425  sc_fixed<8, 5> e(T_CHAR_MIN);
426
427  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
428}
429
430static void test_fx_fixed_int()
431{
432  IDENT("test_fx_fixed_int");
433
434  sc_fixed<8, 5> a(0);
435  sc_fixed<8, 5> b(1);
436  sc_fixed<8, 5> c(-1);
437  sc_fixed<8, 5> d(INT_MAX);
438  sc_fixed<8, 5> e(INT_MIN);
439
440  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
441}
442
443static void test_fx_fixed_uint()
444{
445  IDENT("test_sc_fixed_uint");
446
447  sc_fixed<8, 5> a((uint)0);
448  sc_fixed<8, 5> b((uint)1);
449  sc_fixed<8, 5> c((uint)-1);
450  sc_fixed<8, 5> d(UINT_MAX);
451  sc_fixed<8, 5> e((uint)abs(INT_MIN));
452
453  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
454}
455
456static void test_fx_fixed_short()
457{
458  IDENT("test_fx_fixed_short");
459
460  sc_fixed<8, 5> a((short)0);
461  sc_fixed<8, 5> b((short)1);
462  sc_fixed<8, 5> c((short)-1);
463  sc_fixed<8, 5> d(SHRT_MAX);
464  sc_fixed<8, 5> e(SHRT_MIN);
465
466  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
467}
468
469static void test_fx_fixed_ushort()
470{
471  IDENT("test_sc_fixed_ushort");
472
473  sc_fixed<8, 5> a((ushort)0);
474  sc_fixed<8, 5> b((ushort)1);
475  sc_fixed<8, 5> c((ushort)-1);
476  sc_fixed<8, 5> d(USHRT_MAX);
477  sc_fixed<8, 5> e((ushort)abs(SHRT_MIN));
478
479  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
480}
481
482static void test_fx_fixed_long()
483{
484  IDENT("test_sc_fixeded_long");
485
486  sc_fixed<8, 5> a((long)0);
487  sc_fixed<8, 5> b((long)1);
488  sc_fixed<8, 5> c((long)-1);
489  sc_fixed<8, 5> d(LONG_MAX);
490  sc_fixed<8, 5> e(LONG_MIN);
491
492  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
493}
494
495static void test_fx_fixed_ulong()
496{
497  IDENT("test_fx_fixed_ulong");
498
499  sc_fixed<8, 5> a((ulong)0);
500  sc_fixed<8, 5> b((ulong)1);
501  sc_fixed<8, 5> c((ulong)-1);
502  sc_fixed<8, 5> d(ULONG_MAX);
503  sc_fixed<8, 5> e((ulong)abs(LONG_MIN));
504
505  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
506}
507
508static void test_fx_fixed_float()
509{
510  IDENT("test_fx_fixed_float");
511
512  sc_fixed<8, 5> a(0.0);
513  sc_fixed<8, 5> b(1.0);
514  sc_fixed<8, 5> c(-1.0);
515  sc_fixed<8, 5> d(FLT_MAX);
516  sc_fixed<8, 5> e(FLT_MIN);
517
518  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
519}
520
521static void test_fx_fixed_double()
522{
523  IDENT("test_fx_fixed_double");
524
525  sc_fixed<8, 5> a((double)0.0);
526  sc_fixed<8, 5> b((double)1.0);
527  sc_fixed<8, 5> c((double)-1.0);
528  sc_fixed<8, 5> d(DBL_MAX);
529  sc_fixed<8, 5> e(DBL_MIN);
530
531  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
532}
533
534//-----------------------------------------------------------------------
535static void test_fx_ufixed_char()
536{
537  IDENT("test_fx_ufixed_char");
538
539  sc_ufixed<8, 5> a("0");
540  sc_ufixed<8, 5> b("1");
541  sc_ufixed<8, 5> c("-1");
542  sc_ufixed<8, 5> d(T_UCHAR_MAX);
543  sc_ufixed<8, 5> e(T_UCHAR_MIN);
544
545  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
546}
547
548static void test_fx_ufixed_int()
549{
550  IDENT("test_fx_ufixed_int");
551
552  sc_ufixed<8, 5> a(0);
553  sc_ufixed<8, 5> b(1);
554  sc_ufixed<8, 5> c(-1);
555  sc_ufixed<8, 5> d(INT_MAX);
556  sc_ufixed<8, 5> e(INT_MIN);
557
558  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
559}
560
561static void test_fx_ufixed_uint()
562{
563  IDENT("test_fx_ufixed_uint");
564
565  sc_ufixed<8, 5> a((uint)0);
566  sc_ufixed<8, 5> b((uint)1);
567  sc_ufixed<8, 5> c((uint)-1);
568  sc_ufixed<8, 5> d(UINT_MAX);
569  sc_ufixed<8, 5> e((uint)abs(INT_MIN));
570
571  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
572}
573
574static void test_fx_ufixed_short()
575{
576  IDENT("test_fx_ufixed_short");
577
578  sc_ufixed<8, 5> a((short)0);
579  sc_ufixed<8, 5> b((short)1);
580  sc_ufixed<8, 5> c((short)-1);
581  sc_ufixed<8, 5> d(SHRT_MAX);
582  sc_ufixed<8, 5> e(SHRT_MIN);
583
584  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
585}
586
587static void test_fx_ufixed_ushort()
588{
589  IDENT("test_fx_ufixed_ushort");
590
591  sc_ufixed<8, 5> a((ushort)0);
592  sc_ufixed<8, 5> b((ushort)1);
593  sc_ufixed<8, 5> c((ushort)-1);
594  sc_ufixed<8, 5> d(USHRT_MAX);
595  sc_ufixed<8, 5> e((ushort)abs(SHRT_MIN));
596
597  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
598}
599
600static void test_fx_ufixed_long()
601{
602  IDENT("test_fx_ufixeded_long");
603
604  sc_ufixed<8, 5> a((long)0);
605  sc_ufixed<8, 5> b((long)1);
606  sc_ufixed<8, 5> c((long)-1);
607  sc_ufixed<8, 5> d(LONG_MAX);
608  sc_ufixed<8, 5> e(LONG_MIN);
609
610  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
611}
612
613static void test_fx_ufixed_ulong()
614{
615  IDENT("test_fx_ufixed_ulong");
616
617  sc_ufixed<8, 5> a((ulong)0);
618  sc_ufixed<8, 5> b((ulong)1);
619  sc_ufixed<8, 5> c((ulong)-1);
620  sc_ufixed<8, 5> d(ULONG_MAX);
621  sc_ufixed<8, 5> e((ulong)abs(LONG_MIN));
622
623  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
624}
625
626static void test_fx_ufixed_float()
627{
628  IDENT("test_fx_ufixed_float");
629
630  sc_ufixed<8, 5> a(0.0);
631  sc_ufixed<8, 5> b(1.0);
632  sc_ufixed<8, 5> c(-1.0);
633  sc_ufixed<8, 5> d(FLT_MAX);
634  sc_ufixed<8, 5> e(FLT_MIN);
635
636  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
637}
638
639static void test_fx_ufixed_double()
640{
641  IDENT("test_fx_ufixed_double");
642
643  sc_ufixed<8, 5> a((double)0.0);
644  sc_ufixed<8, 5> b((double)1.0);
645  sc_ufixed<8, 5> c((double)-1.0);
646  sc_ufixed<8, 5> d(DBL_MAX);
647  sc_ufixed<8, 5> e(DBL_MIN);
648
649  SHOW(a); SHOW(b); SHOW(c); SHOW(d); SHOW(e);
650}
651
652void default_constructor()
653{
654  cerr << "************** default_constructor for fx_float\n";
655  test_fx_float_char();
656  test_fx_float_int();
657  test_fx_float_uint();
658  test_fx_float_short();
659  test_fx_float_ushort();
660  test_fx_float_long();
661  test_fx_float_ulong();
662  test_fx_float_float();
663  test_fx_float_double();
664
665  cerr << "************** default_constructor for fx_ufix\n";
666  test_fx_ufix_char();
667  test_fx_ufix_int();
668  test_fx_ufix_uint();
669  test_fx_ufix_short();
670  test_fx_ufix_ushort();
671  test_fx_ufix_long();
672  test_fx_ufix_ulong();
673  test_fx_ufix_float();
674  test_fx_ufix_double();
675
676  cerr << "************** default_constructor for fx_fix\n";
677  test_fx_fix_char();
678  test_fx_fix_int();
679  test_fx_fix_uint();
680  test_fx_fix_short();
681  test_fx_fix_ushort();
682  test_fx_fix_long();
683  test_fx_fix_ulong();
684  test_fx_fix_float();
685  test_fx_fix_double();
686
687  cerr << "************** default_constructor for <wl,iwl>fx_fixed\n";
688  test_fx_fixed_char();
689  test_fx_fixed_int();
690  test_fx_fixed_uint();
691  test_fx_fixed_short();
692  test_fx_fixed_ushort();
693  test_fx_fixed_long();
694  test_fx_fixed_ulong();
695  test_fx_fixed_float();
696  test_fx_fixed_double();
697
698  cerr << "************** default_constructor for <wl,iwl>fx_ufixed\n";
699  test_fx_ufixed_char();
700  test_fx_ufixed_int();
701  test_fx_ufixed_uint();
702  test_fx_ufixed_short();
703  test_fx_ufixed_ushort();
704  test_fx_ufixed_long();
705  test_fx_ufixed_ulong();
706  test_fx_ufixed_float();
707  test_fx_ufixed_double();
708}
709