visaljs 0.0.5 → 0.0.6

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 (433) hide show
  1. package/cli.js +469 -53
  2. package/node/include/js_node.h +36 -0
  3. package/node/prelude/async_hooks.js +63 -8
  4. package/node/prelude/buffer.js +0 -0
  5. package/node/prelude/diagnostics_channel.js +322 -0
  6. package/node/prelude/dns.js +3 -2
  7. package/node/prelude/events.js +17 -3
  8. package/node/prelude/fs.js +177 -5
  9. package/node/prelude/fs_promises.js +24 -0
  10. package/node/prelude/http.js +13 -4
  11. package/node/prelude/http2.js +0 -0
  12. package/node/prelude/internal/async_context.js +27 -0
  13. package/node/prelude/internal/crypto/asym.js +0 -0
  14. package/node/prelude/internal/crypto/cipher.js +0 -0
  15. package/node/prelude/internal/crypto/kdf.js +0 -0
  16. package/node/prelude/internal/crypto/keys.js +0 -0
  17. package/node/prelude/internal/crypto/random.js +0 -0
  18. package/node/prelude/internal/crypto/util.js +0 -0
  19. package/node/prelude/internal/errors.js +11 -0
  20. package/node/prelude/internal/process_events.js +14 -0
  21. package/node/prelude/internal/process_signals.js +42 -0
  22. package/node/prelude/internal/querystring.js +0 -0
  23. package/node/prelude/internal/timers.js +233 -0
  24. package/node/prelude/internal/timers_global.js +9 -0
  25. package/node/prelude/internal/zlib_brotli.js +6 -0
  26. package/node/prelude/internal/zlib_engines.js +4 -0
  27. package/node/prelude/internal/zlib_zstd.js +6 -0
  28. package/node/prelude/module.js +22 -6
  29. package/node/prelude/net.js +9 -8
  30. package/node/prelude/os.js +0 -0
  31. package/node/prelude/path.js +1599 -186
  32. package/node/prelude/path_posix.js +9 -0
  33. package/node/prelude/path_win32.js +9 -0
  34. package/node/prelude/process.js +3 -0
  35. package/node/prelude/querystring.js +0 -0
  36. package/node/prelude/stream.js +18 -6
  37. package/node/prelude/stream_promises.js +0 -0
  38. package/node/prelude/stream_web.js +0 -0
  39. package/node/prelude/string_decoder.js +0 -0
  40. package/node/prelude/timers.js +92 -0
  41. package/node/prelude/timers_promises.js +133 -0
  42. package/node/prelude/tty.js +0 -0
  43. package/node/prelude/url.js +0 -0
  44. package/node/prelude/util.js +0 -0
  45. package/node/prelude/zlib.js +912 -72
  46. package/node/src/host_brotli.c +157 -0
  47. package/node/src/host_fs.c +95 -1
  48. package/node/src/host_loop.c +10 -4
  49. package/node/src/host_os.c +0 -0
  50. package/node/src/host_signal.c +70 -0
  51. package/node/src/host_sys.c +50 -0
  52. package/node/src/host_zlib.c +314 -0
  53. package/node/src/host_zstd.c +179 -0
  54. package/node/third_party/brotli/LICENSE +19 -0
  55. package/node/third_party/brotli/common/constants.c +15 -0
  56. package/node/third_party/brotli/common/constants.h +201 -0
  57. package/node/third_party/brotli/common/context.c +156 -0
  58. package/node/third_party/brotli/common/context.h +113 -0
  59. package/node/third_party/brotli/common/dictionary.c +5916 -0
  60. package/node/third_party/brotli/common/dictionary.h +64 -0
  61. package/node/third_party/brotli/common/platform.c +23 -0
  62. package/node/third_party/brotli/common/platform.h +541 -0
  63. package/node/third_party/brotli/common/shared_dictionary.c +521 -0
  64. package/node/third_party/brotli/common/shared_dictionary_internal.h +75 -0
  65. package/node/third_party/brotli/common/transform.c +291 -0
  66. package/node/third_party/brotli/common/transform.h +85 -0
  67. package/node/third_party/brotli/common/version.h +51 -0
  68. package/node/third_party/brotli/dec/bit_reader.c +78 -0
  69. package/node/third_party/brotli/dec/bit_reader.h +423 -0
  70. package/node/third_party/brotli/dec/decode.c +2875 -0
  71. package/node/third_party/brotli/dec/huffman.c +342 -0
  72. package/node/third_party/brotli/dec/huffman.h +122 -0
  73. package/node/third_party/brotli/dec/prefix.h +733 -0
  74. package/node/third_party/brotli/dec/state.c +183 -0
  75. package/node/third_party/brotli/dec/state.h +400 -0
  76. package/node/third_party/brotli/enc/backward_references.c +207 -0
  77. package/node/third_party/brotli/enc/backward_references.h +40 -0
  78. package/node/third_party/brotli/enc/backward_references_hq.c +939 -0
  79. package/node/third_party/brotli/enc/backward_references_hq.h +96 -0
  80. package/node/third_party/brotli/enc/backward_references_inc.h +189 -0
  81. package/node/third_party/brotli/enc/bit_cost.c +36 -0
  82. package/node/third_party/brotli/enc/bit_cost.h +64 -0
  83. package/node/third_party/brotli/enc/bit_cost_inc.h +127 -0
  84. package/node/third_party/brotli/enc/block_encoder_inc.h +34 -0
  85. package/node/third_party/brotli/enc/block_splitter.c +217 -0
  86. package/node/third_party/brotli/enc/block_splitter.h +52 -0
  87. package/node/third_party/brotli/enc/block_splitter_inc.h +481 -0
  88. package/node/third_party/brotli/enc/brotli_bit_stream.c +1336 -0
  89. package/node/third_party/brotli/enc/brotli_bit_stream.h +89 -0
  90. package/node/third_party/brotli/enc/cluster.c +57 -0
  91. package/node/third_party/brotli/enc/cluster.h +49 -0
  92. package/node/third_party/brotli/enc/cluster_inc.h +325 -0
  93. package/node/third_party/brotli/enc/command.c +28 -0
  94. package/node/third_party/brotli/enc/command.h +191 -0
  95. package/node/third_party/brotli/enc/compound_dictionary.c +207 -0
  96. package/node/third_party/brotli/enc/compound_dictionary.h +74 -0
  97. package/node/third_party/brotli/enc/compress_fragment.c +800 -0
  98. package/node/third_party/brotli/enc/compress_fragment.h +86 -0
  99. package/node/third_party/brotli/enc/compress_fragment_two_pass.c +657 -0
  100. package/node/third_party/brotli/enc/compress_fragment_two_pass.h +72 -0
  101. package/node/third_party/brotli/enc/dictionary_hash.c +1848 -0
  102. package/node/third_party/brotli/enc/dictionary_hash.h +25 -0
  103. package/node/third_party/brotli/enc/encode.c +1996 -0
  104. package/node/third_party/brotli/enc/encoder_dict.c +640 -0
  105. package/node/third_party/brotli/enc/encoder_dict.h +157 -0
  106. package/node/third_party/brotli/enc/entropy_encode.c +504 -0
  107. package/node/third_party/brotli/enc/entropy_encode.h +123 -0
  108. package/node/third_party/brotli/enc/entropy_encode_static.h +542 -0
  109. package/node/third_party/brotli/enc/fast_log.c +105 -0
  110. package/node/third_party/brotli/enc/fast_log.h +67 -0
  111. package/node/third_party/brotli/enc/find_match_length.h +72 -0
  112. package/node/third_party/brotli/enc/hash.h +728 -0
  113. package/node/third_party/brotli/enc/hash_composite_inc.h +140 -0
  114. package/node/third_party/brotli/enc/hash_forgetful_chain_inc.h +295 -0
  115. package/node/third_party/brotli/enc/hash_longest_match64_inc.h +262 -0
  116. package/node/third_party/brotli/enc/hash_longest_match_inc.h +258 -0
  117. package/node/third_party/brotli/enc/hash_longest_match_quickly_inc.h +266 -0
  118. package/node/third_party/brotli/enc/hash_rolling_inc.h +212 -0
  119. package/node/third_party/brotli/enc/hash_to_binary_tree_inc.h +330 -0
  120. package/node/third_party/brotli/enc/histogram.c +100 -0
  121. package/node/third_party/brotli/enc/histogram.h +64 -0
  122. package/node/third_party/brotli/enc/histogram_inc.h +51 -0
  123. package/node/third_party/brotli/enc/literal_cost.c +180 -0
  124. package/node/third_party/brotli/enc/literal_cost.h +32 -0
  125. package/node/third_party/brotli/enc/memory.c +194 -0
  126. package/node/third_party/brotli/enc/memory.h +131 -0
  127. package/node/third_party/brotli/enc/metablock.c +677 -0
  128. package/node/third_party/brotli/enc/metablock.h +106 -0
  129. package/node/third_party/brotli/enc/metablock_inc.h +185 -0
  130. package/node/third_party/brotli/enc/params.h +47 -0
  131. package/node/third_party/brotli/enc/prefix.h +54 -0
  132. package/node/third_party/brotli/enc/quality.h +202 -0
  133. package/node/third_party/brotli/enc/ringbuffer.h +168 -0
  134. package/node/third_party/brotli/enc/state.h +104 -0
  135. package/node/third_party/brotli/enc/static_dict.c +542 -0
  136. package/node/third_party/brotli/enc/static_dict.h +41 -0
  137. package/node/third_party/brotli/enc/static_dict_lut.h +5866 -0
  138. package/node/third_party/brotli/enc/utf8_util.c +85 -0
  139. package/node/third_party/brotli/enc/utf8_util.h +33 -0
  140. package/node/third_party/brotli/enc/write_bits.h +88 -0
  141. package/node/third_party/brotli/include/brotli/decode.h +409 -0
  142. package/node/third_party/brotli/include/brotli/encode.h +501 -0
  143. package/node/third_party/brotli/include/brotli/port.h +305 -0
  144. package/node/third_party/brotli/include/brotli/shared_dictionary.h +100 -0
  145. package/node/third_party/brotli/include/brotli/types.h +83 -0
  146. package/node/third_party/libuv/LICENSE +0 -0
  147. package/node/third_party/libuv/include/uv/aix.h +0 -0
  148. package/node/third_party/libuv/include/uv/bsd.h +0 -0
  149. package/node/third_party/libuv/include/uv/darwin.h +0 -0
  150. package/node/third_party/libuv/include/uv/errno.h +0 -0
  151. package/node/third_party/libuv/include/uv/linux.h +0 -0
  152. package/node/third_party/libuv/include/uv/os390.h +0 -0
  153. package/node/third_party/libuv/include/uv/posix.h +0 -0
  154. package/node/third_party/libuv/include/uv/sunos.h +0 -0
  155. package/node/third_party/libuv/include/uv/threadpool.h +0 -0
  156. package/node/third_party/libuv/include/uv/tree.h +0 -0
  157. package/node/third_party/libuv/include/uv/unix.h +0 -0
  158. package/node/third_party/libuv/include/uv/version.h +0 -0
  159. package/node/third_party/libuv/include/uv/win.h +0 -0
  160. package/node/third_party/libuv/include/uv.h +0 -0
  161. package/node/third_party/libuv/src/fs-poll.c +0 -0
  162. package/node/third_party/libuv/src/heap-inl.h +0 -0
  163. package/node/third_party/libuv/src/idna.c +0 -0
  164. package/node/third_party/libuv/src/idna.h +0 -0
  165. package/node/third_party/libuv/src/inet.c +0 -0
  166. package/node/third_party/libuv/src/queue.h +0 -0
  167. package/node/third_party/libuv/src/random.c +0 -0
  168. package/node/third_party/libuv/src/strscpy.c +0 -0
  169. package/node/third_party/libuv/src/strscpy.h +0 -0
  170. package/node/third_party/libuv/src/strtok.c +0 -0
  171. package/node/third_party/libuv/src/strtok.h +0 -0
  172. package/node/third_party/libuv/src/thread-common.c +0 -0
  173. package/node/third_party/libuv/src/threadpool.c +0 -0
  174. package/node/third_party/libuv/src/timer.c +0 -0
  175. package/node/third_party/libuv/src/unix/async.c +0 -0
  176. package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +0 -0
  177. package/node/third_party/libuv/src/unix/core.c +0 -0
  178. package/node/third_party/libuv/src/unix/darwin-proctitle.c +0 -0
  179. package/node/third_party/libuv/src/unix/darwin-stub.h +0 -0
  180. package/node/third_party/libuv/src/unix/darwin-syscalls.h +0 -0
  181. package/node/third_party/libuv/src/unix/darwin.c +0 -0
  182. package/node/third_party/libuv/src/unix/dl.c +0 -0
  183. package/node/third_party/libuv/src/unix/fs.c +0 -0
  184. package/node/third_party/libuv/src/unix/fsevents.c +0 -0
  185. package/node/third_party/libuv/src/unix/getaddrinfo.c +0 -0
  186. package/node/third_party/libuv/src/unix/getnameinfo.c +0 -0
  187. package/node/third_party/libuv/src/unix/internal.h +0 -0
  188. package/node/third_party/libuv/src/unix/kqueue.c +0 -0
  189. package/node/third_party/libuv/src/unix/linux.c +0 -0
  190. package/node/third_party/libuv/src/unix/loop-watcher.c +0 -0
  191. package/node/third_party/libuv/src/unix/loop.c +0 -0
  192. package/node/third_party/libuv/src/unix/pipe.c +0 -0
  193. package/node/third_party/libuv/src/unix/poll.c +0 -0
  194. package/node/third_party/libuv/src/unix/process.c +0 -0
  195. package/node/third_party/libuv/src/unix/procfs-exepath.c +0 -0
  196. package/node/third_party/libuv/src/unix/proctitle.c +0 -0
  197. package/node/third_party/libuv/src/unix/random-devurandom.c +0 -0
  198. package/node/third_party/libuv/src/unix/random-getentropy.c +0 -0
  199. package/node/third_party/libuv/src/unix/random-getrandom.c +0 -0
  200. package/node/third_party/libuv/src/unix/random-sysctl-linux.c +0 -0
  201. package/node/third_party/libuv/src/unix/signal.c +0 -0
  202. package/node/third_party/libuv/src/unix/stream.c +0 -0
  203. package/node/third_party/libuv/src/unix/tcp.c +0 -0
  204. package/node/third_party/libuv/src/unix/thread.c +0 -0
  205. package/node/third_party/libuv/src/unix/tty.c +0 -0
  206. package/node/third_party/libuv/src/unix/udp.c +0 -0
  207. package/node/third_party/libuv/src/uv-common.c +0 -0
  208. package/node/third_party/libuv/src/uv-common.h +0 -0
  209. package/node/third_party/libuv/src/uv-data-getter-setters.c +0 -0
  210. package/node/third_party/libuv/src/version.c +0 -0
  211. package/node/third_party/llhttp/LICENSE +0 -0
  212. package/node/third_party/llhttp/api.c +0 -0
  213. package/node/third_party/llhttp/http.c +0 -0
  214. package/node/third_party/llhttp/llhttp.c +0 -0
  215. package/node/third_party/llhttp/llhttp.h +0 -0
  216. package/node/third_party/zlib/LICENSE +19 -0
  217. package/node/third_party/zlib/README.chromium +38 -0
  218. package/node/third_party/zlib/adler32.c +197 -0
  219. package/node/third_party/zlib/chromeconf.h +203 -0
  220. package/node/third_party/zlib/contrib/optimizations/insert_string.h +80 -0
  221. package/node/third_party/zlib/cpu_features.c +213 -0
  222. package/node/third_party/zlib/cpu_features.h +22 -0
  223. package/node/third_party/zlib/crc32.c +1192 -0
  224. package/node/third_party/zlib/crc32.h +9446 -0
  225. package/node/third_party/zlib/deflate.c +2289 -0
  226. package/node/third_party/zlib/deflate.h +407 -0
  227. package/node/third_party/zlib/gzguts.h +214 -0
  228. package/node/third_party/zlib/inffast.c +327 -0
  229. package/node/third_party/zlib/inffast.h +26 -0
  230. package/node/third_party/zlib/inffixed.h +94 -0
  231. package/node/third_party/zlib/inflate.c +1528 -0
  232. package/node/third_party/zlib/inflate.h +126 -0
  233. package/node/third_party/zlib/inftrees.c +299 -0
  234. package/node/third_party/zlib/inftrees.h +62 -0
  235. package/node/third_party/zlib/trees.c +1161 -0
  236. package/node/third_party/zlib/trees.h +128 -0
  237. package/node/third_party/zlib/zconf.h +558 -0
  238. package/node/third_party/zlib/zlib.h +1967 -0
  239. package/node/third_party/zlib/zutil.c +299 -0
  240. package/node/third_party/zlib/zutil.h +275 -0
  241. package/node/third_party/zstd/LICENSE +30 -0
  242. package/node/third_party/zstd/common/allocations.h +55 -0
  243. package/node/third_party/zstd/common/bits.h +205 -0
  244. package/node/third_party/zstd/common/bitstream.h +454 -0
  245. package/node/third_party/zstd/common/compiler.h +464 -0
  246. package/node/third_party/zstd/common/cpu.h +249 -0
  247. package/node/third_party/zstd/common/debug.c +30 -0
  248. package/node/third_party/zstd/common/debug.h +107 -0
  249. package/node/third_party/zstd/common/entropy_common.c +340 -0
  250. package/node/third_party/zstd/common/error_private.c +64 -0
  251. package/node/third_party/zstd/common/error_private.h +158 -0
  252. package/node/third_party/zstd/common/fse.h +625 -0
  253. package/node/third_party/zstd/common/fse_decompress.c +315 -0
  254. package/node/third_party/zstd/common/huf.h +277 -0
  255. package/node/third_party/zstd/common/mem.h +422 -0
  256. package/node/third_party/zstd/common/pool.c +371 -0
  257. package/node/third_party/zstd/common/pool.h +81 -0
  258. package/node/third_party/zstd/common/portability_macros.h +171 -0
  259. package/node/third_party/zstd/common/threading.c +182 -0
  260. package/node/third_party/zstd/common/threading.h +142 -0
  261. package/node/third_party/zstd/common/xxhash.c +18 -0
  262. package/node/third_party/zstd/common/xxhash.h +7094 -0
  263. package/node/third_party/zstd/common/zstd_common.c +48 -0
  264. package/node/third_party/zstd/common/zstd_deps.h +123 -0
  265. package/node/third_party/zstd/common/zstd_internal.h +324 -0
  266. package/node/third_party/zstd/common/zstd_trace.h +156 -0
  267. package/node/third_party/zstd/compress/clevels.h +134 -0
  268. package/node/third_party/zstd/compress/fse_compress.c +625 -0
  269. package/node/third_party/zstd/compress/hist.c +191 -0
  270. package/node/third_party/zstd/compress/hist.h +82 -0
  271. package/node/third_party/zstd/compress/huf_compress.c +1464 -0
  272. package/node/third_party/zstd/compress/zstd_compress.c +7843 -0
  273. package/node/third_party/zstd/compress/zstd_compress_internal.h +1636 -0
  274. package/node/third_party/zstd/compress/zstd_compress_literals.c +235 -0
  275. package/node/third_party/zstd/compress/zstd_compress_literals.h +39 -0
  276. package/node/third_party/zstd/compress/zstd_compress_sequences.c +442 -0
  277. package/node/third_party/zstd/compress/zstd_compress_sequences.h +55 -0
  278. package/node/third_party/zstd/compress/zstd_compress_superblock.c +688 -0
  279. package/node/third_party/zstd/compress/zstd_compress_superblock.h +32 -0
  280. package/node/third_party/zstd/compress/zstd_cwksp.h +765 -0
  281. package/node/third_party/zstd/compress/zstd_double_fast.c +778 -0
  282. package/node/third_party/zstd/compress/zstd_double_fast.h +42 -0
  283. package/node/third_party/zstd/compress/zstd_fast.c +985 -0
  284. package/node/third_party/zstd/compress/zstd_fast.h +30 -0
  285. package/node/third_party/zstd/compress/zstd_lazy.c +2199 -0
  286. package/node/third_party/zstd/compress/zstd_lazy.h +193 -0
  287. package/node/third_party/zstd/compress/zstd_ldm.c +745 -0
  288. package/node/third_party/zstd/compress/zstd_ldm.h +109 -0
  289. package/node/third_party/zstd/compress/zstd_ldm_geartab.h +106 -0
  290. package/node/third_party/zstd/compress/zstd_opt.c +1580 -0
  291. package/node/third_party/zstd/compress/zstd_opt.h +72 -0
  292. package/node/third_party/zstd/compress/zstd_preSplit.c +238 -0
  293. package/node/third_party/zstd/compress/zstd_preSplit.h +33 -0
  294. package/node/third_party/zstd/compress/zstdmt_compress.c +1923 -0
  295. package/node/third_party/zstd/compress/zstdmt_compress.h +102 -0
  296. package/node/third_party/zstd/decompress/huf_decompress.c +1944 -0
  297. package/node/third_party/zstd/decompress/zstd_ddict.c +244 -0
  298. package/node/third_party/zstd/decompress/zstd_ddict.h +44 -0
  299. package/node/third_party/zstd/decompress/zstd_decompress.c +2410 -0
  300. package/node/third_party/zstd/decompress/zstd_decompress_block.c +2209 -0
  301. package/node/third_party/zstd/decompress/zstd_decompress_block.h +73 -0
  302. package/node/third_party/zstd/decompress/zstd_decompress_internal.h +240 -0
  303. package/node/third_party/zstd/zdict.h +481 -0
  304. package/node/third_party/zstd/zstd.h +3198 -0
  305. package/node/third_party/zstd/zstd_errors.h +107 -0
  306. package/package.json +2 -3
  307. package/runtime/include/js_atoms.gen.h +0 -0
  308. package/runtime/include/js_atoms.h +0 -0
  309. package/runtime/include/js_bigint.h +0 -0
  310. package/runtime/include/js_buffer.h +0 -0
  311. package/runtime/include/js_builtins.h +0 -0
  312. package/runtime/include/js_console.h +5 -2
  313. package/runtime/include/js_convert.h +0 -0
  314. package/runtime/include/js_core.def +0 -0
  315. package/runtime/include/js_error.h +0 -0
  316. package/runtime/include/js_exception.h +0 -0
  317. package/runtime/include/js_function.h +0 -0
  318. package/runtime/include/js_gc.h +0 -0
  319. package/runtime/include/js_generator.h +0 -0
  320. package/runtime/include/js_host.h +5 -3
  321. package/runtime/include/js_jobs.h +18 -1
  322. package/runtime/include/js_module.h +0 -0
  323. package/runtime/include/js_object.h +0 -0
  324. package/runtime/include/js_ops.h +0 -0
  325. package/runtime/include/js_promise.h +1 -0
  326. package/runtime/include/js_regexp.h +0 -0
  327. package/runtime/include/js_runtime.h +0 -0
  328. package/runtime/include/js_symbol.h +0 -0
  329. package/runtime/include/js_web.h +0 -0
  330. package/runtime/include/jscell.h +0 -0
  331. package/runtime/include/jscontext.h +14 -0
  332. package/runtime/include/jsnum.h +0 -0
  333. package/runtime/include/jsstring.h +0 -0
  334. package/runtime/include/jsvalue.h +0 -0
  335. package/runtime/src/arguments.c +0 -0
  336. package/runtime/src/array.c +0 -0
  337. package/runtime/src/arraybuffer.c +0 -0
  338. package/runtime/src/async_iter.c +0 -0
  339. package/runtime/src/atoms.c +0 -0
  340. package/runtime/src/base64.c +0 -0
  341. package/runtime/src/bigint.c +0 -0
  342. package/runtime/src/blob.c +0 -0
  343. package/runtime/src/buffer.c +20 -16
  344. package/runtime/src/builtin_table.c +0 -0
  345. package/runtime/src/builtins.c +0 -0
  346. package/runtime/src/builtins_util.h +0 -0
  347. package/runtime/src/collections.c +0 -0
  348. package/runtime/src/components.c +0 -0
  349. package/runtime/src/console.c +15 -2
  350. package/runtime/src/convert.c +0 -0
  351. package/runtime/src/core_all.c +0 -0
  352. package/runtime/src/crypto.c +0 -0
  353. package/runtime/src/crypto_host.c +0 -0
  354. package/runtime/src/crypto_kdf.c +0 -0
  355. package/runtime/src/crypto_key.c +0 -0
  356. package/runtime/src/date.c +0 -0
  357. package/runtime/src/domexception.c +0 -0
  358. package/runtime/src/elements.c +0 -0
  359. package/runtime/src/elements.h +0 -0
  360. package/runtime/src/encoding.c +0 -0
  361. package/runtime/src/error.c +0 -0
  362. package/runtime/src/events.c +1 -1
  363. package/runtime/src/exception.c +0 -0
  364. package/runtime/src/fetch.c +0 -0
  365. package/runtime/src/function.c +0 -0
  366. package/runtime/src/gc.c +2 -0
  367. package/runtime/src/generator.c +0 -0
  368. package/runtime/src/global.c +0 -0
  369. package/runtime/src/headers.c +0 -0
  370. package/runtime/src/inspect.c +0 -0
  371. package/runtime/src/internal.h +0 -0
  372. package/runtime/src/iterate.c +0 -0
  373. package/runtime/src/iterator.c +0 -0
  374. package/runtime/src/jobs.c +123 -44
  375. package/runtime/src/jsnum.c +0 -0
  376. package/runtime/src/json.c +0 -0
  377. package/runtime/src/math.c +0 -0
  378. package/runtime/src/module.c +0 -0
  379. package/runtime/src/number.c +0 -0
  380. package/runtime/src/object.c +0 -0
  381. package/runtime/src/ops.c +0 -0
  382. package/runtime/src/os.c +0 -0
  383. package/runtime/src/os.h +0 -0
  384. package/runtime/src/process.c +92 -8
  385. package/runtime/src/promise.c +7 -2
  386. package/runtime/src/proxy.c +0 -0
  387. package/runtime/src/reflect.c +0 -0
  388. package/runtime/src/regexp.c +0 -0
  389. package/runtime/src/regexp_anchor.h +0 -0
  390. package/runtime/src/regexp_message.h +0 -0
  391. package/runtime/src/shape.c +0 -0
  392. package/runtime/src/shape.h +0 -0
  393. package/runtime/src/streams.c +0 -0
  394. package/runtime/src/streams.h +0 -0
  395. package/runtime/src/string.c +0 -0
  396. package/runtime/src/string_builtins.c +0 -0
  397. package/runtime/src/symbol.c +0 -0
  398. package/runtime/src/test_host.c +0 -0
  399. package/runtime/src/typedarray.c +0 -0
  400. package/runtime/src/tznames.gen.h +0 -0
  401. package/runtime/src/uri.c +0 -0
  402. package/runtime/src/url.c +0 -0
  403. package/runtime/src/weak.c +1 -4
  404. package/runtime/src/web.c +0 -0
  405. package/runtime/src/wrapper.c +0 -0
  406. package/runtime/src/writable.c +0 -0
  407. package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
  408. package/runtime/third_party/ada-idna/README.md +0 -0
  409. package/runtime/third_party/ada-idna/convert.mjs +0 -0
  410. package/runtime/third_party/ada-idna/idna.c +0 -0
  411. package/runtime/third_party/ada-idna/idna.h +0 -0
  412. package/runtime/third_party/ada-idna/idna_tables.h +0 -0
  413. package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
  414. package/runtime/third_party/quickjs-dtoa/README.md +0 -0
  415. package/runtime/third_party/quickjs-dtoa/dtoa.c +0 -0
  416. package/runtime/third_party/quickjs-dtoa/dtoa.h +0 -0
  417. package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +0 -0
  418. package/runtime/third_party/quickjs-regexp/LICENSE +0 -0
  419. package/runtime/third_party/quickjs-regexp/README.md +0 -0
  420. package/runtime/third_party/quickjs-regexp/cutils.c +0 -0
  421. package/runtime/third_party/quickjs-regexp/cutils.h +0 -0
  422. package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +0 -0
  423. package/runtime/third_party/quickjs-regexp/libregexp.c +0 -0
  424. package/runtime/third_party/quickjs-regexp/libregexp.h +0 -0
  425. package/runtime/third_party/quickjs-regexp/libunicode-table.h +0 -0
  426. package/runtime/third_party/quickjs-regexp/libunicode.c +0 -0
  427. package/runtime/third_party/quickjs-regexp/libunicode.h +0 -0
  428. package/runtime/third_party/v8-ieee754/LICENSE +0 -0
  429. package/runtime/third_party/v8-ieee754/README.md +0 -0
  430. package/runtime/third_party/v8-ieee754/convert.py +0 -0
  431. package/runtime/third_party/v8-ieee754/ieee754.c +0 -0
  432. package/runtime/third_party/v8-ieee754/ieee754.h +0 -0
  433. package/runtime/tools/regexp_compile.c +0 -0
