2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2015 - Scilab Enterprises - Calixte DENIZET
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 #ifndef __OPVALUE_HXX__
14 #define __OPVALUE_HXX__
25 * \brief OpValue represents an operation between one or two operands
27 * This is struct is mainly used by the GVN.
33 UNARYMINUS = 0, UNARYNEG, PLUS, MINUS, TIMES, DOTTIMES, RDIV, DOTRDIV, POWER, DOTPOWER
40 * \brief constructor for unary operation
41 * \param _kind the operation kind
42 * \param _lnum the value of the operand
44 OpValue(Kind _kind, uint64_t _lnum) : kind(_kind), lnum(_lnum), rnum(0) { }
47 * \brief constructor for binary operation
48 * \param _kind the operation kind
49 * \param _lnum the value of the left operand
50 * \param _rnum the value of the right operand
52 OpValue(Kind _kind, uint64_t _lnum, uint64_t _rnum) : kind(_kind), lnum(_lnum), rnum(_rnum)
54 if (isCommutative() && lnum > rnum)
56 const uint64_t x = lnum;
63 * \brief Check if the operation is commutative
64 * \return true if the operation is commutative
66 inline bool isCommutative() const
68 return kind == PLUS || kind == TIMES || kind == DOTTIMES;
72 * \brief Check if the operation is unary
73 * \return true if the operation is unary
75 inline bool isUnary() const
77 return kind == UNARYMINUS || kind == UNARYNEG;
81 * \brief Compute the hash
84 inline std::size_t hash() const
86 return tools::hash_combine(kind, lnum, rnum);
90 * \brief Overload of the operator ==
92 inline bool operator==(const OpValue & R) const
98 return lnum == R.lnum;
102 return lnum == R.lnum && rnum == R.rnum;
109 * \brief Overload of the operator <<
111 friend std::wostream & operator<<(std::wostream & out, const OpValue & ov);
115 * \brief Helper struct to be used in unordered_map
119 inline std::size_t operator()(const OpValue & ov) const
127 * \brief Helper struct to be used in unordered_map
131 inline bool operator()(const OpValue & L, const OpValue & R) const
138 } // namespace analysis
140 #endif // __OPVALUE_HXX__