mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
add rules for mod(mul(X, Y), A) & mod(add(X, Y), A)
This commit is contained in:
parent
75300c32a8
commit
8c5f5c7db0
@ -279,7 +279,7 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart5(
|
||||
Pattern B,
|
||||
Pattern,
|
||||
Pattern X,
|
||||
Pattern
|
||||
Pattern Y
|
||||
)
|
||||
{
|
||||
using Word = typename Pattern::Word;
|
||||
@ -287,6 +287,24 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart5(
|
||||
|
||||
std::vector<SimplificationRule<Pattern>> rules;
|
||||
|
||||
// Replace MOD(MUL(X, Y), A) with MULMOD(X, Y, A) iff A=2**N
|
||||
rules.push_back({
|
||||
Builtins::MOD(Builtins::MUL(X, Y), A),
|
||||
[=]() -> Pattern { return Builtins::MULMOD(X, Y, A); },
|
||||
[=] {
|
||||
return A.d() > 0 && ((A.d() & (A.d() - 1)) == 0);
|
||||
}
|
||||
});
|
||||
|
||||
// Replace MOD(ADD(X, Y), A) with ADDMOD(X, Y, A) iff A=2**N
|
||||
rules.push_back({
|
||||
Builtins::MOD(Builtins::ADD(X, Y), A),
|
||||
[=]() -> Pattern { return Builtins::ADDMOD(X, Y, A); },
|
||||
[=] {
|
||||
return A.d() > 0 && ((A.d() & (A.d() - 1)) == 0);
|
||||
}
|
||||
});
|
||||
|
||||
// Replace MOD X, <power-of-two> with AND X, <power-of-two> - 1
|
||||
for (size_t i = 0; i < Pattern::WordSize; ++i)
|
||||
{
|
||||
|
@ -0,0 +1,13 @@
|
||||
{
|
||||
mstore(0, mod(add(mload(0), mload(1)), 32))
|
||||
}
|
||||
// ----
|
||||
// step: expressionSimplifier
|
||||
//
|
||||
// {
|
||||
// {
|
||||
// let _3 := mload(1)
|
||||
// let _4 := 0
|
||||
// mstore(_4, addmod(mload(_4), _3, 32))
|
||||
// }
|
||||
// }
|
@ -0,0 +1,13 @@
|
||||
{
|
||||
mstore(0, mod(mul(mload(0), mload(1)), 32))
|
||||
}
|
||||
// ----
|
||||
// step: expressionSimplifier
|
||||
//
|
||||
// {
|
||||
// {
|
||||
// let _3 := mload(1)
|
||||
// let _4 := 0
|
||||
// mstore(_4, mulmod(mload(_4), _3, 32))
|
||||
// }
|
||||
// }
|
Loading…
Reference in New Issue
Block a user