forked from jasder/antlr
Restrict bitwise comparisons to sets with at least 3 elements (direct equality is cheaper for 1-2 elements)
This commit is contained in:
parent
88dbee6352
commit
7c5ec45054
|
@ -453,7 +453,7 @@ Sync(s) ::= "sync(<s.expecting.name>);"
|
||||||
ThrowNoViableAlt(t) ::= "throw new NoViableAltException(this);"
|
ThrowNoViableAlt(t) ::= "throw new NoViableAltException(this);"
|
||||||
|
|
||||||
TestSetInline(s) ::= <<
|
TestSetInline(s) ::= <<
|
||||||
<s.bitsets:{bits | <testShiftInRange({<s.varName> - <bits.shift>})> && ((1L \<\< (<s.varName> - <bits.shift>)) & (<bits.ttypes:{ttype | (1L \<\< (<ttype> - <bits.shift>))}; separator=" | ">)) != 0}; separator=" || ">
|
<s.bitsets:{bits | <if(rest(rest(bits.ttypes)))><bitsetBitfieldComparison(s, bits)><else><bitsetInlineComparison(s, bits)><endif>}; separator=" || ">
|
||||||
>>
|
>>
|
||||||
|
|
||||||
// Java language spec 15.19 - shift operators mask operands rather than overflow to 0... need range test
|
// Java language spec 15.19 - shift operators mask operands rather than overflow to 0... need range test
|
||||||
|
@ -461,6 +461,16 @@ testShiftInRange(shiftAmount) ::= <<
|
||||||
((<shiftAmount>) & ~0x3f) == 0
|
((<shiftAmount>) & ~0x3f) == 0
|
||||||
>>
|
>>
|
||||||
|
|
||||||
|
// produces smaller bytecode only when bits.ttypes contains more than two items
|
||||||
|
bitsetBitfieldComparison(s, bits) ::= <%
|
||||||
|
(<testShiftInRange({<s.varName> - <bits.shift>})> && ((1L \<\< (<s.varName> - <bits.shift>)) & (<bits.ttypes:{ttype | (1L \<\< (<ttype> - <bits.shift>))}; separator=" | ">)) != 0)
|
||||||
|
%>
|
||||||
|
|
||||||
|
// produces more efficient bytecode when bits.ttypes contains at most two items
|
||||||
|
bitsetInlineComparison(s, bits) ::= <%
|
||||||
|
<bits.ttypes:{ttype | <s.varName>==<ttype>}; separator=" || ">
|
||||||
|
%>
|
||||||
|
|
||||||
cases(ttypes) ::= <<
|
cases(ttypes) ::= <<
|
||||||
<ttypes:{t | case <t>:}; separator="\n">
|
<ttypes:{t | case <t>:}; separator="\n">
|
||||||
>>
|
>>
|
||||||
|
|
Loading…
Reference in New Issue