-
Notifications
You must be signed in to change notification settings - Fork 53
Single instruction "superinstructions" #585
Description
Superinstructions can be problematic, as they break the one-instruction-at-a-time model that instrumentation relies on, and are likely to cause problems in optimizers that make the same one-instruction-at-a-time assumption.
Instrumentation rewrites all superinstructions back to the simpler form.
Super instructions also prevent specialization, so superinstructions cannot include any specializable instruction.
#584 proposes a specialization of LOAD_CONST, so that leaves only LOAD_FAST and STORE_FAST to be combined.
If we remove LOAD_CONST we have only:
super(LOAD_FAST__LOAD_FAST) = LOAD_FAST + LOAD_FAST;
super(STORE_FAST__LOAD_FAST) = STORE_FAST + LOAD_FAST;
super(STORE_FAST__STORE_FAST) = STORE_FAST + STORE_FAST;
That is still quite a lot of instructions, dynamically, so we don't want to just remove them.
Instead of removing them, we can combine them into a single instruction.
Given that most locals will have a index in range(16) we combine the operations into a single instruction.
inst(LOAD_FAST_LOAD_FAST_COMPACT, ( -- val1, val2)) {
val1 = GETLOCAL(oparg&15);
val1 = GETLOCAL(oparg>>4);
Py_INCREF(val1);
Py_INCREF(val2);
}
There will be fewer LOAD_FAST_LOAD_FAST_COMPACT than LOAD_FAST__LOAD_FAST, but they should be a little faster (fewer memory reads). I would expect the performance to be about the same.