@@ -0,0 +1,1192 @@
1
+ /* crc32.c -- compute the CRC-32 of a data stream
2
+ * Copyright (C) 1995-2022 Mark Adler
3
+ * For conditions of distribution and use, see copyright notice in zlib.h
4
+ *
5
+ * This interleaved implementation of a CRC makes use of pipelined multiple
6
+ * arithmetic-logic units, commonly found in modern CPU cores. It is due to
7
+ * Kadatch and Jenkins (2010). See doc/crc-doc.1.0.pdf in this distribution.
8
+ */
9
+
10
+ /* @(#) $Id$ */
11
+
12
+ /*
13
+ Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
14
+ protection on the static variables used to control the first-use generation
15
+ of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
16
+ first call get_crc_table() to initialize the tables before allowing more than
17
+ one thread to use crc32().
18
+
19
+ MAKECRCH can be #defined to write out crc32.h. A main() routine is also
20
+ produced, so that this one source file can be compiled to an executable.
21
+ */
22
+
23
+ #ifdef MAKECRCH
24
+ # include <stdio.h>
25
+ # ifndef DYNAMIC_CRC_TABLE
26
+ # define DYNAMIC_CRC_TABLE
27
+ # endif /* !DYNAMIC_CRC_TABLE */
28
+ #endif /* MAKECRCH */
29
+
30
+ #include "deflate.h"
31
+ #include "cpu_features.h"
32
+ #include "zutil.h" /* for Z_U4, Z_U8, z_crc_t, and FAR definitions */
33
+
34
+ #if defined(CRC32_SIMD_SSE42_PCLMUL) || defined(CRC32_ARMV8_CRC32)
35
+ #include "crc32_simd.h"
36
+ #endif
37
+
38
+ /*
39
+ A CRC of a message is computed on N braids of words in the message, where
40
+ each word consists of W bytes (4 or 8). If N is 3, for example, then three
41
+ running sparse CRCs are calculated respectively on each braid, at these
42
+ indices in the array of words: 0, 3, 6, ..., 1, 4, 7, ..., and 2, 5, 8, ...
43
+ This is done starting at a word boundary, and continues until as many blocks
44
+ of N * W bytes as are available have been processed. The results are combined
45
+ into a single CRC at the end. For this code, N must be in the range 1..6 and
46
+ W must be 4 or 8. The upper limit on N can be increased if desired by adding
47
+ more #if blocks, extending the patterns apparent in the code. In addition,
48
+ crc32.h would need to be regenerated, if the maximum N value is increased.
49
+
50
+ N and W are chosen empirically by benchmarking the execution time on a given
51
+ processor. The choices for N and W below were based on testing on Intel Kaby
52
+ Lake i7, AMD Ryzen 7, ARM Cortex-A57, Sparc64-VII, PowerPC POWER9, and MIPS64
53
+ Octeon II processors. The Intel, AMD, and ARM processors were all fastest
54
+ with N=5, W=8. The Sparc, PowerPC, and MIPS64 were all fastest at N=5, W=4.
55
+ They were all tested with either gcc or clang, all using the -O3 optimization
56
+ level. Your mileage may vary.
57
+ */
58
+
59
+ /* Define N */
60
+ #ifdef Z_TESTN
61
+ # define N Z_TESTN
62
+ #else
63
+ # define N 5
64
+ #endif
65
+ #if N < 1 || N > 6
66
+ # error N must be in 1..6
67
+ #endif
68
+
69
+ /*
70
+ z_crc_t must be at least 32 bits. z_word_t must be at least as long as
71
+ z_crc_t. It is assumed here that z_word_t is either 32 bits or 64 bits, and
72
+ that bytes are eight bits.
73
+ */
74
+
75
+ /*
76
+ Define W and the associated z_word_t type. If W is not defined, then a
77
+ braided calculation is not used, and the associated tables and code are not
78
+ compiled.
79
+ */
80
+ #ifdef Z_TESTW
81
+ # if Z_TESTW-1 != -1
82
+ # define W Z_TESTW
83
+ # endif
84
+ #else
85
+ # ifdef MAKECRCH
86
+ # define W 8 /* required for MAKECRCH */
87
+ # else
88
+ # if defined(__x86_64__) || defined(__aarch64__)
89
+ # define W 8
90
+ # else
91
+ # define W 4
92
+ # endif
93
+ # endif
94
+ #endif
95
+ #ifdef W
96
+ # if W == 8 && defined(Z_U8)
97
+ typedef Z_U8 z_word_t;
98
+ # elif defined(Z_U4)
99
+ # undef W
100
+ # define W 4
101
+ typedef Z_U4 z_word_t;
102
+ # else
103
+ # undef W
104
+ # endif
105
+ #endif
106
+
107
+ /* If available, use the ARM processor CRC32 instruction. */
108
+ #if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) && W == 8 \
109
+ && defined(USE_CANONICAL_ARMV8_CRC32)
110
+ # define ARMCRC32_CANONICAL_ZLIB
111
+ #endif
112
+
113
+ #if defined(W) && (!defined(ARMCRC32_CANONICAL_ZLIB) || defined(DYNAMIC_CRC_TABLE))
114
+ /*
115
+ Swap the bytes in a z_word_t to convert between little and big endian. Any
116
+ self-respecting compiler will optimize this to a single machine byte-swap
117
+ instruction, if one is available. This assumes that word_t is either 32 bits
118
+ or 64 bits.
119
+ */
120
+ local z_word_t byte_swap(z_word_t word) {
121
+ # if W == 8
122
+ return
123
+ (word & 0xff00000000000000) >> 56 |
124
+ (word & 0xff000000000000) >> 40 |
125
+ (word & 0xff0000000000) >> 24 |
126
+ (word & 0xff00000000) >> 8 |
127
+ (word & 0xff000000) << 8 |
128
+ (word & 0xff0000) << 24 |
129
+ (word & 0xff00) << 40 |
130
+ (word & 0xff) << 56;
131
+ # else /* W == 4 */
132
+ return
133
+ (word & 0xff000000) >> 24 |
134
+ (word & 0xff0000) >> 8 |
135
+ (word & 0xff00) << 8 |
136
+ (word & 0xff) << 24;
137
+ # endif
138
+ }
139
+ #endif
140
+
141
+ #ifdef DYNAMIC_CRC_TABLE
142
+ /* =========================================================================
143
+ * Table of powers of x for combining CRC-32s, filled in by make_crc_table()
144
+ * below.
145
+ */
146
+ local z_crc_t FAR x2n_table[32];
147
+ #else
148
+ /* =========================================================================
149
+ * Tables for byte-wise and braided CRC-32 calculations, and a table of powers
150
+ * of x for combining CRC-32s, all made by make_crc_table().
151
+ */
152
+ # include "crc32.h"
153
+ #endif
154
+
155
+ /* CRC polynomial. */
156
+ #define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */
157
+
158
+ /*
159
+ Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial,
160
+ reflected. For speed, this requires that a not be zero.
161
+ */
162
+ local z_crc_t multmodp(z_crc_t a, z_crc_t b) {
163
+ z_crc_t m, p;
164
+
165
+ m = (z_crc_t)1 << 31;
166
+ p = 0;
167
+ for (;;) {
168
+ if (a & m) {
169
+ p ^= b;
170
+ if ((a & (m - 1)) == 0)
171
+ break;
172
+ }
173
+ m >>= 1;
174
+ b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
175
+ }
176
+ return p;
177
+ }
178
+
179
+ /*
180
+ Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been
181
+ initialized.
182
+ */
183
+ local z_crc_t x2nmodp(z_off64_t n, unsigned k) {
184
+ z_crc_t p;
185
+
186
+ p = (z_crc_t)1 << 31; /* x^0 == 1 */
187
+ while (n) {
188
+ if (n & 1)
189
+ p = multmodp(x2n_table[k & 31], p);
190
+ n >>= 1;
191
+ k++;
192
+ }
193
+ return p;
194
+ }
195
+
196
+ #ifdef DYNAMIC_CRC_TABLE
197
+ /* =========================================================================
198
+ * Build the tables for byte-wise and braided CRC-32 calculations, and a table
199
+ * of powers of x for combining CRC-32s.
200
+ */
201
+ local z_crc_t FAR crc_table[256];
202
+ #ifdef W
203
+ local z_word_t FAR crc_big_table[256];
204
+ local z_crc_t FAR crc_braid_table[W][256];
205
+ local z_word_t FAR crc_braid_big_table[W][256];
206
+ local void braid(z_crc_t [][256], z_word_t [][256], int, int);
207
+ #endif
208
+ #ifdef MAKECRCH
209
+ local void write_table(FILE *, const z_crc_t FAR *, int);
210
+ local void write_table32hi(FILE *, const z_word_t FAR *, int);
211
+ local void write_table64(FILE *, const z_word_t FAR *, int);
212
+ #endif /* MAKECRCH */
213
+
214
+ /*
215
+ Define a once() function depending on the availability of atomics. If this is
216
+ compiled with DYNAMIC_CRC_TABLE defined, and if CRCs will be computed in
217
+ multiple threads, and if atomics are not available, then get_crc_table() must
218
+ be called to initialize the tables and must return before any threads are
219
+ allowed to compute or combine CRCs.
220
+ */
221
+
222
+ /* Definition of once functionality. */
223
+ typedef struct once_s once_t;
224
+
225
+ /* Check for the availability of atomics. */
226
+ #if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \
227
+ !defined(__STDC_NO_ATOMICS__)
228
+
229
+ #include <stdatomic.h>
230
+
231
+ /* Structure for once(), which must be initialized with ONCE_INIT. */
232
+ struct once_s {
233
+ atomic_flag begun;
234
+ atomic_int done;
235
+ };
236
+ #define ONCE_INIT {ATOMIC_FLAG_INIT, 0}
237
+
238
+ /*
239
+ Run the provided init() function exactly once, even if multiple threads
240
+ invoke once() at the same time. The state must be a once_t initialized with
241
+ ONCE_INIT.
242
+ */
243
+ local void once(once_t *state, void (*init)(void)) {
244
+ if (!atomic_load(&state->done)) {
245
+ if (atomic_flag_test_and_set(&state->begun))
246
+ while (!atomic_load(&state->done))
247
+ ;
248
+ else {
249
+ init();
250
+ atomic_store(&state->done, 1);
251
+ }
252
+ }
253
+ }
254
+
255
+ #else /* no atomics */
256
+
257
+ /* Structure for once(), which must be initialized with ONCE_INIT. */
258
+ struct once_s {
259
+ volatile int begun;
260
+ volatile int done;
261
+ };
262
+ #define ONCE_INIT {0, 0}
263
+
264
+ /* Test and set. Alas, not atomic, but tries to minimize the period of
265
+ vulnerability. */
266
+ local int test_and_set(int volatile *flag) {
267
+ int was;
268
+
269
+ was = *flag;
270
+ *flag = 1;
271
+ return was;
272
+ }
273
+
274
+ /* Run the provided init() function once. This is not thread-safe. */
275
+ local void once(once_t *state, void (*init)(void)) {
276
+ if (!state->done) {
277
+ if (test_and_set(&state->begun))
278
+ while (!state->done)
279
+ ;
280
+ else {
281
+ init();
282
+ state->done = 1;
283
+ }
284
+ }
285
+ }
286
+
287
+ #endif
288
+
289
+ /* State for once(). */
290
+ local once_t made = ONCE_INIT;
291
+
292
+ /*
293
+ Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
294
+ x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
295
+
296
+ Polynomials over GF(2) are represented in binary, one bit per coefficient,
297
+ with the lowest powers in the most significant bit. Then adding polynomials
298
+ is just exclusive-or, and multiplying a polynomial by x is a right shift by
299
+ one. If we call the above polynomial p, and represent a byte as the
300
+ polynomial q, also with the lowest power in the most significant bit (so the
301
+ byte 0xb1 is the polynomial x^7+x^3+x^2+1), then the CRC is (q*x^32) mod p,
302
+ where a mod b means the remainder after dividing a by b.
303
+
304
+ This calculation is done using the shift-register method of multiplying and
305
+ taking the remainder. The register is initialized to zero, and for each
306
+ incoming bit, x^32 is added mod p to the register if the bit is a one (where
307
+ x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by x
308
+ (which is shifting right by one and adding x^32 mod p if the bit shifted out
309
+ is a one). We start with the highest power (least significant bit) of q and
310
+ repeat for all eight bits of q.
311
+
312
+ The table is simply the CRC of all possible eight bit values. This is all the
313
+ information needed to generate CRCs on data a byte at a time for all
314
+ combinations of CRC register values and incoming bytes.
315
+ */
316
+ local void make_crc_table(void)
317
+ {
318
+ unsigned i, j, n;
319
+ z_crc_t p;
320
+
321
+ /* initialize the CRC of bytes tables */
322
+ for (i = 0; i < 256; i++) {
323
+ p = i;
324
+ for (j = 0; j < 8; j++)
325
+ p = p & 1 ? (p >> 1) ^ POLY : p >> 1;
326
+ crc_table[i] = p;
327
+ #ifdef W
328
+ crc_big_table[i] = byte_swap(p);
329
+ #endif
330
+ }
331
+
332
+ /* initialize the x^2^n mod p(x) table */
333
+ p = (z_crc_t)1 << 30; /* x^1 */
334
+ x2n_table[0] = p;
335
+ for (n = 1; n < 32; n++)
336
+ x2n_table[n] = p = multmodp(p, p);
337
+
338
+ #ifdef W
339
+ /* initialize the braiding tables -- needs x2n_table[] */
340
+ braid(crc_braid_table, crc_braid_big_table, N, W);
341
+ #endif
342
+
343
+ #ifdef MAKECRCH
344
+ {
345
+ /*
346
+ The crc32.h header file contains tables for both 32-bit and 64-bit
347
+ z_word_t's, and so requires a 64-bit type be available. In that case,
348
+ z_word_t must be defined to be 64-bits. This code then also generates
349
+ and writes out the tables for the case that z_word_t is 32 bits.
350
+ */
351
+ #if !defined(W) || W != 8
352
+ # error Need a 64-bit integer type in order to generate crc32.h.
353
+ #endif
354
+ FILE *out;
355
+ int k, n;
356
+ z_crc_t ltl[8][256];
357
+ z_word_t big[8][256];
358
+
359
+ out = fopen("crc32.h", "w");
360
+ if (out == NULL) return;
361
+
362
+ /* write out little-endian CRC table to crc32.h */
363
+ fprintf(out,
364
+ "/* crc32.h -- tables for rapid CRC calculation\n"
365
+ " * Generated automatically by crc32.c\n */\n"
366
+ "\n"
367
+ "local const z_crc_t FAR crc_table[] = {\n"
368
+ " ");
369
+ write_table(out, crc_table, 256);
370
+ fprintf(out,
371
+ "};\n");
372
+
373
+ /* write out big-endian CRC table for 64-bit z_word_t to crc32.h */
374
+ fprintf(out,
375
+ "\n"
376
+ "#ifdef W\n"
377
+ "\n"
378
+ "#if W == 8\n"
379
+ "\n"
380
+ "local const z_word_t FAR crc_big_table[] = {\n"
381
+ " ");
382
+ write_table64(out, crc_big_table, 256);
383
+ fprintf(out,
384
+ "};\n");
385
+
386
+ /* write out big-endian CRC table for 32-bit z_word_t to crc32.h */
387
+ fprintf(out,
388
+ "\n"
389
+ "#else /* W == 4 */\n"
390
+ "\n"
391
+ "local const z_word_t FAR crc_big_table[] = {\n"
392
+ " ");
393
+ write_table32hi(out, crc_big_table, 256);
394
+ fprintf(out,
395
+ "};\n"
396
+ "\n"
397
+ "#endif\n");
398
+
399
+ /* write out braid tables for each value of N */
400
+ for (n = 1; n <= 6; n++) {
401
+ fprintf(out,
402
+ "\n"
403
+ "#if N == %d\n", n);
404
+
405
+ /* compute braid tables for this N and 64-bit word_t */
406
+ braid(ltl, big, n, 8);
407
+
408
+ /* write out braid tables for 64-bit z_word_t to crc32.h */
409
+ fprintf(out,
410
+ "\n"
411
+ "#if W == 8\n"
412
+ "\n"
413
+ "local const z_crc_t FAR crc_braid_table[][256] = {\n");
414
+ for (k = 0; k < 8; k++) {
415
+ fprintf(out, " {");
416
+ write_table(out, ltl[k], 256);
417
+ fprintf(out, "}%s", k < 7 ? ",\n" : "");
418
+ }
419
+ fprintf(out,
420
+ "};\n"
421
+ "\n"
422
+ "local const z_word_t FAR crc_braid_big_table[][256] = {\n");
423
+ for (k = 0; k < 8; k++) {
424
+ fprintf(out, " {");
425
+ write_table64(out, big[k], 256);
426
+ fprintf(out, "}%s", k < 7 ? ",\n" : "");
427
+ }
428
+ fprintf(out,
429
+ "};\n");
430
+
431
+ /* compute braid tables for this N and 32-bit word_t */
432
+ braid(ltl, big, n, 4);
433
+
434
+ /* write out braid tables for 32-bit z_word_t to crc32.h */
435
+ fprintf(out,
436
+ "\n"
437
+ "#else /* W == 4 */\n"
438
+ "\n"
439
+ "local const z_crc_t FAR crc_braid_table[][256] = {\n");
440
+ for (k = 0; k < 4; k++) {
441
+ fprintf(out, " {");
442
+ write_table(out, ltl[k], 256);
443
+ fprintf(out, "}%s", k < 3 ? ",\n" : "");
444
+ }
445
+ fprintf(out,
446
+ "};\n"
447
+ "\n"
448
+ "local const z_word_t FAR crc_braid_big_table[][256] = {\n");
449
+ for (k = 0; k < 4; k++) {
450
+ fprintf(out, " {");
451
+ write_table32hi(out, big[k], 256);
452
+ fprintf(out, "}%s", k < 3 ? ",\n" : "");
453
+ }
454
+ fprintf(out,
455
+ "};\n"
456
+ "\n"
457
+ "#endif\n"
458
+ "\n"
459
+ "#endif\n");
460
+ }
461
+ fprintf(out,
462
+ "\n"
463
+ "#endif\n");
464
+
465
+ /* write out zeros operator table to crc32.h */
466
+ fprintf(out,
467
+ "\n"
468
+ "local const z_crc_t FAR x2n_table[] = {\n"
469
+ " ");
470
+ write_table(out, x2n_table, 32);
471
+ fprintf(out,
472
+ "};\n");
473
+ fclose(out);
474
+ }
475
+ #endif /* MAKECRCH */
476
+ }
477
+
478
+ #ifdef MAKECRCH
479
+
480
+ /*
481
+ Write the 32-bit values in table[0..k-1] to out, five per line in
482
+ hexadecimal separated by commas.
483
+ */
484
+ local void write_table(FILE *out, const z_crc_t FAR *table, int k) {
485
+ int n;
486
+
487
+ for (n = 0; n < k; n++)
488
+ fprintf(out, "%s0x%08lx%s", n == 0 || n % 5 ? "" : " ",
489
+ (unsigned long)(table[n]),
490
+ n == k - 1 ? "" : (n % 5 == 4 ? ",\n" : ", "));
491
+ }
492
+
493
+ /*
494
+ Write the high 32-bits of each value in table[0..k-1] to out, five per line
495
+ in hexadecimal separated by commas.
496
+ */
497
+ local void write_table32hi(FILE *out, const z_word_t FAR *table, int k) {
498
+ int n;
499
+
500
+ for (n = 0; n < k; n++)
501
+ fprintf(out, "%s0x%08lx%s", n == 0 || n % 5 ? "" : " ",
502
+ (unsigned long)(table[n] >> 32),
503
+ n == k - 1 ? "" : (n % 5 == 4 ? ",\n" : ", "));
504
+ }
505
+
506
+ /*
507
+ Write the 64-bit values in table[0..k-1] to out, three per line in
508
+ hexadecimal separated by commas. This assumes that if there is a 64-bit
509
+ type, then there is also a long long integer type, and it is at least 64
510
+ bits. If not, then the type cast and format string can be adjusted
511
+ accordingly.
512
+ */
513
+ local void write_table64(FILE *out, const z_word_t FAR *table, int k) {
514
+ int n;
515
+
516
+ for (n = 0; n < k; n++)
517
+ fprintf(out, "%s0x%016llx%s", n == 0 || n % 3 ? "" : " ",
518
+ (unsigned long long)(table[n]),
519
+ n == k - 1 ? "" : (n % 3 == 2 ? ",\n" : ", "));
520
+ }
521
+
522
+ /* Actually do the deed. */
523
+ int main(void) {
524
+ make_crc_table();
525
+ return 0;
526
+ }
527
+
528
+ #endif /* MAKECRCH */
529
+
530
+ #ifdef W
531
+ /*
532
+ Generate the little and big-endian braid tables for the given n and z_word_t
533
+ size w. Each array must have room for w blocks of 256 elements.
534
+ */
535
+ local void braid(z_crc_t ltl[][256], z_word_t big[][256], int n, int w) {
536
+ int k;
537
+ z_crc_t i, p, q;
538
+ for (k = 0; k < w; k++) {
539
+ p = x2nmodp((n * w + 3 - k) << 3, 0);
540
+ ltl[k][0] = 0;
541
+ big[w - 1 - k][0] = 0;
542
+ for (i = 1; i < 256; i++) {
543
+ ltl[k][i] = q = multmodp(i << 24, p);
544
+ big[w - 1 - k][i] = byte_swap(q);
545
+ }
546
+ }
547
+ }
548
+ #endif
549
+
550
+ #endif /* DYNAMIC_CRC_TABLE */
551
+
552
+ /* =========================================================================
553
+ * This function can be used by asm versions of crc32(), and to force the
554
+ * generation of the CRC tables in a threaded application.
555
+ */
556
+ const z_crc_t FAR * ZEXPORT get_crc_table(void) {
557
+ #ifdef DYNAMIC_CRC_TABLE
558
+ once(&made, make_crc_table);
559
+ #endif /* DYNAMIC_CRC_TABLE */
560
+ return (const z_crc_t FAR *)crc_table;
561
+ }
562
+
563
+ /* =========================================================================
564
+ * Use ARM machine instructions if available. This will compute the CRC about
565
+ * ten times faster than the braided calculation. This code does not check for
566
+ * the presence of the CRC instruction at run time. __ARM_FEATURE_CRC32 will
567
+ * only be defined if the compilation specifies an ARM processor architecture
568
+ * that has the instructions. For example, compiling with -march=armv8.1-a or
569
+ * -march=armv8-a+crc, or -march=native if the compile machine has the crc32
570
+ * instructions.
571
+ */
572
+ #if ARMCRC32_CANONICAL_ZLIB
573
+
574
+ /*
575
+ Constants empirically determined to maximize speed. These values are from
576
+ measurements on a Cortex-A57. Your mileage may vary.
577
+ */
578
+ #define Z_BATCH 3990 /* number of words in a batch */
579
+ #define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */
580
+ #define Z_BATCH_MIN 800 /* fewest words in a final batch */
581
+
582
+ unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf,
583
+ z_size_t len) {
584
+ z_crc_t val;
585
+ z_word_t crc1, crc2;
586
+ const z_word_t *word;
587
+ z_word_t val0, val1, val2;
588
+ z_size_t last, last2, i;
589
+ z_size_t num;
590
+
591
+ /* Return initial CRC, if requested. */
592
+ if (buf == Z_NULL) return 0;
593
+
594
+ #ifdef DYNAMIC_CRC_TABLE
595
+ once(&made, make_crc_table);
596
+ #endif /* DYNAMIC_CRC_TABLE */
597
+
598
+ /* Pre-condition the CRC */
599
+ crc = (~crc) & 0xffffffff;
600
+
601
+ /* Compute the CRC up to a word boundary. */
602
+ while (len && ((z_size_t)buf & 7) != 0) {
603
+ len--;
604
+ val = *buf++;
605
+ __asm__ volatile("crc32b %w0, %w0, %w1" : "+r"(crc) : "r"(val));
606
+ }
607
+
608
+ /* Prepare to compute the CRC on full 64-bit words word[0..num-1]. */
609
+ word = (z_word_t const *)buf;
610
+ num = len >> 3;
611
+ len &= 7;
612
+
613
+ /* Do three interleaved CRCs to realize the throughput of one crc32x
614
+ instruction per cycle. Each CRC is calculated on Z_BATCH words. The
615
+ three CRCs are combined into a single CRC after each set of batches. */
616
+ while (num >= 3 * Z_BATCH) {
617
+ crc1 = 0;
618
+ crc2 = 0;
619
+ for (i = 0; i < Z_BATCH; i++) {
620
+ val0 = word[i];
621
+ val1 = word[i + Z_BATCH];
622
+ val2 = word[i + 2 * Z_BATCH];
623
+ __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc) : "r"(val0));
624
+ __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc1) : "r"(val1));
625
+ __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc2) : "r"(val2));
626
+ }
627
+ word += 3 * Z_BATCH;
628
+ num -= 3 * Z_BATCH;
629
+ crc = multmodp(Z_BATCH_ZEROS, crc) ^ crc1;
630
+ crc = multmodp(Z_BATCH_ZEROS, crc) ^ crc2;
631
+ }
632
+
633
+ /* Do one last smaller batch with the remaining words, if there are enough
634
+ to pay for the combination of CRCs. */
635
+ last = num / 3;
636
+ if (last >= Z_BATCH_MIN) {
637
+ last2 = last << 1;
638
+ crc1 = 0;
639
+ crc2 = 0;
640
+ for (i = 0; i < last; i++) {
641
+ val0 = word[i];
642
+ val1 = word[i + last];
643
+ val2 = word[i + last2];
644
+ __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc) : "r"(val0));
645
+ __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc1) : "r"(val1));
646
+ __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc2) : "r"(val2));
647
+ }
648
+ word += 3 * last;
649
+ num -= 3 * last;
650
+ val = x2nmodp(last, 6);
651
+ crc = multmodp(val, crc) ^ crc1;
652
+ crc = multmodp(val, crc) ^ crc2;
653
+ }
654
+
655
+ /* Compute the CRC on any remaining words. */
656
+ for (i = 0; i < num; i++) {
657
+ val0 = word[i];
658
+ __asm__ volatile("crc32x %w0, %w0, %x1" : "+r"(crc) : "r"(val0));
659
+ }
660
+ word += num;
661
+
662
+ /* Complete the CRC on any remaining bytes. */
663
+ buf = (const unsigned char FAR *)word;
664
+ while (len) {
665
+ len--;
666
+ val = *buf++;
667
+ __asm__ volatile("crc32b %w0, %w0, %w1" : "+r"(crc) : "r"(val));
668
+ }
669
+
670
+ /* Return the CRC, post-conditioned. */
671
+ return crc ^ 0xffffffff;
672
+ }
673
+
674
+ #else
675
+
676
+ #ifdef W
677
+
678
+ /*
679
+ Return the CRC of the W bytes in the word_t data, taking the
680
+ least-significant byte of the word as the first byte of data, without any pre
681
+ or post conditioning. This is used to combine the CRCs of each braid.
682
+ */
683
+ local z_crc_t crc_word(z_word_t data) {
684
+ int k;
685
+ for (k = 0; k < W; k++)
686
+ data = (data >> 8) ^ crc_table[data & 0xff];
687
+ return (z_crc_t)data;
688
+ }
689
+
690
+ local z_word_t crc_word_big(z_word_t data) {
691
+ int k;
692
+ for (k = 0; k < W; k++)
693
+ data = (data << 8) ^
694
+ crc_big_table[(data >> ((W - 1) << 3)) & 0xff];
695
+ return data;
696
+ }
697
+
698
+ #endif
699
+
700
+ /* ========================================================================= */
701
+ unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf,
702
+ z_size_t len) {
703
+
704
+ /* If no optimizations are enabled, do it as canonical zlib. */
705
+ #if !defined(CRC32_SIMD_SSE42_PCLMUL) && !defined(CRC32_ARMV8_CRC32) && \
706
+ !defined(RISCV_RVV) && !defined(CRC32_SIMD_AVX512_PCLMUL)
707
+ if (buf == Z_NULL) {
708
+ return 0UL;
709
+ }
710
+ #else
711
+ /*
712
+ * zlib convention is to call crc32(0, NULL, 0); before making
713
+ * calls to crc32(). So this is a good, early (and infrequent)
714
+ * place to cache CPU features if needed for those later, more
715
+ * interesting crc32() calls.
716
+ */
717
+ if (buf == Z_NULL) {
718
+ if (!len)
719
+ cpu_check_features();
720
+ return 0UL;
721
+ }
722
+ #endif
723
+ /* If AVX-512 is enabled, we will use it for longer inputs and fallback
724
+ * to SSE4.2 and eventually the portable implementation to handle the tail.
725
+ */
726
+ #if defined(CRC32_SIMD_AVX512_PCLMUL)
727
+ if (x86_cpu_enable_avx512 && len >= Z_CRC32_AVX512_MINIMUM_LENGTH) {
728
+ /* crc32 64-byte chunks */
729
+ z_size_t chunk_size = len & ~Z_CRC32_AVX512_CHUNKSIZE_MASK;
730
+ crc = ~crc32_avx512_simd_(buf, chunk_size, ~(uint32_t)crc);
731
+ /* check remaining data */
732
+ len -= chunk_size;
733
+ if (!len)
734
+ return crc;
735
+ /* Fall into the default crc32 for the remaining data. */
736
+ buf += chunk_size;
737
+ }
738
+ #endif
739
+ #if defined(CRC32_SIMD_SSE42_PCLMUL)
740
+ if (x86_cpu_enable_simd && len >= Z_CRC32_SSE42_MINIMUM_LENGTH) {
741
+ /* crc32 16-byte chunks */
742
+ z_size_t chunk_size = len & ~Z_CRC32_SSE42_CHUNKSIZE_MASK;
743
+ crc = ~crc32_sse42_simd_(buf, chunk_size, ~(uint32_t)crc);
744
+ /* check remaining data */
745
+ len -= chunk_size;
746
+ if (!len)
747
+ return crc;
748
+ /* Fall into the default crc32 for the remaining data. */
749
+ buf += chunk_size;
750
+ }
751
+ #elif defined(CRC32_ARMV8_CRC32)
752
+ if (arm_cpu_enable_crc32) {
753
+ #if defined(__aarch64__)
754
+ /* PMULL is 64bit only, plus code needs at least a 64 bytes buffer. */
755
+ if (arm_cpu_enable_pmull && (len > Z_CRC32_PMULL_MINIMUM_LENGTH)) {
756
+ const size_t chunk_size = len & ~Z_CRC32_PMULL_CHUNKSIZE_MASK;
757
+ crc = ~armv8_crc32_pmull_little(buf, chunk_size, ~(uint32_t)crc);
758
+ /* Check remaining data. */
759
+ len -= chunk_size;
760
+ if (!len)
761
+ return crc;
762
+
763
+ /* Fall through for the remaining data. */
764
+ buf += chunk_size;
765
+ }
766
+ #endif
767
+ /* This is scalar and self contained, used on Armv8@32bit or tail. */
768
+ return armv8_crc32_little(buf, len, crc);
769
+ }
770
+ #endif /* CRC32_SIMD */
771
+
772
+ #ifdef DYNAMIC_CRC_TABLE
773
+ once(&made, make_crc_table);
774
+ #endif /* DYNAMIC_CRC_TABLE */
775
+ /* Pre-condition the CRC */
776
+ crc = (~crc) & 0xffffffff;
777
+
778
+ #ifdef W
779
+
780
+ /* If provided enough bytes, do a braided CRC calculation. */
781
+ if (len >= N * W + W - 1) {
782
+ z_size_t blks;
783
+ z_word_t const *words;
784
+ unsigned endian;
785
+ int k;
786
+
787
+ /* Compute the CRC up to a z_word_t boundary. */
788
+ while (len && ((z_size_t)buf & (W - 1)) != 0) {
789
+ len--;
790
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
791
+ }
792
+
793
+ /* Compute the CRC on as many N z_word_t blocks as are available. */
794
+ blks = len / (N * W);
795
+ len -= blks * N * W;
796
+ words = (z_word_t const *)buf;
797
+
798
+ /* Do endian check at execution time instead of compile time, since ARM
799
+ processors can change the endianness at execution time. If the
800
+ compiler knows what the endianness will be, it can optimize out the
801
+ check and the unused branch. */
802
+ endian = 1;
803
+ if (*(unsigned char *)&endian) {
804
+ /* Little endian. */
805
+
806
+ z_crc_t crc0;
807
+ z_word_t word0;
808
+ #if N > 1
809
+ z_crc_t crc1;
810
+ z_word_t word1;
811
+ #if N > 2
812
+ z_crc_t crc2;
813
+ z_word_t word2;
814
+ #if N > 3
815
+ z_crc_t crc3;
816
+ z_word_t word3;
817
+ #if N > 4
818
+ z_crc_t crc4;
819
+ z_word_t word4;
820
+ #if N > 5
821
+ z_crc_t crc5;
822
+ z_word_t word5;
823
+ #endif
824
+ #endif
825
+ #endif
826
+ #endif
827
+ #endif
828
+
829
+ /* Initialize the CRC for each braid. */
830
+ crc0 = crc;
831
+ #if N > 1
832
+ crc1 = 0;
833
+ #if N > 2
834
+ crc2 = 0;
835
+ #if N > 3
836
+ crc3 = 0;
837
+ #if N > 4
838
+ crc4 = 0;
839
+ #if N > 5
840
+ crc5 = 0;
841
+ #endif
842
+ #endif
843
+ #endif
844
+ #endif
845
+ #endif
846
+
847
+ /*
848
+ Process the first blks-1 blocks, computing the CRCs on each braid
849
+ independently.
850
+ */
851
+ while (--blks) {
852
+ /* Load the word for each braid into registers. */
853
+ word0 = crc0 ^ words[0];
854
+ #if N > 1
855
+ word1 = crc1 ^ words[1];
856
+ #if N > 2
857
+ word2 = crc2 ^ words[2];
858
+ #if N > 3
859
+ word3 = crc3 ^ words[3];
860
+ #if N > 4
861
+ word4 = crc4 ^ words[4];
862
+ #if N > 5
863
+ word5 = crc5 ^ words[5];
864
+ #endif
865
+ #endif
866
+ #endif
867
+ #endif
868
+ #endif
869
+ words += N;
870
+
871
+ /* Compute and update the CRC for each word. The loop should
872
+ get unrolled. */
873
+ crc0 = crc_braid_table[0][word0 & 0xff];
874
+ #if N > 1
875
+ crc1 = crc_braid_table[0][word1 & 0xff];
876
+ #if N > 2
877
+ crc2 = crc_braid_table[0][word2 & 0xff];
878
+ #if N > 3
879
+ crc3 = crc_braid_table[0][word3 & 0xff];
880
+ #if N > 4
881
+ crc4 = crc_braid_table[0][word4 & 0xff];
882
+ #if N > 5
883
+ crc5 = crc_braid_table[0][word5 & 0xff];
884
+ #endif
885
+ #endif
886
+ #endif
887
+ #endif
888
+ #endif
889
+ for (k = 1; k < W; k++) {
890
+ crc0 ^= crc_braid_table[k][(word0 >> (k << 3)) & 0xff];
891
+ #if N > 1
892
+ crc1 ^= crc_braid_table[k][(word1 >> (k << 3)) & 0xff];
893
+ #if N > 2
894
+ crc2 ^= crc_braid_table[k][(word2 >> (k << 3)) & 0xff];
895
+ #if N > 3
896
+ crc3 ^= crc_braid_table[k][(word3 >> (k << 3)) & 0xff];
897
+ #if N > 4
898
+ crc4 ^= crc_braid_table[k][(word4 >> (k << 3)) & 0xff];
899
+ #if N > 5
900
+ crc5 ^= crc_braid_table[k][(word5 >> (k << 3)) & 0xff];
901
+ #endif
902
+ #endif
903
+ #endif
904
+ #endif
905
+ #endif
906
+ }
907
+ }
908
+
909
+ /*
910
+ Process the last block, combining the CRCs of the N braids at the
911
+ same time.
912
+ */
913
+ crc = crc_word(crc0 ^ words[0]);
914
+ #if N > 1
915
+ crc = crc_word(crc1 ^ words[1] ^ crc);
916
+ #if N > 2
917
+ crc = crc_word(crc2 ^ words[2] ^ crc);
918
+ #if N > 3
919
+ crc = crc_word(crc3 ^ words[3] ^ crc);
920
+ #if N > 4
921
+ crc = crc_word(crc4 ^ words[4] ^ crc);
922
+ #if N > 5
923
+ crc = crc_word(crc5 ^ words[5] ^ crc);
924
+ #endif
925
+ #endif
926
+ #endif
927
+ #endif
928
+ #endif
929
+ words += N;
930
+ }
931
+ else {
932
+ /* Big endian. */
933
+
934
+ z_word_t crc0, word0, comb;
935
+ #if N > 1
936
+ z_word_t crc1, word1;
937
+ #if N > 2
938
+ z_word_t crc2, word2;
939
+ #if N > 3
940
+ z_word_t crc3, word3;
941
+ #if N > 4
942
+ z_word_t crc4, word4;
943
+ #if N > 5
944
+ z_word_t crc5, word5;
945
+ #endif
946
+ #endif
947
+ #endif
948
+ #endif
949
+ #endif
950
+
951
+ /* Initialize the CRC for each braid. */
952
+ crc0 = byte_swap(crc);
953
+ #if N > 1
954
+ crc1 = 0;
955
+ #if N > 2
956
+ crc2 = 0;
957
+ #if N > 3
958
+ crc3 = 0;
959
+ #if N > 4
960
+ crc4 = 0;
961
+ #if N > 5
962
+ crc5 = 0;
963
+ #endif
964
+ #endif
965
+ #endif
966
+ #endif
967
+ #endif
968
+
969
+ /*
970
+ Process the first blks-1 blocks, computing the CRCs on each braid
971
+ independently.
972
+ */
973
+ while (--blks) {
974
+ /* Load the word for each braid into registers. */
975
+ word0 = crc0 ^ words[0];
976
+ #if N > 1
977
+ word1 = crc1 ^ words[1];
978
+ #if N > 2
979
+ word2 = crc2 ^ words[2];
980
+ #if N > 3
981
+ word3 = crc3 ^ words[3];
982
+ #if N > 4
983
+ word4 = crc4 ^ words[4];
984
+ #if N > 5
985
+ word5 = crc5 ^ words[5];
986
+ #endif
987
+ #endif
988
+ #endif
989
+ #endif
990
+ #endif
991
+ words += N;
992
+
993
+ /* Compute and update the CRC for each word. The loop should
994
+ get unrolled. */
995
+ crc0 = crc_braid_big_table[0][word0 & 0xff];
996
+ #if N > 1
997
+ crc1 = crc_braid_big_table[0][word1 & 0xff];
998
+ #if N > 2
999
+ crc2 = crc_braid_big_table[0][word2 & 0xff];
1000
+ #if N > 3
1001
+ crc3 = crc_braid_big_table[0][word3 & 0xff];
1002
+ #if N > 4
1003
+ crc4 = crc_braid_big_table[0][word4 & 0xff];
1004
+ #if N > 5
1005
+ crc5 = crc_braid_big_table[0][word5 & 0xff];
1006
+ #endif
1007
+ #endif
1008
+ #endif
1009
+ #endif
1010
+ #endif
1011
+ for (k = 1; k < W; k++) {
1012
+ crc0 ^= crc_braid_big_table[k][(word0 >> (k << 3)) & 0xff];
1013
+ #if N > 1
1014
+ crc1 ^= crc_braid_big_table[k][(word1 >> (k << 3)) & 0xff];
1015
+ #if N > 2
1016
+ crc2 ^= crc_braid_big_table[k][(word2 >> (k << 3)) & 0xff];
1017
+ #if N > 3
1018
+ crc3 ^= crc_braid_big_table[k][(word3 >> (k << 3)) & 0xff];
1019
+ #if N > 4
1020
+ crc4 ^= crc_braid_big_table[k][(word4 >> (k << 3)) & 0xff];
1021
+ #if N > 5
1022
+ crc5 ^= crc_braid_big_table[k][(word5 >> (k << 3)) & 0xff];
1023
+ #endif
1024
+ #endif
1025
+ #endif
1026
+ #endif
1027
+ #endif
1028
+ }
1029
+ }
1030
+
1031
+ /*
1032
+ Process the last block, combining the CRCs of the N braids at the
1033
+ same time.
1034
+ */
1035
+ comb = crc_word_big(crc0 ^ words[0]);
1036
+ #if N > 1
1037
+ comb = crc_word_big(crc1 ^ words[1] ^ comb);
1038
+ #if N > 2
1039
+ comb = crc_word_big(crc2 ^ words[2] ^ comb);
1040
+ #if N > 3
1041
+ comb = crc_word_big(crc3 ^ words[3] ^ comb);
1042
+ #if N > 4
1043
+ comb = crc_word_big(crc4 ^ words[4] ^ comb);
1044
+ #if N > 5
1045
+ comb = crc_word_big(crc5 ^ words[5] ^ comb);
1046
+ #endif
1047
+ #endif
1048
+ #endif
1049
+ #endif
1050
+ #endif
1051
+ words += N;
1052
+ crc = byte_swap(comb);
1053
+ }
1054
+
1055
+ /*
1056
+ Update the pointer to the remaining bytes to process.
1057
+ */
1058
+ buf = (unsigned char const *)words;
1059
+ }
1060
+
1061
+ #endif /* W */
1062
+
1063
+ /* Complete the computation of the CRC on any remaining bytes. */
1064
+ while (len >= 8) {
1065
+ len -= 8;
1066
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1067
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1068
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1069
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1070
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1071
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1072
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1073
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1074
+ }
1075
+ while (len) {
1076
+ len--;
1077
+ crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1078
+ }
1079
+
1080
+ /* Return the CRC, post-conditioned. */
1081
+ return crc ^ 0xffffffff;
1082
+ }
1083
+
1084
+ #endif
1085
+
1086
+ /* ========================================================================= */
1087
+ unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf,
1088
+ uInt len) {
1089
+ /* Some bots compile with optimizations disabled, others will emulate
1090
+ * ARM on x86 and other weird combinations.
1091
+ */
1092
+ #if defined(CRC32_SIMD_SSE42_PCLMUL) || defined(CRC32_ARMV8_CRC32) \
1093
+ || defined(RISCV_RVV)
1094
+ /* We got to verify CPU features, so exploit the common usage pattern
1095
+ * of calling this function with Z_NULL for an initial valid crc value.
1096
+ * This allows to cache the result of the feature check and avoid extraneous
1097
+ * function calls.
1098
+ */
1099
+ if (buf == Z_NULL) {
1100
+ if (!len) /* Assume user is calling crc32(0, NULL, 0); */
1101
+ cpu_check_features();
1102
+ return 0UL;
1103
+ }
1104
+ #endif
1105
+
1106
+ #if defined(CRC32_ARMV8_CRC32)
1107
+ if (arm_cpu_enable_crc32) {
1108
+ #if defined(__aarch64__)
1109
+ /* PMULL is 64bit only, plus code needs at least a 64 bytes buffer. */
1110
+ if (arm_cpu_enable_pmull && (len > Z_CRC32_PMULL_MINIMUM_LENGTH)) {
1111
+ const size_t chunk_size = len & ~Z_CRC32_PMULL_CHUNKSIZE_MASK;
1112
+ crc = ~armv8_crc32_pmull_little(buf, chunk_size, ~(uint32_t)crc);
1113
+ /* Check remaining data. */
1114
+ len -= chunk_size;
1115
+ if (!len)
1116
+ return crc;
1117
+
1118
+ /* Fall through for the remaining data. */
1119
+ buf += chunk_size;
1120
+ }
1121
+ #endif
1122
+ return armv8_crc32_little(buf, len, crc); /* Armv8@32bit or tail. */
1123
+ }
1124
+ #endif
1125
+ return crc32_z(crc, buf, len); /* Armv7 or Armv8 w/o crypto extensions. */
1126
+ }
1127
+
1128
+ /* ========================================================================= */
1129
+ uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) {
1130
+ #ifdef DYNAMIC_CRC_TABLE
1131
+ once(&made, make_crc_table);
1132
+ #endif /* DYNAMIC_CRC_TABLE */
1133
+ return multmodp(x2nmodp(len2, 3), crc1) ^ (crc2 & 0xffffffff);
1134
+ }
1135
+
1136
+ /* ========================================================================= */
1137
+ uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2) {
1138
+ return crc32_combine64(crc1, crc2, (z_off64_t)len2);
1139
+ }
1140
+ /* ========================================================================= */
1141
+ uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) {
1142
+ #ifdef DYNAMIC_CRC_TABLE
1143
+ once(&made, make_crc_table);
1144
+ #endif /* DYNAMIC_CRC_TABLE */
1145
+ return x2nmodp(len2, 3);
1146
+ }
1147
+
1148
+ /* ========================================================================= */
1149
+ uLong ZEXPORT crc32_combine_gen(z_off_t len2) {
1150
+ return crc32_combine_gen64((z_off64_t)len2);
1151
+ }
1152
+
1153
+ /* ========================================================================= */
1154
+ uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op) {
1155
+ return multmodp(op, crc1) ^ (crc2 & 0xffffffff);
1156
+ }
1157
+
1158
+ ZLIB_INTERNAL void crc_reset(deflate_state *const s)
1159
+ {
1160
+ #ifdef CRC32_SIMD_SSE42_PCLMUL
1161
+ if (x86_cpu_enable_simd) {
1162
+ crc_fold_init(s);
1163
+ return;
1164
+ }
1165
+ #endif
1166
+ s->strm->adler = crc32(0L, Z_NULL, 0);
1167
+ }
1168
+
1169
+ ZLIB_INTERNAL void crc_finalize(deflate_state *const s)
1170
+ {
1171
+ #ifdef QAT_COMPRESSION_ENABLED
1172
+ if (s->qat_s) {
1173
+ return;
1174
+ }
1175
+ #endif
1176
+ #ifdef CRC32_SIMD_SSE42_PCLMUL
1177
+ if (x86_cpu_enable_simd)
1178
+ s->strm->adler = crc_fold_512to32(s);
1179
+ #endif
1180
+ }
1181
+
1182
+ ZLIB_INTERNAL void copy_with_crc(z_streamp strm, Bytef *dst, long size)
1183
+ {
1184
+ #ifdef CRC32_SIMD_SSE42_PCLMUL
1185
+ if (x86_cpu_enable_simd) {
1186
+ crc_fold_copy(strm->state, dst, strm->next_in, size);
1187
+ return;
1188
+ }
1189
+ #endif
1190
+ zmemcpy(dst, strm->next_in, size);
1191
+ strm->adler = crc32(strm->adler, dst, size);
1192
+ }