1/*******************************************************************\
3Module: API to expression classes for bitvectors
5Author: Daniel Kroening, kroening@kroening.com
7\*******************************************************************/
56 // build a mask 0...0 1
61 // shift the mask by the index
67 // zero-extend the replacement bit to match src
71 // shift the replacement bits
74 // or the masked src and the shifted replacement bits
86 // build a mask 1...1 0...0
92 // shift the mask by the index
98 // zero-extend or shrink the replacement bits to match src
101 // shift the replacement bits
104 // or the masked src and the shifted replacement bits
111 // Hacker's Delight, variant pop0:
112 // x = (x & 0x55555555) + ((x >> 1) & 0x55555555);
113 // x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
114 // x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F);
115 // x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF);
118 // http://www.hackersdelight.org/permissions.htm
120 // make sure the operand width is a power of two
133 // repeatedly compute x = (x & bitmask) + ((x >> shift) & bitmask)
134 for(std::size_t shift = 1; shift <
new_width; shift <<= 1)
139 // bitmask is a string of alternating shift-many bits starting from lsb set
143 for(std::size_t i = 0; i <
new_width / (2 * shift); ++i)
144 bitstring += std::string(shift,
'0') + std::string(shift,
'1');
147 // build the expression
151 // the result is restricted to the result type
162 // return popcount(~x);
164 // make sure the operand width is a power of two
177 // repeatedly compute x = x | (x >> shift)
178 for(std::size_t shift = 1; shift <
new_width; shift <<= 1)
183 // build the expression
187 // the result is restricted to the result type
197 // popcount(~(x | (~x + 1)))
198 // compute -x using two's complement
214 for(std::size_t i = 0; i < int_width; ++i)
283 // bitwidth(x) - clz(x & ~((unsigned)x - 1));
304 else // new_width <= old_width
317 for(std::size_t i = 0; i < width; i++)
340 // same as onehot, but on flipped operand bits
static exprt onehot_lowering(const exprt &expr)
API to expression classes for bitvectors.
Pre-defined bitvector types.
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Boolean AND All operands must be boolean, and the result is always boolean.
A base class for binary expressions.
A base class for expressions that are predicates, i.e., Boolean-typed, and that take exactly two argu...
Bit-wise AND Any number of operands that is greater or equal one.
Bit-wise negation of bit-vectors.
Bit-wise OR Any number of operands that is greater or equal one.
exprt lower() const
Lower a bitreverse_exprt to arithmetic and logic expressions.
Fixed-width bit-vector without numerical interpretation.
Concatenation of bit-vector operands.
A constant literal expression.
The count leading zeros (counting the number of zero bits starting from the most-significant bit) exp...
exprt lower() const
Lower a count_leading_zeros_exprt to arithmetic and logic expressions.
exprt lower() const
Lower a count_trailing_zeros_exprt to arithmetic and logic expressions.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
Base class for all expressions.
std::vector< exprt > operandst
typet & type()
Return the type of the expression.
void add_to_operands(const exprt &expr)
Add the given argument to the end of exprt's operands.
The Boolean constant false.
exprt lower() const
Lower a find_first_set_exprt to arithmetic and logic expressions.
Unbounded, signed integers (mathematical integers, not bitvectors)
exprt lower() const
Lower a minus_overflow_exprt to arithmetic and logic expressions.
Binary multiplication Associativity is not specified.
exprt lower() const
Lower a mult_overflow_exprt to arithmetic and logic expressions.
exprt lower() const
lowering to extractbit
exprt lower() const
lowering to extractbit
Boolean OR All operands must be boolean, and the result is always boolean.
The plus expression Associativity is not specified.
exprt lower() const
Lower a plus_overflow_exprt to arithmetic and logic expressions.
The popcount (counting the number of bits set to 1) expression.
exprt lower() const
Lower a popcount_exprt to arithmetic and logic expressions.
shift_exprt(exprt _src, const irep_idt &_id, exprt _distance)
Fixed-width bit-vector with two's complement interpretation.
Expression to hold a symbol (variable)
Semantic type conversion.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
Fixed-width bit-vector with unsigned binary interpretation.
Replaces a sub-range of a bit-vector operand.
update_bit_exprt(exprt _src, exprt _index, exprt _new_value)
Replaces the bit [_index] from _src to produce a result of the same type as _src.
exprt lower() const
A lowering to masking, shifting, or.
exprt lower() const
A lowering to masking, shifting, or.
zero extension The operand is converted to the given type by either a) truncating if the new type is ...
const mp_integer binary2integer(const std::string &n, bool is_signed)
convert binary string representation to mp_integer
#define CHECK_RETURN(CONDITION)
exprt disjunction(const exprt::operandst &op)
1) generates a disjunction for two or more operands 2) for one operand, returns the operand 3) return...