asmjit 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/asmjit.gemspec +1 -1
  4. data/ext/asmjit/asmjit/.editorconfig +10 -0
  5. data/ext/asmjit/asmjit/.github/FUNDING.yml +1 -0
  6. data/ext/asmjit/asmjit/.github/workflows/build-config.json +47 -0
  7. data/ext/asmjit/asmjit/.github/workflows/build.yml +156 -0
  8. data/ext/asmjit/asmjit/.gitignore +6 -0
  9. data/ext/asmjit/asmjit/CMakeLists.txt +611 -0
  10. data/ext/asmjit/asmjit/LICENSE.md +17 -0
  11. data/ext/asmjit/asmjit/README.md +69 -0
  12. data/ext/asmjit/asmjit/src/asmjit/a64.h +62 -0
  13. data/ext/asmjit/asmjit/src/asmjit/arm/a64archtraits_p.h +81 -0
  14. data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.cpp +5115 -0
  15. data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.h +72 -0
  16. data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.cpp +51 -0
  17. data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.h +57 -0
  18. data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.cpp +60 -0
  19. data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.h +247 -0
  20. data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper.cpp +464 -0
  21. data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper_p.h +50 -0
  22. data/ext/asmjit/asmjit/src/asmjit/arm/a64emitter.h +1228 -0
  23. data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter.cpp +298 -0
  24. data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter_p.h +59 -0
  25. data/ext/asmjit/asmjit/src/asmjit/arm/a64func.cpp +189 -0
  26. data/ext/asmjit/asmjit/src/asmjit/arm/a64func_p.h +33 -0
  27. data/ext/asmjit/asmjit/src/asmjit/arm/a64globals.h +1894 -0
  28. data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi.cpp +278 -0
  29. data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi_p.h +41 -0
  30. data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.cpp +1957 -0
  31. data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.h +74 -0
  32. data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb_p.h +876 -0
  33. data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.cpp +85 -0
  34. data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.h +312 -0
  35. data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass.cpp +852 -0
  36. data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass_p.h +105 -0
  37. data/ext/asmjit/asmjit/src/asmjit/arm/a64utils.h +179 -0
  38. data/ext/asmjit/asmjit/src/asmjit/arm/armformatter.cpp +143 -0
  39. data/ext/asmjit/asmjit/src/asmjit/arm/armformatter_p.h +44 -0
  40. data/ext/asmjit/asmjit/src/asmjit/arm/armglobals.h +21 -0
  41. data/ext/asmjit/asmjit/src/asmjit/arm/armoperand.h +621 -0
  42. data/ext/asmjit/asmjit/src/asmjit/arm.h +62 -0
  43. data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-begin.h +17 -0
  44. data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-end.h +9 -0
  45. data/ext/asmjit/asmjit/src/asmjit/asmjit.h +33 -0
  46. data/ext/asmjit/asmjit/src/asmjit/core/api-build_p.h +55 -0
  47. data/ext/asmjit/asmjit/src/asmjit/core/api-config.h +613 -0
  48. data/ext/asmjit/asmjit/src/asmjit/core/archcommons.h +229 -0
  49. data/ext/asmjit/asmjit/src/asmjit/core/archtraits.cpp +160 -0
  50. data/ext/asmjit/asmjit/src/asmjit/core/archtraits.h +290 -0
  51. data/ext/asmjit/asmjit/src/asmjit/core/assembler.cpp +406 -0
  52. data/ext/asmjit/asmjit/src/asmjit/core/assembler.h +129 -0
  53. data/ext/asmjit/asmjit/src/asmjit/core/builder.cpp +889 -0
  54. data/ext/asmjit/asmjit/src/asmjit/core/builder.h +1391 -0
  55. data/ext/asmjit/asmjit/src/asmjit/core/codebuffer.h +113 -0
  56. data/ext/asmjit/asmjit/src/asmjit/core/codeholder.cpp +1149 -0
  57. data/ext/asmjit/asmjit/src/asmjit/core/codeholder.h +1035 -0
  58. data/ext/asmjit/asmjit/src/asmjit/core/codewriter.cpp +175 -0
  59. data/ext/asmjit/asmjit/src/asmjit/core/codewriter_p.h +179 -0
  60. data/ext/asmjit/asmjit/src/asmjit/core/compiler.cpp +582 -0
  61. data/ext/asmjit/asmjit/src/asmjit/core/compiler.h +737 -0
  62. data/ext/asmjit/asmjit/src/asmjit/core/compilerdefs.h +173 -0
  63. data/ext/asmjit/asmjit/src/asmjit/core/constpool.cpp +363 -0
  64. data/ext/asmjit/asmjit/src/asmjit/core/constpool.h +250 -0
  65. data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.cpp +1162 -0
  66. data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.h +813 -0
  67. data/ext/asmjit/asmjit/src/asmjit/core/emithelper.cpp +323 -0
  68. data/ext/asmjit/asmjit/src/asmjit/core/emithelper_p.h +58 -0
  69. data/ext/asmjit/asmjit/src/asmjit/core/emitter.cpp +333 -0
  70. data/ext/asmjit/asmjit/src/asmjit/core/emitter.h +741 -0
  71. data/ext/asmjit/asmjit/src/asmjit/core/emitterutils.cpp +129 -0
  72. data/ext/asmjit/asmjit/src/asmjit/core/emitterutils_p.h +89 -0
  73. data/ext/asmjit/asmjit/src/asmjit/core/environment.cpp +46 -0
  74. data/ext/asmjit/asmjit/src/asmjit/core/environment.h +508 -0
  75. data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.cpp +14 -0
  76. data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.h +228 -0
  77. data/ext/asmjit/asmjit/src/asmjit/core/formatter.cpp +584 -0
  78. data/ext/asmjit/asmjit/src/asmjit/core/formatter.h +247 -0
  79. data/ext/asmjit/asmjit/src/asmjit/core/formatter_p.h +34 -0
  80. data/ext/asmjit/asmjit/src/asmjit/core/func.cpp +286 -0
  81. data/ext/asmjit/asmjit/src/asmjit/core/func.h +1445 -0
  82. data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext.cpp +293 -0
  83. data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext_p.h +199 -0
  84. data/ext/asmjit/asmjit/src/asmjit/core/globals.cpp +133 -0
  85. data/ext/asmjit/asmjit/src/asmjit/core/globals.h +393 -0
  86. data/ext/asmjit/asmjit/src/asmjit/core/inst.cpp +113 -0
  87. data/ext/asmjit/asmjit/src/asmjit/core/inst.h +772 -0
  88. data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.cpp +1242 -0
  89. data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.h +261 -0
  90. data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.cpp +80 -0
  91. data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.h +89 -0
  92. data/ext/asmjit/asmjit/src/asmjit/core/logger.cpp +69 -0
  93. data/ext/asmjit/asmjit/src/asmjit/core/logger.h +198 -0
  94. data/ext/asmjit/asmjit/src/asmjit/core/misc_p.h +33 -0
  95. data/ext/asmjit/asmjit/src/asmjit/core/operand.cpp +132 -0
  96. data/ext/asmjit/asmjit/src/asmjit/core/operand.h +1611 -0
  97. data/ext/asmjit/asmjit/src/asmjit/core/osutils.cpp +84 -0
  98. data/ext/asmjit/asmjit/src/asmjit/core/osutils.h +61 -0
  99. data/ext/asmjit/asmjit/src/asmjit/core/osutils_p.h +68 -0
  100. data/ext/asmjit/asmjit/src/asmjit/core/raassignment_p.h +418 -0
  101. data/ext/asmjit/asmjit/src/asmjit/core/rabuilders_p.h +612 -0
  102. data/ext/asmjit/asmjit/src/asmjit/core/radefs_p.h +1204 -0
  103. data/ext/asmjit/asmjit/src/asmjit/core/ralocal.cpp +1166 -0
  104. data/ext/asmjit/asmjit/src/asmjit/core/ralocal_p.h +254 -0
  105. data/ext/asmjit/asmjit/src/asmjit/core/rapass.cpp +1969 -0
  106. data/ext/asmjit/asmjit/src/asmjit/core/rapass_p.h +1183 -0
  107. data/ext/asmjit/asmjit/src/asmjit/core/rastack.cpp +184 -0
  108. data/ext/asmjit/asmjit/src/asmjit/core/rastack_p.h +171 -0
  109. data/ext/asmjit/asmjit/src/asmjit/core/string.cpp +559 -0
  110. data/ext/asmjit/asmjit/src/asmjit/core/string.h +372 -0
  111. data/ext/asmjit/asmjit/src/asmjit/core/support.cpp +494 -0
  112. data/ext/asmjit/asmjit/src/asmjit/core/support.h +1773 -0
  113. data/ext/asmjit/asmjit/src/asmjit/core/target.cpp +14 -0
  114. data/ext/asmjit/asmjit/src/asmjit/core/target.h +53 -0
  115. data/ext/asmjit/asmjit/src/asmjit/core/type.cpp +74 -0
  116. data/ext/asmjit/asmjit/src/asmjit/core/type.h +419 -0
  117. data/ext/asmjit/asmjit/src/asmjit/core/virtmem.cpp +722 -0
  118. data/ext/asmjit/asmjit/src/asmjit/core/virtmem.h +242 -0
  119. data/ext/asmjit/asmjit/src/asmjit/core/zone.cpp +353 -0
  120. data/ext/asmjit/asmjit/src/asmjit/core/zone.h +615 -0
  121. data/ext/asmjit/asmjit/src/asmjit/core/zonehash.cpp +309 -0
  122. data/ext/asmjit/asmjit/src/asmjit/core/zonehash.h +186 -0
  123. data/ext/asmjit/asmjit/src/asmjit/core/zonelist.cpp +163 -0
  124. data/ext/asmjit/asmjit/src/asmjit/core/zonelist.h +209 -0
  125. data/ext/asmjit/asmjit/src/asmjit/core/zonestack.cpp +176 -0
  126. data/ext/asmjit/asmjit/src/asmjit/core/zonestack.h +239 -0
  127. data/ext/asmjit/asmjit/src/asmjit/core/zonestring.h +120 -0
  128. data/ext/asmjit/asmjit/src/asmjit/core/zonetree.cpp +99 -0
  129. data/ext/asmjit/asmjit/src/asmjit/core/zonetree.h +380 -0
  130. data/ext/asmjit/asmjit/src/asmjit/core/zonevector.cpp +356 -0
  131. data/ext/asmjit/asmjit/src/asmjit/core/zonevector.h +690 -0
  132. data/ext/asmjit/asmjit/src/asmjit/core.h +1861 -0
  133. data/ext/asmjit/asmjit/src/asmjit/x86/x86archtraits_p.h +148 -0
  134. data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.cpp +5110 -0
  135. data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.h +685 -0
  136. data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.cpp +52 -0
  137. data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.h +351 -0
  138. data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.cpp +61 -0
  139. data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.h +721 -0
  140. data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper.cpp +619 -0
  141. data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper_p.h +60 -0
  142. data/ext/asmjit/asmjit/src/asmjit/x86/x86emitter.h +4315 -0
  143. data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter.cpp +944 -0
  144. data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter_p.h +58 -0
  145. data/ext/asmjit/asmjit/src/asmjit/x86/x86func.cpp +503 -0
  146. data/ext/asmjit/asmjit/src/asmjit/x86/x86func_p.h +33 -0
  147. data/ext/asmjit/asmjit/src/asmjit/x86/x86globals.h +2169 -0
  148. data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi.cpp +1732 -0
  149. data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi_p.h +41 -0
  150. data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.cpp +4427 -0
  151. data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.h +563 -0
  152. data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb_p.h +311 -0
  153. data/ext/asmjit/asmjit/src/asmjit/x86/x86opcode_p.h +436 -0
  154. data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.cpp +231 -0
  155. data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.h +1085 -0
  156. data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass.cpp +1509 -0
  157. data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass_p.h +94 -0
  158. data/ext/asmjit/asmjit/src/asmjit/x86.h +93 -0
  159. data/ext/asmjit/asmjit/src/asmjit.natvis +245 -0
  160. data/ext/asmjit/asmjit/test/asmjit_test_assembler.cpp +84 -0
  161. data/ext/asmjit/asmjit/test/asmjit_test_assembler.h +85 -0
  162. data/ext/asmjit/asmjit/test/asmjit_test_assembler_a64.cpp +4006 -0
  163. data/ext/asmjit/asmjit/test/asmjit_test_assembler_x64.cpp +17833 -0
  164. data/ext/asmjit/asmjit/test/asmjit_test_assembler_x86.cpp +8300 -0
  165. data/ext/asmjit/asmjit/test/asmjit_test_compiler.cpp +253 -0
  166. data/ext/asmjit/asmjit/test/asmjit_test_compiler.h +73 -0
  167. data/ext/asmjit/asmjit/test/asmjit_test_compiler_a64.cpp +690 -0
  168. data/ext/asmjit/asmjit/test/asmjit_test_compiler_x86.cpp +4317 -0
  169. data/ext/asmjit/asmjit/test/asmjit_test_emitters.cpp +197 -0
  170. data/ext/asmjit/asmjit/test/asmjit_test_instinfo.cpp +181 -0
  171. data/ext/asmjit/asmjit/test/asmjit_test_misc.h +257 -0
  172. data/ext/asmjit/asmjit/test/asmjit_test_perf.cpp +62 -0
  173. data/ext/asmjit/asmjit/test/asmjit_test_perf.h +61 -0
  174. data/ext/asmjit/asmjit/test/asmjit_test_perf_a64.cpp +699 -0
  175. data/ext/asmjit/asmjit/test/asmjit_test_perf_x86.cpp +5032 -0
  176. data/ext/asmjit/asmjit/test/asmjit_test_unit.cpp +172 -0
  177. data/ext/asmjit/asmjit/test/asmjit_test_x86_sections.cpp +172 -0
  178. data/ext/asmjit/asmjit/test/asmjitutils.h +38 -0
  179. data/ext/asmjit/asmjit/test/broken.cpp +312 -0
  180. data/ext/asmjit/asmjit/test/broken.h +148 -0
  181. data/ext/asmjit/asmjit/test/cmdline.h +61 -0
  182. data/ext/asmjit/asmjit/test/performancetimer.h +41 -0
  183. data/ext/asmjit/asmjit/tools/configure-makefiles.sh +13 -0
  184. data/ext/asmjit/asmjit/tools/configure-ninja.sh +13 -0
  185. data/ext/asmjit/asmjit/tools/configure-sanitizers.sh +13 -0
  186. data/ext/asmjit/asmjit/tools/configure-vs2019-x64.bat +2 -0
  187. data/ext/asmjit/asmjit/tools/configure-vs2019-x86.bat +2 -0
  188. data/ext/asmjit/asmjit/tools/configure-vs2022-x64.bat +2 -0
  189. data/ext/asmjit/asmjit/tools/configure-vs2022-x86.bat +2 -0
  190. data/ext/asmjit/asmjit/tools/configure-xcode.sh +8 -0
  191. data/ext/asmjit/asmjit/tools/enumgen.js +417 -0
  192. data/ext/asmjit/asmjit/tools/enumgen.sh +3 -0
  193. data/ext/asmjit/asmjit/tools/tablegen-arm.js +365 -0
  194. data/ext/asmjit/asmjit/tools/tablegen-arm.sh +3 -0
  195. data/ext/asmjit/asmjit/tools/tablegen-x86.js +2638 -0
  196. data/ext/asmjit/asmjit/tools/tablegen-x86.sh +3 -0
  197. data/ext/asmjit/asmjit/tools/tablegen.js +947 -0
  198. data/ext/asmjit/asmjit/tools/tablegen.sh +4 -0
  199. data/ext/asmjit/asmjit.cc +18 -0
  200. data/lib/asmjit/version.rb +1 -1
  201. metadata +197 -2
