Le mar. 26 févr. 2019 à 23:40, Greg Ewing
<greg.ew...@canterbury.ac.nz> a écrit :
> Victor Stinner wrote:
> > LOAD_CONST_REG       R0, 2 (const#2)
> > LOAD_GLOBAL_REG      R1, 'range' (name#0)
> > CALL_FUNCTION_REG    4, R1, R1, R0, 'n'
>
> Out of curiosity, why is the function being passed twice here?

Ah, I should have explained that :-) The first argument of
CALL_FUNCTION_REG is the name of the register used to store the
result.

The compiler begins with using static single assignment form (SSA) but
then uses a register allocator to reduce the number of used registers.
Usually, at the end you have less than 5 registers for a whole
function.

Since R1 was only used to store the function before the call and isn't
used after, the R1 register can be re-used.

Using a different register may require an explicit "CLEAR_REG R1"
(decref the reference to the builtin range function) which is less
efficient.

Note: The CALL_FUNCTION instruction using the stack implicitly put the
result into the stack (and "pop" function arguments from the stack).

Victor
-- 
Night gathers, and now my watch begins. It shall not end until my death.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to