Skip to content
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

WIP: optimisation of byte opcode #1303

Closed
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
20 changes: 17 additions & 3 deletions crates/interpreter/src/instructions/bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,24 @@ pub fn byte<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H) {
gas!(interpreter, gas::VERYLOW);
pop_top!(interpreter, op1, op2);

let o1 = as_usize_saturated!(op1);
let o1 = as_u64_saturated!(op1);
//const MAX_BYTE: u64 = 31;

*op2 = if o1 < 32 {
// `31 - o1` because `byte` returns LE, while we want BE
U256::from(op2.byte(31 - o1))
/*
number := z[4-1-number/8]
offset := (n[0] & 0x7) << 3 // 8*(n.d % 8)
z[0] = (number & (0xff00000000000000 >> offset)) >> (56 - offset)
z[3], z[2], z[1] = 0, 0, 0
return z
*/
// Calculate which byte to extract
// Calculate bit position for the byte extraction
let byte_index = (o1 * 8) as u64;
let shift_amount = 248 - byte_index;

// Shift the value down to the least significant byte and mask off the rest
(*op2 >> shift_amount) & U256::from(0xFF)
} else {
U256::ZERO
};
Expand Down
Loading