Skip to content
Open
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
34 changes: 33 additions & 1 deletion xlsynth-g8r/src/equiv/bitwuzla_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use bitwuzla_sys::{
};

use crate::{
equiv::solver_interface::{BitVec, Response, Solver},
equiv::solver_interface::{BitVec, Response, Solver, angelic_div_mod_common},
ir_value_utils::{ir_bits_from_lsb_is_0, ir_value_from_bits_with_type},
xls_ir::ir,
};
Expand Down Expand Up @@ -878,6 +878,38 @@ impl Solver for Bitwuzla {
self.bin_op(x, y, BITWUZLA_KIND_BV_UREM)
}

fn angelic_udiv(
&mut self,
x: &BitVec<Self::Term>,
y: &BitVec<Self::Term>,
) -> BitVec<Self::Term> {
angelic_div_mod_common(self, x, y, false).0
}

fn angelic_urem(
&mut self,
x: &BitVec<Self::Term>,
y: &BitVec<Self::Term>,
) -> BitVec<Self::Term> {
angelic_div_mod_common(self, x, y, false).1
}

fn angelic_sdiv(
&mut self,
x: &BitVec<Self::Term>,
y: &BitVec<Self::Term>,
) -> BitVec<Self::Term> {
angelic_div_mod_common(self, x, y, true).0
}

fn angelic_srem(
&mut self,
x: &BitVec<Self::Term>,
y: &BitVec<Self::Term>,
) -> BitVec<Self::Term> {
angelic_div_mod_common(self, x, y, true).1
}

fn srem(&mut self, x: &BitVec<Self::Term>, y: &BitVec<Self::Term>) -> BitVec<Self::Term> {
self.bin_op(x, y, BITWUZLA_KIND_BV_SREM)
}
Expand Down
34 changes: 33 additions & 1 deletion xlsynth-g8r/src/equiv/boolector_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use boolector_sys::{
};

use crate::{
equiv::solver_interface::{BitVec, Response, Solver},
equiv::solver_interface::{BitVec, Response, Solver, angelic_div_mod_common},
ir_value_utils::{ir_bits_from_lsb_is_0, ir_value_from_bits_with_type},
xls_ir::ir,
};
Expand Down Expand Up @@ -372,6 +372,38 @@ impl Solver for Boolector {
self.bin_op(x, y, |b, x, y| unsafe { boolector_urem(b, x, y) })
}

fn angelic_udiv(
&mut self,
x: &BitVec<Self::Term>,
y: &BitVec<Self::Term>,
) -> BitVec<Self::Term> {
angelic_div_mod_common(self, x, y, false).0
}

fn angelic_urem(
&mut self,
x: &BitVec<Self::Term>,
y: &BitVec<Self::Term>,
) -> BitVec<Self::Term> {
angelic_div_mod_common(self, x, y, false).1
}

fn angelic_sdiv(
&mut self,
x: &BitVec<Self::Term>,
y: &BitVec<Self::Term>,
) -> BitVec<Self::Term> {
angelic_div_mod_common(self, x, y, true).0
}

fn angelic_srem(
&mut self,
x: &BitVec<Self::Term>,
y: &BitVec<Self::Term>,
) -> BitVec<Self::Term> {
angelic_div_mod_common(self, x, y, true).1
}

fn srem(&mut self, x: &BitVec<Self::Term>, y: &BitVec<Self::Term>) -> BitVec<Self::Term> {
self.bin_op(x, y, |b, x, y| unsafe { boolector_srem(b, x, y) })
}
Expand Down
52 changes: 51 additions & 1 deletion xlsynth-g8r/src/equiv/easy_smt_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
use easy_smt::{Context, ContextBuilder, SExpr};

use crate::{
equiv::solver_interface::{BitVec, Solver},
equiv::solver_interface::{BitVec, Solver, angelic_div_mod_common},
ir_value_utils::{ir_bits_from_lsb_is_0, ir_value_from_bits_with_type},
xls_ir::ir,
};
Expand Down Expand Up @@ -114,6 +114,7 @@ pub struct EasySmtSolver {
term_cache: HashMap<String, SExpr>,
reverse_cache: HashMap<SExpr, String>,
fresh_counter: u64,
div_rem_cache: HashMap<(SExpr, SExpr, bool), (SExpr, SExpr)>,
}

impl EasySmtSolver {
Expand Down Expand Up @@ -260,6 +261,38 @@ impl EasySmtSolver {
BitVec::ZeroWidth => panic!("Cannot reduce zero-width bitvector"),
}
}
fn angelic_div_mod(
&mut self,
lhs: &BitVec<SExpr>,
rhs: &BitVec<SExpr>,
is_signed: bool,
) -> (BitVec<SExpr>, BitVec<SExpr>) {
let lhs_term = lhs.get_term().unwrap();
let rhs_term = rhs.get_term().unwrap();
if let Some((div_result, rem_result)) =
self.div_rem_cache.get(&(*lhs_term, *rhs_term, is_signed))
{
return (
BitVec::BitVec {
width: lhs.get_width(),
rep: div_result.clone(),
},
BitVec::BitVec {
width: lhs.get_width(),
rep: rem_result.clone(),
},
);
}
let (div_result, rem_result) = angelic_div_mod_common(self, lhs, rhs, is_signed);
self.div_rem_cache.insert(
(*lhs_term, *rhs_term, is_signed),
(
div_result.get_term().unwrap().clone(),
rem_result.get_term().unwrap().clone(),
),
);
(div_result, rem_result)
}
}

impl Solver for EasySmtSolver {
Expand Down Expand Up @@ -288,6 +321,7 @@ impl Solver for EasySmtSolver {
term_cache: HashMap::new(),
reverse_cache: HashMap::new(),
fresh_counter: 0,
div_rem_cache: HashMap::new(),
})
}

Expand Down Expand Up @@ -478,6 +512,22 @@ impl Solver for EasySmtSolver {
self.bin_op(lhs, rhs, Context::bvurem)
}

fn angelic_udiv(&mut self, lhs: &BitVec<SExpr>, rhs: &BitVec<SExpr>) -> BitVec<SExpr> {
self.angelic_div_mod(lhs, rhs, false).0
}

fn angelic_urem(&mut self, lhs: &BitVec<SExpr>, rhs: &BitVec<SExpr>) -> BitVec<SExpr> {
self.angelic_div_mod(lhs, rhs, false).1
}

fn angelic_sdiv(&mut self, lhs: &BitVec<SExpr>, rhs: &BitVec<SExpr>) -> BitVec<SExpr> {
self.angelic_div_mod(lhs, rhs, true).0
}

fn angelic_srem(&mut self, lhs: &BitVec<SExpr>, rhs: &BitVec<SExpr>) -> BitVec<SExpr> {
self.angelic_div_mod(lhs, rhs, true).1
}

fn srem(&mut self, lhs: &BitVec<SExpr>, rhs: &BitVec<SExpr>) -> BitVec<SExpr> {
self.bin_op(lhs, rhs, Context::bvsrem)
}
Expand Down
Loading
Loading