Skip to content

Commit

Permalink
use Awi instead of ExtAwi
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronKutch committed Oct 4, 2023
1 parent 500713a commit 0172998
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 50 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ jobs:
cargo test --all-features
cargo test --release --all-features
msrv_test_suite:
runs-on: ubuntu-latest
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v2
- name: Install Rust components
run: |
rustup set profile minimal
rustup install nightly-2023-04-14
- name: Run test suite
run: |
cargo test --all-features
cargo test --release --all-features
rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions starlight/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use awint::{
Op::*,
},
awint_macro_internals::triple_arena::Advancer,
ExtAwi,
Awi,
};

use crate::{Note, PBack, TDag, Value};
Expand Down Expand Up @@ -122,7 +122,7 @@ impl TDag {
table.clone()
} else {
let mut awi =
ExtAwi::zero(NonZeroUsize::new(num_entries).unwrap());
Awi::zero(NonZeroUsize::new(num_entries).unwrap());
for i in 0..num_entries {
awi.set(i, table.get((i * out_bw) + i_bit).unwrap())
.unwrap();
Expand Down
10 changes: 5 additions & 5 deletions starlight/src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use awint::{
smallvec::SmallVec,
triple_arena::{Advancer, Ptr},
},
ExtAwi, InlAwi,
Awi, InlAwi,
};

use crate::{
Expand Down Expand Up @@ -95,7 +95,7 @@ impl Optimizer {

// reduction of the LUT
let next_bw = lut.bw() / 2;
let mut next_lut = ExtAwi::zero(NonZeroUsize::new(next_bw).unwrap());
let mut next_lut = Awi::zero(NonZeroUsize::new(next_bw).unwrap());
let w = 1 << i;
let mut from = 0;
let mut to = 0;
Expand All @@ -122,7 +122,7 @@ impl Optimizer {
Ok(()) => (),
Err(j) => {
let next_bw = lut.bw() / 2;
let mut next_lut = ExtAwi::zero(NonZeroUsize::new(next_bw).unwrap());
let mut next_lut = Awi::zero(NonZeroUsize::new(next_bw).unwrap());
let mut to = 0;
for k in 0..lut.bw() {
let inx = InlAwi::from_usize(k);
Expand All @@ -149,8 +149,8 @@ impl Optimizer {
for i in (0..len).rev() {
let next_bw = lut.bw() / 2;
if let Some(nzbw) = NonZeroUsize::new(next_bw) {
let mut tmp0 = ExtAwi::zero(nzbw);
let mut tmp1 = ExtAwi::zero(nzbw);
let mut tmp0 = Awi::zero(nzbw);
let mut tmp1 = Awi::zero(nzbw);
let w = 1 << i;
// LUT if the `i`th bit were 0
let mut from = 0;
Expand Down
8 changes: 4 additions & 4 deletions starlight/src/t_dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::num::{NonZeroU64, NonZeroUsize};
use awint::{
awint_dag::{smallvec::SmallVec, EvalError, Location, Op, OpDag, PNote, PState},
awint_macro_internals::triple_arena::Advancer,
Bits, ExtAwi,
Awi, Bits,
};

use crate::{
Expand Down Expand Up @@ -408,7 +408,7 @@ impl TDag {
.insert_key(p_equiv, Referent::ThisTNode(p_tnode))
.unwrap();
let mut tnode = TNode::new(p_self);
tnode.lut = Some(ExtAwi::from(table));
tnode.lut = Some(Awi::from(table));
for p_inx in p_inxs {
let p_back = self
.backrefs
Expand Down Expand Up @@ -622,7 +622,7 @@ impl TDag {
Some(self.backrefs.get_val(p_back)?.val)
}

pub fn get_noted_as_extawi(&self, p_note: PNote) -> Result<ExtAwi, EvalError> {
pub fn get_noted_as_extawi(&self, p_note: PNote) -> Result<Awi, EvalError> {
if let Some(note) = self.notes.get(p_note) {
// avoid partially setting by prechecking validity of all bits
for p_bit in &note.bits {
Expand All @@ -636,7 +636,7 @@ impl TDag {
return Err(EvalError::OtherStr("broken note"))
}
}
let mut x = ExtAwi::zero(NonZeroUsize::new(note.bits.len()).unwrap());
let mut x = Awi::zero(NonZeroUsize::new(note.bits.len()).unwrap());
for (i, p_bit) in note.bits.iter().enumerate() {
let equiv = self.backrefs.get_val(*p_bit).unwrap();
let val = match equiv.val {
Expand Down
22 changes: 11 additions & 11 deletions starlight/src/temporal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{borrow::Borrow, num::NonZeroUsize, ops::Deref};

use awint::{
awint_dag::{Lineage, PState},
dag::{self, Bits, ExtAwi, InlAwi},
dag::{self, Awi, Bits, InlAwi},
};

/// Returned from `Loop::drive` and other structures like `Net::drive` that use
Expand All @@ -12,7 +12,7 @@ use awint::{
#[derive(Debug, Clone)] // TODO make Copy
pub struct LoopHandle {
// just use this for now to have the non-sendability
awi: ExtAwi,
awi: Awi,
}

impl Lineage for LoopHandle {
Expand All @@ -31,7 +31,7 @@ impl Lineage for LoopHandle {
#[derive(Debug)] // do not implement `Clone`, but maybe implement a `duplicate` function that
// explicitly duplicates drivers and loopbacks?
pub struct Loop {
awi: ExtAwi,
awi: Awi,
}

impl Loop {
Expand All @@ -40,7 +40,7 @@ impl Loop {
// TODO add flag on opaque for initial value, and a way to notify if the
// `LoopHandle` is not included in the graph
Self {
awi: ExtAwi::opaque(w),
awi: Awi::opaque(w),
}
}

Expand Down Expand Up @@ -112,16 +112,16 @@ impl AsRef<Bits> for Loop {
#[derive(Debug)]
pub struct Net {
driver: Loop,
initial: ExtAwi,
ports: Vec<ExtAwi>,
initial: Awi,
ports: Vec<Awi>,
}

impl Net {
/// Create a `Net` with an initial value of zero and bitwidth `w`
pub fn zero(w: NonZeroUsize) -> Self {
Self {
driver: Loop::zero(w),
initial: ExtAwi::zero(w),
initial: Awi::zero(w),
ports: vec![],
}
}
Expand Down Expand Up @@ -181,8 +181,8 @@ impl Net {
if self.bw() != rhs.bw() {
None
} else {
self.ports.push(ExtAwi::from(rhs.get()));
rhs.ports.push(ExtAwi::from(self.get()));
self.ports.push(Awi::from(rhs.get()));
rhs.ports.push(Awi::from(self.get()));
Some(())
}
}
Expand All @@ -206,9 +206,9 @@ impl Net {
inx.mux_(&last, gt).unwrap();

// TODO need an optimized onehot selector from `awint_dag`
let mut selector = ExtAwi::uone(NonZeroUsize::new(self.len()).unwrap());
let mut selector = Awi::uone(NonZeroUsize::new(self.len()).unwrap());
selector.shl_(inx.to_usize()).unwrap();
let mut tmp = ExtAwi::zero(self.nzbw());
let mut tmp = Awi::zero(self.nzbw());
for i in 0..self.len() {
tmp.mux_(self.get_mut(i).unwrap(), selector.get(i).unwrap())
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions starlight/src/tnode.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::num::NonZeroU64;

use awint::{awint_dag::smallvec, ExtAwi};
use awint::{awint_dag::smallvec, Awi};
use smallvec::SmallVec;

use crate::triple_arena::ptr_struct;
Expand All @@ -16,7 +16,7 @@ pub struct TNode {
pub inp: SmallVec<[PBack; 4]>,
/// Lookup Table that outputs one bit
// TODO make a SmallAwi
pub lut: Option<ExtAwi>,
pub lut: Option<Awi>,
// If the value cannot be temporally changed with respect to what the
// simplification algorithms can assume.
//pub is_permanent: bool,
Expand Down
34 changes: 17 additions & 17 deletions testcrate/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn _dbg(t_dag: &mut TDag) -> awi::Result<(), EvalError> {
#[test]
fn invert_twice() {
let epoch0 = StateEpoch::new();
let x = extawi!(opaque: ..1);
let x = awi!(opaque: ..1);
let mut y = x.clone();
y.not_();
let y_copy = y.clone();
Expand Down Expand Up @@ -47,18 +47,18 @@ fn invert_twice() {

t_dag.set_noted(p_x, &inlawi!(1)).unwrap();
t_dag.eval_all().unwrap();
assert_eq!(t_dag.get_noted_as_extawi(p_y).unwrap(), extawi!(1));
assert_eq!(t_dag.get_noted_as_extawi(p_y).unwrap(), awi!(1));
t_dag.set_noted(p_x, &inlawi!(0)).unwrap();
t_dag.eval_all().unwrap();
assert_eq!(t_dag.get_noted_as_extawi(p_y).unwrap(), extawi!(0));
assert_eq!(t_dag.get_noted_as_extawi(p_y).unwrap(), awi!(0));
}
}

#[test]
fn invert_in_loop() {
let epoch0 = StateEpoch::new();
let looper = Loop::zero(bw(1));
let mut x = extawi!(looper);
let mut x = awi!(looper);
let x_copy = x.clone();
x.lut_(&inlawi!(10), &x_copy).unwrap();
x.not_();
Expand Down Expand Up @@ -87,13 +87,13 @@ fn invert_in_loop() {
use awi::{assert_eq, *};

t_dag.eval_all().unwrap();
assert_eq!(t_dag.get_noted_as_extawi(p_x).unwrap(), extawi!(1));
assert_eq!(t_dag.get_noted_as_extawi(p_x).unwrap(), awi!(1));
t_dag.drive_loops();
t_dag.eval_all().unwrap();
assert_eq!(t_dag.get_noted_as_extawi(p_x).unwrap(), extawi!(0));
assert_eq!(t_dag.get_noted_as_extawi(p_x).unwrap(), awi!(0));
t_dag.drive_loops();
t_dag.eval_all().unwrap();
assert_eq!(t_dag.get_noted_as_extawi(p_x).unwrap(), extawi!(1));
assert_eq!(t_dag.get_noted_as_extawi(p_x).unwrap(), awi!(1));
}
}

Expand All @@ -102,8 +102,8 @@ fn invert_in_loop() {
fn incrementer() {
let epoch0 = StateEpoch::new();
let looper = Loop::zero(bw(4));
let val = ExtAwi::from(looper.as_ref());
let mut tmp = ExtAwi::from(looper.as_ref());
let val = Awi::from(looper.as_ref());
let mut tmp = Awi::from(looper.as_ref());
tmp.inc_(true);
looper.drive(&tmp).unwrap();

Expand Down Expand Up @@ -163,11 +163,11 @@ fn multiplier() {
t_dag.set_noted(input_a, inlawi!(123u16).as_ref());
t_dag.set_noted(input_b, inlawi!(77u16).as_ref());
t_dag.eval_all().unwrap();
std::assert_eq!(t_dag.get_noted_as_extawi(output).unwrap(), extawi!(9471u32));
std::assert_eq!(t_dag.get_noted_as_extawi(output).unwrap(), awi!(9471u32));

t_dag.set_noted(input_a, inlawi!(10u16).as_ref());
t_dag.eval_all().unwrap();
std::assert_eq!(t_dag.get_noted_as_extawi(output).unwrap(), extawi!(770u32));
std::assert_eq!(t_dag.get_noted_as_extawi(output).unwrap(), awi!(770u32));
}
}

Expand All @@ -180,12 +180,12 @@ fn luts() {
let lut_w = 1 << input_w;
for _ in 0..100 {
let epoch0 = StateEpoch::new();
let mut test_input = awi::ExtAwi::zero(bw(input_w));
let mut test_input = awi::Awi::zero(bw(input_w));
rng.next_bits(&mut test_input);
let original_input = test_input.clone();
let mut input = ExtAwi::opaque(bw(input_w));
let mut input = Awi::opaque(bw(input_w));
let input_state = input.state();
let mut opaque_set = awi::ExtAwi::umax(bw(input_w));
let mut opaque_set = awi::Awi::umax(bw(input_w));
for i in 0..input_w {
// randomly set some bits to a constant and leave some as opaque
if rng.next_bool() {
Expand All @@ -206,10 +206,10 @@ fn luts() {
}
}
}
let mut lut = awi::ExtAwi::zero(bw(lut_w));
let mut lut = awi::Awi::zero(bw(lut_w));
rng.next_bits(&mut lut);
let mut x = ExtAwi::zero(bw(1));
x.lut_(&ExtAwi::from(&lut), &input).unwrap();
let mut x = Awi::zero(bw(1));
x.lut_(&Awi::from(&lut), &input).unwrap();

let (mut op_dag, res) = OpDag::from_epoch(&epoch0);
res.unwrap();
Expand Down
29 changes: 29 additions & 0 deletions testcrate/tests/basic2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use starlight::{awi, dag::*, Epoch};

#[test]
fn auto() -> Option<()> {
let epoch0 = Epoch::new();

/*
// starts as an opaque, but when lazy eval happens it uses zero to start out
let mut x = AutoAwi::zero(bw(1));
// cannot get &mut Bits from x, only &Bits which autoevals each time it is called
let mut a = awi!(x);
a.not_();
let y = AutoAwi::from(&a);
// starts epoch optimization and reevaluates
awi::assert_eq!(y.to_extawi(), awi!(1));
// retroactively change the value that `x` was assigned with
x.retro_(&awi!(1)).unwrap();
awi::assert_eq!(y.eval(), &awi!(0));
*/

// cleans up everything not still used by `AutoAwi`s, `AutoAwi`s deregister
// notes when dropped
drop(epoch0);

Some(())
}
2 changes: 1 addition & 1 deletion testcrate/tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use starlight::{dag::*, Epoch};
#[test]
#[should_panic]
fn state_epoch_unregistered0() {
let _x = ExtAwi::zero(bw(1));
let _x = Awi::zero(bw(1));
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions testcrate/tests/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ptr_struct!(P0);

#[derive(Debug)]
struct Mem {
a: Arena<P0, dag::ExtAwi>,
a: Arena<P0, dag::Awi>,
// the outer Vec has 5 vecs for all supported bitwidths plus one dummy 0 bitwidth vec, the
// inner vecs are unsorted and used for random querying
v: Vec<Vec<P0>>,
Expand Down Expand Up @@ -54,9 +54,9 @@ impl Mem {
if try_query && (!self.v[w].is_empty()) {
self.v[w][(self.rng.next_u32() as usize) % self.v[w].len()]
} else {
let mut lit = awi::ExtAwi::zero(NonZeroUsize::new(w).unwrap());
let mut lit = awi::Awi::zero(NonZeroUsize::new(w).unwrap());
lit.rand_(&mut self.rng).unwrap();
let p = self.a.insert(dag::ExtAwi::from(lit.as_ref()));
let p = self.a.insert(dag::Awi::from(lit.as_ref()));
self.v[w].push(p);
p
}
Expand All @@ -67,7 +67,7 @@ impl Mem {
(w, self.next(w))
}

pub fn get_op(&self, inx: P0) -> dag::ExtAwi {
pub fn get_op(&self, inx: P0) -> dag::Awi {
self.a[inx].clone()
}

Expand Down
Loading

0 comments on commit 0172998

Please sign in to comment.