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
23 changes: 9 additions & 14 deletions src/isa/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,17 +669,8 @@ impl InstructionSet for BytesOp {
let (s1, s2) = regs.get_both_s(*reg1, *reg2)?;
let r1 = s1.as_ref();
let r2 = s2.as_ref();
let len = r2.len();
let mut count = 0usize;
for i in 0..r1.len() {
if r1[i..len] == r2[..len] {
count += 1;
}
}
if count > u16::MAX as usize {
regs.st0 = false;
count -= 1;
}
let count = r1.windows(r2.len()).filter(|r1| *r1 == r2).count();
assert!(count <= u16::MAX as usize);
regs.set(RegA::A16, Reg32::Reg0, count as u16);
Some(())
};
Expand All @@ -698,7 +689,7 @@ impl InstructionSet for BytesOp {
};
f().unwrap_or_else(|| {
regs.st0 = false;
regs.set(RegA::A16, Reg32::Reg0, MaybeNumber::none());
Copy link
Member

Choose a reason for hiding this comment

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

Why are we removing this if the spec below says

If the first or the second string is `None`, sets `st0` to `false` and `a16[0]` to `None`.

Copy link
Contributor Author

@6293 6293 Jun 26, 2023

Choose a reason for hiding this comment

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

this is the spec for Find. The code here is for Rev. I thought this was accidentally copy-pasted from Find above

Copy link
Member

Choose a reason for hiding this comment

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

Yet still the Rev must reset the destination to the uninitialized state:

/// If the source string register is uninitialized, resets destination to the uninitialized

So I assume the above line should stay and be changed to

Suggested change
regs.set(RegA::A16, Reg32::Reg0, MaybeNumber::none());
regs.s16[reg2.as_usize()] = None;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true

regs.s16[reg2.as_usize()] = None;
})
}
BytesOp::Con(reg1, reg2, n, offset_dst, len_dst) => {
Expand Down Expand Up @@ -822,8 +813,12 @@ impl InstructionSet for DigestOp {
DigestOp::Ripemd(src, dst) => {
let s = regs.get_s(*src);
none = s.is_none();
let hash: Option<[u8; 20]> =
s.map(|s| ripemd::Ripemd160::digest(s.as_ref()).into());
let hash = s.map(|s| {
let mut hash: [u8; 20] = ripemd::Ripemd160::digest(s.as_ref()).into();
// RIPEMD-160 is big-endian
hash.reverse();
hash
});
regs.set(RegR::R160, dst, hash);
}
DigestOp::Sha256(src, dst) => {
Expand Down
9 changes: 3 additions & 6 deletions src/isa/instr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,13 +677,10 @@ pub enum BytesOp {
/** `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]`,
/// Count number of occurrences of one string within another putting result to `a16[0]`,
///
/// If the first or the second string is `None`, sets `st0` to `false` and `a16[1]` to `None`.
///
/// If the number of occurrences is `u16::MAX + 1`, sets `a16[1]` to `u16::MAX` and `st0` to
/// `false`.
#[display("find {0},{1},a16[1]")]
/// If the first or the second string is `None`, sets `st0` to `false` and `a16[0]` to `None`.
#[display("find a16[0],{0},{1}")]
Find(/** `s` register with string */ RegS, /** `s` register with matching fragment */ RegS),

/// Extract byte string slice into general `r` register. The length of the extracted string is
Expand Down