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