test02.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  test02.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// test of explicit conversions of the datatypes
39
40#define SC_INCLUDE_FX
41#include "systemc.h"
42
43
44template <class T>
45void
46write1( const T& a )
47{
48    cout << endl;
49    cout << a.to_int() << endl;
50    cout << a.to_uint() << endl;
51    cout << a.to_long() << endl;
52    cout << a.to_ulong() << endl;
53}
54
55template <class T>
56void
57write2( const T& a )
58{
59    write1( a );
60    cout << a.to_double() << endl;
61}
62
63template <class T>
64void
65write3( const T& a )
66{
67    write2( a );
68    cout << a.to_int64() << endl;
69    cout << a.to_uint64() << endl;
70}
71
72
73void
74test_bit()
75{
76    cout << "\n*** test_bit()" << endl;
77
78    sc_bv<8> a( "10101010" );
79    write1( a );
80    write1( a.range( 3, 0 ) );
81
82    sc_lv<8> b( "11001100" );
83    write1( b );
84    write1( b.range( 3, 0 ) );
85
86    write1( ( a.range( 3, 0 ), b.range( 3, 0 ) ) );
87}
88
89void
90test_fx()
91{
92    cout << "\n*** test_fx()" << endl;
93
94    sc_fixed<8,4> a( "0b1010.1010" );
95    write2( a );
96    write1( a.range( 3, 0 ) );
97
98    sc_fixed_fast<8,4> b( "0b1010.1010" );
99    write2( b );
100    write1( b.range( 3, 0 ) );
101
102    sc_ufixed<8,4> c( "0b1010.1010" );
103    write2( c );
104    write1( c.range( 3, 0 ) );
105
106    sc_ufixed_fast<8,4> d( "0b1010.1010" );
107    write2( d );
108    write1( d.range( 3, 0 ) );
109}
110
111void
112test_int()
113{
114    cout << "\n*** test_int()" << endl;
115
116    sc_bigint<8> a( "0b10101010" );
117    write3( a );
118    write3( a.range( 3, 0 ) );
119
120    sc_biguint<8> b( "0b10101010" );
121    write3( b );
122    write3( b.range( 3, 0 ) );
123
124    sc_int<8> c( -86 );
125    write3( c );
126    write3( c.range( 3, 0 ) );
127    write3( ( c.range( 7, 4 ), c.range( 3, 0 ) ) );
128
129    sc_uint<8> d( 170 );
130    write3( d );
131    write3( d.range( 3, 0 ) );
132    write3( ( d.range( 7, 4 ), d.range( 3, 0 ) ) );
133}
134
135int
136sc_main( int, char*[] )
137{
138    test_bit();
139    test_fx();
140    test_int();
141
142    return 0;
143}
144