CBMC
Loading...
Searching...
No Matches
Functions
arith_tools.cpp File Reference
#include "arith_tools.h"
#include "c_types.h"
#include "expr_util.h"
#include "fixedbv.h"
#include "ieee_float.h"
#include "invariant.h"
#include "mathematical_types.h"
#include "std_expr.h"
#include <algorithm>
+ Include dependency graph for arith_tools.cpp:

Go to the source code of this file.

Functions

  Convert a constant expression expr to an arbitrary-precision integer.
 
 
std::size_t  address_bits (const mp_integer &size)
  ceil(log2(size))
 
 
  A multi-precision implementation of the power operator.
 
 
 
bool  get_bvrep_bit (const irep_idt &src, std::size_t width, std::size_t bit_index)
  Get a bit with given index from bit-vector representation.
 
  turn a value 0...15 into '0'-'9', 'A'-'Z'
 
irep_idt  make_bvrep (const std::size_t width, const std::function< bool(std::size_t)> f)
  construct a bit-vector representation from a functor
 
irep_idt  bvrep_bitwise_op (const irep_idt &a, const irep_idt &b, const std::size_t width, const std::function< bool(bool, bool)> f)
  perform a binary bit-wise operation, given as a functor, on a bit-vector representation
 
irep_idt  bvrep_bitwise_op (const irep_idt &a, const std::size_t width, const std::function< bool(bool)> f)
  perform a unary bit-wise operation, given as a functor, on a bit-vector representation
 
irep_idt  integer2bvrep (const mp_integer &src, std::size_t width)
  convert an integer to bit-vector representation with given width This uses two's complement for negative numbers.
 
mp_integer  bvrep2integer (const irep_idt &src, std::size_t width, bool is_signed)
  convert a bit-vector representation (possibly signed) to integer
 

Function Documentation

◆  address_bits()

std::size_t address_bits ( const mp_integersize )

ceil(log2(size))

Definition at line 190 of file arith_tools.cpp.

◆  bvrep2integer()

mp_integer bvrep2integer ( const irep_idtsrc,
std::size_t  width,
bool  is_signed 
)

convert a bit-vector representation (possibly signed) to integer

Definition at line 426 of file arith_tools.cpp.

◆  bvrep_bitwise_op() [1/2]

irep_idt bvrep_bitwise_op ( const irep_idta,
const irep_idtb,
const std::size_t  width,
const std::function< bool(bool, bool)>  f 
)

perform a binary bit-wise operation, given as a functor, on a bit-vector representation

Parameters
a the representation of the first bit vector
b the representation of the second bit vector
width the width of the bit-vector
f the functor
Returns
new bitvector representation

Definition at line 374 of file arith_tools.cpp.

◆  bvrep_bitwise_op() [2/2]

irep_idt bvrep_bitwise_op ( const irep_idta,
const std::size_t  width,
const std::function< bool(bool)>  f 
)

perform a unary bit-wise operation, given as a functor, on a bit-vector representation

Parameters
a the bit-vector representation
width the width of the bit-vector
f the functor
Returns
new bitvector representation

Definition at line 391 of file arith_tools.cpp.

◆  from_integer()

constant_exprt from_integer ( const mp_integerint_value,
const typettype 
)

Definition at line 100 of file arith_tools.cpp.

◆  get_bvrep_bit()

bool get_bvrep_bit ( const irep_idtsrc,
std::size_t  width,
std::size_t  bit_index 
)

Get a bit with given index from bit-vector representation.

Parameters
src the bitvector representation
width the number of bits in the bitvector
bit_index index (0 is the least significant)

Definition at line 286 of file arith_tools.cpp.

◆  integer2bvrep()

irep_idt integer2bvrep ( const mp_integersrc,
std::size_t  width 
)

convert an integer to bit-vector representation with given width This uses two's complement for negative numbers.

If the value is out of range, it is 'wrapped around'.

Definition at line 404 of file arith_tools.cpp.

◆  is_power_of_two()

bool is_power_of_two ( const mp_integern )

Definition at line 205 of file arith_tools.cpp.

◆  make_bvrep()

irep_idt make_bvrep ( const std::size_t  width,
const std::function< bool(std::size_t)>  f 
)

construct a bit-vector representation from a functor

Parameters
width the width of the bit-vector
f the functor – the parameter is the bit index
Returns
new bitvector representation

Definition at line 330 of file arith_tools.cpp.

◆  mp_max()

void mp_max ( mp_integera,
const mp_integerb 
)

Definition at line 276 of file arith_tools.cpp.

◆  mp_min()

void mp_min ( mp_integera,
const mp_integerb 
)

Definition at line 270 of file arith_tools.cpp.

◆  nibble2hex()

static char nibble2hex ( unsigned char  nibble )
static

turn a value 0...15 into '0'-'9', 'A'-'Z'

Definition at line 315 of file arith_tools.cpp.

◆  power()

mp_integer power ( const mp_integerbase,
const mp_integerexponent 
)

A multi-precision implementation of the power operator.

parameters: Two mp_integers, base and exponent
Returns
One mp_integer with the value base^{exponent}

Definition at line 219 of file arith_tools.cpp.

◆  to_integer()

bool to_integer ( const constant_exprtexpr,
mp_integerint_value 
)

Convert a constant expression expr to an arbitrary-precision integer.

Parameters
expr Source expression
[out] int_value Integer value (only modified if conversion succeeds)
Returns
False if, and only if, the conversion was successful.

Definition at line 21 of file arith_tools.cpp.

AltStyle によって変換されたページ (->オリジナル) /