@@ -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,45 @@ 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. 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
+
158
200
### thread.exdata
159
201
160
202
** syntax:** * exdata = th_exdata(data?)*
@@ -207,6 +249,14 @@ help distinguishing this OpenResty-specific branch of LuaJIT.
207
249
208
250
[Back to TOC](#table-of-contents)
209
251
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
+
210
260
## Optimizations
211
261
212
262
### Updated JIT default parameters
@@ -227,13 +277,17 @@ maxmcode=40960 -- in KB
227
277
228
278
### String hashing
229
279
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 ) ).
234
288
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 ` .
237
291
238
292
[ Back to TOC] ( #table-of-contents )
239
293
0 commit comments