Skip to content

Commit 0a70f32

Browse files
committed
realtek: rt-loader: use -O2 with selective LZMA inlining
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: openwrt/openwrt#25813 Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
1 parent 1daf141 commit 0a70f32

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎target/linux/realtek/image/rt-loader/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ LD := $(CROSS_COMPILE)ld
7373
OBJCOPY := $(CROSS_COMPILE)objcopy
7474
OBJDUMP := $(CROSS_COMPILE)objdump
7575

76-
CFLAGS = -fpic -mabicalls -O3 -fno-builtin-printf -Iinclude
76+
CFLAGS = -fpic -mabicalls -O2 -fno-builtin-printf -Iinclude
7777
CFLAGS += -DFLASH_ADDR=$(FLASH_ADDR)
7878
CFLAGS += -DKERNEL_ADDR=$(KERNEL_ADDR)
7979

‎target/linux/realtek/image/rt-loader/src/unlzma.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static inline void rc_init_code(struct rc *rc)
124124

125125

126126
/* Called twice, but one callsite is in inline'd rc_is_bit_0_helper() */
127-
static void rc_do_normalize(struct rc *rc)
127+
static __attribute__((noinline)) void rc_do_normalize(struct rc *rc)
128128
{
129129
if (rc->ptr >= rc->buffer_end)
130130
rc_read(rc);
@@ -167,7 +167,7 @@ static inline void rc_update_bit_1(struct rc *rc, uint16_t *p)
167167
}
168168

169169
/* Called 4 times in unlzma loop */
170-
static int rc_get_bit(struct rc *rc, uint16_t *p, int *symbol)
170+
static inline int rc_get_bit(struct rc *rc, uint16_t *p, int *symbol)
171171
{
172172
if (rc_is_bit_0(rc, p)) {
173173
rc_update_bit_0(rc, p);

0 commit comments

Comments
 (0)