Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfvi committed Mar 12, 2024
1 parent d183a84 commit 2b5d670
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/run/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@ impl Addr {

const HALF_MASK: usize = 0b1000;

/// TODO
/// Rounds this address down to be aligned to `align`.
#[inline(always)]
pub(super) fn floor(&self, align: Align) -> Self {
Addr(self.0 & (usize::MAX << align.tag_bits()))
}

/// TODO
/// Returns the other address of alignment `align` within alignment
/// `align.next()`.
#[inline(always)]
pub(super) fn other(&self, align: Align) -> Self {
Addr(self.0 ^ (1 << align.tag_bits()))
}

/// TODO
/// Offsets the address by a specified number of words.
#[inline(always)]
pub(super) fn offset(&self, words: usize) -> Self {
Addr(self.0 + (words << 3))
Expand Down
4 changes: 4 additions & 0 deletions src/run/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ use super::*;
/// net.link(aw, bw);
/// ```
///
/// ```js
/// let a =5;
/// ```
///
/// Each instruction documents both the native implementation and the polarity
/// of each `TrgId`.
///
Expand Down
1 change: 1 addition & 0 deletions src/run/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl<'a, M: Mode> Net<'a, M> {
let next = self.weak_normal(prev, root.clone());
trace!(self, "got", next);
if next.is_full_node() {
for i in 0 .. next.tag().arity() {}
todo!();
// visit.push(Port::new_var( next.addr()));
// visit.push(Port::new_var( next.addr().other_half()));
Expand Down
11 changes: 6 additions & 5 deletions src/run/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Port {

/// TODO
#[inline(always)]
pub fn new_adtz(variant_count: u8, variant_index: u8) -> Self {
pub const fn new_adtz(variant_count: u8, variant_index: u8) -> Self {

Check warning on line 87 in src/run/port.rs

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (adtz)
Port(Tag::AdtZ as u64 | ((variant_count as u64) << 16) | ((variant_index as u64) << 8))
}

Expand Down Expand Up @@ -112,11 +112,12 @@ impl Port {
unsafe { Tag::from_unchecked((self.0 & (1 << self.align().tag_bits()) - 1) as u8) }
}

/// TODO
/// Checks if this port is of the given `tag`.
#[inline(always)]
pub fn is(&self, tag: Tag) -> bool {
// TODO: optimize
self.tag() == tag
// This could be `self.tag() == tag`, but this is more efficient when `tag`
// is a constant.
(self.0 & ((1 << tag.align().tag_bits()) - 1)) as u8 == tag as u8
}

/// Accesses the label of this port; this is valid for all non-`Num` ports.
Expand Down Expand Up @@ -192,6 +193,6 @@ impl Port {
/// TODO
#[inline(always)]
pub(super) fn is_ctr_ish(&self) -> bool {
(self.0 * 0b111) > 0b100
(self.0 & 0b111) > 0b100
}
}
12 changes: 12 additions & 0 deletions src/run/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ impl Tag {
pub(super) fn align(self) -> Align {
unsafe { Align::from_unchecked(self as u8 & 0b11) }
}

/// Returns the width -- the size of the allocation -- of nodes of this tag.
#[inline]
pub(super) fn width(self) -> u8 {
match self {
Expand All @@ -58,6 +60,9 @@ impl Tag {
CtrN!() | AdtN!() => (1 << (self.align() as u8 - 1)) + 1 + (self as u8 >> 4),
}
}

/// Returns the arity -- the number of auxiliary ports -- of nodes of this
/// tag.
#[inline]
pub(super) fn arity(self) -> u8 {
match self {
Expand All @@ -67,12 +72,14 @@ impl Tag {
}
}

/// Matches any `Ctr` tag.
macro_rules! CtrN {
() => {
Tag::Ctr2 | Tag::Ctr3 | Tag::Ctr4 | Tag::Ctr5 | Tag::Ctr6 | Tag::Ctr7 | Tag::Ctr8
};
}

/// Matches any `Adt` tag except `AdtZ` (which is handled quite differently).
macro_rules! AdtN {
() => {
Tag::Adt2 | Tag::Adt3 | Tag::Adt4 | Tag::Adt5 | Tag::Adt6 | Tag::Adt7 | Tag::Adt8
Expand All @@ -84,6 +91,9 @@ pub(crate) use CtrN;

bi_enum! {
#[repr(u8)]
/// The alignment of an [`Addr`], measured in words.
///
/// The numeric representation of the alignment is `log2(align.width())`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub(crate) enum Align {
Align1 = 0b00,
Expand All @@ -96,6 +106,7 @@ bi_enum! {
pub(crate) use Align::*;

impl Align {
/// The number of bits available for tagging in addresses of this alignment.
#[inline(always)]
pub(super) fn tag_bits(self) -> u8 {
self as u8 + 3
Expand All @@ -104,6 +115,7 @@ impl Align {
pub(super) fn width(self) -> u8 {
1 << self as u8
}
/// Returns the next largest alignment, if it exists.
#[inline(always)]
pub(super) fn next(self) -> Option<Self> {
match self {
Expand Down

0 comments on commit 2b5d670

Please sign in to comment.