#line 6156 "smat.w" // -*- c++ -*- #ifndef _SMAT_H_ #define _SMAT_H_ // forward declarations. template class smat_p; template class smat_v; template class smat_d; #line 7125 "smat.w" template class smat_singleton { smat_singleton(); static T* p; public: static T& ref() { static T obj; if (!p) p = &obj; return *p; } }; template T* smat_singleton::p; #line 6165 "smat.w" #line 6208 "smat.w" #define SMAT_A(ADDR) reinterpret_cast(&(ADDR)) //#define SMAT_A(ADDR) reinterpret_cast(boost::addressof(ADDR)) #define SMAT_W(C, ID, L, S1, S2, D) \ smat_inst::write_binary(C, smat_inst::id2type(ID), L, S1, S2, D, \ (smat_singleton::ref().fout())) #define SMAT_LOG1(C, ID, S1) do { \ SMAT_W((C), (ID), sizeof(S1), SMAT_A(S1), 0U, 0U); } while (0) #define SMAT_LOG2(C, ID, S1, D) do { \ SMAT_W((C), (ID), sizeof(S1), SMAT_A(S1), 0U, SMAT_A(D)); } while (0) #define SMAT_LOG2B(C, ID, S1, S2) do { \ SMAT_W((C), (ID), sizeof(S1), SMAT_A(S1), SMAT_A(S2), 0U); } while (0) #define SMAT_LOG3(C, ID, S1, S2, D) do { \ SMAT_W((C), (ID), sizeof(S1), SMAT_A(S1), SMAT_A(S2), SMAT_A(D)); } while (0) #define SMAT_MARK(M) do { SMAT_W(SMAT_FMARK, 0, 0, (M), 0, 0); } while (0) #define SMAT_SET_OSTREAM(OS) \ do { smat_singleton::ref().set_fout(OS); } while (0) #define SMAT_SET_ISTREAM(IS) \ do { smat_singleton::ref().set_fin(IS); } while (0) #line 6166 "smat.w" #include #include // sprintf #include // EXIT_FAILURE #include #include #include #include // for std::iterator_traits #include // htonl, ntohl #line 7149 "smat.w" enum smat_code { SMAT_NOP, SMAT_MOV, SMAT_CMPL, SMAT_AND, SMAT_OR, SMAT_XOR, SMAT_ADD, SMAT_SUB, SMAT_MUL, SMAT_DIV, SMAT_MOD, SMAT_LSHIFT, SMAT_RSHIFT, SMAT_INC, SMAT_DEC, SMAT_MINUS, SMAT_EQ, SMAT_NEQ, SMAT_GT, SMAT_GEQ, SMAT_LT, SMAT_LEQ, SMAT_IAND, SMAT_IOR, SMAT_IXOR, SMAT_IADD, SMAT_ISUB, SMAT_IMUL, SMAT_IDIV, SMAT_IMOD, SMAT_ILSHIFT, SMAT_IRSHIFT, SMAT_IEQ, SMAT_INEQ, SMAT_IGT, SMAT_IGEQ, SMAT_ILT, SMAT_ILEQ, SMAT_READ, SMAT_WRITE, SMAT_DTOR, SMAT_FMARK, SMAT_CTOR, SMAT_CCTOR, SMAT_BCTOR, SMAT_END }; #line 6177 "smat.w" #line 7163 "smat.w" struct smat_inst { typedef unsigned long addr_t; int code, type; size_t len; addr_t src1, src2, dst; smat_inst(int c = SMAT_NOP, int t = 0, size_t l = 0, addr_t s1 = 0, addr_t s2 = 0, addr_t d = 0) : code(c), type(t), len(l), src1(s1), src2(s2), dst(d) {} smat_inst& operator=(const smat_inst& x) { code = x.code; type = x.type; len = x.len; src1 = x.src1; src2 = x.src2; dst = x.dst; return *this; } static std::istream& read_binary(int& c, int &t, size_t& l, addr_t& s1, addr_t& s2, addr_t& d, std::istream& is = std::cin); static std::istream& read_readable(int& c, int &t, size_t& l, addr_t& s1, addr_t& s2, addr_t& d, std::istream& is = std::cin); static std::ostream& write_readable(int c, int t, size_t l, addr_t s1, addr_t s2, addr_t d, std::ostream& os = std::cout); static std::ostream& write_binary(int c, int t, int l, addr_t s1, addr_t s2, addr_t d, std::ostream& os = std::cout); std::ostream& write_readable(std::ostream& os = std::cout) const { return write_readable(code, type, len, src1, src2, dst, os); } std::istream& read_readable(std::istream& is = std::cin) { return read_readable(code, type, len, src1, src2, dst, is); } std::ostream& write(std::ostream& os = std::cout) const { return write_binary(code, type, len, src1, src2, dst, os); } std::istream& read(std::istream& is = std::cin) { return read_binary(code, type, len, src1, src2, dst, is); } static const char* name(int c); static int str2code(const std::string& s); static inline int id2type(char id); }; #line 7218 "smat.w" inline std::istream& smat_inst::read_binary(int& c, int &t, size_t& l, addr_t& s1, addr_t& s2, addr_t& d, std::istream& is) { addr_t v[4], v0; is.read(reinterpret_cast(v), sizeof(v)); v0 = ntohl(v[0]); c = ((v0 >> 24) & 0x3f); t = (v0 >> 30); l = v0 & 0xff; s1 = ntohl(v[1]); s2 = ntohl(v[2]); d = ntohl(v[3]); return is; } inline std::ostream& smat_inst::write_binary(int c, int t, int l, addr_t s1, addr_t s2, addr_t d, std::ostream& os) { addr_t v[4]; v[0] = htonl((t << 30) | (c << 24) | (l & 0xff)); v[1] = htonl(s1); v[2] = htonl(s2); v[3] = htonl(d); return os.write(reinterpret_cast(v), sizeof(v)); } #line 7207 "smat.w" #line 7244 "smat.w" inline std::ostream& smat_inst::write_readable(int c, int t, size_t l, addr_t s1, addr_t s2, addr_t d, std::ostream& os) { char buf[80]; const char *opname = name(c); char id[] = { 'i', 'v', 'd', 'p' }; switch (c) { case SMAT_MOV: case SMAT_CMPL: case SMAT_MINUS: case SMAT_IAND: case SMAT_IOR: case SMAT_IXOR: case SMAT_IADD: case SMAT_ISUB: case SMAT_IMUL: case SMAT_IDIV: case SMAT_IMOD: case SMAT_ILSHIFT: case SMAT_IRSHIFT: case SMAT_CCTOR: case SMAT_BCTOR: sprintf(buf, "\t%s%c\t%d, (0x%08lx), (0x%08lx)\n", opname, id[t], l, s1, d); os << buf; break; case SMAT_INC: case SMAT_DEC: case SMAT_READ: case SMAT_WRITE: case SMAT_DTOR: case SMAT_IEQ: case SMAT_INEQ: case SMAT_IGT: case SMAT_IGEQ: case SMAT_ILT: case SMAT_ILEQ: case SMAT_CTOR: sprintf(buf, "\t%s%c\t%d, (0x%08lx)\n", opname, id[t], l, s1); os << buf; break; case SMAT_AND: case SMAT_OR: case SMAT_XOR: case SMAT_ADD: case SMAT_SUB: case SMAT_MUL: case SMAT_DIV: case SMAT_MOD: case SMAT_LSHIFT: case SMAT_RSHIFT: sprintf(buf, "\t%s%c\t%d, (0x%08lx), (0x%08lx), (0x%08lx)\n", opname, id[t], l, s1, s2, d); os << buf; break; case SMAT_EQ: case SMAT_NEQ: case SMAT_GT: case SMAT_GEQ: case SMAT_LT: case SMAT_LEQ: sprintf(buf, "\t%s%c\t%d, (0x%08lx), (0x%08lx)\n", opname, id[t], l, s1, s2); os << buf; break; case SMAT_FMARK: os << '\t' << opname << '\t' << s1 << '\n'; break; case SMAT_NOP: os << '\t' << opname << '\n'; break; default: os << '\t' << opname << " (code = " << c << ")" << '\n'; break; } return os; } inline std::istream& smat_inst::read_readable(int& c, int &t, size_t& l, addr_t& s1, addr_t& s2, addr_t& d, std::istream& is) { std::string mnemonic; char comma, paren_open, paren_close; is >> mnemonic; t = id2type(mnemonic[mnemonic.size() - 1]); mnemonic.erase(mnemonic.size() - 1, 1); c = str2code(mnemonic); l = s1 = s2 = d = 0; switch (c) { case SMAT_MOV: case SMAT_CMPL: case SMAT_MINUS: case SMAT_IAND: case SMAT_IOR: case SMAT_IXOR: case SMAT_IADD: case SMAT_ISUB: case SMAT_IMUL: case SMAT_IDIV: case SMAT_IMOD: case SMAT_ILSHIFT: case SMAT_IRSHIFT: case SMAT_CCTOR: case SMAT_BCTOR: is >> std::dec >> l >> std::hex; is >> comma >> paren_open >> s1 >> paren_close; is >> comma >> paren_open >> d >> paren_close; break; case SMAT_INC: case SMAT_DEC: case SMAT_READ: case SMAT_WRITE: case SMAT_DTOR: case SMAT_IEQ: case SMAT_INEQ: case SMAT_IGT: case SMAT_IGEQ: case SMAT_ILT: case SMAT_ILEQ: case SMAT_CTOR: is >> std::dec >> l >> std::hex; is >> comma >> paren_open >> s1 >> paren_close; break; case SMAT_AND: case SMAT_OR: case SMAT_XOR: case SMAT_ADD: case SMAT_SUB: case SMAT_MUL: case SMAT_DIV: case SMAT_MOD: case SMAT_LSHIFT: case SMAT_RSHIFT: is >> std::dec >> l >> std::hex; is >> comma >> paren_open >> s1 >> paren_close; is >> comma >> paren_open >> s2 >> paren_close; is >> comma >> paren_open >> d >> paren_close; break; case SMAT_EQ: case SMAT_NEQ: case SMAT_GT: case SMAT_GEQ: case SMAT_LT: case SMAT_LEQ: is >> std::dec >> l >> std::hex; is >> comma >> paren_open >> s1 >> paren_close; is >> comma >> paren_open >> s2 >> paren_close; break; case SMAT_FMARK: is >> std::dec >> s1; break; default: break; } return is; } #line 7208 "smat.w" #line 7354 "smat.w" inline std::istream& operator>>(std::istream& is, smat_inst& s) { return smat_inst::read_binary(s.code, s.type, s.len, s.src1, s.src2, s.dst, is); } inline std::ostream& operator<<(std::ostream& os, const smat_inst& s) { return s.write_binary(s.code, s.type, s.len, s.src1, s.src2, s.dst, os); } #line 7209 "smat.w" #line 7370 "smat.w" inline const char* smat_inst::name(int c) { static char* const opname[] = { "nop", "mov", "cmpl", "and", "or", "xor", "add", "sub", "mul", "div", "mod", "sl", "sr", "inc", "dec", "minus", "eq", "neq", "gt", "geq", "lt", "leq", "iand", "ior", "ixor", "iadd", "isub", "imul", "idiv", "imod", "isl", "isr", "ieq", "ineq", "igt", "igeq", "ilt", "ileq", "read", "write", "dtor", "mark", "ctor", "cctor", "bctor" }; if (SMAT_NOP <= c && c < SMAT_END) return opname[c]; return "???"; } inline int smat_inst::str2code(const std::string& s) { static char* const opname[] = { "nop", "mov", "cmpl", "and", "or", "xor", "add", "sub", "mul", "div", "mod", "sl", "sr", "inc", "dec", "minus", "eq", "neq", "gt", "geq", "lt", "leq", "iand", "ior", "ixor", "iadd", "isub", "imul", "idiv", "imod", "isl", "isr", "ieq", "ineq", "igt", "igeq", "ilt", "ileq", "read", "write", "dtor", "mark", "ctor", "cctor", "bctor", 0 }; for (int i = SMAT_NOP; i < SMAT_END; ++i) { if (s.compare(opname[i]) == 0) return i; } return SMAT_END; } inline int smat_inst::id2type(char id) { static int tbl[] = { 3, 3, 3, 2, 3, 3, 3, 3, 0, 3, 3, 3, 3, // 'a' - 'm' 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 3 // 'n' - 'z' }; return tbl[id - 'a']; } #line 7210 "smat.w" #line 6178 "smat.w" #line 7104 "smat.w" class smat_io { std::ostream* fout_; std::istream* fin_; public: smat_io(std::ostream& os = std::cout, std::istream& is = std::cin) : fout_(&os), fin_(&is) { } std::ostream& fout() { return *fout_; } std::istream& fin() { return *fin_; } void set_fout(std::ostream& os) { fout_ = &os; } void set_fin(std::istream& is) { fin_ = &is; } }; #line 6180 "smat.w" #line 6264 "smat.w" template class smat { T base_; typedef typename std::iterator_traits::difference_type raw_difference_type; typedef typename std::iterator_traits::value_type raw_value_type; typedef typename std::iterator_traits::pointer raw_pointer; public: typedef smat_v value_type; typedef smat_d difference_type; typedef smat_p pointer; typedef value_type& reference; typedef typename std::iterator_traits::iterator_category iterator_category; #line 6488 "smat.w" BOOST_STATIC_ASSERT(sizeof(value_type) == sizeof(raw_value_type)); BOOST_STATIC_ASSERT(sizeof(value_type) < 256); #line 6278 "smat.w" #line 7069 "smat.w" #ifdef SMAT_DISABLE typedef T type; #else typedef smat type; #endif #line 6280 "smat.w" smat(); smat(const smat& x); smat(const T& x); smat(const T& x, int); ~smat(); //explicit smat(value_type* x); operator T() const { SMAT_LOG1(SMAT_READ, 'i', base_); return base_; } const T& base() const { return base_; } smat& operator=(const smat& x); //bool operator!() const; T operator->() const; reference operator*() const; reference operator[](const difference_type& x) const; template reference operator[](const U& x) const; smat& operator++(); smat operator++(int); smat& operator--(); smat operator--(int); smat& operator+=(const difference_type& x); smat& operator-=(const difference_type& x); template smat& operator+=(const U& x); template smat& operator-=(const U& x); }; #line 6182 "smat.w" #line 6312 "smat.w" template class smat_p { T base_; typedef typename std::iterator_traits::difference_type raw_difference_type; typedef typename std::iterator_traits::value_type raw_value_type; typedef typename std::iterator_traits::pointer raw_pointer; public: typedef smat_v value_type; typedef smat_d difference_type; typedef smat_p pointer; typedef value_type& reference; typedef std::random_access_iterator_tag iterator_category; #line 7076 "smat.w" #ifdef SMAT_DISABLE typedef T type; #else typedef smat_p type; #endif #line 6327 "smat.w" smat_p(); smat_p(const smat_p& x); smat_p(const T& x); smat_p(const T& x, int); ~smat_p(); operator T() const { SMAT_LOG1(SMAT_READ, 'p', base_); return base_; } const T& base() const { return base_; } smat_p& operator=(const smat_p& x); smat_p& operator=(value_type* x); //bool operator!() const; T operator->() const; reference operator*() const; reference operator[](const difference_type& x) const; template reference operator[](const U& x) const; smat_p& operator++(); smat_p operator++(int); smat_p& operator--(); smat_p operator--(int); smat_p& operator+=(const difference_type& x); smat_p& operator-=(const difference_type& x); template smat_p& operator+=(const U& x); template smat_p& operator-=(const U& x); }; #line 6183 "smat.w" #line 6359 "smat.w" template class smat_v { T base_; public: smat_v(); smat_v(const smat_v& x); smat_v(const T& x); smat_v(const T& x, int); ~smat_v(); #line 7083 "smat.w" #ifdef SMAT_DISABLE typedef T type; #else typedef smat_v type; #endif #line 6370 "smat.w" operator T() const { SMAT_LOG1(SMAT_READ, 'v', base_); return base_; } const T& base() const { return base_; } smat_v& operator=(const smat_v& x); smat_v* operator&(); const smat_v* operator&() const; smat_v operator+() const; smat_v operator-() const; smat_v operator~() const; smat_v& operator++(); smat_v operator++(int); smat_v& operator--(); smat_v operator--(int); smat_v& operator+=(const smat_v& x); smat_v& operator-=(const smat_v& x); smat_v& operator*=(const smat_v& x); smat_v& operator/=(const smat_v& x); smat_v& operator%=(const smat_v& x); smat_v& operator<<=(const smat_v& x); smat_v& operator>>=(const smat_v& x); smat_v& operator&=(const smat_v& x); smat_v& operator|=(const smat_v& x); smat_v& operator^=(const smat_v& x); template smat_v& operator+=(const U& x); template smat_v& operator-=(const U& x); template smat_v& operator*=(const U& x); template smat_v& operator/=(const U& x); template smat_v& operator%=(const U& x); template smat_v& operator<<=(const U& x); template smat_v& operator>>=(const U& x); template smat_v& operator&=(const U& x); template smat_v& operator|=(const U& x); template smat_v& operator^=(const U& x); }; #line 6184 "smat.w" #line 6410 "smat.w" template class smat_d { T base_; public: smat_d(); smat_d(const smat_d& x); smat_d(const T& x); smat_d(const T& x, int); ~smat_d(); #line 7090 "smat.w" #ifdef SMAT_DISABLE typedef T type; #else typedef smat_d type; #endif #line 6421 "smat.w" operator T() const { SMAT_LOG1(SMAT_READ, 'd', base_); return base_; } const T& base() const { return base_; } smat_d& operator=(const smat_d& x); smat_d* operator&(); const smat_d* operator&() const; smat_d operator+() const; smat_d operator-() const; smat_d operator~() const; smat_d& operator++(); smat_d operator++(int); smat_d& operator--(); smat_d operator--(int); smat_d& operator+=(const smat_d& x); smat_d& operator-=(const smat_d& x); smat_d& operator*=(const smat_d& x); smat_d& operator/=(const smat_d& x); smat_d& operator%=(const smat_d& x); smat_d& operator<<=(const smat_d& x); smat_d& operator>>=(const smat_d& x); smat_d& operator&=(const smat_d& x); smat_d& operator|=(const smat_d& x); smat_d& operator^=(const smat_d& x); template smat_d& operator+=(const U& x); template smat_d& operator-=(const U& x); template smat_d& operator*=(const U& x); template smat_d& operator/=(const U& x); template smat_d& operator%=(const U& x); template smat_d& operator<<=(const U& x); template smat_d& operator>>=(const U& x); template smat_d& operator&=(const U& x); template smat_d& operator|=(const U& x); template smat_d& operator^=(const U& x); }; #line 6185 "smat.w" #line 6461 "smat.w" #line 6555 "smat.w" #define SMAT_MDEF_INCDEC(CLASS, ID) \ template \ inline CLASS& CLASS::operator++() { \ SMAT_LOG1(SMAT_INC, ID, base_); ++base_; return *this; \ } \ template \ inline CLASS CLASS::operator++(int) { \ SMAT_LOG1(SMAT_INC, ID, base_); \ CLASS x(*this); ++base_; return x; \ } \ template \ inline CLASS& CLASS::operator--() { \ SMAT_LOG1(SMAT_DEC, ID, base_); --base_; return *this; \ } \ template \ inline CLASS CLASS::operator--(int) { \ SMAT_LOG1(SMAT_DEC, ID, base_); \ CLASS x(*this); --base_; return x; \ } SMAT_MDEF_INCDEC(smat, 'i') SMAT_MDEF_INCDEC(smat_p, 'p') SMAT_MDEF_INCDEC(smat_v, 'v') SMAT_MDEF_INCDEC(smat_d, 'd') #undef SMAT_MDEF_INCDEC #line 6461 "smat.w" #line 6494 "smat.w" #define SMAT_MDEF_CTORDTOR(CLASS, ID) \ template \ inline CLASS::CLASS() : base_() { \ SMAT_LOG1(SMAT_CTOR, ID, base_); \ } \ template \ inline CLASS::CLASS(const CLASS& x) : base_(x.base_) { \ SMAT_LOG2(SMAT_CCTOR, ID, x.base_, base_); \ } \ template \ inline CLASS::CLASS(const T& x) : base_(x) { \ SMAT_LOG2(SMAT_BCTOR, ID, x, base_); \ } \ template \ inline CLASS::CLASS(const T& x, int) : base_(x) { \ SMAT_LOG1(SMAT_CTOR, ID, base_); \ } \ template \ inline CLASS::~CLASS() { \ SMAT_LOG1(SMAT_DTOR, ID, base_); \ } SMAT_MDEF_CTORDTOR(smat, 'i') SMAT_MDEF_CTORDTOR(smat_p, 'p') SMAT_MDEF_CTORDTOR(smat_v, 'v') SMAT_MDEF_CTORDTOR(smat_d, 'd') #undef SMAT_MDEF_CTORDTOR #line 6462 "smat.w" #line 6585 "smat.w" #define SMAT_MDEF_ASSIGNOP(CLASS, ID, OP, TCODE) \ template \ inline CLASS& \ CLASS::operator OP(const CLASS& x) { \ SMAT_LOG3(TCODE, ID, base_, x.base(), base_); \ base_ OP x.base(); return *this; \ } SMAT_MDEF_ASSIGNOP(smat_v, 'v', +=, SMAT_ADD) SMAT_MDEF_ASSIGNOP(smat_v, 'v', -=, SMAT_SUB) SMAT_MDEF_ASSIGNOP(smat_v, 'v', *=, SMAT_MUL) SMAT_MDEF_ASSIGNOP(smat_v, 'v', /=, SMAT_DIV) SMAT_MDEF_ASSIGNOP(smat_v, 'v', %=, SMAT_MOD) SMAT_MDEF_ASSIGNOP(smat_v, 'v', <<=, SMAT_LSHIFT) SMAT_MDEF_ASSIGNOP(smat_v, 'v', >>=, SMAT_RSHIFT) SMAT_MDEF_ASSIGNOP(smat_v, 'v', &=, SMAT_AND) SMAT_MDEF_ASSIGNOP(smat_v, 'v', |=, SMAT_OR) SMAT_MDEF_ASSIGNOP(smat_v, 'v', ^=, SMAT_XOR) SMAT_MDEF_ASSIGNOP(smat_d, 'd', +=, SMAT_ADD) SMAT_MDEF_ASSIGNOP(smat_d, 'd', -=, SMAT_SUB) SMAT_MDEF_ASSIGNOP(smat_d, 'd', *=, SMAT_MUL) SMAT_MDEF_ASSIGNOP(smat_d, 'd', /=, SMAT_DIV) SMAT_MDEF_ASSIGNOP(smat_d, 'd', %=, SMAT_MOD) SMAT_MDEF_ASSIGNOP(smat_d, 'd', <<=, SMAT_LSHIFT) SMAT_MDEF_ASSIGNOP(smat_d, 'd', >>=, SMAT_RSHIFT) SMAT_MDEF_ASSIGNOP(smat_d, 'd', &=, SMAT_AND) SMAT_MDEF_ASSIGNOP(smat_d, 'd', |=, SMAT_OR) SMAT_MDEF_ASSIGNOP(smat_d, 'd', ^=, SMAT_XOR) #undef SMAT_MDEF_ASSIGNOP template inline smat& smat::operator+=(const smat_d::difference_type>& x) { SMAT_LOG3(SMAT_ADD, 'i', base_, x.base(), base_); base_ += x.base(); return *this; } template inline smat& smat::operator-=(const smat_d::difference_type>& x) { SMAT_LOG3(SMAT_SUB, 'i', base_, x.base(), base_); base_ -= x.base(); return *this; } template inline smat_p& smat_p::operator+=(const smat_d::difference_type>& x) { SMAT_LOG3(SMAT_ADD, 'p', base_, x.base(), base_); base_ += x.base(); return *this; } template inline smat_p& smat_p::operator-=(const smat_d::difference_type>& x) { SMAT_LOG3(SMAT_SUB, 'p', base_, x.base(), base_); base_ -= x.base(); return *this; } #line 6463 "smat.w" #line 6659 "smat.w" #define SMAT_MDEF_ASSIGNOP_IMMEDIATE(CLASS, ID, OP, TCODE) \ template \ template \ inline CLASS& \ CLASS::operator OP(const U& x) { \ SMAT_LOG2(TCODE, ID, base_, base_); \ base_ OP x; return *this; \ } SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat, 'i', +=, SMAT_IADD) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat, 'i', -=, SMAT_ISUB) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_p, 'p', +=, SMAT_IADD) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_p, 'p', -=, SMAT_ISUB) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_v, 'v', +=, SMAT_IADD) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_v, 'v', -=, SMAT_ISUB) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_v, 'v', *=, SMAT_IMUL) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_v, 'v', /=, SMAT_IDIV) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_v, 'v', %=, SMAT_IMOD) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_v, 'v', <<=, SMAT_ILSHIFT) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_v, 'v', >>=, SMAT_IRSHIFT) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_v, 'v', &=, SMAT_IAND) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_v, 'v', |=, SMAT_IOR) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_v, 'v', ^=, SMAT_IXOR) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_d, 'd', +=, SMAT_IADD) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_d, 'd', -=, SMAT_ISUB) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_d, 'd', *=, SMAT_IMUL) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_d, 'd', /=, SMAT_IDIV) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_d, 'd', %=, SMAT_IMOD) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_d, 'd', <<=, SMAT_ILSHIFT) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_d, 'd', >>=, SMAT_IRSHIFT) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_d, 'd', &=, SMAT_IAND) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_d, 'd', |=, SMAT_IOR) SMAT_MDEF_ASSIGNOP_IMMEDIATE(smat_d, 'd', ^=, SMAT_IXOR) #undef SMAT_MDEF_ASSIGNOP_IMMEDIATE #line 6464 "smat.w" #line 6749 "smat.w" template inline T smat::operator->() const { SMAT_LOG1(SMAT_READ, 'i', base_); return base_; } template inline T smat_p::operator->() const { SMAT_LOG1(SMAT_READ, 'p', base_); return base_; } #line 6465 "smat.w" #line 6524 "smat.w" template inline smat& smat::operator=(const smat& x) { SMAT_LOG2(SMAT_MOV, 'i', x.base_, base_); base_ = x.base_; return *this; } template inline smat_p& smat_p::operator=(const smat_p& x) { SMAT_LOG2(SMAT_MOV, 'p', x.base_, base_); base_ = x.base_; return *this; } template inline smat_p& smat_p::operator=( smat_v::value_type>* x) { SMAT_LOG2(SMAT_MOV, 'p', x, base_); base_ = reinterpret_cast(x); return *this; } template inline smat_v& smat_v::operator=(const smat_v& x) { SMAT_LOG2(SMAT_MOV, 'v', x.base_, base_); base_ = x.base_; return *this; } template inline smat_d& smat_d::operator=(const smat_d& x) { SMAT_LOG2(SMAT_MOV, 'd', x.base_, base_); base_ = x.base_; return *this; } #line 6466 "smat.w" #line 6760 "smat.w" template inline smat_v::value_type>& smat::operator*() const { SMAT_LOG1(SMAT_READ, 'i', base_); return reinterpret_cast::value_type>&>(*base_); } template inline smat_v::value_type>& smat::operator[](const smat_d::difference_type>& x) const { return *(*this + x); } template template inline smat_v::value_type>& smat::operator[](const U& x) const { return *(*this + x); } template inline smat_v::value_type>& smat_p::operator*() const { SMAT_LOG1(SMAT_READ, 'p', base_); return reinterpret_cast::value_type>&>(*base_); } template inline smat_v::value_type>& smat_p::operator[](const smat_d::difference_type>& x) const { return *(*this + x); } template template inline smat_v::value_type>& smat_p::operator[](const U& x) const { return *(*this + x); } #line 6467 "smat.w" #line 6700 "smat.w" template smat_v smat_v::operator+() const { smat_v _tmp(base_, 0); SMAT_LOG1(SMAT_READ, 'v', base_); return _tmp; } template smat_v smat_v::operator-() const { smat_v _tmp(-base_, 0); SMAT_LOG2(SMAT_MINUS, 'v', base_, _tmp); return _tmp; } template smat_v smat_v::operator~() const { smat_v _tmp(~base_, 0); SMAT_LOG2(SMAT_CMPL, 'v', base_, _tmp); return _tmp; } template smat_v* smat_v::operator&() { return reinterpret_cast*>(&base_); } template const smat_v* smat_v::operator&() const { return reinterpret_cast*>(&base_); } template smat_d smat_d::operator+() const { smat_d _tmp(base_, 0); SMAT_LOG1(SMAT_READ, 'd', base_); return _tmp; } template smat_d smat_d::operator-() const { smat_d _tmp(-base_, 0); SMAT_LOG2(SMAT_MINUS, 'd', base_, _tmp); return _tmp; } template smat_d smat_d::operator~() const { smat_d _tmp(~base_, 0); SMAT_LOG2(SMAT_CMPL, 'd', base_, _tmp); return _tmp; } template smat_d* smat_d::operator&() { return reinterpret_cast*>(&base_); } template const smat_d* smat_d::operator&() const { return reinterpret_cast*>(&base_); } #line 6468 "smat.w" #line 6187 "smat.w" #line 6471 "smat.w" #line 6807 "smat.w" #define SMAT_GDEF_BINARYOP(CLASS, ID, OP, TCODE) \ template \ inline const CLASS \ operator OP(const CLASS& lhs, const CLASS& rhs) { \ CLASS _tmp(lhs.base() OP rhs.base(), 0); \ SMAT_LOG3(TCODE, ID, lhs.base(), rhs.base(),_tmp); return _tmp; \ } SMAT_GDEF_BINARYOP(smat_v, 'v', +, SMAT_IADD) SMAT_GDEF_BINARYOP(smat_v, 'v', -, SMAT_ISUB) SMAT_GDEF_BINARYOP(smat_v, 'v', *, SMAT_IMUL) SMAT_GDEF_BINARYOP(smat_v, 'v', /, SMAT_IDIV) SMAT_GDEF_BINARYOP(smat_v, 'v', %, SMAT_IMOD) SMAT_GDEF_BINARYOP(smat_v, 'v', <<, SMAT_ILSHIFT) SMAT_GDEF_BINARYOP(smat_v, 'v', >>, SMAT_IRSHIFT) SMAT_GDEF_BINARYOP(smat_v, 'v', &, SMAT_IAND) SMAT_GDEF_BINARYOP(smat_v, 'v', |, SMAT_IOR) SMAT_GDEF_BINARYOP(smat_v, 'v', ^, SMAT_IXOR) SMAT_GDEF_BINARYOP(smat_d, 'd', +, SMAT_IADD) SMAT_GDEF_BINARYOP(smat_d, 'd', -, SMAT_ISUB) SMAT_GDEF_BINARYOP(smat_d, 'd', *, SMAT_IMUL) SMAT_GDEF_BINARYOP(smat_d, 'd', /, SMAT_IDIV) SMAT_GDEF_BINARYOP(smat_d, 'd', %, SMAT_IMOD) SMAT_GDEF_BINARYOP(smat_d, 'd', <<, SMAT_ILSHIFT) SMAT_GDEF_BINARYOP(smat_d, 'd', >>, SMAT_IRSHIFT) SMAT_GDEF_BINARYOP(smat_d, 'd', &, SMAT_IAND) SMAT_GDEF_BINARYOP(smat_d, 'd', |, SMAT_IOR) SMAT_GDEF_BINARYOP(smat_d, 'd', ^, SMAT_IXOR) #undef SMAT_GDEF_BINARYOP template const smat operator+(const smat& lhs, const smat_d::difference_type>& rhs) { smat _tmp(lhs.base() + rhs.base(), 0); SMAT_LOG3(SMAT_ADD, 'i', lhs.base(), rhs.base(), _tmp); return _tmp; } template const smat operator+(const smat_d::difference_type>& lhs, const smat& rhs) { smat _tmp(lhs.base() + rhs.base(), 0); SMAT_LOG3(SMAT_ADD, 'i', lhs.base(), rhs.base(), _tmp); return _tmp; } template const smat operator-(const smat& lhs, const smat_d::difference_type>& rhs) { smat _tmp(lhs.base() - rhs.base(), 0); SMAT_LOG3(SMAT_SUB, 'i', lhs.base(), rhs.base(), _tmp); return _tmp; } template const smat_d::difference_type> operator-(const smat& lhs, const smat& rhs) { smat_d::difference_type> _tmp(lhs.base() - rhs.base(), 0); SMAT_LOG3(SMAT_SUB, 'i', lhs.base(), rhs.base(), _tmp); return _tmp; } template const smat_p operator+(const smat_p& lhs, const smat_d::difference_type>& rhs) { smat_p _tmp(lhs.base() + rhs.base(), 0); SMAT_LOG3(SMAT_ADD, 'p', lhs.base(), rhs.base(), _tmp); return _tmp; } template const smat_p operator+(const smat_d::difference_type>& lhs, const smat_p& rhs) { smat_p _tmp(lhs.base() + rhs.base(), 0); SMAT_LOG3(SMAT_ADD, 'p', lhs.base(), rhs.base(), _tmp); return _tmp; } template const smat_p operator-(const smat_p& lhs, const smat_d::difference_type>& rhs) { smat_p _tmp(lhs.base() - rhs.base(), 0); SMAT_LOG3(SMAT_SUB, 'p', lhs.base(), rhs.base(), _tmp); return _tmp; } template const smat_d::difference_type> operator-(const smat_p& lhs, const smat_p& rhs) { smat_d::difference_type> _tmp(lhs.base() - rhs.base(), 0); SMAT_LOG3(SMAT_SUB, 'p', lhs.base(), rhs.base(), _tmp); return _tmp; } #line 6471 "smat.w" #line 6906 "smat.w" #define SMAT_GDEF_BINARYOP_IMMEDIATE(CLASS, ID, OP, TCODE) \ template \ inline const CLASS \ operator OP(const CLASS& lhs, const U& rhs) { \ CLASS _tmp(lhs.base() OP rhs, 0); \ SMAT_LOG2(TCODE, ID, lhs.base(), _tmp); return _tmp; \ } \ template \ inline const CLASS \ operator OP(const U& lhs, const CLASS& rhs) { \ CLASS _tmp(lhs OP rhs.base(), 0); \ SMAT_LOG2(TCODE, ID, rhs.base(), _tmp); return _tmp; \ } SMAT_GDEF_BINARYOP_IMMEDIATE(smat, 'i', +, SMAT_IADD) SMAT_GDEF_BINARYOP_IMMEDIATE(smat, 'i', -, SMAT_ISUB) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_p, 'p', +, SMAT_IADD) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_p, 'p', -, SMAT_ISUB) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_v, 'v', +, SMAT_IADD) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_v, 'v', -, SMAT_ISUB) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_v, 'v', *, SMAT_IMUL) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_v, 'v', /, SMAT_IDIV) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_v, 'v', %, SMAT_IMOD) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_v, 'v', <<, SMAT_ILSHIFT) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_v, 'v', >>, SMAT_IRSHIFT) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_v, 'v', &, SMAT_IAND) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_v, 'v', |, SMAT_IOR) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_v, 'v', ^, SMAT_IXOR) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_d, 'd', +, SMAT_IADD) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_d, 'd', -, SMAT_ISUB) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_d, 'd', *, SMAT_IMUL) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_d, 'd', /, SMAT_IDIV) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_d, 'd', %, SMAT_IMOD) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_d, 'd', <<, SMAT_ILSHIFT) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_d, 'd', >>, SMAT_IRSHIFT) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_d, 'd', &, SMAT_IAND) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_d, 'd', |, SMAT_IOR) SMAT_GDEF_BINARYOP_IMMEDIATE(smat_d, 'd', ^, SMAT_IXOR) #undef SMAT_GDEF_BINARYOP_IMMEDIATE #line 6472 "smat.w" #line 6957 "smat.w" template inline std::ostream& operator<<(std::ostream& os, const smat& x) { return os << x.base(); } template inline std::ostream& operator<<(std::ostream& os, const smat_d& x) { return os << x.base(); } template inline std::ostream& operator<<(std::ostream& os, const smat_v& x) { return os << x.base(); } template inline std::ostream& operator<<(std::ostream& os, const smat_p& x) { return os << x.base(); } template inline std::istream& operator>>(std::istream& os, smat& x) { return is >> x.base(); } template inline std::istream& operator>>(std::istream& os, smat_d& x) { return is >> x.base(); } template inline std::istream& operator>>(std::istream& os, smat_v& x) { return is >> x.base(); } template inline std::istream& operator>>(std::istream& os, smat_p& x) { return is >> x.base(); } #line 6473 "smat.w" #line 6992 "smat.w" #define SMAT_GDEF_CMP(CLASS, ID, OP, TCODE) \ template \ inline bool operator OP(const CLASS& lhs, const CLASS& rhs) { \ SMAT_LOG2B(TCODE, ID, lhs.base(), rhs.base()); \ return lhs.base() OP rhs.base(); \ } SMAT_GDEF_CMP(smat, 'i', ==, SMAT_EQ) SMAT_GDEF_CMP(smat, 'i', !=, SMAT_NEQ) SMAT_GDEF_CMP(smat, 'i', <, SMAT_LT) SMAT_GDEF_CMP(smat, 'i', >, SMAT_GT) SMAT_GDEF_CMP(smat, 'i', <=, SMAT_LEQ) SMAT_GDEF_CMP(smat, 'i', >=, SMAT_GEQ) SMAT_GDEF_CMP(smat_p, 'p', ==, SMAT_EQ) SMAT_GDEF_CMP(smat_p, 'p', !=, SMAT_NEQ) SMAT_GDEF_CMP(smat_p, 'p', <, SMAT_LT) SMAT_GDEF_CMP(smat_p, 'p', >, SMAT_GT) SMAT_GDEF_CMP(smat_p, 'p', <=, SMAT_LEQ) SMAT_GDEF_CMP(smat_p, 'p', >=, SMAT_GEQ) SMAT_GDEF_CMP(smat_v, 'v', ==, SMAT_EQ) SMAT_GDEF_CMP(smat_v, 'v', !=, SMAT_NEQ) SMAT_GDEF_CMP(smat_v, 'v', <, SMAT_LT) SMAT_GDEF_CMP(smat_v, 'v', >, SMAT_GT) SMAT_GDEF_CMP(smat_v, 'v', <=, SMAT_LEQ) SMAT_GDEF_CMP(smat_v, 'v', >=, SMAT_GEQ) SMAT_GDEF_CMP(smat_d, 'd', ==, SMAT_EQ) SMAT_GDEF_CMP(smat_d, 'd', !=, SMAT_NEQ) SMAT_GDEF_CMP(smat_d, 'd', <, SMAT_LT) SMAT_GDEF_CMP(smat_d, 'd', >, SMAT_GT) SMAT_GDEF_CMP(smat_d, 'd', <=, SMAT_LEQ) SMAT_GDEF_CMP(smat_d, 'd', >=, SMAT_GEQ) #undef SMAT_GDEF_CMP #line 6474 "smat.w" #line 7032 "smat.w" #define SMAT_GDEF_CMP_IMMEDIATE(CLASS, ID, OP, TCODE) \ template \ inline bool operator OP(const CLASS& lhs, const U& rhs) { \ SMAT_LOG1(TCODE, ID, lhs.base()); \ return lhs.base() OP rhs; \ } \ template \ inline bool operator OP(const U& lhs, const CLASS& rhs) { \ SMAT_LOG1(TCODE, ID, rhs.base()); \ return lhs OP rhs.base(); \ } SMAT_GDEF_CMP_IMMEDIATE(smat_v, 'v', ==, SMAT_IEQ) SMAT_GDEF_CMP_IMMEDIATE(smat_v, 'v', !=, SMAT_INEQ) SMAT_GDEF_CMP_IMMEDIATE(smat_v, 'v', <, SMAT_ILT) SMAT_GDEF_CMP_IMMEDIATE(smat_v, 'v', >, SMAT_IGT) SMAT_GDEF_CMP_IMMEDIATE(smat_v, 'v', <=, SMAT_ILEQ) SMAT_GDEF_CMP_IMMEDIATE(smat_v, 'v', >=, SMAT_IGEQ) SMAT_GDEF_CMP_IMMEDIATE(smat_d, 'd', ==, SMAT_IEQ) SMAT_GDEF_CMP_IMMEDIATE(smat_d, 'd', !=, SMAT_INEQ) SMAT_GDEF_CMP_IMMEDIATE(smat_d, 'd', <, SMAT_ILT) SMAT_GDEF_CMP_IMMEDIATE(smat_d, 'd', >, SMAT_IGT) SMAT_GDEF_CMP_IMMEDIATE(smat_d, 'd', <=, SMAT_ILEQ) SMAT_GDEF_CMP_IMMEDIATE(smat_d, 'd', >=, SMAT_IGEQ) #undef SMAT_GDEF_CMP_IMMEDIATE #line 6475 "smat.w" #line 6188 "smat.w" #line 6240 "smat.w" #ifdef SMAT_DISABLE #undef SMAT_A #undef SMAT_W #undef SMAT_SET_OSTREAM #undef SMAT_SET_ISTREAM #undef SMAT_LOG1 #undef SMAT_LOG2 #undef SMAT_LOG2B #undef SMAT_LOG3 #undef SMAT_MASK #define SMAT_SET_OSTREAM(OS) #define SMAT_SET_ISTREAM(IS) #define SMAT_LOG1(C, ID, S1) #define SMAT_LOG2(C, ID, S1, D) #define SMAT_LOG2B(C, ID, S1, S2) #define SMAT_LOG3(C, ID, S1, S2, D) #define SMAT_MASK(M) #endif // SMAT_DISABLE #line 6190 "smat.w" #endif // _SMAT_H_