Skip to content
Merged
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
9 changes: 1 addition & 8 deletions src/data/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,8 @@ impl IntLayout {
}

/// Returns whether a `usize`-value fits the layout dimensions.
///
/// # Panics
///
/// Panics on platforms where usize is less than `u64`
pub fn fits_usize(self, value: usize) -> bool {
(self.bytes() <= 8 && value > u64::MAX as usize)
|| (self.bytes() <= 4 && value > u32::MAX as usize)
|| (self.bytes() <= 2 && value > u16::MAX as usize)
|| (self.bytes() <= 1 && value > u8::MAX as usize)
self.bits() >= (usize::BITS - value.leading_zeros()) as u16
}
}

Expand Down
19 changes: 8 additions & 11 deletions src/isa/instr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,18 +644,15 @@ pub enum BytesOp {
///
/// If the string register is empty, or destination register can't fit the length, sets `st0`
/// to `false` and destination register to `None`.
#[display("len {0},{1}{2}")]
#[display("len {1}{2},{0}")]
Len(/** `s` register index */ RegS, RegA, Reg32),

/// Count number of byte occurrences from the `a8` register within the string and stores that
/// value into destination `a16` register.
///
/// If the string register is empty, or destination register can't fit the length, sets `st0`
/// to `false` and destination register to `None`.
///
/// If the source byte value register is uninitialized, sets destination register to `None` and
/// `st0` to `false`.
#[display("cnt {0},a8{1},a16{2}")]
/// If the string register is empty, or the source byte value register is uninitialized, sets
/// `st0` to `false` and destination register to `None`.
#[display("cnt a16{2},{0},a8{1}")]
Cnt(
Comment on lines 645 to 656
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unlike len, the return value cannot overflow the destination register which is always a16 in cnt

/** `s` register index */ RegS,
/** `a8` register with the byte value */ Reg16,
Expand All @@ -669,15 +666,15 @@ pub enum BytesOp {
Eq(RegS, RegS),

/// Compute offset and length of the `n`th fragment shared between two strings ("conjoint
/// fragment"), putting it to the destination `u16` registers. If strings have no conjoint
/// fragment"), putting it to the destination `a16` registers. If strings have no conjoint
/// fragment sets destination to `None`.
#[display("con {0},{1},a16{2},u16{3},u16{4}")]
#[display("con a16{3},a16{4},{0},{1},a16{2}")]
Con(
/** First source string register */ RegS,
/** Second source string register */ RegS,
/** Index of the conjoint fragment to match */ Reg32,
/** `u16` register index to save the offset of the conjoint fragment */ Reg32,
/** `u16` register index to save the length of the conjoint fragment */ Reg32,
/** `a16` register index to save the offset of the conjoint fragment */ Reg32,
/** `a16` register index to save the length of the conjoint fragment */ Reg32,
),

/// Count number of occurrences of one string within another putting result to `a16[1]`,
Expand Down
6 changes: 5 additions & 1 deletion src/library/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ where
// We write the value only if the value is not yet present in the data segment
let len = bytes.len();
let offset = self.data.as_ref().len();
if let Some(offset) = self.data.as_ref().windows(len).position(|window| window == bytes) {
if len == 0 {
Ok(offset as u16)
} else if let Some(offset) =
self.data.as_ref().windows(len).position(|window| window == bytes)
{
Ok(offset as u16)
} else if offset + len > DATA_SEGMENT_MAX_LEN {
Err(WriteError::DataNotFittingSegment)
Expand Down