[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; |
---|
| 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; |
---|
| 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; |
---|
| 47 | ui64 = 0xABCF1234; |
---|
| 48 | i6 = 0xF; |
---|
| 49 | i16 = 0x3F; |
---|
| 50 | i31 = 0x11112222; |
---|
| 51 | i32 = 0x43214321; |
---|
| 52 | i64 = 0x4444abcd; |
---|
| 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 | { |
---|
| 93 | int errnum = 1; |
---|
| 94 | cout << "Tests ok\n"; |
---|
| 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 | |
---|
| 102 | sc_trace_file *tf; |
---|
| 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]; |
---|
| 111 | tf = sc_create_vcd_trace_file (trace_filename.c_str()); |
---|
| 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 | sc_close_vcd_trace_file (tf); |
---|
| 142 | |
---|
| 143 | #if 1 |
---|
| 144 | cout << "0x3f" << " 0x" << hex << (unsigned int) (sc_uint<6> )test.ui6 << endl; |
---|
| 145 | cout << "0x100fffff" << " 0x" << hex << (unsigned int) (sc_uint<31>)test.ui31 << endl; |
---|
| 146 | cout << "0x211fffff" << " 0x" << hex << (unsigned int) (sc_uint<32>)test.ui32 << endl; |
---|
| 147 | cout << "0xabcf1234fffff" << " 0x" << hex << (long long unsigned int) (sc_uint<64>)test.ui64 << endl; |
---|
| 148 | #endif |
---|
| 149 | cerr << test.ui6.read() << endl; |
---|
| 150 | union t { |
---|
| 151 | int v1:3; |
---|
| 152 | int v2; |
---|
| 153 | }; |
---|
| 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); |
---|
| 163 | long long unsigned int ui64_reference = 0xabcf1234; |
---|
| 164 | ui64_reference <<= 20; |
---|
| 165 | ui64_reference += 0xfffff; |
---|
| 166 | #if 0 |
---|
| 167 | cout << "0xffffffff" << " 0x" << hex << (int) (sc_int<6>)test.i6 << endl; |
---|
| 168 | cout << "0x222fffff" << " 0x" << hex << (int) (sc_int<31>)test.i31 << endl; |
---|
| 169 | cout << "0x321fffff" << " 0x" << hex << (int) (sc_int<32>)test.i32 << endl; |
---|
| 170 | cout << "0x4444abcdfffff" << " 0x" << hex << (long long signed int) (sc_int<64>)test.i64 << endl; |
---|
| 171 | #endif |
---|
| 172 | ASSERT(test.ui64.read() == ui64_reference); |
---|
| 173 | ASSERT(test.i6.read() == (sc_int<6>)~0); |
---|
| 174 | ASSERT(test.i31.read() == 0x222fffff); |
---|
| 175 | ASSERT(test.i32.read() == 0x321fffff) |
---|
| 176 | long long signed int i64_reference = 0x4444abcd; |
---|
| 177 | i64_reference <<= 20; |
---|
| 178 | i64_reference += 0xfffff; |
---|
| 179 | ASSERT(test.i64.read() == i64_reference); |
---|
| 180 | // cout << "0x4294967315" << " 0x" << hex << test.bui64 << endl; |
---|
| 181 | cout << "Test OK.\n"; |
---|
| 182 | return EXIT_SUCCESS; |
---|
| 183 | } |
---|