koffi 0.9.4 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (327) hide show
  1. package/CMakeLists.txt +60 -60
  2. package/README.md +163 -153
  3. package/package.json +19 -18
  4. package/src/call.hh +27 -27
  5. package/src/call_arm64.cc +482 -482
  6. package/src/call_arm64_fwd.S +115 -115
  7. package/src/call_x64_sysv.cc +477 -477
  8. package/src/call_x64_sysv_fwd.S +131 -131
  9. package/src/call_x64_win.cc +243 -243
  10. package/src/call_x64_win_fwd.asm +105 -105
  11. package/src/call_x86.cc +259 -259
  12. package/src/call_x86_fwd.S +48 -48
  13. package/src/call_x86_fwd.asm +50 -50
  14. package/src/ffi.cc +504 -504
  15. package/src/ffi.hh +135 -135
  16. package/src/util.cc +296 -296
  17. package/src/util.hh +80 -80
  18. package/vendor/dragonbox/CMakeLists.txt +122 -122
  19. package/vendor/dragonbox/LICENSE-Apache2-LLVM +218 -218
  20. package/vendor/dragonbox/LICENSE-Boost +23 -23
  21. package/vendor/dragonbox/README.md +277 -277
  22. package/vendor/dragonbox/cmake/dragonboxConfig.cmake +1 -1
  23. package/vendor/dragonbox/include/dragonbox/dragonbox.h +2670 -2670
  24. package/vendor/dragonbox/include/dragonbox/dragonbox_to_chars.h +108 -108
  25. package/vendor/dragonbox/other_files/unknown_win64_vc2019.html +539 -539
  26. package/vendor/dragonbox/source/dragonbox_to_chars.cpp +303 -303
  27. package/vendor/dragonbox/subproject/3rdparty/grisu_exact/CMakeLists.txt +23 -23
  28. package/vendor/dragonbox/subproject/3rdparty/grisu_exact/fp_to_chars.cpp +238 -238
  29. package/vendor/dragonbox/subproject/3rdparty/grisu_exact/fp_to_chars.h +95 -95
  30. package/vendor/dragonbox/subproject/3rdparty/grisu_exact/grisu_exact.h +2666 -2666
  31. package/vendor/dragonbox/subproject/3rdparty/ryu/CMakeLists.txt +16 -16
  32. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/common.h +114 -114
  33. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s.c +509 -509
  34. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s_full_table.h +367 -367
  35. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s_intrinsics.h +357 -357
  36. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/digit_table.h +35 -35
  37. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s.c +345 -345
  38. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s_full_table.h +55 -55
  39. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s_intrinsics.h +128 -128
  40. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/ryu.h +46 -46
  41. package/vendor/dragonbox/subproject/3rdparty/schubfach/CMakeLists.txt +21 -21
  42. package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_32.cc +699 -699
  43. package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_32.h +31 -31
  44. package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_64.cc +1354 -1354
  45. package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_64.h +31 -31
  46. package/vendor/dragonbox/subproject/3rdparty/shaded_plots/example_shaded_plots.m +68 -68
  47. package/vendor/dragonbox/subproject/3rdparty/shaded_plots/license.txt +25 -25
  48. package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_distribution.m +92 -92
  49. package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_distribution_prctile.m +121 -121
  50. package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_histogram_shaded.m +99 -99
  51. package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_shaded.m +93 -93
  52. package/vendor/dragonbox/subproject/benchmark/CMakeLists.txt +64 -64
  53. package/vendor/dragonbox/subproject/benchmark/include/benchmark.h +40 -40
  54. package/vendor/dragonbox/subproject/benchmark/matlab/plot_benchmarks.m +21 -21
  55. package/vendor/dragonbox/subproject/benchmark/matlab/plot_digit_benchmark.m +78 -78
  56. package/vendor/dragonbox/subproject/benchmark/matlab/plot_uniform_benchmark.m +95 -95
  57. package/vendor/dragonbox/subproject/benchmark/source/benchmark.cpp +237 -237
  58. package/vendor/dragonbox/subproject/benchmark/source/dragonbox.cpp +30 -30
  59. package/vendor/dragonbox/subproject/benchmark/source/grisu_exact.cpp +36 -36
  60. package/vendor/dragonbox/subproject/benchmark/source/ryu.cpp +27 -27
  61. package/vendor/dragonbox/subproject/benchmark/source/schubfach.cpp +31 -31
  62. package/vendor/dragonbox/subproject/common/CMakeLists.txt +41 -41
  63. package/vendor/dragonbox/subproject/common/include/best_rational_approx.h +96 -96
  64. package/vendor/dragonbox/subproject/common/include/big_uint.h +217 -217
  65. package/vendor/dragonbox/subproject/common/include/continued_fractions.h +173 -173
  66. package/vendor/dragonbox/subproject/common/include/good_rational_approx.h +266 -266
  67. package/vendor/dragonbox/subproject/common/include/random_float.h +182 -182
  68. package/vendor/dragonbox/subproject/common/include/rational_continued_fractions.h +56 -56
  69. package/vendor/dragonbox/subproject/common/source/big_uint.cpp +601 -601
  70. package/vendor/dragonbox/subproject/meta/CMakeLists.txt +40 -40
  71. package/vendor/dragonbox/subproject/meta/results/binary32_generated_cache.txt +81 -81
  72. package/vendor/dragonbox/subproject/meta/results/binary64_compressed_cache_error_table.txt +9 -9
  73. package/vendor/dragonbox/subproject/meta/results/binary64_generated_cache.txt +622 -622
  74. package/vendor/dragonbox/subproject/meta/source/generate_cache.cpp +126 -126
  75. package/vendor/dragonbox/subproject/meta/source/live_test.cpp +81 -81
  76. package/vendor/dragonbox/subproject/meta/source/perf_test.cpp +104 -104
  77. package/vendor/dragonbox/subproject/meta/source/sandbox.cpp +20 -20
  78. package/vendor/dragonbox/subproject/test/CMakeLists.txt +69 -69
  79. package/vendor/dragonbox/subproject/test/results/binary32.csv +255 -255
  80. package/vendor/dragonbox/subproject/test/results/binary64.csv +2047 -2047
  81. package/vendor/dragonbox/subproject/test/results/plot_required_bits.m +17 -17
  82. package/vendor/dragonbox/subproject/test/source/test_all_shorter_interval_cases.cpp +88 -88
  83. package/vendor/dragonbox/subproject/test/source/uniform_random_test.cpp +95 -95
  84. package/vendor/dragonbox/subproject/test/source/verify_cache_precision.cpp +337 -337
  85. package/vendor/dragonbox/subproject/test/source/verify_compressed_cache.cpp +154 -154
  86. package/vendor/dragonbox/subproject/test/source/verify_fast_multiplication.cpp +168 -168
  87. package/vendor/dragonbox/subproject/test/source/verify_log_computation.cpp +251 -251
  88. package/vendor/dragonbox/subproject/test/source/verify_magic_division.cpp +113 -113
  89. package/vendor/libcc/libcc.cc +7651 -7651
  90. package/vendor/libcc/libcc.hh +4312 -4312
  91. package/vendor/node-addon-api/CHANGELOG.md +859 -859
  92. package/vendor/node-addon-api/CODE_OF_CONDUCT.md +4 -4
  93. package/vendor/node-addon-api/CONTRIBUTING.md +93 -93
  94. package/vendor/node-addon-api/LICENSE.md +12 -12
  95. package/vendor/node-addon-api/README.md +293 -293
  96. package/vendor/node-addon-api/appveyor.yml +37 -37
  97. package/vendor/node-addon-api/benchmark/README.md +47 -47
  98. package/vendor/node-addon-api/benchmark/binding.gyp +25 -25
  99. package/vendor/node-addon-api/benchmark/function_args.cc +217 -217
  100. package/vendor/node-addon-api/benchmark/function_args.js +60 -60
  101. package/vendor/node-addon-api/benchmark/index.js +34 -34
  102. package/vendor/node-addon-api/benchmark/property_descriptor.cc +91 -91
  103. package/vendor/node-addon-api/benchmark/property_descriptor.js +37 -37
  104. package/vendor/node-addon-api/common.gypi +21 -21
  105. package/vendor/node-addon-api/doc/addon.md +163 -163
  106. package/vendor/node-addon-api/doc/array.md +81 -81
  107. package/vendor/node-addon-api/doc/array_buffer.md +155 -155
  108. package/vendor/node-addon-api/doc/async_context.md +86 -86
  109. package/vendor/node-addon-api/doc/async_operations.md +31 -31
  110. package/vendor/node-addon-api/doc/async_worker.md +427 -427
  111. package/vendor/node-addon-api/doc/async_worker_variants.md +557 -557
  112. package/vendor/node-addon-api/doc/bigint.md +97 -97
  113. package/vendor/node-addon-api/doc/boolean.md +68 -68
  114. package/vendor/node-addon-api/doc/buffer.md +150 -150
  115. package/vendor/node-addon-api/doc/callback_scope.md +54 -54
  116. package/vendor/node-addon-api/doc/callbackinfo.md +97 -97
  117. package/vendor/node-addon-api/doc/checker-tool.md +32 -32
  118. package/vendor/node-addon-api/doc/class_property_descriptor.md +115 -115
  119. package/vendor/node-addon-api/doc/cmake-js.md +68 -68
  120. package/vendor/node-addon-api/doc/conversion-tool.md +27 -27
  121. package/vendor/node-addon-api/doc/creating_a_release.md +62 -62
  122. package/vendor/node-addon-api/doc/dataview.md +248 -248
  123. package/vendor/node-addon-api/doc/date.md +68 -68
  124. package/vendor/node-addon-api/doc/env.md +196 -196
  125. package/vendor/node-addon-api/doc/error.md +120 -120
  126. package/vendor/node-addon-api/doc/error_handling.md +254 -254
  127. package/vendor/node-addon-api/doc/escapable_handle_scope.md +80 -80
  128. package/vendor/node-addon-api/doc/external.md +63 -63
  129. package/vendor/node-addon-api/doc/function.md +402 -402
  130. package/vendor/node-addon-api/doc/function_reference.md +238 -238
  131. package/vendor/node-addon-api/doc/generator.md +13 -13
  132. package/vendor/node-addon-api/doc/handle_scope.md +63 -63
  133. package/vendor/node-addon-api/doc/hierarchy.md +91 -91
  134. package/vendor/node-addon-api/doc/instance_wrap.md +408 -408
  135. package/vendor/node-addon-api/doc/maybe.md +76 -76
  136. package/vendor/node-addon-api/doc/memory_management.md +27 -27
  137. package/vendor/node-addon-api/doc/name.md +29 -29
  138. package/vendor/node-addon-api/doc/node-gyp.md +82 -82
  139. package/vendor/node-addon-api/doc/number.md +163 -163
  140. package/vendor/node-addon-api/doc/object.md +432 -432
  141. package/vendor/node-addon-api/doc/object_lifetime_management.md +83 -83
  142. package/vendor/node-addon-api/doc/object_reference.md +117 -117
  143. package/vendor/node-addon-api/doc/object_wrap.md +561 -561
  144. package/vendor/node-addon-api/doc/prebuild_tools.md +16 -16
  145. package/vendor/node-addon-api/doc/promises.md +79 -79
  146. package/vendor/node-addon-api/doc/property_descriptor.md +286 -286
  147. package/vendor/node-addon-api/doc/propertylvalue.md +50 -50
  148. package/vendor/node-addon-api/doc/range_error.md +59 -59
  149. package/vendor/node-addon-api/doc/reference.md +113 -113
  150. package/vendor/node-addon-api/doc/setup.md +110 -110
  151. package/vendor/node-addon-api/doc/string.md +93 -93
  152. package/vendor/node-addon-api/doc/symbol.md +60 -60
  153. package/vendor/node-addon-api/doc/threadsafe.md +121 -121
  154. package/vendor/node-addon-api/doc/threadsafe_function.md +290 -290
  155. package/vendor/node-addon-api/doc/type_error.md +59 -59
  156. package/vendor/node-addon-api/doc/typed_array.md +78 -78
  157. package/vendor/node-addon-api/doc/typed_array_of.md +137 -137
  158. package/vendor/node-addon-api/doc/typed_threadsafe_function.md +306 -306
  159. package/vendor/node-addon-api/doc/value.md +340 -340
  160. package/vendor/node-addon-api/doc/version_management.md +43 -43
  161. package/vendor/node-addon-api/except.gypi +25 -25
  162. package/vendor/node-addon-api/index.js +11 -11
  163. package/vendor/node-addon-api/napi-inl.deprecated.h +192 -192
  164. package/vendor/node-addon-api/napi-inl.h +6209 -6209
  165. package/vendor/node-addon-api/napi.h +2983 -2983
  166. package/vendor/node-addon-api/node_api.gyp +9 -9
  167. package/vendor/node-addon-api/noexcept.gypi +26 -26
  168. package/vendor/node-addon-api/package-support.json +21 -21
  169. package/vendor/node-addon-api/package.json +399 -399
  170. package/vendor/node-addon-api/test/README.md +91 -91
  171. package/vendor/node-addon-api/test/addon.cc +36 -36
  172. package/vendor/node-addon-api/test/addon.js +11 -11
  173. package/vendor/node-addon-api/test/addon_build/index.js +49 -49
  174. package/vendor/node-addon-api/test/addon_build/tpl/addon.cc +17 -17
  175. package/vendor/node-addon-api/test/addon_build/tpl/binding.gyp +62 -62
  176. package/vendor/node-addon-api/test/addon_build/tpl/index.js +9 -9
  177. package/vendor/node-addon-api/test/addon_build/tpl/package.json +11 -11
  178. package/vendor/node-addon-api/test/addon_data.cc +99 -99
  179. package/vendor/node-addon-api/test/addon_data.js +46 -46
  180. package/vendor/node-addon-api/test/array_buffer.cc +243 -243
  181. package/vendor/node-addon-api/test/array_buffer.js +69 -69
  182. package/vendor/node-addon-api/test/async_context.cc +21 -21
  183. package/vendor/node-addon-api/test/async_context.js +86 -86
  184. package/vendor/node-addon-api/test/async_progress_queue_worker.cc +83 -83
  185. package/vendor/node-addon-api/test/async_progress_queue_worker.js +46 -46
  186. package/vendor/node-addon-api/test/async_progress_worker.cc +134 -134
  187. package/vendor/node-addon-api/test/async_progress_worker.js +61 -61
  188. package/vendor/node-addon-api/test/async_worker.cc +106 -106
  189. package/vendor/node-addon-api/test/async_worker.js +179 -179
  190. package/vendor/node-addon-api/test/async_worker_nocallback.js +13 -13
  191. package/vendor/node-addon-api/test/async_worker_persistent.cc +63 -63
  192. package/vendor/node-addon-api/test/async_worker_persistent.js +24 -24
  193. package/vendor/node-addon-api/test/basic_types/array.cc +40 -40
  194. package/vendor/node-addon-api/test/basic_types/array.js +35 -35
  195. package/vendor/node-addon-api/test/basic_types/boolean.cc +38 -38
  196. package/vendor/node-addon-api/test/basic_types/boolean.js +35 -35
  197. package/vendor/node-addon-api/test/basic_types/number.cc +99 -99
  198. package/vendor/node-addon-api/test/basic_types/number.js +114 -114
  199. package/vendor/node-addon-api/test/basic_types/value.cc +120 -120
  200. package/vendor/node-addon-api/test/basic_types/value.js +133 -133
  201. package/vendor/node-addon-api/test/bigint.cc +91 -91
  202. package/vendor/node-addon-api/test/bigint.js +53 -53
  203. package/vendor/node-addon-api/test/binding-swallowexcept.cc +12 -12
  204. package/vendor/node-addon-api/test/binding.cc +171 -171
  205. package/vendor/node-addon-api/test/binding.gyp +117 -117
  206. package/vendor/node-addon-api/test/buffer.cc +183 -183
  207. package/vendor/node-addon-api/test/buffer.js +69 -69
  208. package/vendor/node-addon-api/test/callbackscope.cc +22 -22
  209. package/vendor/node-addon-api/test/callbackscope.js +49 -49
  210. package/vendor/node-addon-api/test/common/index.js +113 -113
  211. package/vendor/node-addon-api/test/common/test_helper.h +61 -61
  212. package/vendor/node-addon-api/test/dataview/dataview.cc +48 -48
  213. package/vendor/node-addon-api/test/dataview/dataview.js +35 -35
  214. package/vendor/node-addon-api/test/dataview/dataview_read_write.cc +115 -115
  215. package/vendor/node-addon-api/test/dataview/dataview_read_write.js +90 -90
  216. package/vendor/node-addon-api/test/date.cc +44 -44
  217. package/vendor/node-addon-api/test/date.js +18 -18
  218. package/vendor/node-addon-api/test/env_cleanup.cc +88 -88
  219. package/vendor/node-addon-api/test/env_cleanup.js +56 -56
  220. package/vendor/node-addon-api/test/error.cc +287 -287
  221. package/vendor/node-addon-api/test/error.js +81 -81
  222. package/vendor/node-addon-api/test/error_handling_for_primitives.cc +13 -13
  223. package/vendor/node-addon-api/test/error_handling_for_primitives.js +29 -29
  224. package/vendor/node-addon-api/test/error_terminating_environment.js +94 -94
  225. package/vendor/node-addon-api/test/external.cc +81 -81
  226. package/vendor/node-addon-api/test/external.js +88 -88
  227. package/vendor/node-addon-api/test/function.cc +295 -295
  228. package/vendor/node-addon-api/test/function.js +121 -121
  229. package/vendor/node-addon-api/test/function_reference.cc +202 -202
  230. package/vendor/node-addon-api/test/function_reference.js +157 -157
  231. package/vendor/node-addon-api/test/globalObject/global_object.cc +61 -61
  232. package/vendor/node-addon-api/test/globalObject/global_object_delete_property.cc +31 -31
  233. package/vendor/node-addon-api/test/globalObject/global_object_delete_property.js +61 -61
  234. package/vendor/node-addon-api/test/globalObject/global_object_get_property.cc +40 -40
  235. package/vendor/node-addon-api/test/globalObject/global_object_get_property.js +57 -57
  236. package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.cc +28 -28
  237. package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.js +48 -48
  238. package/vendor/node-addon-api/test/globalObject/global_object_set_property.cc +30 -30
  239. package/vendor/node-addon-api/test/globalObject/global_object_set_property.js +58 -58
  240. package/vendor/node-addon-api/test/handlescope.cc +60 -60
  241. package/vendor/node-addon-api/test/handlescope.js +14 -14
  242. package/vendor/node-addon-api/test/index.js +136 -136
  243. package/vendor/node-addon-api/test/maybe/check.cc +23 -23
  244. package/vendor/node-addon-api/test/maybe/index.js +38 -38
  245. package/vendor/node-addon-api/test/memory_management.cc +17 -17
  246. package/vendor/node-addon-api/test/memory_management.js +9 -9
  247. package/vendor/node-addon-api/test/movable_callbacks.cc +23 -23
  248. package/vendor/node-addon-api/test/movable_callbacks.js +21 -21
  249. package/vendor/node-addon-api/test/name.cc +108 -108
  250. package/vendor/node-addon-api/test/name.js +59 -59
  251. package/vendor/node-addon-api/test/napi_child.js +14 -14
  252. package/vendor/node-addon-api/test/object/delete_property.cc +38 -38
  253. package/vendor/node-addon-api/test/object/delete_property.js +41 -41
  254. package/vendor/node-addon-api/test/object/finalizer.cc +29 -29
  255. package/vendor/node-addon-api/test/object/finalizer.js +28 -28
  256. package/vendor/node-addon-api/test/object/get_property.cc +34 -34
  257. package/vendor/node-addon-api/test/object/get_property.js +40 -40
  258. package/vendor/node-addon-api/test/object/has_own_property.cc +34 -34
  259. package/vendor/node-addon-api/test/object/has_own_property.js +34 -34
  260. package/vendor/node-addon-api/test/object/has_property.cc +38 -38
  261. package/vendor/node-addon-api/test/object/has_property.js +37 -37
  262. package/vendor/node-addon-api/test/object/object.cc +348 -348
  263. package/vendor/node-addon-api/test/object/object.js +217 -217
  264. package/vendor/node-addon-api/test/object/object_deprecated.cc +66 -66
  265. package/vendor/node-addon-api/test/object/object_deprecated.js +47 -47
  266. package/vendor/node-addon-api/test/object/object_freeze_seal.cc +25 -25
  267. package/vendor/node-addon-api/test/object/object_freeze_seal.js +61 -61
  268. package/vendor/node-addon-api/test/object/set_property.cc +37 -37
  269. package/vendor/node-addon-api/test/object/set_property.js +29 -29
  270. package/vendor/node-addon-api/test/object/subscript_operator.cc +42 -42
  271. package/vendor/node-addon-api/test/object/subscript_operator.js +17 -17
  272. package/vendor/node-addon-api/test/object_reference.cc +219 -219
  273. package/vendor/node-addon-api/test/object_reference.js +259 -259
  274. package/vendor/node-addon-api/test/objectwrap.cc +268 -268
  275. package/vendor/node-addon-api/test/objectwrap.js +284 -284
  276. package/vendor/node-addon-api/test/objectwrap_constructor_exception.cc +26 -26
  277. package/vendor/node-addon-api/test/objectwrap_constructor_exception.js +18 -18
  278. package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.cc +30 -30
  279. package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.js +13 -13
  280. package/vendor/node-addon-api/test/objectwrap_removewrap.cc +45 -45
  281. package/vendor/node-addon-api/test/objectwrap_removewrap.js +40 -40
  282. package/vendor/node-addon-api/test/objectwrap_worker_thread.js +19 -19
  283. package/vendor/node-addon-api/test/promise.cc +29 -29
  284. package/vendor/node-addon-api/test/promise.js +18 -18
  285. package/vendor/node-addon-api/test/reference.cc +24 -24
  286. package/vendor/node-addon-api/test/reference.js +14 -14
  287. package/vendor/node-addon-api/test/run_script.cc +56 -56
  288. package/vendor/node-addon-api/test/run_script.js +45 -45
  289. package/vendor/node-addon-api/test/symbol.cc +79 -79
  290. package/vendor/node-addon-api/test/symbol.js +73 -73
  291. package/vendor/node-addon-api/test/testUtil.js +54 -54
  292. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.cc +195 -195
  293. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.js +188 -188
  294. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.cc +63 -63
  295. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.js +12 -12
  296. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.cc +115 -115
  297. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.js +14 -14
  298. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.cc +26 -26
  299. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.js +7 -7
  300. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.cc +225 -225
  301. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.js +59 -59
  302. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.cc +42 -42
  303. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.js +53 -53
  304. package/vendor/node-addon-api/test/thunking_manual.cc +140 -140
  305. package/vendor/node-addon-api/test/thunking_manual.js +17 -17
  306. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.cc +215 -215
  307. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.js +188 -188
  308. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc +68 -68
  309. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +12 -12
  310. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc +127 -127
  311. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js +14 -14
  312. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc +28 -28
  313. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js +7 -7
  314. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc +237 -237
  315. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.js +59 -59
  316. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc +53 -53
  317. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js +53 -53
  318. package/vendor/node-addon-api/test/typedarray-bigint.js +58 -58
  319. package/vendor/node-addon-api/test/typedarray.cc +216 -216
  320. package/vendor/node-addon-api/test/typedarray.js +69 -69
  321. package/vendor/node-addon-api/test/version_management.cc +27 -27
  322. package/vendor/node-addon-api/test/version_management.js +31 -31
  323. package/vendor/node-addon-api/tools/README.md +73 -73
  324. package/vendor/node-addon-api/tools/check-napi.js +100 -100
  325. package/vendor/node-addon-api/tools/clang-format.js +68 -68
  326. package/vendor/node-addon-api/tools/conversion.js +309 -309
  327. package/vendor/node-addon-api/tools/eslint-format.js +71 -71
