Skip to content
New issue

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

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

Already on GitHub? # to your account

Shortcut for 2^e #233

Closed
wants to merge 2 commits into from
Closed

Conversation

AlexeyAkhunov
Copy link

@AlexeyAkhunov AlexeyAkhunov commented May 6, 2020

There are a lot of contracts on the Ethereum mainnet that were compiled with Solidity prior to the shifting operations were available. For those, exponentiation 2^160 is used to emulate 1<<160. Measurements performed on turbo-geth confirm this. Since we are planning to integrate evmone into turbo-geth, and we have already implemented this shortcut (erigontech/erigon#505), it would be good to maintain that in evmone.

For #231

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.

@chfast
Copy link
Member

chfast commented Jun 12, 2020

Yes, this makes sense, but I think I will move to the implementation of intx::exp()...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants