cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
boolbv_bv_rel.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module:
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
9
#include "
boolbv.h
"
10
11
#include <
util/bitvector_types.h
>
12
13
#include "
boolbv_type.h
"
14
15
#include <
solvers/floatbv/float_utils.h
>
16
18
literalt
boolbvt::convert_bv_rel
(
const
binary_relation_exprt
&expr)
19
{
20
const
irep_idt
&rel=expr.
id
();
21
22
const
exprt
&lhs = expr.
lhs
();
23
const
exprt
&rhs = expr.
rhs
();
24
25
const
bvt
&bv_lhs =
convert_bv
(lhs);
26
const
bvt
&bv_rhs =
convert_bv
(rhs);
27
28
bvtypet
bvtype_lhs =
get_bvtype
(lhs.
type
());
29
bvtypet
bvtype_rhs =
get_bvtype
(rhs.
type
());
30
31
if
(
32
bv_lhs.size() == bv_rhs.size() && !bv_lhs.empty() &&
33
bvtype_lhs == bvtype_rhs)
34
{
35
if
(bvtype_lhs ==
bvtypet::IS_FLOAT
)
36
{
37
float_utilst
float_utils(
prop
,
to_floatbv_type
(lhs.
type
()));
38
39
if
(rel == ID_le)
40
return
float_utils.
relation
(bv_lhs,
float_utilst::relt::LE
, bv_rhs);
41
else
if
(rel == ID_lt)
42
return
float_utils.
relation
(bv_lhs,
float_utilst::relt::LT
, bv_rhs);
43
else
if
(rel == ID_ge)
44
return
float_utils.
relation
(bv_lhs,
float_utilst::relt::GE
, bv_rhs);
45
else
if
(rel == ID_gt)
46
return
float_utils.
relation
(bv_lhs,
float_utilst::relt::GT
, bv_rhs);
47
else
48
return
SUB::convert_rest
(expr);
49
}
50
else
if
(
51
(lhs.
type
().
id
() == ID_range && rhs.
type
() == lhs.
type
()) ||
52
bvtype_lhs ==
bvtypet::IS_SIGNED
|| bvtype_lhs ==
bvtypet::IS_UNSIGNED
||
53
bvtype_lhs ==
bvtypet::IS_FIXED
)
54
{
55
literalt
literal;
56
57
bv_utilst::representationt
rep = ((bvtype_lhs ==
bvtypet::IS_SIGNED
) ||
58
(bvtype_lhs ==
bvtypet::IS_FIXED
))
59
?
bv_utilst::representationt::SIGNED
60
:
bv_utilst::representationt::UNSIGNED
;
61
62
#if 1
63
64
return
bv_utils
.rel(bv_lhs, expr.
id
(), bv_rhs, rep);
65
66
#else
67
literalt
literal =
bv_utils
.rel(bv_lhs, expr.
id
(), bv_rhs, rep);
68
69
if
(
prop
.has_set_to())
70
{
71
// it's unclear if this helps
72
if
(bv_lhs.size() > 8)
73
{
74
literalt
equal_lit =
equality
(lhs, rhs);
75
76
if
(or_equal)
77
prop
.l_set_to_true(
prop
.limplies(equal_lit, literal));
78
else
79
prop
.l_set_to_true(
prop
.limplies(equal_lit, !literal));
80
}
81
}
82
83
return
literal;
84
#endif
85
}
86
else
if
(
87
(bvtype_lhs ==
bvtypet::IS_VERILOG_SIGNED
||
88
bvtype_lhs ==
bvtypet::IS_VERILOG_UNSIGNED
) &&
89
lhs.
type
() == rhs.
type
())
90
{
91
// extract number bits
92
bvt
extract0, extract1;
93
94
extract0.resize(bv_lhs.size() / 2);
95
extract1.resize(bv_rhs.size() / 2);
96
97
for
(std::size_t i = 0; i < extract0.size(); i++)
98
extract0[i] = bv_lhs[i * 2];
99
100
for
(std::size_t i = 0; i < extract1.size(); i++)
101
extract1[i] = bv_rhs[i * 2];
102
103
bv_utilst::representationt
rep =
bv_utilst::representationt::UNSIGNED
;
104
105
// now compare
106
return
bv_utils
.rel(extract0, expr.
id
(), extract1, rep);
107
}
108
}
109
110
return
SUB::convert_rest
(expr);
111
}
bitvector_types.h
Pre-defined bitvector types.
to_floatbv_type
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
Definition
bitvector_types.h:386
boolbv.h
get_bvtype
bvtypet get_bvtype(const typet &type)
Definition
boolbv_type.cpp:13
boolbv_type.h
bvtypet
bvtypet
Definition
boolbv_type.h:17
bvtypet::IS_FIXED
@ IS_FIXED
Definition
boolbv_type.h:18
bvtypet::IS_VERILOG_UNSIGNED
@ IS_VERILOG_UNSIGNED
Definition
boolbv_type.h:19
bvtypet::IS_VERILOG_SIGNED
@ IS_VERILOG_SIGNED
Definition
boolbv_type.h:19
bvtypet::IS_FLOAT
@ IS_FLOAT
Definition
boolbv_type.h:18
bvtypet::IS_SIGNED
@ IS_SIGNED
Definition
boolbv_type.h:18
bvtypet::IS_UNSIGNED
@ IS_UNSIGNED
Definition
boolbv_type.h:18
binary_exprt::lhs
exprt & lhs()
Definition
std_expr.h:669
binary_exprt::rhs
exprt & rhs()
Definition
std_expr.h:679
binary_relation_exprt
A base class for relations, i.e., binary predicates whose two operands have the same type.
Definition
std_expr.h:774
boolbvt::convert_bv_rel
virtual literalt convert_bv_rel(const binary_relation_exprt &)
Flatten <, >, <= and >= expressions.
Definition
boolbv_bv_rel.cpp:18
boolbvt::convert_bv
virtual const bvt & convert_bv(const exprt &expr, const std::optional< std::size_t > expected_width={})
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
Definition
boolbv.cpp:40
boolbvt::bv_utils
bv_utilst bv_utils
Definition
boolbv.h:121
bv_utilst::representationt
representationt
Definition
bv_utils.h:28
bv_utilst::representationt::SIGNED
@ SIGNED
Definition
bv_utils.h:28
bv_utilst::representationt::UNSIGNED
@ UNSIGNED
Definition
bv_utils.h:28
equalityt::equality
virtual literalt equality(const exprt &e1, const exprt &e2)
Definition
equality.cpp:17
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::type
typet & type()
Return the type of the expression.
Definition
expr.h:85
float_utilst
Definition
float_utils.h:18
float_utilst::relt::LT
@ LT
Definition
float_utils.h:152
float_utilst::relt::GT
@ GT
Definition
float_utils.h:152
float_utilst::relt::LE
@ LE
Definition
float_utils.h:152
float_utilst::relt::GE
@ GE
Definition
float_utils.h:152
float_utilst::relation
literalt relation(const bvt &src1, relt rel, const bvt &src2)
Definition
float_utils.cpp:726
irept::id
const irep_idt & id() const
Definition
irep.h:388
literalt
Definition
literal.h:26
prop_conv_solvert::convert_rest
virtual literalt convert_rest(const exprt &expr)
Definition
prop_conv_solver.cpp:314
prop_conv_solvert::prop
propt & prop
Definition
prop_conv_solver.h:130
float_utils.h
bvt
std::vector< literalt > bvt
Definition
literal.h:201
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
solvers
flattening
boolbv_bv_rel.cpp
Generated by
1.17.0