Split comparison ops into "object" and "bit" versions. #190
Replies: 4 comments 1 reply
-
Why not introduce |
Beta Was this translation helpful? Give feedback.
-
Oh, it's because COMPARE has an oparg that indicates the comparison operation. (Though I don't recall why IS and CONTAINS aren't also encoded that way -- perhaps because they don't call into RichCompare?) |
Beta Was this translation helpful? Give feedback.
-
It is because |
Beta Was this translation helpful? Give feedback.
-
This proposal would only need 4 additional instructions (including We can encode the direction of the branch in the test. As Brandt says, the compiler can guarantee that the second instruction is |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Comparison operations are commonly followed by
POP_JUMP_IF_(TRUE|FALSE)
Would could split each
${compare}
opcode into${compare}_OBJECT
and${compare}_BIT
.{compare}
can be eitherCOMPARE_
andIS_
.The
${compare}_OBJECT
would behave as the current${compare}
.The
${compare}_BIT
form would perform the comparison, but instead of pushing the result of the comparison, would set some notional VM flag in the same way as a CISC processor does.Then we would then need two
BRANCH_IF_(TRUE|FALSE)
instructions and insist that${compare}_BIT
andBRANCH_IF_(TRUE|FALSE)
always form pairs:${compare}_BIT
must be followed byBRANCH_IF_(TRUE|FALSE)
BRANCH_IF_(TRUE|FALSE)
must be preceded by a${compare}_BIT
.We can then convert:
to
The implementation of
${compare}_BIT
can perform the jump as well, since it is guaranteed to be followed byBRANCH_IF_(TRUE|FALSE)
. This avoids the need to create the temporary boolean, and saves an instruction dispatch.We already specialize compare-branch pairs in a fairly ad-hoc way. Adding these new instructions will give a slight speed boost to unspecialized code and allow us to specialize compare-branch pairs in a less adhoc fashion.
Beta Was this translation helpful? Give feedback.
All reactions