@@ -13,9 +13,12 @@ openresty/luajit2 - OpenResty's maintained branch of LuaJIT.
1313 * [ table.nkeys] ( #tablenkeys )
1414 * [ table.clone] ( #tableclone )
1515 * [ jit.prngstate] ( #jitprngstate )
16+ * [ jit.crc32] ( #jitcrc32 )
17+ * [ jit.strhashcrc32] ( #jitstrhashcrc32 )
1618 * [ thread.exdata] ( #threadexdata )
1719 * [ New macros] ( #new-macros )
1820 * [ ` OPENRESTY_LUAJIT ` ] ( #openresty-luajit )
21+ * [ ` LJ_OR_DISABLE_STRHASHCRC32 ` ] ( #lj-or-disable-strhashcrc32 )
1922 * [ Optimizations] ( #optimizations )
2023 * [ Updated JIT default parameters] ( #updated-jit-default-parameters )
2124 * [ String hashing] ( #string-hashing )
@@ -155,6 +158,45 @@ local newstate = jit.prngstate(123456)
155158
156159[ Back to TOC] ( #table-of-contents )
157160
161+ ### jit.crc32
162+
163+ ** syntax:** * ok = jit.crc32()*
164+
165+ Returns a boolean value indicating if the current architecture supports a CRC32
166+ instruction set. CRC32 support will be checked at runtime on x64 and ARM64
167+ platforms.
168+
169+ CRC32 support allows for this branch to use an optimized string hashing
170+ algorithm. See the [ String hashing] ( #string-hashing ) section for details on
171+ how to enable this optimization.
172+
173+ Usage:
174+
175+ ``` lua
176+ local ok = jit .crc32 ()
177+ ```
178+
179+ [ Back to TOC] ( #table-of-contents )
180+
181+ ### jit.strhashcrc32
182+
183+ ** syntax:** * ok = jit.strhashcrc32()*
184+
185+ Returns a boolean value indicating if the optimized string hashing algorithm
186+ implemented by this branch is enabled. The ` ok ` return value will be ` true ` if
187+ it is enabled, or ` false ` otherwise.
188+
189+ See the [ String hashing] ( #string-hashing ) section for details on
190+ how to enable this optimization.
191+
192+ Usage:
193+
194+ ``` lua
195+ local ok = jit .strhashcrc32 ()
196+ ```
197+
198+ [ Back to TOC] ( #table-of-contents )
199+
158200### thread.exdata
159201
160202** syntax:** * exdata = th_exdata(data?)*
@@ -207,6 +249,14 @@ help distinguishing this OpenResty-specific branch of LuaJIT.
207249
208250[Back to TOC](#table-of-contents)
209251
252+ ### `LJ_OR_DISABLE_STRHASHCRC32`
253+
254+ When specified at compilation (`-DLJ_OR_DISABLE_STRHASHCRC32`), this flag will
255+ disable the string hashing optimization described in the [String
256+ hashing](#string-hashing) section.
257+
258+ [Back to TOC](#table-of-contents)
259+
210260## Optimizations
211261
212262### Updated JIT default parameters
@@ -227,13 +277,17 @@ maxmcode=40960 -- in KB
227277
228278### String hashing
229279
230- This optimization only applies to Intel CPUs supporting the SSE 4.2 instruction
231- sets. For such CPUs, and when this branch is compiled with ` -msse4.2 ` , the
232- string hashing function used for strings interning will be based on an
233- optimized crc32 implementation (see ` lj_str_new() ` ).
280+ This optimizations modifies the string hashing algorithm to use a CRC32-based
281+ variant. This variant still provides constant-time hashing complexity (` O(n) ` )
282+ but makes hash collision attacks harder for strings up to 127 bytes of size
283+ (see ` lj_str_new() ` ).
284+
285+ This optimization is only available for x64 and ARM64 architectures, and will
286+ be enabled if a CRC32 instruction set is detected at runtime (see
287+ [ jit.crc32] ( #jitcrc32 ) ).
234288
235- This optimization still provides constant-time hashing complexity ( ` O(n) ` ), but
236- makes hash collision attacks harder for strings up to 127 bytes of size .
289+ ** Note: ** This optimization can be disabled by compiling LuaJIT with
290+ ` -DLJ_OR_DISABLE_STRHASHCRC32 ` .
237291
238292[ Back to TOC] ( #table-of-contents )
239293
0 commit comments