| |||
| Home > Using the Basic Linker Functionality > RW data compression > How is compression applied? | |||
Run-length compression encodes data as non-repeated bytes and repeated zero-bytes. Non-repeated bytes are output unchanged, followed by a count of zero-bytes. Limpel-Ziv 1977 (LZ77) compression keeps track of the last n bytes of data seen and, when a phrase is encountered that has already been seen, it outputs a pair of values corresponding to the position of the phrase in the previously-seen buffer of data, and the length of the phrase.
To specify a compressor, use the required ID on the linker command line, for example:
armlink --datacompressor 2 ...
When choosing a compressor be aware that:
Compressor 0 performs well on data with large areas of zero-bytes but few nonzero bytes.
Compressor 1 performs well on data where the nonzero bytes are repeating.
Compressor 2 performs well on data that contains repeated values.
The linker prefers compressor 0 or 1 where the data contains mostly zero-bytes (>75%). Compressor 2 is chosen where the data contains few zero-bytes (<10%). If the image is made up only of ARM code, then ARM decompressors are used automatically. If the image contains any Thumb code, Thumb decompressors are used. If there is no clear preference, all compressors are tested to produce the best overall size (see Choosing a compressor).
It is not possible to add your own compressors into the linker. The algorithms that are available, and how the linker chooses to use them, might change in the future.