@@ -13,9 +13,12 @@ openresty/luajit2 - OpenResty's maintained branch of LuaJIT.
13
13
* [ table.nkeys] ( #tablenkeys )
14
14
* [ table.clone] ( #tableclone )
15
15
* [ jit.prngstate] ( #jitprngstate )
16
+ * [ jit.crc32] ( #jitcrc32 )
17
+ * [ jit.strhashcrc32] ( #jitstrhashcrc32 )
16
18
* [ thread.exdata] ( #threadexdata )
17
19
* [ New macros] ( #new-macros )
18
20
* [ ` OPENRESTY_LUAJIT ` ] ( #openresty-luajit )
21
+ * [ ` LJ_OR_DISABLE_STRHASHCRC32 ` ] ( #lj-or-disable-strhashcrc32 )
19
22
* [ Optimizations] ( #optimizations )
20
23
* [ Updated JIT default parameters] ( #updated-jit-default-parameters )
21
24
* [ String hashing] ( #string-hashing )
@@ -155,6 +158,47 @@ local newstate = jit.prngstate(123456)
155
158
156
159
[ Back to TOC] ( #table-of-contents )
157
160
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.
167
+
168
+ CRC32 support will be checked at runtime if LuaJIT was compiled with ` -msse4.2 `
169
+ on x64 architectures, or ` -march=armv8-a+crc ` on ARM64.
170
+
171
+ CRC32 support allows for this branch to use an optimized string hashing
172
+ algorithm. See the [ String hashing] ( #string-hashing ) section for details on
173
+ how to enable this optimization.
174
+
175
+ Usage:
176
+
177
+ ``` lua
178
+ local ok = jit .crc32 ()
179
+ ```
180
+
181
+ [ Back to TOC] ( #table-of-contents )
182
+
183
+ ### jit.strhashcrc32
184
+
185
+ ** syntax:** * ok = jit.strhashcrc32()*
186
+
187
+ Returns a boolean value indicating if the optimized string hashing algorithm
188
+ implemented by this branch is enabled. The ` ok ` return value will be ` true ` if
189
+ it is enabled, or ` false ` otherwise.
190
+
191
+ See the [ String hashing] ( #string-hashing ) section for details on
192
+ how to enable this optimization.
193
+
194
+ Usage:
195
+
196
+ ``` lua
197
+ local ok = jit .strhashcrc32 ()
198
+ ```
199
+
200
+ [ Back to TOC] ( #table-of-contents )
201
+
158
202
### thread.exdata
159
203
160
204
** syntax:** * exdata = th_exdata(data?)*
@@ -207,6 +251,14 @@ help distinguishing this OpenResty-specific branch of LuaJIT.
207
251
208
252
[Back to TOC](#table-of-contents)
209
253
254
+ ### `LJ_OR_DISABLE_STRHASHCRC32`
255
+
256
+ When specified at compilation (`-DLJ_OR_DISABLE_STRHASHCRC32`), this flag will
257
+ disable the string hashing optimization described in the [String
258
+ hashing](#string-hashing) section.
259
+
260
+ [Back to TOC](#table-of-contents)
261
+
210
262
## Optimizations
211
263
212
264
### Updated JIT default parameters
@@ -227,13 +279,19 @@ maxmcode=40960 -- in KB
227
279
228
280
### String hashing
229
281
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() ` ).
282
+ This optimizations modifies the string hashing algorithm to use a CRC32-based
283
+ variant. This variant still provides constant-time hashing complexity (` O(n) ` )
284
+ but makes hash collision attacks harder for strings up to 127 bytes of size
285
+ (see ` lj_str_new() ` ).
286
+
287
+ This optimization is only available for x64 and ARM64 architectures, and will
288
+ be enabled if:
289
+
290
+ 1 . LuaJIT is compiled with ` -msse4.2 ` on x64, or ` -march=armv8-a+crc ` on ARM64.
291
+ 2 . A CRC32 instruction set is detected at runtime (see [ jit.crc32] ( #jitcrc32 ) ).
234
292
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 .
293
+ ** Note: ** This optimization can be disabled by compiling LuaJIT with
294
+ ` -DLJ_OR_DISABLE_STRHASHCRC32 ` .
237
295
238
296
[ Back to TOC] ( #table-of-contents )
239
297
0 commit comments