mirror of
https://github.com/licsber/micropython.git
synced 2024-09-20 09:00:23 +08:00
b5ebfadbd6
The start of the bytecode prelude contains 6 numbers telling the amount of stack needed for the Python values and exceptions, and the signature of the function. Prior to this patch these numbers were all encoded one after the other (2x variable unsigned integers, then 4x bytes), but using so many bytes is unnecessary. An entropy analysis of around 150,000 bytecode functions from the CPython standard library showed that the optimal Shannon coding would need about 7.1 bits on average to encode these 6 numbers, compared to the existing 48 bits. This patch attempts to get close to this optimal value by packing the 6 numbers into a single, varible-length unsigned integer via bit-wise interleaving. The interleaving scheme is chosen to minimise the average number of bytes needed, and at the same time keep the scheme simple enough so it can be implemented without too much overhead in code size or speed. The scheme requires about 10.5 bits on average to store the 6 numbers. As a result most functions which originally took 6 bytes to encode these 6 numbers now need only 1 byte (in 80% of cases). |
||
---|---|---|
.. | ||
pkg | ||
pkg2 | ||
pkg3 | ||
pkg6 | ||
pkg7 | ||
pkg8 | ||
builtin_import.py | ||
gen_context2.py | ||
gen_context.py | ||
import1a.py | ||
import1b.py | ||
import2a.py | ||
import3a.py | ||
import_file.py | ||
import_long_dyn2.py | ||
import_long_dyn.py | ||
import_override.py | ||
import_pkg1.py | ||
import_pkg2.py | ||
import_pkg3.py | ||
import_pkg4.py | ||
import_pkg5.py | ||
import_pkg6.py | ||
import_pkg7.py | ||
import_pkg8.py | ||
module_getattr.py | ||
module_getattr.py.exp | ||
mpy_invalid.py | ||
mpy_invalid.py.exp | ||
mpy_native.py | ||
mpy_native.py.exp | ||
rel_import_inv.py | ||
try_module.py |