asmjit 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/Rakefile +5 -3
- data/asmjit.gemspec +1 -3
- data/ext/asmjit/asmjit/.editorconfig +10 -0
- data/ext/asmjit/asmjit/.github/FUNDING.yml +1 -0
- data/ext/asmjit/asmjit/.github/workflows/build-config.json +47 -0
- data/ext/asmjit/asmjit/.github/workflows/build.yml +156 -0
- data/ext/asmjit/asmjit/.gitignore +6 -0
- data/ext/asmjit/asmjit/CMakeLists.txt +611 -0
- data/ext/asmjit/asmjit/LICENSE.md +17 -0
- data/ext/asmjit/asmjit/README.md +69 -0
- data/ext/asmjit/asmjit/src/asmjit/a64.h +62 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64archtraits_p.h +81 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.cpp +5115 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.h +72 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.cpp +51 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.h +57 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.cpp +60 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.h +247 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper.cpp +464 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper_p.h +50 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64emitter.h +1228 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter.cpp +298 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter_p.h +59 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64func.cpp +189 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64func_p.h +33 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64globals.h +1894 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi.cpp +278 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi_p.h +41 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.cpp +1957 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.h +74 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb_p.h +876 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.cpp +85 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.h +312 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass.cpp +852 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass_p.h +105 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/a64utils.h +179 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/armformatter.cpp +143 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/armformatter_p.h +44 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/armglobals.h +21 -0
- data/ext/asmjit/asmjit/src/asmjit/arm/armoperand.h +621 -0
- data/ext/asmjit/asmjit/src/asmjit/arm.h +62 -0
- data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-begin.h +17 -0
- data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-end.h +9 -0
- data/ext/asmjit/asmjit/src/asmjit/asmjit.h +33 -0
- data/ext/asmjit/asmjit/src/asmjit/core/api-build_p.h +55 -0
- data/ext/asmjit/asmjit/src/asmjit/core/api-config.h +613 -0
- data/ext/asmjit/asmjit/src/asmjit/core/archcommons.h +229 -0
- data/ext/asmjit/asmjit/src/asmjit/core/archtraits.cpp +160 -0
- data/ext/asmjit/asmjit/src/asmjit/core/archtraits.h +290 -0
- data/ext/asmjit/asmjit/src/asmjit/core/assembler.cpp +406 -0
- data/ext/asmjit/asmjit/src/asmjit/core/assembler.h +129 -0
- data/ext/asmjit/asmjit/src/asmjit/core/builder.cpp +889 -0
- data/ext/asmjit/asmjit/src/asmjit/core/builder.h +1391 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codebuffer.h +113 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codeholder.cpp +1149 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codeholder.h +1035 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codewriter.cpp +175 -0
- data/ext/asmjit/asmjit/src/asmjit/core/codewriter_p.h +179 -0
- data/ext/asmjit/asmjit/src/asmjit/core/compiler.cpp +582 -0
- data/ext/asmjit/asmjit/src/asmjit/core/compiler.h +737 -0
- data/ext/asmjit/asmjit/src/asmjit/core/compilerdefs.h +173 -0
- data/ext/asmjit/asmjit/src/asmjit/core/constpool.cpp +363 -0
- data/ext/asmjit/asmjit/src/asmjit/core/constpool.h +250 -0
- data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.cpp +1162 -0
- data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.h +813 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emithelper.cpp +323 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emithelper_p.h +58 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emitter.cpp +333 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emitter.h +741 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emitterutils.cpp +129 -0
- data/ext/asmjit/asmjit/src/asmjit/core/emitterutils_p.h +89 -0
- data/ext/asmjit/asmjit/src/asmjit/core/environment.cpp +46 -0
- data/ext/asmjit/asmjit/src/asmjit/core/environment.h +508 -0
- data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.cpp +14 -0
- data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.h +228 -0
- data/ext/asmjit/asmjit/src/asmjit/core/formatter.cpp +584 -0
- data/ext/asmjit/asmjit/src/asmjit/core/formatter.h +247 -0
- data/ext/asmjit/asmjit/src/asmjit/core/formatter_p.h +34 -0
- data/ext/asmjit/asmjit/src/asmjit/core/func.cpp +286 -0
- data/ext/asmjit/asmjit/src/asmjit/core/func.h +1445 -0
- data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext.cpp +293 -0
- data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext_p.h +199 -0
- data/ext/asmjit/asmjit/src/asmjit/core/globals.cpp +133 -0
- data/ext/asmjit/asmjit/src/asmjit/core/globals.h +393 -0
- data/ext/asmjit/asmjit/src/asmjit/core/inst.cpp +113 -0
- data/ext/asmjit/asmjit/src/asmjit/core/inst.h +772 -0
- data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.cpp +1242 -0
- data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.h +261 -0
- data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.cpp +80 -0
- data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.h +89 -0
- data/ext/asmjit/asmjit/src/asmjit/core/logger.cpp +69 -0
- data/ext/asmjit/asmjit/src/asmjit/core/logger.h +198 -0
- data/ext/asmjit/asmjit/src/asmjit/core/misc_p.h +33 -0
- data/ext/asmjit/asmjit/src/asmjit/core/operand.cpp +132 -0
- data/ext/asmjit/asmjit/src/asmjit/core/operand.h +1611 -0
- data/ext/asmjit/asmjit/src/asmjit/core/osutils.cpp +84 -0
- data/ext/asmjit/asmjit/src/asmjit/core/osutils.h +61 -0
- data/ext/asmjit/asmjit/src/asmjit/core/osutils_p.h +68 -0
- data/ext/asmjit/asmjit/src/asmjit/core/raassignment_p.h +418 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rabuilders_p.h +612 -0
- data/ext/asmjit/asmjit/src/asmjit/core/radefs_p.h +1204 -0
- data/ext/asmjit/asmjit/src/asmjit/core/ralocal.cpp +1166 -0
- data/ext/asmjit/asmjit/src/asmjit/core/ralocal_p.h +254 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rapass.cpp +1969 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rapass_p.h +1183 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rastack.cpp +184 -0
- data/ext/asmjit/asmjit/src/asmjit/core/rastack_p.h +171 -0
- data/ext/asmjit/asmjit/src/asmjit/core/string.cpp +559 -0
- data/ext/asmjit/asmjit/src/asmjit/core/string.h +372 -0
- data/ext/asmjit/asmjit/src/asmjit/core/support.cpp +494 -0
- data/ext/asmjit/asmjit/src/asmjit/core/support.h +1773 -0
- data/ext/asmjit/asmjit/src/asmjit/core/target.cpp +14 -0
- data/ext/asmjit/asmjit/src/asmjit/core/target.h +53 -0
- data/ext/asmjit/asmjit/src/asmjit/core/type.cpp +74 -0
- data/ext/asmjit/asmjit/src/asmjit/core/type.h +419 -0
- data/ext/asmjit/asmjit/src/asmjit/core/virtmem.cpp +722 -0
- data/ext/asmjit/asmjit/src/asmjit/core/virtmem.h +242 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zone.cpp +353 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zone.h +615 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonehash.cpp +309 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonehash.h +186 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonelist.cpp +163 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonelist.h +209 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonestack.cpp +176 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonestack.h +239 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonestring.h +120 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonetree.cpp +99 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonetree.h +380 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonevector.cpp +356 -0
- data/ext/asmjit/asmjit/src/asmjit/core/zonevector.h +690 -0
- data/ext/asmjit/asmjit/src/asmjit/core.h +1861 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86archtraits_p.h +148 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.cpp +5110 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.h +685 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.cpp +52 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.h +351 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.cpp +61 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.h +721 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper.cpp +619 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper_p.h +60 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86emitter.h +4315 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter.cpp +944 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter_p.h +58 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86func.cpp +503 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86func_p.h +33 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86globals.h +2169 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi.cpp +1732 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi_p.h +41 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.cpp +4427 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.h +563 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb_p.h +311 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86opcode_p.h +436 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.cpp +231 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.h +1085 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass.cpp +1509 -0
- data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass_p.h +94 -0
- data/ext/asmjit/asmjit/src/asmjit/x86.h +93 -0
- data/ext/asmjit/asmjit/src/asmjit.natvis +245 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler.cpp +84 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler.h +85 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler_a64.cpp +4006 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler_x64.cpp +17833 -0
- data/ext/asmjit/asmjit/test/asmjit_test_assembler_x86.cpp +8300 -0
- data/ext/asmjit/asmjit/test/asmjit_test_compiler.cpp +253 -0
- data/ext/asmjit/asmjit/test/asmjit_test_compiler.h +73 -0
- data/ext/asmjit/asmjit/test/asmjit_test_compiler_a64.cpp +690 -0
- data/ext/asmjit/asmjit/test/asmjit_test_compiler_x86.cpp +4317 -0
- data/ext/asmjit/asmjit/test/asmjit_test_emitters.cpp +197 -0
- data/ext/asmjit/asmjit/test/asmjit_test_instinfo.cpp +181 -0
- data/ext/asmjit/asmjit/test/asmjit_test_misc.h +257 -0
- data/ext/asmjit/asmjit/test/asmjit_test_perf.cpp +62 -0
- data/ext/asmjit/asmjit/test/asmjit_test_perf.h +61 -0
- data/ext/asmjit/asmjit/test/asmjit_test_perf_a64.cpp +699 -0
- data/ext/asmjit/asmjit/test/asmjit_test_perf_x86.cpp +5032 -0
- data/ext/asmjit/asmjit/test/asmjit_test_unit.cpp +172 -0
- data/ext/asmjit/asmjit/test/asmjit_test_x86_sections.cpp +172 -0
- data/ext/asmjit/asmjit/test/asmjitutils.h +38 -0
- data/ext/asmjit/asmjit/test/broken.cpp +312 -0
- data/ext/asmjit/asmjit/test/broken.h +148 -0
- data/ext/asmjit/asmjit/test/cmdline.h +61 -0
- data/ext/asmjit/asmjit/test/performancetimer.h +41 -0
- data/ext/asmjit/asmjit/tools/configure-makefiles.sh +13 -0
- data/ext/asmjit/asmjit/tools/configure-ninja.sh +13 -0
- data/ext/asmjit/asmjit/tools/configure-sanitizers.sh +13 -0
- data/ext/asmjit/asmjit/tools/configure-vs2019-x64.bat +2 -0
- data/ext/asmjit/asmjit/tools/configure-vs2019-x86.bat +2 -0
- data/ext/asmjit/asmjit/tools/configure-vs2022-x64.bat +2 -0
- data/ext/asmjit/asmjit/tools/configure-vs2022-x86.bat +2 -0
- data/ext/asmjit/asmjit/tools/configure-xcode.sh +8 -0
- data/ext/asmjit/asmjit/tools/enumgen.js +417 -0
- data/ext/asmjit/asmjit/tools/enumgen.sh +3 -0
- data/ext/asmjit/asmjit/tools/tablegen-arm.js +365 -0
- data/ext/asmjit/asmjit/tools/tablegen-arm.sh +3 -0
- data/ext/asmjit/asmjit/tools/tablegen-x86.js +2638 -0
- data/ext/asmjit/asmjit/tools/tablegen-x86.sh +3 -0
- data/ext/asmjit/asmjit/tools/tablegen.js +947 -0
- data/ext/asmjit/asmjit/tools/tablegen.sh +4 -0
- data/ext/asmjit/asmjit.cc +167 -30
- data/ext/asmjit/extconf.rb +9 -9
- data/lib/asmjit/version.rb +1 -1
- data/lib/asmjit.rb +14 -4
- metadata +198 -17
@@ -0,0 +1,309 @@
|
|
1
|
+
// This file is part of AsmJit project <https://asmjit.com>
|
2
|
+
//
|
3
|
+
// See asmjit.h or LICENSE.md for license and copyright information
|
4
|
+
// SPDX-License-Identifier: Zlib
|
5
|
+
|
6
|
+
#include "../core/api-build_p.h"
|
7
|
+
#include "../core/support.h"
|
8
|
+
#include "../core/zone.h"
|
9
|
+
#include "../core/zonehash.h"
|
10
|
+
|
11
|
+
ASMJIT_BEGIN_NAMESPACE
|
12
|
+
|
13
|
+
// ZoneHashBase - Prime Numbers
|
14
|
+
// ============================
|
15
|
+
|
16
|
+
#define ASMJIT_POPULATE_PRIMES(ENTRY) \
|
17
|
+
ENTRY(2 , 0x80000000, 32), /* [N * 0x80000000 >> 32] (rcp=2147483648) */ \
|
18
|
+
ENTRY(11 , 0xBA2E8BA3, 35), /* [N * 0xBA2E8BA3 >> 35] (rcp=3123612579) */ \
|
19
|
+
ENTRY(29 , 0x8D3DCB09, 36), /* [N * 0x8D3DCB09 >> 36] (rcp=2369637129) */ \
|
20
|
+
ENTRY(41 , 0xC7CE0C7D, 37), /* [N * 0xC7CE0C7D >> 37] (rcp=3352169597) */ \
|
21
|
+
ENTRY(59 , 0x8AD8F2FC, 37), /* [N * 0x8AD8F2FC >> 37] (rcp=2329473788) */ \
|
22
|
+
ENTRY(83 , 0xC565C87C, 38), /* [N * 0xC565C87C >> 38] (rcp=3311782012) */ \
|
23
|
+
ENTRY(131 , 0xFA232CF3, 39), /* [N * 0xFA232CF3 >> 39] (rcp=4196609267) */ \
|
24
|
+
ENTRY(191 , 0xAB8F69E3, 39), /* [N * 0xAB8F69E3 >> 39] (rcp=2878302691) */ \
|
25
|
+
ENTRY(269 , 0xF3A0D52D, 40), /* [N * 0xF3A0D52D >> 40] (rcp=4087403821) */ \
|
26
|
+
ENTRY(383 , 0xAB1CBDD4, 40), /* [N * 0xAB1CBDD4 >> 40] (rcp=2870787540) */ \
|
27
|
+
ENTRY(541 , 0xF246FACC, 41), /* [N * 0xF246FACC >> 41] (rcp=4064737996) */ \
|
28
|
+
ENTRY(757 , 0xAD2589A4, 41), /* [N * 0xAD2589A4 >> 41] (rcp=2904918436) */ \
|
29
|
+
ENTRY(1061 , 0xF7129426, 42), /* [N * 0xF7129426 >> 42] (rcp=4145189926) */ \
|
30
|
+
ENTRY(1499 , 0xAEE116B7, 42), /* [N * 0xAEE116B7 >> 42] (rcp=2933986999) */ \
|
31
|
+
ENTRY(2099 , 0xF9C7A737, 43), /* [N * 0xF9C7A737 >> 43] (rcp=4190611255) */ \
|
32
|
+
ENTRY(2939 , 0xB263D25C, 43), /* [N * 0xB263D25C >> 43] (rcp=2992886364) */ \
|
33
|
+
ENTRY(4111 , 0xFF10E02E, 44), /* [N * 0xFF10E02E >> 44] (rcp=4279296046) */ \
|
34
|
+
ENTRY(5779 , 0xB5722823, 44), /* [N * 0xB5722823 >> 44] (rcp=3044157475) */ \
|
35
|
+
ENTRY(8087 , 0x81A97405, 44), /* [N * 0x81A97405 >> 44] (rcp=2175366149) */ \
|
36
|
+
ENTRY(11321 , 0xB93E91DB, 45), /* [N * 0xB93E91DB >> 45] (rcp=3107885531) */ \
|
37
|
+
ENTRY(15859 , 0x843CC26B, 45), /* [N * 0x843CC26B >> 45] (rcp=2218574443) */ \
|
38
|
+
ENTRY(22189 , 0xBD06B9EA, 46), /* [N * 0xBD06B9EA >> 46] (rcp=3171334634) */ \
|
39
|
+
ENTRY(31051 , 0x8713F186, 46), /* [N * 0x8713F186 >> 46] (rcp=2266231174) */ \
|
40
|
+
ENTRY(43451 , 0xC10F1CB9, 47), /* [N * 0xC10F1CB9 >> 47] (rcp=3238993081) */ \
|
41
|
+
ENTRY(60869 , 0x89D06A86, 47), /* [N * 0x89D06A86 >> 47] (rcp=2312137350) */ \
|
42
|
+
ENTRY(85159 , 0xC502AF3B, 48), /* [N * 0xC502AF3B >> 48] (rcp=3305287483) */ \
|
43
|
+
ENTRY(102107 , 0xA44F65AE, 48), /* [N * 0xA44F65AE >> 48] (rcp=2756666798) */ \
|
44
|
+
ENTRY(122449 , 0x89038F77, 48), /* [N * 0x89038F77 >> 48] (rcp=2298711927) */ \
|
45
|
+
ENTRY(146819 , 0xE48AF7E9, 49), /* [N * 0xE48AF7E9 >> 49] (rcp=3834312681) */ \
|
46
|
+
ENTRY(176041 , 0xBE9B145B, 49), /* [N * 0xBE9B145B >> 49] (rcp=3197834331) */ \
|
47
|
+
ENTRY(211073 , 0x9EF882BA, 49), /* [N * 0x9EF882BA >> 49] (rcp=2667086522) */ \
|
48
|
+
ENTRY(253081 , 0x849571AB, 49), /* [N * 0x849571AB >> 49] (rcp=2224386475) */ \
|
49
|
+
ENTRY(303469 , 0xDD239C97, 50), /* [N * 0xDD239C97 >> 50] (rcp=3710098583) */ \
|
50
|
+
ENTRY(363887 , 0xB86C196D, 50), /* [N * 0xB86C196D >> 50] (rcp=3094092141) */ \
|
51
|
+
ENTRY(436307 , 0x99CFA4E9, 50), /* [N * 0x99CFA4E9 >> 50] (rcp=2580522217) */ \
|
52
|
+
ENTRY(523177 , 0x804595C0, 50), /* [N * 0x804595C0 >> 50] (rcp=2152043968) */ \
|
53
|
+
ENTRY(627293 , 0xD5F69FCF, 51), /* [N * 0xD5F69FCF >> 51] (rcp=3589709775) */ \
|
54
|
+
ENTRY(752177 , 0xB27063BA, 51), /* [N * 0xB27063BA >> 51] (rcp=2993710010) */ \
|
55
|
+
ENTRY(901891 , 0x94D170AC, 51), /* [N * 0x94D170AC >> 51] (rcp=2496753836) */ \
|
56
|
+
ENTRY(1081369 , 0xF83C9767, 52), /* [N * 0xF83C9767 >> 52] (rcp=4164720487) */ \
|
57
|
+
ENTRY(1296563 , 0xCF09435D, 52), /* [N * 0xCF09435D >> 52] (rcp=3473490781) */ \
|
58
|
+
ENTRY(1554583 , 0xACAC7198, 52), /* [N * 0xACAC7198 >> 52] (rcp=2896982424) */ \
|
59
|
+
ENTRY(1863971 , 0x90033EE3, 52), /* [N * 0x90033EE3 >> 52] (rcp=2416131811) */ \
|
60
|
+
ENTRY(2234923 , 0xF0380EBD, 53), /* [N * 0xF0380EBD >> 53] (rcp=4030205629) */ \
|
61
|
+
ENTRY(2679673 , 0xC859731E, 53), /* [N * 0xC859731E >> 53] (rcp=3361305374) */ \
|
62
|
+
ENTRY(3212927 , 0xA718DE27, 53), /* [N * 0xA718DE27 >> 53] (rcp=2803424807) */ \
|
63
|
+
ENTRY(3852301 , 0x8B5D1B4B, 53), /* [N * 0x8B5D1B4B >> 53] (rcp=2338134859) */ \
|
64
|
+
ENTRY(4618921 , 0xE8774804, 54), /* [N * 0xE8774804 >> 54] (rcp=3900131332) */ \
|
65
|
+
ENTRY(5076199 , 0xD386574E, 54), /* [N * 0xD386574E >> 54] (rcp=3548796750) */ \
|
66
|
+
ENTRY(5578757 , 0xC0783FE1, 54), /* [N * 0xC0783FE1 >> 54] (rcp=3229106145) */ \
|
67
|
+
ENTRY(6131057 , 0xAF21B08F, 54), /* [N * 0xAF21B08F >> 54] (rcp=2938220687) */ \
|
68
|
+
ENTRY(6738031 , 0x9F5AFD6E, 54), /* [N * 0x9F5AFD6E >> 54] (rcp=2673540462) */ \
|
69
|
+
ENTRY(7405163 , 0x90FFC3B9, 54), /* [N * 0x90FFC3B9 >> 54] (rcp=2432680889) */ \
|
70
|
+
ENTRY(8138279 , 0x83EFECFC, 54), /* [N * 0x83EFECFC >> 54] (rcp=2213539068) */ \
|
71
|
+
ENTRY(8943971 , 0xF01AA2EF, 55), /* [N * 0xF01AA2EF >> 55] (rcp=4028277487) */ \
|
72
|
+
ENTRY(9829447 , 0xDA7979B2, 55), /* [N * 0xDA7979B2 >> 55] (rcp=3665394098) */ \
|
73
|
+
ENTRY(10802581 , 0xC6CB2771, 55), /* [N * 0xC6CB2771 >> 55] (rcp=3335202673) */ \
|
74
|
+
ENTRY(11872037 , 0xB4E2C7DD, 55), /* [N * 0xB4E2C7DD >> 55] (rcp=3034761181) */ \
|
75
|
+
ENTRY(13047407 , 0xA4974124, 55), /* [N * 0xA4974124 >> 55] (rcp=2761376036) */ \
|
76
|
+
ENTRY(14339107 , 0x95C39CF1, 55), /* [N * 0x95C39CF1 >> 55] (rcp=2512624881) */ \
|
77
|
+
ENTRY(15758737 , 0x8845C763, 55), /* [N * 0x8845C763 >> 55] (rcp=2286274403) */ \
|
78
|
+
ENTRY(17318867 , 0xF7FE593F, 56), /* [N * 0xF7FE593F >> 56] (rcp=4160641343) */ \
|
79
|
+
ENTRY(19033439 , 0xE1A75D93, 56), /* [N * 0xE1A75D93 >> 56] (rcp=3785842067) */ \
|
80
|
+
ENTRY(20917763 , 0xCD5389B3, 56), /* [N * 0xCD5389B3 >> 56] (rcp=3444804019) */ \
|
81
|
+
ENTRY(22988621 , 0xBAD4841A, 56), /* [N * 0xBAD4841A >> 56] (rcp=3134489626) */ \
|
82
|
+
ENTRY(25264543 , 0xA9FFF2FF, 56), /* [N * 0xA9FFF2FF >> 56] (rcp=2852123391) */ \
|
83
|
+
ENTRY(27765763 , 0x9AAF8BF3, 56), /* [N * 0x9AAF8BF3 >> 56] (rcp=2595195891) */ \
|
84
|
+
ENTRY(30514607 , 0x8CC04E18, 56), /* [N * 0x8CC04E18 >> 56] (rcp=2361413144) */ \
|
85
|
+
ENTRY(33535561 , 0x80127068, 56), /* [N * 0x80127068 >> 56] (rcp=2148692072) */ \
|
86
|
+
ENTRY(36855587 , 0xE911F0BB, 57), /* [N * 0xE911F0BB >> 57] (rcp=3910267067) */ \
|
87
|
+
ENTRY(38661533 , 0xDE2ED7BE, 57), /* [N * 0xDE2ED7BE >> 57] (rcp=3727611838) */ \
|
88
|
+
ENTRY(40555961 , 0xD3CDF2FD, 57), /* [N * 0xD3CDF2FD >> 57] (rcp=3553489661) */ \
|
89
|
+
ENTRY(42543269 , 0xC9E9196C, 57), /* [N * 0xC9E9196C >> 57] (rcp=3387496812) */ \
|
90
|
+
ENTRY(44627909 , 0xC07A9EB6, 57), /* [N * 0xC07A9EB6 >> 57] (rcp=3229261494) */ \
|
91
|
+
ENTRY(46814687 , 0xB77CEF65, 57), /* [N * 0xB77CEF65 >> 57] (rcp=3078418277) */ \
|
92
|
+
ENTRY(49108607 , 0xAEEAC65C, 57), /* [N * 0xAEEAC65C >> 57] (rcp=2934621788) */ \
|
93
|
+
ENTRY(51514987 , 0xA6BF0EF0, 57), /* [N * 0xA6BF0EF0 >> 57] (rcp=2797539056) */ \
|
94
|
+
ENTRY(54039263 , 0x9EF510B5, 57), /* [N * 0x9EF510B5 >> 57] (rcp=2666860725) */ \
|
95
|
+
ENTRY(56687207 , 0x97883B42, 57), /* [N * 0x97883B42 >> 57] (rcp=2542287682) */ \
|
96
|
+
ENTRY(59464897 , 0x907430ED, 57), /* [N * 0x907430ED >> 57] (rcp=2423533805) */ \
|
97
|
+
ENTRY(62378699 , 0x89B4CA91, 57), /* [N * 0x89B4CA91 >> 57] (rcp=2310326929) */ \
|
98
|
+
ENTRY(65435273 , 0x83461568, 57), /* [N * 0x83461568 >> 57] (rcp=2202408296) */ \
|
99
|
+
ENTRY(68641607 , 0xFA489AA8, 58), /* [N * 0xFA489AA8 >> 58] (rcp=4199062184) */ \
|
100
|
+
ENTRY(72005051 , 0xEE97B1C5, 58), /* [N * 0xEE97B1C5 >> 58] (rcp=4002918853) */ \
|
101
|
+
ENTRY(75533323 , 0xE3729293, 58), /* [N * 0xE3729293 >> 58] (rcp=3815936659) */ \
|
102
|
+
ENTRY(79234469 , 0xD8D2BBA3, 58), /* [N * 0xD8D2BBA3 >> 58] (rcp=3637689251) */ \
|
103
|
+
ENTRY(83116967 , 0xCEB1F196, 58), /* [N * 0xCEB1F196 >> 58] (rcp=3467768214) */ \
|
104
|
+
ENTRY(87189709 , 0xC50A4426, 58), /* [N * 0xC50A4426 >> 58] (rcp=3305784358) */ \
|
105
|
+
ENTRY(91462061 , 0xBBD6052B, 58), /* [N * 0xBBD6052B >> 58] (rcp=3151365419) */ \
|
106
|
+
ENTRY(95943737 , 0xB30FD999, 58), /* [N * 0xB30FD999 >> 58] (rcp=3004160409) */ \
|
107
|
+
ENTRY(100644991 , 0xAAB29CED, 58), /* [N * 0xAAB29CED >> 58] (rcp=2863832301) */ \
|
108
|
+
ENTRY(105576619 , 0xA2B96421, 58), /* [N * 0xA2B96421 >> 58] (rcp=2730058785) */ \
|
109
|
+
ENTRY(110749901 , 0x9B1F8434, 58), /* [N * 0x9B1F8434 >> 58] (rcp=2602533940) */ \
|
110
|
+
ENTRY(116176651 , 0x93E08B4A, 58), /* [N * 0x93E08B4A >> 58] (rcp=2480966474) */ \
|
111
|
+
ENTRY(121869317 , 0x8CF837E0, 58), /* [N * 0x8CF837E0 >> 58] (rcp=2365077472) */ \
|
112
|
+
ENTRY(127840913 , 0x86627F01, 58), /* [N * 0x86627F01 >> 58] (rcp=2254601985) */ \
|
113
|
+
ENTRY(134105159 , 0x801B8178, 58), /* [N * 0x801B8178 >> 58] (rcp=2149286264) */ \
|
114
|
+
ENTRY(140676353 , 0xF43F294F, 59), /* [N * 0xF43F294F >> 59] (rcp=4097780047) */ \
|
115
|
+
ENTRY(147569509 , 0xE8D67089, 59), /* [N * 0xE8D67089 >> 59] (rcp=3906367625) */ \
|
116
|
+
ENTRY(154800449 , 0xDDF6243C, 59), /* [N * 0xDDF6243C >> 59] (rcp=3723895868) */ \
|
117
|
+
ENTRY(162385709 , 0xD397E6AE, 59), /* [N * 0xD397E6AE >> 59] (rcp=3549947566) */ \
|
118
|
+
ENTRY(170342629 , 0xC9B5A65A, 59), /* [N * 0xC9B5A65A >> 59] (rcp=3384125018) */ \
|
119
|
+
ENTRY(178689419 , 0xC0499865, 59), /* [N * 0xC0499865 >> 59] (rcp=3226048613) */ \
|
120
|
+
ENTRY(187445201 , 0xB74E35FA, 59), /* [N * 0xB74E35FA >> 59] (rcp=3075356154) */ \
|
121
|
+
ENTRY(196630033 , 0xAEBE3AC1, 59), /* [N * 0xAEBE3AC1 >> 59] (rcp=2931702465) */ \
|
122
|
+
ENTRY(206264921 , 0xA694A37F, 59), /* [N * 0xA694A37F >> 59] (rcp=2794759039) */ \
|
123
|
+
ENTRY(216371963 , 0x9ECCA59F, 59), /* [N * 0x9ECCA59F >> 59] (rcp=2664211871) */ \
|
124
|
+
ENTRY(226974197 , 0x9761B6AE, 59), /* [N * 0x9761B6AE >> 59] (rcp=2539763374) */ \
|
125
|
+
ENTRY(238095983 , 0x904F79A1, 59), /* [N * 0x904F79A1 >> 59] (rcp=2421127585) */ \
|
126
|
+
ENTRY(249762697 , 0x8991CD1F, 59), /* [N * 0x8991CD1F >> 59] (rcp=2308033823) */ \
|
127
|
+
ENTRY(262001071 , 0x8324BCA5, 59), /* [N * 0x8324BCA5 >> 59] (rcp=2200222885) */ \
|
128
|
+
ENTRY(274839137 , 0xFA090732, 60), /* [N * 0xFA090732 >> 60] (rcp=4194895666) */ \
|
129
|
+
ENTRY(288306269 , 0xEE5B16ED, 60), /* [N * 0xEE5B16ED >> 60] (rcp=3998947053) */ \
|
130
|
+
ENTRY(302433337 , 0xE338CE49, 60), /* [N * 0xE338CE49 >> 60] (rcp=3812150857) */ \
|
131
|
+
ENTRY(317252587 , 0xD89BABC0, 60), /* [N * 0xD89BABC0 >> 60] (rcp=3634080704) */ \
|
132
|
+
ENTRY(374358107 , 0xB790EF43, 60), /* [N * 0xB790EF43 >> 60] (rcp=3079728963) */ \
|
133
|
+
ENTRY(441742621 , 0x9B908414, 60), /* [N * 0x9B908414 >> 60] (rcp=2609939476) */ \
|
134
|
+
ENTRY(521256293 , 0x83D596FA, 60), /* [N * 0x83D596FA >> 60] (rcp=2211813114) */ \
|
135
|
+
ENTRY(615082441 , 0xDF72B16E, 61), /* [N * 0xDF72B16E >> 61] (rcp=3748835694) */ \
|
136
|
+
ENTRY(725797313 , 0xBD5CDB3B, 61), /* [N * 0xBD5CDB3B >> 61] (rcp=3176979259) */ \
|
137
|
+
ENTRY(856440829 , 0xA07A14E9, 61), /* [N * 0xA07A14E9 >> 61] (rcp=2692355305) */ \
|
138
|
+
ENTRY(1010600209, 0x87FF5289, 61), /* [N * 0x87FF5289 >> 61] (rcp=2281656969) */ \
|
139
|
+
ENTRY(1192508257, 0xE6810540, 62), /* [N * 0xE6810540 >> 62] (rcp=3867215168) */ \
|
140
|
+
ENTRY(1407159797, 0xC357A480, 62), /* [N * 0xC357A480 >> 62] (rcp=3277300864) */ \
|
141
|
+
ENTRY(1660448617, 0xA58B5B4F, 62), /* [N * 0xA58B5B4F >> 62] (rcp=2777373519) */ \
|
142
|
+
ENTRY(1959329399, 0x8C4AB55F, 62), /* [N * 0x8C4AB55F >> 62] (rcp=2353706335) */ \
|
143
|
+
ENTRY(2312008693, 0xEDC86320, 63), /* [N * 0xEDC86320 >> 63] (rcp=3989332768) */ \
|
144
|
+
ENTRY(2728170257, 0xC982C4D2, 63), /* [N * 0xC982C4D2 >> 63] (rcp=3380790482) */ \
|
145
|
+
ENTRY(3219240923, 0xAAC599B6, 63) /* [N * 0xAAC599B6 >> 63] (rcp=2865076662) */
|
146
|
+
|
147
|
+
|
148
|
+
struct HashPrime {
|
149
|
+
//! Prime number
|
150
|
+
uint32_t prime;
|
151
|
+
//! Reciprocal to turn division into multiplication.
|
152
|
+
uint32_t rcp;
|
153
|
+
};
|
154
|
+
|
155
|
+
static const HashPrime ZoneHash_primeArray[] = {
|
156
|
+
#define E(PRIME, RCP, SHIFT) { PRIME, RCP }
|
157
|
+
ASMJIT_POPULATE_PRIMES(E)
|
158
|
+
#undef E
|
159
|
+
};
|
160
|
+
|
161
|
+
static const uint8_t ZoneHash_primeShift[] = {
|
162
|
+
#define E(PRIME, RCP, SHIFT) uint8_t(SHIFT)
|
163
|
+
ASMJIT_POPULATE_PRIMES(E)
|
164
|
+
#undef E
|
165
|
+
};
|
166
|
+
|
167
|
+
// ZoneHashBase - Rehash
|
168
|
+
// =====================
|
169
|
+
|
170
|
+
void ZoneHashBase::_rehash(ZoneAllocator* allocator, uint32_t primeIndex) noexcept {
|
171
|
+
ASMJIT_ASSERT(primeIndex < ASMJIT_ARRAY_SIZE(ZoneHash_primeArray));
|
172
|
+
uint32_t newCount = ZoneHash_primeArray[primeIndex].prime;
|
173
|
+
|
174
|
+
ZoneHashNode** oldData = _data;
|
175
|
+
ZoneHashNode** newData = reinterpret_cast<ZoneHashNode**>(
|
176
|
+
allocator->allocZeroed(size_t(newCount) * sizeof(ZoneHashNode*)));
|
177
|
+
|
178
|
+
// We can still store nodes into the table, but it will degrade.
|
179
|
+
if (ASMJIT_UNLIKELY(newData == nullptr))
|
180
|
+
return;
|
181
|
+
|
182
|
+
uint32_t i;
|
183
|
+
uint32_t oldCount = _bucketsCount;
|
184
|
+
|
185
|
+
_data = newData;
|
186
|
+
_bucketsCount = newCount;
|
187
|
+
_bucketsGrow = uint32_t(newCount * 0.9);
|
188
|
+
_rcpValue = ZoneHash_primeArray[primeIndex].rcp;
|
189
|
+
_rcpShift = ZoneHash_primeShift[primeIndex];
|
190
|
+
_primeIndex = uint8_t(primeIndex);
|
191
|
+
|
192
|
+
for (i = 0; i < oldCount; i++) {
|
193
|
+
ZoneHashNode* node = oldData[i];
|
194
|
+
while (node) {
|
195
|
+
ZoneHashNode* next = node->_hashNext;
|
196
|
+
uint32_t hashMod = _calcMod(node->_hashCode);
|
197
|
+
|
198
|
+
node->_hashNext = newData[hashMod];
|
199
|
+
newData[hashMod] = node;
|
200
|
+
node = next;
|
201
|
+
}
|
202
|
+
}
|
203
|
+
|
204
|
+
if (oldData != _embedded)
|
205
|
+
allocator->release(oldData, oldCount * sizeof(ZoneHashNode*));
|
206
|
+
}
|
207
|
+
|
208
|
+
// ZoneHashBase - Operations
|
209
|
+
// =========================
|
210
|
+
|
211
|
+
ZoneHashNode* ZoneHashBase::_insert(ZoneAllocator* allocator, ZoneHashNode* node) noexcept {
|
212
|
+
uint32_t hashMod = _calcMod(node->_hashCode);
|
213
|
+
ZoneHashNode* next = _data[hashMod];
|
214
|
+
|
215
|
+
node->_hashNext = next;
|
216
|
+
_data[hashMod] = node;
|
217
|
+
|
218
|
+
if (++_size > _bucketsGrow) {
|
219
|
+
uint32_t primeIndex = Support::min<uint32_t>(_primeIndex + 2, ASMJIT_ARRAY_SIZE(ZoneHash_primeArray) - 1);
|
220
|
+
if (primeIndex > _primeIndex)
|
221
|
+
_rehash(allocator, primeIndex);
|
222
|
+
}
|
223
|
+
|
224
|
+
return node;
|
225
|
+
}
|
226
|
+
|
227
|
+
ZoneHashNode* ZoneHashBase::_remove(ZoneAllocator* allocator, ZoneHashNode* node) noexcept {
|
228
|
+
DebugUtils::unused(allocator);
|
229
|
+
uint32_t hashMod = _calcMod(node->_hashCode);
|
230
|
+
|
231
|
+
ZoneHashNode** pPrev = &_data[hashMod];
|
232
|
+
ZoneHashNode* p = *pPrev;
|
233
|
+
|
234
|
+
while (p) {
|
235
|
+
if (p == node) {
|
236
|
+
*pPrev = p->_hashNext;
|
237
|
+
_size--;
|
238
|
+
return node;
|
239
|
+
}
|
240
|
+
|
241
|
+
pPrev = &p->_hashNext;
|
242
|
+
p = *pPrev;
|
243
|
+
}
|
244
|
+
|
245
|
+
return nullptr;
|
246
|
+
}
|
247
|
+
|
248
|
+
// ZoneHashBase - Tests
|
249
|
+
// ====================
|
250
|
+
|
251
|
+
#if defined(ASMJIT_TEST)
|
252
|
+
struct MyHashNode : public ZoneHashNode {
|
253
|
+
inline MyHashNode(uint32_t key) noexcept
|
254
|
+
: ZoneHashNode(key),
|
255
|
+
_key(key) {}
|
256
|
+
|
257
|
+
uint32_t _key;
|
258
|
+
};
|
259
|
+
|
260
|
+
struct MyKeyMatcher {
|
261
|
+
inline MyKeyMatcher(uint32_t key) noexcept
|
262
|
+
: _key(key) {}
|
263
|
+
|
264
|
+
inline uint32_t hashCode() const noexcept { return _key; }
|
265
|
+
inline bool matches(const MyHashNode* node) const noexcept { return node->_key == _key; }
|
266
|
+
|
267
|
+
uint32_t _key;
|
268
|
+
};
|
269
|
+
|
270
|
+
UNIT(zone_hash) {
|
271
|
+
uint32_t kCount = BrokenAPI::hasArg("--quick") ? 1000 : 10000;
|
272
|
+
|
273
|
+
Zone zone(4096);
|
274
|
+
ZoneAllocator allocator(&zone);
|
275
|
+
|
276
|
+
ZoneHash<MyHashNode> hashTable;
|
277
|
+
|
278
|
+
uint32_t key;
|
279
|
+
INFO("Inserting %u elements to HashTable", unsigned(kCount));
|
280
|
+
for (key = 0; key < kCount; key++) {
|
281
|
+
hashTable.insert(&allocator, zone.newT<MyHashNode>(key));
|
282
|
+
}
|
283
|
+
|
284
|
+
uint32_t count = kCount;
|
285
|
+
INFO("Removing %u elements from HashTable and validating each operation", unsigned(kCount));
|
286
|
+
do {
|
287
|
+
MyHashNode* node;
|
288
|
+
|
289
|
+
for (key = 0; key < count; key++) {
|
290
|
+
node = hashTable.get(MyKeyMatcher(key));
|
291
|
+
EXPECT(node != nullptr);
|
292
|
+
EXPECT(node->_key == key);
|
293
|
+
}
|
294
|
+
|
295
|
+
{
|
296
|
+
count--;
|
297
|
+
node = hashTable.get(MyKeyMatcher(count));
|
298
|
+
hashTable.remove(&allocator, node);
|
299
|
+
|
300
|
+
node = hashTable.get(MyKeyMatcher(count));
|
301
|
+
EXPECT(node == nullptr);
|
302
|
+
}
|
303
|
+
} while (count);
|
304
|
+
|
305
|
+
EXPECT(hashTable.empty());
|
306
|
+
}
|
307
|
+
#endif
|
308
|
+
|
309
|
+
ASMJIT_END_NAMESPACE
|
@@ -0,0 +1,186 @@
|
|
1
|
+
// This file is part of AsmJit project <https://asmjit.com>
|
2
|
+
//
|
3
|
+
// See asmjit.h or LICENSE.md for license and copyright information
|
4
|
+
// SPDX-License-Identifier: Zlib
|
5
|
+
|
6
|
+
#ifndef ASMJIT_CORE_ZONEHASH_H_INCLUDED
|
7
|
+
#define ASMJIT_CORE_ZONEHASH_H_INCLUDED
|
8
|
+
|
9
|
+
#include "../core/zone.h"
|
10
|
+
|
11
|
+
ASMJIT_BEGIN_NAMESPACE
|
12
|
+
|
13
|
+
//! \addtogroup asmjit_zone
|
14
|
+
//! \{
|
15
|
+
|
16
|
+
//! Node used by \ref ZoneHash template.
|
17
|
+
//!
|
18
|
+
//! You must provide function `bool eq(const Key& key)` in order to make `ZoneHash::get()` working.
|
19
|
+
class ZoneHashNode {
|
20
|
+
public:
|
21
|
+
ASMJIT_NONCOPYABLE(ZoneHashNode)
|
22
|
+
|
23
|
+
inline ZoneHashNode(uint32_t hashCode = 0) noexcept
|
24
|
+
: _hashNext(nullptr),
|
25
|
+
_hashCode(hashCode),
|
26
|
+
_customData(0) {}
|
27
|
+
|
28
|
+
//! Next node in the chain, null if it terminates the chain.
|
29
|
+
ZoneHashNode* _hashNext;
|
30
|
+
//! Precalculated hash-code of key.
|
31
|
+
uint32_t _hashCode;
|
32
|
+
//! Padding, can be reused by any Node that inherits `ZoneHashNode`.
|
33
|
+
uint32_t _customData;
|
34
|
+
};
|
35
|
+
|
36
|
+
//! Base class used by \ref ZoneHash template
|
37
|
+
class ZoneHashBase {
|
38
|
+
public:
|
39
|
+
ASMJIT_NONCOPYABLE(ZoneHashBase)
|
40
|
+
|
41
|
+
//! Buckets data.
|
42
|
+
ZoneHashNode** _data;
|
43
|
+
//! Count of records inserted into the hash table.
|
44
|
+
size_t _size;
|
45
|
+
//! Count of hash buckets.
|
46
|
+
uint32_t _bucketsCount;
|
47
|
+
//! When buckets array should grow (only checked after insertion).
|
48
|
+
uint32_t _bucketsGrow;
|
49
|
+
//! Reciprocal value of `_bucketsCount`.
|
50
|
+
uint32_t _rcpValue;
|
51
|
+
//! How many bits to shift right when hash is multiplied with `_rcpValue`.
|
52
|
+
uint8_t _rcpShift;
|
53
|
+
//! Prime value index in internal prime array.
|
54
|
+
uint8_t _primeIndex;
|
55
|
+
|
56
|
+
//! Embedded data, used by empty hash tables.
|
57
|
+
ZoneHashNode* _embedded[1];
|
58
|
+
|
59
|
+
//! \name Construction & Destruction
|
60
|
+
//! \{
|
61
|
+
|
62
|
+
inline ZoneHashBase() noexcept {
|
63
|
+
reset();
|
64
|
+
}
|
65
|
+
|
66
|
+
inline ZoneHashBase(ZoneHashBase&& other) noexcept {
|
67
|
+
_data = other._data;
|
68
|
+
_size = other._size;
|
69
|
+
_bucketsCount = other._bucketsCount;
|
70
|
+
_bucketsGrow = other._bucketsGrow;
|
71
|
+
_rcpValue = other._rcpValue;
|
72
|
+
_rcpShift = other._rcpShift;
|
73
|
+
_primeIndex = other._primeIndex;
|
74
|
+
_embedded[0] = other._embedded[0];
|
75
|
+
|
76
|
+
if (_data == other._embedded) _data = _embedded;
|
77
|
+
}
|
78
|
+
|
79
|
+
inline void reset() noexcept {
|
80
|
+
_data = _embedded;
|
81
|
+
_size = 0;
|
82
|
+
_bucketsCount = 1;
|
83
|
+
_bucketsGrow = 1;
|
84
|
+
_rcpValue = 1;
|
85
|
+
_rcpShift = 0;
|
86
|
+
_primeIndex = 0;
|
87
|
+
_embedded[0] = nullptr;
|
88
|
+
}
|
89
|
+
|
90
|
+
inline void release(ZoneAllocator* allocator) noexcept {
|
91
|
+
ZoneHashNode** oldData = _data;
|
92
|
+
if (oldData != _embedded)
|
93
|
+
allocator->release(oldData, _bucketsCount * sizeof(ZoneHashNode*));
|
94
|
+
reset();
|
95
|
+
}
|
96
|
+
|
97
|
+
//! \}
|
98
|
+
|
99
|
+
//! \name Accessors
|
100
|
+
//! \{
|
101
|
+
|
102
|
+
inline bool empty() const noexcept { return _size == 0; }
|
103
|
+
inline size_t size() const noexcept { return _size; }
|
104
|
+
|
105
|
+
//! \}
|
106
|
+
|
107
|
+
//! \name Utilities
|
108
|
+
//! \{
|
109
|
+
|
110
|
+
inline void _swap(ZoneHashBase& other) noexcept {
|
111
|
+
std::swap(_data, other._data);
|
112
|
+
std::swap(_size, other._size);
|
113
|
+
std::swap(_bucketsCount, other._bucketsCount);
|
114
|
+
std::swap(_bucketsGrow, other._bucketsGrow);
|
115
|
+
std::swap(_rcpValue, other._rcpValue);
|
116
|
+
std::swap(_rcpShift, other._rcpShift);
|
117
|
+
std::swap(_primeIndex, other._primeIndex);
|
118
|
+
std::swap(_embedded[0], other._embedded[0]);
|
119
|
+
|
120
|
+
if (_data == other._embedded) _data = _embedded;
|
121
|
+
if (other._data == _embedded) other._data = other._embedded;
|
122
|
+
}
|
123
|
+
|
124
|
+
//! \cond INTERNAL
|
125
|
+
inline uint32_t _calcMod(uint32_t hash) const noexcept {
|
126
|
+
uint32_t x = uint32_t((uint64_t(hash) * _rcpValue) >> _rcpShift);
|
127
|
+
return hash - x * _bucketsCount;
|
128
|
+
}
|
129
|
+
|
130
|
+
ASMJIT_API void _rehash(ZoneAllocator* allocator, uint32_t newCount) noexcept;
|
131
|
+
ASMJIT_API ZoneHashNode* _insert(ZoneAllocator* allocator, ZoneHashNode* node) noexcept;
|
132
|
+
ASMJIT_API ZoneHashNode* _remove(ZoneAllocator* allocator, ZoneHashNode* node) noexcept;
|
133
|
+
//! \endcond
|
134
|
+
|
135
|
+
//! \}
|
136
|
+
};
|
137
|
+
|
138
|
+
//! Low-level hash table specialized for storing string keys and POD values.
|
139
|
+
//!
|
140
|
+
//! This hash table allows duplicates to be inserted (the API is so low level that it's up to you if you allow it or
|
141
|
+
//! not, as you should first `get()` the node and then modify it or insert a new node by using `insert()`, depending
|
142
|
+
//! on the intention).
|
143
|
+
template<typename NodeT>
|
144
|
+
class ZoneHash : public ZoneHashBase {
|
145
|
+
public:
|
146
|
+
ASMJIT_NONCOPYABLE(ZoneHash)
|
147
|
+
|
148
|
+
typedef NodeT Node;
|
149
|
+
|
150
|
+
//! \name Construction & Destruction
|
151
|
+
//! \{
|
152
|
+
|
153
|
+
inline ZoneHash() noexcept
|
154
|
+
: ZoneHashBase() {}
|
155
|
+
|
156
|
+
inline ZoneHash(ZoneHash&& other) noexcept
|
157
|
+
: ZoneHash(other) {}
|
158
|
+
|
159
|
+
//! \}
|
160
|
+
|
161
|
+
//! \name Utilities
|
162
|
+
//! \{
|
163
|
+
|
164
|
+
inline void swap(ZoneHash& other) noexcept { ZoneHashBase::_swap(other); }
|
165
|
+
|
166
|
+
template<typename KeyT>
|
167
|
+
inline NodeT* get(const KeyT& key) const noexcept {
|
168
|
+
uint32_t hashMod = _calcMod(key.hashCode());
|
169
|
+
NodeT* node = static_cast<NodeT*>(_data[hashMod]);
|
170
|
+
|
171
|
+
while (node && !key.matches(node))
|
172
|
+
node = static_cast<NodeT*>(node->_hashNext);
|
173
|
+
return node;
|
174
|
+
}
|
175
|
+
|
176
|
+
inline NodeT* insert(ZoneAllocator* allocator, NodeT* node) noexcept { return static_cast<NodeT*>(_insert(allocator, node)); }
|
177
|
+
inline NodeT* remove(ZoneAllocator* allocator, NodeT* node) noexcept { return static_cast<NodeT*>(_remove(allocator, node)); }
|
178
|
+
|
179
|
+
//! \}
|
180
|
+
};
|
181
|
+
|
182
|
+
//! \}
|
183
|
+
|
184
|
+
ASMJIT_END_NAMESPACE
|
185
|
+
|
186
|
+
#endif // ASMJIT_CORE_ZONEHASH_H_INCLUDED
|
@@ -0,0 +1,163 @@
|
|
1
|
+
// This file is part of AsmJit project <https://asmjit.com>
|
2
|
+
//
|
3
|
+
// See asmjit.h or LICENSE.md for license and copyright information
|
4
|
+
// SPDX-License-Identifier: Zlib
|
5
|
+
|
6
|
+
#include "../core/api-build_p.h"
|
7
|
+
#include "../core/zone.h"
|
8
|
+
#include "../core/zonelist.h"
|
9
|
+
|
10
|
+
ASMJIT_BEGIN_NAMESPACE
|
11
|
+
|
12
|
+
// ZoneList - Tests
|
13
|
+
// ================
|
14
|
+
|
15
|
+
#if defined(ASMJIT_TEST)
|
16
|
+
class MyListNode : public ZoneListNode<MyListNode> {};
|
17
|
+
|
18
|
+
UNIT(zone_list) {
|
19
|
+
Zone zone(4096);
|
20
|
+
ZoneList<MyListNode> list;
|
21
|
+
|
22
|
+
MyListNode* a = zone.newT<MyListNode>();
|
23
|
+
MyListNode* b = zone.newT<MyListNode>();
|
24
|
+
MyListNode* c = zone.newT<MyListNode>();
|
25
|
+
MyListNode* d = zone.newT<MyListNode>();
|
26
|
+
|
27
|
+
INFO("Append / Unlink");
|
28
|
+
|
29
|
+
// []
|
30
|
+
EXPECT(list.empty() == true);
|
31
|
+
|
32
|
+
// [A]
|
33
|
+
list.append(a);
|
34
|
+
EXPECT(list.empty() == false);
|
35
|
+
EXPECT(list.first() == a);
|
36
|
+
EXPECT(list.last() == a);
|
37
|
+
EXPECT(a->prev() == nullptr);
|
38
|
+
EXPECT(a->next() == nullptr);
|
39
|
+
|
40
|
+
// [A, B]
|
41
|
+
list.append(b);
|
42
|
+
EXPECT(list.first() == a);
|
43
|
+
EXPECT(list.last() == b);
|
44
|
+
EXPECT(a->prev() == nullptr);
|
45
|
+
EXPECT(a->next() == b);
|
46
|
+
EXPECT(b->prev() == a);
|
47
|
+
EXPECT(b->next() == nullptr);
|
48
|
+
|
49
|
+
// [A, B, C]
|
50
|
+
list.append(c);
|
51
|
+
EXPECT(list.first() == a);
|
52
|
+
EXPECT(list.last() == c);
|
53
|
+
EXPECT(a->prev() == nullptr);
|
54
|
+
EXPECT(a->next() == b);
|
55
|
+
EXPECT(b->prev() == a);
|
56
|
+
EXPECT(b->next() == c);
|
57
|
+
EXPECT(c->prev() == b);
|
58
|
+
EXPECT(c->next() == nullptr);
|
59
|
+
|
60
|
+
// [B, C]
|
61
|
+
list.unlink(a);
|
62
|
+
EXPECT(list.first() == b);
|
63
|
+
EXPECT(list.last() == c);
|
64
|
+
EXPECT(a->prev() == nullptr);
|
65
|
+
EXPECT(a->next() == nullptr);
|
66
|
+
EXPECT(b->prev() == nullptr);
|
67
|
+
EXPECT(b->next() == c);
|
68
|
+
EXPECT(c->prev() == b);
|
69
|
+
EXPECT(c->next() == nullptr);
|
70
|
+
|
71
|
+
// [B]
|
72
|
+
list.unlink(c);
|
73
|
+
EXPECT(list.first() == b);
|
74
|
+
EXPECT(list.last() == b);
|
75
|
+
EXPECT(b->prev() == nullptr);
|
76
|
+
EXPECT(b->next() == nullptr);
|
77
|
+
EXPECT(c->prev() == nullptr);
|
78
|
+
EXPECT(c->next() == nullptr);
|
79
|
+
|
80
|
+
// []
|
81
|
+
list.unlink(b);
|
82
|
+
EXPECT(list.empty() == true);
|
83
|
+
EXPECT(list.first() == nullptr);
|
84
|
+
EXPECT(list.last() == nullptr);
|
85
|
+
EXPECT(b->prev() == nullptr);
|
86
|
+
EXPECT(b->next() == nullptr);
|
87
|
+
|
88
|
+
INFO("Prepend / Unlink");
|
89
|
+
|
90
|
+
// [A]
|
91
|
+
list.prepend(a);
|
92
|
+
EXPECT(list.empty() == false);
|
93
|
+
EXPECT(list.first() == a);
|
94
|
+
EXPECT(list.last() == a);
|
95
|
+
EXPECT(a->prev() == nullptr);
|
96
|
+
EXPECT(a->next() == nullptr);
|
97
|
+
|
98
|
+
// [B, A]
|
99
|
+
list.prepend(b);
|
100
|
+
EXPECT(list.first() == b);
|
101
|
+
EXPECT(list.last() == a);
|
102
|
+
EXPECT(b->prev() == nullptr);
|
103
|
+
EXPECT(b->next() == a);
|
104
|
+
EXPECT(a->prev() == b);
|
105
|
+
EXPECT(a->next() == nullptr);
|
106
|
+
|
107
|
+
INFO("InsertAfter / InsertBefore");
|
108
|
+
|
109
|
+
// [B, A, C]
|
110
|
+
list.insertAfter(a, c);
|
111
|
+
EXPECT(list.first() == b);
|
112
|
+
EXPECT(list.last() == c);
|
113
|
+
EXPECT(b->prev() == nullptr);
|
114
|
+
EXPECT(b->next() == a);
|
115
|
+
EXPECT(a->prev() == b);
|
116
|
+
EXPECT(a->next() == c);
|
117
|
+
EXPECT(c->prev() == a);
|
118
|
+
EXPECT(c->next() == nullptr);
|
119
|
+
|
120
|
+
// [B, D, A, C]
|
121
|
+
list.insertBefore(a, d);
|
122
|
+
EXPECT(list.first() == b);
|
123
|
+
EXPECT(list.last() == c);
|
124
|
+
EXPECT(b->prev() == nullptr);
|
125
|
+
EXPECT(b->next() == d);
|
126
|
+
EXPECT(d->prev() == b);
|
127
|
+
EXPECT(d->next() == a);
|
128
|
+
EXPECT(a->prev() == d);
|
129
|
+
EXPECT(a->next() == c);
|
130
|
+
EXPECT(c->prev() == a);
|
131
|
+
EXPECT(c->next() == nullptr);
|
132
|
+
|
133
|
+
INFO("PopFirst / Pop");
|
134
|
+
|
135
|
+
// [D, A, C]
|
136
|
+
EXPECT(list.popFirst() == b);
|
137
|
+
EXPECT(b->prev() == nullptr);
|
138
|
+
EXPECT(b->next() == nullptr);
|
139
|
+
|
140
|
+
EXPECT(list.first() == d);
|
141
|
+
EXPECT(list.last() == c);
|
142
|
+
EXPECT(d->prev() == nullptr);
|
143
|
+
EXPECT(d->next() == a);
|
144
|
+
EXPECT(a->prev() == d);
|
145
|
+
EXPECT(a->next() == c);
|
146
|
+
EXPECT(c->prev() == a);
|
147
|
+
EXPECT(c->next() == nullptr);
|
148
|
+
|
149
|
+
// [D, A]
|
150
|
+
EXPECT(list.pop() == c);
|
151
|
+
EXPECT(c->prev() == nullptr);
|
152
|
+
EXPECT(c->next() == nullptr);
|
153
|
+
|
154
|
+
EXPECT(list.first() == d);
|
155
|
+
EXPECT(list.last() == a);
|
156
|
+
EXPECT(d->prev() == nullptr);
|
157
|
+
EXPECT(d->next() == a);
|
158
|
+
EXPECT(a->prev() == d);
|
159
|
+
EXPECT(a->next() == nullptr);
|
160
|
+
}
|
161
|
+
#endif
|
162
|
+
|
163
|
+
ASMJIT_END_NAMESPACE
|