@@ -0,0 +1,209 @@
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_ZONELIST_H_INCLUDED
7
+ #define ASMJIT_CORE_ZONELIST_H_INCLUDED
8
+
9
+ #include "../core/support.h"
10
+
11
+ ASMJIT_BEGIN_NAMESPACE
12
+
13
+ //! \addtogroup asmjit_zone
14
+ //! \{
15
+
16
+ //! Node used by \ref ZoneList template.
17
+ template<typename NodeT>
18
+ class ZoneListNode {
19
+ public:
20
+ ASMJIT_NONCOPYABLE(ZoneListNode)
21
+
22
+ //! \name Constants
23
+ //! \{
24
+
25
+ enum : size_t {
26
+ kNodeIndexPrev = 0,
27
+ kNodeIndexNext = 1
28
+ };
29
+
30
+ //! \}
31
+
32
+ //! \name Members
33
+ //! \{
34
+
35
+ NodeT* _listNodes[2];
36
+
37
+ //! \}
38
+
39
+ //! \name Construction & Destruction
40
+ //! \{
41
+
42
+ inline ZoneListNode() noexcept
43
+ : _listNodes { nullptr, nullptr } {}
44
+
45
+ inline ZoneListNode(ZoneListNode&& other) noexcept
46
+ : _listNodes { other._listNodes[0], other._listNodes[1] } {}
47
+
48
+ //! \}
49
+
50
+ //! \name Accessors
51
+ //! \{
52
+
53
+ inline bool hasPrev() const noexcept { return _listNodes[kNodeIndexPrev] != nullptr; }
54
+ inline bool hasNext() const noexcept { return _listNodes[kNodeIndexNext] != nullptr; }
55
+
56
+ inline NodeT* prev() const noexcept { return _listNodes[kNodeIndexPrev]; }
57
+ inline NodeT* next() const noexcept { return _listNodes[kNodeIndexNext]; }
58
+
59
+ //! \}
60
+ };
61
+
62
+ //! Zone allocated list container that uses nodes of `NodeT` type.
63
+ template <typename NodeT>
64
+ class ZoneList {
65
+ public:
66
+ ASMJIT_NONCOPYABLE(ZoneList)
67
+
68
+ //! \name Constants
69
+ //! \{
70
+
71
+ enum : size_t {
72
+ kNodeIndexFirst = 0,
73
+ kNodeIndexLast = 1
74
+ };
75
+
76
+ //! \}
77
+
78
+ //! \name Members
79
+ //! \{
80
+
81
+ NodeT* _nodes[2];
82
+
83
+ //! \}
84
+
85
+ //! \name Construction & Destruction
86
+ //! \{
87
+
88
+ inline ZoneList() noexcept
89
+ : _nodes { nullptr, nullptr } {}
90
+
91
+ inline ZoneList(ZoneList&& other) noexcept
92
+ : _nodes { other._nodes[0], other._nodes[1] } {}
93
+
94
+ inline void reset() noexcept {
95
+ _nodes[0] = nullptr;
96
+ _nodes[1] = nullptr;
97
+ }
98
+
99
+ //! \}
100
+
101
+ //! \name Accessors
102
+ //! \{
103
+
104
+ inline bool empty() const noexcept { return _nodes[0] == nullptr; }
105
+ inline NodeT* first() const noexcept { return _nodes[kNodeIndexFirst]; }
106
+ inline NodeT* last() const noexcept { return _nodes[kNodeIndexLast]; }
107
+
108
+ //! \}
109
+
110
+ //! \name Utilities
111
+ //! \{
112
+
113
+ inline void swap(ZoneList& other) noexcept {
114
+ std::swap(_nodes[0], other._nodes[0]);
115
+ std::swap(_nodes[1], other._nodes[1]);
116
+ }
117
+
118
+ // Can be used to both append and prepend.
119
+ inline void _addNode(NodeT* node, size_t dir) noexcept {
120
+ NodeT* prev = _nodes[dir];
121
+
122
+ node->_listNodes[!dir] = prev;
123
+ _nodes[dir] = node;
124
+ if (prev)
125
+ prev->_listNodes[dir] = node;
126
+ else
127
+ _nodes[!dir] = node;
128
+ }
129
+
130
+ // Can be used to both append and prepend.
131
+ inline void _insertNode(NodeT* ref, NodeT* node, size_t dir) noexcept {
132
+ ASMJIT_ASSERT(ref != nullptr);
133
+
134
+ NodeT* prev = ref;
135
+ NodeT* next = ref->_listNodes[dir];
136
+
137
+ prev->_listNodes[dir] = node;
138
+ if (next)
139
+ next->_listNodes[!dir] = node;
140
+ else
141
+ _nodes[dir] = node;
142
+
143
+ node->_listNodes[!dir] = prev;
144
+ node->_listNodes[ dir] = next;
145
+ }
146
+
147
+ inline void append(NodeT* node) noexcept { _addNode(node, kNodeIndexLast); }
148
+ inline void prepend(NodeT* node) noexcept { _addNode(node, kNodeIndexFirst); }
149
+
150
+ inline void insertAfter(NodeT* ref, NodeT* node) noexcept { _insertNode(ref, node, NodeT::kNodeIndexNext); }
151
+ inline void insertBefore(NodeT* ref, NodeT* node) noexcept { _insertNode(ref, node, NodeT::kNodeIndexPrev); }
152
+
153
+ inline NodeT* unlink(NodeT* node) noexcept {
154
+ NodeT* prev = node->prev();
155
+ NodeT* next = node->next();
156
+
157
+ if (prev) { prev->_listNodes[1] = next; node->_listNodes[0] = nullptr; } else { _nodes[0] = next; }
158
+ if (next) { next->_listNodes[0] = prev; node->_listNodes[1] = nullptr; } else { _nodes[1] = prev; }
159
+
160
+ node->_listNodes[0] = nullptr;
161
+ node->_listNodes[1] = nullptr;
162
+
163
+ return node;
164
+ }
165
+
166
+ inline NodeT* popFirst() noexcept {
167
+ NodeT* node = _nodes[0];
168
+ ASMJIT_ASSERT(node != nullptr);
169
+
170
+ NodeT* next = node->next();
171
+ _nodes[0] = next;
172
+
173
+ if (next) {
174
+ next->_listNodes[0] = nullptr;
175
+ node->_listNodes[1] = nullptr;
176
+ }
177
+ else {
178
+ _nodes[1] = nullptr;
179
+ }
180
+
181
+ return node;
182
+ }
183
+
184
+ inline NodeT* pop() noexcept {
185
+ NodeT* node = _nodes[1];
186
+ ASMJIT_ASSERT(node != nullptr);
187
+
188
+ NodeT* prev = node->prev();
189
+ _nodes[1] = prev;
190
+
191
+ if (prev) {
192
+ prev->_listNodes[1] = nullptr;
193
+ node->_listNodes[0] = nullptr;
194
+ }
195
+ else {
196
+ _nodes[0] = nullptr;
197
+ }
198
+
199
+ return node;
200
+ }
201
+
202
+ //! \}
203
+ };
204
+
205
+ //! \}
206
+
207
+ ASMJIT_END_NAMESPACE
208
+
209
+ #endif // ASMJIT_CORE_ZONELIST_H_INCLUDED
@@ -0,0 +1,176 @@
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/zonestack.h"
9
+
10
+ ASMJIT_BEGIN_NAMESPACE
11
+
12
+ // ZoneStackBase - Init & Reset
13
+ // ============================
14
+
15
+ Error ZoneStackBase::_init(ZoneAllocator* allocator, size_t middleIndex) noexcept {
16
+ ZoneAllocator* oldAllocator = _allocator;
17
+
18
+ if (oldAllocator) {
19
+ Block* block = _block[kBlockIndexFirst];
20
+ while (block) {
21
+ Block* next = block->next();
22
+ oldAllocator->release(block, kBlockSize);
23
+ block = next;
24
+ }
25
+
26
+ _allocator = nullptr;
27
+ _block[kBlockIndexFirst] = nullptr;
28
+ _block[kBlockIndexLast] = nullptr;
29
+ }
30
+
31
+ if (allocator) {
32
+ Block* block = static_cast<Block*>(allocator->alloc(kBlockSize));
33
+ if (ASMJIT_UNLIKELY(!block))
34
+ return DebugUtils::errored(kErrorOutOfMemory);
35
+
36
+ block->_link[kBlockIndexPrev] = nullptr;
37
+ block->_link[kBlockIndexNext] = nullptr;
38
+ block->_start = (uint8_t*)block + middleIndex;
39
+ block->_end = (uint8_t*)block + middleIndex;
40
+
41
+ _allocator = allocator;
42
+ _block[kBlockIndexFirst] = block;
43
+ _block[kBlockIndexLast] = block;
44
+ }
45
+
46
+ return kErrorOk;
47
+ }
48
+
49
+ // ZoneStackBase - Operations
50
+ // ==========================
51
+
52
+ Error ZoneStackBase::_prepareBlock(uint32_t side, size_t initialIndex) noexcept {
53
+ ASMJIT_ASSERT(isInitialized());
54
+
55
+ Block* prev = _block[side];
56
+ ASMJIT_ASSERT(!prev->empty());
57
+
58
+ Block* block = _allocator->allocT<Block>(kBlockSize);
59
+ if (ASMJIT_UNLIKELY(!block))
60
+ return DebugUtils::errored(kErrorOutOfMemory);
61
+
62
+ block->_link[ side] = nullptr;
63
+ block->_link[!side] = prev;
64
+ block->_start = (uint8_t*)block + initialIndex;
65
+ block->_end = (uint8_t*)block + initialIndex;
66
+
67
+ prev->_link[side] = block;
68
+ _block[side] = block;
69
+
70
+ return kErrorOk;
71
+ }
72
+
73
+ void ZoneStackBase::_cleanupBlock(uint32_t side, size_t middleIndex) noexcept {
74
+ Block* block = _block[side];
75
+ ASMJIT_ASSERT(block->empty());
76
+
77
+ Block* prev = block->_link[!side];
78
+ if (prev) {
79
+ ASMJIT_ASSERT(prev->_link[side] == block);
80
+ _allocator->release(block, kBlockSize);
81
+
82
+ prev->_link[side] = nullptr;
83
+ _block[side] = prev;
84
+ }
85
+ else if (_block[!side] == block) {
86
+ // If the container becomes empty center both pointers in the remaining block.
87
+ block->_start = (uint8_t*)block + middleIndex;
88
+ block->_end = (uint8_t*)block + middleIndex;
89
+ }
90
+ }
91
+
92
+ // ZoneStack - Tests
93
+ // =================
94
+
95
+ #if defined(ASMJIT_TEST)
96
+ template<typename T>
97
+ static void test_zone_stack(ZoneAllocator* allocator, const char* typeName) {
98
+ ZoneStack<T> stack;
99
+
100
+ INFO("Testing ZoneStack<%s>", typeName);
101
+ INFO(" (%d items per one Block)", ZoneStack<T>::kNumBlockItems);
102
+
103
+ EXPECT(stack.init(allocator) == kErrorOk);
104
+ EXPECT(stack.empty(), "Stack must be empty after `init()`");
105
+
106
+ EXPECT(stack.append(42) == kErrorOk);
107
+ EXPECT(!stack.empty() , "Stack must not be empty after an item has been appended");
108
+ EXPECT(stack.pop() == 42 , "Stack.pop() must return the item that has been appended last");
109
+ EXPECT(stack.empty() , "Stack must be empty after the last item has been removed");
110
+
111
+ EXPECT(stack.prepend(43) == kErrorOk);
112
+ EXPECT(!stack.empty() , "Stack must not be empty after an item has been prepended");
113
+ EXPECT(stack.popFirst() == 43, "Stack.popFirst() must return the item that has been prepended last");
114
+ EXPECT(stack.empty() , "Stack must be empty after the last item has been removed");
115
+
116
+ int i;
117
+ int iMin =-100000;
118
+ int iMax = 100000;
119
+
120
+ INFO("Validating prepend() & popFirst()");
121
+ for (i = iMax; i >= 0; i--) stack.prepend(T(i));
122
+ for (i = 0; i <= iMax; i++) {
123
+ T item = stack.popFirst();
124
+ EXPECT(i == item, "Item '%d' didn't match the item '%lld' popped", i, (long long)item);
125
+ if (!stack.empty()) {
126
+ item = stack.popFirst();
127
+ EXPECT(i + 1 == item, "Item '%d' didn't match the item '%lld' popped", i + 1, (long long)item);
128
+ stack.prepend(item);
129
+ }
130
+ }
131
+ EXPECT(stack.empty());
132
+
133
+ INFO("Validating append() & pop()");
134
+ for (i = 0; i <= iMax; i++) stack.append(T(i));
135
+ for (i = iMax; i >= 0; i--) {
136
+ T item = stack.pop();
137
+ EXPECT(i == item, "Item '%d' didn't match the item '%lld' popped", i, (long long)item);
138
+ if (!stack.empty()) {
139
+ item = stack.pop();
140
+ EXPECT(i - 1 == item, "Item '%d' didn't match the item '%lld' popped", i - 1, (long long)item);
141
+ stack.append(item);
142
+ }
143
+ }
144
+ EXPECT(stack.empty());
145
+
146
+ INFO("Validating append()/prepend() & popFirst()");
147
+ for (i = 1; i <= iMax; i++) stack.append(T(i));
148
+ for (i = 0; i >= iMin; i--) stack.prepend(T(i));
149
+
150
+ for (i = iMin; i <= iMax; i++) {
151
+ T item = stack.popFirst();
152
+ EXPECT(i == item, "Item '%d' didn't match the item '%lld' popped", i, (long long)item);
153
+ }
154
+ EXPECT(stack.empty());
155
+
156
+ INFO("Validating append()/prepend() & pop()");
157
+ for (i = 0; i >= iMin; i--) stack.prepend(T(i));
158
+ for (i = 1; i <= iMax; i++) stack.append(T(i));
159
+
160
+ for (i = iMax; i >= iMin; i--) {
161
+ T item = stack.pop();
162
+ EXPECT(i == item, "Item '%d' didn't match the item '%lld' popped", i, (long long)item);
163
+ }
164
+ EXPECT(stack.empty());
165
+ }
166
+
167
+ UNIT(zone_stack) {
168
+ Zone zone(8096 - Zone::kBlockOverhead);
169
+ ZoneAllocator allocator(&zone);
170
+
171
+ test_zone_stack<int>(&allocator, "int");
172
+ test_zone_stack<int64_t>(&allocator, "int64_t");
173
+ }
174
+ #endif
175
+
176
+ ASMJIT_END_NAMESPACE
@@ -0,0 +1,239 @@
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_ZONESTACK_H_INCLUDED
7
+ #define ASMJIT_CORE_ZONESTACK_H_INCLUDED
8
+
9
+ #include "../core/zone.h"
10
+
11
+ ASMJIT_BEGIN_NAMESPACE
12
+
13
+ //! \addtogroup asmjit_zone
14
+ //! \{
15
+
16
+ //! Base class used by \ref ZoneStack.
17
+ class ZoneStackBase {
18
+ public:
19
+ ASMJIT_NONCOPYABLE(ZoneStackBase)
20
+
21
+ //! \name Constants
22
+ //! \{
23
+
24
+ enum : size_t {
25
+ kBlockIndexPrev = 0,
26
+ kBlockIndexNext = 1,
27
+
28
+ kBlockIndexFirst = 0,
29
+ kBlockIndexLast = 1,
30
+
31
+ kBlockSize = ZoneAllocator::kHiMaxSize
32
+ };
33
+
34
+ //! \}
35
+
36
+ //! \name Types
37
+ //! \{
38
+
39
+ struct Block {
40
+ //! Next and previous blocks.
41
+ Block* _link[2];
42
+ //! Pointer to the start of the array.
43
+ void* _start;
44
+ //! Pointer to the end of the array.
45
+ void* _end;
46
+
47
+ inline bool empty() const noexcept { return _start == _end; }
48
+ inline Block* prev() const noexcept { return _link[kBlockIndexPrev]; }
49
+ inline Block* next() const noexcept { return _link[kBlockIndexNext]; }
50
+
51
+ inline void setPrev(Block* block) noexcept { _link[kBlockIndexPrev] = block; }
52
+ inline void setNext(Block* block) noexcept { _link[kBlockIndexNext] = block; }
53
+
54
+ template<typename T>
55
+ inline T* start() const noexcept { return static_cast<T*>(_start); }
56
+ template<typename T>
57
+ inline void setStart(T* start) noexcept { _start = static_cast<void*>(start); }
58
+
59
+ template<typename T>
60
+ inline T* end() const noexcept { return (T*)_end; }
61
+ template<typename T>
62
+ inline void setEnd(T* end) noexcept { _end = (void*)end; }
63
+
64
+ template<typename T>
65
+ inline T* data() const noexcept { return (T*)((uint8_t*)(this) + sizeof(Block)); }
66
+
67
+ template<typename T>
68
+ inline bool canPrepend() const noexcept { return _start > data<void>(); }
69
+
70
+ template<typename T>
71
+ inline bool canAppend() const noexcept {
72
+ size_t kNumBlockItems = (kBlockSize - sizeof(Block)) / sizeof(T);
73
+ size_t kStartBlockIndex = sizeof(Block);
74
+ size_t kEndBlockIndex = kStartBlockIndex + kNumBlockItems * sizeof(T);
75
+
76
+ return (uintptr_t)_end <= ((uintptr_t)this + kEndBlockIndex - sizeof(T));
77
+ }
78
+ };
79
+
80
+ //! \}
81
+
82
+ //! \name Members
83
+ //! \{
84
+
85
+ //! Allocator used to allocate data.
86
+ ZoneAllocator* _allocator;
87
+ //! First and last blocks.
88
+ Block* _block[2];
89
+
90
+ //! \}
91
+
92
+ //! \name Construction & Destruction
93
+ //! \{
94
+
95
+ inline ZoneStackBase() noexcept {
96
+ _allocator = nullptr;
97
+ _block[0] = nullptr;
98
+ _block[1] = nullptr;
99
+ }
100
+ inline ~ZoneStackBase() noexcept { reset(); }
101
+
102
+ inline bool isInitialized() const noexcept { return _allocator != nullptr; }
103
+ ASMJIT_API Error _init(ZoneAllocator* allocator, size_t middleIndex) noexcept;
104
+ inline Error reset() noexcept { return _init(nullptr, 0); }
105
+
106
+ //! \}
107
+
108
+ //! \name Accessors
109
+ //! \{
110
+
111
+ //! Returns `ZoneAllocator` attached to this container.
112
+ inline ZoneAllocator* allocator() const noexcept { return _allocator; }
113
+
114
+ inline bool empty() const noexcept {
115
+ ASMJIT_ASSERT(isInitialized());
116
+ return _block[0]->start<void>() == _block[1]->end<void>();
117
+ }
118
+
119
+ //! \}
120
+
121
+ //! \cond INTERNAL
122
+ //! \name Internal
123
+ //! \{
124
+
125
+ ASMJIT_API Error _prepareBlock(uint32_t side, size_t initialIndex) noexcept;
126
+ ASMJIT_API void _cleanupBlock(uint32_t side, size_t middleIndex) noexcept;
127
+
128
+ //! \}
129
+ //! \endcond
130
+ };
131
+
132
+ //! Zone allocated stack container.
133
+ template<typename T>
134
+ class ZoneStack : public ZoneStackBase {
135
+ public:
136
+ ASMJIT_NONCOPYABLE(ZoneStack)
137
+
138
+ //! \name Constants
139
+ //! \{
140
+
141
+ enum : uint32_t {
142
+ kNumBlockItems = uint32_t((kBlockSize - sizeof(Block)) / sizeof(T)),
143
+ kStartBlockIndex = uint32_t(sizeof(Block)),
144
+ kMidBlockIndex = uint32_t(kStartBlockIndex + (kNumBlockItems / 2) * sizeof(T)),
145
+ kEndBlockIndex = uint32_t(kStartBlockIndex + (kNumBlockItems ) * sizeof(T))
146
+ };
147
+
148
+ //! \}
149
+
150
+ //! \name Construction & Destruction
151
+ //! \{
152
+
153
+ inline ZoneStack() noexcept {}
154
+ inline ~ZoneStack() noexcept {}
155
+
156
+ inline Error init(ZoneAllocator* allocator) noexcept { return _init(allocator, kMidBlockIndex); }
157
+
158
+ //! \}
159
+
160
+ //! \name Utilities
161
+ //! \{
162
+
163
+ inline Error prepend(T item) noexcept {
164
+ ASMJIT_ASSERT(isInitialized());
165
+ Block* block = _block[kBlockIndexFirst];
166
+
167
+ if (!block->canPrepend<T>()) {
168
+ ASMJIT_PROPAGATE(_prepareBlock(kBlockIndexFirst, kEndBlockIndex));
169
+ block = _block[kBlockIndexFirst];
170
+ }
171
+
172
+ T* ptr = block->start<T>() - 1;
173
+ ASMJIT_ASSERT(ptr >= block->data<T>() && ptr <= block->data<T>() + (kNumBlockItems - 1));
174
+ *ptr = item;
175
+ block->setStart<T>(ptr);
176
+ return kErrorOk;
177
+ }
178
+
179
+ inline Error append(T item) noexcept {
180
+ ASMJIT_ASSERT(isInitialized());
181
+ Block* block = _block[kBlockIndexLast];
182
+
183
+ if (!block->canAppend<T>()) {
184
+ ASMJIT_PROPAGATE(_prepareBlock(kBlockIndexLast, kStartBlockIndex));
185
+ block = _block[kBlockIndexLast];
186
+ }
187
+
188
+ T* ptr = block->end<T>();
189
+ ASMJIT_ASSERT(ptr >= block->data<T>() && ptr <= block->data<T>() + (kNumBlockItems - 1));
190
+
191
+ *ptr++ = item;
192
+ block->setEnd(ptr);
193
+ return kErrorOk;
194
+ }
195
+
196
+ inline T popFirst() noexcept {
197
+ ASMJIT_ASSERT(isInitialized());
198
+ ASMJIT_ASSERT(!empty());
199
+
200
+ Block* block = _block[kBlockIndexFirst];
201
+ ASMJIT_ASSERT(!block->empty());
202
+
203
+ T* ptr = block->start<T>();
204
+ T item = *ptr++;
205
+
206
+ block->setStart(ptr);
207
+ if (block->empty())
208
+ _cleanupBlock(kBlockIndexFirst, kMidBlockIndex);
209
+
210
+ return item;
211
+ }
212
+
213
+ inline T pop() noexcept {
214
+ ASMJIT_ASSERT(isInitialized());
215
+ ASMJIT_ASSERT(!empty());
216
+
217
+ Block* block = _block[kBlockIndexLast];
218
+ ASMJIT_ASSERT(!block->empty());
219
+
220
+ T* ptr = block->end<T>();
221
+ T item = *--ptr;
222
+ ASMJIT_ASSERT(ptr >= block->data<T>());
223
+ ASMJIT_ASSERT(ptr >= block->start<T>());
224
+
225
+ block->setEnd(ptr);
226
+ if (block->empty())
227
+ _cleanupBlock(kBlockIndexLast, kMidBlockIndex);
228
+
229
+ return item;
230
+ }
231
+
232
+ //! \}
233
+ };
234
+
235
+ //! \}
236
+
237
+ ASMJIT_END_NAMESPACE
238
+
239
+ #endif // ASMJIT_CORE_ZONESTACK_H_INCLUDED