Skip to content

Simplify pop_cnt() #770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 5, 2025
Merged
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
17 changes: 4 additions & 13 deletions crates/interpreter/src/valid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,21 +1152,12 @@ fn delta(
}

fn pop_cnt(source: SideTableBranch, target: SideTableBranch) -> MResult<u32, Check> {
let source = source.stack;
// TODO(dev/fast-interp): Figure out why we can't simply source.stack - target.stack and
// document it.
let target_without_result = target.stack - target.result;
let Some(delta) = source.checked_sub(target_without_result) else {
// document it. We're losing information by saturating.
let res = source.stack.saturating_sub(target.stack);
u32::try_from(res).map_err(|_| {
#[cfg(feature = "debug")]
eprintln!("side-table negative stack delta {source} - {target_without_result}");
return Err(unsupported(if_debug!(Unsupported::SideTable)));
};
if delta < target.result {
return Ok(0);
}
u32::try_from(delta - target.result).map_err(|_| {
#[cfg(feature = "debug")]
eprintln!("side-table pop_cnt overflow {delta}");
eprintln!("side-table pop_cnt overflow {res}");
unsupported(if_debug!(Unsupported::SideTable))
})
}
Loading