1 | #include <systemc.h> |
---|
2 | #include <signal.h> |
---|
3 | #include <iostream> |
---|
4 | #include <fstream> |
---|
5 | |
---|
6 | #define ASSERT(x) \ |
---|
7 | { \ |
---|
8 | if (!(x)) \ |
---|
9 | { \ |
---|
10 | cerr << "ASSERT : '" #x "' at cycle number " << sc_simulation_time () << "\n"; \ |
---|
11 | exit (1); \ |
---|
12 | } \ |
---|
13 | } |
---|
14 | |
---|
15 | using namespace std; |
---|
16 | |
---|
17 | struct sc_test : public sc_module |
---|
18 | { |
---|
19 | sc_in<bool> clk; |
---|
20 | sc_in<bool> resetn; |
---|
21 | sc_signal<sc_uint<6> > ui6; |
---|
22 | sc_signal<sc_uint<16> > ui16; |
---|
23 | sc_signal<sc_uint<31> > ui31; |
---|
24 | sc_signal<sc_uint<32> > ui32; |
---|
25 | sc_signal<sc_uint<64> > ui64; |
---|
26 | sc_signal<sc_int<6> > i6; |
---|
27 | sc_signal<sc_int<16> > i16; |
---|
28 | sc_signal<sc_int<31> > i31; |
---|
29 | sc_signal<sc_int<32> > i32; |
---|
30 | sc_signal<sc_int<64> > i64; |
---|
31 | |
---|
32 | unsigned int ui6_c_type :6; |
---|
33 | sc_uint<6> ui6_sc_uint; |
---|
34 | // sc_signal<sc_biguint<64> > bui64; |
---|
35 | // long long unsigned int bui64b; |
---|
36 | // sc_signal<sc_biguint<96> > bui96; |
---|
37 | |
---|
38 | void eval () |
---|
39 | { |
---|
40 | if (resetn == false) |
---|
41 | { |
---|
42 | ui6 = 0xF; ui6_c_type = 0xF; ui6_sc_uint = 0xF; |
---|
43 | ui16 = 0x3F; |
---|
44 | ui31 = 0x100; |
---|
45 | ui32 = 0x211; |
---|
46 | ui64 = 0xABCF1234; |
---|
47 | i6 = 0xF; |
---|
48 | i16 = 0x3F; |
---|
49 | i31 = 0x11112222; |
---|
50 | i32 = 0x43214321; |
---|
51 | i64 = 0x4444abcd; |
---|
52 | // bui64 = 0xFFFFFFFF; |
---|
53 | // bui64b= 0xFFFFFFFF; |
---|
54 | // bui96 = 0xABCDEF01; |
---|
55 | } else { |
---|
56 | cerr << hex << ui6.read () << " " |
---|
57 | << ui6_c_type << " " |
---|
58 | << ui6_sc_uint << endl; |
---|
59 | ASSERT(ui6.read() == ui6_c_type); |
---|
60 | ui6 = (ui6 .read() * 2) + 1; |
---|
61 | ui6_c_type = (ui6_c_type * 2) + 1; |
---|
62 | ui6_sc_uint = (ui6_sc_uint * 2) + 1; |
---|
63 | ui16 = (ui16 .read() * 2) + 1; |
---|
64 | ui31 = (ui31 .read() * 2) + 1; |
---|
65 | ui32 = (ui32 .read() * 2) + 1; |
---|
66 | ui64 = (ui64 .read() * 2) + 1; |
---|
67 | i6 = (i6 .read() * 2) + 1; |
---|
68 | i16 = (i16 .read() * 2) + 1; |
---|
69 | i31 = (i31 .read() * 2) + 1; |
---|
70 | i32 = (i32 .read() * 2) + 1; |
---|
71 | i64 = (i64 .read() * 2) + 1; |
---|
72 | // bui64 = (bui64 .read() * 2) + 1; |
---|
73 | // bui64b= bui64b * 2; bui64b= bui64b + 1; |
---|
74 | // bui96 = bui96 .read() * 2; bui96 = bui96 .read() + 1; |
---|
75 | #if 0 |
---|
76 | cout << bui64.read() << " "; |
---|
77 | cout << bui64b << "\n"; |
---|
78 | #endif |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | SC_CTOR(sc_test) |
---|
83 | { |
---|
84 | SC_METHOD(eval); |
---|
85 | dont_initialize (); |
---|
86 | sensitive << clk.pos(); |
---|
87 | } |
---|
88 | }; |
---|
89 | |
---|
90 | int sc_main (int argc, char *argv[]) |
---|
91 | { |
---|
92 | int errnum = 1; |
---|
93 | cout << "Tests ok\n"; |
---|
94 | sc_clock clk("clk"); |
---|
95 | sc_signal<bool> resetn("resetn"); |
---|
96 | |
---|
97 | sc_test test("test"); |
---|
98 | test.clk (clk); |
---|
99 | test.resetn (resetn); |
---|
100 | |
---|
101 | sc_trace_file *tf; |
---|
102 | |
---|
103 | if (argc != 3) |
---|
104 | { |
---|
105 | cerr << "Usage : " << argv[0] << " <trace filename> <#cycles>\n"; |
---|
106 | exit (-1); |
---|
107 | } |
---|
108 | |
---|
109 | string trace_filename = argv[1]; |
---|
110 | tf = sc_create_vcd_trace_file (trace_filename.c_str()); |
---|
111 | sc_trace (tf, test.ui6 , "ui6" ); |
---|
112 | sc_trace (tf, test.ui16 , "ui16" ); |
---|
113 | sc_trace (tf, test.ui31 , "ui31" ); |
---|
114 | sc_trace (tf, test.ui32 , "ui32" ); |
---|
115 | sc_trace (tf, test.ui64 , "ui64" ); |
---|
116 | sc_trace (tf, test.i6 , "i6" ); |
---|
117 | sc_trace (tf, test.i16 , "i16" ); |
---|
118 | sc_trace (tf, test.i31 , "i31" ); |
---|
119 | sc_trace (tf, test.i32 , "i32" ); |
---|
120 | sc_trace (tf, test.i64 , "i64" ); |
---|
121 | sc_trace (tf, clk , "clk" ); |
---|
122 | // sc_trace (tf, test.bui64, "bui64"); |
---|
123 | // sc_trace (tf, test.bui96, "bui96"); |
---|
124 | |
---|
125 | ASSERT(test.ui6.read() == 0); |
---|
126 | ASSERT(test.ui31.read() == 0); |
---|
127 | ASSERT(test.ui32.read() == 0); |
---|
128 | ASSERT(test.ui64.read() == 0); |
---|
129 | ASSERT(test.i6.read() == 0); |
---|
130 | ASSERT(test.i64.read() == 0); |
---|
131 | |
---|
132 | sc_initialize (); |
---|
133 | |
---|
134 | resetn = false; |
---|
135 | |
---|
136 | sc_start (3); |
---|
137 | resetn = true; |
---|
138 | sc_start (20); |
---|
139 | |
---|
140 | sc_close_vcd_trace_file (tf); |
---|
141 | |
---|
142 | #if 1 |
---|
143 | cout << "0x3f" << " 0x" << hex << (unsigned int) (sc_uint<6> )test.ui6 << endl; |
---|
144 | cout << "0x100fffff" << " 0x" << hex << (unsigned int) (sc_uint<31>)test.ui31 << endl; |
---|
145 | cout << "0x211fffff" << " 0x" << hex << (unsigned int) (sc_uint<32>)test.ui32 << endl; |
---|
146 | cout << "0xabcf1234fffff" << " 0x" << hex << (long long unsigned int) (sc_uint<64>)test.ui64 << endl; |
---|
147 | #endif |
---|
148 | cerr << test.ui6.read() << endl; |
---|
149 | union t { |
---|
150 | int v1:3; |
---|
151 | int v2; |
---|
152 | }; |
---|
153 | t t1,t2; |
---|
154 | t1.v1 = 7; |
---|
155 | cerr << t1.v1 << " " << t1.v2 << endl; |
---|
156 | t2.v2 = 7; |
---|
157 | cerr << t2.v1 << " " << t2.v2 << endl; |
---|
158 | |
---|
159 | ASSERT(test.ui6.read() == 0x3f); |
---|
160 | ASSERT(test.ui31.read() == 0x100fffff); |
---|
161 | ASSERT(test.ui32.read() == 0x211fffff); |
---|
162 | long long unsigned int ui64_reference = 0xabcf1234; |
---|
163 | ui64_reference <<= 20; |
---|
164 | ui64_reference += 0xfffff; |
---|
165 | #if 0 |
---|
166 | cout << "0xffffffff" << " 0x" << hex << (int) (sc_int<6>)test.i6 << endl; |
---|
167 | cout << "0x222fffff" << " 0x" << hex << (int) (sc_int<31>)test.i31 << endl; |
---|
168 | cout << "0x321fffff" << " 0x" << hex << (int) (sc_int<32>)test.i32 << endl; |
---|
169 | cout << "0x4444abcdfffff" << " 0x" << hex << (long long signed int) (sc_int<64>)test.i64 << endl; |
---|
170 | #endif |
---|
171 | ASSERT(test.ui64.read() == ui64_reference); |
---|
172 | ASSERT(test.i6.read() == (sc_int<6>)~0); |
---|
173 | ASSERT(test.i31.read() == 0x222fffff); |
---|
174 | ASSERT(test.i32.read() == 0x321fffff) |
---|
175 | long long signed int i64_reference = 0x4444abcd; |
---|
176 | i64_reference <<= 20; |
---|
177 | i64_reference += 0xfffff; |
---|
178 | ASSERT(test.i64.read() == i64_reference); |
---|
179 | // cout << "0x4294967315" << " 0x" << hex << test.bui64 << endl; |
---|
180 | cout << "Test OK.\n"; |
---|
181 | return EXIT_SUCCESS; |
---|
182 | } |
---|