Skip to content

simplify bitxnor #8506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/util/bitvector_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,41 @@
return static_cast<bitxor_exprt &>(expr);
}

/// \brief Bit-wise XNOR
class bitxnor_exprt : public multi_ary_exprt

Check warning on line 194 in src/util/bitvector_expr.h

View check run for this annotation

Codecov / codecov/patch

src/util/bitvector_expr.h#L194

Added line #L194 was not covered by tests
{
public:
bitxnor_exprt(exprt _op0, exprt _op1)
: multi_ary_exprt(std::move(_op0), ID_bitxnor, std::move(_op1))

Check warning on line 198 in src/util/bitvector_expr.h

View check run for this annotation

Codecov / codecov/patch

src/util/bitvector_expr.h#L197-L198

Added lines #L197 - L198 were not covered by tests
{
}
};

template <>
inline bool can_cast_expr<bitxnor_exprt>(const exprt &base)
{
return base.id() == ID_bitxnor;
}

/// \brief Cast an exprt to a \ref bitxnor_exprt
///
/// \a expr must be known to be \ref bitxnor_exprt.
///
/// \param expr: Source expression
/// \return Object of type \ref bitxnor_exprt
inline const bitxnor_exprt &to_bitxnor_expr(const exprt &expr)
{
PRECONDITION(expr.id() == ID_bitxnor);
return static_cast<const bitxnor_exprt &>(expr);
}

/// \copydoc to_bitxnor_expr(const exprt &)
inline bitxnor_exprt &to_bitxnor_expr(exprt &expr)
{
PRECONDITION(expr.id() == ID_bitxnor);
return static_cast<bitxnor_exprt &>(expr);
}

/// \brief Bit-wise AND
class bitand_exprt : public multi_ary_exprt
{
Expand Down
13 changes: 7 additions & 6 deletions src/util/simplify_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,9 +950,10 @@ simplify_exprt::simplify_typecast(const typecast_exprt &expr)
{
irep_idt op_id = expr.op().id();

if(op_id==ID_plus || op_id==ID_minus || op_id==ID_mult ||
op_id==ID_unary_minus ||
op_id==ID_bitxor || op_id==ID_bitor || op_id==ID_bitand)
if(
op_id == ID_plus || op_id == ID_minus || op_id == ID_mult ||
op_id == ID_unary_minus || op_id == ID_bitxor || op_id == ID_bitxnor ||
op_id == ID_bitor || op_id == ID_bitand)
{
exprt result = expr.op();

Expand Down Expand Up @@ -2949,9 +2950,9 @@ simplify_exprt::resultt<> simplify_exprt::simplify_node(const exprt &node)
{
r = simplify_bitnot(to_bitnot_expr(expr));
}
else if(expr.id()==ID_bitand ||
expr.id()==ID_bitor ||
expr.id()==ID_bitxor)
else if(
expr.id() == ID_bitand || expr.id() == ID_bitor || expr.id() == ID_bitxor ||
expr.id() == ID_bitxnor)
{
r = simplify_bitwise(to_multi_ary_expr(expr));
}
Expand Down
2 changes: 2 additions & 0 deletions src/util/simplify_expr_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@
f = [](bool a, bool b) { return a || b; };
else if(new_expr.id() == ID_bitxor)
f = [](bool a, bool b) { return a != b; };
else if(new_expr.id() == ID_bitxnor)
f = [](bool a, bool b) { return a == b; };

Check warning on line 749 in src/util/simplify_expr_int.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/simplify_expr_int.cpp#L748-L749

Added lines #L748 - L749 were not covered by tests
else
UNREACHABLE;

Expand Down
Loading