assign.cpp revision 12855:588919e0e4aa
16157Snate@binkert.org/*****************************************************************************
26157Snate@binkert.org
36157Snate@binkert.org  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
46157Snate@binkert.org  more contributor license agreements.  See the NOTICE file distributed
56157Snate@binkert.org  with this work for additional information regarding copyright ownership.
66157Snate@binkert.org  Accellera licenses this file to you under the Apache License, Version 2.0
76157Snate@binkert.org  (the "License"); you may not use this file except in compliance with the
86157Snate@binkert.org  License.  You may obtain a copy of the License at
96157Snate@binkert.org
106157Snate@binkert.org    http://www.apache.org/licenses/LICENSE-2.0
116157Snate@binkert.org
126157Snate@binkert.org  Unless required by applicable law or agreed to in writing, software
136157Snate@binkert.org  distributed under the License is distributed on an "AS IS" BASIS,
146157Snate@binkert.org  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
156157Snate@binkert.org  implied.  See the License for the specific language governing
166157Snate@binkert.org  permissions and limitations under the License.
176157Snate@binkert.org
186157Snate@binkert.org *****************************************************************************/
196157Snate@binkert.org
206157Snate@binkert.org/*****************************************************************************
216157Snate@binkert.org
226157Snate@binkert.org  assign.cpp --
236157Snate@binkert.org
246157Snate@binkert.org  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
256157Snate@binkert.org
266157Snate@binkert.org *****************************************************************************/
276157Snate@binkert.org
286157Snate@binkert.org/*****************************************************************************
296157Snate@binkert.org
306157Snate@binkert.org  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
316157Snate@binkert.org  changes you are making here.
326157Snate@binkert.org
336157Snate@binkert.org      Name, Affiliation, Date:
346157Snate@binkert.org  Description of Modification:
356157Snate@binkert.org
366157Snate@binkert.org *****************************************************************************/
376157Snate@binkert.org
386157Snate@binkert.org// This may look like C code, but it is really -*- C++ -*-
396157Snate@binkert.org//
4010133Sandreas.hansson@arm.com// assign.cxx --
4110133Sandreas.hansson@arm.com// Copyright Synopsys 1998
4210133Sandreas.hansson@arm.com// Author          : Ric Hilderink
4310133Sandreas.hansson@arm.com// Created On      : Wed Dec 30 09:58:11 1998
4410133Sandreas.hansson@arm.com// Status          : none
4510133Sandreas.hansson@arm.com//
4610133Sandreas.hansson@arm.com
4710133Sandreas.hansson@arm.com#include <limits.h>
4810133Sandreas.hansson@arm.com
4910133Sandreas.hansson@arm.com#define SC_INCLUDE_FX
5010133Sandreas.hansson@arm.com#include "systemc.h"
5110133Sandreas.hansson@arm.com#include "fx_precision_double.h"
5210133Sandreas.hansson@arm.com
5310133Sandreas.hansson@arm.comtypedef unsigned int   uint;
5410133Sandreas.hansson@arm.comtypedef unsigned short ushort;
5510133Sandreas.hansson@arm.comtypedef unsigned long  ulong;
5610133Sandreas.hansson@arm.com
5710133Sandreas.hansson@arm.com#define SHOW_ASSIGN(a) cerr << #a << " : " << double(a) << " : " << a.to_string(SC_HEX) << "\n"
5810133Sandreas.hansson@arm.com#define IDENT_ASSIGN(a) cerr << "--assign-Inf-Inf-Inf-Inf-Inf- " << a << "\n"
5910133Sandreas.hansson@arm.com
6010133Sandreas.hansson@arm.com//----------------------------------------------------------------
6110133Sandreas.hansson@arm.comstatic void test_fx_float_int()
628492Snilay@cs.wisc.edu{
636168Snate@binkert.org  IDENT_ASSIGN("test_fx_float_int");
646168Snate@binkert.org
656157Snate@binkert.org  sc_fxval a(0);
666157Snate@binkert.org  sc_fxval b;
676157Snate@binkert.org  sc_fxval c = b = -1;
686157Snate@binkert.org
696157Snate@binkert.org  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
706157Snate@binkert.org}
716157Snate@binkert.org
726157Snate@binkert.orgstatic void test_fx_float_uint()
736157Snate@binkert.org{
746157Snate@binkert.org  IDENT_ASSIGN("test_fx_float_uint");
756157Snate@binkert.org
766157Snate@binkert.org  sc_fxval a(0u);
776157Snate@binkert.org  sc_fxval b;
786157Snate@binkert.org  sc_fxval c = b = (uint)-1;
796157Snate@binkert.org
806157Snate@binkert.org  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
816157Snate@binkert.org}
826157Snate@binkert.org
836157Snate@binkert.orgstatic void test_fx_float_short()
846157Snate@binkert.org{
856157Snate@binkert.org  IDENT_ASSIGN("test_fx_float_short");
866157Snate@binkert.org
876157Snate@binkert.org  sc_fxval a((short)0);
886157Snate@binkert.org  sc_fxval b;
896157Snate@binkert.org  sc_fxval c = b = (short)-1;
906157Snate@binkert.org
916157Snate@binkert.org  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
926157Snate@binkert.org}
936157Snate@binkert.org
946157Snate@binkert.orgstatic void test_fx_float_ushort()
956157Snate@binkert.org{
966157Snate@binkert.org  IDENT_ASSIGN("test_fx_float_ushort");
976157Snate@binkert.org
986157Snate@binkert.org  sc_fxval a((ushort)0);
996157Snate@binkert.org  sc_fxval b;
1006157Snate@binkert.org  sc_fxval c = b = (ushort)-1;
1016157Snate@binkert.org
1026157Snate@binkert.org  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
1036157Snate@binkert.org}
1046157Snate@binkert.org
1056157Snate@binkert.orgstatic void test_fx_float_long()
1066157Snate@binkert.org{
1076157Snate@binkert.org  IDENT_ASSIGN("test_fx_float_long");
1088483Sgblack@eecs.umich.edu
1098483Sgblack@eecs.umich.edu  sc_fxval a(0L);
1106157Snate@binkert.org  sc_fxval b;
1116882SBrad.Beckmann@amd.com  sc_fxval c = b = -1L;
1126286Snate@binkert.org
1136286Snate@binkert.org  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
1148092Snilay@cs.wisc.edu}
1156286Snate@binkert.org
1166286Snate@binkert.orgstatic void test_fx_float_ulong()
1176157Snate@binkert.org{
11811208Sjoseph.gross@amd.com  IDENT_ASSIGN("test_fx_float_ulong");
1196157Snate@binkert.org  sc_fxval a(0UL);
12010301Snilay@cs.wisc.edu  sc_fxval b;
1216157Snate@binkert.org  sc_fxval c = b = -1UL;
1226157Snate@binkert.org
12311122Snilay@cs.wisc.edu  SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c);
12410301Snilay@cs.wisc.edu}
1259363Snilay@cs.wisc.edu
12610301Snilay@cs.wisc.edustatic void test_fx_float_float()
1276286Snate@binkert.org{
12810301Snilay@cs.wisc.edu  IDENT_ASSIGN("test_fx_float_float");
12910301Snilay@cs.wisc.edu
13010301Snilay@cs.wisc.edu  sc_fxval a(0.0f);
13110301Snilay@cs.wisc.edu  sc_fxval b;
1326157Snate@binkert.org  sc_fxval c = b = -1.0f;
13310301Snilay@cs.wisc.edu
13410301Snilay@cs.wisc.edu  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