Skip to content

Commit d4684f6

Browse files
committed
Cleanup the API of bv_utilst::adder
Don't make every caller create an uninitialised literal.
1 parent 682880a commit d4684f6

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

src/solvers/flattening/bv_utils.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,21 @@ literalt bv_utilst::carry(literalt a, literalt b, literalt c)
290290
}
291291
}
292292

293-
void bv_utilst::adder(
293+
literalt bv_utilst::adder(
294294
bvt &sum,
295295
const bvt &op,
296-
literalt carry_in,
297-
literalt &carry_out)
296+
literalt carry_in)
298297
{
299298
PRECONDITION(sum.size() == op.size());
300299

301-
carry_out=carry_in;
300+
literalt carry_out = carry_in;
302301

303302
for(std::size_t i=0; i<sum.size(); i++)
304303
{
305304
sum[i] = full_adder(sum[i], op[i], carry_out, carry_out);
306305
}
306+
307+
return carry_out;
307308
}
308309

309310
literalt bv_utilst::carry_out(
@@ -337,12 +338,12 @@ bvt bv_utilst::add_sub(const bvt &op0, const bvt &op1, bool subtract)
337338
PRECONDITION(op0.size() == op1.size());
338339

339340
literalt carry_in=const_literal(subtract);
340-
literalt carry_out;
341341

342342
bvt result=op0;
343343
bvt tmp_op1=subtract?inverted(op1):op1;
344344

345-
adder(result, tmp_op1, carry_in, carry_out);
345+
// we ignore the carry-out
346+
(void)adder(result, tmp_op1, carry_in);
346347

347348
return result;
348349
}
@@ -353,9 +354,9 @@ bvt bv_utilst::add_sub(const bvt &op0, const bvt &op1, literalt subtract)
353354
select(subtract, inverted(op1), op1);
354355

355356
bvt result=op0;
356-
literalt carry_out;
357357

358-
adder(result, op1_sign_applied, subtract, carry_out);
358+
// we ignore the carry-out
359+
(void)adder(result, op1_sign_applied, subtract);
359360

360361
return result;
361362
}
@@ -371,12 +372,11 @@ bvt bv_utilst::saturating_add_sub(
371372
rep == representationt::SIGNED || rep == representationt::UNSIGNED);
372373

373374
literalt carry_in = const_literal(subtract);
374-
literalt carry_out;
375375

376376
bvt add_sub_result = op0;
377377
bvt tmp_op1 = subtract ? inverted(op1) : op1;
378378

379-
adder(add_sub_result, tmp_op1, carry_in, carry_out);
379+
literalt carry_out = adder(add_sub_result, tmp_op1, carry_in);
380380

381381
bvt result;
382382
result.reserve(add_sub_result.size());
@@ -496,8 +496,8 @@ void bv_utilst::adder_no_overflow(
496496
literalt sign_the_same=
497497
prop.lequal(sum[sum.size()-1], tmp_op[tmp_op.size()-1]);
498498

499-
literalt carry;
500-
adder(sum, tmp_op, const_literal(subtract), carry);
499+
// we ignore the carry-out
500+
(void)adder(sum, tmp_op, const_literal(subtract));
501501

502502
// result of addition in sum
503503
prop.l_set_to_false(
@@ -508,18 +508,14 @@ void bv_utilst::adder_no_overflow(
508508
INVARIANT(
509509
rep == representationt::UNSIGNED,
510510
"representation has either value signed or unsigned");
511-
literalt carry_out;
512-
adder(sum, tmp_op, const_literal(subtract), carry_out);
511+
literalt carry_out = adder(sum, tmp_op, const_literal(subtract));
513512
prop.l_set_to(carry_out, subtract);
514513
}
515514
}
516515

517516
void bv_utilst::adder_no_overflow(bvt &sum, const bvt &op)
518517
{
519-
literalt carry_out=const_literal(false);
520-
521-
adder(sum, op, carry_out, carry_out);
522-
518+
literalt carry_out = adder(sum, op, const_literal(false));
523519
prop.l_set_to_false(carry_out); // enforce no overflow
524520
}
525521

src/solvers/flattening/bv_utils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,10 @@ class bv_utilst
223223
protected:
224224
propt &prop;
225225

226-
void adder(
226+
literalt adder(
227227
bvt &sum,
228228
const bvt &op,
229-
literalt carry_in,
230-
literalt &carry_out);
229+
literalt carry_in);
231230

232231
void adder_no_overflow(
233232
bvt &sum,

0 commit comments

Comments
 (0)