asmjit 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/Rakefile +5 -3
  4. data/asmjit.gemspec +1 -3
  5. data/ext/asmjit/asmjit/.editorconfig +10 -0
  6. data/ext/asmjit/asmjit/.github/FUNDING.yml +1 -0
  7. data/ext/asmjit/asmjit/.github/workflows/build-config.json +47 -0
  8. data/ext/asmjit/asmjit/.github/workflows/build.yml +156 -0
  9. data/ext/asmjit/asmjit/.gitignore +6 -0
  10. data/ext/asmjit/asmjit/CMakeLists.txt +611 -0
  11. data/ext/asmjit/asmjit/LICENSE.md +17 -0
  12. data/ext/asmjit/asmjit/README.md +69 -0
  13. data/ext/asmjit/asmjit/src/asmjit/a64.h +62 -0
  14. data/ext/asmjit/asmjit/src/asmjit/arm/a64archtraits_p.h +81 -0
  15. data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.cpp +5115 -0
  16. data/ext/asmjit/asmjit/src/asmjit/arm/a64assembler.h +72 -0
  17. data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.cpp +51 -0
  18. data/ext/asmjit/asmjit/src/asmjit/arm/a64builder.h +57 -0
  19. data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.cpp +60 -0
  20. data/ext/asmjit/asmjit/src/asmjit/arm/a64compiler.h +247 -0
  21. data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper.cpp +464 -0
  22. data/ext/asmjit/asmjit/src/asmjit/arm/a64emithelper_p.h +50 -0
  23. data/ext/asmjit/asmjit/src/asmjit/arm/a64emitter.h +1228 -0
  24. data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter.cpp +298 -0
  25. data/ext/asmjit/asmjit/src/asmjit/arm/a64formatter_p.h +59 -0
  26. data/ext/asmjit/asmjit/src/asmjit/arm/a64func.cpp +189 -0
  27. data/ext/asmjit/asmjit/src/asmjit/arm/a64func_p.h +33 -0
  28. data/ext/asmjit/asmjit/src/asmjit/arm/a64globals.h +1894 -0
  29. data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi.cpp +278 -0
  30. data/ext/asmjit/asmjit/src/asmjit/arm/a64instapi_p.h +41 -0
  31. data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.cpp +1957 -0
  32. data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb.h +74 -0
  33. data/ext/asmjit/asmjit/src/asmjit/arm/a64instdb_p.h +876 -0
  34. data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.cpp +85 -0
  35. data/ext/asmjit/asmjit/src/asmjit/arm/a64operand.h +312 -0
  36. data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass.cpp +852 -0
  37. data/ext/asmjit/asmjit/src/asmjit/arm/a64rapass_p.h +105 -0
  38. data/ext/asmjit/asmjit/src/asmjit/arm/a64utils.h +179 -0
  39. data/ext/asmjit/asmjit/src/asmjit/arm/armformatter.cpp +143 -0
  40. data/ext/asmjit/asmjit/src/asmjit/arm/armformatter_p.h +44 -0
  41. data/ext/asmjit/asmjit/src/asmjit/arm/armglobals.h +21 -0
  42. data/ext/asmjit/asmjit/src/asmjit/arm/armoperand.h +621 -0
  43. data/ext/asmjit/asmjit/src/asmjit/arm.h +62 -0
  44. data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-begin.h +17 -0
  45. data/ext/asmjit/asmjit/src/asmjit/asmjit-scope-end.h +9 -0
  46. data/ext/asmjit/asmjit/src/asmjit/asmjit.h +33 -0
  47. data/ext/asmjit/asmjit/src/asmjit/core/api-build_p.h +55 -0
  48. data/ext/asmjit/asmjit/src/asmjit/core/api-config.h +613 -0
  49. data/ext/asmjit/asmjit/src/asmjit/core/archcommons.h +229 -0
  50. data/ext/asmjit/asmjit/src/asmjit/core/archtraits.cpp +160 -0
  51. data/ext/asmjit/asmjit/src/asmjit/core/archtraits.h +290 -0
  52. data/ext/asmjit/asmjit/src/asmjit/core/assembler.cpp +406 -0
  53. data/ext/asmjit/asmjit/src/asmjit/core/assembler.h +129 -0
  54. data/ext/asmjit/asmjit/src/asmjit/core/builder.cpp +889 -0
  55. data/ext/asmjit/asmjit/src/asmjit/core/builder.h +1391 -0
  56. data/ext/asmjit/asmjit/src/asmjit/core/codebuffer.h +113 -0
  57. data/ext/asmjit/asmjit/src/asmjit/core/codeholder.cpp +1149 -0
  58. data/ext/asmjit/asmjit/src/asmjit/core/codeholder.h +1035 -0
  59. data/ext/asmjit/asmjit/src/asmjit/core/codewriter.cpp +175 -0
  60. data/ext/asmjit/asmjit/src/asmjit/core/codewriter_p.h +179 -0
  61. data/ext/asmjit/asmjit/src/asmjit/core/compiler.cpp +582 -0
  62. data/ext/asmjit/asmjit/src/asmjit/core/compiler.h +737 -0
  63. data/ext/asmjit/asmjit/src/asmjit/core/compilerdefs.h +173 -0
  64. data/ext/asmjit/asmjit/src/asmjit/core/constpool.cpp +363 -0
  65. data/ext/asmjit/asmjit/src/asmjit/core/constpool.h +250 -0
  66. data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.cpp +1162 -0
  67. data/ext/asmjit/asmjit/src/asmjit/core/cpuinfo.h +813 -0
  68. data/ext/asmjit/asmjit/src/asmjit/core/emithelper.cpp +323 -0
  69. data/ext/asmjit/asmjit/src/asmjit/core/emithelper_p.h +58 -0
  70. data/ext/asmjit/asmjit/src/asmjit/core/emitter.cpp +333 -0
  71. data/ext/asmjit/asmjit/src/asmjit/core/emitter.h +741 -0
  72. data/ext/asmjit/asmjit/src/asmjit/core/emitterutils.cpp +129 -0
  73. data/ext/asmjit/asmjit/src/asmjit/core/emitterutils_p.h +89 -0
  74. data/ext/asmjit/asmjit/src/asmjit/core/environment.cpp +46 -0
  75. data/ext/asmjit/asmjit/src/asmjit/core/environment.h +508 -0
  76. data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.cpp +14 -0
  77. data/ext/asmjit/asmjit/src/asmjit/core/errorhandler.h +228 -0
  78. data/ext/asmjit/asmjit/src/asmjit/core/formatter.cpp +584 -0
  79. data/ext/asmjit/asmjit/src/asmjit/core/formatter.h +247 -0
  80. data/ext/asmjit/asmjit/src/asmjit/core/formatter_p.h +34 -0
  81. data/ext/asmjit/asmjit/src/asmjit/core/func.cpp +286 -0
  82. data/ext/asmjit/asmjit/src/asmjit/core/func.h +1445 -0
  83. data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext.cpp +293 -0
  84. data/ext/asmjit/asmjit/src/asmjit/core/funcargscontext_p.h +199 -0
  85. data/ext/asmjit/asmjit/src/asmjit/core/globals.cpp +133 -0
  86. data/ext/asmjit/asmjit/src/asmjit/core/globals.h +393 -0
  87. data/ext/asmjit/asmjit/src/asmjit/core/inst.cpp +113 -0
  88. data/ext/asmjit/asmjit/src/asmjit/core/inst.h +772 -0
  89. data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.cpp +1242 -0
  90. data/ext/asmjit/asmjit/src/asmjit/core/jitallocator.h +261 -0
  91. data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.cpp +80 -0
  92. data/ext/asmjit/asmjit/src/asmjit/core/jitruntime.h +89 -0
  93. data/ext/asmjit/asmjit/src/asmjit/core/logger.cpp +69 -0
  94. data/ext/asmjit/asmjit/src/asmjit/core/logger.h +198 -0
  95. data/ext/asmjit/asmjit/src/asmjit/core/misc_p.h +33 -0
  96. data/ext/asmjit/asmjit/src/asmjit/core/operand.cpp +132 -0
  97. data/ext/asmjit/asmjit/src/asmjit/core/operand.h +1611 -0
  98. data/ext/asmjit/asmjit/src/asmjit/core/osutils.cpp +84 -0
  99. data/ext/asmjit/asmjit/src/asmjit/core/osutils.h +61 -0
  100. data/ext/asmjit/asmjit/src/asmjit/core/osutils_p.h +68 -0
  101. data/ext/asmjit/asmjit/src/asmjit/core/raassignment_p.h +418 -0
  102. data/ext/asmjit/asmjit/src/asmjit/core/rabuilders_p.h +612 -0
  103. data/ext/asmjit/asmjit/src/asmjit/core/radefs_p.h +1204 -0
  104. data/ext/asmjit/asmjit/src/asmjit/core/ralocal.cpp +1166 -0
  105. data/ext/asmjit/asmjit/src/asmjit/core/ralocal_p.h +254 -0
  106. data/ext/asmjit/asmjit/src/asmjit/core/rapass.cpp +1969 -0
  107. data/ext/asmjit/asmjit/src/asmjit/core/rapass_p.h +1183 -0
  108. data/ext/asmjit/asmjit/src/asmjit/core/rastack.cpp +184 -0
  109. data/ext/asmjit/asmjit/src/asmjit/core/rastack_p.h +171 -0
  110. data/ext/asmjit/asmjit/src/asmjit/core/string.cpp +559 -0
  111. data/ext/asmjit/asmjit/src/asmjit/core/string.h +372 -0
  112. data/ext/asmjit/asmjit/src/asmjit/core/support.cpp +494 -0
  113. data/ext/asmjit/asmjit/src/asmjit/core/support.h +1773 -0
  114. data/ext/asmjit/asmjit/src/asmjit/core/target.cpp +14 -0
  115. data/ext/asmjit/asmjit/src/asmjit/core/target.h +53 -0
  116. data/ext/asmjit/asmjit/src/asmjit/core/type.cpp +74 -0
  117. data/ext/asmjit/asmjit/src/asmjit/core/type.h +419 -0
  118. data/ext/asmjit/asmjit/src/asmjit/core/virtmem.cpp +722 -0
  119. data/ext/asmjit/asmjit/src/asmjit/core/virtmem.h +242 -0
  120. data/ext/asmjit/asmjit/src/asmjit/core/zone.cpp +353 -0
  121. data/ext/asmjit/asmjit/src/asmjit/core/zone.h +615 -0
  122. data/ext/asmjit/asmjit/src/asmjit/core/zonehash.cpp +309 -0
  123. data/ext/asmjit/asmjit/src/asmjit/core/zonehash.h +186 -0
  124. data/ext/asmjit/asmjit/src/asmjit/core/zonelist.cpp +163 -0
  125. data/ext/asmjit/asmjit/src/asmjit/core/zonelist.h +209 -0
  126. data/ext/asmjit/asmjit/src/asmjit/core/zonestack.cpp +176 -0
  127. data/ext/asmjit/asmjit/src/asmjit/core/zonestack.h +239 -0
  128. data/ext/asmjit/asmjit/src/asmjit/core/zonestring.h +120 -0
  129. data/ext/asmjit/asmjit/src/asmjit/core/zonetree.cpp +99 -0
  130. data/ext/asmjit/asmjit/src/asmjit/core/zonetree.h +380 -0
  131. data/ext/asmjit/asmjit/src/asmjit/core/zonevector.cpp +356 -0
  132. data/ext/asmjit/asmjit/src/asmjit/core/zonevector.h +690 -0
  133. data/ext/asmjit/asmjit/src/asmjit/core.h +1861 -0
  134. data/ext/asmjit/asmjit/src/asmjit/x86/x86archtraits_p.h +148 -0
  135. data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.cpp +5110 -0
  136. data/ext/asmjit/asmjit/src/asmjit/x86/x86assembler.h +685 -0
  137. data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.cpp +52 -0
  138. data/ext/asmjit/asmjit/src/asmjit/x86/x86builder.h +351 -0
  139. data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.cpp +61 -0
  140. data/ext/asmjit/asmjit/src/asmjit/x86/x86compiler.h +721 -0
  141. data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper.cpp +619 -0
  142. data/ext/asmjit/asmjit/src/asmjit/x86/x86emithelper_p.h +60 -0
  143. data/ext/asmjit/asmjit/src/asmjit/x86/x86emitter.h +4315 -0
  144. data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter.cpp +944 -0
  145. data/ext/asmjit/asmjit/src/asmjit/x86/x86formatter_p.h +58 -0
  146. data/ext/asmjit/asmjit/src/asmjit/x86/x86func.cpp +503 -0
  147. data/ext/asmjit/asmjit/src/asmjit/x86/x86func_p.h +33 -0
  148. data/ext/asmjit/asmjit/src/asmjit/x86/x86globals.h +2169 -0
  149. data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi.cpp +1732 -0
  150. data/ext/asmjit/asmjit/src/asmjit/x86/x86instapi_p.h +41 -0
  151. data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.cpp +4427 -0
  152. data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb.h +563 -0
  153. data/ext/asmjit/asmjit/src/asmjit/x86/x86instdb_p.h +311 -0
  154. data/ext/asmjit/asmjit/src/asmjit/x86/x86opcode_p.h +436 -0
  155. data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.cpp +231 -0
  156. data/ext/asmjit/asmjit/src/asmjit/x86/x86operand.h +1085 -0
  157. data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass.cpp +1509 -0
  158. data/ext/asmjit/asmjit/src/asmjit/x86/x86rapass_p.h +94 -0
  159. data/ext/asmjit/asmjit/src/asmjit/x86.h +93 -0
  160. data/ext/asmjit/asmjit/src/asmjit.natvis +245 -0
  161. data/ext/asmjit/asmjit/test/asmjit_test_assembler.cpp +84 -0
  162. data/ext/asmjit/asmjit/test/asmjit_test_assembler.h +85 -0
  163. data/ext/asmjit/asmjit/test/asmjit_test_assembler_a64.cpp +4006 -0
  164. data/ext/asmjit/asmjit/test/asmjit_test_assembler_x64.cpp +17833 -0
  165. data/ext/asmjit/asmjit/test/asmjit_test_assembler_x86.cpp +8300 -0
  166. data/ext/asmjit/asmjit/test/asmjit_test_compiler.cpp +253 -0
  167. data/ext/asmjit/asmjit/test/asmjit_test_compiler.h +73 -0
  168. data/ext/asmjit/asmjit/test/asmjit_test_compiler_a64.cpp +690 -0
  169. data/ext/asmjit/asmjit/test/asmjit_test_compiler_x86.cpp +4317 -0
  170. data/ext/asmjit/asmjit/test/asmjit_test_emitters.cpp +197 -0
  171. data/ext/asmjit/asmjit/test/asmjit_test_instinfo.cpp +181 -0
  172. data/ext/asmjit/asmjit/test/asmjit_test_misc.h +257 -0
  173. data/ext/asmjit/asmjit/test/asmjit_test_perf.cpp +62 -0
  174. data/ext/asmjit/asmjit/test/asmjit_test_perf.h +61 -0
  175. data/ext/asmjit/asmjit/test/asmjit_test_perf_a64.cpp +699 -0
  176. data/ext/asmjit/asmjit/test/asmjit_test_perf_x86.cpp +5032 -0
  177. data/ext/asmjit/asmjit/test/asmjit_test_unit.cpp +172 -0
  178. data/ext/asmjit/asmjit/test/asmjit_test_x86_sections.cpp +172 -0
  179. data/ext/asmjit/asmjit/test/asmjitutils.h +38 -0
  180. data/ext/asmjit/asmjit/test/broken.cpp +312 -0
  181. data/ext/asmjit/asmjit/test/broken.h +148 -0
  182. data/ext/asmjit/asmjit/test/cmdline.h +61 -0
  183. data/ext/asmjit/asmjit/test/performancetimer.h +41 -0
  184. data/ext/asmjit/asmjit/tools/configure-makefiles.sh +13 -0
  185. data/ext/asmjit/asmjit/tools/configure-ninja.sh +13 -0
  186. data/ext/asmjit/asmjit/tools/configure-sanitizers.sh +13 -0
  187. data/ext/asmjit/asmjit/tools/configure-vs2019-x64.bat +2 -0
  188. data/ext/asmjit/asmjit/tools/configure-vs2019-x86.bat +2 -0
  189. data/ext/asmjit/asmjit/tools/configure-vs2022-x64.bat +2 -0
  190. data/ext/asmjit/asmjit/tools/configure-vs2022-x86.bat +2 -0
  191. data/ext/asmjit/asmjit/tools/configure-xcode.sh +8 -0
  192. data/ext/asmjit/asmjit/tools/enumgen.js +417 -0
  193. data/ext/asmjit/asmjit/tools/enumgen.sh +3 -0
  194. data/ext/asmjit/asmjit/tools/tablegen-arm.js +365 -0
  195. data/ext/asmjit/asmjit/tools/tablegen-arm.sh +3 -0
  196. data/ext/asmjit/asmjit/tools/tablegen-x86.js +2638 -0
  197. data/ext/asmjit/asmjit/tools/tablegen-x86.sh +3 -0
  198. data/ext/asmjit/asmjit/tools/tablegen.js +947 -0
  199. data/ext/asmjit/asmjit/tools/tablegen.sh +4 -0
  200. data/ext/asmjit/asmjit.cc +167 -30
  201. data/ext/asmjit/extconf.rb +9 -9
  202. data/lib/asmjit/version.rb +1 -1
  203. data/lib/asmjit.rb +14 -4
  204. metadata +198 -17
