-
Notifications
You must be signed in to change notification settings - Fork 49
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
Making conversions to booleans in jumps explicit. #568
Comments
@brandtbucher I think we discussed adding something like |
Update: I don't know if there was a discussion, but I'm experimenting with this now at the sprints. Note that we probably get an even bigger win from this now, since My approach is going to be to prefix all conditional jumps (with a non-guaranteed-bool) with Then we can specialize (We could also specialize the two jumps themselves if the extra overhead from |
Did this ever produce any results? @brandtbucher |
Still in progress. So no, but maybe. I have a branch where all of the conditional jumps require an exact bool, and are prefixed by |
We could change inst(POP_JUMP_IF_FALSE, (cond -- )) {
JUMPBY(oparg * _PyLong_IsZero(cond));
} Should save a specialization, and speedup tests on ints. |
The stats suggest this probably isn't worth it. |
This is now complete. Thanks @brandtbucher |
POP_JUMP_IF_TRUE
andPOP_JUMP_IF_FALSE
implicitly convert their argument to a boolean before choosing which way to branch."Explicit is better than implicit"
If we make the conversion explicit:
POP_JUMP_IF_TRUE
becomesTO_BOOL; POP_JUMP_IF_IS_TRUE
Where
TO_BOOL
converts TOS to a boolean andPOP_JUMP_IF_IS_TRUE
performs the jump:TO_BOOL
should specialize nicely.Compare-and-branch
Now consider how this combines with compares:
Now, all of the current specializations, and almost all of the possible specializations of
COMPARE_OP
produce a boolean value.We take advantage of that by combining
COMPARE_OP
andTO_BOOL
by using remaining bit of the oparg to indicate whether we should convert the result to a boolean:The above version of
COMPARE_OP
specializes as effectively as before, removes the bool conversion fromPOP_JUMP_IF_TRUE
and makes the conversion tobool
explicit, which should help specialization.The text was updated successfully, but these errors were encountered: