Skip to content

Add simplification rule for bitwise shifting#3580

Merged
chriseth merged 4 commits intodevelopfrom
asm-bitshift-optim
Apr 11, 2018
Merged

Add simplification rule for bitwise shifting#3580
chriseth merged 4 commits intodevelopfrom
asm-bitshift-optim

Conversation

@axic
Copy link
Contributor

@axic axic commented Feb 23, 2018

Depends on #2541.

@axic axic force-pushed the asm-bitshift-optim branch from d78fc1f to 255f7a5 Compare February 27, 2018 19:18
@axic axic mentioned this pull request Mar 2, 2018
1 task
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
Contributor 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
Contributor 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
Contributor 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
Contributor 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
Contributor

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
Contributor 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 axic force-pushed the asm-bitshift-optim branch from 255f7a5 to bb05038 Compare April 9, 2018 14:23
@axic axic force-pushed the asm-bitshift-optim branch from 5eb68e2 to 4fa6415 Compare April 9, 2018 19:08
@axic axic force-pushed the asm-bitshift-optim branch from 9685f89 to 2e73ef5 Compare April 10, 2018 14:30
@axic
Copy link
Contributor 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
Contributor

@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

Comments