@@ -0,0 +1,690 @@
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_ZONEVECTOR_H_INCLUDED
7
+ #define ASMJIT_CORE_ZONEVECTOR_H_INCLUDED
8
+
9
+ #include "../core/support.h"
10
+ #include "../core/zone.h"
11
+
12
+ ASMJIT_BEGIN_NAMESPACE
13
+
14
+ //! \addtogroup asmjit_zone
15
+ //! \{
16
+
17
+ //! Base class used by \ref ZoneVector template.
18
+ class ZoneVectorBase {
19
+ public:
20
+ ASMJIT_NONCOPYABLE(ZoneVectorBase)
21
+
22
+ // STL compatibility;
23
+ typedef uint32_t size_type;
24
+ typedef ptrdiff_t difference_type;
25
+
26
+ //! Vector data (untyped).
27
+ void* _data = nullptr;
28
+ //! Size of the vector.
29
+ size_type _size = 0;
30
+ //! Capacity of the vector.
31
+ size_type _capacity = 0;
32
+
33
+ protected:
34
+ //! \name Construction & Destruction
35
+ //! \{
36
+
37
+ //! Creates a new instance of `ZoneVectorBase`.
38
+ inline ZoneVectorBase() noexcept {}
39
+
40
+ inline ZoneVectorBase(ZoneVectorBase&& other) noexcept
41
+ : _data(other._data),
42
+ _size(other._size),
43
+ _capacity(other._capacity) {}
44
+
45
+ //! \}
46
+
47
+ //! \cond INTERNAL
48
+ //! \name Internal
49
+ //! \{
50
+
51
+ inline void _release(ZoneAllocator* allocator, uint32_t sizeOfT) noexcept {
52
+ if (_data != nullptr) {
53
+ allocator->release(_data, _capacity * sizeOfT);
54
+ reset();
55
+ }
56
+ }
57
+
58
+ ASMJIT_API Error _grow(ZoneAllocator* allocator, uint32_t sizeOfT, uint32_t n) noexcept;
59
+ ASMJIT_API Error _resize(ZoneAllocator* allocator, uint32_t sizeOfT, uint32_t n) noexcept;
60
+ ASMJIT_API Error _reserve(ZoneAllocator* allocator, uint32_t sizeOfT, uint32_t n) noexcept;
61
+
62
+ inline void _swap(ZoneVectorBase& other) noexcept {
63
+ std::swap(_data, other._data);
64
+ std::swap(_size, other._size);
65
+ std::swap(_capacity, other._capacity);
66
+ }
67
+
68
+ //! \}
69
+ //! \endcond
70
+
71
+ public:
72
+ //! \name Accessors
73
+ //! \{
74
+
75
+ //! Tests whether the vector is empty.
76
+ inline bool empty() const noexcept { return _size == 0; }
77
+ //! Returns the vector size.
78
+ inline size_type size() const noexcept { return _size; }
79
+ //! Returns the vector capacity.
80
+ inline size_type capacity() const noexcept { return _capacity; }
81
+
82
+ //! \}
83
+
84
+ //! \name Utilities
85
+ //! \{
86
+
87
+ //! Makes the vector empty (won't change the capacity or data pointer).
88
+ inline void clear() noexcept { _size = 0; }
89
+ //! Resets the vector data and set its `size` to zero.
90
+ inline void reset() noexcept {
91
+ _data = nullptr;
92
+ _size = 0;
93
+ _capacity = 0;
94
+ }
95
+
96
+ //! Truncates the vector to at most `n` items.
97
+ inline void truncate(size_type n) noexcept {
98
+ _size = Support::min(_size, n);
99
+ }
100
+
101
+ //! Sets size of the vector to `n`. Used internally by some algorithms.
102
+ inline void _setSize(size_type n) noexcept {
103
+ ASMJIT_ASSERT(n <= _capacity);
104
+ _size = n;
105
+ }
106
+
107
+ //! \}
108
+ };
109
+
110
+ //! Template used to store and manage array of Zone allocated data.
111
+ //!
112
+ //! This template has these advantages over other std::vector<>:
113
+ //! - Always non-copyable (designed to be non-copyable, we want it).
114
+ //! - Optimized for working only with POD types.
115
+ //! - Uses ZoneAllocator, thus small vectors are almost for free.
116
+ //! - Explicit allocation, ZoneAllocator is not part of the data.
117
+ template <typename T>
118
+ class ZoneVector : public ZoneVectorBase {
119
+ public:
120
+ ASMJIT_NONCOPYABLE(ZoneVector)
121
+
122
+ // STL compatibility;
123
+ typedef T value_type;
124
+ typedef T* pointer;
125
+ typedef const T* const_pointer;
126
+ typedef T& reference;
127
+ typedef const T& const_reference;
128
+
129
+ typedef T* iterator;
130
+ typedef const T* const_iterator;
131
+ typedef std::reverse_iterator<iterator> reverse_iterator;
132
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
133
+
134
+ //! \name Construction & Destruction
135
+ //! \{
136
+
137
+ inline ZoneVector() noexcept : ZoneVectorBase() {}
138
+ inline ZoneVector(ZoneVector&& other) noexcept : ZoneVector(other) {}
139
+
140
+ //! \}
141
+
142
+ //! \name Accessors
143
+ //! \{
144
+
145
+ //! Returns vector data.
146
+ inline T* data() noexcept { return static_cast<T*>(_data); }
147
+ //! Returns vector data (const)
148
+ inline const T* data() const noexcept { return static_cast<const T*>(_data); }
149
+
150
+ //! Returns item at the given index `i` (const).
151
+ inline const T& at(size_t i) const noexcept {
152
+ ASMJIT_ASSERT(i < _size);
153
+ return data()[i];
154
+ }
155
+
156
+ inline void _setEndPtr(T* p) noexcept {
157
+ ASMJIT_ASSERT(p >= data() && p <= data() + _capacity);
158
+ _setSize(uint32_t((uintptr_t)(p - data())));
159
+ }
160
+
161
+ //! \}
162
+
163
+ //! \name STL Compatibility (Iterators)
164
+ //! \{
165
+
166
+ inline iterator begin() noexcept { return iterator(data()); };
167
+ inline const_iterator begin() const noexcept { return const_iterator(data()); };
168
+
169
+ inline iterator end() noexcept { return iterator(data() + _size); };
170
+ inline const_iterator end() const noexcept { return const_iterator(data() + _size); };
171
+
172
+ inline reverse_iterator rbegin() noexcept { return reverse_iterator(end()); };
173
+ inline const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); };
174
+
175
+ inline reverse_iterator rend() noexcept { return reverse_iterator(begin()); };
176
+ inline const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); };
177
+
178
+ inline const_iterator cbegin() const noexcept { return const_iterator(data()); };
179
+ inline const_iterator cend() const noexcept { return const_iterator(data() + _size); };
180
+
181
+ inline const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(cend()); };
182
+ inline const_reverse_iterator crend() const noexcept { return const_reverse_iterator(cbegin()); };
183
+
184
+ //! \}
185
+
186
+ //! \name Utilities
187
+ //! \{
188
+
189
+ //! Swaps this vector with `other`.
190
+ ASMJIT_FORCE_INLINE void swap(ZoneVector<T>& other) noexcept { _swap(other); }
191
+
192
+ //! Prepends `item` to the vector.
193
+ ASMJIT_FORCE_INLINE Error prepend(ZoneAllocator* allocator, const T& item) noexcept {
194
+ if (ASMJIT_UNLIKELY(_size == _capacity))
195
+ ASMJIT_PROPAGATE(grow(allocator, 1));
196
+
197
+ ::memmove(static_cast<T*>(_data) + 1, _data, size_t(_size) * sizeof(T));
198
+ memcpy(_data, &item, sizeof(T));
199
+
200
+ _size++;
201
+ return kErrorOk;
202
+ }
203
+
204
+ //! Inserts an `item` at the specified `index`.
205
+ ASMJIT_FORCE_INLINE Error insert(ZoneAllocator* allocator, size_t index, const T& item) noexcept {
206
+ ASMJIT_ASSERT(index <= _size);
207
+
208
+ if (ASMJIT_UNLIKELY(_size == _capacity))
209
+ ASMJIT_PROPAGATE(grow(allocator, 1));
210
+
211
+ T* dst = static_cast<T*>(_data) + index;
212
+ ::memmove(dst + 1, dst, size_t(_size - index) * sizeof(T));
213
+ memcpy(dst, &item, sizeof(T));
214
+ _size++;
215
+
216
+ return kErrorOk;
217
+ }
218
+
219
+ //! Appends `item` to the vector.
220
+ ASMJIT_FORCE_INLINE Error append(ZoneAllocator* allocator, const T& item) noexcept {
221
+ if (ASMJIT_UNLIKELY(_size == _capacity))
222
+ ASMJIT_PROPAGATE(grow(allocator, 1));
223
+
224
+ memcpy(static_cast<T*>(_data) + _size, &item, sizeof(T));
225
+ _size++;
226
+
227
+ return kErrorOk;
228
+ }
229
+
230
+ //! Appends `other` vector at the end of this vector.
231
+ ASMJIT_FORCE_INLINE Error concat(ZoneAllocator* allocator, const ZoneVector<T>& other) noexcept {
232
+ uint32_t size = other._size;
233
+ if (_capacity - _size < size)
234
+ ASMJIT_PROPAGATE(grow(allocator, size));
235
+
236
+ if (size) {
237
+ memcpy(static_cast<T*>(_data) + _size, other._data, size_t(size) * sizeof(T));
238
+ _size += size;
239
+ }
240
+
241
+ return kErrorOk;
242
+ }
243
+
244
+ //! Prepends `item` to the vector (unsafe case).
245
+ //!
246
+ //! Can only be used together with `willGrow()`. If `willGrow(N)` returns `kErrorOk` then N elements
247
+ //! can be added to the vector without checking if there is a place for them. Used mostly internally.
248
+ ASMJIT_FORCE_INLINE void prependUnsafe(const T& item) noexcept {
249
+ ASMJIT_ASSERT(_size < _capacity);
250
+ T* data = static_cast<T*>(_data);
251
+
252
+ if (_size)
253
+ ::memmove(data + 1, data, size_t(_size) * sizeof(T));
254
+
255
+ memcpy(data, &item, sizeof(T));
256
+ _size++;
257
+ }
258
+
259
+ //! Append s`item` to the vector (unsafe case).
260
+ //!
261
+ //! Can only be used together with `willGrow()`. If `willGrow(N)` returns `kErrorOk` then N elements
262
+ //! can be added to the vector without checking if there is a place for them. Used mostly internally.
263
+ ASMJIT_FORCE_INLINE void appendUnsafe(const T& item) noexcept {
264
+ ASMJIT_ASSERT(_size < _capacity);
265
+
266
+ memcpy(static_cast<T*>(_data) + _size, &item, sizeof(T));
267
+ _size++;
268
+ }
269
+
270
+ //! Inserts an `item` at the specified `index` (unsafe case).
271
+ ASMJIT_FORCE_INLINE void insertUnsafe(size_t index, const T& item) noexcept {
272
+ ASMJIT_ASSERT(_size < _capacity);
273
+ ASMJIT_ASSERT(index <= _size);
274
+
275
+ T* dst = static_cast<T*>(_data) + index;
276
+ ::memmove(dst + 1, dst, size_t(_size - index) * sizeof(T));
277
+ memcpy(dst, &item, sizeof(T));
278
+ _size++;
279
+ }
280
+ //! Concatenates all items of `other` at the end of the vector.
281
+ ASMJIT_FORCE_INLINE void concatUnsafe(const ZoneVector<T>& other) noexcept {
282
+ uint32_t size = other._size;
283
+ ASMJIT_ASSERT(_capacity - _size >= size);
284
+
285
+ if (size) {
286
+ memcpy(static_cast<T*>(_data) + _size, other._data, size_t(size) * sizeof(T));
287
+ _size += size;
288
+ }
289
+ }
290
+
291
+ //! Returns index of the given `val` or `Globals::kNotFound` if it doesn't exist.
292
+ ASMJIT_FORCE_INLINE uint32_t indexOf(const T& val) const noexcept {
293
+ const T* data = static_cast<const T*>(_data);
294
+ uint32_t size = _size;
295
+
296
+ for (uint32_t i = 0; i < size; i++)
297
+ if (data[i] == val)
298
+ return i;
299
+ return Globals::kNotFound;
300
+ }
301
+
302
+ //! Tests whether the vector contains `val`.
303
+ inline bool contains(const T& val) const noexcept {
304
+ return indexOf(val) != Globals::kNotFound;
305
+ }
306
+
307
+ //! Removes item at index `i`.
308
+ inline void removeAt(size_t i) noexcept {
309
+ ASMJIT_ASSERT(i < _size);
310
+
311
+ T* data = static_cast<T*>(_data) + i;
312
+ size_t size = --_size - i;
313
+
314
+ if (size)
315
+ ::memmove(data, data + 1, size_t(size) * sizeof(T));
316
+ }
317
+
318
+ //! Pops the last element from the vector and returns it.
319
+ inline T pop() noexcept {
320
+ ASMJIT_ASSERT(_size > 0);
321
+
322
+ uint32_t index = --_size;
323
+ return data()[index];
324
+ }
325
+
326
+ template<typename CompareT = Support::Compare<Support::SortOrder::kAscending>>
327
+ inline void sort(const CompareT& cmp = CompareT()) noexcept {
328
+ Support::qSort<T, CompareT>(data(), size(), cmp);
329
+ }
330
+
331
+ //! Returns item at index `i`.
332
+ inline T& operator[](size_t i) noexcept {
333
+ ASMJIT_ASSERT(i < _size);
334
+ return data()[i];
335
+ }
336
+
337
+ //! Returns item at index `i`.
338
+ inline const T& operator[](size_t i) const noexcept {
339
+ ASMJIT_ASSERT(i < _size);
340
+ return data()[i];
341
+ }
342
+
343
+ //! Returns a reference to the first element of the vector.
344
+ //!
345
+ //! \note The vector must have at least one element. Attempting to use `first()` on empty vector will trigger
346
+ //! an assertion failure in debug builds.
347
+ inline T& first() noexcept { return operator[](0); }
348
+ //! \overload
349
+ inline const T& first() const noexcept { return operator[](0); }
350
+
351
+ //! Returns a reference to the last element of the vector.
352
+ //!
353
+ //! \note The vector must have at least one element. Attempting to use `last()` on empty vector will trigger
354
+ //! an assertion failure in debug builds.
355
+ inline T& last() noexcept { return operator[](_size - 1); }
356
+ //! \overload
357
+ inline const T& last() const noexcept { return operator[](_size - 1); }
358
+
359
+ //! \}
360
+
361
+ //! \name Memory Management
362
+ //! \{
363
+
364
+ //! Releases the memory held by `ZoneVector<T>` back to the `allocator`.
365
+ inline void release(ZoneAllocator* allocator) noexcept {
366
+ _release(allocator, sizeof(T));
367
+ }
368
+
369
+ //! Called to grow the buffer to fit at least `n` elements more.
370
+ inline Error grow(ZoneAllocator* allocator, uint32_t n) noexcept {
371
+ return ZoneVectorBase::_grow(allocator, sizeof(T), n);
372
+ }
373
+
374
+ //! Resizes the vector to hold `n` elements.
375
+ //!
376
+ //! If `n` is greater than the current size then the additional elements' content will be initialized to zero.
377
+ //! If `n` is less than the current size then the vector will be truncated to exactly `n` elements.
378
+ inline Error resize(ZoneAllocator* allocator, uint32_t n) noexcept {
379
+ return ZoneVectorBase::_resize(allocator, sizeof(T), n);
380
+ }
381
+
382
+ //! Reallocates the internal array to fit at least `n` items.
383
+ inline Error reserve(ZoneAllocator* allocator, uint32_t n) noexcept {
384
+ return n > _capacity ? ZoneVectorBase::_reserve(allocator, sizeof(T), n) : Error(kErrorOk);
385
+ }
386
+
387
+ inline Error willGrow(ZoneAllocator* allocator, uint32_t n = 1) noexcept {
388
+ return _capacity - _size < n ? grow(allocator, n) : Error(kErrorOk);
389
+ }
390
+
391
+ //! \}
392
+ };
393
+
394
+ //! Zone-allocated bit vector.
395
+ class ZoneBitVector {
396
+ public:
397
+ typedef Support::BitWord BitWord;
398
+
399
+ ASMJIT_NONCOPYABLE(ZoneBitVector)
400
+
401
+ //! \name Constants
402
+ //! \{
403
+
404
+ enum : uint32_t {
405
+ kBitWordSizeInBits = Support::kBitWordSizeInBits
406
+ };
407
+
408
+ //! \}
409
+
410
+ //! \name Members
411
+ //! \{
412
+
413
+ //! Bits.
414
+ BitWord* _data = nullptr;
415
+ //! Size of the bit-vector (in bits).
416
+ uint32_t _size = 0;
417
+ //! Capacity of the bit-vector (in bits).
418
+ uint32_t _capacity = 0;
419
+
420
+ //! \}
421
+
422
+ //! \cond INTERNAL
423
+ //! \name Internal
424
+ //! \{
425
+
426
+ static inline uint32_t _wordsPerBits(uint32_t nBits) noexcept {
427
+ return ((nBits + kBitWordSizeInBits - 1) / kBitWordSizeInBits);
428
+ }
429
+
430
+ static inline void _zeroBits(BitWord* dst, uint32_t nBitWords) noexcept {
431
+ for (uint32_t i = 0; i < nBitWords; i++)
432
+ dst[i] = 0;
433
+ }
434
+
435
+ static inline void _fillBits(BitWord* dst, uint32_t nBitWords) noexcept {
436
+ for (uint32_t i = 0; i < nBitWords; i++)
437
+ dst[i] = ~BitWord(0);
438
+ }
439
+
440
+ static inline void _copyBits(BitWord* dst, const BitWord* src, uint32_t nBitWords) noexcept {
441
+ for (uint32_t i = 0; i < nBitWords; i++)
442
+ dst[i] = src[i];
443
+ }
444
+
445
+ //! \}
446
+ //! \endcond
447
+
448
+ //! \name Construction & Destruction
449
+ //! \{
450
+
451
+ inline ZoneBitVector() noexcept {}
452
+
453
+ inline ZoneBitVector(ZoneBitVector&& other) noexcept
454
+ : _data(other._data),
455
+ _size(other._size),
456
+ _capacity(other._capacity) {}
457
+
458
+ //! \}
459
+
460
+ //! \name Overloaded Operators
461
+ //! \{
462
+
463
+ inline bool operator==(const ZoneBitVector& other) const noexcept { return eq(other); }
464
+ inline bool operator!=(const ZoneBitVector& other) const noexcept { return !eq(other); }
465
+
466
+ //! \}
467
+
468
+ //! \name Accessors
469
+ //! \{
470
+
471
+ //! Tests whether the bit-vector is empty (has no bits).
472
+ inline bool empty() const noexcept { return _size == 0; }
473
+ //! Returns the size of this bit-vector (in bits).
474
+ inline uint32_t size() const noexcept { return _size; }
475
+ //! Returns the capacity of this bit-vector (in bits).
476
+ inline uint32_t capacity() const noexcept { return _capacity; }
477
+
478
+ //! Returns the size of the `BitWord[]` array in `BitWord` units.
479
+ inline uint32_t sizeInBitWords() const noexcept { return _wordsPerBits(_size); }
480
+ //! Returns the capacity of the `BitWord[]` array in `BitWord` units.
481
+ inline uint32_t capacityInBitWords() const noexcept { return _wordsPerBits(_capacity); }
482
+
483
+ //! REturns bit-vector data as `BitWord[]`.
484
+ inline BitWord* data() noexcept { return _data; }
485
+ //! \overload
486
+ inline const BitWord* data() const noexcept { return _data; }
487
+
488
+ //! \}
489
+
490
+ //! \name Utilities
491
+ //! \{
492
+
493
+ inline void swap(ZoneBitVector& other) noexcept {
494
+ std::swap(_data, other._data);
495
+ std::swap(_size, other._size);
496
+ std::swap(_capacity, other._capacity);
497
+ }
498
+
499
+ inline void clear() noexcept {
500
+ _size = 0;
501
+ }
502
+
503
+ inline void reset() noexcept {
504
+ _data = nullptr;
505
+ _size = 0;
506
+ _capacity = 0;
507
+ }
508
+
509
+ inline void truncate(uint32_t newSize) noexcept {
510
+ _size = Support::min(_size, newSize);
511
+ _clearUnusedBits();
512
+ }
513
+
514
+ inline bool bitAt(uint32_t index) const noexcept {
515
+ ASMJIT_ASSERT(index < _size);
516
+ return Support::bitVectorGetBit(_data, index);
517
+ }
518
+
519
+ inline void setBit(uint32_t index, bool value) noexcept {
520
+ ASMJIT_ASSERT(index < _size);
521
+ Support::bitVectorSetBit(_data, index, value);
522
+ }
523
+
524
+ inline void flipBit(uint32_t index) noexcept {
525
+ ASMJIT_ASSERT(index < _size);
526
+ Support::bitVectorFlipBit(_data, index);
527
+ }
528
+
529
+ ASMJIT_FORCE_INLINE Error append(ZoneAllocator* allocator, bool value) noexcept {
530
+ uint32_t index = _size;
531
+ if (ASMJIT_UNLIKELY(index >= _capacity))
532
+ return _append(allocator, value);
533
+
534
+ uint32_t idx = index / kBitWordSizeInBits;
535
+ uint32_t bit = index % kBitWordSizeInBits;
536
+
537
+ if (bit == 0)
538
+ _data[idx] = BitWord(value) << bit;
539
+ else
540
+ _data[idx] |= BitWord(value) << bit;
541
+
542
+ _size++;
543
+ return kErrorOk;
544
+ }
545
+
546
+ ASMJIT_API Error copyFrom(ZoneAllocator* allocator, const ZoneBitVector& other) noexcept;
547
+
548
+ ASMJIT_FORCE_INLINE void clearAll() noexcept {
549
+ _zeroBits(_data, _wordsPerBits(_size));
550
+ }
551
+
552
+ ASMJIT_FORCE_INLINE void fillAll() noexcept {
553
+ _fillBits(_data, _wordsPerBits(_size));
554
+ _clearUnusedBits();
555
+ }
556
+
557
+ ASMJIT_FORCE_INLINE void clearBits(uint32_t start, uint32_t count) noexcept {
558
+ ASMJIT_ASSERT(start <= _size);
559
+ ASMJIT_ASSERT(_size - start >= count);
560
+
561
+ Support::bitVectorClear(_data, start, count);
562
+ }
563
+
564
+ ASMJIT_FORCE_INLINE void fillBits(uint32_t start, uint32_t count) noexcept {
565
+ ASMJIT_ASSERT(start <= _size);
566
+ ASMJIT_ASSERT(_size - start >= count);
567
+
568
+ Support::bitVectorFill(_data, start, count);
569
+ }
570
+
571
+ //! Performs a logical bitwise AND between bits specified in this array and bits in `other`. If `other` has less
572
+ //! bits than `this` then all remaining bits are set to zero.
573
+ //!
574
+ //! \note The size of the BitVector is unaffected by this operation.
575
+ ASMJIT_FORCE_INLINE void and_(const ZoneBitVector& other) noexcept {
576
+ BitWord* dst = _data;
577
+ const BitWord* src = other._data;
578
+
579
+ uint32_t thisBitWordCount = sizeInBitWords();
580
+ uint32_t otherBitWordCount = other.sizeInBitWords();
581
+ uint32_t commonBitWordCount = Support::min(thisBitWordCount, otherBitWordCount);
582
+
583
+ uint32_t i = 0;
584
+ while (i < commonBitWordCount) {
585
+ dst[i] = dst[i] & src[i];
586
+ i++;
587
+ }
588
+
589
+ while (i < thisBitWordCount) {
590
+ dst[i] = 0;
591
+ i++;
592
+ }
593
+ }
594
+
595
+ //! Performs a logical bitwise AND between bits specified in this array and negated bits in `other`. If `other`
596
+ //! has less bits than `this` then all remaining bits are kept intact.
597
+ //!
598
+ //! \note The size of the BitVector is unaffected by this operation.
599
+ ASMJIT_FORCE_INLINE void andNot(const ZoneBitVector& other) noexcept {
600
+ BitWord* dst = _data;
601
+ const BitWord* src = other._data;
602
+
603
+ uint32_t commonBitWordCount = _wordsPerBits(Support::min(_size, other._size));
604
+ for (uint32_t i = 0; i < commonBitWordCount; i++)
605
+ dst[i] = dst[i] & ~src[i];
606
+ }
607
+
608
+ //! Performs a logical bitwise OP between bits specified in this array and bits in `other`. If `other` has less
609
+ //! bits than `this` then all remaining bits are kept intact.
610
+ //!
611
+ //! \note The size of the BitVector is unaffected by this operation.
612
+ ASMJIT_FORCE_INLINE void or_(const ZoneBitVector& other) noexcept {
613
+ BitWord* dst = _data;
614
+ const BitWord* src = other._data;
615
+
616
+ uint32_t commonBitWordCount = _wordsPerBits(Support::min(_size, other._size));
617
+ for (uint32_t i = 0; i < commonBitWordCount; i++)
618
+ dst[i] = dst[i] | src[i];
619
+ _clearUnusedBits();
620
+ }
621
+
622
+ ASMJIT_FORCE_INLINE void _clearUnusedBits() noexcept {
623
+ uint32_t idx = _size / kBitWordSizeInBits;
624
+ uint32_t bit = _size % kBitWordSizeInBits;
625
+
626
+ if (!bit)
627
+ return;
628
+ _data[idx] &= (BitWord(1) << bit) - 1u;
629
+ }
630
+
631
+ ASMJIT_FORCE_INLINE bool eq(const ZoneBitVector& other) const noexcept {
632
+ if (_size != other._size)
633
+ return false;
634
+
635
+ const BitWord* aData = _data;
636
+ const BitWord* bData = other._data;
637
+ uint32_t numBitWords = _wordsPerBits(_size);
638
+
639
+ for (uint32_t i = 0; i < numBitWords; i++)
640
+ if (aData[i] != bData[i])
641
+ return false;
642
+ return true;
643
+ }
644
+
645
+ //! \}
646
+
647
+ //! \name Memory Management
648
+ //! \{
649
+
650
+ inline void release(ZoneAllocator* allocator) noexcept {
651
+ if (!_data) return;
652
+ allocator->release(_data, _capacity / 8);
653
+ reset();
654
+ }
655
+
656
+ inline Error resize(ZoneAllocator* allocator, uint32_t newSize, bool newBitsValue = false) noexcept {
657
+ return _resize(allocator, newSize, newSize, newBitsValue);
658
+ }
659
+
660
+ ASMJIT_API Error _resize(ZoneAllocator* allocator, uint32_t newSize, uint32_t idealCapacity, bool newBitsValue) noexcept;
661
+ ASMJIT_API Error _append(ZoneAllocator* allocator, bool value) noexcept;
662
+
663
+ //! \}
664
+
665
+ //! \name Iterators
666
+ //! \{
667
+
668
+ class ForEachBitSet : public Support::BitVectorIterator<BitWord> {
669
+ public:
670
+ inline explicit ForEachBitSet(const ZoneBitVector& bitVector) noexcept
671
+ : Support::BitVectorIterator<BitWord>(bitVector.data(), bitVector.sizeInBitWords()) {}
672
+ };
673
+
674
+ template<class Operator>
675
+ class ForEachBitOp : public Support::BitVectorOpIterator<BitWord, Operator> {
676
+ public:
677
+ inline ForEachBitOp(const ZoneBitVector& a, const ZoneBitVector& b) noexcept
678
+ : Support::BitVectorOpIterator<BitWord, Operator>(a.data(), b.data(), a.sizeInBitWords()) {
679
+ ASMJIT_ASSERT(a.size() == b.size());
680
+ }
681
+ };
682
+
683
+ //! \}
684
+ };
685
+
686
+ //! \}
687
+
688
+ ASMJIT_END_NAMESPACE
689
+
690
+ #endif // ASMJIT_CORE_ZONEVECTOR_H_INCLUDED