-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
130 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
// author: Mohanna Shahrad <[email protected]> | ||
|
||
mod samples; | ||
mod summarize; | ||
|
||
use clap::Parser; | ||
use egg::*; | ||
|
@@ -23,6 +24,8 @@ struct Args { | |
print_samples: bool, | ||
#[arg(long)] | ||
dump_smt: bool, | ||
#[arg(long)] | ||
bdd_formula: bool, | ||
#[arg(value_name = "RULE", index = 1)] | ||
rule: String, | ||
} | ||
|
@@ -58,7 +61,8 @@ fn main() { | |
} | ||
}; | ||
|
||
let samples = samples::generate_samples(&args.rule, rule, args.max_width, true, args.dump_smt); | ||
let (samples, rule_info) = | ||
samples::generate_samples(&args.rule, rule, args.max_width, true, args.dump_smt); | ||
let delta_t = std::time::Instant::now() - start; | ||
|
||
println!("Found {} equivalent rewrites.", samples.num_equivalent()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright 2024 Cornell University | ||
// released under BSD 3-Clause License | ||
// author: Kevin Laeufer <[email protected]> | ||
|
||
use crate::samples::{RuleInfo, Samples}; | ||
use egg::Var; | ||
use patronus::expr::WidthInt; | ||
use rustc_hash::FxHashMap; | ||
|
||
/// generate a simplified re-writ condition from samples, using BDDs | ||
pub fn bdd_summarize(rule: &RuleInfo, samples: &Samples) { | ||
for (assignment, is_equal) in samples.iter() { | ||
let v = FxHashMap::from_iter(assignment); | ||
} | ||
} | ||
|
||
const FEATURES: &[Feature] = &[ | ||
Feature { | ||
name: "is_unsigned", // (13) | ||
len: |r| Some(r.signs().count()), | ||
eval: |r, v, o| { | ||
for sign in r.signs() { | ||
// s_i == unsign | ||
o.push(v[&sign] == 0); | ||
} | ||
}, | ||
}, | ||
Feature { | ||
name: "is_width_equal", // (14) | ||
len: |r| { | ||
if r.widths().count() <= 0 { | ||
None | ||
} else { | ||
Some(r.widths().count() * (r.widths().count() - 1)) | ||
} | ||
}, | ||
eval: |r, v, o| { | ||
for w_i in r.widths() { | ||
for w_j in r.widths() { | ||
if w_i != w_j { | ||
// w_i == w_j | ||
o.push(v[&w_i] == v[&w_j]); | ||
} | ||
} | ||
} | ||
}, | ||
}, | ||
Feature { | ||
name: "is_width_smaller", // (15) + (16) | ||
len: |r| { | ||
if r.widths().count() <= 0 { | ||
None | ||
} else { | ||
Some(r.widths().count() * (r.widths().count() - 1) * 3) | ||
} | ||
}, | ||
eval: |r, v, o| { | ||
for w_i in r.widths() { | ||
for w_j in r.widths() { | ||
if w_i != w_j { | ||
let (w_i, w_j) = (v[&w_i], v[&w_j]); | ||
// w_i < w_j | ||
o.push(w_i < w_j); | ||
// w_i + 1 < w_j | ||
o.push(w_i + 1 < w_j); | ||
// w_i - 1 < w_j | ||
o.push(w_i - 1 < w_j); | ||
} | ||
} | ||
} | ||
}, | ||
}, | ||
Feature { | ||
name: "is_width_sum_smaller", // (17) + (18) | ||
len: |r| { | ||
if r.widths().count() <= 1 { | ||
None | ||
} else { | ||
Some(r.widths().count() * (r.widths().count() - 1) * (r.widths().count() - 2) * 2) | ||
} | ||
}, | ||
eval: |r, v, o| { | ||
for w_i in r.widths() { | ||
for w_j in r.widths() { | ||
if w_i != w_j { | ||
for w_k in r.widths() { | ||
if w_k != w_i && w_k != w_j { | ||
let (w_i, w_j, w_k) = (v[&w_i], v[&w_j], v[&w_k]); | ||
// w_i + w_j < w_k | ||
o.push(w_i + w_j < w_k); | ||
// w_i + 2**w_j < w_k | ||
o.push(w_i as u64 + 2u64.pow(w_j) < w_k as u64); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
}, | ||
]; | ||
|
||
struct Feature { | ||
name: &'static str, | ||
len: fn(rule: &RuleInfo) -> Option<usize>, | ||
eval: fn(rule: &RuleInfo, v: &FxHashMap<Var, WidthInt>, out: &mut Vec<bool>), | ||
} |