Skip to content

Commit d851bb9

Browse files
vai-mikarfabiobaltieri
authored andcommitted
modules: lz4: add configurability
- Add possibility to disable functions that use heap. This is to reduce code size and prevent accidental use of heap. - Add possibility to compile xxhash library, "Extremely Fast Hash algorithm" in. It might be sometimes needed as a standalone, but especially lz4frame requires it. - Add possibility to compile also hc and lz4frame modules. The config options include possibility to configure will heap or stack be used. Defaults are set according to lz4's current defaults. Signed-off-by: Miika Karanki <[email protected]>
1 parent 054d60f commit d851bb9

File tree

2 files changed

+123
-2
lines changed

2 files changed

+123
-2
lines changed

modules/lz4/CMakeLists.txt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,45 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
if(CONFIG_LZ4)
5-
65
set(LZ4_DIR ${ZEPHYR_CURRENT_MODULE_DIR})
76

87
zephyr_library()
98

109
zephyr_include_directories(${LZ4_DIR}/lib)
1110

11+
zephyr_library_compile_definitions_ifdef(CONFIG_LZ4_HEAPMODE_STACK
12+
LZ4_HEAPMODE=0
13+
)
14+
15+
zephyr_library_compile_definitions_ifdef(CONFIG_LZ4_DISABLE_DYNAMIC_MEMORY_ALLOCATION
16+
LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION
17+
)
18+
19+
zephyr_library_compile_definitions(
20+
LZ4_MEMORY_USAGE=${CONFIG_LZ4_MEMORY_USAGE}
21+
)
22+
1223
zephyr_library_sources(
1324
${LZ4_DIR}/lib/lz4.c
1425
)
1526

27+
zephyr_library_sources_ifdef(CONFIG_LZ4_HIGH_COMPRESSION_VARIANT
28+
${LZ4_DIR}/lib/lz4hc.c
29+
)
30+
31+
zephyr_library_compile_definitions_ifdef(CONFIG_LZ4HC_HEAPMODE_STACK
32+
LZ4HC_HEAPMODE=0
33+
)
34+
35+
zephyr_library_sources_ifdef(CONFIG_LZ4_XX_HASH
36+
${LZ4_DIR}/lib/xxhash.c
37+
)
38+
39+
zephyr_library_sources_ifdef(CONFIG_LZ4_FRAME_SUPPORT
40+
${LZ4_DIR}/lib/lz4frame.c
41+
)
42+
43+
zephyr_library_compile_definitions_ifdef(CONFIG_LZ4F_HEAPMODE_HEAP
44+
LZ4F_HEAPMODE=1
45+
)
1646
endif()

modules/lz4/Kconfig

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,99 @@
44
config ZEPHYR_LZ4_MODULE
55
bool
66

7-
config LZ4
7+
menuconfig LZ4
88
bool "Lz4 data compression and decompression"
99
help
1010
This option enables lz4 compression & decompression library
1111
support.
12+
if LZ4
13+
14+
config LZ4_MEMORY_USAGE
15+
int "Lz4 memory usage"
16+
range 10 20
17+
default 14
18+
help
19+
Increasing memory usage improves compression ratio, but usually at the
20+
cost of speed, due to cache locality. Memory usage 2^value (10 -> 1KB,
21+
12 -> 4KB, 20 -> 1MB).
22+
23+
config LZ4_DISABLE_DYNAMIC_MEMORY_ALLOCATION
24+
bool "Disable dynamic memory allocation"
25+
help
26+
Disable lz4 functions that use dynamic memory allocation functions.
27+
28+
choice LZ4_HEAPMODE
29+
prompt "How stateless compression functions allocate memory for their hash table"
30+
default LZ4_HEAPMODE_HEAP
31+
32+
config LZ4_HEAPMODE_STACK
33+
bool "in memory stack"
34+
help
35+
Allocate memory from stack (fastest).
36+
37+
config LZ4_HEAPMODE_HEAP
38+
bool "in memory heap"
39+
depends on !LZ4_DISABLE_DYNAMIC_MEMORY_ALLOCATION
40+
help
41+
Allocate memory from heap (requires malloc()).
42+
endchoice
43+
44+
config LZ4_HIGH_COMPRESSION_VARIANT
45+
bool "Lz4 high compression variant"
46+
help
47+
For more compression ratio at the cost of compression speed,
48+
the High Compression variant called lz4hc is available. This variant
49+
also compresses data using the lz4 block format.
50+
51+
if LZ4_HIGH_COMPRESSION_VARIANT
52+
choice LZ4HC_HEAPMODE
53+
prompt "How stateless HC compression functions allocate memory for their workspace"
54+
default LZ4HC_HEAPMODE_HEAP
55+
56+
config LZ4HC_HEAPMODE_STACK
57+
bool "in memory stack"
58+
help
59+
Allocate memory from stack (fastest).
60+
61+
config LZ4HC_HEAPMODE_HEAP
62+
bool "in memory heap"
63+
depends on !LZ4_DISABLE_DYNAMIC_MEMORY_ALLOCATION
64+
help
65+
Allocate memory from heap (requires malloc()).
66+
endchoice
67+
endif
68+
69+
config LZ4_XX_HASH
70+
bool "xxHash hashing algorithm"
71+
help
72+
Build xxHash library included in lz4 sources.
73+
74+
config LZ4_FRAME_SUPPORT
75+
bool "LZ4 frame support"
76+
select LZ4_XX_HASH
77+
select LZ4_HIGH_COMPRESSION_VARIANT
78+
help
79+
In order to produce compressed data compatible with lz4 command line
80+
utility, it's necessary to use the official interoperable frame format.
81+
This format is generated and decoded automatically by the lz4frame library.
82+
Its public API is described in lib/lz4frame.h.
83+
84+
if LZ4_FRAME_SUPPORT
85+
choice LZ4F_HEAPMODE
86+
prompt "Control how LZ4F_compressFrame() allocates the Compression State"
87+
default LZ4F_HEAPMODE_STACK
88+
89+
config LZ4F_HEAPMODE_STACK
90+
bool "in memory stack"
91+
help
92+
Allocate memory from stack (fastest).
93+
94+
config LZ4F_HEAPMODE_HEAP
95+
bool "in memory heap"
96+
depends on !LZ4_DISABLE_DYNAMIC_MEMORY_ALLOCATION
97+
help
98+
Allocate memory from heap (requires malloc()).
99+
endchoice
100+
endif
101+
102+
endif

0 commit comments

Comments
 (0)