Abstract
This paper presents a novel code compression framework for memory-constrained embedded systems that leverages the program's Control Flow Graph (CFG). By utilizing a predictive $k$-edge algorithm, the system manages the compression and decompression of individual basic blocks at runtime. This approach allows for dynamic memory optimization by keeping only the currently relevant code segments decompressed, effectively balancing memory footprint and execution performance through multi-threaded execution.
Introduction
Embedded systems frequently operate under severe memory limitations, necessitating efficient code compression techniques. Traditional methods are often "application-insensitive," applying uniform strategies regardless of runtime program behavior. This research identifies a significant opportunity in predicting execution paths: since not all code is required simultaneously, maintaining the majority of a program in a compressed state can drastically reduce the memory footprint. The challenge lies in performing "just-in-time" decompression without creating execution bottlenecks.
Methodology: The $k$-edge Algorithm
The proposed system operates at the granularity of basic blocks—straight-line sequences of instructions. This fine-grained approach allows for tighter memory management compared to function-level compression. The core logic is driven by the $k$-edge algorithm, which acts as a tunable parameter for the system.
Under this algorithm, a basic block is compressed once the execution thread has moved $k$ edges away from it. Conversely, a block is decompressed when it falls within a $k$-edge distance of the current execution point. This mechanism transforms code compression into a tunable system parameter, allowing developers to balance aggressive memory savings against performance overhead.
System Architecture and Multi-threading
To mitigate the latency inherent in software-based decompression, the authors propose a multi-threaded management system. Three concurrent threads shadow the execution:
- Execution Thread: Runs the application code.
- Decompression Thread: Stays $k$ edges ahead of the execution point, pre-emptively preparing blocks.
- Compression Thread: Follows $k$ edges behind, re-compressing used blocks to free memory.
Decompression Strategies
The system must account for branching within the CFG to ensure the correct blocks are available when needed.
The authors outline three primary strategies:
- On-Demand (Lazy): Decompression occurs only when the program counter hits a compressed block. While simple, this can lead to execution stalls.
- Pre-decompress-all: Every possible path within $k$ edges is decompressed. This ensures high performance but increases memory usage.
- Pre-decompress-single: Leverages branch prediction to decompress only the most likely subsequent block, offering a balanced trade-off.
Implementation and Discussion
Implementation requires real-time patching of branch targets as blocks are moved or decompressed, managed via a "remember set." A notable limitation is potential memory fragmentation. The authors propose mitigating this by maintaining a permanent compressed image and utilizing a dedicated scratch-pad memory for active decompressed blocks.
While the provided text focuses on the conceptual framework rather than specific quantitative benchmarks, it establishes that this CFG-centric approach can reduce memory requirements without excessive increases in instruction cycle counts. Future work suggests using the reclaimed memory to enable smaller hardware footprints or to reduce energy consumption in banked memory architectures.
Summary updated