assign.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  assign.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// assign.cxx --
41// Copyright Synopsys 1998
42// Author          : Ric Hilderink
43// Created On      : Wed Dec 30 09:58:11 1998
44// Status          : none
45//
46
47#include <limits.h>
48
49#define SC_INCLUDE_FX
50#include "systemc.h"
51#include "fx_precision_double.h"
52
53typedef unsigned int   uint;
54typedef unsigned short ushort;
55typedef unsigned long  ulong;
56
57#define SHOW_ASSIGN(a) cerr << #a << " : " << double(a) << " : " << a.to_string(SC_HEX) << "\n"
58#define IDENT_ASSIGN(a) cerr << "--assign-Inf-Inf-Inf-Inf-Inf- " << a << "\n"
59
60//----------------------------------------------------------------
61static void test_fx_float_int()
62{
63  IDENT_ASSIGN("test_fx_float_int");
64
65  sc_fxval a(0);
66  sc_fxval b;
67  sc_fxval c = b = -1;
68
69  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
70}
71
72static void test_fx_float_uint()
73{
74  IDENT_ASSIGN("test_fx_float_uint");
75
76  sc_fxval a(0u);
77  sc_fxval b;
78  sc_fxval c = b = (uint)-1;
79
80  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
81}
82
83static void test_fx_float_short()
84{
85  IDENT_ASSIGN("test_fx_float_short");
86
87  sc_fxval a((short)0);
88  sc_fxval b;
89  sc_fxval c = b = (short)-1;
90
91  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
92}
93
94static void test_fx_float_ushort()
95{
96  IDENT_ASSIGN("test_fx_float_ushort");
97
98  sc_fxval a((ushort)0);
99  sc_fxval b;
100  sc_fxval c = b = (ushort)-1;
101
102  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
103}
104
105static void test_fx_float_long()
106{
107  IDENT_ASSIGN("test_fx_float_long");
108
109  sc_fxval a(0L);
110  sc_fxval b;
111  sc_fxval c = b = -1L;
112
113  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
114}
115
116static void test_fx_float_ulong()
117{
118  IDENT_ASSIGN("test_fx_float_ulong");
119  sc_fxval a(0UL);
120  sc_fxval b;
121  sc_fxval c = b = -1UL;
122
123  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
124}
125
126static void test_fx_float_float()
127{
128  IDENT_ASSIGN("test_fx_float_float");
129
130  sc_fxval a(0.0f);
131  sc_fxval b;
132  sc_fxval c = b = -1.0f;
133
134  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
135}
136
137static void test_fx_float_double()
138{
139  IDENT_ASSIGN("test_fx_float_double");
140
141  sc_fxval a(0.0);
142  sc_fxval b;
143  sc_fxval c = b = -1.0;
144
145  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
146}
147
148//----------------------------------------------------------------
149static void test_fx_ufix_int()
150{
151  IDENT_ASSIGN("test_fx_ufix_int");
152
153  sc_ufix a = 0;
154  sc_ufix b;
155  sc_ufix c = b = -1;
156
157  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
158}
159
160static void test_fx_ufix_uint()
161{
162  IDENT_ASSIGN("test_fx_ufix_uint");
163
164  sc_ufix a = (uint)0;
165  sc_ufix b;
166  sc_ufix c = b = (uint)-1;
167
168  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
169}
170
171static void test_fx_ufix_short()
172{
173  IDENT_ASSIGN("test_fx_ufix_short");
174
175  sc_ufix a = (short)0;
176  sc_ufix b;
177  sc_ufix c = b = (short)-1;
178
179  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
180}
181
182static void test_fx_ufix_ushort()
183{
184  IDENT_ASSIGN("test_fx_ufix_ushort");
185
186  sc_ufix a = (ushort)0;
187  sc_ufix b;
188  sc_ufix c = b = (ushort)-1;
189
190  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
191}
192
193static void test_fx_ufix_long()
194{
195  IDENT_ASSIGN("test_fx_ufix_long");
196
197  sc_ufix a = (long)0;
198  sc_ufix b;
199  sc_ufix c = b = (long)-1;
200
201  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
202}
203
204static void test_fx_ufix_ulong()
205{
206  IDENT_ASSIGN("test_fx_ufix_ulong");
207  sc_ufix a = (ulong)0;
208  sc_ufix b;
209  sc_ufix c = b = (ulong)-1;
210
211  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
212}
213
214static void test_fx_ufix_float()
215{
216  IDENT_ASSIGN("test_fx_ufix_float");
217
218  sc_ufix a = 0.0;
219  sc_ufix b;
220  sc_ufix c = b = -1.0;
221
222  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
223}
224
225static void test_fx_ufix_double()
226{
227  IDENT_ASSIGN("test_fx_ufix_double");
228
229  sc_ufix a = (double)0.0;
230  sc_ufix b;
231  sc_ufix c = b = (double)-1.0;
232
233  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
234}
235
236//----------------------------------------------------------------
237static void test_fx_fix_int()
238{
239  IDENT_ASSIGN("test_fx_fix_int");
240
241  sc_fix a = 0;
242  sc_fix b;
243  sc_fix c = b = -1;
244
245  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
246}
247
248static void test_fx_fix_uint()
249{
250  IDENT_ASSIGN("test_fx_fix_uint");
251
252  sc_fix a = (uint)0;
253  sc_fix b;
254  sc_fix c = b = (uint)-1;
255
256  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
257}
258
259static void test_fx_fix_short()
260{
261  IDENT_ASSIGN("test_fx_fix_short");
262
263  sc_fix a = (short)0;
264  sc_fix b;
265  sc_fix c = b = (short)-1;
266
267  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
268}
269
270static void test_fx_fix_ushort()
271{
272  IDENT_ASSIGN("test_fx_fix_ushort");
273
274  sc_fix a = (ushort)0;
275  sc_fix b;
276  sc_fix c = b = (ushort)-1;
277
278  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
279}
280
281static void test_fx_fix_long()
282{
283  IDENT_ASSIGN("test_fx_fix_long");
284
285  sc_fix a = (long)0;
286  sc_fix b;
287  sc_fix c = b = (long)-1;
288
289  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
290}
291
292static void test_fx_fix_ulong()
293{
294  IDENT_ASSIGN("test_fx_fix_ulong");
295  sc_fix a = (ulong)0;
296  sc_fix b;
297  sc_fix c = b = (ulong)-1;
298
299  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
300}
301
302static void test_fx_fix_float()
303{
304  IDENT_ASSIGN("test_fx_fix_float");
305
306  sc_fix a = 0.0;
307  sc_fix b;
308  sc_fix c = b = -1.0;
309
310  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
311}
312
313static void test_fx_fix_double()
314{
315  IDENT_ASSIGN("test_fx_fix_double");
316
317  sc_fix a = (double)0.0;
318  sc_fix b;
319  sc_fix c = b = (double)-1.0;
320
321  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
322}
323
324//----------------------------------------------------------------
325static void test_fx_fixed_int()
326{
327  IDENT_ASSIGN("test_fx_fixed_int");
328
329  sc_fixed<8, 5> a = 0;
330  sc_fixed<8, 5> b;
331  sc_fixed<8, 5> c = b = -1;
332
333  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
334}
335
336static void test_fx_fixed_uint()
337{
338  IDENT_ASSIGN("test_fx_fixed_uint");
339
340  sc_fixed<8, 5> a = (uint)0;
341  sc_fixed<8, 5> b;
342  sc_fixed<8, 5> c = b = (uint)abs(-1);
343
344  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
345}
346
347static void test_fx_fixed_short()
348{
349  IDENT_ASSIGN("test_fx_fixed_short");
350
351  sc_fixed<8, 5> a = (short)0;
352  sc_fixed<8, 5> b;
353  sc_fixed<8, 5> c = b = (short)-1;
354
355  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
356}
357
358static void test_fx_fixed_ushort()
359{
360  IDENT_ASSIGN("test_fx_fixed_ushort");
361
362  sc_fixed<8, 5> a = (ushort)0;
363  sc_fixed<8, 5> b;
364  sc_fixed<8, 5> c = b = (ushort)abs(-1);
365
366  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
367}
368
369static void test_fx_fixed_long()
370{
371  IDENT_ASSIGN("test_fx_fixed_long");
372
373  sc_fixed<8, 5> a = (long)0;
374  sc_fixed<8, 5> b;
375  sc_fixed<8, 5> c = b = (long)-1;
376
377  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
378}
379
380static void test_fx_fixed_ulong()
381{
382  IDENT_ASSIGN("test_fx_fixed_ulong");
383  sc_fixed<8, 5> a = (ulong)0;
384  sc_fixed<8, 5> b;
385  sc_fixed<8, 5> c = b = (ulong)abs(-1);
386
387  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
388}
389
390static void test_fx_fixed_float()
391{
392  IDENT_ASSIGN("test_fx_fixed_float");
393
394  sc_fixed<8, 5> a = 0.0;
395  sc_fixed<8, 5> b;
396  sc_fixed<8, 5> c = b = -1.0;
397
398  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
399}
400
401static void test_fx_fixed_double()
402{
403  IDENT_ASSIGN("test_fx_fixed_double");
404
405  sc_fixed<8, 5> a = (double)0.0;
406  sc_fixed<8, 5> b;
407  sc_fixed<8, 5> c = b = (double)-1.0;
408
409  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
410}
411
412//----------------------------------------------------------------
413static void test_fx_ufixed_int()
414{
415  IDENT_ASSIGN("test_fx_ufixed_int");
416
417  sc_ufixed<8, 5> a = 0;
418  sc_ufixed<8, 5> b;
419  sc_ufixed<8, 5> c = b = -1;
420
421  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
422}
423
424static void test_fx_ufixed_uint()
425{
426  IDENT_ASSIGN("test_fx_ufixed_uint");
427
428  sc_ufixed<8, 5> a = (uint)0;
429  sc_ufixed<8, 5> b;
430  sc_ufixed<8, 5> c = b = (uint)abs(-1);
431
432  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
433}
434
435static void test_fx_ufixed_short()
436{
437  IDENT_ASSIGN("test_fx_ufixed_short");
438
439  sc_ufixed<8, 5> a = (short)0;
440  sc_ufixed<8, 5> b;
441  sc_ufixed<8, 5> c = b = (short)-1;
442
443  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
444}
445
446static void test_fx_ufixed_ushort()
447{
448  IDENT_ASSIGN("test_fx_ufixed_ushort");
449
450  sc_ufixed<8, 5> a = (ushort)0;
451  sc_ufixed<8, 5> b;
452  sc_ufixed<8, 5> c = b = (ushort)abs(-1);
453
454  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
455}
456
457static void test_fx_ufixed_long()
458{
459  IDENT_ASSIGN("test_fx_ufixed_long");
460
461  sc_ufixed<8, 5> a = (long)0;
462  sc_ufixed<8, 5> b;
463  sc_ufixed<8, 5> c = b = (long)-1;
464
465  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
466}
467
468static void test_fx_ufixed_ulong()
469{
470  IDENT_ASSIGN("test_fx_ufixed_ulong");
471  sc_ufixed<8, 5> a = (ulong)0;
472  sc_ufixed<8, 5> b;
473  sc_ufixed<8, 5> c = b = (ulong)abs(-1);
474
475  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
476}
477
478static void test_fx_ufixed_float()
479{
480  IDENT_ASSIGN("test_fx_ufixed_float");
481
482  sc_ufixed<8, 5> a = 0.0;
483  sc_ufixed<8, 5> b;
484  sc_ufixed<8, 5> c = b = -1.0;
485
486  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
487}
488
489static void test_fx_ufixed_double()
490{
491  IDENT_ASSIGN("test_fx_ufixed_double");
492
493  sc_ufixed<8, 5> a = (double)0.0;
494  sc_ufixed<8, 5> b;
495  sc_ufixed<8, 5> c = b = (double)-1.0;
496
497  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
498}
499
500void assign()
501{
502  cerr << "************** assign test_fx_float_\n";
503  test_fx_float_int();
504  test_fx_float_uint();
505  test_fx_float_short();
506  test_fx_float_ushort();
507  test_fx_float_long();
508  test_fx_float_ulong();
509  test_fx_float_float();
510  test_fx_float_double();
511  cerr << "************** assign test_fx_ufix_\n";
512  test_fx_ufix_int();
513  test_fx_ufix_uint();
514  test_fx_ufix_short();
515  test_fx_ufix_ushort();
516  test_fx_ufix_long();
517  test_fx_ufix_ulong();
518  test_fx_ufix_float();
519  test_fx_ufix_double();
520  cerr << "************** assign test_fx_fix_\n";
521  test_fx_fix_int();
522  test_fx_fix_uint();
523  test_fx_fix_short();
524  test_fx_fix_ushort();
525  test_fx_fix_long();
526  test_fx_fix_ulong();
527  test_fx_fix_float();
528  test_fx_fix_double();
529  cerr << "************** assign test_fx_fixed_\n";
530  test_fx_fixed_int();
531  test_fx_fixed_uint();
532  test_fx_fixed_short();
533  test_fx_fixed_ushort();
534  test_fx_fixed_long();
535  test_fx_fixed_ulong();
536  test_fx_fixed_float();
537  test_fx_fixed_double();
538  cerr << "************** assign test_fx_ufixed_\n";
539  test_fx_ufixed_int();
540  test_fx_ufixed_uint();
541  test_fx_ufixed_short();
542  test_fx_ufixed_ushort();
543  test_fx_ufixed_long();
544  test_fx_ufixed_ulong();
545  test_fx_ufixed_float();
546  test_fx_ufixed_double();
547}
548