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

Shortcut for 2^e #233

Closed
wants to merge 2 commits into from
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
12 changes: 11 additions & 1 deletion lib/evmone/instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,17 @@ const instruction* op_exp(const instruction* instr, execution_state& state) noex
if ((state.gas_left -= additional_cost) < 0)
return state.exit(EVMC_OUT_OF_GAS);

exponent = intx::exp(base, exponent);
if (base == 2 && exponent < 256)
{
auto exp_bytes = as_bytes(exponent);
uint8_t bit_to_set = exp_bytes[0];
exp_bytes[0] = 0;
exp_bytes[bit_to_set >> 3] = uint8_t(uint8_t(1) << (bit_to_set & 7));
Copy link
Member

Choose a reason for hiding this comment

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

Why not something like exponent = 2 << exponent; ?

@chfast would either of these solutions have a significant speed difference?

Copy link
Member

Choose a reason for hiding this comment

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

Looks like at least in my benchmarks the 1 << exponent is the fastest (surprisingly). Full story in chfast/intx#146.

}
else
{
exponent = intx::exp(base, exponent);
}
return ++instr;
}

Expand Down