@@ -1,357 +1,357 @@
1
- // Copyright 2018 Ulf Adams
2
- //
3
- // The contents of this file may be used under the terms of the Apache License,
4
- // Version 2.0.
5
- //
6
- // (See accompanying file LICENSE-Apache or copy at
7
- // http://www.apache.org/licenses/LICENSE-2.0)
8
- //
9
- // Alternatively, the contents of this file may be used under the terms of
10
- // the Boost Software License, Version 1.0.
11
- // (See accompanying file LICENSE-Boost or copy at
12
- // https://www.boost.org/LICENSE_1_0.txt)
13
- //
14
- // Unless required by applicable law or agreed to in writing, this software
15
- // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- // KIND, either express or implied.
17
- #ifndef RYU_D2S_INTRINSICS_H
18
- #define RYU_D2S_INTRINSICS_H
19
-
20
- #include <assert.h>
21
- #include <stdint.h>
22
-
23
- // Defines RYU_32_BIT_PLATFORM if applicable.
24
- #include "ryu/common.h"
25
-
26
- // ABSL avoids uint128_t on Win32 even if __SIZEOF_INT128__ is defined.
27
- // Let's do the same for now.
28
- #if defined(__SIZEOF_INT128__) && !defined(_MSC_VER) && !defined(RYU_ONLY_64_BIT_OPS)
29
- #define HAS_UINT128
30
- #elif defined(_MSC_VER) && !defined(RYU_ONLY_64_BIT_OPS) && defined(_M_X64)
31
- #define HAS_64_BIT_INTRINSICS
32
- #endif
33
-
34
- #if defined(HAS_UINT128)
35
- typedef __uint128_t uint128_t;
36
- #endif
37
-
38
- #if defined(HAS_64_BIT_INTRINSICS)
39
-
40
- #include <intrin.h>
41
-
42
- static inline uint64_t umul128(const uint64_t a, const uint64_t b, uint64_t* const productHi) {
43
- return _umul128(a, b, productHi);
44
- }
45
-
46
- // Returns the lower 64 bits of (hi*2^64 + lo) >> dist, with 0 < dist < 64.
47
- static inline uint64_t shiftright128(const uint64_t lo, const uint64_t hi, const uint32_t dist) {
48
- // For the __shiftright128 intrinsic, the shift value is always
49
- // modulo 64.
50
- // In the current implementation of the double-precision version
51
- // of Ryu, the shift value is always < 64. (In the case
52
- // RYU_OPTIMIZE_SIZE == 0, the shift value is in the range [49, 58].
53
- // Otherwise in the range [2, 59].)
54
- // However, this function is now also called by s2d, which requires supporting
55
- // the larger shift range (TODO: what is the actual range?).
56
- // Check this here in case a future change requires larger shift
57
- // values. In this case this function needs to be adjusted.
58
- assert(dist < 64);
59
- return __shiftright128(lo, hi, (unsigned char) dist);
60
- }
61
-
62
- #else // defined(HAS_64_BIT_INTRINSICS)
63
-
64
- static inline uint64_t umul128(const uint64_t a, const uint64_t b, uint64_t* const productHi) {
65
- // The casts here help MSVC to avoid calls to the __allmul library function.
66
- const uint32_t aLo = (uint32_t)a;
67
- const uint32_t aHi = (uint32_t)(a >> 32);
68
- const uint32_t bLo = (uint32_t)b;
69
- const uint32_t bHi = (uint32_t)(b >> 32);
70
-
71
- const uint64_t b00 = (uint64_t)aLo * bLo;
72
- const uint64_t b01 = (uint64_t)aLo * bHi;
73
- const uint64_t b10 = (uint64_t)aHi * bLo;
74
- const uint64_t b11 = (uint64_t)aHi * bHi;
75
-
76
- const uint32_t b00Lo = (uint32_t)b00;
77
- const uint32_t b00Hi = (uint32_t)(b00 >> 32);
78
-
79
- const uint64_t mid1 = b10 + b00Hi;
80
- const uint32_t mid1Lo = (uint32_t)(mid1);
81
- const uint32_t mid1Hi = (uint32_t)(mid1 >> 32);
82
-
83
- const uint64_t mid2 = b01 + mid1Lo;
84
- const uint32_t mid2Lo = (uint32_t)(mid2);
85
- const uint32_t mid2Hi = (uint32_t)(mid2 >> 32);
86
-
87
- const uint64_t pHi = b11 + mid1Hi + mid2Hi;
88
- const uint64_t pLo = ((uint64_t)mid2Lo << 32) | b00Lo;
89
-
90
- *productHi = pHi;
91
- return pLo;
92
- }
93
-
94
- static inline uint64_t shiftright128(const uint64_t lo, const uint64_t hi, const uint32_t dist) {
95
- // We don't need to handle the case dist >= 64 here (see above).
96
- assert(dist < 64);
97
- assert(dist > 0);
98
- return (hi << (64 - dist)) | (lo >> dist);
99
- }
100
-
101
- #endif // defined(HAS_64_BIT_INTRINSICS)
102
-
103
- #if defined(RYU_32_BIT_PLATFORM)
104
-
105
- // Returns the high 64 bits of the 128-bit product of a and b.
106
- static inline uint64_t umulh(const uint64_t a, const uint64_t b) {
107
- // Reuse the umul128 implementation.
108
- // Optimizers will likely eliminate the instructions used to compute the
109
- // low part of the product.
110
- uint64_t hi;
111
- umul128(a, b, &hi);
112
- return hi;
113
- }
114
-
115
- // On 32-bit platforms, compilers typically generate calls to library
116
- // functions for 64-bit divisions, even if the divisor is a constant.
117
- //
118
- // E.g.:
119
- // https://bugs.llvm.org/show_bug.cgi?id=37932
120
- // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17958
121
- // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37443
122
- //
123
- // The functions here perform division-by-constant using multiplications
124
- // in the same way as 64-bit compilers would do.
125
- //
126
- // NB:
127
- // The multipliers and shift values are the ones generated by clang x64
128
- // for expressions like x/5, x/10, etc.
129
-
130
- static inline uint64_t div5(const uint64_t x) {
131
- return umulh(x, 0xCCCCCCCCCCCCCCCDu) >> 2;
132
- }
133
-
134
- static inline uint64_t div10(const uint64_t x) {
135
- return umulh(x, 0xCCCCCCCCCCCCCCCDu) >> 3;
136
- }
137
-
138
- static inline uint64_t div100(const uint64_t x) {
139
- return umulh(x >> 2, 0x28F5C28F5C28F5C3u) >> 2;
140
- }
141
-
142
- static inline uint64_t div1e8(const uint64_t x) {
143
- return umulh(x, 0xABCC77118461CEFDu) >> 26;
144
- }
145
-
146
- static inline uint64_t div1e9(const uint64_t x) {
147
- return umulh(x >> 9, 0x44B82FA09B5A53u) >> 11;
148
- }
149
-
150
- static inline uint32_t mod1e9(const uint64_t x) {
151
- // Avoid 64-bit math as much as possible.
152
- // Returning (uint32_t) (x - 1000000000 * div1e9(x)) would
153
- // perform 32x64-bit multiplication and 64-bit subtraction.
154
- // x and 1000000000 * div1e9(x) are guaranteed to differ by
155
- // less than 10^9, so their highest 32 bits must be identical,
156
- // so we can truncate both sides to uint32_t before subtracting.
157
- // We can also simplify (uint32_t) (1000000000 * div1e9(x)).
158
- // We can truncate before multiplying instead of after, as multiplying
159
- // the highest 32 bits of div1e9(x) can't affect the lowest 32 bits.
160
- return ((uint32_t) x) - 1000000000 * ((uint32_t) div1e9(x));
161
- }
162
-
163
- #else // defined(RYU_32_BIT_PLATFORM)
164
-
165
- static inline uint64_t div5(const uint64_t x) {
166
- return x / 5;
167
- }
168
-
169
- static inline uint64_t div10(const uint64_t x) {
170
- return x / 10;
171
- }
172
-
173
- static inline uint64_t div100(const uint64_t x) {
174
- return x / 100;
175
- }
176
-
177
- static inline uint64_t div1e8(const uint64_t x) {
178
- return x / 100000000;
179
- }
180
-
181
- static inline uint64_t div1e9(const uint64_t x) {
182
- return x / 1000000000;
183
- }
184
-
185
- static inline uint32_t mod1e9(const uint64_t x) {
186
- return (uint32_t) (x - 1000000000 * div1e9(x));
187
- }
188
-
189
- #endif // defined(RYU_32_BIT_PLATFORM)
190
-
191
- static inline uint32_t pow5Factor(uint64_t value) {
192
- const uint64_t m_inv_5 = 14757395258967641293u; // 5 * m_inv_5 = 1 (mod 2^64)
193
- const uint64_t n_div_5 = 3689348814741910323u; // #{ n | n = 0 (mod 2^64) } = 2^64 / 5
194
- uint32_t count = 0;
195
- for (;;) {
196
- assert(value != 0);
197
- value *= m_inv_5;
198
- if (value > n_div_5)
199
- break;
200
- ++count;
201
- }
202
- return count;
203
- }
204
-
205
- // Returns true if value is divisible by 5^p.
206
- static inline bool multipleOfPowerOf5(const uint64_t value, const uint32_t p) {
207
- // I tried a case distinction on p, but there was no performance difference.
208
- return pow5Factor(value) >= p;
209
- }
210
-
211
- // Returns true if value is divisible by 2^p.
212
- static inline bool multipleOfPowerOf2(const uint64_t value, const uint32_t p) {
213
- assert(value != 0);
214
- assert(p < 64);
215
- // __builtin_ctzll doesn't appear to be faster here.
216
- return (value & ((1ull << p) - 1)) == 0;
217
- }
218
-
219
- // We need a 64x128-bit multiplication and a subsequent 128-bit shift.
220
- // Multiplication:
221
- // The 64-bit factor is variable and passed in, the 128-bit factor comes
222
- // from a lookup table. We know that the 64-bit factor only has 55
223
- // significant bits (i.e., the 9 topmost bits are zeros). The 128-bit
224
- // factor only has 124 significant bits (i.e., the 4 topmost bits are
225
- // zeros).
226
- // Shift:
227
- // In principle, the multiplication result requires 55 + 124 = 179 bits to
228
- // represent. However, we then shift this value to the right by j, which is
229
- // at least j >= 115, so the result is guaranteed to fit into 179 - 115 = 64
230
- // bits. This means that we only need the topmost 64 significant bits of
231
- // the 64x128-bit multiplication.
232
- //
233
- // There are several ways to do this:
234
- // 1. Best case: the compiler exposes a 128-bit type.
235
- // We perform two 64x64-bit multiplications, add the higher 64 bits of the
236
- // lower result to the higher result, and shift by j - 64 bits.
237
- //
238
- // We explicitly cast from 64-bit to 128-bit, so the compiler can tell
239
- // that these are only 64-bit inputs, and can map these to the best
240
- // possible sequence of assembly instructions.
241
- // x64 machines happen to have matching assembly instructions for
242
- // 64x64-bit multiplications and 128-bit shifts.
243
- //
244
- // 2. Second best case: the compiler exposes intrinsics for the x64 assembly
245
- // instructions mentioned in 1.
246
- //
247
- // 3. We only have 64x64 bit instructions that return the lower 64 bits of
248
- // the result, i.e., we have to use plain C.
249
- // Our inputs are less than the full width, so we have three options:
250
- // a. Ignore this fact and just implement the intrinsics manually.
251
- // b. Split both into 31-bit pieces, which guarantees no internal overflow,
252
- // but requires extra work upfront (unless we change the lookup table).
253
- // c. Split only the first factor into 31-bit pieces, which also guarantees
254
- // no internal overflow, but requires extra work since the intermediate
255
- // results are not perfectly aligned.
256
- #if defined(HAS_UINT128)
257
-
258
- // Best case: use 128-bit type.
259
- static inline uint64_t mulShift64(const uint64_t m, const uint64_t* const mul, const int32_t j) {
260
- const uint128_t b0 = ((uint128_t) m) * mul[0];
261
- const uint128_t b2 = ((uint128_t) m) * mul[1];
262
- return (uint64_t) (((b0 >> 64) + b2) >> (j - 64));
263
- }
264
-
265
- static inline uint64_t mulShiftAll64(const uint64_t m, const uint64_t* const mul, const int32_t j,
266
- uint64_t* const vp, uint64_t* const vm, const uint32_t mmShift) {
267
- // m <<= 2;
268
- // uint128_t b0 = ((uint128_t) m) * mul[0]; // 0
269
- // uint128_t b2 = ((uint128_t) m) * mul[1]; // 64
270
- //
271
- // uint128_t hi = (b0 >> 64) + b2;
272
- // uint128_t lo = b0 & 0xffffffffffffffffull;
273
- // uint128_t factor = (((uint128_t) mul[1]) << 64) + mul[0];
274
- // uint128_t vpLo = lo + (factor << 1);
275
- // *vp = (uint64_t) ((hi + (vpLo >> 64)) >> (j - 64));
276
- // uint128_t vmLo = lo - (factor << mmShift);
277
- // *vm = (uint64_t) ((hi + (vmLo >> 64) - (((uint128_t) 1ull) << 64)) >> (j - 64));
278
- // return (uint64_t) (hi >> (j - 64));
279
- *vp = mulShift64(4 * m + 2, mul, j);
280
- *vm = mulShift64(4 * m - 1 - mmShift, mul, j);
281
- return mulShift64(4 * m, mul, j);
282
- }
283
-
284
- #elif defined(HAS_64_BIT_INTRINSICS)
285
-
286
- static inline uint64_t mulShift64(const uint64_t m, const uint64_t* const mul, const int32_t j) {
287
- // m is maximum 55 bits
288
- uint64_t high1; // 128
289
- const uint64_t low1 = umul128(m, mul[1], &high1); // 64
290
- uint64_t high0; // 64
291
- umul128(m, mul[0], &high0); // 0
292
- const uint64_t sum = high0 + low1;
293
- if (sum < high0) {
294
- ++high1; // overflow into high1
295
- }
296
- return shiftright128(sum, high1, j - 64);
297
- }
298
-
299
- static inline uint64_t mulShiftAll64(const uint64_t m, const uint64_t* const mul, const int32_t j,
300
- uint64_t* const vp, uint64_t* const vm, const uint32_t mmShift) {
301
- *vp = mulShift64(4 * m + 2, mul, j);
302
- *vm = mulShift64(4 * m - 1 - mmShift, mul, j);
303
- return mulShift64(4 * m, mul, j);
304
- }
305
-
306
- #else // !defined(HAS_UINT128) && !defined(HAS_64_BIT_INTRINSICS)
307
-
308
- static inline uint64_t mulShift64(const uint64_t m, const uint64_t* const mul, const int32_t j) {
309
- // m is maximum 55 bits
310
- uint64_t high1; // 128
311
- const uint64_t low1 = umul128(m, mul[1], &high1); // 64
312
- uint64_t high0; // 64
313
- umul128(m, mul[0], &high0); // 0
314
- const uint64_t sum = high0 + low1;
315
- if (sum < high0) {
316
- ++high1; // overflow into high1
317
- }
318
- return shiftright128(sum, high1, j - 64);
319
- }
320
-
321
- // This is faster if we don't have a 64x64->128-bit multiplication.
322
- static inline uint64_t mulShiftAll64(uint64_t m, const uint64_t* const mul, const int32_t j,
323
- uint64_t* const vp, uint64_t* const vm, const uint32_t mmShift) {
324
- m <<= 1;
325
- // m is maximum 55 bits
326
- uint64_t tmp;
327
- const uint64_t lo = umul128(m, mul[0], &tmp);
328
- uint64_t hi;
329
- const uint64_t mid = tmp + umul128(m, mul[1], &hi);
330
- hi += mid < tmp; // overflow into hi
331
-
332
- const uint64_t lo2 = lo + mul[0];
333
- const uint64_t mid2 = mid + mul[1] + (lo2 < lo);
334
- const uint64_t hi2 = hi + (mid2 < mid);
335
- *vp = shiftright128(mid2, hi2, (uint32_t) (j - 64 - 1));
336
-
337
- if (mmShift == 1) {
338
- const uint64_t lo3 = lo - mul[0];
339
- const uint64_t mid3 = mid - mul[1] - (lo3 > lo);
340
- const uint64_t hi3 = hi - (mid3 > mid);
341
- *vm = shiftright128(mid3, hi3, (uint32_t) (j - 64 - 1));
342
- } else {
343
- const uint64_t lo3 = lo + lo;
344
- const uint64_t mid3 = mid + mid + (lo3 < lo);
345
- const uint64_t hi3 = hi + hi + (mid3 < mid);
346
- const uint64_t lo4 = lo3 - mul[0];
347
- const uint64_t mid4 = mid3 - mul[1] - (lo4 > lo3);
348
- const uint64_t hi4 = hi3 - (mid4 > mid3);
349
- *vm = shiftright128(mid4, hi4, (uint32_t) (j - 64));
350
- }
351
-
352
- return shiftright128(mid, hi, (uint32_t) (j - 64 - 1));
353
- }
354
-
355
- #endif // HAS_64_BIT_INTRINSICS
356
-
357
- #endif // RYU_D2S_INTRINSICS_H
1
+ // Copyright 2018 Ulf Adams
2
+ //
3
+ // The contents of this file may be used under the terms of the Apache License,
4
+ // Version 2.0.
5
+ //
6
+ // (See accompanying file LICENSE-Apache or copy at
7
+ // http://www.apache.org/licenses/LICENSE-2.0)
8
+ //
9
+ // Alternatively, the contents of this file may be used under the terms of
10
+ // the Boost Software License, Version 1.0.
11
+ // (See accompanying file LICENSE-Boost or copy at
12
+ // https://www.boost.org/LICENSE_1_0.txt)
13
+ //
14
+ // Unless required by applicable law or agreed to in writing, this software
15
+ // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ // KIND, either express or implied.
17
+ #ifndef RYU_D2S_INTRINSICS_H
18
+ #define RYU_D2S_INTRINSICS_H
19
+
20
+ #include <assert.h>
21
+ #include <stdint.h>
22
+
23
+ // Defines RYU_32_BIT_PLATFORM if applicable.
24
+ #include "ryu/common.h"
25
+
26
+ // ABSL avoids uint128_t on Win32 even if __SIZEOF_INT128__ is defined.
27
+ // Let's do the same for now.
28
+ #if defined(__SIZEOF_INT128__) && !defined(_MSC_VER) && !defined(RYU_ONLY_64_BIT_OPS)
29
+ #define HAS_UINT128
30
+ #elif defined(_MSC_VER) && !defined(RYU_ONLY_64_BIT_OPS) && defined(_M_X64)
31
+ #define HAS_64_BIT_INTRINSICS
32
+ #endif
33
+
34
+ #if defined(HAS_UINT128)
35
+ typedef __uint128_t uint128_t;
36
+ #endif
37
+
38
+ #if defined(HAS_64_BIT_INTRINSICS)
39
+
40
+ #include <intrin.h>
41
+
42
+ static inline uint64_t umul128(const uint64_t a, const uint64_t b, uint64_t* const productHi) {
43
+ return _umul128(a, b, productHi);
44
+ }
45
+
46
+ // Returns the lower 64 bits of (hi*2^64 + lo) >> dist, with 0 < dist < 64.
47
+ static inline uint64_t shiftright128(const uint64_t lo, const uint64_t hi, const uint32_t dist) {
48
+ // For the __shiftright128 intrinsic, the shift value is always
49
+ // modulo 64.
50
+ // In the current implementation of the double-precision version
51
+ // of Ryu, the shift value is always < 64. (In the case
52
+ // RYU_OPTIMIZE_SIZE == 0, the shift value is in the range [49, 58].
53
+ // Otherwise in the range [2, 59].)
54
+ // However, this function is now also called by s2d, which requires supporting
55
+ // the larger shift range (TODO: what is the actual range?).
56
+ // Check this here in case a future change requires larger shift
57
+ // values. In this case this function needs to be adjusted.
58
+ assert(dist < 64);
59
+ return __shiftright128(lo, hi, (unsigned char) dist);
60
+ }
61
+
62
+ #else // defined(HAS_64_BIT_INTRINSICS)
63
+
64
+ static inline uint64_t umul128(const uint64_t a, const uint64_t b, uint64_t* const productHi) {
65
+ // The casts here help MSVC to avoid calls to the __allmul library function.
66
+ const uint32_t aLo = (uint32_t)a;
67
+ const uint32_t aHi = (uint32_t)(a >> 32);
68
+ const uint32_t bLo = (uint32_t)b;
69
+ const uint32_t bHi = (uint32_t)(b >> 32);
70
+
71
+ const uint64_t b00 = (uint64_t)aLo * bLo;
72
+ const uint64_t b01 = (uint64_t)aLo * bHi;
73
+ const uint64_t b10 = (uint64_t)aHi * bLo;
74
+ const uint64_t b11 = (uint64_t)aHi * bHi;
75
+
76
+ const uint32_t b00Lo = (uint32_t)b00;
77
+ const uint32_t b00Hi = (uint32_t)(b00 >> 32);
78
+
79
+ const uint64_t mid1 = b10 + b00Hi;
80
+ const uint32_t mid1Lo = (uint32_t)(mid1);
81
+ const uint32_t mid1Hi = (uint32_t)(mid1 >> 32);
82
+
83
+ const uint64_t mid2 = b01 + mid1Lo;
84
+ const uint32_t mid2Lo = (uint32_t)(mid2);
85
+ const uint32_t mid2Hi = (uint32_t)(mid2 >> 32);
86
+
87
+ const uint64_t pHi = b11 + mid1Hi + mid2Hi;
88
+ const uint64_t pLo = ((uint64_t)mid2Lo << 32) | b00Lo;
89
+
90
+ *productHi = pHi;
91
+ return pLo;
92
+ }
93
+
94
+ static inline uint64_t shiftright128(const uint64_t lo, const uint64_t hi, const uint32_t dist) {
95
+ // We don't need to handle the case dist >= 64 here (see above).
96
+ assert(dist < 64);
97
+ assert(dist > 0);
98
+ return (hi << (64 - dist)) | (lo >> dist);
99
+ }
100
+
101
+ #endif // defined(HAS_64_BIT_INTRINSICS)
102
+
103
+ #if defined(RYU_32_BIT_PLATFORM)
104
+
105
+ // Returns the high 64 bits of the 128-bit product of a and b.
106
+ static inline uint64_t umulh(const uint64_t a, const uint64_t b) {
107
+ // Reuse the umul128 implementation.
108
+ // Optimizers will likely eliminate the instructions used to compute the
109
+ // low part of the product.
110
+ uint64_t hi;
111
+ umul128(a, b, &hi);
112
+ return hi;
113
+ }
114
+
115
+ // On 32-bit platforms, compilers typically generate calls to library
116
+ // functions for 64-bit divisions, even if the divisor is a constant.
117
+ //
118
+ // E.g.:
119
+ // https://bugs.llvm.org/show_bug.cgi?id=37932
120
+ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17958
121
+ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37443
122
+ //
123
+ // The functions here perform division-by-constant using multiplications
124
+ // in the same way as 64-bit compilers would do.
125
+ //
126
+ // NB:
127
+ // The multipliers and shift values are the ones generated by clang x64
128
+ // for expressions like x/5, x/10, etc.
129
+
130
+ static inline uint64_t div5(const uint64_t x) {
131
+ return umulh(x, 0xCCCCCCCCCCCCCCCDu) >> 2;
132
+ }
133
+
134
+ static inline uint64_t div10(const uint64_t x) {
135
+ return umulh(x, 0xCCCCCCCCCCCCCCCDu) >> 3;
136
+ }
137
+
138
+ static inline uint64_t div100(const uint64_t x) {
139
+ return umulh(x >> 2, 0x28F5C28F5C28F5C3u) >> 2;
140
+ }
141
+
142
+ static inline uint64_t div1e8(const uint64_t x) {
143
+ return umulh(x, 0xABCC77118461CEFDu) >> 26;
144
+ }
145
+
146
+ static inline uint64_t div1e9(const uint64_t x) {
147
+ return umulh(x >> 9, 0x44B82FA09B5A53u) >> 11;
148
+ }
149
+
150
+ static inline uint32_t mod1e9(const uint64_t x) {
151
+ // Avoid 64-bit math as much as possible.
152
+ // Returning (uint32_t) (x - 1000000000 * div1e9(x)) would
153
+ // perform 32x64-bit multiplication and 64-bit subtraction.
154
+ // x and 1000000000 * div1e9(x) are guaranteed to differ by
155
+ // less than 10^9, so their highest 32 bits must be identical,
156
+ // so we can truncate both sides to uint32_t before subtracting.
157
+ // We can also simplify (uint32_t) (1000000000 * div1e9(x)).
158
+ // We can truncate before multiplying instead of after, as multiplying
159
+ // the highest 32 bits of div1e9(x) can't affect the lowest 32 bits.
160
+ return ((uint32_t) x) - 1000000000 * ((uint32_t) div1e9(x));
161
+ }
162
+
163
+ #else // defined(RYU_32_BIT_PLATFORM)
164
+
165
+ static inline uint64_t div5(const uint64_t x) {
166
+ return x / 5;
167
+ }
168
+
169
+ static inline uint64_t div10(const uint64_t x) {
170
+ return x / 10;
171
+ }
172
+
173
+ static inline uint64_t div100(const uint64_t x) {
174
+ return x / 100;
175
+ }
176
+
177
+ static inline uint64_t div1e8(const uint64_t x) {
178
+ return x / 100000000;
179
+ }
180
+
181
+ static inline uint64_t div1e9(const uint64_t x) {
182
+ return x / 1000000000;
183
+ }
184
+
185
+ static inline uint32_t mod1e9(const uint64_t x) {
186
+ return (uint32_t) (x - 1000000000 * div1e9(x));
187
+ }
188
+
189
+ #endif // defined(RYU_32_BIT_PLATFORM)
190
+
191
+ static inline uint32_t pow5Factor(uint64_t value) {
192
+ const uint64_t m_inv_5 = 14757395258967641293u; // 5 * m_inv_5 = 1 (mod 2^64)
193
+ const uint64_t n_div_5 = 3689348814741910323u; // #{ n | n = 0 (mod 2^64) } = 2^64 / 5
194
+ uint32_t count = 0;
195
+ for (;;) {
196
+ assert(value != 0);
197
+ value *= m_inv_5;
198
+ if (value > n_div_5)
199
+ break;
200
+ ++count;
201
+ }
202
+ return count;
203
+ }
204
+
205
+ // Returns true if value is divisible by 5^p.
206
+ static inline bool multipleOfPowerOf5(const uint64_t value, const uint32_t p) {
207
+ // I tried a case distinction on p, but there was no performance difference.
208
+ return pow5Factor(value) >= p;
209
+ }
210
+
211
+ // Returns true if value is divisible by 2^p.
212
+ static inline bool multipleOfPowerOf2(const uint64_t value, const uint32_t p) {
213
+ assert(value != 0);
214
+ assert(p < 64);
215
+ // __builtin_ctzll doesn't appear to be faster here.
216
+ return (value & ((1ull << p) - 1)) == 0;
217
+ }
218
+
219
+ // We need a 64x128-bit multiplication and a subsequent 128-bit shift.
220
+ // Multiplication:
221
+ // The 64-bit factor is variable and passed in, the 128-bit factor comes
222
+ // from a lookup table. We know that the 64-bit factor only has 55
223
+ // significant bits (i.e., the 9 topmost bits are zeros). The 128-bit
224
+ // factor only has 124 significant bits (i.e., the 4 topmost bits are
225
+ // zeros).
226
+ // Shift:
227
+ // In principle, the multiplication result requires 55 + 124 = 179 bits to
228
+ // represent. However, we then shift this value to the right by j, which is
229
+ // at least j >= 115, so the result is guaranteed to fit into 179 - 115 = 64
230
+ // bits. This means that we only need the topmost 64 significant bits of
231
+ // the 64x128-bit multiplication.
232
+ //
233
+ // There are several ways to do this:
234
+ // 1. Best case: the compiler exposes a 128-bit type.
235
+ // We perform two 64x64-bit multiplications, add the higher 64 bits of the
236
+ // lower result to the higher result, and shift by j - 64 bits.
237
+ //
238
+ // We explicitly cast from 64-bit to 128-bit, so the compiler can tell
239
+ // that these are only 64-bit inputs, and can map these to the best
240
+ // possible sequence of assembly instructions.
241
+ // x64 machines happen to have matching assembly instructions for
242
+ // 64x64-bit multiplications and 128-bit shifts.
243
+ //
244
+ // 2. Second best case: the compiler exposes intrinsics for the x64 assembly
245
+ // instructions mentioned in 1.
246
+ //
247
+ // 3. We only have 64x64 bit instructions that return the lower 64 bits of
248
+ // the result, i.e., we have to use plain C.
249
+ // Our inputs are less than the full width, so we have three options:
250
+ // a. Ignore this fact and just implement the intrinsics manually.
251
+ // b. Split both into 31-bit pieces, which guarantees no internal overflow,
252
+ // but requires extra work upfront (unless we change the lookup table).
253
+ // c. Split only the first factor into 31-bit pieces, which also guarantees
254
+ // no internal overflow, but requires extra work since the intermediate
255
+ // results are not perfectly aligned.
256
+ #if defined(HAS_UINT128)
257
+
258
+ // Best case: use 128-bit type.
259
+ static inline uint64_t mulShift64(const uint64_t m, const uint64_t* const mul, const int32_t j) {
260
+ const uint128_t b0 = ((uint128_t) m) * mul[0];
261
+ const uint128_t b2 = ((uint128_t) m) * mul[1];
262
+ return (uint64_t) (((b0 >> 64) + b2) >> (j - 64));
263
+ }
264
+
265
+ static inline uint64_t mulShiftAll64(const uint64_t m, const uint64_t* const mul, const int32_t j,
266
+ uint64_t* const vp, uint64_t* const vm, const uint32_t mmShift) {
267
+ // m <<= 2;
268
+ // uint128_t b0 = ((uint128_t) m) * mul[0]; // 0
269
+ // uint128_t b2 = ((uint128_t) m) * mul[1]; // 64
270
+ //
271
+ // uint128_t hi = (b0 >> 64) + b2;
272
+ // uint128_t lo = b0 & 0xffffffffffffffffull;
273
+ // uint128_t factor = (((uint128_t) mul[1]) << 64) + mul[0];
274
+ // uint128_t vpLo = lo + (factor << 1);
275
+ // *vp = (uint64_t) ((hi + (vpLo >> 64)) >> (j - 64));
276
+ // uint128_t vmLo = lo - (factor << mmShift);
277
+ // *vm = (uint64_t) ((hi + (vmLo >> 64) - (((uint128_t) 1ull) << 64)) >> (j - 64));
278
+ // return (uint64_t) (hi >> (j - 64));
279
+ *vp = mulShift64(4 * m + 2, mul, j);
280
+ *vm = mulShift64(4 * m - 1 - mmShift, mul, j);
281
+ return mulShift64(4 * m, mul, j);
282
+ }
283
+
284
+ #elif defined(HAS_64_BIT_INTRINSICS)
285
+
286
+ static inline uint64_t mulShift64(const uint64_t m, const uint64_t* const mul, const int32_t j) {
287
+ // m is maximum 55 bits
288
+ uint64_t high1; // 128
289
+ const uint64_t low1 = umul128(m, mul[1], &high1); // 64
290
+ uint64_t high0; // 64
291
+ umul128(m, mul[0], &high0); // 0
292
+ const uint64_t sum = high0 + low1;
293
+ if (sum < high0) {
294
+ ++high1; // overflow into high1
295
+ }
296
+ return shiftright128(sum, high1, j - 64);
297
+ }
298
+
299
+ static inline uint64_t mulShiftAll64(const uint64_t m, const uint64_t* const mul, const int32_t j,
300
+ uint64_t* const vp, uint64_t* const vm, const uint32_t mmShift) {
301
+ *vp = mulShift64(4 * m + 2, mul, j);
302
+ *vm = mulShift64(4 * m - 1 - mmShift, mul, j);
303
+ return mulShift64(4 * m, mul, j);
304
+ }
305
+
306
+ #else // !defined(HAS_UINT128) && !defined(HAS_64_BIT_INTRINSICS)
307
+
308
+ static inline uint64_t mulShift64(const uint64_t m, const uint64_t* const mul, const int32_t j) {
309
+ // m is maximum 55 bits
310
+ uint64_t high1; // 128
311
+ const uint64_t low1 = umul128(m, mul[1], &high1); // 64
312
+ uint64_t high0; // 64
313
+ umul128(m, mul[0], &high0); // 0
314
+ const uint64_t sum = high0 + low1;
315
+ if (sum < high0) {
316
+ ++high1; // overflow into high1
317
+ }
318
+ return shiftright128(sum, high1, j - 64);
319
+ }
320
+
321
+ // This is faster if we don't have a 64x64->128-bit multiplication.
322
+ static inline uint64_t mulShiftAll64(uint64_t m, const uint64_t* const mul, const int32_t j,
323
+ uint64_t* const vp, uint64_t* const vm, const uint32_t mmShift) {
324
+ m <<= 1;
325
+ // m is maximum 55 bits
326
+ uint64_t tmp;
327
+ const uint64_t lo = umul128(m, mul[0], &tmp);
328
+ uint64_t hi;
329
+ const uint64_t mid = tmp + umul128(m, mul[1], &hi);
330
+ hi += mid < tmp; // overflow into hi
331
+
332
+ const uint64_t lo2 = lo + mul[0];
333
+ const uint64_t mid2 = mid + mul[1] + (lo2 < lo);
334
+ const uint64_t hi2 = hi + (mid2 < mid);
335
+ *vp = shiftright128(mid2, hi2, (uint32_t) (j - 64 - 1));
336
+
337
+ if (mmShift == 1) {
338
+ const uint64_t lo3 = lo - mul[0];
339
+ const uint64_t mid3 = mid - mul[1] - (lo3 > lo);
340
+ const uint64_t hi3 = hi - (mid3 > mid);
341
+ *vm = shiftright128(mid3, hi3, (uint32_t) (j - 64 - 1));
342
+ } else {
343
+ const uint64_t lo3 = lo + lo;
344
+ const uint64_t mid3 = mid + mid + (lo3 < lo);
345
+ const uint64_t hi3 = hi + hi + (mid3 < mid);
346
+ const uint64_t lo4 = lo3 - mul[0];
347
+ const uint64_t mid4 = mid3 - mul[1] - (lo4 > lo3);
348
+ const uint64_t hi4 = hi3 - (mid4 > mid3);
349
+ *vm = shiftright128(mid4, hi4, (uint32_t) (j - 64));
350
+ }
351
+
352
+ return shiftright128(mid, hi, (uint32_t) (j - 64 - 1));
353
+ }
354
+
355
+ #endif // HAS_64_BIT_INTRINSICS
356
+
357
+ #endif // RYU_D2S_INTRINSICS_H