Skip to content

Commit 098ecfa

Browse files
committed
btorsim: implement rol and ror
This is a simple implementation delegating to sll and srl and or-ing the results together Signed-off-by: Ferdinand Bachmann <[email protected]>
1 parent 8dc0add commit 098ecfa

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

src/btorsim/btorsim.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ parse_model_line (Btor2Line *l)
257257
case BTOR2_TAG_redand:
258258
case BTOR2_TAG_redor:
259259
case BTOR2_TAG_redxor:
260+
case BTOR2_TAG_rol:
261+
case BTOR2_TAG_ror:
260262
case BTOR2_TAG_sdiv:
261263
case BTOR2_TAG_sext:
262264
case BTOR2_TAG_sgt:
@@ -284,8 +286,6 @@ parse_model_line (Btor2Line *l)
284286

285287
case BTOR2_TAG_fair:
286288
case BTOR2_TAG_justice:
287-
case BTOR2_TAG_rol:
288-
case BTOR2_TAG_ror:
289289
case BTOR2_TAG_saddo:
290290
case BTOR2_TAG_sdivo:
291291
case BTOR2_TAG_smod:
@@ -554,6 +554,20 @@ simulate (int64_t id)
554554
assert (args[0].type == BtorSimState::Type::BITVEC);
555555
res.bv_state = btorsim_bv_redxor (args[0].bv_state);
556556
break;
557+
case BTOR2_TAG_rol:
558+
assert (l->nargs == 2);
559+
assert (res.type == BtorSimState::Type::BITVEC);
560+
assert (args[0].type == BtorSimState::Type::BITVEC);
561+
assert (args[1].type == BtorSimState::Type::BITVEC);
562+
res.bv_state = btorsim_bv_rol (args[0].bv_state, args[1].bv_state);
563+
break;
564+
case BTOR2_TAG_ror:
565+
assert (l->nargs == 2);
566+
assert (res.type == BtorSimState::Type::BITVEC);
567+
assert (args[0].type == BtorSimState::Type::BITVEC);
568+
assert (args[1].type == BtorSimState::Type::BITVEC);
569+
res.bv_state = btorsim_bv_ror (args[0].bv_state, args[1].bv_state);
570+
break;
557571
case BTOR2_TAG_slice:
558572
assert (l->nargs == 1);
559573
assert (res.type == BtorSimState::Type::BITVEC);

src/btorsim/btorsimbv.c

+32
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,38 @@ btorsim_bv_sra (const BtorSimBitVector *a, const BtorSimBitVector *b)
17531753
return res;
17541754
}
17551755

1756+
BtorSimBitVector *
1757+
btorsim_bv_rol (const BtorSimBitVector *a, const BtorSimBitVector *b) {
1758+
BtorSimBitVector *width = btorsim_bv_uint64_to_bv(a->width, a->width);
1759+
BtorSimBitVector *rev = btorsim_bv_sub(width, b);
1760+
1761+
BtorSimBitVector *sll_part = btorsim_bv_sll(a, b);
1762+
BtorSimBitVector *srl_part = btorsim_bv_srl(a, rev);
1763+
BtorSimBitVector *res = btorsim_bv_or(sll_part, srl_part);
1764+
1765+
btorsim_bv_free(width);
1766+
btorsim_bv_free(rev);
1767+
btorsim_bv_free(sll_part);
1768+
btorsim_bv_free(srl_part);
1769+
return res;
1770+
}
1771+
1772+
BtorSimBitVector *
1773+
btorsim_bv_ror (const BtorSimBitVector *a, const BtorSimBitVector *b) {
1774+
BtorSimBitVector *width = btorsim_bv_uint64_to_bv(a->width, a->width);
1775+
BtorSimBitVector *rev = btorsim_bv_sub(width, b);
1776+
1777+
BtorSimBitVector *srl_part = btorsim_bv_srl(a, b);
1778+
BtorSimBitVector *sll_part = btorsim_bv_sll(a, rev);
1779+
BtorSimBitVector *res = btorsim_bv_or(srl_part, sll_part);
1780+
1781+
btorsim_bv_free(width);
1782+
btorsim_bv_free(rev);
1783+
btorsim_bv_free(srl_part);
1784+
btorsim_bv_free(sll_part);
1785+
return res;
1786+
}
1787+
17561788
BtorSimBitVector *
17571789
btorsim_bv_mul (const BtorSimBitVector *a, const BtorSimBitVector *b)
17581790
{

src/btorsim/btorsimbv.h

+6
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ BtorSimBitVector *btorsim_bv_srl (const BtorSimBitVector *a,
191191
BtorSimBitVector *btorsim_bv_sra (const BtorSimBitVector *a,
192192
const BtorSimBitVector *b);
193193

194+
BtorSimBitVector *btorsim_bv_rol (const BtorSimBitVector *a,
195+
const BtorSimBitVector *b);
196+
197+
BtorSimBitVector *btorsim_bv_ror (const BtorSimBitVector *a,
198+
const BtorSimBitVector *b);
199+
194200
BtorSimBitVector *btorsim_bv_mul (const BtorSimBitVector *a,
195201
const BtorSimBitVector *b);
196202

0 commit comments

Comments
 (0)