![]() When a literal is used on the left-hand side of a numeric operator, Python is able to constant-fold some expressions: >>> dis.dis(lambda x: 0 + 0 + x) 1 0 LOAD_CONST 1 (0) 2 LOAD_FAST 0 (x) 4 BINARY_ADD 6 RETURN_VALUE If a literal is used on the right-hand side such that the left-hand side is variable, this doesn't happen: >>> dis.dis(lambda x: x + 0 + 0) 1 0 LOAD_FAST 0 (x) 2 LOAD_CONST 1 (0) 4 BINARY_ADD 6 LOAD_CONST 1 (0) 8 BINARY_ADD 10 RETURN_VALUE PyRTL generates fairly redundant code due to the pervasive masking, and because of that, transforming expressions into the former form, where possible, improves runtime by about 10% on Minerva SRAM SoC. |
||
---|---|---|
.. | ||
__init__.py | ||
_cmds.py | ||
_core.py | ||
_pycoro.py | ||
_pyrtl.py | ||
pysim.py |