mirror of
https://github.com/openwrt/openwrt.git
synced 2026-10-22 19:37:51 +04:00
Build rt-loader with -O2 and tune the LZMA decoder's inlining decisions to balance code size and decompression performance. The existing -O3 setting applies to all loader C sources. In the standalone decoder comparison used to investigate this change, -O3 substantially increased the generated code size. Simply switching to -O2 reduced that footprint, but left the frequently used rc_get_bit() helper out of line, adding function-call and stack-access overhead throughout range decoding. Adjust the two helpers independently: - Declare rc_get_bit() inline to encourage integration into its callers. This lets the compiler eliminate call overhead and optimise accesses to the range-coder state, probability values and decoded symbols. - Mark rc_do_normalize() noinline to retain a shared implementation of the conditional normalisation path. This limits code duplication as the surrounding bit-decoding helpers are inlined. Use the inline keyword rather than always_inline for rc_get_bit(). With the tested compiler, forcing this helper to inline provided no additional benefit over the simpler declaration. A standalone comparison with GCC 13.2.0 targeting MIPS32r2/34Kc used the same synthetic 1 MiB LZMA stream, producing 4 MiB of output. A generic single-issue in-order model with a 32 KiB instruction cache and a 16 KiB data cache produced the following results: - Original -O2: 4,960 bytes of decoder .text; 548,160,936 model cycles. - Modified -O2: 4,960 bytes of decoder .text; 389,069,748 model cycles. - Original -O3: 10,496 bytes of decoder .text; 336,140,240 model cycles. In that setup, the modified -O2 decoder retains approximately 75% of the cycle reduction achieved by -O3 while using 52.7% less code. It requires 15.7% more model cycles than -O3. Compared with unmodified -O2, it reduces model cycles by 29.0% without increasing code size. All compared variants produced byte-identical output. These figures describe the standalone decoder experiment, not measured Realtek hardware performance. The experiment used -fno-pic and -mno-abicalls; rt-loader retains -fpic and -mabicalls. Actual loader size and boot-time effects therefore require validation with the target build and hardware. The patch changes the optimisation level for the whole loader and the inlining policy of these two decoder helpers. It leaves the decompression algorithm, bitstream format and error-handling logic unchanged. Assisted-by: ChatGPT (OpenAI GPT-6 Astra) Link: https://github.com/openwrt/openwrt/pull/25813 Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>