Skip to content

Commit

Permalink
perf(interpreter): don't run signextend with 31 too (#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Mar 25, 2024
1 parent 240e559 commit 176e0cf
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions crates/interpreter/src/instructions/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ pub fn exp<H: Host, SPEC: Spec>(interpreter: &mut Interpreter, _host: &mut H) {
/// bits from `b`; this is equal to `y & mask` where `&` is bitwise `AND`.
pub fn signextend<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
gas!(interpreter, gas::LOW);
pop_top!(interpreter, op1, op2);
if op1 < U256::from(32) {
// `low_u32` works since op1 < 32
let bit_index = (8 * op1.as_limbs()[0] + 7) as usize;
let bit = op2.bit(bit_index);
pop_top!(interpreter, ext, x);
// For 31 we also don't need to do anything.
if ext < U256::from(31) {
let ext = ext.as_limbs()[0];
let bit_index = (8 * ext + 7) as usize;
let bit = x.bit(bit_index);
let mask = (U256::from(1) << bit_index) - U256::from(1);
*op2 = if bit { *op2 | !mask } else { *op2 & mask };
*x = if bit { *x | !mask } else { *x & mask };
}
}

0 comments on commit 176e0cf

Please sign in to comment.