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

Add simplification rule for bitwise shifting #3580

Merged
merged 4 commits into from
Apr 11, 2018
Merged

Conversation

axic
Copy link
Member

@axic axic commented Feb 23, 2018

Depends on #2541.

@axic axic mentioned this pull request Mar 2, 2018
1 task
@@ -89,6 +89,16 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleList(
u256 mask = (u256(1) << testBit) - 1;
return u256(boost::multiprecision::bit_test(B.d(), testBit) ? B.d() | ~mask : B.d() & mask);
}, false},
{{Instruction::SHL, {A, B}}, [=]{
Copy link
Member Author

Choose a reason for hiding this comment

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

@chriseth do we want to introduce evmVersion in the rule list or is it safe to have this merged (after some cleanup/squashing)?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be safe. Let's add a comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure about the order of the operands?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a test.

Copy link
Contributor

Choose a reason for hiding this comment

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

(is that possible?)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is blocked by the same problem as in #3797: need to build a constantinople supporting version of eth and run endtoend tests with that target.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you sure about the order of the operands?

The top of the stack is the number of bits to shift he value with.

@axic
Copy link
Member Author

axic commented Apr 5, 2018

@pirapira can you check this, since you have written tests for shifts?

@axic axic requested a review from pirapira April 5, 2018 15:18
{{Instruction::SHR, {A, B}}, [=]{
if (A.d() > 255)
return u256(0);
return B.d() >> unsigned(A.d());
Copy link
Member

Choose a reason for hiding this comment

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

Is B.d() signed or unsigned? If signed, can it be negative?

Copy link
Contributor

Choose a reason for hiding this comment

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

It always returns u256.

Copy link
Member Author

Choose a reason for hiding this comment

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

SHR always considers B as unsigned. There is no optimisation rule adde for SAR as I was lazy.

@axic
Copy link
Member Author

axic commented Apr 10, 2018

@chfast @pirapira do you want to double check the expectations in the endtoend tests?

@chriseth this should be ready to merge

@axic axic changed the title [WIP] Add simplification rule for bitwise shifting Add simplification rule for bitwise shifting Apr 10, 2018
Copy link
Member

@chfast chfast left a comment

Choose a reason for hiding this comment

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

For constants this is ok.
What was the other one what tried to optimize division?

@chriseth chriseth merged commit d50d1f0 into develop Apr 11, 2018
@axic axic deleted the asm-bitshift-optim branch April 11, 2018 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants