//------------------------------------------------------------------------ void ASCII_DEC::Decode() { IS_HEX = sc_logic('1'); switch(CHR) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': DGT = CHR & 0x0F; break; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': DGT = (CHR & 0x0F) + 9; break; default: IS_HEX = sc_logic('0'); DGT = 0; } if(CHR == ':') SC = sc_logic('1'); else SC = sc_logic('0'); }
//------------------------------------------------------------------------ void CD4029::CEO4029() { if(CE.read()==sc_logic('1')) { if(UP.read()== sc_logic('1')) { if(BCD.read() == sc_logic('1')) { if(Q.read() == "1001") CEO = sc_logic('1'); else CEO = sc_logic('0'); } else { if(Q.read() == "1111") CEO = sc_logic('1'); else CEO = sc_logic('0'); } } else { if(Q.read() == "0000") CEO = sc_logic('1'); else CEO = sc_logic('0'); } } else CEO = sc_logic('0'); }
//------------------------------------------------------------------------ void CMP::CMP_AB() { if(A.read() == B.read()) EQ = sc_logic('1'); else EQ = sc_logic('0'); }
//------------------------------------------------------------------------ void DAT_CNT::CO_ZD() { if(QI[0].read() == "0000" && QI[1].read() == "0000") ZD = sc_logic('1'); else ZD = sc_logic('0'); }
int foo() { sc_logic x; sc_logic y; sc_logic z; char q; x = 'X'; z = '1'; y = x & z; y = x | z; y = x ^ z; y ^= x; y |= z; y &= z; y = z; y = x & sc_logic('1'); y = sc_logic('1') | x; y = '0'; return 0; }
void ts_buf::entry() { bool c; bool bus_val; sc_logic val; c = control.read(); if (c == false) { ts_out.write(sc_logic('Z')); } else { bus_val = in.read(); val = bus_val; // automatic type conversion ts_out.write(val); } } // end of entry function
void xc::xsim::main() { while (true) { XsiStatus status = xsi_clock(instance); report_status(status); wait(); std::vector<package *>::iterator pkg; for (pkg = packages.begin();pkg != packages.end();pkg++) { std::map<std::string, sc_inout_resolved *>::iterator it; const char *pkg_name = ((*pkg)->id).c_str(); for (it = (*pkg)->pins.begin(); it != (*pkg)->pins.end(); it++) { sc_inout_resolved *p = (it->second); const char *pin_name = (it->first).c_str(); unsigned int is_driving; report_status(xsi_is_pin_driving(instance, pkg_name, pin_name, &is_driving)); if (is_driving) { unsigned int value; report_status(xsi_sample_pin(instance, pkg_name, pin_name, &value)); (*p)->write(sc_logic((int) value)); } else { sc_logic bit = (*p)->read(); if (bit != 'z' && bit != 'x') { report_status(xsi_drive_pin(instance, pkg_name, pin_name, bit.to_bool())); } } } } } }
int sc_main(int ac, char *av[]) { // 0. SIZE OF TYPES int integer; short short_integer; long long_integer; unsigned long unsigned_long; signed long signed_long; cout << "\nINTEGER SIZE \t\t= " << sizeof integer << " bytes" << "\nSHORT INTEGER SIZE \t= " << sizeof short_integer << " bytes" << "\nLONG INTEGER SIZE \t= " << sizeof long_integer << " bytes" << "\nUNSIGNED LONG SIZE \t= " << sizeof unsigned_long << " bytes" << "\nSIGNED LONG SIZE \t= " << sizeof signed_long << " bytes" << "\n" << endl; // 1. DECLARATION SYNTAX std_ulogic_vector<9> a; std_ulogic_vector<9> b; std_ulogic_vector<68> big; std_ulogic_vector<1284> huge_; // 2. TYPE CONVERSION // std_ulogic_vector <- C++ string a = "01XZUWLH-"; b = "ZZ1XX0UU1WWW"; big = "11110000111100001111000011110000111100001111000011110000111100001111"; huge_ = "111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111000011110000111100001111"; cout << "std_ulogic_vector \t<=\t C++ string" << "\n-------------------------------------------" << "\nA = " << a << "\t\t \"01XZUWLH-\" " << "\nB = " << b << "\t\t \"ZZ1XX0UU1WWW\" " << "\nBIG = " << big << "\n " <<"\"11110000111100001111000011110000111100001111000011110000111100001111\"" << "\nHUGE = " << huge_.range(0,63) << "\n " << huge_.range(64,127) << "\n " << huge_.range(128,191) << "\n " << huge_.range(192,255) << "\n " << huge_.range(256,319) << "\n " << huge_.range(320,383) << "\n " << huge_.range(384,447) << "\n " << huge_.range(448,511) << "\n " << huge_.range(512,575) << "\n " << huge_.range(576,639) << "\n " << huge_.range(640,703) << "\n " << huge_.range(704,767) << "\n " << huge_.range(768,831) << "\n " << huge_.range(832,895) << "\n " << huge_.range(896,959) << "\n " << huge_.range(960,1023) << "\n " << huge_.range(1024,1087) << "\n " << huge_.range(1088,1151) << "\n " << huge_.range(1152,1215) << "\n " << huge_.range(1216,1279) << "\n " << huge_.range(1280,1283) << "\n" << endl; // std_ulogic_vector <- std_ulogic_vector std_ulogic_vector<9> c; std_ulogic_vector<68> big2; c = b; big2 = big; cout << "std_ulogic_vector \t<=\t std_ulogic_vector" << "\n--------------------------------------------------" << "\nC = " << c << "\t\t ZZ1XX0XX1XXX" << "\nBIG2 = " << big2 << "\n " <<"\"11110000111100001111000011110000111100001111000011110000111100001111\"" << "\n" << endl; // std_ulogic_vector <- C++ array of std_ulogic std_ulogic_vector<9> d; std_ulogic_vector<9> e; std_ulogic_vector<68> big3; std_ulogic cb1[9] = { sc_logic( 'U' ), sc_logic( 0 ) , sc_logic( 1 ), sc_logic( 'X' ), sc_logic( 'Z' ), sc_logic( 'W' ), sc_logic( 'H' ), sc_logic( 'L' ), sc_logic( '-' ) }; std_ulogic cb2[12] = { sc_logic( 'U' ), sc_logic( 'U' ), sc_logic( 'X' ), sc_logic( 'X' ), sc_logic( 1 ) , sc_logic( 1 ), sc_logic( 0 ) , sc_logic( 0 ) , sc_logic( 1 ), sc_logic( 1 ) , sc_logic( 'X' ), sc_logic( 'X' ) }; std_ulogic cb3[80] = { sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 1 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ), sc_logic( 0 ) }; d = cb1; e = cb2; big3 = cb3; cout << "std_ulogic_vector \t<=\t C++ array of bool" << "\n--------------------------------------------------" << "\nD = " << d << "\t\t -, L, H, W, Z, X, 1, 0, U" << "\nE = " << e << "\t\t X, X, 1, 1, 0, 0, 1, 1, X, X, U, U" << "\nBIG3 = " << big3 << "\n " <<"\"11110000111100001111000011110000111100001111000011110000111100001111" <<"\n 000011110000\"" << "\n" << endl; // std_ulogic_vector <- bool_vector std_ulogic_vector<4> f; bool_vector<4> sv1; sv1 = "1010"; f = sv1; cout << "std_ulogic_vector \t<=\t bool_vector" << "\n--------------------------------------------" << "\nF = " << f << "\t\t \"1010\" " << "\n" << endl; // std_ulogic_vector <- unsigned long std_ulogic_vector<4> h; std_ulogic_vector<32> i; std_ulogic_vector<40> j; unsigned long ul1 = 137; // ...10001001 unsigned long ul2 = 137; // ...10001001 unsigned long ul3 = 137; // ...10001001 h = ul1; i = ul2; j = ul3; cout << "std_ulogic_vector \t<=\t unsigned long" << "\n----------------------------------------------" << "\nH = " << h << "\t\t\t\t\t ...10001001 (137)" << "\nI = " << i << "\t\t ...10001001 (137)" << "\nJ = " << j << "\t ...10001001 (137)" << "\n" << endl; // std_ulogic_vector <- sc_unsigned std_ulogic_vector<4> k; std_ulogic_vector<4> l; std_ulogic_vector<4> m; sc_biguint<2> scu1; sc_biguint<4> scu2; sc_biguint<8> scu3; scu1 = 3; // .........11 scu2 = 13; // .......1101 scu3 = 137; // ...10001001 k = scu1; l = scu2; m = scu3; cout << "std_ulogic_vector \t<=\t sc_unsigned" << "\n--------------------------------------------" << "\nK = " << k << "\t\t 11 (3)" << "\nL = " << l << "\t\t 1101 (13)" << "\nM = " << m << "\t\t 10001001 (137)" << "\n" << endl; // std_ulogic_vector <- signed long std_ulogic_vector<5> n; std_ulogic_vector<32> o; std_ulogic_vector<40> p; std_ulogic_vector<5> q; std_ulogic_vector<32> r; std_ulogic_vector<40> s; signed long sl1 = 137; // ...010001001 signed long sl2 = 137; // ...010001001 signed long sl3 = 137; // ...010001001 signed long sl4 = -137; // ...101110111 signed long sl5 = -137; // ...101110111 signed long sl6 = -137; // ...101110111 n = sl1; o = sl2; p = sl3; q = sl4; r = sl5; s = sl6; cout << "std_ulogic_vector \t<=\t signed long" << "\n--------------------------------------------" << "\nN = " << n << "\t\t\t\t\t ...010001001 (137)" << "\nO = " << o << "\t\t ...010001001 (137)" << "\nP = " << p << "\t ...010001001 (137)" << "\nQ = " << q << "\t\t\t\t\t ...101110111 (-137)" << "\nR = " << r << "\t\t ...101110111 (-137)" << "\nS = " << s << "\t ...101110111 (-137)" << "\n" << endl; // std_ulogic_vector <- sc_signed std_ulogic_vector<5> t; std_ulogic_vector<5> u; std_ulogic_vector<5> v; std_ulogic_vector<5> w; std_ulogic_vector<5> x; std_ulogic_vector<5> y; sc_bigint<3> scs1; sc_bigint<5> scs2; sc_bigint<9> scs3; sc_bigint<3> scs4; sc_bigint<5> scs5; sc_bigint<9> scs6; scs1 = 3; // ........011 scs2 = 13; // ......01101 scs3 = 137; // ..010001001 scs4 = -3; // ........101 scs5 = -13; // ......10011 scs6 = -137; // ..101110111 t = scs1; u = scs2; v = scs3; w = scs4; x = scs5; y = scs6; cout << "std_ulogic_vector \t<=\t sc_signed" << "\n------------------------------------------" << "\nT = " << t << "\t\t 011 (3)" << "\nU = " << u << "\t\t 01101 (13)" << "\nV = " << v << "\t\t 010001001 (137)" << "\nW = " << w << "\t\t 101 (-3)" << "\nX = " << x << "\t\t 10011 (-13)" << "\nY = " << y << "\t\t 101110111 (-137)" << "\n" << endl; // std_ulogic_vector .to_uint() std_ulogic_vector<4> tu1; std_ulogic_vector<32> tu2; std_ulogic_vector<40> tu3; std_ulogic_vector<4> tu4; sc_biguint<2> tu5; sc_biguint<4> tu6; sc_biguint<8> tu7; tu1 = "1001"; // 9 tu2 = "10000000000000000000000000000001"; // 2147483649 tu3 = "0000000110000000000000000000000000000001"; // 6442450945 tu4 = "1101"; tu5 = tu4.to_uint(); tu6 = tu4.to_uint(); tu7 = tu4.to_uint(); cout << "std_ulogic_vector \t\t<=\t\t to_uint()" << "\n-----------------------------------------------------------------" << "\nTU1 = \t\t\t\t " << tu1 << "\t " << tu1.to_uint() << "\nTU2 = " << tu2 << "\t " << tu2.to_uint() << "\nTU3 = " << tu3 << "\t " << tu3.to_uint() << "\nTU4 = " << tu4 << " \t\t\t\t\t " << tu5 << "\t (" << tu5[1] << tu5[0] << ")" << "\nTU4 = " << tu4 << " \t\t\t\t\t " << tu6 << "\t (" << tu6[3] << tu6[2] << tu6[1] << tu6[0] << ")" << "\nTU4 = " << tu4 << " \t\t\t\t\t " << tu7 << "\t(" << tu7[7] << tu7[6] << tu7[5] << tu7[4] << tu7[3] << tu7[2] << tu7[1] << tu7[0] << ")" << "\n" << endl; // std_ulogic_vector .to_int() std_ulogic_vector<4> ts1; std_ulogic_vector<32> ts2; std_ulogic_vector<40> ts3; std_ulogic_vector<5> ts4; sc_bigint<3> ts5; sc_bigint<5> ts6; sc_bigint<9> ts7; ts1 = "1001"; // -7 ts2 = "11111111111111111111101111111001"; // -1031 ts3 = "0000000111111111111111111111101111111001"; // 8589933561 ts4 = "11001"; ts5 = ts4.to_int(); ts6 = ts4.to_int(); ts7 = ts4.to_int(); cout << "std_ulogic_vector \t\t<=\t\t to_int()" << "\n-----------------------------------------------------------------" << "\nTS1 = \t\t\t\t " << ts1 << "\t " << ts1.to_int() << "\nTS2 = " << ts2 << "\t " << ts2.to_int() << "\nTS3 = " << ts3 << "\t " << ts3.to_int() << "\nTS4 = " << ts4 << " \t\t\t\t\t " << ts5 << "\t (" << ts5[2] << ts5[1] << ts5[0] << ")" << "\nTS4 = " << ts4 << " \t\t\t\t\t " << ts6 << "\t (" << ts6[4] << ts6[3] << ts6[2] << ts6[1] << ts6[0] << ")" << "\nTS4 = " << ts4 << " \t\t\t\t\t " << ts7 << "\t(" << ts7[8] << ts7[7] << ts7[6] << ts7[5] << ts7[4] << ts7[3] << ts7[2] << ts7[1] << ts7[0] << ")" << "\n" << endl; // std_ulogic_vector Typecasted to sc_unsigned std_ulogic_vector<4> tcu1; sc_biguint<2> tcu2; sc_biguint<4> tcu3; sc_biguint<8> tcu4; tcu1 = "1101"; tcu2 = tcu1; tcu3 = tcu1; tcu4 = tcu1; cout << "std_ulogic_vector \t\t<=\t\t Typecast sc_unsigned" << "\n-----------------------------------------------------------------" << "\nTCU1 = " << tcu1 << " \t\t\t\t\t " << tcu2 << "\t (" << tcu2[1] << tcu2[0] << ")" << "\nTCU1 = " << tcu1 << " \t\t\t\t\t " << tcu3 << "\t (" << tcu3[3] << tcu3[2] << tcu3[1] << tcu3[0] << ")" << "\nTCU1 = " << tcu1 << " \t\t\t\t\t " << tcu4 << "\t(" << tcu4[7] << tcu4[6] << tcu4[5] << tcu4[4] << tcu4[3] << tcu4[2] << tcu4[1] << tcu4[0] << ")" << "\n" << endl; // std_ulogic_vector Typecasted to sc_signed std_ulogic_vector<5> tcs1; sc_bigint<3> tcs2; sc_bigint<5> tcs3; sc_bigint<9> tcs4; tcs1 = "11001"; tcs2 = sc_bigint<3>(tcs1); tcs3 = sc_bigint<5>(tcs1); tcs4 = sc_bigint<9>(tcs1); cout << "std_ulogic_vector \t\t<=\t\t Typecast sc_signed" << "\n-----------------------------------------------------------------" << "\nTCS1 = " << tcs1 << " \t\t\t\t\t " << tcs2 << "\t (" << tcs2[2] << tcs2[1] << tcs2[0] << ")" << "\nTCS1 = " << tcs1 << " \t\t\t\t\t " << tcs3 << "\t (" << tcs3[4] << tcs3[3] << tcs3[2] << tcs3[1] << tcs3[0] << ")" << "\nTCS1 = " << tcs1 << " \t\t\t\t\t " << tcs4 << "\t(" << tcs4[8] << tcs4[7] << tcs4[6] << tcs4[5] << tcs4[4] << tcs4[3] << tcs4[2] << tcs4[1] << tcs4[0] << ")" << "\n" << endl; // std_ulogic_vector .to_string() std_ulogic_vector<9> tstr; std::string str; tstr = "UXZ01WLH-"; str = tstr.to_string(); cout << "std_ulogic_vector \t<=\t to_string()" << "\n--------------------------------------------" << "\nTSTR = " << tstr << " \t\t " << str << endl; // 3. OPERATORS // Supported operators: ~ & ^ | &= ^= |= = [] range() // and_reduce() or_reduce() xor_reduce() std_ulogic_vector<4> ra; std_ulogic_vector<4> rb; std_ulogic_vector<4> rc; std_ulogic_vector<9> rd; std_ulogic_vector<4> re; std_ulogic_vector<4> rf; std_ulogic_vector<4> rg; std_ulogic_vector<9> rh; std_ulogic_vector<4> ri; std_ulogic_vector<4> rj; std_ulogic_vector<4> rl; std_ulogic_vector<4> rdata4; std_ulogic_vector<9> rdata9; rdata4 = "1000"; rdata9 = "UXZ01WHL-"; ra.range(0,3) = rdata4; rb.range(3,0) = rdata4; ( rc.range(1,3), rc.range(0,0) ) = rdata4; ( rd.range(8,6), rd.range(5,0) ) = rdata9; re = "1111"; re.range(2,2) = std_ulogic_vector<1>( rdata4[1] ); rf = rdata4.range(0,3); rg = rdata4.range(3,0); rh = ( rdata9.range(8,6), rdata9.range(5,0) ); ri = ( rdata4.range(0,1), rdata4.range(2,3) ); rj = "1111"; rj[1] = rdata4.range(2,2)[0]; rl = ( rdata4.range(1,1), rdata4.range(3,3), rdata4.range(0,0), rdata4.range(2,2) ); cout.precision(15); cout << "\nrange() tests" << "\n-----------------------------------------------------------------" << "\nINITIAL 4-BIT \t" << rdata4 << "\nINITIAL 9-BIT \t" << rdata9 << "\n" << "\nLVALUE RISE \t" << ra[0] << "\t" << ra[1] << "\t" << ra[2] << "\t" << ra[3] << "\nLVALUE FALL \t" << rb[0] << "\t" << rb[1] << "\t" << rb[2] << "\t" << rb[3] << "\nLVALUE SUB RISE " << rc[0] << "\t" << rc[1] << "\t" << rc[2] << "\t" << rc[3] << "\nLVALUE SUB FALL " << rd[0] << "\t" << rd[1] << "\t" << rd[2] << "\t" << rd[3] << "\t" << rd[4] << "\t" << rd[5] << "\t" << rd[6] << "\t" << rd[7] << "\t" << rd[8] << "\nLVALUE BIT \t" << re[0] << "\t" << re[1] << "\t" << re[2] << "\t" << re[3] << "\n\nRVALUE RISE \t" << rf[0] << "\t" << rf[1] << "\t" << rf[2] << "\t" << rf[3] << "\nRVALUE FALL \t" << rg[0] << "\t" << rg[1] << "\t" << rg[2] << "\t" << rg[3] << "\nRVALUE SUB FALL " << rh[0] << "\t" << rh[1] << "\t" << rh[2] << "\t" << rh[3] << "\t" << rh[4] << "\t" << rh[5] << "\t" << rh[6] << "\t" << rh[7] << "\t" << rh[8] << "\nRVALUE SUB RISE " << ri[0] << "\t" << ri[1] << "\t" << ri[2] << "\t" << ri[3] << "\nRVALUE BIT [] \t" << rj[0] << "\t" << rj[1] << "\t" << rj[2] << "\t" << rj[3] << "\nRVALUE BIT \t" << rl[0] << "\t" << rl[1] << "\t" << rl[2] << "\t" << rl[3] << endl; #define VAL1 "1010" #define VAL2 "1000" #define VAL3 "111011" std_ulogic_vector<4> op1; op1 = VAL1; std_ulogic_vector<4> op2; op2 = VAL2; std_ulogic_vector<4> r1, r2, r3, r4, r5, r6, r7, r8; std_ulogic_vector<4> r9, r10, r11, r12, r13, r14; std_ulogic_vector<4> r15, r16, r17, r18, r19; std_ulogic_vector<4> r20, r21, r22, r23, r24; std_ulogic_vector<4> r25, r26, r27, r28, r29; std_ulogic_vector<4> r30, r31, r32, r33, r34, r35; std_ulogic_vector<4> r36, r37, r38, r39, r40, r41; std_ulogic r42, r43, r44; // r1 = op1 * op2; // Multiplication // r2 = op1 / op2; // Division // r3 = op1 % op2; // Modulus // r4 = op1 + op2; // Addition // r5 = op1 - op2; // Subtraction // r6 = !op1; // Logical NOT // r7 = op1 && op2; // Logical AND // r8 = op1 || op2; // Logical OR // r9 = op1 < op2; // Less than // r10 = op1 <= op2; // Less than or equal // r11 = op1 > op2; // Greater than // r12 = op1 >= op2; // Greater than or equal // r13 = op1 += op2; // Compound addition // op1 = VAL1; op2 = VAL2; // r14 = op1 -= op2; // Compound subtraction // op1 = VAL1; op2 = VAL2; // r15 = op1 *= op2; // Compound multiplication // op1 = VAL1; op2 = VAL2; // r16 = op1 /= op2; // Compound division // op1 = VAL1; op2 = VAL2; // r17 = op1 %= op2; // Compound modulus // op1 = VAL1; op2 = VAL2; // r18 = op1 <<= op2; // Compound shift left // op1 = VAL1; op2 = VAL2; // r19 = op1 >>= op2; // Compound shift right // op1 = VAL1; op2 = VAL2; r20 = op1 &= op2; // Compound bitwise AND op1 = VAL1; op2 = VAL2; r36 = op1 &= VAL3; op1 = VAL1; r21 = op1 ^= op2; // Compound bitwise XOR op1 = VAL1; op2 = VAL2; r37 = op1 ^= VAL3; op1 = VAL1; r22 = op1 |= op2; // Compound bitwise OR op1 = VAL1; op2 = VAL2; r38 = op1 |= VAL3; op1 = VAL1; // r23 = op2++; // Postfix increment // op1 = VAL1; op2 = VAL2; // r24 = ++op2; // Prefix increment // op1 = VAL1; op2 = VAL2; // r25 = op2--; // Postfix decrement // op1 = VAL1; op2 = VAL2; // r26 = --op2; // Prefix decrement // op1 = VAL1; op2 = VAL2; // r27 = (op1 > op2) ? true : false; // Arithmetic if // r28 = (op1 < op2) ? true : false; // Arithmetic if // r29 = op1, r29 = op2; // Comma r30 = ~op1; // Bitwise NOT // r31 = op1 << op2; // Left shift // op1 = VAL1; op2 = VAL2; // r32 = op1 >> op2; // Right shift // op1 = VAL1; op2 = VAL2; r33 = op1 & op2; // Bitwise AND r39 = op1 & VAL3; r34 = op1 ^ op2; // Bitwise XOR r40 = op1 ^ VAL3; r35 = op1 | op2; // Bitwise OR r41 = op1 | VAL3; r42 = and_reduce(op1); // AND reduction r43 = or_reduce(op1); // OR reduction r44 = xor_reduce(op1); // XOR reduction cout << "\nop1\t operator\t op2\t result [All operands are std_ulogic_vector]" << "\n----------------------------------------------------------------" // << "\n" << op1 << "\t * \t\t " << op2 << "\t = " << r1 // << "\n" << op1 << "\t / \t\t " << op2 << "\t = " << r2 // << "\n" << op1 << "\t % \t\t " << op2 << "\t = " << r3 // << "\n" << op1 << "\t + \t\t " << op2 << "\t = " << r4 // << "\n" << op1 << "\t - \t\t " << op2 << "\t = " << r5 // << "\n!(" << op1 << ") \t\t\t\t = " << r6 // << "\n" << op1 << "\t && \t\t " << op2 << "\t = " << r7 // << "\n" << op1 << "\t || \t\t " << op2 << "\t = " << r8 // << "\n" << op1 << "\t < \t\t " << op2 << "\t = " << r9 // << "\n" << op1 << "\t <= \t\t " << op2 << "\t = " << r10 // << "\n" << op1 << "\t > \t\t " << op2 << "\t = " << r11 // << "\n" << op1 << "\t >= \t\t " << op2 << "\t = " << r12 // << "\n" << op1 << "\t += \t\t " << op2 << "\t = " << r13 // << "\n" << op1 << "\t -= \t\t " << op2 << "\t = " << r14 // << "\n" << op1 << "\t *= \t\t " << op2 << "\t = " << r15 // << "\n" << op1 << "\t /= \t\t " << op2 << "\t = " << r16 // << "\n" << op1 << "\t %= \t\t " << op2 << "\t = " << r17 // << "\n" << op1 << "\t <<=\t\t " << op2 << "\t = " << r18 // << "\n" << op1 << "\t >>=\t\t " << op2 << "\t = " << r19 << "\n" << op1 << "\t &= \t\t " << op2 << "\t = " << r20 << "\n" << op1 << "\t ^= \t\t " << op2 << "\t = " << r21 << "\n" << op1 << "\t |= \t\t " << op2 << "\t = " << r22 // << "\n" << "\t ()++ \t " << op2 << "\t = " << r23 // << "\n" << "\t ++() \t " << op2 << "\t = " << r24 // << "\n" << "\t ()-- \t " << op2 << "\t = " << r25 // << "\n" << "\t --() \t " << op2 << "\t = " << r26 // << "\n" << op1 << "\t > ?: \t " << op2 << "\t = " << r27 // << "\n" << op1 << "\t < ?: \t " << op2 << "\t = " << r28 // << "\n" << op1 << "\t , \t\t " << op2 << "\t = " << r29 << "\n~(" << op1 << ") \t\t\t = " << r30 // << "\n" << op1 << "\t << \t\t " << op2 << "\t = " << r31 // << "\n" << op1 << "\t >> \t\t " << op2 << "\t = " << r32 << "\n" << op1 << "\t & \t\t " << op2 << "\t = " << r33 << "\n" << op1 << "\t ^ \t\t " << op2 << "\t = " << r34 << "\n" << op1 << "\t | \t\t " << op2 << "\t = " << r35 << "\n\n" << op1 << "\t &= \t\t " << VAL3 << "\t = " << r36 << "\n" << op1 << "\t ^= \t\t " << VAL3 << "\t = " << r37 << "\n" << op1 << "\t |= \t\t " << VAL3 << "\t = " << r38 << "\n" << op1 << "\t & \t\t " << VAL3 << "\t = " << r39 << "\n" << op1 << "\t ^ \t\t " << VAL3 << "\t = " << r40 << "\n" << op1 << "\t | \t\t " << VAL3 << "\t = " << r41 << "\n\n" << op1 << "\t and_reduce() \t = " << r42 << "\n" << op1 << "\t or_reduce() \t = " << r43 << "\n" << op1 << "\t xor_reduce() \t = " << r44 << endl; if (op1 == op2) // Equality cout << "\n" << op1 << "\t == \t\t " << op2 << "\t -> true" << endl; else cout << "\n" << op1 << "\t == \t\t " << op2 << "\t -> false" << endl; if (op1 != op2) // Inequality cout << op1 << "\t != \t\t " << op2 << "\t -> true" << endl; else cout << op1 << "\t != \t\t " << op2 << "\t -> false" << endl; op1 = op2 = "1111"; // Assignment operator concatenation cout << "\n" << op1 << "\t = \t\t " << op2 << endl; // 4. OPERATOR DEFINITIONS // & | ^ ~ std_ulogic_vector<9> suv; std_ulogic_vector<9> vu; std_ulogic_vector<9> vx; std_ulogic_vector<9> v0; std_ulogic_vector<9> v1; std_ulogic_vector<9> vz; std_ulogic_vector<9> vw; std_ulogic_vector<9> vl; std_ulogic_vector<9> vh; std_ulogic_vector<9> vd; std_ulogic_vector<9> bang; suv = "UX01ZWLH-"; vu = "UUUUUUUUU" & suv; vx = "XXXXXXXXX" & suv; v0 = "000000000" & suv; v1 = "111111111" & suv; vz = "ZZZZZZZZZ" & suv; vw = "WWWWWWWWW" & suv; vl = "LLLLLLLLL" & suv; vh = "HHHHHHHHH" & suv; vd = "---------" & suv; cout << "\n+-------------------------+" << "\n| AND (&) | X | 0 | 1 | Z |" << "\n+-------------------------+" << "\n| X | " << vx[7] << " | " << vx[6] << " | " << vx[5] << " | " << vx[4] << " | " << "\n+-------------------------+" << "\n| 0 | " << v0[7] << " | " << v0[6] << " | " << v0[5] << " | " << v0[4] << " | " << "\n+-------------------------+" << "\n| 1 | " << v1[7] << " | " << v1[6] << " | " << v1[5] << " | " << v1[4] << " | " << "\n+-------------------------+" << "\n| Z | " << vz[7] << " | " << vz[6] << " | " << vz[5] << " | " << vz[4] << " | " << "\n+-------------------------+" << endl; vu = "UUUUUUUUU" | suv; vx = "XXXXXXXXX" | suv; v0 = "000000000" | suv; v1 = "111111111" | suv; vz = "ZZZZZZZZZ" | suv; vw = "WWWWWWWWW" | suv; vl = "LLLLLLLLL" | suv; vh = "HHHHHHHHH" | suv; vd = "---------" | suv; cout << "\n+-------------------------+" << "\n| OR (|) | X | 0 | 1 | Z |" << "\n+-------------------------+" << "\n| X | " << vx[7] << " | " << vx[6] << " | " << vx[5] << " | " << vx[4] << " | " << "\n+-------------------------+" << "\n| 0 | " << v0[7] << " | " << v0[6] << " | " << v0[5] << " | " << v0[4] << " | " << "\n+-------------------------+" << "\n| 1 | " << v1[7] << " | " << v1[6] << " | " << v1[5] << " | " << v1[4] << " | " << "\n+-------------------------+" << "\n| Z | " << vz[7] << " | " << vz[6] << " | " << vz[5] << " | " << vz[4] << " | " << "\n+-------------------------+" << endl; vu = "UUUUUUUUU" ^ suv; vx = "XXXXXXXXX" ^ suv; v0 = "000000000" ^ suv; v1 = "111111111" ^ suv; vz = "ZZZZZZZZZ" ^ suv; vw = "WWWWWWWWW" ^ suv; vl = "LLLLLLLLL" ^ suv; vh = "HHHHHHHHH" ^ suv; vd = "---------" ^ suv; cout << "\n+-------------------------+" << "\n| XOR (^) | X | 0 | 1 | Z |" << "\n+-------------------------+" << "\n| X | " << vx[7] << " | " << vx[6] << " | " << vx[5] << " | " << vx[4] << " | " << "\n+-------------------------+" << "\n| 0 | " << v0[7] << " | " << v0[6] << " | " << v0[5] << " | " << v0[4] << " | " << "\n+-------------------------+" << "\n| 1 | " << v1[7] << " | " << v1[6] << " | " << v1[5] << " | " << v1[4] << " | " << "\n+-------------------------+" << "\n| Z | " << vz[7] << " | " << vz[6] << " | " << vz[5] << " | " << vz[4] << " | " << "\n+-------------------------+" << endl; bang = ~suv; cout << "\n+-------------------------+" << "\n| NOT (~) | X | 0 | 1 | Z |" << "\n+-------------------------+" << "\n| | " << bang[7] << " | " << bang[6] << " | " << bang[5] << " | " << bang[4] << " | " << "\n+-------------------------+" << endl; return 0; }
int sc_main(int argc, char* argv[]) { // signal declaration sc_clock clk("clk", 1, SC_US, 0.5); sc_signal<sc_logic> reset; sc_signal<sc_lv<32> > instruction; sc_signal<sc_logic> overflow; // module declaration top top0("top0"); // signal connection top0.clock(clk); top0.reset(reset); top0.instruction(instruction); top0.overflow(overflow); // Open VCD file sc_trace_file *wf = sc_create_vcd_trace_file("test_DM_wave"); wf->set_time_unit(1, SC_NS); // error counter for tb int tb_error = 0; // set signal to .vcd wave file sc_trace(wf,clk,"clk"); sc_trace(wf,instruction,"instruction"); sc_trace(wf,overflow,"overflow"); sc_trace(wf,reset,"reset"); sc_trace(wf,top0.r1_data,"r1_data"); sc_trace(wf,top0.r2_data,"r2_data"); sc_trace(wf,top0.r3_data,"r3_data"); sc_trace(wf,top0.out_data,"mem_output"); sc_trace(wf,top0.alu_output,"alu_output"); sc_trace(wf,top0.m31out,"rw_data"); // init reset = sc_logic('0'); instruction = sc_lv<32>("00000000000000000000000000000000"); // run simulation sc_start(0,SC_US); instruction = sc_lv<32>("01000100000000000000001111111111"); sc_start(1,SC_US); cout << "@" << sc_time_stamp() << endl << "instruction : " << instruction << endl << "reset : " << reset << endl << "r1data :" << top0.r1_data << endl << "r2data :" << top0.r2_data << endl << "r3data :" << top0.r3_data << endl << "mem_output :" << top0.out_data << endl << "alu_output :" << top0.alu_output << endl << "rw_data :" << top0.m31out << endl << endl; /* // start testing here for(int i=0 ; i<SIZE_OF_TEST ; i++) { instruction = sc_lv<32>(in_data_list[i]); // add simulation time sc_start(1,SC_US); cout << "@" << sc_time_stamp() <<" ,instruction : " << instruction << " ,reset : " << reset << endl; // error check! temp_output = out_data_list[i]; if(out_data.read() != temp_output){ tb_error++; #ifdef REG_DEBUG cout << " error! " << endl; #endif } } */ if(tb_error != 0) cout << tb_error << " errors!" << endl; else cout << "pass!" << endl; sc_start(2,SC_NS); sc_close_vcd_trace_file(wf); return 0; }
void cover_sc_bit() { sc_bit bdef; sc_bit bf(false); sc_bit bt(true); sc_bit b0(0); sc_bit b1(1); try { sc_bit foo(2); } catch (sc_report) { cout << "Caught exception for sc_bit(2)\n"; } sc_bit bc0('0'); sc_bit bc1('1'); try { sc_bit foo('2'); } catch (sc_report) { cout << "Caught exception for sc_bit('2')\n"; } sc_bit blc0(sc_logic('0')); sc_bit blc1(sc_logic('1')); sc_bit blcx(sc_logic('X')); sc_bit bcop(bt); cout << bdef << bf << bt << b0 << b1 << bc0 << bc1 << blc0 << blc1 << blcx << bcop << endl; sc_bit b; b = bt; sc_assert(b); b = 0; sc_assert(!b); b = true; sc_assert(b.to_bool()); b = '0'; sc_assert(!b.to_bool()); b = sc_logic('1'); sc_assert(b.to_char() == '1'); b = bf; sc_assert(~b); b |= bt; sc_assert(b); b &= bf; sc_assert(!b); b |= 1; sc_assert(b); b &= 0; sc_assert(!b); b |= '1'; sc_assert(b); b &= '0'; sc_assert(!b); b |= true; sc_assert(b); b &= false; sc_assert(!b); b ^= bt; sc_assert(b); b ^= 1; sc_assert(!b); b ^= '1'; sc_assert(b); b ^= true; sc_assert(!b); sc_assert(b == bf); sc_assert(b == 0); sc_assert(b == '0'); sc_assert(b == false); b = 1; sc_assert(b == bt); sc_assert(b == 1); sc_assert(b == '1'); sc_assert(b == true); sc_assert(1 == b); sc_assert('1' == b); sc_assert(true == b); sc_assert(equal(b, bt)); sc_assert(equal(b, 1)); sc_assert(equal(b, '1')); sc_assert(equal(b, true)); sc_assert(equal(1, b)); sc_assert(equal('1', b)); sc_assert(equal(true, b)); b = 0; sc_assert(b != bt); sc_assert(b != 1); sc_assert(b != '1'); sc_assert(b != true); sc_assert(1 != b); sc_assert('1' != b); sc_assert(true != b); sc_assert(not_equal(b, bt)); sc_assert(not_equal(b, 1)); sc_assert(not_equal(b, '1')); sc_assert(not_equal(b, true)); sc_assert(not_equal(1, b)); sc_assert(not_equal('1', b)); sc_assert(not_equal(true, b)); // the following assertion is incorrect, because the b_not() method // is destructive, i.e., it implements something like b ~= void. /// sc_assert(b == b_not(b.b_not())); b.b_not(); sc_assert(b); sc_bit bx; b_not(bx, b0); sc_assert(bx); b_not(bx, b1); sc_assert(!bx); cout << (b0|b0) << (b0|b1) << (b1|b0) << (b1|b1) << endl; cout << (b0&b0) << (b0&b1) << (b1&b0) << (b1&b1) << endl; cout << (b0^b0) << (b0^b1) << (b1^b0) << (b1^b1) << endl; cout << (b0|0) << (b0|1) << (b1|0) << (b1|1) << endl; cout << (b0&0) << (b0&1) << (b1&0) << (b1&1) << endl; cout << (b0^0) << (b0^1) << (b1^0) << (b1^1) << endl; cout << (b0|'0') << (b0|'1') << (b1|'0') << (b1|'1') << endl; cout << (b0&'0') << (b0&'1') << (b1&'0') << (b1&'1') << endl; cout << (b0^'0') << (b0^'1') << (b1^'0') << (b1^'1') << endl; cout << (b0|true) << (b0|false) << (b1|true) << (b1|false) << endl; cout << (b0&true) << (b0&false) << (b1&true) << (b1&false) << endl; cout << (b0^true) << (b0^false) << (b1^true) << (b1^false) << endl; cout << (0|b0) << (0|b1) << (1|b0) << (1|b1) << endl; cout << (0&b0) << (0&b1) << (1&b0) << (1&b1) << endl; cout << (0^b0) << (0^b1) << (1^b0) << (1^b1) << endl; cout << ('0'|b0) << ('0'|b1) << ('1'|b0) << ('1'|b1) << endl; cout << ('0'&b0) << ('0'&b1) << ('1'&b0) << ('1'&b1) << endl; cout << ('0'^b0) << ('0'^b1) << ('1'^b0) << ('1'^b1) << endl; cout << (false|b0) << (false|b1) << (true|b0) << (true|b1) << endl; cout << (false&b0) << (false&b1) << (true&b0) << (true&b1) << endl; cout << (false^b0) << (false^b1) << (true^b0) << (true^b1) << endl; cout << b_or(b0,b0) << b_or(b0,b1) << b_or(b1,b0) << b_or(b1,b1) << endl; cout << b_and(b0,b0) << b_and(b0,b1) << b_and(b1,b0) << b_and(b1,b1) << endl; cout << b_xor(b0,b0) << b_xor(b0,b1) << b_xor(b1,b0) << b_xor(b1,b1) << endl; cout << b_or(b0,0) << b_or(b0,1) << b_or(b1,0) << b_or(b1,1) << endl; cout << b_and(b0,0) << b_and(b0,1) << b_and(b1,0) << b_and(b1,1) << endl; cout << b_xor(b0,0) << b_xor(b0,1) << b_xor(b1,0) << b_xor(b1,1) << endl; cout << b_or(b0,'0') << b_or(b0,'1') << b_or(b1,'0') << b_or(b1,'1') << endl; cout << b_and(b0,'0') << b_and(b0,'1') << b_and(b1,'0') << b_and(b1,'1') << endl; cout << b_xor(b0,'0') << b_xor(b0,'1') << b_xor(b1,'0') << b_xor(b1,'1') << endl; cout << b_or(b0,false) << b_or(b0,true) << b_or(b1,false) << b_or(b1,true) << endl; cout << b_and(b0,false) << b_and(b0,true) << b_and(b1,false) << b_and(b1,true) << endl; cout << b_xor(b0,false) << b_xor(b0,true) << b_xor(b1,false) << b_xor(b1,true) << endl; cout << b_or(0,b0) << b_or(0,b1) << b_or(1,b0) << b_or(1,b1) << endl; cout << b_and(0,b0) << b_and(0,b1) << b_and(1,b0) << b_and(1,b1) << endl; cout << b_xor(0,b0) << b_xor(0,b1) << b_xor(1,b0) << b_xor(1,b1) << endl; cout << b_or('0',b0) << b_or('0',b1) << b_or('1',b0) << b_or('1',b1) << endl; cout << b_and('0',b0) << b_and('0',b1) << b_and('1',b0) << b_and('1',b1) << endl; cout << b_xor('0',b0) << b_xor('0',b1) << b_xor('1',b0) << b_xor('1',b1) << endl; cout << b_or(false,b0) << b_or(false,b1) << b_or(true,b0) << b_or(true,b1) << endl; cout << b_and(false,b0) << b_and(false,b1) << b_and(true,b0) << b_and(true,b1) << endl; cout << b_xor(false,b0) << b_xor(false,b1) << b_xor(true,b0) << b_xor(true,b1) << endl; b_or(b, b0, b1); sc_assert(b); b_and(b, b0, b1); sc_assert(!b); b_xor(b, b0, b1); sc_assert(b); }
//------------------------------------------------------------------------ void IHEX_FSM::FSM_NEXT_Q() { for(i=0;i<2;i++) { LRC[i] = sc_logic('0'); ALE[i] = sc_logic('0'); DLE[i] = sc_logic('0'); CLE[i] = sc_logic('0'); } for(;i<4;i++) { LRC[i] = sc_logic('0'); ALE[i] = sc_logic('0'); } switch(Q) { case IDLE: if(SC.read() == '1') next_Q = DCH; break; case DCH: CLE[1] = sc_logic('1'); if(IS_HEX.read() == '1') next_Q = DCL; else next_Q = ERR; break; case DCL: CLE[0] = sc_logic('1'); if(IS_HEX.read() == '1') next_Q = ADHH; else next_Q = ERR; break; case ADHH: ALE[3] = sc_logic('1'); if(IS_HEX.read() == '1') next_Q = ADHL; else next_Q = ERR; break; case ADHL: ALE[2] = sc_logic('1'); if(IS_HEX.read() == '1') next_Q = ADLH; else next_Q = ERR; break; case ADLH: ALE[1] = sc_logic('1'); if(IS_HEX.read() == '1') next_Q = ADLL; else next_Q = ERR; break; case ADLL: ALE[0] = sc_logic('1'); if(IS_HEX.read() == '1') next_Q = EMH; else next_Q = ERR; break; case EMH: if(IS_HEX.read() == '1') next_Q = EML; else next_Q = ERR; break; case EML: if(IS_HEX.read() == '1') if(TDC.read() == '0') next_Q = DH; else next_Q = LRCH; else next_Q = ERR; break; case DH: DLE[1] = sc_logic('1'); if(IS_HEX.read() == '1') next_Q = DL; else next_Q = ERR; break; case DL: DLE[0] = sc_logic('1'); if(IS_HEX.read() == '1') { if(TDC.read() == '0') next_Q = DH; else next_Q = LRCH; } else next_Q = ERR; break; case MEMW: break; case LRCH: if(IS_HEX.read() == '1') next_Q = LRCL; else next_Q = ERR; break; case LRCL: if(IS_HEX.read() == '1') next_Q = IDLE; else next_Q = ERR; break; case CMPLRC: break; case ERR: next_Q = IDLE; } }
* Created on: 1 mars 2016 * Author: joel */ #include <systemc.h> #include "Block_Switching.h" //#include "Bloc_Deswitching.h" //#include "BDT_croisee.h" //#include "register.h" //#include "xor2.h" //#include "Block_Routage.h" //Declaration of struct const int N = 5; struct logic_vals { sc_logic a, b; } AB [N]= { { sc_logic(0), sc_logic(0) }, { sc_logic(0), sc_logic(1) }, { sc_logic(1), sc_logic(0) }, { sc_logic(1), sc_logic(0) }, { sc_logic(0), sc_logic(1) } }; int sc_main(int args, char* argv[]){ //////////////////////////---------- SIMULACION DE BLOQUE DE SWITCHING-----------------///////////////////////// module_Block_Switching B_Switching("B_Switching"); sc_clock clk("clk", 10, 0.5, 0, true); // perido = 10 ns duty = 0.5, iniciar en 0 logico o en 1 logico, true = iniciar con rising edge false= iniciar con falling edge sc_signal < sc_logic > fil_j, fil_j1, fil_j_code, fil_j1_code, S_switch; B_Switching (clk, fil_j, fil_j1, S_switch, fil_j_code, fil_j1_code);
int sc_main(int ac, char *av[]) { // 1. DECLARATION SYNTAX std_ulogic s1; std_ulogic s2, s3, s4, s5, s6, s7, s8, s9, s10, s11; // 2. TYPE CONVERSION // std_ulogic <- std_ulogic s1 = 'U'; s2 = 'X'; s3 = '0'; s4 = '1'; s5 = 'Z'; s6 = 'W'; s7 = 'L'; s8 = 'H'; s9 = '-'; s10 = true; s11 = false; cout << "\nstd_ulogic \t<=\t\t std_ulogic" << "\n-------------------------------------------" << "\nUNINITIALIZED \t= " << s1 << "\t\t 'U'" << "\nUNKNOWN \t= " << s2 << "\t\t 'X'" << "\nZERO \t\t= " << s3 << "\t\t '0'" << "\nONE \t\t= " << s4 << "\t\t '1'" << "\nTRISTATE \t= " << s5 << "\t\t 'Z'" << "\nWEAK-UNKNOWN \t= " << s6 << "\t\t 'W'" << "\nWEAK-ZERO \t= " << s7 << "\t\t 'L'" << "\nWEAK-ONE \t= " << s8 << "\t\t 'H'" << "\nDONT-CARE \t= " << s9 << "\t\t '-'" << "\nTRUE \t\t= " << s10 << "\t\t true" << "\nFALSE \t\t= " << s11 << "\t\t false" << "\n" << endl; // std_ulogic <- literals std_ulogic a, b, c, d; a = true; b = false; c = 1; d = 0; cout << "std_ulogic <=\t literals" << "\n-------------------------" << "\nA = " << a << "\t\t true" << "\nB = " << b << "\t\t false" << "\nC = " << c << "\t\t 1" << "\nD = " << d << "\t\t 0" << "\n" << endl; // std_ulogic <- bool std_ulogic su1, su2, su3, su4; bool b1, b2, b3, b4; b1 = true; b2 = false; b3 = 1; b4 = 0; su1 = b1; su2 = b2; su3 = b3; su4 = b4; cout << "std_ulogic <=\t bool" << "\n---------------------" << "\nTRUE \t= " << su1 << "\t " << b1 << "\nFALSE \t= " << su2 << "\t " << b2 << "\n1 \t= " << su3 << "\t " << b3 << "\n0 \t= " << su4 << "\t " << b4 << "\n" << endl; // std_ulogic <- char std_ulogic sc1, sc2, sc3, sc4, sc5, sc6, sc7, sc8, sc9; std_ulogic sc10, sc11, sc12, sc13, sc14, sc15, sc16, sc17, sc18, sc19; char c1, c2, c3, c4, c5, c6, c7, c8, c9; char c10, c11, c12, c13, c14, c15, c16, c17, c18, c19; c1 = 'U'; c2 = 'u'; c3 = 'X'; c4 = 'x'; c5 = '0'; c6 = '1'; c7 = 'Z'; c8 = 'z'; c9 = 'W'; c10 = 'w'; c11 = 'L'; c12 = 'l'; c13 = 'H'; c14 = 'h'; c15 = '-'; c16 = 'D'; c17 = 'd'; c18 = 'B'; c19 = 'F'; sc1 = c1; sc2 = c2; sc3 = c3; sc4 = c4; sc5 = c5; sc6 = c6; sc7 = c7; sc8 = c8; sc9 = c9; sc10 = c10; sc11 = c11; sc12 = c12; sc13 = c13; sc14 = c14; sc15 = c15; sc16 = c16; sc17 = c17; sc18 = c18; sc19 = c19; cout << "std_ulogic <=\t char" << "\n---------------------" << "\nSC1 \t= " << sc1 << "\t '" << c1 << "'" << "\nSC2 \t= " << sc2 << "\t '" << c2 << "'" << "\nSC3 \t= " << sc3 << "\t '" << c3 << "'" << "\nSC4 \t= " << sc4 << "\t '" << c4 << "'" << "\nSC5 \t= " << sc5 << "\t '" << c5 << "'" << "\nSC6 \t= " << sc6 << "\t '" << c6 << "'" << "\nSC7 \t= " << sc7 << "\t '" << c7 << "'" << "\nSC8 \t= " << sc8 << "\t '" << c8 << "'" << "\nSC9 \t= " << sc9 << "\t '" << c9 << "'" << "\nSC10 \t= " << sc10 << "\t '" << c10 << "'" << "\nSC11 \t= " << sc11 << "\t '" << c11 << "'" << "\nSC12 \t= " << sc12 << "\t '" << c12 << "'" << "\nSC13 \t= " << sc13 << "\t '" << c13 << "'" << "\nSC14 \t= " << sc14 << "\t '" << c14 << "'" << "\nSC15 \t= " << sc15 << "\t '" << c15 << "'" << "\nSC16 \t= " << sc16 << "\t '" << c16 << "'" << "\nSC17 \t= " << sc17 << "\t '" << c17 << "'" << "\nSC18 \t= " << sc18 << "\t '" << c18 << "'" << "\nSC19 \t= " << sc19 << "\t '" << c19 << "'" << "\n" << endl; // 3. OPERATORS // Supported operators: ~ & ^ | &= ^= |= == != = #define VAL1 '1' #define VAL2 '1' std_ulogic op1 = sc_logic(VAL1); std_ulogic op2 = sc_logic(VAL2); std_ulogic r1, r2, r3, r4, r5, r6, r7, r8, r9; std_ulogic r10, r11, r12, r13, r14, r15, r16, r17, r18, r19; std_ulogic r20, r21, r22, r23, r24, r25, r26, r27, r28, r29; std_ulogic r30, r31, r32, r33, r34, r35; // r1 = op1 * op2; // Multiplication // r2 = op1 / op2; // Division // r3 = op1 % op2; // Modulus // r4 = op1 + op2; // Addition // r5 = op1 - op2; // Subtraction // r6 = !op1; // Logical NOT // r7 = op1 && op2; // Logical AND // r8 = op1 || op2; // Logical OR // r9 = op1 < op2; // Less than // r10 = op1 <= op2; // Less than or equal // r11 = op1 > op2; // Greater than // r12 = op1 >= op2; // Greater than or equal // r13 = op1 += op2; // Compound addition // op1 = VAL1; op2 = VAL2; // r14 = op1 -= op2; // Compound subtraction // op1 = VAL1; op2 = VAL2; // r15 = op1 *= op2; // Compound multiplication // op1 = VAL1; op2 = VAL2; // r16 = op1 /= op2; // Compound division // op1 = VAL1; op2 = VAL2; // r17 = op1 %= op2; // Compound modulus // op1 = VAL1; op2 = VAL2; // r18 = op1 <<= op2; // Compound shift left // op1 = VAL1; op2 = VAL2; // r19 = op1 >>= op2; // Compound shift right // op1 = VAL1; op2 = VAL2; r20 = op1 &= op2; // Compound bitwise AND op1 = VAL1; op2 = VAL2; r21 = op1 ^= op2; // Compound bitwise XOR op1 = VAL1; op2 = VAL2; r22 = op1 |= op2; // Compound bitwise OR op1 = VAL1; op2 = VAL2; // r23 = op2++; // Postfix increment // op1 = VAL1; op2 = VAL2; // r24 = ++op2; // Prefix increment // op1 = VAL1; op2 = VAL2; // r25 = op2--; // Postfix decrement // op1 = VAL1; op2 = VAL2; // r26 = --op2; // Prefix decrement // op1 = VAL1; op2 = VAL2; // r27 = (op1 > op2) ? true : false; // Arithmetic if // r28 = (op1 < op2) ? true : false; // Arithmetic if // r29 = op1, r29 = op2; // Comma r30 = ~op1; // Bitwise NOT // r31 = op1 << op2; // Left shift // op1 = VAL1; op2 = VAL2; // r32 = op1 >> op2; // Right shift // op1 = VAL1; op2 = VAL2; r33 = op1 & op2; // Bitwise AND r34 = op1 ^ op2; // Bitwise XOR r35 = op1 | op2; // Bitwise OR cout << "op1 \t operator \t op2 \t result [All operands are std_ulogic]" << "\n----------------------------------------------------------------" // << "\n" << op1 << "\t * \t\t " << op2 << "\t = " << r1 // << "\n" << op1 << "\t / \t\t " << op2 << "\t = " << r2 // << "\n" << op1 << "\t % \t\t " << op2 << "\t = " << r3 // << "\n" << op1 << "\t + \t\t " << op2 << "\t = " << r4 // << "\n" << op1 << "\t - \t\t " << op2 << "\t = " << r5 // << "\n!(" << op1 << ") \t\t\t\t = " << r6 // << "\n" << op1 << "\t && \t\t " << op2 << "\t = " << r7 // << "\n" << op1 << "\t || \t\t " << op2 << "\t = " << r8 // << "\n" << op1 << "\t < \t\t " << op2 << "\t = " << r9 // << "\n" << op1 << "\t <= \t\t " << op2 << "\t = " << r10 // << "\n" << op1 << "\t > \t\t " << op2 << "\t = " << r11 // << "\n" << op1 << "\t >= \t\t " << op2 << "\t = " << r12 // << "\n" << op1 << "\t += \t\t " << op2 << "\t = " << r13 // << "\n" << op1 << "\t -= \t\t " << op2 << "\t = " << r14 // << "\n" << op1 << "\t *= \t\t " << op2 << "\t = " << r15 // << "\n" << op1 << "\t /= \t\t " << op2 << "\t = " << r16 // << "\n" << op1 << "\t %= \t\t " << op2 << "\t = " << r17 // << "\n" << op1 << "\t <<=\t\t " << op2 << "\t = " << r18 // << "\n" << op1 << "\t >>=\t\t " << op2 << "\t = " << r19 << "\n" << op1 << "\t &= \t\t " << op2 << "\t = " << r20 << "\n" << op1 << "\t ^= \t\t " << op2 << "\t = " << r21 << "\n" << op1 << "\t |= \t\t " << op2 << "\t = " << r22 // << "\n" << "\t ()++ \t " << op2 << "\t = " << r23 // << "\n" << "\t ++() \t " << op2 << "\t = " << r24 // << "\n" << "\t ()-- \t " << op2 << "\t = " << r25 // << "\n" << "\t --() \t " << op2 << "\t = " << r26 // << "\n" << op1 << "\t > ?: \t " << op2 << "\t = " << r27 // << "\n" << op1 << "\t < ?: \t " << op2 << "\t = " << r28 // << "\n" << op1 << "\t , \t\t " << op2 << "\t = " << r29 << "\n~(" << op1 << ") \t\t\t\t = " << r30 // << "\n" << op1 << "\t << \t\t " << op2 << "\t = " << r31 // << "\n" << op1 << "\t >> \t\t " << op2 << "\t = " << r32 << "\n" << op1 << "\t & \t\t " << op2 << "\t = " << r33 << "\n" << op1 << "\t ^ \t\t " << op2 << "\t = " << r34 << "\n" << op1 << "\t | \t\t " << op2 << "\t = " << r35 << endl; if (op1 == op2) // Equality cout << op1 << "\t == \t\t " << op2 << "\t -> true" << endl; else cout << op1 << "\t == \t\t " << op2 << "\t -> false" << endl; if (op1 != op2) // Inequality cout << op1 << "\t != \t\t " << op2 << "\t -> true" << endl; else cout << op1 << "\t != \t\t " << op2 << "\t -> false" << endl; op1 = op2 = 0; // Assignment operator concatenation cout << op1 << "\t = \t\t " << op2 << endl; // 4. OPERATOR DEFINITIONS // & | ^ ~ std_ulogic v1, v2, v3, v4, v5, v6, v7, v8, v9; std_ulogic uu, ux, u0, u1, uz, uw, ul, uh, ud; std_ulogic xu, xx, x0, x1, xz, xw, xl, xh, xd; std_ulogic _0u, _0x, _00, _01, _0z, _0w, _0l, _0h, _0d; std_ulogic _1u, _1x, _10, _11, _1z, _1w, _1l, _1h, _1d; std_ulogic zu, zx, z0, z1, zz, zw, zl, zh, zd; std_ulogic wu, wx, w0, w1, wz, ww, wl, wh, wd; std_ulogic lu, lx, l0, l1, lz, lw, ll, lh, ld; std_ulogic hu, hx, h0, h1, hz, hw, hl, hh, hd; std_ulogic du, dx, d0, d1, dz, dw, dl, dh, dd; v1 = 'U'; v2 = 'X'; v3 = '0'; v4 = '1'; v5 = 'Z'; v6 = 'W'; v7 = 'L'; v8 = 'H'; v9 = '-'; uu = v1 & v1; ux = v1 & v2; u0 = v1 & v3; u1 = v1 & v4; uz = v1 & v5; uw = v1 & v6; ul = v1 & v7; uh = v1 & v8; ud = v1 & v9; xu = v2 & v1; xx = v2 & v2; x0 = v2 & v3; x1 = v2 & v4; xz = v2 & v5; xw = v2 & v6; xl = v2 & v7; xh = v2 & v8; xd = v2 & v9; _0u = v3 & v1; _0x = v3 & v2; _00 = v3 & v3; _01 = v3 & v4; _0z = v3 & v5; _0w = v3 & v6; _0l = v3 & v7; _0h = v3 & v8; _0d = v3 & v9; _1u = v4 & v1; _1x = v4 & v2; _10 = v4 & v3; _11 = v4 & v4; _1z = v4 & v5; _1w = v4 & v6; _1l = v4 & v7; _1h = v4 & v8; _1d = v4 & v9; zu = v5 & v1; zx = v5 & v2; z0 = v5 & v3; z1 = v5 & v4; zz = v5 & v5; zw = v5 & v6; zl = v5 & v7; zh = v5 & v8; zd = v5 & v9; wu = v6 & v1; wx = v6 & v2; w0 = v6 & v3; w1 = v6 & v4; wz = v6 & v5; ww = v6 & v6; wl = v6 & v7; wh = v6 & v8; wd = v6 & v9; lu = v7 & v1; lx = v7 & v2; l0 = v7 & v3; l1 = v7 & v4; lz = v7 & v5; lw = v7 & v6; ll = v7 & v7; lh = v7 & v8; ld = v7 & v9; hu = v8 & v1; hx = v8 & v2; h0 = v8 & v3; h1 = v8 & v4; hz = v8 & v5; hw = v8 & v6; hl = v8 & v7; hh = v8 & v8; hd = v8 & v9; du = v9 & v1; dx = v9 & v2; d0 = v9 & v3; d1 = v9 & v4; dz = v9 & v5; dw = v9 & v6; dl = v9 & v7; dh = v9 & v8; dd = v9 & v9; cout << "\n+-------------------------+" << "\n| AND (&) | X | 0 | 1 | Z |" << "\n+-------------------------+" << "\n| X | " << xx << " | " << x0 << " | " << x1 << " | " << xz << " | " << "\n+-------------------------+" << "\n| 0 | " << _0x << " | " << _00 << " | " << _01 << " | " << _0z << " | " << "\n+-------------------------+" << "\n| 1 | " << _1x << " | " << _10 << " | " << _11 << " | " << _1z << " | " << "\n+-------------------------+" << "\n| Z | " << zx << " | " << z0 << " | " << z1 << " | " << zz << " | " << "\n+-------------------------+" << endl; uu = v1 | v1; ux = v1 | v2; u0 = v1 | v3; u1 = v1 | v4; uz = v1 | v5; uw = v1 | v6; ul = v1 | v7; uh = v1 | v8; ud = v1 | v9; xu = v2 | v1; xx = v2 | v2; x0 = v2 | v3; x1 = v2 | v4; xz = v2 | v5; xw = v2 | v6; xl = v2 | v7; xh = v2 | v8; xd = v2 | v9; _0u = v3 | v1; _0x = v3 | v2; _00 = v3 | v3; _01 = v3 | v4; _0z = v3 | v5; _0w = v3 | v6; _0l = v3 | v7; _0h = v3 | v8; _0d = v3 | v9; _1u = v4 | v1; _1x = v4 | v2; _10 = v4 | v3; _11 = v4 | v4; _1z = v4 | v5; _1w = v4 | v6; _1l = v4 | v7; _1h = v4 | v8; _1d = v4 | v9; zu = v5 | v1; zx = v5 | v2; z0 = v5 | v3; z1 = v5 | v4; zz = v5 | v5; zw = v5 | v6; zl = v5 | v7; zh = v5 | v8; zd = v5 | v9; wu = v6 | v1; wx = v6 | v2; w0 = v6 | v3; w1 = v6 | v4; wz = v6 | v5; ww = v6 | v6; wl = v6 | v7; wh = v6 | v8; wd = v6 | v9; lu = v7 | v1; lx = v7 | v2; l0 = v7 | v3; l1 = v7 | v4; lz = v7 | v5; lw = v7 | v6; ll = v7 | v7; lh = v7 | v8; ld = v7 | v9; hu = v8 | v1; hx = v8 | v2; h0 = v8 | v3; h1 = v8 | v4; hz = v8 | v5; hw = v8 | v6; hl = v8 | v7; hh = v8 | v8; hd = v8 | v9; du = v9 | v1; dx = v9 | v2; d0 = v9 | v3; d1 = v9 | v4; dz = v9 | v5; dw = v9 | v6; dl = v9 | v7; dh = v9 | v8; dd = v9 | v9; cout << "\n+-------------------------+" << "\n| OR (|) | X | 0 | 1 | Z |" << "\n+-------------------------+" << "\n| X | " << xx << " | " << x0 << " | " << x1 << " | " << xz << " | " << "\n+-------------------------+" << "\n| 0 | " << _0x << " | " << _00 << " | " << _01 << " | " << _0z << " | " << "\n+-------------------------+" << "\n| 1 | " << _1x << " | " << _10 << " | " << _11 << " | " << _1z << " | " << "\n+-------------------------+" << "\n| Z | " << zx << " | " << z0 << " | " << z1 << " | " << zz << " | " << "\n+-------------------------+" << endl; uu = v1 ^ v1; ux = v1 ^ v2; u0 = v1 ^ v3; u1 = v1 ^ v4; uz = v1 ^ v5; uw = v1 ^ v6; ul = v1 ^ v7; uh = v1 ^ v8; ud = v1 ^ v9; xu = v2 ^ v1; xx = v2 ^ v2; x0 = v2 ^ v3; x1 = v2 ^ v4; xz = v2 ^ v5; xw = v2 ^ v6; xl = v2 ^ v7; xh = v2 ^ v8; xd = v2 ^ v9; _0u = v3 ^ v1; _0x = v3 ^ v2; _00 = v3 ^ v3; _01 = v3 ^ v4; _0z = v3 ^ v5; _0w = v3 ^ v6; _0l = v3 ^ v7; _0h = v3 ^ v8; _0d = v3 ^ v9; _1u = v4 ^ v1; _1x = v4 ^ v2; _10 = v4 ^ v3; _11 = v4 ^ v4; _1z = v4 ^ v5; _1w = v4 ^ v6; _1l = v4 ^ v7; _1h = v4 ^ v8; _1d = v4 ^ v9; zu = v5 ^ v1; zx = v5 ^ v2; z0 = v5 ^ v3; z1 = v5 ^ v4; zz = v5 ^ v5; zw = v5 ^ v6; zl = v5 ^ v7; zh = v5 ^ v8; zd = v5 ^ v9; wu = v6 ^ v1; wx = v6 ^ v2; w0 = v6 ^ v3; w1 = v6 ^ v4; wz = v6 ^ v5; ww = v6 ^ v6; wl = v6 ^ v7; wh = v6 ^ v8; wd = v6 ^ v9; lu = v7 ^ v1; lx = v7 ^ v2; l0 = v7 ^ v3; l1 = v7 ^ v4; lz = v7 ^ v5; lw = v7 ^ v6; ll = v7 ^ v7; lh = v7 ^ v8; ld = v7 ^ v9; hu = v8 ^ v1; hx = v8 ^ v2; h0 = v8 ^ v3; h1 = v8 ^ v4; hz = v8 ^ v5; hw = v8 ^ v6; hl = v8 ^ v7; hh = v8 ^ v8; hd = v8 ^ v9; du = v9 ^ v1; dx = v9 ^ v2; d0 = v9 ^ v3; d1 = v9 ^ v4; dz = v9 ^ v5; dw = v9 ^ v6; dl = v9 ^ v7; dh = v9 ^ v8; dd = v9 ^ v9; cout << "\n+-------------------------+" << "\n| XOR (^) | X | 0 | 1 | Z |" << "\n+-------------------------+" << "\n| X | " << xx << " | " << x0 << " | " << x1 << " | " << xz << " | " << "\n+-------------------------+" << "\n| 0 | " << _0x << " | " << _00 << " | " << _01 << " | " << _0z << " | " << "\n+-------------------------+" << "\n| 1 | " << _1x << " | " << _10 << " | " << _11 << " | " << _1z << " | " << "\n+-------------------------+" << "\n| Z | " << zx << " | " << z0 << " | " << z1 << " | " << zz << " | " << "\n+-------------------------+" << endl; std_ulogic nu, nx, n0, n1, nz, nw, nl, nh, nd; nu = ~v1; nx = ~v2; n0 = ~v3; n1 = ~v4; nz = ~v5; nw = ~v6; nl = ~v7; nh = ~v8; nd = ~v9; cout << "\n+-------------------------+" << "\n| NOT (~) | X | 0 | 1 | Z |" << "\n+-------------------------+" << "\n| | " << nx << " | " << n0 << " | " << n1 << " | " << nz << " | " << "\n+-------------------------+" << endl; return 0; }