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,494 @@
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
+
9
+ ASMJIT_BEGIN_NAMESPACE
10
+
11
+ // Support - Tests
12
+ // ===============
13
+
14
+ #if defined(ASMJIT_TEST)
15
+ template<typename T>
16
+ static void testArrays(const T* a, const T* b, size_t size) noexcept {
17
+ for (size_t i = 0; i < size; i++)
18
+ EXPECT(a[i] == b[i], "Mismatch at %u", unsigned(i));
19
+ }
20
+
21
+ static void testAlignment() noexcept {
22
+ INFO("Support::isAligned()");
23
+ EXPECT(Support::isAligned<size_t>(0xFFFF, 4) == false);
24
+ EXPECT(Support::isAligned<size_t>(0xFFF4, 4) == true);
25
+ EXPECT(Support::isAligned<size_t>(0xFFF8, 8) == true);
26
+ EXPECT(Support::isAligned<size_t>(0xFFF0, 16) == true);
27
+
28
+ INFO("Support::alignUp()");
29
+ EXPECT(Support::alignUp<size_t>(0xFFFF, 4) == 0x10000);
30
+ EXPECT(Support::alignUp<size_t>(0xFFF4, 4) == 0x0FFF4);
31
+ EXPECT(Support::alignUp<size_t>(0xFFF8, 8) == 0x0FFF8);
32
+ EXPECT(Support::alignUp<size_t>(0xFFF0, 16) == 0x0FFF0);
33
+ EXPECT(Support::alignUp<size_t>(0xFFF0, 32) == 0x10000);
34
+
35
+ INFO("Support::alignUpDiff()");
36
+ EXPECT(Support::alignUpDiff<size_t>(0xFFFF, 4) == 1);
37
+ EXPECT(Support::alignUpDiff<size_t>(0xFFF4, 4) == 0);
38
+ EXPECT(Support::alignUpDiff<size_t>(0xFFF8, 8) == 0);
39
+ EXPECT(Support::alignUpDiff<size_t>(0xFFF0, 16) == 0);
40
+ EXPECT(Support::alignUpDiff<size_t>(0xFFF0, 32) == 16);
41
+
42
+ INFO("Support::alignUpPowerOf2()");
43
+ EXPECT(Support::alignUpPowerOf2<size_t>(0x0000) == 0x00000);
44
+ EXPECT(Support::alignUpPowerOf2<size_t>(0xFFFF) == 0x10000);
45
+ EXPECT(Support::alignUpPowerOf2<size_t>(0xF123) == 0x10000);
46
+ EXPECT(Support::alignUpPowerOf2<size_t>(0x0F00) == 0x01000);
47
+ EXPECT(Support::alignUpPowerOf2<size_t>(0x0100) == 0x00100);
48
+ EXPECT(Support::alignUpPowerOf2<size_t>(0x1001) == 0x02000);
49
+ }
50
+
51
+ static void testBitUtils() noexcept {
52
+ uint32_t i;
53
+
54
+ INFO("Support::shl() / shr()");
55
+ EXPECT(Support::shl(int32_t(0x00001111), 16) == int32_t(0x11110000u));
56
+ EXPECT(Support::shl(uint32_t(0x00001111), 16) == uint32_t(0x11110000u));
57
+ EXPECT(Support::shr(int32_t(0x11110000u), 16) == int32_t(0x00001111u));
58
+ EXPECT(Support::shr(uint32_t(0x11110000u), 16) == uint32_t(0x00001111u));
59
+ EXPECT(Support::sar(int32_t(0xFFFF0000u), 16) == int32_t(0xFFFFFFFFu));
60
+ EXPECT(Support::sar(uint32_t(0xFFFF0000u), 16) == uint32_t(0xFFFFFFFFu));
61
+
62
+ INFO("Support::blsi()");
63
+ for (i = 0; i < 32; i++) EXPECT(Support::blsi(uint32_t(1) << i) == uint32_t(1) << i);
64
+ for (i = 0; i < 31; i++) EXPECT(Support::blsi(uint32_t(3) << i) == uint32_t(1) << i);
65
+ for (i = 0; i < 64; i++) EXPECT(Support::blsi(uint64_t(1) << i) == uint64_t(1) << i);
66
+ for (i = 0; i < 63; i++) EXPECT(Support::blsi(uint64_t(3) << i) == uint64_t(1) << i);
67
+
68
+ INFO("Support::ctz()");
69
+ for (i = 0; i < 32; i++) EXPECT(Support::Internal::clzFallback(uint32_t(1) << i) == 31 - i);
70
+ for (i = 0; i < 64; i++) EXPECT(Support::Internal::clzFallback(uint64_t(1) << i) == 63 - i);
71
+ for (i = 0; i < 32; i++) EXPECT(Support::Internal::ctzFallback(uint32_t(1) << i) == i);
72
+ for (i = 0; i < 64; i++) EXPECT(Support::Internal::ctzFallback(uint64_t(1) << i) == i);
73
+ for (i = 0; i < 32; i++) EXPECT(Support::clz(uint32_t(1) << i) == 31 - i);
74
+ for (i = 0; i < 64; i++) EXPECT(Support::clz(uint64_t(1) << i) == 63 - i);
75
+ for (i = 0; i < 32; i++) EXPECT(Support::ctz(uint32_t(1) << i) == i);
76
+ for (i = 0; i < 64; i++) EXPECT(Support::ctz(uint64_t(1) << i) == i);
77
+
78
+ INFO("Support::bitMask()");
79
+ EXPECT(Support::bitMask(0, 1, 7) == 0x83u);
80
+ for (i = 0; i < 32; i++)
81
+ EXPECT(Support::bitMask(i) == (1u << i));
82
+
83
+ INFO("Support::bitTest()");
84
+ for (i = 0; i < 32; i++) {
85
+ EXPECT(Support::bitTest((1 << i), i) == true, "Support::bitTest(%X, %u) should return true", (1 << i), i);
86
+ }
87
+
88
+ INFO("Support::lsbMask<uint32_t>()");
89
+ for (i = 0; i < 32; i++) {
90
+ uint32_t expectedBits = 0;
91
+ for (uint32_t b = 0; b < i; b++)
92
+ expectedBits |= uint32_t(1) << b;
93
+ EXPECT(Support::lsbMask<uint32_t>(i) == expectedBits);
94
+ }
95
+
96
+ INFO("Support::lsbMask<uint64_t>()");
97
+ for (i = 0; i < 64; i++) {
98
+ uint64_t expectedBits = 0;
99
+ for (uint32_t b = 0; b < i; b++)
100
+ expectedBits |= uint64_t(1) << b;
101
+ EXPECT(Support::lsbMask<uint64_t>(i) == expectedBits);
102
+ }
103
+
104
+ INFO("Support::popcnt()");
105
+ for (i = 0; i < 32; i++) EXPECT(Support::popcnt((uint32_t(1) << i)) == 1);
106
+ for (i = 0; i < 64; i++) EXPECT(Support::popcnt((uint64_t(1) << i)) == 1);
107
+ EXPECT(Support::popcnt(0x000000F0) == 4);
108
+ EXPECT(Support::popcnt(0x10101010) == 4);
109
+ EXPECT(Support::popcnt(0xFF000000) == 8);
110
+ EXPECT(Support::popcnt(0xFFFFFFF7) == 31);
111
+ EXPECT(Support::popcnt(0x7FFFFFFF) == 31);
112
+
113
+ INFO("Support::isPowerOf2()");
114
+ for (i = 0; i < 64; i++) {
115
+ EXPECT(Support::isPowerOf2(uint64_t(1) << i) == true);
116
+ EXPECT(Support::isPowerOf2((uint64_t(1) << i) ^ 0x001101) == false);
117
+ }
118
+ }
119
+
120
+ static void testIntUtils() noexcept {
121
+ INFO("Support::byteswap()");
122
+ EXPECT(Support::byteswap16(int32_t(0x0102)) == int32_t(0x0201));
123
+ EXPECT(Support::byteswap32(int32_t(0x01020304)) == int32_t(0x04030201));
124
+ EXPECT(Support::byteswap32(uint32_t(0x01020304)) == uint32_t(0x04030201));
125
+ EXPECT(Support::byteswap64(uint64_t(0x0102030405060708)) == uint64_t(0x0807060504030201));
126
+
127
+ INFO("Support::bytepack()");
128
+ union BytePackData {
129
+ uint8_t bytes[4];
130
+ uint32_t u32;
131
+ } bpdata;
132
+
133
+ bpdata.u32 = Support::bytepack32_4x8(0x00, 0x11, 0x22, 0x33);
134
+ EXPECT(bpdata.bytes[0] == 0x00);
135
+ EXPECT(bpdata.bytes[1] == 0x11);
136
+ EXPECT(bpdata.bytes[2] == 0x22);
137
+ EXPECT(bpdata.bytes[3] == 0x33);
138
+
139
+ INFO("Support::isBetween()");
140
+ EXPECT(Support::isBetween<int>(10 , 10, 20) == true);
141
+ EXPECT(Support::isBetween<int>(11 , 10, 20) == true);
142
+ EXPECT(Support::isBetween<int>(20 , 10, 20) == true);
143
+ EXPECT(Support::isBetween<int>(9 , 10, 20) == false);
144
+ EXPECT(Support::isBetween<int>(21 , 10, 20) == false);
145
+ EXPECT(Support::isBetween<int>(101, 10, 20) == false);
146
+
147
+ INFO("Support::isInt8()");
148
+ EXPECT(Support::isInt8(-128) == true);
149
+ EXPECT(Support::isInt8( 127) == true);
150
+ EXPECT(Support::isInt8(-129) == false);
151
+ EXPECT(Support::isInt8( 128) == false);
152
+
153
+ INFO("Support::isInt16()");
154
+ EXPECT(Support::isInt16(-32768) == true);
155
+ EXPECT(Support::isInt16( 32767) == true);
156
+ EXPECT(Support::isInt16(-32769) == false);
157
+ EXPECT(Support::isInt16( 32768) == false);
158
+
159
+ INFO("Support::isInt32()");
160
+ EXPECT(Support::isInt32( 2147483647 ) == true);
161
+ EXPECT(Support::isInt32(-2147483647 - 1) == true);
162
+ EXPECT(Support::isInt32(uint64_t(2147483648u)) == false);
163
+ EXPECT(Support::isInt32(uint64_t(0xFFFFFFFFu)) == false);
164
+ EXPECT(Support::isInt32(uint64_t(0xFFFFFFFFu) + 1) == false);
165
+
166
+ INFO("Support::isUInt8()");
167
+ EXPECT(Support::isUInt8(0) == true);
168
+ EXPECT(Support::isUInt8(255) == true);
169
+ EXPECT(Support::isUInt8(256) == false);
170
+ EXPECT(Support::isUInt8(-1) == false);
171
+
172
+ INFO("Support::isUInt12()");
173
+ EXPECT(Support::isUInt12(0) == true);
174
+ EXPECT(Support::isUInt12(4095) == true);
175
+ EXPECT(Support::isUInt12(4096) == false);
176
+ EXPECT(Support::isUInt12(-1) == false);
177
+
178
+ INFO("Support::isUInt16()");
179
+ EXPECT(Support::isUInt16(0) == true);
180
+ EXPECT(Support::isUInt16(65535) == true);
181
+ EXPECT(Support::isUInt16(65536) == false);
182
+ EXPECT(Support::isUInt16(-1) == false);
183
+
184
+ INFO("Support::isUInt32()");
185
+ EXPECT(Support::isUInt32(uint64_t(0xFFFFFFFF)) == true);
186
+ EXPECT(Support::isUInt32(uint64_t(0xFFFFFFFF) + 1) == false);
187
+ EXPECT(Support::isUInt32(-1) == false);
188
+ }
189
+
190
+ static void testReadWrite() noexcept {
191
+ INFO("Support::readX() / writeX()");
192
+
193
+ uint8_t arr[32] = { 0 };
194
+
195
+ Support::writeU16uBE(arr + 1, 0x0102u);
196
+ Support::writeU16uBE(arr + 3, 0x0304u);
197
+ EXPECT(Support::readU32uBE(arr + 1) == 0x01020304u);
198
+ EXPECT(Support::readU32uLE(arr + 1) == 0x04030201u);
199
+ EXPECT(Support::readU32uBE(arr + 2) == 0x02030400u);
200
+ EXPECT(Support::readU32uLE(arr + 2) == 0x00040302u);
201
+
202
+ Support::writeU32uLE(arr + 5, 0x05060708u);
203
+ EXPECT(Support::readU64uBE(arr + 1) == 0x0102030408070605u);
204
+ EXPECT(Support::readU64uLE(arr + 1) == 0x0506070804030201u);
205
+
206
+ Support::writeU64uLE(arr + 7, 0x1122334455667788u);
207
+ EXPECT(Support::readU32uBE(arr + 8) == 0x77665544u);
208
+ }
209
+
210
+ static void testBitVector() noexcept {
211
+ INFO("Support::bitVectorOp");
212
+ {
213
+ uint32_t vec[3] = { 0 };
214
+ Support::bitVectorFill(vec, 1, 64);
215
+ EXPECT(vec[0] == 0xFFFFFFFEu);
216
+ EXPECT(vec[1] == 0xFFFFFFFFu);
217
+ EXPECT(vec[2] == 0x00000001u);
218
+
219
+ Support::bitVectorClear(vec, 1, 1);
220
+ EXPECT(vec[0] == 0xFFFFFFFCu);
221
+ EXPECT(vec[1] == 0xFFFFFFFFu);
222
+ EXPECT(vec[2] == 0x00000001u);
223
+
224
+ Support::bitVectorFill(vec, 0, 32);
225
+ EXPECT(vec[0] == 0xFFFFFFFFu);
226
+ EXPECT(vec[1] == 0xFFFFFFFFu);
227
+ EXPECT(vec[2] == 0x00000001u);
228
+
229
+ Support::bitVectorClear(vec, 0, 32);
230
+ EXPECT(vec[0] == 0x00000000u);
231
+ EXPECT(vec[1] == 0xFFFFFFFFu);
232
+ EXPECT(vec[2] == 0x00000001u);
233
+
234
+ Support::bitVectorFill(vec, 1, 30);
235
+ EXPECT(vec[0] == 0x7FFFFFFEu);
236
+ EXPECT(vec[1] == 0xFFFFFFFFu);
237
+ EXPECT(vec[2] == 0x00000001u);
238
+
239
+ Support::bitVectorClear(vec, 1, 95);
240
+ EXPECT(vec[0] == 0x00000000u);
241
+ EXPECT(vec[1] == 0x00000000u);
242
+ EXPECT(vec[2] == 0x00000000u);
243
+
244
+ Support::bitVectorFill(vec, 32, 64);
245
+ EXPECT(vec[0] == 0x00000000u);
246
+ EXPECT(vec[1] == 0xFFFFFFFFu);
247
+ EXPECT(vec[2] == 0xFFFFFFFFu);
248
+
249
+ Support::bitVectorSetBit(vec, 1, true);
250
+ EXPECT(vec[0] == 0x00000002u);
251
+ EXPECT(vec[1] == 0xFFFFFFFFu);
252
+ EXPECT(vec[2] == 0xFFFFFFFFu);
253
+
254
+ Support::bitVectorSetBit(vec, 95, false);
255
+ EXPECT(vec[0] == 0x00000002u);
256
+ EXPECT(vec[1] == 0xFFFFFFFFu);
257
+ EXPECT(vec[2] == 0x7FFFFFFFu);
258
+
259
+ Support::bitVectorClear(vec, 33, 32);
260
+ EXPECT(vec[0] == 0x00000002u);
261
+ EXPECT(vec[1] == 0x00000001u);
262
+ EXPECT(vec[2] == 0x7FFFFFFEu);
263
+ }
264
+
265
+ INFO("Support::bitVectorIndexOf");
266
+ {
267
+ uint32_t vec1[1] = { 0x80000000 };
268
+ EXPECT(Support::bitVectorIndexOf(vec1, 0, true) == 31);
269
+ EXPECT(Support::bitVectorIndexOf(vec1, 1, true) == 31);
270
+ EXPECT(Support::bitVectorIndexOf(vec1, 31, true) == 31);
271
+
272
+ uint32_t vec2[2] = { 0x00000000, 0x80000000 };
273
+ EXPECT(Support::bitVectorIndexOf(vec2, 0, true) == 63);
274
+ EXPECT(Support::bitVectorIndexOf(vec2, 1, true) == 63);
275
+ EXPECT(Support::bitVectorIndexOf(vec2, 31, true) == 63);
276
+ EXPECT(Support::bitVectorIndexOf(vec2, 32, true) == 63);
277
+ EXPECT(Support::bitVectorIndexOf(vec2, 33, true) == 63);
278
+ EXPECT(Support::bitVectorIndexOf(vec2, 63, true) == 63);
279
+
280
+ uint32_t vec3[3] = { 0x00000001, 0x00000000, 0x80000000 };
281
+ EXPECT(Support::bitVectorIndexOf(vec3, 0, true) == 0);
282
+ EXPECT(Support::bitVectorIndexOf(vec3, 1, true) == 95);
283
+ EXPECT(Support::bitVectorIndexOf(vec3, 2, true) == 95);
284
+ EXPECT(Support::bitVectorIndexOf(vec3, 31, true) == 95);
285
+ EXPECT(Support::bitVectorIndexOf(vec3, 32, true) == 95);
286
+ EXPECT(Support::bitVectorIndexOf(vec3, 63, true) == 95);
287
+ EXPECT(Support::bitVectorIndexOf(vec3, 64, true) == 95);
288
+ EXPECT(Support::bitVectorIndexOf(vec3, 95, true) == 95);
289
+
290
+ uint32_t vec4[3] = { ~vec3[0], ~vec3[1], ~vec3[2] };
291
+ EXPECT(Support::bitVectorIndexOf(vec4, 0, false) == 0);
292
+ EXPECT(Support::bitVectorIndexOf(vec4, 1, false) == 95);
293
+ EXPECT(Support::bitVectorIndexOf(vec4, 2, false) == 95);
294
+ EXPECT(Support::bitVectorIndexOf(vec4, 31, false) == 95);
295
+ EXPECT(Support::bitVectorIndexOf(vec4, 32, false) == 95);
296
+ EXPECT(Support::bitVectorIndexOf(vec4, 63, false) == 95);
297
+ EXPECT(Support::bitVectorIndexOf(vec4, 64, false) == 95);
298
+ EXPECT(Support::bitVectorIndexOf(vec4, 95, false) == 95);
299
+ }
300
+
301
+ INFO("Support::BitWordIterator<uint32_t>");
302
+ {
303
+ Support::BitWordIterator<uint32_t> it(0x80000F01u);
304
+ EXPECT(it.hasNext());
305
+ EXPECT(it.next() == 0);
306
+ EXPECT(it.hasNext());
307
+ EXPECT(it.next() == 8);
308
+ EXPECT(it.hasNext());
309
+ EXPECT(it.next() == 9);
310
+ EXPECT(it.hasNext());
311
+ EXPECT(it.next() == 10);
312
+ EXPECT(it.hasNext());
313
+ EXPECT(it.next() == 11);
314
+ EXPECT(it.hasNext());
315
+ EXPECT(it.next() == 31);
316
+ EXPECT(!it.hasNext());
317
+
318
+ // No bits set.
319
+ it.init(0x00000000u);
320
+ ASMJIT_ASSERT(!it.hasNext());
321
+
322
+ // Only first bit set.
323
+ it.init(0x00000001u);
324
+ EXPECT(it.hasNext());
325
+ EXPECT(it.next() == 0);
326
+ ASMJIT_ASSERT(!it.hasNext());
327
+
328
+ // Only last bit set (special case).
329
+ it.init(0x80000000u);
330
+ ASMJIT_ASSERT(it.hasNext());
331
+ ASMJIT_ASSERT(it.next() == 31);
332
+ ASMJIT_ASSERT(!it.hasNext());
333
+ }
334
+
335
+ INFO("Support::BitWordIterator<uint64_t>");
336
+ {
337
+ Support::BitWordIterator<uint64_t> it(uint64_t(1) << 63);
338
+ ASMJIT_ASSERT(it.hasNext());
339
+ ASMJIT_ASSERT(it.next() == 63);
340
+ ASMJIT_ASSERT(!it.hasNext());
341
+ }
342
+
343
+ INFO("Support::BitVectorIterator<uint32_t>");
344
+ {
345
+ // Border cases.
346
+ static const uint32_t bitsNone[] = { 0xFFFFFFFFu };
347
+ Support::BitVectorIterator<uint32_t> it(bitsNone, 0);
348
+
349
+ EXPECT(!it.hasNext());
350
+ it.init(bitsNone, 0, 1);
351
+ EXPECT(!it.hasNext());
352
+ it.init(bitsNone, 0, 128);
353
+ EXPECT(!it.hasNext());
354
+
355
+ static const uint32_t bits1[] = { 0x80000008u, 0x80000001u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00003000u };
356
+ it.init(bits1, ASMJIT_ARRAY_SIZE(bits1));
357
+
358
+ EXPECT(it.hasNext());
359
+ EXPECT(it.next() == 3);
360
+ EXPECT(it.hasNext());
361
+ EXPECT(it.next() == 31);
362
+ EXPECT(it.hasNext());
363
+ EXPECT(it.next() == 32);
364
+ EXPECT(it.hasNext());
365
+ EXPECT(it.next() == 63);
366
+ EXPECT(it.hasNext());
367
+ EXPECT(it.next() == 127);
368
+ EXPECT(it.hasNext());
369
+ EXPECT(it.next() == 204);
370
+ EXPECT(it.hasNext());
371
+ EXPECT(it.next() == 205);
372
+ EXPECT(!it.hasNext());
373
+
374
+ it.init(bits1, ASMJIT_ARRAY_SIZE(bits1), 4);
375
+ EXPECT(it.hasNext());
376
+ EXPECT(it.next() == 31);
377
+
378
+ it.init(bits1, ASMJIT_ARRAY_SIZE(bits1), 64);
379
+ EXPECT(it.hasNext());
380
+ EXPECT(it.next() == 127);
381
+
382
+ it.init(bits1, ASMJIT_ARRAY_SIZE(bits1), 127);
383
+ EXPECT(it.hasNext());
384
+ EXPECT(it.next() == 127);
385
+
386
+ static const uint32_t bits2[] = { 0x80000000u, 0x80000000u, 0x00000000u, 0x80000000u };
387
+ it.init(bits2, ASMJIT_ARRAY_SIZE(bits2));
388
+
389
+ EXPECT(it.hasNext());
390
+ EXPECT(it.next() == 31);
391
+ EXPECT(it.hasNext());
392
+ EXPECT(it.next() == 63);
393
+ EXPECT(it.hasNext());
394
+ EXPECT(it.next() == 127);
395
+ EXPECT(!it.hasNext());
396
+
397
+ static const uint32_t bits3[] = { 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u };
398
+ it.init(bits3, ASMJIT_ARRAY_SIZE(bits3));
399
+ EXPECT(!it.hasNext());
400
+
401
+ static const uint32_t bits4[] = { 0x00000000u, 0x00000000u, 0x00000000u, 0x80000000u };
402
+ it.init(bits4, ASMJIT_ARRAY_SIZE(bits4));
403
+ EXPECT(it.hasNext());
404
+ EXPECT(it.next() == 127);
405
+ EXPECT(!it.hasNext());
406
+ }
407
+
408
+ INFO("Support::BitVectorIterator<uint64_t>");
409
+ {
410
+ static const uint64_t bits1[] = { 0x80000000u, 0x80000000u, 0x00000000u, 0x80000000u };
411
+ Support::BitVectorIterator<uint64_t> it(bits1, ASMJIT_ARRAY_SIZE(bits1));
412
+
413
+ EXPECT(it.hasNext());
414
+ EXPECT(it.next() == 31);
415
+ EXPECT(it.hasNext());
416
+ EXPECT(it.next() == 95);
417
+ EXPECT(it.hasNext());
418
+ EXPECT(it.next() == 223);
419
+ EXPECT(!it.hasNext());
420
+
421
+ static const uint64_t bits2[] = { 0x8000000000000000u, 0, 0, 0 };
422
+ it.init(bits2, ASMJIT_ARRAY_SIZE(bits2));
423
+
424
+ EXPECT(it.hasNext());
425
+ EXPECT(it.next() == 63);
426
+ EXPECT(!it.hasNext());
427
+ }
428
+ }
429
+
430
+ static void testSorting() noexcept {
431
+ INFO("Support::qSort() - Testing qsort and isort of predefined arrays");
432
+ {
433
+ constexpr size_t kArraySize = 11;
434
+
435
+ int ref_[kArraySize] = { -4, -2, -1, 0, 1, 9, 12, 13, 14, 19, 22 };
436
+ int arr1[kArraySize] = { 0, 1, -1, 19, 22, 14, -4, 9, 12, 13, -2 };
437
+ int arr2[kArraySize];
438
+
439
+ memcpy(arr2, arr1, kArraySize * sizeof(int));
440
+
441
+ Support::iSort(arr1, kArraySize);
442
+ Support::qSort(arr2, kArraySize);
443
+ testArrays(arr1, ref_, kArraySize);
444
+ testArrays(arr2, ref_, kArraySize);
445
+ }
446
+
447
+ INFO("Support::qSort() - Testing qsort and isort of artificial arrays");
448
+ {
449
+ constexpr size_t kArraySize = 200;
450
+
451
+ int arr1[kArraySize];
452
+ int arr2[kArraySize];
453
+ int ref_[kArraySize];
454
+
455
+ for (size_t size = 2; size < kArraySize; size++) {
456
+ for (size_t i = 0; i < size; i++) {
457
+ arr1[i] = int(size - 1 - i);
458
+ arr2[i] = int(size - 1 - i);
459
+ ref_[i] = int(i);
460
+ }
461
+
462
+ Support::iSort(arr1, size);
463
+ Support::qSort(arr2, size);
464
+ testArrays(arr1, ref_, size);
465
+ testArrays(arr2, ref_, size);
466
+ }
467
+ }
468
+
469
+ INFO("Support::qSort() - Testing qsort and isort with an unstable compare function");
470
+ {
471
+ constexpr size_t kArraySize = 5;
472
+
473
+ float arr1[kArraySize] = { 1.0f, 0.0f, 3.0f, -1.0f, std::numeric_limits<float>::quiet_NaN() };
474
+ float arr2[kArraySize] = { };
475
+
476
+ memcpy(arr2, arr1, kArraySize * sizeof(float));
477
+
478
+ // We don't test as it's undefined where the NaN would be.
479
+ Support::iSort(arr1, kArraySize);
480
+ Support::qSort(arr2, kArraySize);
481
+ }
482
+ }
483
+
484
+ UNIT(support) {
485
+ testAlignment();
486
+ testBitUtils();
487
+ testIntUtils();
488
+ testReadWrite();
489
+ testBitVector();
490
+ testSorting();
491
+ }
492
+ #endif
493
+
494
+ ASMJIT_END_NAMESPACE